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