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