ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/plugins/cfperl/cfperl.xs
(Generate patch)

Comparing deliantra/server/plugins/cfperl/cfperl.xs (file contents):
Revision 1.22 by root, Fri Feb 10 07:37:13 2006 UTC vs.
Revision 1.56 by root, Tue Jul 11 14:24:16 2006 UTC

1/*****************************************************************************/ 1/*****************************************************************************/
2/* CrossFire, A Multiplayer game for the X Window System */ 2/* CrossFire, A Multiplayer game for the X Window System */
3/* */
4/*****************************************************************************/ 3/*****************************************************************************/
5 4
6/* 5/*
7 * This code is placed under the GNU General Public Licence (GPL) 6 * This code is placed under the GNU General Public Licence (GPL)
8 * 7 *
29#include <XSUB.h> 28#include <XSUB.h>
30 29
31#undef save_long // clashes with libproto.h 30#undef save_long // clashes with libproto.h
32 31
33#define PLUGIN_NAME "perl" 32#define PLUGIN_NAME "perl"
34#define PLUGIN_VERSION "cfperl 0.1" 33#define PLUGIN_VERSION "cfperl 0.3"
35 34
36#ifndef __CEXTRACT__ 35#ifndef __CEXTRACT__
37#include <plugin.h> 36#include <plugin.h>
38#endif 37#endif
39 38
42#else 41#else
43#define MODULEAPI 42#define MODULEAPI
44#endif 43#endif
45 44
46#include <plugin_common.h> 45#include <plugin_common.h>
46#include <sounds.h>
47 47
48#include <stdarg.h> 48#include <stdarg.h>
49 49
50//#include "EventAPI.h"
50#include "perlxsi.c" 51#include "perlxsi.c"
51 52
52typedef object object_ornull; 53typedef object object_ornull;
53typedef mapstruct mapstruct_ornull; 54typedef mapstruct mapstruct_ornull;
54 55
58static f_plug_api systemDirectory; 59static f_plug_api systemDirectory;
59static f_plug_api object_set_property; 60static f_plug_api object_set_property;
60static f_plug_api map_get_map; 61static f_plug_api map_get_map;
61static f_plug_api object_insert; 62static f_plug_api object_insert;
62 63
64/* this is a stupid way to do things, and awkward to use for plug-in authors */
63typedef struct 65typedef struct
64{ 66{
65 object* who; 67 object* who;
66 object* activator; 68 object* activator;
67 object* third; 69 object* third;
70 object* event;
71 mapstruct* map;
68 char message[1024]; 72 char message[1024];
69 int fix; 73 int fix; // seems to be python-only, and should not be part of the API
70 int event_code; 74 int event_code;
71 char extension[1024]; // name field, should invoke specific perl extension 75 char extension[1024]; // name field, should invoke specific perl extension
72 char options[1024]; // slaying field of event_connectors 76 char options[1024]; // slaying field of event_connectors
73 int returnvalue; 77 int returnvalue;
74} CFPContext; 78} CFPContext;
75 79
76//static int current_command = -999;
77
78static HV *obj_cache; 80static HV *obj_cache;
79static PerlInterpreter *perl; 81static PerlInterpreter *perl;
82
83#define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value))))
84#define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype))
85#define PUSH_OB PUSHcfapi_va(POBJECT, object *)
86#define PUSH_PL PUSHcfapi_va(PPLAYER, player *)
87#define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *)
88#define PUSH_PV PUSHcfapi_va(STRING, const char *)
89#define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int))))
80 90
81////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 91//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 92
83// garbage collect some perl objects, if possible 93// garbage collect some perl objects, if possible
84// all objects no longer referenced and empty are 94// all objects no longer referenced and empty are
126 sv = newSV (0); 136 sv = newSV (0);
127 sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 137 sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
128 return sv_bless (newRV_noinc (sv), gv_stashpv (klass, 1)); 138 return sv_bless (newRV_noinc (sv), gv_stashpv (klass, 1));
129} 139}
130 140
141static void
142SVptr_cache_set (void *ptr, SV *sv)
143{
144 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0);
145}
146
147static SV *
148SVptr_cache_get (void *ptr)
149{
150 SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0);
151
152 return he ? *he : 0;
153}
154
131static SV * 155static SV *
132newSVptr_cached (void *ptr, const char *klass) 156newSVptr_cached (void *ptr, const char *klass)
133{ 157{
134 SV *sv, **he; 158 SV *sv;
135 159
136 if (!ptr) 160 if (!ptr)
137 return &PL_sv_undef; 161 return &PL_sv_undef;
138 162
139 he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); 163 sv = SVptr_cache_get (ptr);
140 164
141 if (he) 165 if (!sv)
142 sv = *he;
143 else
144 { 166 {
145 HV *hv = newHV (); 167 HV *hv = newHV ();
146 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 168 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
147 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 169 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
148 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); 170
171 SVptr_cache_set (ptr, sv);
149 } 172 }
150 173
151 return newSVsv (sv); 174 return newSVsv (sv);
152} 175}
153 176
192 va_list args; 215 va_list args;
193 va_start (args, type); 216 va_start (args, type);
194 217
195 switch (type) 218 switch (type)
196 { 219 {
220#if 0
221 case CFAPI_INT16:
222 sv = newSViv (*va_arg (args, sint16_t *));
223 break;
224#endif
225
197 case CFAPI_INT: 226 case CFAPI_INT:
198 sv = newSViv (*va_arg (args, int *)); 227 sv = newSViv (*va_arg (args, int *));
199 break; 228 break;
200 229
201 case CFAPI_LONG: 230 case CFAPI_LONG:
202 sv = newSViv (*va_arg (args, long *)); 231 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
203 break; 232 break;
204 233
205 case CFAPI_DOUBLE: 234 case CFAPI_DOUBLE:
206 sv = newSViv (*va_arg (args, double *)); 235 sv = newSVnv (*va_arg (args, double *));
207 break; 236 break;
208 237
209 case CFAPI_STRING: 238 case CFAPI_STRING:
210 { 239 {
211 char *str = va_arg (args, char *); 240 char *str = va_arg (args, char *);
218 object *obj = va_arg (args, object *); 247 object *obj = va_arg (args, object *);
219 248
220 if (!obj) 249 if (!obj)
221 sv = &PL_sv_undef; 250 sv = &PL_sv_undef;
222 else 251 else
223 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 252 switch (obj->type)
224 { 253 {
225 case MAP: 254 case MAP:
226 sv = newSVptr_cached (obj, "cf::object::map"); 255 sv = newSVptr_cached (obj, "cf::object::map");
227 break; 256 break;
228 257
264 va_end (args); 293 va_end (args);
265 294
266 return sv; 295 return sv;
267} 296}
268 297
269/////////////////////////////////////////////////////////////////////////////
270
271void
272inject_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///////////////////////////////////////////////////////////////////////////// 298/////////////////////////////////////////////////////////////////////////////
309 299
310int 300int
311initPlugin (const char *iversion, f_plug_api gethooksptr) 301initPlugin (const char *iversion, f_plug_api gethooksptr)
312{ 302{
426 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); 416 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener);
427 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); 417 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener);
428 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); 418 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener);
429 registerGlobalEvent (NULL, EVENT_MAPLEAVE, PLUGIN_NAME, globalEventListener); 419 registerGlobalEvent (NULL, EVENT_MAPLEAVE, PLUGIN_NAME, globalEventListener);
430 registerGlobalEvent (NULL, EVENT_MAPRESET, PLUGIN_NAME, globalEventListener); 420 registerGlobalEvent (NULL, EVENT_MAPRESET, PLUGIN_NAME, globalEventListener);
421 registerGlobalEvent (NULL, EVENT_MAPLOAD, PLUGIN_NAME, globalEventListener);
422 registerGlobalEvent (NULL, EVENT_MAPOUT, PLUGIN_NAME, globalEventListener);
423 registerGlobalEvent (NULL, EVENT_MAPIN, PLUGIN_NAME, globalEventListener);
424 registerGlobalEvent (NULL, EVENT_MAPCLEAN, PLUGIN_NAME, globalEventListener);
431 registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener); 425 registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener);
432 registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); 426 registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener);
433 registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); 427 registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener);
434 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
435 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
436 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 430 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
431 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
432 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
433 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
437 434
438 char *argv[] = { 435 char *argv[] = {
439 "", 436 "",
440 "-e" 437 "-e"
441 "BEGIN {" 438 "BEGIN {"
447 }; 444 };
448 445
449 perl = perl_alloc (); 446 perl = perl_alloc ();
450 perl_construct (perl); 447 perl_construct (perl);
451 448
449 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
450
452 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 451 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
453 { 452 {
454 printf ("unable to initialize perl-interpreter, continuing without.\n"); 453 printf ("unable to initialize perl-interpreter, continuing without.\n");
455 454
456 perl_destruct (perl); 455 perl_destruct (perl);
467 466
468void * 467void *
469globalEventListener (int *type, ...) 468globalEventListener (int *type, ...)
470{ 469{
471 va_list args; 470 va_list args;
472 static int rv = 0; 471 static int rv;
473 CFPContext context; 472 int event_code;
474 char *buf;
475 player *pl;
476 object *op;
477 473
478 if (!perl) 474 if (!perl)
479 return; 475 return;
480 476
481 memset (&context, 0, sizeof (context));
482
483 va_start (args, type); 477 va_start (args, type);
484 context.event_code = va_arg (args, int); 478 event_code = va_arg (args, int);
485 479
486 switch (context.event_code) 480 if (event_code == EVENT_FREE_OB)
487 { 481 {
488 case EVENT_CRASH: 482 player *pl;
489 printf ("Unimplemented for now\n"); 483 object *op;
490 break; 484 SV *sv;
491 485
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 *); 486 op = 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); 487 sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0);
546 488
547 if (sv) 489 if (sv)
548 clearSVptr (sv); 490 clearSVptr (sv);
491
492 rv = 0;
493 }
494 else if (event_code == EVENT_CLOCK)
495 {
496 dSP;
497
498 clean_obj_cache ();
499
500 ENTER;
501 SAVETMPS;
502 PUSHMARK (SP);
503 XPUSHs (sv_2mortal (newSViv (0)));
504 PUTBACK;
505 call_pv ("Event::one_event", G_DISCARD | G_EVAL);
506 SPAGAIN;
507 FREETMPS;
508 LEAVE;
549 } 509 }
550 else 510 else
551 inject_event ("cf::inject_global_event", &context); 511 {
552 512 dSP;
553 rv = context.returnvalue; 513
514 ENTER;
515 SAVETMPS;
516
517 PUSHMARK (SP);
518
519 EXTEND (SP, 10);
520 PUSHs (sv_2mortal (newSViv (event_code)));
521
522 switch (event_code)
523 {
524 case EVENT_CRASH:
525 break;
526
527 case EVENT_PLAYER_LOAD:
528 case EVENT_PLAYER_SAVE:
529 PUSH_OB;
530 PUSH_PV;
531 break;
532
533 case EVENT_MAPLOAD:
534 case EVENT_MAPOUT:
535 case EVENT_MAPIN:
536 case EVENT_MAPCLEAN:
537 case EVENT_MAPRESET:
538 PUSH_MAP;
539 break;
540
541 case EVENT_MAPENTER:
542 case EVENT_MAPLEAVE:
543 case EVENT_BORN:
544 case EVENT_REMOVE:
545 case EVENT_PLAYER_DEATH:
546 PUSH_OB;
547 break;
548
549 case EVENT_GKILL:
550 PUSH_OB;
551 PUSH_OB;
552 break;
553
554 case EVENT_LOGIN:
555 case EVENT_LOGOUT:
556 PUSH_PL;
557 PUSH_PV;
558 break;
559
560 case EVENT_SHOUT:
561 case EVENT_MUZZLE:
562 case EVENT_KICK:
563 PUSH_OB;
564 PUSH_PV;
565 break;
566
567 case EVENT_EXTCMD:
568 PUSH_PL;
569 {
570 char *buf = va_arg (args, char *);
571 int len = va_arg (args, int);
572 PUSHs (sv_2mortal (newSVpvn (buf, len)));
573 }
574 break;
575
576 case EVENT_TELL:
577 break;
578 }
579
580 va_end (args);
581
582 PUTBACK;
583 int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL);
584 SPAGAIN;
585
586 if (SvTRUE (ERRSV))
587 LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
588
589 rv = count > 0 ? POPi : 0;
590
591 PUTBACK;
592 FREETMPS;
593 LEAVE;
594 }
554 595
555 return &rv; 596 return &rv;
556} 597}
557 598
558void * 599void *
559eventListener (int *type, ...) 600eventListener (int *type, ...)
560{ 601{
561 static int rv = 0; 602 static int rv;
562 va_list args; 603 va_list args;
563 char *buf; 604 int event_code;
564 CFPContext context; 605 object *who, *activator, *third, *event;
606 char *message, *extension, *options;
565 607
566 if (!perl) 608 if (!perl)
567 return; 609 return;
568 610
569 memset (&context, 0, sizeof (context));
570
571 va_start (args, type); 611 va_start (args, type);
572
573 context.who = va_arg (args, object *); 612 who = va_arg (args, object *);
574 context.event_code = va_arg (args, int); 613 event_code = va_arg (args, int);
575 context.activator = va_arg (args, object *); 614 activator = va_arg (args, object *);
576 context.third = va_arg (args, object *); 615 third = va_arg (args, object *);
577
578 buf = va_arg (args, char *); 616 message = va_arg (args, char *);
579 if (buf != 0) 617 va_arg (args, int); // fix yourself
580 strncpy (context.message, buf, sizeof (context.message)); 618 extension = va_arg (args, char *);
581 619 options = va_arg (args, char *);
582 context.fix = va_arg (args, int); 620 event = va_arg (args, object *);
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); 621 va_end (args);
587 622
588 inject_event ("cf::inject_event", &context); 623 {
624 dSP;
625
626 ENTER;
627 SAVETMPS;
628
629 PUSHMARK (SP);
630 EXTEND (SP, 10);
631
632 PUSHcfapi (STRING, extension);
633 PUSHs (sv_2mortal (newSViv (event_code)));
634
635 PUSHcfapi (POBJECT, event);
636 PUSHcfapi (POBJECT, who);
637
638 switch (event_code)
639 {
640 case EVENT_STOP: // $ob (e.g. arrow)
641 case EVENT_TIME: // $ob
642 case EVENT_TIMER: // $ob
643 break;
644
645 case EVENT_APPLY: // $ob, $who
646 case EVENT_DROP: // $ob, $who
647 case EVENT_CLOSE: // $ob, $who
648 case EVENT_DEATH: // $ob[, $killer]
649 case EVENT_MOVE: // $ob, $enemy
650 case EVENT_THROW: // $ob, $thrower
651 PUSHcfapi (POBJECT, activator);
652 break;
653
654 case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me)
655 PUSHcfapi (POBJECT, activator);
656 PUSHcfapi (POBJECT, third);
657 break;
658
659 case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg]
660 PUSHcfapi (POBJECT, activator);
661 PUSHcfapi (POBJECT, third);
662 PUSHcfapi (POBJECT, message);
663 break;
664
665 case EVENT_SAY: // $ob, $who, $msg
666 PUSHcfapi (POBJECT, activator);
667 PUSHcfapi (STRING, message);
668 break;
669
670 default:
671 LOG (llevError, "perl plugin called for unsupported event type %d", event_code);
672 break;
673 }
674
675 PUTBACK;
676 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
677 SPAGAIN;
678
679 if (SvTRUE (ERRSV))
680 LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV));
681
682 rv = count > 0 ? POPi : 0;
683
684 PUTBACK;
685 FREETMPS;
686 LEAVE;
687 }
589 688
590 rv = context.returnvalue;
591 return &rv; 689 return &rv;
592} 690}
593 691
594int 692int
595closePlugin () 693closePlugin ()
621 const_iv (llevInfo) 719 const_iv (llevInfo)
622 const_iv (llevDebug) 720 const_iv (llevDebug)
623 const_iv (llevMonster) 721 const_iv (llevMonster)
624 722
625 const_iv (PLAYER) 723 const_iv (PLAYER)
724 const_iv (TRANSPORT)
626 const_iv (ROD) 725 const_iv (ROD)
627 const_iv (TREASURE) 726 const_iv (TREASURE)
628 const_iv (POTION) 727 const_iv (POTION)
629 const_iv (FOOD) 728 const_iv (FOOD)
630 const_iv (POISON) 729 const_iv (POISON)
635 const_iv (BOW) 734 const_iv (BOW)
636 const_iv (WEAPON) 735 const_iv (WEAPON)
637 const_iv (ARMOUR) 736 const_iv (ARMOUR)
638 const_iv (PEDESTAL) 737 const_iv (PEDESTAL)
639 const_iv (ALTAR) 738 const_iv (ALTAR)
640 const_iv (CONFUSION)
641 const_iv (LOCKED_DOOR) 739 const_iv (LOCKED_DOOR)
642 const_iv (SPECIAL_KEY) 740 const_iv (SPECIAL_KEY)
643 const_iv (MAP) 741 const_iv (MAP)
644 const_iv (DOOR) 742 const_iv (DOOR)
645 const_iv (KEY) 743 const_iv (KEY)
746 const_iv (ITEM_TRANSFORMER) 844 const_iv (ITEM_TRANSFORMER)
747 const_iv (QUEST) 845 const_iv (QUEST)
748 846
749 const_iv (ST_BD_BUILD) 847 const_iv (ST_BD_BUILD)
750 const_iv (ST_BD_REMOVE) 848 const_iv (ST_BD_REMOVE)
849
751 const_iv (ST_MAT_FLOOR) 850 const_iv (ST_MAT_FLOOR)
752 const_iv (ST_MAT_WALL) 851 const_iv (ST_MAT_WALL)
753 const_iv (ST_MAT_ITEM) 852 const_iv (ST_MAT_ITEM)
853
854 const_iv (AT_PHYSICAL)
855 const_iv (AT_MAGIC)
856 const_iv (AT_FIRE)
857 const_iv (AT_ELECTRICITY)
858 const_iv (AT_COLD)
859 const_iv (AT_CONFUSION)
860 const_iv (AT_ACID)
861 const_iv (AT_DRAIN)
862 const_iv (AT_WEAPONMAGIC)
863 const_iv (AT_GHOSTHIT)
864 const_iv (AT_POISON)
865 const_iv (AT_SLOW)
866 const_iv (AT_PARALYZE)
867 const_iv (AT_TURN_UNDEAD)
868 const_iv (AT_FEAR)
869 const_iv (AT_CANCELLATION)
870 const_iv (AT_DEPLETE)
871 const_iv (AT_DEATH)
872 const_iv (AT_CHAOS)
873 const_iv (AT_COUNTERSPELL)
874 const_iv (AT_GODPOWER)
875 const_iv (AT_HOLYWORD)
876 const_iv (AT_BLIND)
877 const_iv (AT_INTERNAL)
878 const_iv (AT_LIFE_STEALING)
879 const_iv (AT_DISEASE)
754 880
755 const_iv (QUEST_IN_PROGRESS) 881 const_iv (QUEST_IN_PROGRESS)
756 const_iv (QUEST_DONE_QUEST) 882 const_iv (QUEST_DONE_QUEST)
757 const_iv (QUEST_DONE_TASK) 883 const_iv (QUEST_DONE_TASK)
758 const_iv (QUEST_START_QUEST) 884 const_iv (QUEST_START_QUEST)
926 const_iv (WILL_APPLY_HANDLE) 1052 const_iv (WILL_APPLY_HANDLE)
927 const_iv (WILL_APPLY_TREASURE) 1053 const_iv (WILL_APPLY_TREASURE)
928 const_iv (WILL_APPLY_EARTHWALL) 1054 const_iv (WILL_APPLY_EARTHWALL)
929 const_iv (WILL_APPLY_DOOR) 1055 const_iv (WILL_APPLY_DOOR)
930 const_iv (WILL_APPLY_FOOD) 1056 const_iv (WILL_APPLY_FOOD)
1057
1058 const_iv (SAVE_MODE)
1059 const_iv (SAVE_DIR_MODE)
1060
1061 const_iv (M_PAPER)
1062 const_iv (M_IRON)
1063 const_iv (M_GLASS)
1064 const_iv (M_LEATHER)
1065 const_iv (M_WOOD)
1066 const_iv (M_ORGANIC)
1067 const_iv (M_STONE)
1068 const_iv (M_CLOTH)
1069 const_iv (M_ADAMANT)
1070 const_iv (M_LIQUID)
1071 const_iv (M_SOFT_METAL)
1072 const_iv (M_BONE)
1073 const_iv (M_ICE)
1074 const_iv (M_SPECIAL)
1075
1076 const_iv (SK_EXP_ADD_SKILL)
1077 const_iv (SK_EXP_TOTAL)
1078 const_iv (SK_EXP_NONE)
1079 const_iv (SK_SUBTRACT_SKILL_EXP)
1080
1081 const_iv (SK_LOCKPICKING)
1082 const_iv (SK_HIDING)
1083 const_iv (SK_SMITHERY)
1084 const_iv (SK_BOWYER)
1085 const_iv (SK_JEWELER)
1086 const_iv (SK_ALCHEMY)
1087 const_iv (SK_STEALING)
1088 const_iv (SK_LITERACY)
1089 const_iv (SK_BARGAINING)
1090 const_iv (SK_JUMPING)
1091 const_iv (SK_DET_MAGIC)
1092 const_iv (SK_ORATORY)
1093 const_iv (SK_SINGING)
1094 const_iv (SK_DET_CURSE)
1095 const_iv (SK_FIND_TRAPS)
1096 const_iv (SK_MEDITATION)
1097 const_iv (SK_PUNCHING)
1098 const_iv (SK_FLAME_TOUCH)
1099 const_iv (SK_KARATE)
1100 const_iv (SK_CLIMBING)
1101 const_iv (SK_WOODSMAN)
1102 const_iv (SK_INSCRIPTION)
1103 const_iv (SK_ONE_HANDED_WEAPON)
1104 const_iv (SK_MISSILE_WEAPON)
1105 const_iv (SK_THROWING)
1106 const_iv (SK_USE_MAGIC_ITEM)
1107 const_iv (SK_DISARM_TRAPS)
1108 const_iv (SK_SET_TRAP)
1109 const_iv (SK_THAUMATURGY)
1110 const_iv (SK_PRAYING)
1111 const_iv (SK_CLAWING)
1112 const_iv (SK_LEVITATION)
1113 const_iv (SK_SUMMONING)
1114 const_iv (SK_PYROMANCY)
1115 const_iv (SK_EVOCATION)
1116 const_iv (SK_SORCERY)
1117 const_iv (SK_TWO_HANDED_WEAPON)
1118 const_iv (SK_SPARK_TOUCH)
1119 const_iv (SK_SHIVER)
1120 const_iv (SK_ACID_SPLASH)
1121 const_iv (SK_POISON_NAIL)
1122
1123 const_iv (SOUND_NEW_PLAYER)
1124 const_iv (SOUND_FIRE_ARROW)
1125 const_iv (SOUND_LEARN_SPELL)
1126 const_iv (SOUND_FUMBLE_SPELL)
1127 const_iv (SOUND_WAND_POOF)
1128 const_iv (SOUND_OPEN_DOOR)
1129 const_iv (SOUND_PUSH_PLAYER)
1130 const_iv (SOUND_PLAYER_HITS1)
1131 const_iv (SOUND_PLAYER_HITS2)
1132 const_iv (SOUND_PLAYER_HITS3)
1133 const_iv (SOUND_PLAYER_HITS4)
1134 const_iv (SOUND_PLAYER_IS_HIT1)
1135 const_iv (SOUND_PLAYER_IS_HIT2)
1136 const_iv (SOUND_PLAYER_IS_HIT3)
1137 const_iv (SOUND_PLAYER_KILLS)
1138 const_iv (SOUND_PET_IS_KILLED)
1139 const_iv (SOUND_PLAYER_DIES)
1140 const_iv (SOUND_OB_EVAPORATE)
1141 const_iv (SOUND_OB_EXPLODE)
1142 const_iv (SOUND_CLOCK)
1143 const_iv (SOUND_TURN_HANDLE)
1144 const_iv (SOUND_FALL_HOLE)
1145 const_iv (SOUND_DRINK_POISON)
1146 const_iv (SOUND_CAST_SPELL_0)
1147
1148 const_iv (MAP_FLUSH)
1149 const_iv (MAP_PLAYER_UNIQUE)
1150 const_iv (MAP_BLOCK)
1151 const_iv (MAP_STYLE)
1152 const_iv (MAP_OVERLAY)
1153
1154 const_iv (MAP_IN_MEMORY)
1155 const_iv (MAP_SWAPPED)
1156 const_iv (MAP_LOADING)
1157 const_iv (MAP_SAVING)
931 }; 1158 };
932 1159
933 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1160 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
934 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1161 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
935 1162
952 const_event (CLOSE) 1179 const_event (CLOSE)
953 const_event (TIMER) 1180 const_event (TIMER)
954 const_event (MOVE) 1181 const_event (MOVE)
955 1182
956 const_event (BORN) 1183 const_event (BORN)
957 const_event (CLOCK) 1184 //const_event (CLOCK)
958 const_event (CRASH) 1185 const_event (CRASH)
959 const_event (PLAYER_DEATH) 1186 const_event (PLAYER_DEATH)
1187 const_event (PLAYER_LOAD)
1188 const_event (PLAYER_SAVE)
960 const_event (GKILL) 1189 const_event (GKILL)
961 const_event (LOGIN) 1190 const_event (LOGIN)
962 const_event (LOGOUT) 1191 const_event (LOGOUT)
963 const_event (MAPENTER) 1192 const_event (MAPENTER)
964 const_event (MAPLEAVE) 1193 const_event (MAPLEAVE)
965 const_event (MAPRESET) 1194 const_event (MAPRESET)
1195 const_event (MAPLOAD)
1196 const_event (MAPOUT)
1197 const_event (MAPIN)
1198 const_event (MAPCLEAN)
966 const_event (REMOVE) 1199 const_event (REMOVE)
967 const_event (SHOUT) 1200 const_event (SHOUT)
968 const_event (TELL) 1201 const_event (TELL)
969 const_event (MUZZLE) 1202 const_event (MUZZLE)
970 const_event (KICK) 1203 const_event (KICK)
1204 const_event (EXTCMD)
971 //const_event (FREE_OB) 1205 //const_event (FREE_OB)
972 }; 1206 };
973 1207
974 AV *av = get_av ("cf::EVENT", 1); 1208 AV *av = get_av ("cf::EVENT", 1);
975 1209
1073 prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED) 1307 prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED)
1074 prop (CFAPI_INT, OBJECT_PROP_FRIENDLY) 1308 prop (CFAPI_INT, OBJECT_PROP_FRIENDLY)
1075 prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) 1309 prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME)
1076 prop (CFAPI_INT, OBJECT_PROP_MAGICAL) 1310 prop (CFAPI_INT, OBJECT_PROP_MAGICAL)
1077 prop (CFAPI_INT, OBJECT_PROP_LUCK) 1311 prop (CFAPI_INT, OBJECT_PROP_LUCK)
1078 prop (CFAPI_LONG, OBJECT_PROP_EXP)
1079 prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) 1312 prop (CFAPI_POBJECT, OBJECT_PROP_OWNER)
1080 prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) 1313 prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT)
1081 prop (CFAPI_INT, OBJECT_PROP_CHEATER) 1314 prop (CFAPI_INT, OBJECT_PROP_CHEATER)
1082 prop (CFAPI_INT, OBJECT_PROP_MERGEABLE) 1315 prop (CFAPI_INT, OBJECT_PROP_MERGEABLE)
1083 prop (CFAPI_INT, OBJECT_PROP_PICKABLE) 1316 prop (CFAPI_INT, OBJECT_PROP_PICKABLE)
1110 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1343 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1111 { 1344 {
1112 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1345 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1113 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); 1346 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1114 } 1347 }
1348
1349 //I_EVENT_API (PACKAGE);
1115} 1350}
1116 1351
1117void 1352void
1118LOG (int level, char *msg) 1353LOG (int level, char *msg)
1119 PROTOTYPE: $$ 1354 PROTOTYPE: $$
1120 C_ARGS: level, "%s", msg 1355 C_ARGS: level, "%s", msg
1356
1357char *path_combine (char *base, char *path)
1358 PROTOTYPE: $$
1359
1360char *path_combine_and_normalize (char *base, char *path)
1361 PROTOTYPE: $$
1121 1362
1122char * 1363char *
1123cf_get_maps_directory (char *path) 1364cf_get_maps_directory (char *path)
1124 PROTOTYPE: $ 1365 PROTOTYPE: $
1125 ALIAS: maps_directory = 0 1366 ALIAS: maps_directory = 0
1170 int unused_type; 1411 int unused_type;
1171 object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); 1412 object_set_property (&unused_type, obj, idx, (double)SvNV (newval));
1172 } 1413 }
1173 break; 1414 break;
1174 case CFAPI_STRING: 1415 case CFAPI_STRING:
1175 cf_object_set_string_property (obj, idx, SvPV_nolen (newval)); 1416 cf_object_set_string_property (obj, idx, SvOK (newval) ? SvPV_nolen (newval) : 0);
1417 break;
1418 case CFAPI_POBJECT:
1419 {
1420 int unused_type;
1421 object_set_property (&unused_type, obj, idx, (object *)SvPTR_ornull (newval, "cf::object"));
1422 }
1176 break; 1423 break;
1177 default: 1424 default:
1178 croak ("unhandled type '%d' in set_property '%d'", type, idx); 1425 croak ("unhandled type '%d' in set_property '%d'", type, idx);
1179 } 1426 }
1180 1427
1428# missing properties
1429
1430void
1431set_attacktype (object *obj, U32 attacktype)
1432 CODE:
1433 obj->attacktype = attacktype;
1434
1435U32
1436get_attacktype (object *obj)
1437 ALIAS:
1438 attacktype = 0
1439 CODE:
1440 RETVAL = obj->attacktype;
1441 OUTPUT: RETVAL
1442
1443# missing in plug-in api, of course
1444void
1445set_food (object *obj, int food)
1446 CODE:
1447 obj->stats.food = food;
1448
1449int
1450get_food (object *obj)
1451 ALIAS:
1452 food = 0
1453 CODE:
1454 RETVAL = obj->stats.food;
1455 OUTPUT: RETVAL
1456
1181void 1457void
1182inv (object *obj) 1458inv (object *obj)
1183 PROTOTYPE: $ 1459 PROTOTYPE: $
1184 PPCODE: 1460 PPCODE:
1185{ 1461{
1206 1482
1207void cf_object_free (object *op) 1483void cf_object_free (object *op)
1208 1484
1209object *cf_object_present_archname_inside (object *op, char *whatstr) 1485object *cf_object_present_archname_inside (object *op, char *whatstr)
1210 1486
1211int cf_object_transfer (object *op, int x, int y, int r, object *orig) 1487int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1212 1488
1213int cf_object_change_map (object *op, int x, int y, mapstruct *map) 1489int cf_object_change_map (object *op, int x, int y, mapstruct *map)
1214 1490
1215object *cf_object_clone (object *op, int clonetype = 0) 1491object *cf_object_clone (object *op, int clonetype = 0)
1216 1492
1217int cf_object_pay_item (object *op, object *buyer) 1493int cf_object_pay_item (object *op, object *buyer)
1218 1494
1219int cf_object_pay_amount (object *op, double amount) 1495int cf_object_pay_amount (object *op, double amount)
1220 1496
1221int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *sp_, char *flags) 1497int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0)
1222 1498
1223int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *flags) 1499int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0)
1224 1500
1225void cf_object_learn_spell (object *op, object *sp) 1501void cf_object_learn_spell (object *op, object *sp)
1226 1502
1227void cf_object_forget_spell (object *op, object *sp) 1503void cf_object_forget_spell (object *op, object *sp)
1228 1504
1259 1535
1260void cf_object_update (object *op, int flags) 1536void cf_object_update (object *op, int flags)
1261 1537
1262void cf_object_pickup (object *op, object *what) 1538void cf_object_pickup (object *op, object *what)
1263 1539
1264char *cf_object_get_key (object *op, char *keyname) 1540object *cf_create_object_by_name (const char *name)
1265 ALIAS: key = 0
1266 1541
1267void cf_object_set_key (object *op, char *keyname, char *value) 1542void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0)
1543
1544void player_lvl_adj (object *who, object *skill = 0)
1545
1546int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1268 1547
1269MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1548MODULE = cf PACKAGE = cf::object PREFIX = cf_
1270 1549
1271void cf_fix_object (object *pl) 1550void cf_fix_object (object *pl)
1272 ALIAS: fix = 0 1551 ALIAS: fix = 0
1273 1552
1274object *cf_insert_ob_in_ob (object *ob, object *where) 1553object *cf_insert_ob_in_ob (object *ob, object *where)
1275 1554
1276object *create_object_by_name (const char *name = 0) 1555# no clean way to get an object from an archetype - stupid idiotic
1556# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1557
1558object *new (const char *archetype = 0)
1277 PROTOTYPE: ;$ 1559 PROTOTYPE: ;$
1278 ALIAS:
1279 create_object = 0
1280 new = 0
1281 CODE: 1560 CODE:
1282 RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); 1561 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1283 OUTPUT: 1562 OUTPUT:
1284 RETVAL 1563 RETVAL
1285 1564
1286object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) 1565object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y)
1287 PROTOTYPE: $$$$$$ 1566 PROTOTYPE: $$$$$$
1288 CODE: 1567 CODE:
1289{ 1568{
1290 int unused_type; 1569 int unused_type;
1291 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1570 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1292} 1571}
1572
1573# syntatic sugar for easier use in event callbacks.
1574const char *options (object *op)
1575 CODE:
1576 RETVAL = op->name;
1577 OUTPUT:
1578 RETVAL
1579
1580const char *get_ob_key_value (object *op, const char *key)
1581
1582bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1293 1583
1294object *get_nearest_player (object *ob) 1584object *get_nearest_player (object *ob)
1295 ALIAS: nearest_player = 0 1585 ALIAS: nearest_player = 0
1296 PREINIT: 1586 PREINIT:
1297 extern object *get_nearest_player (object *); 1587 extern object *get_nearest_player (object *);
1319base_name (object *ob, int plural) 1609base_name (object *ob, int plural)
1320 CODE: 1610 CODE:
1321 RETVAL = cf_query_base_name (ob, plural); 1611 RETVAL = cf_query_base_name (ob, plural);
1322 OUTPUT: RETVAL 1612 OUTPUT: RETVAL
1323 1613
1614living *
1615stats (object *ob)
1616 CODE:
1617 RETVAL = &ob->stats;
1618 OUTPUT: RETVAL
1619
1324 1620
1325MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1621MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1326 1622
1327player *player (object *op) 1623player *player (object *op)
1328 CODE: 1624 CODE:
1329 RETVAL = cf_player_find (cf_query_name (op)); 1625 RETVAL = op->contr;
1330 OUTPUT: RETVAL 1626 OUTPUT: RETVAL
1331 1627
1332void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 1628void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1333 1629
1334object *cf_player_send_inventory (object *op) 1630object *cf_player_send_inventory (object *op)
1349partylist *cf_player_get_party (object *op) 1645partylist *cf_player_get_party (object *op)
1350 ALIAS: party = 0 1646 ALIAS: party = 0
1351 1647
1352void cf_player_set_party (object *op, partylist *party) 1648void cf_player_set_party (object *op, partylist *party)
1353 1649
1650void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1651
1652void kill_player (object *op)
1354 1653
1355MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1654MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1356 1655
1357MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1656MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1358 1657
1361 1660
1362void cf_player_move (player *pl, int dir) 1661void cf_player_move (player *pl, int dir)
1363 1662
1364void MapNewmapCmd (player *pl) 1663void MapNewmapCmd (player *pl)
1365 1664
1665void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1666
1366# nonstandard 1667# nonstandard
1367object *ob (player *pl) 1668object *ob (player *pl)
1368 CODE: 1669 CODE:
1369 RETVAL = pl->ob; 1670 RETVAL = pl->ob;
1370 OUTPUT: RETVAL 1671 OUTPUT: RETVAL
1376 1677
1377player *next (player *pl) 1678player *next (player *pl)
1378 CODE: 1679 CODE:
1379 RETVAL = pl->next; 1680 RETVAL = pl->next;
1380 OUTPUT: RETVAL 1681 OUTPUT: RETVAL
1682
1683bool
1684cell_visible (player *pl, int dx, int dy)
1685 CODE:
1686 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1687 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1688 OUTPUT:
1689 RETVAL
1690
1691void
1692send (player *pl, SV *packet)
1693 CODE:
1694{
1695 STRLEN len;
1696 char *buf = SvPVbyte (packet, len);
1697
1698 Write_String_To_Socket (&pl->socket, buf, len);
1699}
1700
1701int
1702listening (player *pl, int new_value = -1)
1703 CODE:
1704 RETVAL = pl->listening;
1705 if (new_value >= 0)
1706 pl->listening = new_value;
1707 OUTPUT:
1708 RETVAL
1709
1710void get_savebed (player *pl)
1711 ALIAS:
1712 savebed = 0
1713 PPCODE:
1714 EXTEND (SP, 3);
1715 PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0)));
1716 PUSHs (sv_2mortal (newSViv (pl->bed_x)));
1717 PUSHs (sv_2mortal (newSViv (pl->bed_y)));
1718
1719void set_savebed (player *pl, char *map_path, int x, int y)
1720 CODE:
1721 strcpy (pl->savebed_map, map_path);
1722 pl->bed_x = x;
1723 pl->bed_y = y;
1381 1724
1382void 1725void
1383list () 1726list ()
1384 PPCODE: 1727 PPCODE:
1385{ 1728{
1386 player *pl; 1729 player *pl;
1387 for (pl = first_player; pl; pl = pl->next) 1730 for (pl = first_player; pl; pl = pl->next)
1388 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 1731 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1389} 1732}
1733
1734bool
1735peaceful (player *pl, bool new_setting = 0)
1736 PROTOTYPE: $;$
1737 CODE:
1738 RETVAL = pl->peaceful;
1739 if (items > 1)
1740 pl->peaceful = new_setting;
1741 OUTPUT:
1742 RETVAL
1743
1744living *
1745orig_stats (player *pl)
1746 CODE:
1747 RETVAL = &pl->orig_stats;
1748 OUTPUT: RETVAL
1749
1750living *
1751last_stats (player *pl)
1752 CODE:
1753 RETVAL = &pl->last_stats;
1754 OUTPUT: RETVAL
1390 1755
1391 1756
1392MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 1757MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
1393 1758
1394SV * 1759SV *
1417 RETVAL = map_get_map (&unused_type, 0, width, height); 1782 RETVAL = map_get_map (&unused_type, 0, width, height);
1418} 1783}
1419 OUTPUT: 1784 OUTPUT:
1420 RETVAL 1785 RETVAL
1421 1786
1787void delete_map (mapstruct *map)
1788
1789void clean_tmp_map (mapstruct *map)
1790
1791void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1792
1793mapstruct *tile_map (mapstruct *map, unsigned int dir)
1794 CODE:
1795 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1796 OUTPUT:
1797 RETVAL
1798
1799char *tile_path (mapstruct *map, unsigned int dir)
1800 CODE:
1801 if (dir >= 4)
1802 XSRETURN_UNDEF;
1803 RETVAL = map->tile_path [dir];
1804 OUTPUT:
1805 RETVAL
1806
1422mapstruct *cf_map_get_map (char *name) 1807mapstruct *cf_map_get_map (char *name)
1423 PROTOTYPE: $ 1808 PROTOTYPE: $
1424 ALIAS: map = 0 1809 ALIAS: map = 0
1425 1810
1811mapstruct *has_been_loaded (char *name)
1812 PROTOTYPE: $
1813
1426mapstruct *cf_map_get_first () 1814mapstruct *cf_map_get_first ()
1427 PROTOTYPE: 1815 PROTOTYPE:
1428 ALIAS: first = 0 1816 ALIAS: first = 0
1429 1817
1818# whoever "designed" the plug-in api should have wasted
1819# his/her time with staying away from the project - would have
1820# saved others a lot of time, without doubt.
1821void set_path (mapstruct *where, char *path)
1822 CODE:
1823 strcpy (where->path, path);
1824
1825int in_memory (mapstruct *map)
1826 CODE:
1827 RETVAL = map->in_memory;
1828 OUTPUT:
1829 RETVAL
1830
1831bool unique (mapstruct *map)
1832 CODE:
1833 RETVAL = map->unique;
1834 OUTPUT:
1835 RETVAL
1836
1837void set_unique (mapstruct *map, bool unique)
1838 CODE:
1839 map->unique = unique;
1840
1430object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) 1841object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags)
1431 1842
1432object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1843object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1433 1844
1434object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1845object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1435 C_ARGS: str, map, nx, ny 1846 C_ARGS: str, map, nx, ny
1436 1847
1437#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1438
1439void 1848void
1849cf_map_normalise (mapstruct *map, int x, int y)
1850 PPCODE:
1851{
1852 mapstruct *nmap = 0;
1853 I16 nx = 0, ny = 0;
1854 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1855
1856 EXTEND (SP, 4);
1857 PUSHs (sv_2mortal (newSViv (flags)));
1858
1859 if (GIMME_V == G_ARRAY)
1860 {
1861 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1862 PUSHs (sv_2mortal (newSViv (nx)));
1863 PUSHs (sv_2mortal (newSViv (ny)));
1864 }
1865}
1866
1867void
1440at (mapstruct *obj, unsigned int x, unsigned int y) 1868at (mapstruct *map, unsigned int x, unsigned int y)
1441 PROTOTYPE: $$$ 1869 PROTOTYPE: $$$
1442 INIT:
1443 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1444 PPCODE: 1870 PPCODE:
1445{ 1871{
1446 object *o; 1872 object *o;
1873 mapstruct *nmap = 0;
1874 I16 nx, ny;
1875
1876 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1877
1878 if (nmap)
1447 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1879 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1448 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1880 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1449} 1881}
1450 1882
1451SV * 1883SV *
1452bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1884bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1453 PROTOTYPE: $$$ 1885 PROTOTYPE: $$$
1474 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 1906 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
1475 } 1907 }
1476 OUTPUT: 1908 OUTPUT:
1477 RETVAL 1909 RETVAL
1478 1910
1911# "serialise" map perl data into a ref
1912void
1913_get_obs (mapstruct *map)
1914 PPCODE:
1915{
1916 object *o;
1917 int x, y;
1918 AV *obs = newAV ();
1919 int nonnull = 0;
1920
1921 for (y = 0; y < MAP_HEIGHT (map); y++)
1922 for (x = 0; x < MAP_WIDTH (map); x++)
1923 {
1924 AV *av = newAV ();
1925
1926 for (o = GET_MAP_OB (map, x, y); o; o = o->above)
1927 {
1928 SV *sv = SVptr_cache_get (o);
1929
1930 if (sv && HvFILL (SvRV (sv)))
1931 {
1932 nonnull = 1;
1933 sv = newSVsv (sv);
1934 }
1935 else
1936 sv = &PL_sv_undef;
1937
1938 av_push (av, sv);
1939 }
1940
1941 av_store (obs, x + y * MAP_HEIGHT (map), newRV_noinc ((SV *)av));
1942 }
1943
1944 if (nonnull)
1945 XPUSHs (sv_2mortal (newRV_noinc ((SV *)obs)));
1946 else
1947 SvREFCNT_dec (obs);
1948}
1949
1950# "deserialise" perl map data into the map
1951void
1952_set_obs (mapstruct *map, SV *sv)
1953 CODE:
1954{
1955 object *o;
1956 AV *av;
1957 int x, y;
1958 AV *obs = (AV *)SvRV (sv);
1959
1960 for (y = 0; y < MAP_HEIGHT (map); y++)
1961 for (x = 0; x < MAP_WIDTH (map); x++)
1962 {
1963 sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1);
1964
1965 if (!SvROK (sv))
1966 continue;
1967
1968 av = (AV *)SvRV (sv);
1969
1970 for (o = GET_MAP_OB (map, x, y); o; o = o->above)
1971 {
1972 sv = av_shift (av);
1973
1974 if (SvROK (sv))
1975 {
1976 sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0);
1977 SVptr_cache_set (o, sv);
1978 }
1979 }
1980 }
1981}
1982
1479 1983
1480MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ 1984MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_
1481 1985
1482archetype *cf_archetype_get_first() 1986archetype *cf_archetype_get_first()
1483 PROTOTYPE: 1987 PROTOTYPE:
1536 2040
1537const char *cf_region_get_message (region *reg) 2041const char *cf_region_get_message (region *reg)
1538 ALIAS: message = 0 2042 ALIAS: message = 0
1539 2043
1540 2044
2045MODULE = cf PACKAGE = cf::living PREFIX = cf_living_
2046
2047double
2048exp (living *liv, double new_val = 0.)
2049 PROTOTYPE: $;$
2050 ALIAS:
2051 Str = 1
2052 Dex = 2
2053 Con = 3
2054 Wis = 4
2055 Cha = 5
2056 Int = 6
2057 Pow = 7
2058 wc = 8
2059 ac = 9
2060 hp = 10
2061 maxhp = 11
2062 sp = 12
2063 maxsp = 13
2064 grace = 14
2065 maxgrace = 15
2066 food = 16
2067 dam = 17
2068 luck = 18
2069 CODE:
2070# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = new_val; break
2071 switch (ix)
2072 {
2073 LIVING_ACC (exp , 0);
2074 LIVING_ACC (Str , 1);
2075 LIVING_ACC (Dex , 2);
2076 LIVING_ACC (Con , 3);
2077 LIVING_ACC (Wis , 4);
2078 LIVING_ACC (Cha , 5);
2079 LIVING_ACC (Int , 6);
2080 LIVING_ACC (Pow , 7);
2081 LIVING_ACC (wc , 8);
2082 LIVING_ACC (ac , 9);
2083 LIVING_ACC (hp , 10);
2084 LIVING_ACC (maxhp , 11);
2085 LIVING_ACC (sp , 12);
2086 LIVING_ACC (maxsp , 13);
2087 LIVING_ACC (grace , 14);
2088 LIVING_ACC (maxgrace, 15);
2089 LIVING_ACC (food , 16);
2090 LIVING_ACC (dam , 17);
2091 LIVING_ACC (luck , 18);
2092 }
2093# undef LIVING_ACC
2094 OUTPUT:
2095 RETVAL
2096

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines