ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/plugins/cfperl/cfperl.xs
Revision: 1.28
Committed: Mon Mar 6 22:59:26 2006 UTC (18 years, 3 months ago) by root
Branch: MAIN
Changes since 1.27: +65 -5 lines
Log Message:
*** empty log message ***

File Contents

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