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