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.19 by root, Wed Feb 8 07:14:56 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.0" 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"
52
53typedef object object_ornull;
54typedef mapstruct mapstruct_ornull;
51 55
52static f_plug_api gethook; 56static f_plug_api gethook;
53static f_plug_api registerGlobalEvent; 57static f_plug_api registerGlobalEvent;
54static f_plug_api unregisterGlobalEvent; 58static f_plug_api unregisterGlobalEvent;
55static f_plug_api systemDirectory; 59static f_plug_api systemDirectory;
56static f_plug_api object_set_property; 60static f_plug_api object_set_property;
57static f_plug_api map_get_map; 61static f_plug_api map_get_map;
62static f_plug_api object_insert;
58 63
64/* this is a stupid way to do things, and awkward to use for plug-in authors */
59typedef struct 65typedef struct
60{ 66{
61 object* who; 67 object* who;
62 object* activator; 68 object* activator;
63 object* third; 69 object* third;
70 object* event;
71 mapstruct* map;
64 char message[1024]; 72 char message[1024];
65 int fix; 73 int fix; // seems to be python-only, and should not be part of the API
66 int event_code; 74 int event_code;
67 char extension[1024]; // name field, should invoke specific perl extension 75 char extension[1024]; // name field, should invoke specific perl extension
68 char options[1024]; // slaying field of event_connectors 76 char options[1024]; // slaying field of event_connectors
69 int returnvalue; 77 int returnvalue;
70} CFPContext; 78} CFPContext;
71 79
72//static int current_command = -999;
73
74static HV *obj_cache; 80static HV *obj_cache;
75static 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))))
76 90
77////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 91//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78 92
79// garbage collect some perl objects, if possible 93// garbage collect some perl objects, if possible
80// all objects no longer referenced and empty are 94// all objects no longer referenced and empty are
112} 126}
113 127
114static SV * 128static SV *
115newSVptr (void *ptr, const char *klass) 129newSVptr (void *ptr, const char *klass)
116{ 130{
131 SV *sv;
132
117 if (!ptr) 133 if (!ptr)
118 return &PL_sv_undef; 134 return &PL_sv_undef;
119 135
120 HV *hv = newHV (); 136 sv = newSV (0);
121 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 137 sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
122 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 138 return sv_bless (newRV_noinc (sv), gv_stashpv (klass, 1));
139}
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;
123} 153}
124 154
125static SV * 155static SV *
126newSVptr_cached (void *ptr, const char *klass) 156newSVptr_cached (void *ptr, const char *klass)
127{ 157{
128 SV *sv, **he; 158 SV *sv;
129 159
130 if (!ptr) 160 if (!ptr)
131 return &PL_sv_undef; 161 return &PL_sv_undef;
132 162
133 he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); 163 sv = SVptr_cache_get (ptr);
134 164
135 if (he) 165 if (!sv)
136 sv = *he;
137 else
138 { 166 {
139 sv = newSVptr (ptr, klass); 167 HV *hv = newHV ();
140 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); 168 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
169 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
170
171 SVptr_cache_set (ptr, sv);
141 } 172 }
142 173
143 return newSVsv (sv); 174 return newSVsv (sv);
144} 175}
145 176
165 croak ("perl code used %s object, but C object is already destroyed, caught", klass); 196 croak ("perl code used %s object, but C object is already destroyed, caught", klass);
166 197
167 return (long)mg->mg_ptr; 198 return (long)mg->mg_ptr;
168} 199}
169 200
201static long
202SvPTR_ornull (SV *sv, const char *klass)
203{
204 if (SvOK (sv))
205 return SvPTR (sv, klass);
206 else
207 return 0;
208}
209
170SV * 210SV *
171newSVcfapi (int type, ...) 211newSVcfapi (int type, ...)
172{ 212{
173 SV *sv; 213 SV *sv;
174 214
175 va_list args; 215 va_list args;
176 va_start (args, type); 216 va_start (args, type);
177 217
178 switch (type) 218 switch (type)
179 { 219 {
220#if 0
221 case CFAPI_INT16:
222 sv = newSViv (*va_arg (args, sint16_t *));
223 break;
224#endif
225
180 case CFAPI_INT: 226 case CFAPI_INT:
181 sv = newSViv (*va_arg (args, int *)); 227 sv = newSViv (*va_arg (args, int *));
182 break; 228 break;
183 229
184 case CFAPI_LONG: 230 case CFAPI_LONG:
185 sv = newSViv (*va_arg (args, long *)); 231 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
186 break; 232 break;
187 233
188 case CFAPI_DOUBLE: 234 case CFAPI_DOUBLE:
189 sv = newSViv (*va_arg (args, double *)); 235 sv = newSVnv (*va_arg (args, double *));
190 break; 236 break;
191 237
192 case CFAPI_STRING: 238 case CFAPI_STRING:
193 { 239 {
194 char *str = va_arg (args, char *); 240 char *str = va_arg (args, char *);
201 object *obj = va_arg (args, object *); 247 object *obj = va_arg (args, object *);
202 248
203 if (!obj) 249 if (!obj)
204 sv = &PL_sv_undef; 250 sv = &PL_sv_undef;
205 else 251 else
206 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 252 switch (obj->type)
207 { 253 {
208 case MAP: 254 case MAP:
209 sv = newSVptr_cached (obj, "cf::object::map"); 255 sv = newSVptr_cached (obj, "cf::object::map");
210 break; 256 break;
211 257
247 va_end (args); 293 va_end (args);
248 294
249 return sv; 295 return sv;
250} 296}
251 297
252/////////////////////////////////////////////////////////////////////////////
253
254void
255inject_event (const char *func, CFPContext *context)
256{
257 dSP;
258
259 ENTER;
260 SAVETMPS;
261
262 PUSHMARK (SP);
263
264 HV *hv = newHV ();
265#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
266 hv_context (CFAPI_POBJECT, ,who);
267 hv_context (CFAPI_POBJECT, ,activator);
268 hv_context (CFAPI_POBJECT, ,third);
269 hv_context (CFAPI_STRING , ,message);
270 hv_context (CFAPI_INT ,&,fix);
271 hv_context (CFAPI_INT ,&,event_code);
272 hv_context (CFAPI_STRING , ,options);
273 hv_context (CFAPI_STRING , ,extension);
274
275 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
276
277 PUTBACK;
278 int count = call_pv (func, G_SCALAR | G_EVAL);
279 SPAGAIN;
280
281 if (SvTRUE (ERRSV))
282 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
283
284 context->returnvalue = count > 0 ? POPi : 0;
285
286 PUTBACK;
287 FREETMPS;
288 LEAVE;
289}
290
291///////////////////////////////////////////////////////////////////////////// 298/////////////////////////////////////////////////////////////////////////////
292 299
293int 300int
294initPlugin (const char *iversion, f_plug_api gethooksptr) 301initPlugin (const char *iversion, f_plug_api gethooksptr)
295{ 302{
394 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); 401 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event");
395 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); 402 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event");
396 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); 403 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory");
397 object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); 404 object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property");
398 map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); 405 map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map");
406 object_insert = gethook (&rtype, hooktype, "cfapi_object_insert");
399 407
400 cf_init_plugin (gethook); 408 cf_init_plugin (gethook);
401 409
402 /* Pick the global events you want to monitor from this plugin */ 410 /* Pick the global events you want to monitor from this plugin */
403 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); 411 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener);
408 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); 416 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener);
409 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); 417 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener);
410 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); 418 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener);
411 registerGlobalEvent (NULL, EVENT_MAPLEAVE, PLUGIN_NAME, globalEventListener); 419 registerGlobalEvent (NULL, EVENT_MAPLEAVE, PLUGIN_NAME, globalEventListener);
412 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);
413 registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener); 425 registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener);
414 registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); 426 registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener);
415 registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); 427 registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener);
416 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
417 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
418 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);
419 434
420 char *argv[] = { 435 char *argv[] = {
421 "", 436 "",
422 "-e" 437 "-e"
423 "BEGIN {" 438 "BEGIN {"
429 }; 444 };
430 445
431 perl = perl_alloc (); 446 perl = perl_alloc ();
432 perl_construct (perl); 447 perl_construct (perl);
433 448
449 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
450
434 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))
435 { 452 {
436 printf ("unable to initialize perl-interpreter, continuing without.\n"); 453 printf ("unable to initialize perl-interpreter, continuing without.\n");
437 454
438 perl_destruct (perl); 455 perl_destruct (perl);
449 466
450void * 467void *
451globalEventListener (int *type, ...) 468globalEventListener (int *type, ...)
452{ 469{
453 va_list args; 470 va_list args;
454 static int rv = 0; 471 static int rv;
455 CFPContext context; 472 int event_code;
456 char *buf;
457 player *pl;
458 object *op;
459 473
460 if (!perl) 474 if (!perl)
461 return; 475 return;
462 476
463 memset (&context, 0, sizeof (context));
464
465 va_start (args, type); 477 va_start (args, type);
466 context.event_code = va_arg (args, int); 478 event_code = va_arg (args, int);
467 479
468 switch (context.event_code) 480 if (event_code == EVENT_FREE_OB)
469 { 481 {
470 case EVENT_CRASH: 482 player *pl;
471 printf ("Unimplemented for now\n"); 483 object *op;
472 break; 484 SV *sv;
473 485
474 case EVENT_MAPENTER:
475 case EVENT_MAPLEAVE:
476 case EVENT_FREE_OB:
477 case EVENT_BORN:
478 case EVENT_REMOVE:
479 context.activator = va_arg (args, object *);
480 break;
481
482 case EVENT_PLAYER_DEATH:
483 context.who = va_arg (args, object *); 486 op = va_arg (args, object *);
484 break; 487 sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0);
485 488
486 case EVENT_GKILL: 489 if (sv)
487 context.who = va_arg (args, object *); 490 clearSVptr (sv);
488 context.activator = va_arg (args, object *);
489 break;
490 491
491 case EVENT_LOGIN: 492 rv = 0;
492 case EVENT_LOGOUT:
493 pl = va_arg (args, player *);
494 context.activator = pl->ob;
495 buf = va_arg (args, char *);
496 if (buf != 0)
497 strncpy (context.message, buf, sizeof (context.message));
498 break;
499
500 case EVENT_SHOUT:
501 case EVENT_MUZZLE:
502 case EVENT_KICK:
503 context.activator = va_arg (args, object *);
504 buf = va_arg (args, char *);
505 if (buf != 0)
506 strncpy (context.message, buf, sizeof (context.message));
507 break;
508
509 case EVENT_CLOCK:
510 clean_obj_cache ();
511 break;
512
513 case EVENT_TELL:
514 break;
515
516 case EVENT_MAPRESET:
517 buf = va_arg (args, char *);
518 if (buf != 0)
519 strncpy (context.message, buf, sizeof (context.message));
520 break;
521 } 493 }
522 494 else if (event_code == EVENT_CLOCK)
523 va_end (args);
524
525 if (context.event_code == EVENT_FREE_OB)
526 { 495 {
527 SV **svp = hv_fetch (obj_cache, (char *)&context.activator, sizeof (void *), 0); 496 dSP;
528 497
529 if (svp) 498 clean_obj_cache ();
530 clearSVptr (*svp); 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;
531 } 509 }
532 else 510 else
533 inject_event ("cf::inject_global_event", &context); 511 {
534 512 dSP;
535 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 }
536 595
537 return &rv; 596 return &rv;
538} 597}
539 598
540void * 599void *
541eventListener (int *type, ...) 600eventListener (int *type, ...)
542{ 601{
543 static int rv = 0; 602 static int rv;
544 va_list args; 603 va_list args;
545 char *buf; 604 int event_code;
546 CFPContext context; 605 object *who, *activator, *third, *event;
606 char *message, *extension, *options;
547 607
548 if (!perl) 608 if (!perl)
549 return; 609 return;
550 610
551 memset (&context, 0, sizeof (context));
552
553 va_start (args, type); 611 va_start (args, type);
554
555 context.who = va_arg (args, object *); 612 who = va_arg (args, object *);
556 context.event_code = va_arg (args, int); 613 event_code = va_arg (args, int);
557 context.activator = va_arg (args, object *); 614 activator = va_arg (args, object *);
558 context.third = va_arg (args, object *); 615 third = va_arg (args, object *);
559
560 buf = va_arg (args, char *); 616 message = va_arg (args, char *);
561 if (buf != 0) 617 va_arg (args, int); // fix yourself
562 strncpy (context.message, buf, sizeof (context.message)); 618 extension = va_arg (args, char *);
563 619 options = va_arg (args, char *);
564 context.fix = va_arg (args, int); 620 event = va_arg (args, object *);
565 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension));
566 strncpy (context.options, va_arg (args, char *), sizeof (context.options));
567 context.returnvalue = 0;
568 va_end (args); 621 va_end (args);
569 622
570 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 }
571 688
572 rv = context.returnvalue;
573 return &rv; 689 return &rv;
574} 690}
575 691
576int 692int
577closePlugin () 693closePlugin ()
603 const_iv (llevInfo) 719 const_iv (llevInfo)
604 const_iv (llevDebug) 720 const_iv (llevDebug)
605 const_iv (llevMonster) 721 const_iv (llevMonster)
606 722
607 const_iv (PLAYER) 723 const_iv (PLAYER)
724 const_iv (TRANSPORT)
608 const_iv (ROD) 725 const_iv (ROD)
609 const_iv (TREASURE) 726 const_iv (TREASURE)
610 const_iv (POTION) 727 const_iv (POTION)
611 const_iv (FOOD) 728 const_iv (FOOD)
612 const_iv (POISON) 729 const_iv (POISON)
617 const_iv (BOW) 734 const_iv (BOW)
618 const_iv (WEAPON) 735 const_iv (WEAPON)
619 const_iv (ARMOUR) 736 const_iv (ARMOUR)
620 const_iv (PEDESTAL) 737 const_iv (PEDESTAL)
621 const_iv (ALTAR) 738 const_iv (ALTAR)
622 const_iv (CONFUSION)
623 const_iv (LOCKED_DOOR) 739 const_iv (LOCKED_DOOR)
624 const_iv (SPECIAL_KEY) 740 const_iv (SPECIAL_KEY)
625 const_iv (MAP) 741 const_iv (MAP)
626 const_iv (DOOR) 742 const_iv (DOOR)
627 const_iv (KEY) 743 const_iv (KEY)
728 const_iv (ITEM_TRANSFORMER) 844 const_iv (ITEM_TRANSFORMER)
729 const_iv (QUEST) 845 const_iv (QUEST)
730 846
731 const_iv (ST_BD_BUILD) 847 const_iv (ST_BD_BUILD)
732 const_iv (ST_BD_REMOVE) 848 const_iv (ST_BD_REMOVE)
849
733 const_iv (ST_MAT_FLOOR) 850 const_iv (ST_MAT_FLOOR)
734 const_iv (ST_MAT_WALL) 851 const_iv (ST_MAT_WALL)
735 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)
736 880
737 const_iv (QUEST_IN_PROGRESS) 881 const_iv (QUEST_IN_PROGRESS)
738 const_iv (QUEST_DONE_QUEST) 882 const_iv (QUEST_DONE_QUEST)
739 const_iv (QUEST_DONE_TASK) 883 const_iv (QUEST_DONE_TASK)
740 const_iv (QUEST_START_QUEST) 884 const_iv (QUEST_START_QUEST)
908 const_iv (WILL_APPLY_HANDLE) 1052 const_iv (WILL_APPLY_HANDLE)
909 const_iv (WILL_APPLY_TREASURE) 1053 const_iv (WILL_APPLY_TREASURE)
910 const_iv (WILL_APPLY_EARTHWALL) 1054 const_iv (WILL_APPLY_EARTHWALL)
911 const_iv (WILL_APPLY_DOOR) 1055 const_iv (WILL_APPLY_DOOR)
912 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)
913 }; 1158 };
914 1159
915 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; )
916 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1161 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
917 1162
934 const_event (CLOSE) 1179 const_event (CLOSE)
935 const_event (TIMER) 1180 const_event (TIMER)
936 const_event (MOVE) 1181 const_event (MOVE)
937 1182
938 const_event (BORN) 1183 const_event (BORN)
939 const_event (CLOCK) 1184 //const_event (CLOCK)
940 const_event (CRASH) 1185 const_event (CRASH)
941 const_event (PLAYER_DEATH) 1186 const_event (PLAYER_DEATH)
1187 const_event (PLAYER_LOAD)
1188 const_event (PLAYER_SAVE)
942 const_event (GKILL) 1189 const_event (GKILL)
943 const_event (LOGIN) 1190 const_event (LOGIN)
944 const_event (LOGOUT) 1191 const_event (LOGOUT)
945 const_event (MAPENTER) 1192 const_event (MAPENTER)
946 const_event (MAPLEAVE) 1193 const_event (MAPLEAVE)
947 const_event (MAPRESET) 1194 const_event (MAPRESET)
1195 const_event (MAPLOAD)
1196 const_event (MAPOUT)
1197 const_event (MAPIN)
1198 const_event (MAPCLEAN)
948 const_event (REMOVE) 1199 const_event (REMOVE)
949 const_event (SHOUT) 1200 const_event (SHOUT)
950 const_event (TELL) 1201 const_event (TELL)
951 const_event (MUZZLE) 1202 const_event (MUZZLE)
952 const_event (KICK) 1203 const_event (KICK)
1204 const_event (EXTCMD)
953 //const_event (FREE_OB) 1205 //const_event (FREE_OB)
954 }; 1206 };
955 1207
956 AV *av = get_av ("cf::EVENT", 1); 1208 AV *av = get_av ("cf::EVENT", 1);
957 1209
1055 prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED) 1307 prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED)
1056 prop (CFAPI_INT, OBJECT_PROP_FRIENDLY) 1308 prop (CFAPI_INT, OBJECT_PROP_FRIENDLY)
1057 prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) 1309 prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME)
1058 prop (CFAPI_INT, OBJECT_PROP_MAGICAL) 1310 prop (CFAPI_INT, OBJECT_PROP_MAGICAL)
1059 prop (CFAPI_INT, OBJECT_PROP_LUCK) 1311 prop (CFAPI_INT, OBJECT_PROP_LUCK)
1060 prop (CFAPI_LONG, OBJECT_PROP_EXP)
1061 prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) 1312 prop (CFAPI_POBJECT, OBJECT_PROP_OWNER)
1062 prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) 1313 prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT)
1063 prop (CFAPI_INT, OBJECT_PROP_CHEATER) 1314 prop (CFAPI_INT, OBJECT_PROP_CHEATER)
1064 prop (CFAPI_INT, OBJECT_PROP_MERGEABLE) 1315 prop (CFAPI_INT, OBJECT_PROP_MERGEABLE)
1065 prop (CFAPI_INT, OBJECT_PROP_PICKABLE) 1316 prop (CFAPI_INT, OBJECT_PROP_PICKABLE)
1092 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; )
1093 { 1344 {
1094 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);
1095 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);
1096 } 1347 }
1348
1349 //I_EVENT_API (PACKAGE);
1097} 1350}
1098 1351
1099void 1352void
1100LOG (int level, char *msg) 1353LOG (int level, char *msg)
1101 PROTOTYPE: $$ 1354 PROTOTYPE: $$
1102 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: $$
1103 1362
1104char * 1363char *
1105cf_get_maps_directory (char *path) 1364cf_get_maps_directory (char *path)
1106 PROTOTYPE: $ 1365 PROTOTYPE: $
1107 ALIAS: maps_directory = 0 1366 ALIAS: maps_directory = 0
1152 int unused_type; 1411 int unused_type;
1153 object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); 1412 object_set_property (&unused_type, obj, idx, (double)SvNV (newval));
1154 } 1413 }
1155 break; 1414 break;
1156 case CFAPI_STRING: 1415 case CFAPI_STRING:
1157 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 }
1158 break; 1423 break;
1159 default: 1424 default:
1160 croak ("unhandled type '%d' in set_property '%d'", type, idx); 1425 croak ("unhandled type '%d' in set_property '%d'", type, idx);
1161 } 1426 }
1162 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
1163void 1457void
1164inv (object *obj) 1458inv (object *obj)
1165 PROTOTYPE: $ 1459 PROTOTYPE: $
1166 PPCODE: 1460 PPCODE:
1167{ 1461{
1188 1482
1189void cf_object_free (object *op) 1483void cf_object_free (object *op)
1190 1484
1191object *cf_object_present_archname_inside (object *op, char *whatstr) 1485object *cf_object_present_archname_inside (object *op, char *whatstr)
1192 1486
1193int 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)
1194 1488
1195int 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)
1196 1490
1197object *cf_object_clone (object *op, int clonetype) 1491object *cf_object_clone (object *op, int clonetype = 0)
1198 1492
1199int cf_object_pay_item (object *op, object *buyer) 1493int cf_object_pay_item (object *op, object *buyer)
1200 1494
1201int cf_object_pay_amount (object *op, double amount) 1495int cf_object_pay_amount (object *op, double amount)
1202 1496
1203int 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)
1204 1498
1205int 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)
1206 1500
1207void cf_object_learn_spell (object *op, object *sp) 1501void cf_object_learn_spell (object *op, object *sp)
1208 1502
1209void cf_object_forget_spell (object *op, object *sp) 1503void cf_object_forget_spell (object *op, object *sp)
1210 1504
1241 1535
1242void cf_object_update (object *op, int flags) 1536void cf_object_update (object *op, int flags)
1243 1537
1244void cf_object_pickup (object *op, object *what) 1538void cf_object_pickup (object *op, object *what)
1245 1539
1246char *cf_object_get_key (object *op, char *keyname) 1540object *cf_create_object_by_name (const char *name)
1541
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)
1547
1548MODULE = cf PACKAGE = cf::object PREFIX = cf_
1549
1550void cf_fix_object (object *pl)
1247 ALIAS: key = 0 1551 ALIAS: fix = 0
1248 1552
1249void cf_object_set_key (object *op, char *keyname, char *value) 1553object *cf_insert_ob_in_ob (object *ob, object *where)
1250 1554
1251char * 1555# no clean way to get an object from an archetype - stupid idiotic
1252base_name (object *ob, int plural) 1556# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1557
1558object *new (const char *archetype = 0)
1559 PROTOTYPE: ;$
1253 CODE: 1560 CODE:
1254 RETVAL = cf_query_base_name (ob, plural); 1561 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1255 OUTPUT: RETVAL
1256
1257MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1258
1259object *cf_create_object_by_name (const char *name = 0)
1260 PROTOTYPE: ;$
1261 ALIAS:
1262 create_object = 0
1263 new = 0
1264 CODE:
1265 RETVAL = name ? cf_create_object_by_name (name) : cf_create_object ();
1266 OUTPUT: 1562 OUTPUT:
1267 RETVAL 1563 RETVAL
1268 1564
1269void cf_fix_object (object *pl) 1565object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y)
1270 ALIAS: fix = 0 1566 PROTOTYPE: $$$$$$
1567 CODE:
1568{
1569 int unused_type;
1570 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1571}
1271 1572
1272object *cf_insert_ob_in_ob (object *ob, object *where) 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)
1273 1583
1274object *get_nearest_player (object *ob) 1584object *get_nearest_player (object *ob)
1275 ALIAS: nearest_player = 0 1585 ALIAS: nearest_player = 0
1276 PREINIT: 1586 PREINIT:
1277 extern object *get_nearest_player (object *); 1587 extern object *get_nearest_player (object *);
1293bool on_same_map_as (object *ob, object *other) 1603bool on_same_map_as (object *ob, object *other)
1294 CODE: 1604 CODE:
1295 RETVAL = on_same_map (ob, other); 1605 RETVAL = on_same_map (ob, other);
1296 OUTPUT: RETVAL 1606 OUTPUT: RETVAL
1297 1607
1608char *
1609base_name (object *ob, int plural)
1610 CODE:
1611 RETVAL = cf_query_base_name (ob, plural);
1612 OUTPUT: RETVAL
1613
1614living *
1615stats (object *ob)
1616 CODE:
1617 RETVAL = &ob->stats;
1618 OUTPUT: RETVAL
1619
1298 1620
1299MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1621MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1300 1622
1301player *player (object *op) 1623player *player (object *op)
1302 CODE: 1624 CODE:
1303 RETVAL = cf_player_find (cf_query_name (op)); 1625 RETVAL = op->contr;
1304 OUTPUT: RETVAL 1626 OUTPUT: RETVAL
1305 1627
1306void 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)
1307 1629
1308object *cf_player_send_inventory (object *op) 1630object *cf_player_send_inventory (object *op)
1631
1632player *contr (object *op)
1633 CODE:
1634 RETVAL = op->contr;
1635 OUTPUT: RETVAL
1309 1636
1310char *cf_player_get_ip (object *op) 1637char *cf_player_get_ip (object *op)
1311 ALIAS: ip = 0 1638 ALIAS: ip = 0
1312 1639
1313object *cf_player_get_marked_item (object *op) 1640object *cf_player_get_marked_item (object *op)
1318partylist *cf_player_get_party (object *op) 1645partylist *cf_player_get_party (object *op)
1319 ALIAS: party = 0 1646 ALIAS: party = 0
1320 1647
1321void cf_player_set_party (object *op, partylist *party) 1648void cf_player_set_party (object *op, partylist *party)
1322 1649
1650void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1651
1652void kill_player (object *op)
1323 1653
1324MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1654MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1325 1655
1326MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1656MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1327 1657
1328player *cf_player_find (char *name) 1658player *cf_player_find (char *name)
1329 PROTOTYPE: $ 1659 PROTOTYPE: $
1330 1660
1331void cf_player_move (player *pl, int dir) 1661void cf_player_move (player *pl, int dir)
1332 1662
1663void MapNewmapCmd (player *pl)
1664
1665void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1666
1333# nonstandard 1667# nonstandard
1334object *ob (player *pl) 1668object *ob (player *pl)
1335 CODE: 1669 CODE:
1336 RETVAL = pl->ob; 1670 RETVAL = pl->ob;
1337 OUTPUT: RETVAL 1671 OUTPUT: RETVAL
1343 1677
1344player *next (player *pl) 1678player *next (player *pl)
1345 CODE: 1679 CODE:
1346 RETVAL = pl->next; 1680 RETVAL = pl->next;
1347 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;
1348 1724
1349void 1725void
1350list () 1726list ()
1351 PPCODE: 1727 PPCODE:
1352{ 1728{
1353 player *pl; 1729 player *pl;
1354 for (pl = first_player; pl; pl = pl->next) 1730 for (pl = first_player; pl; pl = pl->next)
1355 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 1731 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1356} 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
1357 1755
1358 1756
1359MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 1757MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
1360 1758
1361SV * 1759SV *
1384 RETVAL = map_get_map (&unused_type, 0, width, height); 1782 RETVAL = map_get_map (&unused_type, 0, width, height);
1385} 1783}
1386 OUTPUT: 1784 OUTPUT:
1387 RETVAL 1785 RETVAL
1388 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
1389mapstruct *cf_map_get_map (char *name) 1807mapstruct *cf_map_get_map (char *name)
1390 PROTOTYPE: $ 1808 PROTOTYPE: $
1391 ALIAS: map = 0 1809 ALIAS: map = 0
1392 1810
1811mapstruct *has_been_loaded (char *name)
1812 PROTOTYPE: $
1813
1393mapstruct *cf_map_get_first () 1814mapstruct *cf_map_get_first ()
1394 PROTOTYPE: 1815 PROTOTYPE:
1395 ALIAS: first = 0 1816 ALIAS: first = 0
1396 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
1397object *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)
1398 1842
1399object *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)
1400 1844
1401object* 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)
1402 C_ARGS: str, map, nx, ny 1846 C_ARGS: str, map, nx, ny
1403 1847
1404#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1405
1406void 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
1407at (mapstruct *obj, unsigned int x, unsigned int y) 1868at (mapstruct *map, unsigned int x, unsigned int y)
1408 PROTOTYPE: $$$ 1869 PROTOTYPE: $$$
1409 INIT:
1410 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1411 PPCODE: 1870 PPCODE:
1412{ 1871{
1413 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)
1414 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)
1415 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1880 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1416} 1881}
1417 1882
1418SV * 1883SV *
1419bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1884bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1420 PROTOTYPE: $$$ 1885 PROTOTYPE: $$$
1441 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;
1442 } 1907 }
1443 OUTPUT: 1908 OUTPUT:
1444 RETVAL 1909 RETVAL
1445 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
1446 1983
1447MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ 1984MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_
1448 1985
1449archetype *cf_archetype_get_first() 1986archetype *cf_archetype_get_first()
1450 PROTOTYPE: 1987 PROTOTYPE:
1503 2040
1504const char *cf_region_get_message (region *reg) 2041const char *cf_region_get_message (region *reg)
1505 ALIAS: message = 0 2042 ALIAS: message = 0
1506 2043
1507 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