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.17 by root, Wed Feb 8 05:22:41 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
81// eligible for destruction. 95// eligible for destruction.
82void 96void
83clean_obj_cache () 97clean_obj_cache ()
84{ 98{
85 return; //D // killing neko-san gives me an unreferenced scalar 99 static int count;
100
101 if (++count & 7)
102 return;
103
86 int todo = 10; 104 int todo = 1000;
87 do 105 do
88 { 106 {
89 I32 klen; 107 I32 klen;
90 char *key; 108 char *key;
91 HE *he = hv_iternext (obj_cache); 109 HE *he = hv_iternext (obj_cache);
92 110
93 if (he) 111 if (he)
94 { 112 {
95 SV *sv = hv_iterval (obj_cache, he); 113 SV *sv = hv_iterval (obj_cache, he);
96 114
97 // emopty and unreferened? nuke it 115 // empty and unreferenced? nuke it
98 if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv)))) 116 if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv))))
99 { 117 {
100 hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); 118 hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD);
101 todo++; 119 todo++;
102 } 120 }
108} 126}
109 127
110static SV * 128static SV *
111newSVptr (void *ptr, const char *klass) 129newSVptr (void *ptr, const char *klass)
112{ 130{
131 SV *sv;
132
113 if (!ptr) 133 if (!ptr)
114 return &PL_sv_undef; 134 return &PL_sv_undef;
115 135
116 HV *hv = newHV (); 136 sv = newSV (0);
117 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 137 sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
118 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;
119} 153}
120 154
121static SV * 155static SV *
122newSVptr_cached (void *ptr, const char *klass) 156newSVptr_cached (void *ptr, const char *klass)
123{ 157{
124 SV *sv, **he; 158 SV *sv;
125 159
126 if (!ptr) 160 if (!ptr)
127 return &PL_sv_undef; 161 return &PL_sv_undef;
128 162
129 he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); 163 sv = SVptr_cache_get (ptr);
130 164
131 if (he) 165 if (!sv)
132 sv = *he;
133 else
134 { 166 {
135 return sv; //D 167 HV *hv = newHV ();
136 sv = newSVptr (ptr, klass); 168 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
137 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); 169 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
170
171 SVptr_cache_set (ptr, sv);
138 } 172 }
139 173
140 return newSVsv (sv); 174 return newSVsv (sv);
141} 175}
142 176
162 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);
163 197
164 return (long)mg->mg_ptr; 198 return (long)mg->mg_ptr;
165} 199}
166 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
167SV * 210SV *
168newSVcfapi (int type, ...) 211newSVcfapi (int type, ...)
169{ 212{
170 SV *sv; 213 SV *sv;
171 214
172 va_list args; 215 va_list args;
173 va_start (args, type); 216 va_start (args, type);
174 217
175 switch (type) 218 switch (type)
176 { 219 {
220#if 0
221 case CFAPI_INT16:
222 sv = newSViv (*va_arg (args, sint16_t *));
223 break;
224#endif
225
177 case CFAPI_INT: 226 case CFAPI_INT:
178 sv = newSViv (*va_arg (args, int *)); 227 sv = newSViv (*va_arg (args, int *));
179 break; 228 break;
180 229
181 case CFAPI_LONG: 230 case CFAPI_LONG:
182 sv = newSViv (*va_arg (args, long *)); 231 sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */
183 break; 232 break;
184 233
185 case CFAPI_DOUBLE: 234 case CFAPI_DOUBLE:
186 sv = newSViv (*va_arg (args, double *)); 235 sv = newSVnv (*va_arg (args, double *));
187 break; 236 break;
188 237
189 case CFAPI_STRING: 238 case CFAPI_STRING:
190 { 239 {
191 char *str = va_arg (args, char *); 240 char *str = va_arg (args, char *);
198 object *obj = va_arg (args, object *); 247 object *obj = va_arg (args, object *);
199 248
200 if (!obj) 249 if (!obj)
201 sv = &PL_sv_undef; 250 sv = &PL_sv_undef;
202 else 251 else
203 switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) 252 switch (obj->type)
204 { 253 {
205 case MAP: 254 case MAP:
206 sv = newSVptr_cached (obj, "cf::object::map"); 255 sv = newSVptr_cached (obj, "cf::object::map");
207 break; 256 break;
208 257
244 va_end (args); 293 va_end (args);
245 294
246 return sv; 295 return sv;
247} 296}
248 297
249/////////////////////////////////////////////////////////////////////////////
250
251void
252inject_event (const char *func, CFPContext *context)
253{
254 dSP;
255
256 ENTER;
257 SAVETMPS;
258
259 PUSHMARK (SP);
260
261 HV *hv = newHV ();
262#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
263 hv_context (CFAPI_POBJECT, ,who);
264 hv_context (CFAPI_POBJECT, ,activator);
265 hv_context (CFAPI_POBJECT, ,third);
266 hv_context (CFAPI_STRING , ,message);
267 hv_context (CFAPI_INT ,&,fix);
268 hv_context (CFAPI_INT ,&,event_code);
269 hv_context (CFAPI_STRING , ,options);
270 hv_context (CFAPI_STRING , ,extension);
271
272 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
273
274 PUTBACK;
275 int count = call_pv (func, G_SCALAR | G_EVAL);
276 SPAGAIN;
277
278 if (SvTRUE (ERRSV))
279 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
280
281 context->returnvalue = count > 0 ? POPi : 0;
282
283 PUTBACK;
284 FREETMPS;
285 LEAVE;
286}
287
288///////////////////////////////////////////////////////////////////////////// 298/////////////////////////////////////////////////////////////////////////////
289 299
290int 300int
291initPlugin (const char *iversion, f_plug_api gethooksptr) 301initPlugin (const char *iversion, f_plug_api gethooksptr)
292{ 302{
391 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); 401 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event");
392 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); 402 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event");
393 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); 403 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory");
394 object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); 404 object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property");
395 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");
396 407
397 cf_init_plugin (gethook); 408 cf_init_plugin (gethook);
398 409
399 /* Pick the global events you want to monitor from this plugin */ 410 /* Pick the global events you want to monitor from this plugin */
400 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); 411 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener);
405 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); 416 registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener);
406 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); 417 registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener);
407 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); 418 registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener);
408 registerGlobalEvent (NULL, EVENT_MAPLEAVE, PLUGIN_NAME, globalEventListener); 419 registerGlobalEvent (NULL, EVENT_MAPLEAVE, PLUGIN_NAME, globalEventListener);
409 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);
410 registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener); 425 registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener);
411 registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); 426 registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener);
412 registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); 427 registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener);
413 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
414 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
415 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);
416 434
417 char *argv[] = { 435 char *argv[] = {
418 "", 436 "",
419 "-e" 437 "-e"
420 "BEGIN {" 438 "BEGIN {"
426 }; 444 };
427 445
428 perl = perl_alloc (); 446 perl = perl_alloc ();
429 perl_construct (perl); 447 perl_construct (perl);
430 448
449 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
450
431 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))
432 { 452 {
433 printf ("unable to initialize perl-interpreter, continuing without.\n"); 453 printf ("unable to initialize perl-interpreter, continuing without.\n");
434 454
435 perl_destruct (perl); 455 perl_destruct (perl);
446 466
447void * 467void *
448globalEventListener (int *type, ...) 468globalEventListener (int *type, ...)
449{ 469{
450 va_list args; 470 va_list args;
451 static int rv = 0; 471 static int rv;
452 CFPContext context; 472 int event_code;
453 char *buf;
454 player *pl;
455 object *op;
456 473
457 if (!perl) 474 if (!perl)
458 return; 475 return;
459 476
460 memset (&context, 0, sizeof (context));
461
462 va_start (args, type); 477 va_start (args, type);
463 context.event_code = va_arg (args, int); 478 event_code = va_arg (args, int);
464 479
465 switch (context.event_code) 480 if (event_code == EVENT_FREE_OB)
466 { 481 {
467 case EVENT_CRASH: 482 player *pl;
468 printf ("Unimplemented for now\n"); 483 object *op;
469 break; 484 SV *sv;
470 485
471 case EVENT_MAPENTER:
472 case EVENT_MAPLEAVE:
473 case EVENT_FREE_OB:
474 case EVENT_BORN:
475 case EVENT_REMOVE:
476 context.activator = va_arg (args, object *);
477 break;
478
479 case EVENT_PLAYER_DEATH:
480 context.who = va_arg (args, object *); 486 op = va_arg (args, object *);
481 break; 487 sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0);
482 488
483 case EVENT_GKILL: 489 if (sv)
484 context.who = va_arg (args, object *); 490 clearSVptr (sv);
485 context.activator = va_arg (args, object *);
486 break;
487 491
488 case EVENT_LOGIN: 492 rv = 0;
489 case EVENT_LOGOUT:
490 pl = va_arg (args, player *);
491 context.activator = pl->ob;
492 buf = va_arg (args, char *);
493 if (buf != 0)
494 strncpy (context.message, buf, sizeof (context.message));
495 break;
496
497 case EVENT_SHOUT:
498 case EVENT_MUZZLE:
499 case EVENT_KICK:
500 context.activator = va_arg (args, object *);
501 buf = va_arg (args, char *);
502 if (buf != 0)
503 strncpy (context.message, buf, sizeof (context.message));
504 break;
505
506 case EVENT_CLOCK:
507 clean_obj_cache ();
508 break;
509
510 case EVENT_TELL:
511 break;
512
513 case EVENT_MAPRESET:
514 buf = va_arg (args, char *);
515 if (buf != 0)
516 strncpy (context.message, buf, sizeof (context.message));
517 break;
518 } 493 }
519 494 else if (event_code == EVENT_CLOCK)
520 va_end (args);
521
522 if (context.event_code == EVENT_FREE_OB)
523 { 495 {
524 SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (object *), 0); 496 dSP;
525 497
526 if (sv) 498 clean_obj_cache ();
527 { 499
528 clearSVptr (sv); 500 ENTER;
529 SvREFCNT_dec (sv); 501 SAVETMPS;
530 } 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{
1176int cf_object_get_flag (object *op, int flag) 1470int cf_object_get_flag (object *op, int flag)
1177 ALIAS: flag = 0 1471 ALIAS: flag = 0
1178 1472
1179void cf_object_set_flag (object *op, int flag, int value) 1473void cf_object_set_flag (object *op, int flag, int value)
1180 1474
1181void cf_object_move (object *op, int dir, object *originator) 1475void cf_object_move (object *op, int dir, object *originator = op)
1182 1476
1183void cf_object_apply (object *op, object *author, int flags = 0) 1477void cf_object_apply (object *op, object *author, int flags = 0)
1184 1478
1185void cf_object_apply_below (object *op) 1479void cf_object_apply_below (object *op)
1186 1480
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
1586 PREINIT:
1587 extern object *get_nearest_player (object *);
1276 1588
1277void rangevector (object *ob, object *other, int flags = 0) 1589void rangevector (object *ob, object *other, int flags = 0)
1278 PROTOTYPE: $$;$ 1590 PROTOTYPE: $$;$
1279 PPCODE: 1591 PPCODE:
1280{ 1592{
1291bool on_same_map_as (object *ob, object *other) 1603bool on_same_map_as (object *ob, object *other)
1292 CODE: 1604 CODE:
1293 RETVAL = on_same_map (ob, other); 1605 RETVAL = on_same_map (ob, other);
1294 OUTPUT: RETVAL 1606 OUTPUT: RETVAL
1295 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
1296 1620
1297MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1621MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1298 1622
1299player *player (object *op) 1623player *player (object *op)
1300 CODE: 1624 CODE:
1301 RETVAL = cf_player_find (cf_query_name (op)); 1625 RETVAL = op->contr;
1302 OUTPUT: RETVAL 1626 OUTPUT: RETVAL
1303 1627
1304void 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)
1305 1629
1306object *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
1307 1636
1308char *cf_player_get_ip (object *op) 1637char *cf_player_get_ip (object *op)
1309 ALIAS: ip = 0 1638 ALIAS: ip = 0
1310 1639
1311object *cf_player_get_marked_item (object *op) 1640object *cf_player_get_marked_item (object *op)
1316partylist *cf_player_get_party (object *op) 1645partylist *cf_player_get_party (object *op)
1317 ALIAS: party = 0 1646 ALIAS: party = 0
1318 1647
1319void cf_player_set_party (object *op, partylist *party) 1648void cf_player_set_party (object *op, partylist *party)
1320 1649
1650void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0)
1651
1652void kill_player (object *op)
1321 1653
1322MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1654MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1323 1655
1324MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 1656MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1325 1657
1326player *cf_player_find (char *name) 1658player *cf_player_find (char *name)
1327 PROTOTYPE: $ 1659 PROTOTYPE: $
1328 1660
1329void cf_player_move (player *pl, int dir) 1661void cf_player_move (player *pl, int dir)
1330 1662
1663void MapNewmapCmd (player *pl)
1664
1665void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1666
1331# nonstandard 1667# nonstandard
1332object *ob (player *pl) 1668object *ob (player *pl)
1333 CODE: 1669 CODE:
1334 RETVAL = pl->ob; 1670 RETVAL = pl->ob;
1335 OUTPUT: RETVAL 1671 OUTPUT: RETVAL
1341 1677
1342player *next (player *pl) 1678player *next (player *pl)
1343 CODE: 1679 CODE:
1344 RETVAL = pl->next; 1680 RETVAL = pl->next;
1345 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;
1346 1724
1347void 1725void
1348list () 1726list ()
1349 PPCODE: 1727 PPCODE:
1350{ 1728{
1351 player *pl; 1729 player *pl;
1352 for (pl = first_player; pl; pl = pl->next) 1730 for (pl = first_player; pl; pl = pl->next)
1353 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 1731 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1354} 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
1355 1755
1356 1756
1357MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 1757MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
1358 1758
1359SV * 1759SV *
1382 RETVAL = map_get_map (&unused_type, 0, width, height); 1782 RETVAL = map_get_map (&unused_type, 0, width, height);
1383} 1783}
1384 OUTPUT: 1784 OUTPUT:
1385 RETVAL 1785 RETVAL
1386 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
1387mapstruct *cf_map_get_map (char *name) 1807mapstruct *cf_map_get_map (char *name)
1388 PROTOTYPE: $ 1808 PROTOTYPE: $
1389 ALIAS: map = 0 1809 ALIAS: map = 0
1390 1810
1811mapstruct *has_been_loaded (char *name)
1812 PROTOTYPE: $
1813
1391mapstruct *cf_map_get_first () 1814mapstruct *cf_map_get_first ()
1392 PROTOTYPE: 1815 PROTOTYPE:
1393 ALIAS: first = 0 1816 ALIAS: first = 0
1394 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
1395object *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)
1396 1842
1397object *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)
1398 1844
1399object* 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)
1400 C_ARGS: str, map, nx, ny 1846 C_ARGS: str, map, nx, ny
1401 1847
1402#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1403
1404void 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
1405at (mapstruct *obj, unsigned int x, unsigned int y) 1868at (mapstruct *map, unsigned int x, unsigned int y)
1406 PROTOTYPE: $$$ 1869 PROTOTYPE: $$$
1407 INIT:
1408 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1409 PPCODE: 1870 PPCODE:
1410{ 1871{
1411 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)
1412 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)
1413 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1880 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1414} 1881}
1415 1882
1416SV * 1883SV *
1417bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1884bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1418 PROTOTYPE: $$$ 1885 PROTOTYPE: $$$
1439 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;
1440 } 1907 }
1441 OUTPUT: 1908 OUTPUT:
1442 RETVAL 1909 RETVAL
1443 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
1444 1983
1445MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ 1984MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_
1446 1985
1447archetype *cf_archetype_get_first() 1986archetype *cf_archetype_get_first()
1448 PROTOTYPE: 1987 PROTOTYPE:
1501 2040
1502const char *cf_region_get_message (region *reg) 2041const char *cf_region_get_message (region *reg)
1503 ALIAS: message = 0 2042 ALIAS: message = 0
1504 2043
1505 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