ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/plugins/cfperl/cfperl.xs
Revision: 1.16
Committed: Wed Feb 8 04:32:19 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.15: +13 -16 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /*****************************************************************************/
2 /* CrossFire, A Multiplayer game for the X Window System */
3 /* */
4 /*****************************************************************************/
5
6 /*
7 * This code is placed under the GNU General Public Licence (GPL)
8 *
9 * Copyright (C) 2001-2005 by Chachkoff Yann
10 * Copyright (C) 2006 by Marc Lehmann <cf@schmorpd.e>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include <EXTERN.h>
28 #include <perl.h>
29 #include <XSUB.h>
30
31 #undef save_long // clashes with libproto.h
32
33 #define PLUGIN_NAME "perl"
34 #define PLUGIN_VERSION "cfperl 0.0"
35
36 #ifndef __CEXTRACT__
37 #include <plugin.h>
38 #endif
39
40 #undef MODULEAPI
41 #ifdef WIN32
42 #else
43 #define MODULEAPI
44 #endif
45
46 #include <plugin_common.h>
47
48 #include <stdarg.h>
49
50 #include "perlxsi.c"
51
52 static f_plug_api gethook;
53 static f_plug_api registerGlobalEvent;
54 static f_plug_api unregisterGlobalEvent;
55 static f_plug_api systemDirectory;
56 static f_plug_api object_set_property;
57 static f_plug_api map_get_map;
58
59 typedef struct
60 {
61 object* who;
62 object* activator;
63 object* third;
64 char message[1024];
65 int fix;
66 int event_code;
67 char extension[1024]; // name field, should invoke specific perl extension
68 char options[1024]; // slaying field of event_connectors
69 int returnvalue;
70 } CFPContext;
71
72 //static int current_command = -999;
73
74 static HV *obj_cache;
75 static PerlInterpreter *perl;
76
77 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78
79 // garbage collect some perl objects, if possible
80 // all objects no longer referenced and empty are
81 // eligible for destruction.
82 void
83 clean_obj_cache ()
84 {
85 return; // killing neko-san gives me an unreferenced scalar
86 int todo = 10;
87 do
88 {
89 I32 klen;
90 char *key;
91 HE *he = hv_iternext (obj_cache);
92
93 if (he)
94 {
95 SV *sv = hv_iterval (obj_cache, he);
96
97 // emopty and unreferened? nuke it
98 if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv))))
99 {
100 hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD);
101 todo++;
102 }
103 }
104 else
105 break;
106 }
107 while (--todo);
108 }
109
110 static SV *
111 newSVptr (void *ptr, const char *klass)
112 {
113 if (!ptr)
114 return &PL_sv_undef;
115
116 HV *hv = newHV ();
117 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
118 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
119 }
120
121 static SV *
122 newSVptr_cached (void *ptr, const char *klass)
123 {
124 SV *sv, **he;
125
126 if (!ptr)
127 return &PL_sv_undef;
128
129 he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0);
130
131 if (he)
132 sv = *he;
133 else
134 {
135 sv = newSVptr (ptr, klass);
136 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0);
137 }
138
139 return newSVsv (sv);
140 }
141
142 static void
143 clearSVptr (SV *sv)
144 {
145 if (SvROK (sv))
146 sv = SvRV (sv);
147
148 hv_clear ((HV *)sv);
149 sv_unmagic (sv, PERL_MAGIC_ext);
150 }
151
152 static long
153 SvPTR (SV *sv, const char *klass)
154 {
155 if (!sv_derived_from (sv, klass))
156 croak ("object of type %s expected", klass);
157
158 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
159
160 if (!mg)
161 croak ("perl code used %s object, but C object is already destroyed, caught", klass);
162
163 return (long)mg->mg_ptr;
164 }
165
166 SV *
167 newSVcfapi (int type, ...)
168 {
169 SV *sv;
170
171 va_list args;
172 va_start (args, type);
173
174 switch (type)
175 {
176 case CFAPI_INT:
177 sv = newSViv (*va_arg (args, int *));
178 break;
179
180 case CFAPI_LONG:
181 sv = newSViv (*va_arg (args, long *));
182 break;
183
184 case CFAPI_DOUBLE:
185 sv = newSViv (*va_arg (args, double *));
186 break;
187
188 case CFAPI_STRING:
189 {
190 char *str = va_arg (args, char *);
191 sv = str ? newSVpv (str, 0) : &PL_sv_undef;
192 }
193 break;
194
195 case CFAPI_POBJECT:
196 {
197 object *obj = va_arg (args, object *);
198
199 if (!obj)
200 sv = &PL_sv_undef;
201 else
202 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE))
203 {
204 case MAP:
205 sv = newSVptr_cached (obj, "cf::object::map");
206 break;
207
208 case PLAYER:
209 sv = newSVptr_cached (obj, "cf::object::player");
210 break;
211
212 default:
213 sv = newSVptr_cached (obj, "cf::object");
214 break;
215 }
216 }
217 break;
218
219 case CFAPI_PMAP:
220 sv = newSVptr (va_arg (args, mapstruct *), "cf::map");
221 break;
222
223 case CFAPI_PPLAYER:
224 sv = newSVptr (va_arg (args, player *), "cf::player");
225 break;
226
227 case CFAPI_PARCH:
228 sv = newSVptr (va_arg (args, archetype *), "cf::arch");
229 break;
230
231 case CFAPI_PPARTY:
232 sv = newSVptr (va_arg (args, partylist *), "cf::party");
233 break;
234
235 case CFAPI_PREGION:
236 sv = newSVptr (va_arg (args, region *), "cf::region");
237 break;
238
239 default:
240 assert (("unhandled type in newSVcfapi", 0));
241 }
242
243 va_end (args);
244
245 return sv;
246 }
247
248 /////////////////////////////////////////////////////////////////////////////
249
250 void
251 inject_event (const char *func, CFPContext *context)
252 {
253 dSP;
254
255 ENTER;
256 SAVETMPS;
257
258 PUSHMARK (SP);
259
260 HV *hv = newHV ();
261 #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
262 hv_context (CFAPI_POBJECT, ,who);
263 hv_context (CFAPI_POBJECT, ,activator);
264 hv_context (CFAPI_POBJECT, ,third);
265 hv_context (CFAPI_STRING , ,message);
266 hv_context (CFAPI_INT ,&,fix);
267 hv_context (CFAPI_INT ,&,event_code);
268 hv_context (CFAPI_STRING , ,options);
269 hv_context (CFAPI_STRING , ,extension);
270
271 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
272
273 PUTBACK;
274 int count = call_pv (func, G_SCALAR | G_EVAL);
275 SPAGAIN;
276
277 if (SvTRUE (ERRSV))
278 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
279
280 context->returnvalue = count > 0 ? POPi : 0;
281
282 PUTBACK;
283 FREETMPS;
284 LEAVE;
285 }
286
287 /////////////////////////////////////////////////////////////////////////////
288
289 int
290 initPlugin (const char *iversion, f_plug_api gethooksptr)
291 {
292 gethook = gethooksptr;
293 printf (PLUGIN_VERSION " init\n");
294
295 return 0;
296 }
297
298 static CommArray_s rtn_cmd;
299
300 int
301 runPluginCommand (object *obj, char *params)
302 {
303 dSP;
304
305 ENTER;
306 SAVETMPS;
307
308 PUSHMARK (SP);
309
310 EXTEND (SP, 3);
311 PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0)));
312 PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj)));
313
314 if (params)
315 PUSHs (sv_2mortal (newSVpv (params, 0)));
316
317 PUTBACK;
318 int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL);
319 SPAGAIN;
320
321 if (SvTRUE (ERRSV))
322 LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV));
323
324 int returnvalue = count > 0 ? POPi : -1;
325
326 PUTBACK;
327 FREETMPS;
328 LEAVE;
329
330 return returnvalue;
331 }
332
333 void *
334 getPluginProperty (int *type, ...)
335 {
336 va_list args;
337 char *propname;
338 int i;
339 va_start (args, type);
340 propname = va_arg (args, char *);
341 //printf ("Property name: %s\n", propname);
342
343 if (!strcmp (propname, "command?"))
344 {
345 if (!perl)
346 return NULL;
347
348 const char *cmdname = va_arg (args, const char *);
349 HV *hv = get_hv ("cf::COMMAND", 1);
350 SV **svp = hv_fetch (hv, cmdname, strlen (cmdname) + 1, 0);
351
352 va_end (args);
353
354 if (svp)
355 {
356 // this is totaly broken, should stash it into %COMMAND
357 rtn_cmd.name = cmdname;
358 rtn_cmd.time = SvNV (*svp);
359 rtn_cmd.func = runPluginCommand;
360
361 return &rtn_cmd;
362 }
363 }
364 else if (!strcmp (propname, "Identification"))
365 {
366 va_end (args);
367 return PLUGIN_NAME;
368 }
369 else if (!strcmp (propname, "FullName"))
370 {
371 va_end (args);
372 return PLUGIN_VERSION;
373 }
374 else
375 va_end (args);
376
377 return NULL;
378 }
379
380 void *globalEventListener (int *type, ...);
381
382 int
383 postInitPlugin ()
384 {
385 int hooktype = 1;
386 int rtype = 0;
387
388 printf (PLUGIN_VERSION " post init\n");
389
390 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event");
391 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event");
392 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory");
393 object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property");
394 map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map");
395
396 cf_init_plugin (gethook);
397
398 /* Pick the global events you want to monitor from this plugin */
399 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener);
400 registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener);
401 //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener);
402 registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener);
403 registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener);
404 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener);
405 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener);
406 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener);
407 registerGlobalEvent (NULL, EVENT_MAPLEAVE, PLUGIN_NAME, globalEventListener);
408 registerGlobalEvent (NULL, EVENT_MAPRESET, PLUGIN_NAME, globalEventListener);
409 registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener);
410 registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener);
411 registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener);
412 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
413 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
414 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
415
416 char *argv[] = {
417 "",
418 "-e"
419 "BEGIN {"
420 " cf->bootstrap;"
421 " unshift @INC, cf::datadir ();"
422 "}"
423 ""
424 "use cf;"
425 };
426
427 perl = perl_alloc ();
428 perl_construct (perl);
429
430 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
431 {
432 printf ("unable to initialize perl-interpreter, continuing without.\n");
433
434 perl_destruct (perl);
435 perl_free (perl);
436 perl = 0;
437 }
438 else
439 {
440 obj_cache = newHV ();
441 }
442
443 return 0;
444 }
445
446 void *
447 globalEventListener (int *type, ...)
448 {
449 va_list args;
450 static int rv = 0;
451 CFPContext context;
452 char *buf;
453 player *pl;
454 object *op;
455
456 if (!perl)
457 return;
458
459 memset (&context, 0, sizeof (context));
460
461 va_start (args, type);
462 context.event_code = va_arg (args, int);
463
464 switch (context.event_code)
465 {
466 case EVENT_CRASH:
467 printf ("Unimplemented for now\n");
468 break;
469
470 case EVENT_MAPENTER:
471 case EVENT_MAPLEAVE:
472 case EVENT_FREE_OB:
473 case EVENT_BORN:
474 case EVENT_REMOVE:
475 context.activator = va_arg (args, object *);
476 break;
477
478 case EVENT_PLAYER_DEATH:
479 context.who = va_arg (args, object *);
480 break;
481
482 case EVENT_GKILL:
483 context.who = va_arg (args, object *);
484 context.activator = va_arg (args, object *);
485 break;
486
487 case EVENT_LOGIN:
488 case EVENT_LOGOUT:
489 pl = va_arg (args, player *);
490 context.activator = pl->ob;
491 buf = va_arg (args, char *);
492 if (buf != 0)
493 strncpy (context.message, buf, sizeof (context.message));
494 break;
495
496 case EVENT_SHOUT:
497 case EVENT_MUZZLE:
498 case EVENT_KICK:
499 context.activator = va_arg (args, object *);
500 buf = va_arg (args, char *);
501 if (buf != 0)
502 strncpy (context.message, buf, sizeof (context.message));
503 break;
504
505 case EVENT_CLOCK:
506 clean_obj_cache ();
507 break;
508
509 case EVENT_TELL:
510 break;
511
512 case EVENT_MAPRESET:
513 buf = va_arg (args, char *);
514 if (buf != 0)
515 strncpy (context.message, buf, sizeof (context.message));
516 break;
517 }
518
519 va_end (args);
520
521 if (context.event_code == EVENT_FREE_OB)
522 {
523 SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (object *), 0);
524
525 if (sv)
526 {
527 clearSVptr (sv);
528 SvREFCNT_dec (sv);
529 }
530 }
531 else
532 inject_event ("cf::inject_global_event", &context);
533
534 rv = context.returnvalue;
535
536 return &rv;
537 }
538
539 void *
540 eventListener (int *type, ...)
541 {
542 static int rv = 0;
543 va_list args;
544 char *buf;
545 CFPContext context;
546
547 if (!perl)
548 return;
549
550 memset (&context, 0, sizeof (context));
551
552 va_start (args, type);
553
554 context.who = va_arg (args, object *);
555 context.event_code = va_arg (args, int);
556 context.activator = va_arg (args, object *);
557 context.third = va_arg (args, object *);
558
559 buf = va_arg (args, char *);
560 if (buf != 0)
561 strncpy (context.message, buf, sizeof (context.message));
562
563 context.fix = va_arg (args, int);
564 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension));
565 strncpy (context.options, va_arg (args, char *), sizeof (context.options));
566 context.returnvalue = 0;
567 va_end (args);
568
569 inject_event ("cf::inject_event", &context);
570
571 rv = context.returnvalue;
572 return &rv;
573 }
574
575 int
576 closePlugin ()
577 {
578 printf (PLUGIN_VERSION " closing\n");
579
580 if (perl)
581 {
582 perl_destruct (perl);
583 perl_free (perl);
584 perl = 0;
585 }
586
587 return 0;
588 }
589
590 MODULE = cf PACKAGE = cf PREFIX = cf_
591
592 BOOT:
593 {
594 HV *stash = gv_stashpv ("cf", 1);
595
596 static const struct {
597 const char *name;
598 IV iv;
599 } *civ, const_iv[] = {
600 # define const_iv(name) { # name, (IV)name },
601 const_iv (llevError)
602 const_iv (llevInfo)
603 const_iv (llevDebug)
604 const_iv (llevMonster)
605
606 const_iv (PLAYER)
607 const_iv (ROD)
608 const_iv (TREASURE)
609 const_iv (POTION)
610 const_iv (FOOD)
611 const_iv (POISON)
612 const_iv (BOOK)
613 const_iv (CLOCK)
614 const_iv (LIGHTNING)
615 const_iv (ARROW)
616 const_iv (BOW)
617 const_iv (WEAPON)
618 const_iv (ARMOUR)
619 const_iv (PEDESTAL)
620 const_iv (ALTAR)
621 const_iv (CONFUSION)
622 const_iv (LOCKED_DOOR)
623 const_iv (SPECIAL_KEY)
624 const_iv (MAP)
625 const_iv (DOOR)
626 const_iv (KEY)
627 const_iv (TIMED_GATE)
628 const_iv (TRIGGER)
629 const_iv (GRIMREAPER)
630 const_iv (MAGIC_EAR)
631 const_iv (TRIGGER_BUTTON)
632 const_iv (TRIGGER_ALTAR)
633 const_iv (TRIGGER_PEDESTAL)
634 const_iv (SHIELD)
635 const_iv (HELMET)
636 const_iv (HORN)
637 const_iv (MONEY)
638 const_iv (CLASS)
639 const_iv (GRAVESTONE)
640 const_iv (AMULET)
641 const_iv (PLAYERMOVER)
642 const_iv (TELEPORTER)
643 const_iv (CREATOR)
644 const_iv (SKILL)
645 const_iv (EXPERIENCE)
646 const_iv (EARTHWALL)
647 const_iv (GOLEM)
648 const_iv (THROWN_OBJ)
649 const_iv (BLINDNESS)
650 const_iv (GOD)
651 const_iv (DETECTOR)
652 const_iv (TRIGGER_MARKER)
653 const_iv (DEAD_OBJECT)
654 const_iv (DRINK)
655 const_iv (MARKER)
656 const_iv (HOLY_ALTAR)
657 const_iv (PLAYER_CHANGER)
658 const_iv (BATTLEGROUND)
659 const_iv (PEACEMAKER)
660 const_iv (GEM)
661 const_iv (FIREWALL)
662 const_iv (ANVIL)
663 const_iv (CHECK_INV)
664 const_iv (MOOD_FLOOR)
665 const_iv (EXIT)
666 const_iv (ENCOUNTER)
667 const_iv (SHOP_FLOOR)
668 const_iv (SHOP_MAT)
669 const_iv (RING)
670 const_iv (FLOOR)
671 const_iv (FLESH)
672 const_iv (INORGANIC)
673 const_iv (SKILL_TOOL)
674 const_iv (LIGHTER)
675 const_iv (TRAP_PART)
676 const_iv (WALL)
677 const_iv (LIGHT_SOURCE)
678 const_iv (MISC_OBJECT)
679 const_iv (MONSTER)
680 const_iv (SPAWN_GENERATOR)
681 const_iv (LAMP)
682 const_iv (DUPLICATOR)
683 const_iv (TOOL)
684 const_iv (SPELLBOOK)
685 const_iv (BUILDFAC)
686 const_iv (CLOAK)
687 const_iv (SPINNER)
688 const_iv (GATE)
689 const_iv (BUTTON)
690 const_iv (CF_HANDLE)
691 const_iv (HOLE)
692 const_iv (TRAPDOOR)
693 const_iv (SIGN)
694 const_iv (BOOTS)
695 const_iv (GLOVES)
696 const_iv (SPELL)
697 const_iv (SPELL_EFFECT)
698 const_iv (CONVERTER)
699 const_iv (BRACERS)
700 const_iv (POISONING)
701 const_iv (SAVEBED)
702 const_iv (POISONCLOUD)
703 const_iv (FIREHOLES)
704 const_iv (WAND)
705 const_iv (SCROLL)
706 const_iv (DIRECTOR)
707 const_iv (GIRDLE)
708 const_iv (FORCE)
709 const_iv (POTION_EFFECT)
710 const_iv (EVENT_CONNECTOR)
711 const_iv (CLOSE_CON)
712 const_iv (CONTAINER)
713 const_iv (ARMOUR_IMPROVER)
714 const_iv (WEAPON_IMPROVER)
715 const_iv (SKILLSCROLL)
716 const_iv (DEEP_SWAMP)
717 const_iv (IDENTIFY_ALTAR)
718 const_iv (MENU)
719 const_iv (RUNE)
720 const_iv (TRAP)
721 const_iv (POWER_CRYSTAL)
722 const_iv (CORPSE)
723 const_iv (DISEASE)
724 const_iv (SYMPTOM)
725 const_iv (BUILDER)
726 const_iv (MATERIAL)
727 const_iv (ITEM_TRANSFORMER)
728 const_iv (QUEST)
729
730 const_iv (ST_BD_BUILD)
731 const_iv (ST_BD_REMOVE)
732 const_iv (ST_MAT_FLOOR)
733 const_iv (ST_MAT_WALL)
734 const_iv (ST_MAT_ITEM)
735
736 const_iv (QUEST_IN_PROGRESS)
737 const_iv (QUEST_DONE_QUEST)
738 const_iv (QUEST_DONE_TASK)
739 const_iv (QUEST_START_QUEST)
740 const_iv (QUEST_END_QUEST)
741 const_iv (QUEST_START_TASK)
742 const_iv (QUEST_END_TASK)
743 const_iv (QUEST_OVERRIDE)
744 const_iv (QUEST_ON_ACTIVATE)
745
746 const_iv (WEAP_HIT)
747 const_iv (WEAP_SLASH)
748 const_iv (WEAP_PIERCE)
749 const_iv (WEAP_CLEAVE)
750 const_iv (WEAP_SLICE)
751 const_iv (WEAP_STAB)
752 const_iv (WEAP_WHIP)
753 const_iv (WEAP_CRUSH)
754 const_iv (WEAP_BLUD)
755
756 const_iv (FLAG_ALIVE)
757 const_iv (FLAG_WIZ)
758 const_iv (FLAG_REMOVED)
759 const_iv (FLAG_FREED)
760 const_iv (FLAG_WAS_WIZ)
761 const_iv (FLAG_APPLIED)
762 const_iv (FLAG_UNPAID)
763 const_iv (FLAG_USE_SHIELD)
764 const_iv (FLAG_NO_PICK)
765 const_iv (FLAG_ANIMATE)
766 const_iv (FLAG_MONSTER)
767 const_iv (FLAG_FRIENDLY)
768 const_iv (FLAG_GENERATOR)
769 const_iv (FLAG_IS_THROWN)
770 const_iv (FLAG_AUTO_APPLY)
771 const_iv (FLAG_TREASURE)
772 const_iv (FLAG_PLAYER_SOLD)
773 const_iv (FLAG_SEE_INVISIBLE)
774 const_iv (FLAG_CAN_ROLL)
775 const_iv (FLAG_OVERLAY_FLOOR)
776 const_iv (FLAG_IS_TURNABLE)
777 const_iv (FLAG_IS_USED_UP)
778 const_iv (FLAG_IDENTIFIED)
779 const_iv (FLAG_REFLECTING)
780 const_iv (FLAG_CHANGING)
781 const_iv (FLAG_SPLITTING)
782 const_iv (FLAG_HITBACK)
783 const_iv (FLAG_STARTEQUIP)
784 const_iv (FLAG_BLOCKSVIEW)
785 const_iv (FLAG_UNDEAD)
786 const_iv (FLAG_SCARED)
787 const_iv (FLAG_UNAGGRESSIVE)
788 const_iv (FLAG_REFL_MISSILE)
789 const_iv (FLAG_REFL_SPELL)
790 const_iv (FLAG_NO_MAGIC)
791 const_iv (FLAG_NO_FIX_PLAYER)
792 const_iv (FLAG_IS_LIGHTABLE)
793 const_iv (FLAG_TEAR_DOWN)
794 const_iv (FLAG_RUN_AWAY)
795 const_iv (FLAG_PICK_UP)
796 const_iv (FLAG_UNIQUE)
797 const_iv (FLAG_NO_DROP)
798 const_iv (FLAG_WIZCAST)
799 const_iv (FLAG_CAST_SPELL)
800 const_iv (FLAG_USE_SCROLL)
801 const_iv (FLAG_USE_RANGE)
802 const_iv (FLAG_USE_BOW)
803 const_iv (FLAG_USE_ARMOUR)
804 const_iv (FLAG_USE_WEAPON)
805 const_iv (FLAG_USE_RING)
806 const_iv (FLAG_READY_RANGE)
807 const_iv (FLAG_READY_BOW)
808 const_iv (FLAG_XRAYS)
809 const_iv (FLAG_NO_APPLY)
810 const_iv (FLAG_IS_FLOOR)
811 const_iv (FLAG_LIFESAVE)
812 const_iv (FLAG_NO_STRENGTH)
813 const_iv (FLAG_SLEEP)
814 const_iv (FLAG_STAND_STILL)
815 const_iv (FLAG_RANDOM_MOVE)
816 const_iv (FLAG_ONLY_ATTACK)
817 const_iv (FLAG_CONFUSED)
818 const_iv (FLAG_STEALTH)
819 const_iv (FLAG_WIZPASS)
820 const_iv (FLAG_IS_LINKED)
821 const_iv (FLAG_CURSED)
822 const_iv (FLAG_DAMNED)
823 const_iv (FLAG_SEE_ANYWHERE)
824 const_iv (FLAG_KNOWN_MAGICAL)
825 const_iv (FLAG_KNOWN_CURSED)
826 const_iv (FLAG_CAN_USE_SKILL)
827 const_iv (FLAG_BEEN_APPLIED)
828 const_iv (FLAG_READY_SCROLL)
829 const_iv (FLAG_USE_ROD)
830 const_iv (FLAG_USE_HORN)
831 const_iv (FLAG_MAKE_INVIS)
832 const_iv (FLAG_INV_LOCKED)
833 const_iv (FLAG_IS_WOODED)
834 const_iv (FLAG_IS_HILLY)
835 const_iv (FLAG_READY_SKILL)
836 const_iv (FLAG_READY_WEAPON)
837 const_iv (FLAG_NO_SKILL_IDENT)
838 const_iv (FLAG_BLIND)
839 const_iv (FLAG_SEE_IN_DARK)
840 const_iv (FLAG_IS_CAULDRON)
841 const_iv (FLAG_NO_STEAL)
842 const_iv (FLAG_ONE_HIT)
843 const_iv (FLAG_CLIENT_SENT)
844 const_iv (FLAG_BERSERK)
845 const_iv (FLAG_NEUTRAL)
846 const_iv (FLAG_NO_ATTACK)
847 const_iv (FLAG_NO_DAMAGE)
848 const_iv (FLAG_OBJ_ORIGINAL)
849 const_iv (FLAG_OBJ_SAVE_ON_OVL)
850 const_iv (FLAG_ACTIVATE_ON_PUSH)
851 const_iv (FLAG_ACTIVATE_ON_RELEASE)
852 const_iv (FLAG_IS_WATER)
853 const_iv (FLAG_CONTENT_ON_GEN)
854 const_iv (FLAG_IS_A_TEMPLATE)
855 const_iv (FLAG_IS_BUILDABLE)
856 const_iv (FLAG_AFK)
857
858 const_iv (NDI_BLACK)
859 const_iv (NDI_WHITE)
860 const_iv (NDI_NAVY)
861 const_iv (NDI_RED)
862 const_iv (NDI_ORANGE)
863 const_iv (NDI_BLUE)
864 const_iv (NDI_DK_ORANGE)
865 const_iv (NDI_GREEN)
866 const_iv (NDI_LT_GREEN)
867 const_iv (NDI_GREY)
868 const_iv (NDI_BROWN)
869 const_iv (NDI_GOLD)
870 const_iv (NDI_TAN)
871 const_iv (NDI_MAX_COLOR)
872 const_iv (NDI_COLOR_MASK)
873 const_iv (NDI_UNIQUE)
874 const_iv (NDI_ALL)
875
876 const_iv (F_APPLIED)
877 const_iv (F_LOCATION)
878 const_iv (F_UNPAID)
879 const_iv (F_MAGIC)
880 const_iv (F_CURSED)
881 const_iv (F_DAMNED)
882 const_iv (F_OPEN)
883 const_iv (F_NOPICK)
884 const_iv (F_LOCKED)
885
886 const_iv (P_BLOCKSVIEW)
887 const_iv (P_NO_MAGIC)
888 const_iv (P_IS_ALIVE)
889 const_iv (P_NO_CLERIC)
890 const_iv (P_NEED_UPDATE)
891 const_iv (P_NO_ERROR)
892 const_iv (P_OUT_OF_MAP)
893 const_iv (P_NEW_MAP)
894
895 const_iv (UP_OBJ_INSERT)
896 const_iv (UP_OBJ_REMOVE)
897 const_iv (UP_OBJ_CHANGE)
898 const_iv (UP_OBJ_FACE)
899
900 const_iv (INS_NO_MERGE)
901 const_iv (INS_ABOVE_FLOOR_ONLY)
902 const_iv (INS_NO_WALK_ON)
903 const_iv (INS_ON_TOP)
904 const_iv (INS_BELOW_ORIGINATOR)
905 const_iv (INS_MAP_LOAD)
906
907 const_iv (WILL_APPLY_HANDLE)
908 const_iv (WILL_APPLY_TREASURE)
909 const_iv (WILL_APPLY_EARTHWALL)
910 const_iv (WILL_APPLY_DOOR)
911 const_iv (WILL_APPLY_FOOD)
912 };
913
914 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
915 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
916
917 static const struct {
918 const char *name;
919 IV iv;
920 } *event, event_list[] = {
921 # define const_event(name) { # name, (IV)EVENT_ ## name },
922 const_event (NONE)
923 const_event (APPLY)
924 const_event (ATTACK)
925 const_event (DEATH)
926 const_event (DROP)
927 const_event (PICKUP)
928 const_event (SAY)
929 const_event (STOP)
930 const_event (TIME)
931 const_event (THROW)
932 const_event (TRIGGER)
933 const_event (CLOSE)
934 const_event (TIMER)
935 const_event (MOVE)
936
937 const_event (BORN)
938 const_event (CLOCK)
939 const_event (CRASH)
940 const_event (PLAYER_DEATH)
941 const_event (GKILL)
942 const_event (LOGIN)
943 const_event (LOGOUT)
944 const_event (MAPENTER)
945 const_event (MAPLEAVE)
946 const_event (MAPRESET)
947 const_event (REMOVE)
948 const_event (SHOUT)
949 const_event (TELL)
950 const_event (MUZZLE)
951 const_event (KICK)
952 //const_event (FREE_OB)
953 };
954
955 AV *av = get_av ("cf::EVENT", 1);
956
957 for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; )
958 av_store (av, event->iv, newSVpv ((char *)event->name, 0));
959
960 static const struct {
961 int dtype;
962 const char *name;
963 IV idx;
964 } *cprop, prop_table[] = {
965 # define prop(type, name) { type, # name, (IV) CFAPI_ ## name },
966 prop (CFAPI_INT, MAP_PROP_FLAGS)
967 prop (CFAPI_INT, MAP_PROP_DIFFICULTY)
968 prop (CFAPI_STRING, MAP_PROP_PATH)
969 prop (CFAPI_STRING, MAP_PROP_TMPNAME)
970 prop (CFAPI_STRING, MAP_PROP_NAME)
971 prop (CFAPI_INT, MAP_PROP_RESET_TIME)
972 prop (CFAPI_INT, MAP_PROP_RESET_TIMEOUT)
973 prop (CFAPI_INT, MAP_PROP_PLAYERS)
974 prop (CFAPI_INT, MAP_PROP_DARKNESS)
975 prop (CFAPI_INT, MAP_PROP_WIDTH)
976 prop (CFAPI_INT, MAP_PROP_HEIGHT)
977 prop (CFAPI_INT, MAP_PROP_ENTER_X)
978 prop (CFAPI_INT, MAP_PROP_ENTER_Y)
979 prop (CFAPI_INT, MAP_PROP_TEMPERATURE)
980 prop (CFAPI_INT, MAP_PROP_PRESSURE)
981 prop (CFAPI_INT, MAP_PROP_HUMIDITY)
982 prop (CFAPI_INT, MAP_PROP_WINDSPEED)
983 prop (CFAPI_INT, MAP_PROP_WINDDIR)
984 prop (CFAPI_INT, MAP_PROP_SKY)
985 prop (CFAPI_INT, MAP_PROP_WPARTX)
986 prop (CFAPI_INT, MAP_PROP_WPARTY)
987 prop (CFAPI_STRING, MAP_PROP_MESSAGE)
988 prop (CFAPI_PMAP, MAP_PROP_NEXT)
989 prop (CFAPI_PREGION, MAP_PROP_REGION)
990 prop (CFAPI_POBJECT, OBJECT_PROP_OB_ABOVE)
991 prop (CFAPI_POBJECT, OBJECT_PROP_OB_BELOW)
992 prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB)
993 prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB)
994 prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY)
995 prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT)
996 prop (CFAPI_POBJECT, OBJECT_PROP_HEAD)
997 prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER)
998 prop (CFAPI_PMAP, OBJECT_PROP_MAP)
999 prop (CFAPI_INT, OBJECT_PROP_COUNT)
1000 prop (CFAPI_INT, OBJECT_PROP_REFCOUNT)
1001 prop (CFAPI_STRING, OBJECT_PROP_NAME)
1002 prop (CFAPI_STRING, OBJECT_PROP_NAME_PLURAL)
1003 prop (CFAPI_STRING, OBJECT_PROP_TITLE)
1004 prop (CFAPI_STRING, OBJECT_PROP_RACE)
1005 prop (CFAPI_STRING, OBJECT_PROP_SLAYING)
1006 prop (CFAPI_STRING, OBJECT_PROP_SKILL)
1007 prop (CFAPI_STRING, OBJECT_PROP_MESSAGE)
1008 prop (CFAPI_STRING, OBJECT_PROP_LORE)
1009 prop (CFAPI_INT, OBJECT_PROP_X)
1010 prop (CFAPI_INT, OBJECT_PROP_Y)
1011 prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED)
1012 prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED_LEFT)
1013 prop (CFAPI_INT, OBJECT_PROP_NROF)
1014 prop (CFAPI_INT, OBJECT_PROP_DIRECTION)
1015 prop (CFAPI_INT, OBJECT_PROP_FACING)
1016 prop (CFAPI_INT, OBJECT_PROP_TYPE)
1017 prop (CFAPI_INT, OBJECT_PROP_SUBTYPE)
1018 prop (CFAPI_INT, OBJECT_PROP_CLIENT_TYPE)
1019 prop (CFAPI_INT, OBJECT_PROP_ATTACK_TYPE)
1020 prop (CFAPI_INT, OBJECT_PROP_PATH_ATTUNED)
1021 prop (CFAPI_INT, OBJECT_PROP_PATH_REPELLED)
1022 prop (CFAPI_INT, OBJECT_PROP_PATH_DENIED)
1023 prop (CFAPI_INT, OBJECT_PROP_MATERIAL)
1024 prop (CFAPI_STRING, OBJECT_PROP_MATERIAL_NAME)
1025 prop (CFAPI_INT, OBJECT_PROP_MAGIC)
1026 prop (CFAPI_INT, OBJECT_PROP_VALUE)
1027 prop (CFAPI_INT, OBJECT_PROP_LEVEL)
1028 prop (CFAPI_INT, OBJECT_PROP_LAST_HEAL)
1029 prop (CFAPI_INT, OBJECT_PROP_LAST_SP)
1030 prop (CFAPI_INT, OBJECT_PROP_LAST_GRACE)
1031 prop (CFAPI_INT, OBJECT_PROP_LAST_EAT)
1032 prop (CFAPI_INT, OBJECT_PROP_INVISIBLE_TIME)
1033 prop (CFAPI_INT, OBJECT_PROP_PICK_UP)
1034 prop (CFAPI_INT, OBJECT_PROP_ITEM_POWER)
1035 prop (CFAPI_INT, OBJECT_PROP_GEN_SP_ARMOUR)
1036 prop (CFAPI_INT, OBJECT_PROP_WEIGHT)
1037 prop (CFAPI_INT, OBJECT_PROP_WEIGHT_LIMIT)
1038 prop (CFAPI_INT, OBJECT_PROP_CARRYING)
1039 prop (CFAPI_INT, OBJECT_PROP_GLOW_RADIUS)
1040 prop (CFAPI_LONG, OBJECT_PROP_PERM_EXP)
1041 prop (CFAPI_POBJECT, OBJECT_PROP_CURRENT_WEAPON)
1042 prop (CFAPI_POBJECT, OBJECT_PROP_ENEMY)
1043 prop (CFAPI_POBJECT, OBJECT_PROP_ATTACKED_BY)
1044 prop (CFAPI_INT, OBJECT_PROP_RUN_AWAY)
1045 prop (CFAPI_POBJECT, OBJECT_PROP_CHOSEN_SKILL)
1046 prop (CFAPI_INT, OBJECT_PROP_HIDDEN)
1047 prop (CFAPI_INT, OBJECT_PROP_MOVE_STATUS)
1048 prop (CFAPI_INT, OBJECT_PROP_MOVE_TYPE)
1049 prop (CFAPI_POBJECT, OBJECT_PROP_SPELL_ITEM)
1050 prop (CFAPI_DOUBLE, OBJECT_PROP_EXP_MULTIPLIER)
1051 prop (CFAPI_PARCH, OBJECT_PROP_ARCHETYPE)
1052 prop (CFAPI_PARCH, OBJECT_PROP_OTHER_ARCH)
1053 prop (CFAPI_STRING, OBJECT_PROP_CUSTOM_NAME)
1054 prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED)
1055 prop (CFAPI_INT, OBJECT_PROP_FRIENDLY)
1056 prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME)
1057 prop (CFAPI_INT, OBJECT_PROP_MAGICAL)
1058 prop (CFAPI_INT, OBJECT_PROP_LUCK)
1059 prop (CFAPI_LONG, OBJECT_PROP_EXP)
1060 prop (CFAPI_POBJECT, OBJECT_PROP_OWNER)
1061 prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT)
1062 prop (CFAPI_INT, OBJECT_PROP_CHEATER)
1063 prop (CFAPI_INT, OBJECT_PROP_MERGEABLE)
1064 prop (CFAPI_INT, OBJECT_PROP_PICKABLE)
1065 prop (CFAPI_INT, OBJECT_PROP_STR)
1066 prop (CFAPI_INT, OBJECT_PROP_DEX)
1067 prop (CFAPI_INT, OBJECT_PROP_CON)
1068 prop (CFAPI_INT, OBJECT_PROP_WIS)
1069 prop (CFAPI_INT, OBJECT_PROP_INT)
1070 prop (CFAPI_INT, OBJECT_PROP_POW)
1071 prop (CFAPI_INT, OBJECT_PROP_CHA)
1072 prop (CFAPI_INT, OBJECT_PROP_WC)
1073 prop (CFAPI_INT, OBJECT_PROP_AC)
1074 prop (CFAPI_INT, OBJECT_PROP_HP)
1075 prop (CFAPI_INT, OBJECT_PROP_SP)
1076 prop (CFAPI_INT, OBJECT_PROP_GP)
1077 prop (CFAPI_INT, OBJECT_PROP_FP)
1078 prop (CFAPI_INT, OBJECT_PROP_MAXHP)
1079 prop (CFAPI_INT, OBJECT_PROP_MAXSP)
1080 prop (CFAPI_INT, OBJECT_PROP_MAXGP)
1081 prop (CFAPI_INT, OBJECT_PROP_DAM)
1082 prop (CFAPI_STRING, OBJECT_PROP_GOD)
1083 prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME)
1084 prop (CFAPI_INT, OBJECT_PROP_INVISIBLE)
1085 prop (CFAPI_INT, OBJECT_PROP_FACE)
1086 };
1087
1088 HV *prop_type = get_hv ("cf::PROP_TYPE", 1);
1089 HV *prop_idx = get_hv ("cf::PROP_IDX", 1);
1090
1091 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1092 {
1093 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1094 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1095 }
1096 }
1097
1098 void
1099 LOG (int level, char *msg)
1100 PROTOTYPE: $$
1101 C_ARGS: level, "%s", msg
1102
1103 char *
1104 cf_get_maps_directory (char *path)
1105 PROTOTYPE: $
1106 ALIAS: maps_directory = 0
1107
1108 char *
1109 mapdir ()
1110 PROTOTYPE:
1111 ALIAS:
1112 mapdir = 0
1113 uniquedir = 1
1114 tmpdir = 2
1115 confdir = 3
1116 localdir = 4
1117 playerdir = 5
1118 datadir = 6
1119 CODE:
1120 {
1121 int unused_type;
1122 RETVAL = (char *)systemDirectory (&unused_type, ix);
1123 }
1124 OUTPUT: RETVAL
1125
1126 int
1127 cf_find_animation (char *text)
1128 PROTOTYPE: $
1129
1130 MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1131
1132 SV *
1133 get_property (object *obj, int type, int idx)
1134 CODE:
1135 RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx));
1136 OUTPUT: RETVAL
1137
1138 SV *
1139 set_property (object *obj, int type, int idx, SV *newval)
1140 CODE:
1141 switch (type)
1142 {
1143 case CFAPI_INT:
1144 cf_object_set_int_property (obj, idx, SvIV (newval));
1145 break;
1146 case CFAPI_LONG:
1147 cf_object_set_long_property (obj, idx, SvNV (newval));
1148 break;
1149 case CFAPI_DOUBLE:
1150 {
1151 int unused_type;
1152 object_set_property (&unused_type, obj, idx, (double)SvNV (newval));
1153 }
1154 break;
1155 case CFAPI_STRING:
1156 cf_object_set_string_property (obj, idx, SvPV_nolen (newval));
1157 break;
1158 default:
1159 croak ("unhandled type '%d' in set_property '%d'", type, idx);
1160 }
1161
1162 void
1163 inv (object *obj)
1164 PROTOTYPE: $
1165 PPCODE:
1166 {
1167 object *o;
1168 for (o = obj->inv; o; o = o->below)
1169 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1170 }
1171
1172 int cf_object_get_resistance (object *op, int rtype)
1173 ALIAS: resistance = 0
1174
1175 int cf_object_get_flag (object *op, int flag)
1176 ALIAS: flag = 0
1177
1178 void cf_object_set_flag (object *op, int flag, int value)
1179
1180 void cf_object_move (object *op, int dir, object *originator)
1181
1182 void cf_object_apply (object *op, object *author, int flags = 0)
1183
1184 void cf_object_apply_below (object *op)
1185
1186 void cf_object_remove (object *op)
1187
1188 void cf_object_free (object *op)
1189
1190 object *cf_object_present_archname_inside (object *op, char *whatstr)
1191
1192 int cf_object_transfer (object *op, int x, int y, int r, object *orig)
1193
1194 int cf_object_change_map (object *op, int x, int y, mapstruct *map)
1195
1196 object *cf_object_clone (object *op, int clonetype)
1197
1198 int cf_object_pay_item (object *op, object *buyer)
1199
1200 int cf_object_pay_amount (object *op, double amount)
1201
1202 int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *sp_, char *flags)
1203
1204 int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *flags)
1205
1206 void cf_object_learn_spell (object *op, object *sp)
1207
1208 void cf_object_forget_spell (object *op, object *sp)
1209
1210 object *cf_object_check_for_spell (object *op, char *spellname)
1211
1212 int cf_object_query_money (object *op)
1213 ALIAS: money = 0
1214
1215 int cf_object_query_cost (object *op, object *who, int flags)
1216 ALIAS: cost = 0
1217
1218 void cf_object_activate_rune (object *op , object *victim)
1219
1220 int cf_object_check_trigger (object *op, object *cause)
1221
1222 int cf_object_out_of_map (object *op, int x, int y)
1223
1224 void cf_object_drop (object *op, object *author)
1225
1226 void cf_object_take (object *op, object *author)
1227
1228 void cf_object_say (object *op, char *msg)
1229
1230 void cf_object_speak (object *op, char *msg)
1231
1232 object *cf_object_insert_object (object *op, object *container)
1233
1234 const char *cf_object_get_msg (object *ob)
1235 ALIAS: msg = 0
1236
1237 object *cf_object_insert_in_ob (object *ob, object *where)
1238
1239 int cf_object_teleport (object *op, mapstruct *map, int x, int y)
1240
1241 void cf_object_update (object *op, int flags)
1242
1243 void cf_object_pickup (object *op, object *what)
1244
1245 char *cf_object_get_key (object *op, char *keyname)
1246 ALIAS: key = 0
1247
1248 void cf_object_set_key (object *op, char *keyname, char *value)
1249
1250 char *
1251 base_name (object *ob, int plural)
1252 CODE:
1253 RETVAL = cf_query_base_name (ob, plural);
1254 OUTPUT: RETVAL
1255
1256 MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1257
1258 object *cf_create_object_by_name (const char *name = 0)
1259 PROTOTYPE: ;$
1260 ALIAS:
1261 create_object = 0
1262 new = 0
1263 CODE:
1264 RETVAL = name ? cf_create_object_by_name (name) : cf_create_object ();
1265 OUTPUT:
1266 RETVAL
1267
1268 void cf_fix_object (object *pl)
1269 ALIAS: fix = 0
1270
1271 object *cf_insert_ob_in_ob (object *ob, object *where)
1272
1273 object *get_nearest_player (object *ob)
1274 ALIAS: nearest_player = 0
1275
1276 void rangevector (object *ob, object *other, int flags = 0)
1277 PROTOTYPE: $$;$
1278 PPCODE:
1279 {
1280 rv_vector rv;
1281 get_rangevector (ob, other, &rv, flags);
1282 EXTEND (SP, 5);
1283 PUSHs (newSVuv (rv.distance));
1284 PUSHs (newSViv (rv.distance_x));
1285 PUSHs (newSViv (rv.distance_y));
1286 PUSHs (newSViv (rv.direction));
1287 PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part));
1288 }
1289
1290 bool on_same_map_as (object *ob, object *other)
1291 CODE:
1292 RETVAL = on_same_map (ob, other);
1293 OUTPUT: RETVAL
1294
1295
1296 MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1297
1298 player *player (object *op)
1299 CODE:
1300 RETVAL = cf_player_find (cf_query_name (op));
1301 OUTPUT: RETVAL
1302
1303 void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1304
1305 object *cf_player_send_inventory (object *op)
1306
1307 char *cf_player_get_ip (object *op)
1308 ALIAS: ip = 0
1309
1310 object *cf_player_get_marked_item (object *op)
1311 ALIAS: marked_item = 0
1312
1313 void cf_player_set_marked_item (object *op, object *ob)
1314
1315 partylist *cf_player_get_party (object *op)
1316 ALIAS: party = 0
1317
1318 void cf_player_set_party (object *op, partylist *party)
1319
1320
1321 MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1322
1323 MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1324
1325 player *cf_player_find (char *name)
1326 PROTOTYPE: $
1327
1328 void cf_player_move (player *pl, int dir)
1329
1330 # nonstandard
1331 object *ob (player *pl)
1332 CODE:
1333 RETVAL = pl->ob;
1334 OUTPUT: RETVAL
1335
1336 player *first ()
1337 CODE:
1338 RETVAL = first_player;
1339 OUTPUT: RETVAL
1340
1341 player *next (player *pl)
1342 CODE:
1343 RETVAL = pl->next;
1344 OUTPUT: RETVAL
1345
1346 void
1347 list ()
1348 PPCODE:
1349 {
1350 player *pl;
1351 for (pl = first_player; pl; pl = pl->next)
1352 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1353 }
1354
1355
1356 MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
1357
1358 SV *
1359 get_property (mapstruct *obj, int type, int idx)
1360 CODE:
1361 RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx));
1362 OUTPUT: RETVAL
1363
1364 SV *
1365 set_property (mapstruct *obj, int type, int idx, SV *newval)
1366 CODE:
1367 switch (type)
1368 {
1369 case CFAPI_INT:
1370 cf_map_set_int_property (obj, idx, SvIV (newval));
1371 break;
1372 default:
1373 croak ("unhandled type '%d' in set_property '%d'", type, idx);
1374 }
1375
1376 mapstruct *new (int width, int height)
1377 PROTOTYPE:
1378 CODE:
1379 {
1380 int unused_type;
1381 RETVAL = map_get_map (&unused_type, 0, width, height);
1382 }
1383 OUTPUT:
1384 RETVAL
1385
1386 mapstruct *cf_map_get_map (char *name)
1387 PROTOTYPE: $
1388 ALIAS: map = 0
1389
1390 mapstruct *cf_map_get_first ()
1391 PROTOTYPE:
1392 ALIAS: first = 0
1393
1394 object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags)
1395
1396 object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1397
1398 object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1399 C_ARGS: str, map, nx, ny
1400
1401 #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1402
1403 void
1404 at (mapstruct *obj, unsigned int x, unsigned int y)
1405 PROTOTYPE: $$$
1406 INIT:
1407 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1408 PPCODE:
1409 {
1410 object *o;
1411 for (o = GET_MAP_OB (obj, x, y); o; o = o->above)
1412 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1413 }
1414
1415 SV *
1416 bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1417 PROTOTYPE: $$$
1418 ALIAS:
1419 top_at = 1
1420 flags_at = 2
1421 light_at = 3
1422 move_block_at = 4
1423 move_slow_at = 5
1424 move_on_at = 6
1425 move_off_at = 7
1426 INIT:
1427 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF;
1428 CODE:
1429 switch (ix)
1430 {
1431 case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break;
1432 case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break;
1433 case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break;
1434 case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break;
1435 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break;
1436 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break;
1437 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break;
1438 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
1439 }
1440 OUTPUT:
1441 RETVAL
1442
1443
1444 MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_
1445
1446 archetype *cf_archetype_get_first()
1447 PROTOTYPE:
1448 ALIAS: first = 0
1449
1450 archetype *cf_archetype_get_next (archetype *arch)
1451 ALIAS: next = 0
1452
1453 archetype *cf_archetype_get_head (archetype *arch)
1454 ALIAS: head = 0
1455
1456 archetype *cf_archetype_get_more (archetype *arch)
1457 ALIAS: more = 0
1458
1459 const char *cf_archetype_get_name (archetype *arch)
1460 ALIAS: name = 0
1461
1462 MODULE = cf PACKAGE = cf::party PREFIX = cf_party_
1463
1464 partylist *cf_party_get_first ()
1465 PROTOTYPE:
1466 ALIAS: first = 0
1467
1468 partylist *cf_party_get_next (partylist *party)
1469 ALIAS: next = 0
1470
1471 const char *cf_party_get_name (partylist *party)
1472
1473 const char *cf_party_get_password (partylist *party)
1474 ALIAS: password = 0
1475
1476 player *cf_party_get_first_player (partylist *party)
1477 ALIAS: first_player = 0
1478
1479 player *cf_party_get_next_player (partylist *party, player *op)
1480 ALIAS: next_player = 0
1481
1482
1483 MODULE = cf PACKAGE = cf::region PREFIX = cf_region_
1484
1485 region *cf_region_get_first ()
1486 PROTOTYPE:
1487 ALIAS: first = 0
1488
1489 const char *cf_region_get_name (region *reg)
1490 ALIAS: name = 0
1491
1492 region *cf_region_get_next (region *reg)
1493 ALIAS: next = 0
1494
1495 region *cf_region_get_parent (region *reg)
1496 ALIAS: parent = 0
1497
1498 const char *cf_region_get_longname (region *reg)
1499 ALIAS: longname = 0
1500
1501 const char *cf_region_get_message (region *reg)
1502 ALIAS: message = 0
1503
1504