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.2" |
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 | |
… | |
… | |
46 | #include <plugin_common.h> |
45 | #include <plugin_common.h> |
47 | #include <sounds.h> |
46 | #include <sounds.h> |
48 | |
47 | |
49 | #include <stdarg.h> |
48 | #include <stdarg.h> |
50 | |
49 | |
|
|
50 | //#include "EventAPI.h" |
51 | #include "perlxsi.c" |
51 | #include "perlxsi.c" |
52 | |
52 | |
53 | typedef object object_ornull; |
53 | typedef object object_ornull; |
54 | typedef mapstruct mapstruct_ornull; |
54 | typedef mapstruct mapstruct_ornull; |
55 | |
55 | |
… | |
… | |
65 | typedef struct |
65 | typedef struct |
66 | { |
66 | { |
67 | object* who; |
67 | object* who; |
68 | object* activator; |
68 | object* activator; |
69 | object* third; |
69 | object* third; |
|
|
70 | object* event; |
70 | mapstruct* map; |
71 | mapstruct* map; |
71 | char message[1024]; |
72 | char message[1024]; |
72 | int fix; // seems to be python-only, and should not be part of the API |
73 | int fix; // seems to be python-only, and should not be part of the API |
73 | int event_code; |
74 | int event_code; |
74 | char extension[1024]; // name field, should invoke specific perl extension |
75 | char extension[1024]; // name field, should invoke specific perl extension |
… | |
… | |
76 | int returnvalue; |
77 | int returnvalue; |
77 | } CFPContext; |
78 | } CFPContext; |
78 | |
79 | |
79 | static HV *obj_cache; |
80 | static HV *obj_cache; |
80 | static PerlInterpreter *perl; |
81 | static 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)))) |
81 | |
90 | |
82 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
91 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | |
92 | |
84 | // garbage collect some perl objects, if possible |
93 | // garbage collect some perl objects, if possible |
85 | // all objects no longer referenced and empty are |
94 | // all objects no longer referenced and empty are |
… | |
… | |
221 | case CFAPI_LONG: |
230 | case CFAPI_LONG: |
222 | sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ |
231 | sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ |
223 | break; |
232 | break; |
224 | |
233 | |
225 | case CFAPI_DOUBLE: |
234 | case CFAPI_DOUBLE: |
226 | sv = newSViv (*va_arg (args, double *)); |
235 | sv = newSVnv (*va_arg (args, double *)); |
227 | break; |
236 | break; |
228 | |
237 | |
229 | case CFAPI_STRING: |
238 | case CFAPI_STRING: |
230 | { |
239 | { |
231 | char *str = va_arg (args, char *); |
240 | char *str = va_arg (args, char *); |
… | |
… | |
238 | object *obj = va_arg (args, object *); |
247 | object *obj = va_arg (args, object *); |
239 | |
248 | |
240 | if (!obj) |
249 | if (!obj) |
241 | sv = &PL_sv_undef; |
250 | sv = &PL_sv_undef; |
242 | else |
251 | else |
243 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
252 | switch (obj->type) |
244 | { |
253 | { |
245 | case MAP: |
254 | case MAP: |
246 | sv = newSVptr_cached (obj, "cf::object::map"); |
255 | sv = newSVptr_cached (obj, "cf::object::map"); |
247 | break; |
256 | break; |
248 | |
257 | |
… | |
… | |
284 | va_end (args); |
293 | va_end (args); |
285 | |
294 | |
286 | return sv; |
295 | return sv; |
287 | } |
296 | } |
288 | |
297 | |
289 | ///////////////////////////////////////////////////////////////////////////// |
|
|
290 | |
|
|
291 | void |
|
|
292 | inject_event (const char *func, CFPContext *context) |
|
|
293 | { |
|
|
294 | dSP; |
|
|
295 | |
|
|
296 | ENTER; |
|
|
297 | SAVETMPS; |
|
|
298 | |
|
|
299 | PUSHMARK (SP); |
|
|
300 | |
|
|
301 | HV *hv = newHV (); |
|
|
302 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
|
|
303 | hv_context (CFAPI_POBJECT, ,who); |
|
|
304 | hv_context (CFAPI_POBJECT, ,activator); |
|
|
305 | hv_context (CFAPI_POBJECT, ,third); |
|
|
306 | hv_context (CFAPI_PMAP, ,map); |
|
|
307 | hv_context (CFAPI_STRING , ,message); |
|
|
308 | hv_context (CFAPI_INT ,&,fix); |
|
|
309 | hv_context (CFAPI_INT ,&,event_code); |
|
|
310 | hv_context (CFAPI_STRING , ,options); |
|
|
311 | hv_context (CFAPI_STRING , ,extension); |
|
|
312 | |
|
|
313 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
314 | |
|
|
315 | PUTBACK; |
|
|
316 | int count = call_pv (func, G_SCALAR | G_EVAL); |
|
|
317 | SPAGAIN; |
|
|
318 | |
|
|
319 | if (SvTRUE (ERRSV)) |
|
|
320 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
|
|
321 | |
|
|
322 | context->returnvalue = count > 0 ? POPi : 0; |
|
|
323 | |
|
|
324 | PUTBACK; |
|
|
325 | FREETMPS; |
|
|
326 | LEAVE; |
|
|
327 | } |
|
|
328 | |
|
|
329 | ///////////////////////////////////////////////////////////////////////////// |
298 | ///////////////////////////////////////////////////////////////////////////// |
330 | |
299 | |
331 | int |
300 | int |
332 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
301 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
333 | { |
302 | { |
… | |
… | |
459 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
428 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
460 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
429 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
461 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
430 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
462 | registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); |
431 | registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); |
463 | registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); |
432 | registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); |
|
|
433 | registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener); |
464 | |
434 | |
465 | char *argv[] = { |
435 | char *argv[] = { |
466 | "", |
436 | "", |
467 | "-e" |
437 | "-e" |
468 | "BEGIN {" |
438 | "BEGIN {" |
… | |
… | |
474 | }; |
444 | }; |
475 | |
445 | |
476 | perl = perl_alloc (); |
446 | perl = perl_alloc (); |
477 | perl_construct (perl); |
447 | perl_construct (perl); |
478 | |
448 | |
|
|
449 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
450 | |
479 | 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)) |
480 | { |
452 | { |
481 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
453 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
482 | |
454 | |
483 | perl_destruct (perl); |
455 | perl_destruct (perl); |
… | |
… | |
494 | |
466 | |
495 | void * |
467 | void * |
496 | globalEventListener (int *type, ...) |
468 | globalEventListener (int *type, ...) |
497 | { |
469 | { |
498 | va_list args; |
470 | va_list args; |
499 | static int rv = 0; |
471 | static int rv; |
500 | CFPContext context; |
472 | int event_code; |
501 | char *buf; |
|
|
502 | player *pl; |
|
|
503 | object *op; |
|
|
504 | |
473 | |
505 | if (!perl) |
474 | if (!perl) |
506 | return; |
475 | return; |
507 | |
476 | |
508 | memset (&context, 0, sizeof (context)); |
|
|
509 | |
|
|
510 | va_start (args, type); |
477 | va_start (args, type); |
511 | context.event_code = va_arg (args, int); |
478 | event_code = va_arg (args, int); |
512 | |
479 | |
513 | switch (context.event_code) |
480 | if (event_code == EVENT_FREE_OB) |
514 | { |
481 | { |
515 | case EVENT_CRASH: |
482 | player *pl; |
516 | printf ("Unimplemented for now\n"); |
483 | object *op; |
517 | break; |
484 | SV *sv; |
518 | |
485 | |
519 | case EVENT_PLAYER_LOAD: |
|
|
520 | case EVENT_PLAYER_SAVE: |
|
|
521 | context.who = va_arg (args, object *); |
486 | op = va_arg (args, object *); |
522 | buf = va_arg (args, char *); |
|
|
523 | if (buf != 0) |
|
|
524 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
525 | break; |
|
|
526 | |
|
|
527 | case EVENT_MAPLOAD: |
|
|
528 | case EVENT_MAPOUT: |
|
|
529 | case EVENT_MAPIN: |
|
|
530 | case EVENT_MAPCLEAN: |
|
|
531 | context.map = va_arg (args, mapstruct *); |
|
|
532 | break; |
|
|
533 | |
|
|
534 | case EVENT_MAPENTER: |
|
|
535 | case EVENT_MAPLEAVE: |
|
|
536 | case EVENT_FREE_OB: |
|
|
537 | case EVENT_BORN: |
|
|
538 | case EVENT_REMOVE: |
|
|
539 | context.activator = va_arg (args, object *); |
|
|
540 | break; |
|
|
541 | |
|
|
542 | case EVENT_PLAYER_DEATH: |
|
|
543 | context.who = va_arg (args, object *); |
|
|
544 | break; |
|
|
545 | |
|
|
546 | case EVENT_GKILL: |
|
|
547 | context.who = va_arg (args, object *); |
|
|
548 | context.activator = va_arg (args, object *); |
|
|
549 | break; |
|
|
550 | |
|
|
551 | case EVENT_LOGIN: |
|
|
552 | case EVENT_LOGOUT: |
|
|
553 | pl = va_arg (args, player *); |
|
|
554 | context.activator = pl->ob; |
|
|
555 | buf = va_arg (args, char *); |
|
|
556 | if (buf != 0) |
|
|
557 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
558 | break; |
|
|
559 | |
|
|
560 | case EVENT_SHOUT: |
|
|
561 | case EVENT_MUZZLE: |
|
|
562 | case EVENT_KICK: |
|
|
563 | context.activator = va_arg (args, object *); |
|
|
564 | buf = va_arg (args, char *); |
|
|
565 | if (buf != 0) |
|
|
566 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
567 | break; |
|
|
568 | |
|
|
569 | case EVENT_CLOCK: |
|
|
570 | clean_obj_cache (); |
|
|
571 | break; |
|
|
572 | |
|
|
573 | case EVENT_TELL: |
|
|
574 | break; |
|
|
575 | |
|
|
576 | case EVENT_MAPRESET: |
|
|
577 | /* stupid, should be the map itself, not "message"??? */ |
|
|
578 | buf = va_arg (args, char *); |
|
|
579 | if (buf != 0) |
|
|
580 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
581 | break; |
|
|
582 | } |
|
|
583 | |
|
|
584 | va_end (args); |
|
|
585 | |
|
|
586 | if (context.event_code == EVENT_FREE_OB) |
|
|
587 | { |
|
|
588 | SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); |
487 | sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0); |
589 | |
488 | |
590 | if (sv) |
489 | if (sv) |
591 | clearSVptr (sv); |
490 | clearSVptr (sv); |
|
|
491 | |
|
|
492 | rv = 0; |
|
|
493 | } |
|
|
494 | else if (event_code == EVENT_CLOCK) |
|
|
495 | { |
|
|
496 | dSP; |
|
|
497 | int i, count; |
|
|
498 | |
|
|
499 | clean_obj_cache (); |
|
|
500 | |
|
|
501 | ENTER; |
|
|
502 | SAVETMPS; |
|
|
503 | |
|
|
504 | // service up to 8 events per tick better would be |
|
|
505 | // to check for elapsed time and stop processing after |
|
|
506 | // 0.25 * server_tick or so |
|
|
507 | for (i = 9; --i; ) |
|
|
508 | { |
|
|
509 | PUSHMARK (SP); |
|
|
510 | XPUSHs (sv_2mortal (newSViv (0))); |
|
|
511 | PUTBACK; |
|
|
512 | count = call_pv ("Event::one_event", G_SCALAR | G_EVAL); |
|
|
513 | SPAGAIN; |
|
|
514 | |
|
|
515 | if (!count || !POPi) |
|
|
516 | break; |
|
|
517 | } |
|
|
518 | |
|
|
519 | FREETMPS; |
|
|
520 | LEAVE; |
592 | } |
521 | } |
593 | else |
522 | else |
594 | inject_event ("cf::inject_global_event", &context); |
523 | { |
595 | |
524 | dSP; |
596 | rv = context.returnvalue; |
525 | |
|
|
526 | ENTER; |
|
|
527 | SAVETMPS; |
|
|
528 | |
|
|
529 | PUSHMARK (SP); |
|
|
530 | |
|
|
531 | EXTEND (SP, 10); |
|
|
532 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
533 | |
|
|
534 | switch (event_code) |
|
|
535 | { |
|
|
536 | case EVENT_CRASH: |
|
|
537 | break; |
|
|
538 | |
|
|
539 | case EVENT_PLAYER_LOAD: |
|
|
540 | case EVENT_PLAYER_SAVE: |
|
|
541 | PUSH_OB; |
|
|
542 | PUSH_PV; |
|
|
543 | break; |
|
|
544 | |
|
|
545 | case EVENT_MAPLOAD: |
|
|
546 | case EVENT_MAPOUT: |
|
|
547 | case EVENT_MAPIN: |
|
|
548 | case EVENT_MAPCLEAN: |
|
|
549 | case EVENT_MAPRESET: |
|
|
550 | PUSH_MAP; |
|
|
551 | break; |
|
|
552 | |
|
|
553 | case EVENT_MAPENTER: |
|
|
554 | case EVENT_MAPLEAVE: |
|
|
555 | case EVENT_BORN: |
|
|
556 | case EVENT_REMOVE: |
|
|
557 | case EVENT_PLAYER_DEATH: |
|
|
558 | PUSH_OB; |
|
|
559 | break; |
|
|
560 | |
|
|
561 | case EVENT_GKILL: |
|
|
562 | PUSH_OB; |
|
|
563 | PUSH_OB; |
|
|
564 | break; |
|
|
565 | |
|
|
566 | case EVENT_LOGIN: |
|
|
567 | case EVENT_LOGOUT: |
|
|
568 | PUSH_PL; |
|
|
569 | PUSH_PV; |
|
|
570 | break; |
|
|
571 | |
|
|
572 | case EVENT_SHOUT: |
|
|
573 | case EVENT_MUZZLE: |
|
|
574 | case EVENT_KICK: |
|
|
575 | PUSH_OB; |
|
|
576 | PUSH_PV; |
|
|
577 | break; |
|
|
578 | |
|
|
579 | case EVENT_EXTCMD: |
|
|
580 | PUSH_PL; |
|
|
581 | { |
|
|
582 | char *buf = va_arg (args, char *); |
|
|
583 | int len = va_arg (args, int); |
|
|
584 | PUSHs (sv_2mortal (newSVpvn (buf, len))); |
|
|
585 | } |
|
|
586 | break; |
|
|
587 | |
|
|
588 | case EVENT_TELL: |
|
|
589 | break; |
|
|
590 | } |
|
|
591 | |
|
|
592 | va_end (args); |
|
|
593 | |
|
|
594 | PUTBACK; |
|
|
595 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
|
|
596 | SPAGAIN; |
|
|
597 | |
|
|
598 | if (SvTRUE (ERRSV)) |
|
|
599 | LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
600 | |
|
|
601 | rv = count > 0 ? POPi : 0; |
|
|
602 | |
|
|
603 | PUTBACK; |
|
|
604 | FREETMPS; |
|
|
605 | LEAVE; |
|
|
606 | } |
597 | |
607 | |
598 | return &rv; |
608 | return &rv; |
599 | } |
609 | } |
600 | |
610 | |
601 | void * |
611 | void * |
602 | eventListener (int *type, ...) |
612 | eventListener (int *type, ...) |
603 | { |
613 | { |
604 | static int rv = 0; |
614 | static int rv; |
605 | va_list args; |
615 | va_list args; |
606 | char *buf; |
616 | int event_code; |
607 | CFPContext context; |
617 | object *who, *activator, *third, *event; |
|
|
618 | char *message, *extension, *options; |
608 | |
619 | |
609 | if (!perl) |
620 | if (!perl) |
610 | return; |
621 | return; |
611 | |
622 | |
612 | memset (&context, 0, sizeof (context)); |
|
|
613 | |
|
|
614 | va_start (args, type); |
623 | va_start (args, type); |
615 | |
|
|
616 | context.who = va_arg (args, object *); |
624 | who = va_arg (args, object *); |
617 | context.event_code = va_arg (args, int); |
625 | event_code = va_arg (args, int); |
618 | context.activator = va_arg (args, object *); |
626 | activator = va_arg (args, object *); |
619 | context.third = va_arg (args, object *); |
627 | third = va_arg (args, object *); |
620 | |
|
|
621 | buf = va_arg (args, char *); |
628 | message = va_arg (args, char *); |
622 | if (buf != 0) |
629 | va_arg (args, int); // fix yourself |
623 | strncpy (context.message, buf, sizeof (context.message)); |
630 | extension = va_arg (args, char *); |
624 | |
631 | options = va_arg (args, char *); |
625 | context.fix = va_arg (args, int); |
632 | event = va_arg (args, object *); |
626 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
|
|
627 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
|
|
628 | context.returnvalue = 0; |
|
|
629 | va_end (args); |
633 | va_end (args); |
630 | |
634 | |
631 | inject_event ("cf::inject_event", &context); |
635 | { |
|
|
636 | dSP; |
|
|
637 | |
|
|
638 | ENTER; |
|
|
639 | SAVETMPS; |
|
|
640 | |
|
|
641 | PUSHMARK (SP); |
|
|
642 | EXTEND (SP, 10); |
|
|
643 | |
|
|
644 | PUSHcfapi (STRING, extension); |
|
|
645 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
646 | |
|
|
647 | PUSHcfapi (POBJECT, event); |
|
|
648 | PUSHcfapi (POBJECT, who); |
|
|
649 | |
|
|
650 | switch (event_code) |
|
|
651 | { |
|
|
652 | case EVENT_STOP: // $ob (e.g. arrow) |
|
|
653 | case EVENT_TIME: // $ob |
|
|
654 | case EVENT_TIMER: // $ob |
|
|
655 | break; |
|
|
656 | |
|
|
657 | case EVENT_APPLY: // $ob, $who |
|
|
658 | case EVENT_DROP: // $ob, $who |
|
|
659 | case EVENT_CLOSE: // $ob, $who |
|
|
660 | case EVENT_DEATH: // $ob[, $killer] |
|
|
661 | case EVENT_MOVE: // $ob, $enemy |
|
|
662 | case EVENT_THROW: // $ob, $thrower |
|
|
663 | PUSHcfapi (POBJECT, activator); |
|
|
664 | break; |
|
|
665 | |
|
|
666 | case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me) |
|
|
667 | PUSHcfapi (POBJECT, activator); |
|
|
668 | PUSHcfapi (POBJECT, third); |
|
|
669 | break; |
|
|
670 | |
|
|
671 | case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg] |
|
|
672 | PUSHcfapi (POBJECT, activator); |
|
|
673 | PUSHcfapi (POBJECT, third); |
|
|
674 | PUSHcfapi (POBJECT, message); |
|
|
675 | break; |
|
|
676 | |
|
|
677 | case EVENT_SAY: // $ob, $who, $msg |
|
|
678 | PUSHcfapi (POBJECT, activator); |
|
|
679 | PUSHcfapi (STRING, message); |
|
|
680 | break; |
|
|
681 | |
|
|
682 | default: |
|
|
683 | LOG (llevError, "perl plugin called for unsupported event type %d", event_code); |
|
|
684 | break; |
|
|
685 | } |
|
|
686 | |
|
|
687 | PUTBACK; |
|
|
688 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
|
|
689 | SPAGAIN; |
|
|
690 | |
|
|
691 | if (SvTRUE (ERRSV)) |
|
|
692 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
693 | |
|
|
694 | rv = count > 0 ? POPi : 0; |
|
|
695 | |
|
|
696 | PUTBACK; |
|
|
697 | FREETMPS; |
|
|
698 | LEAVE; |
|
|
699 | } |
632 | |
700 | |
633 | rv = context.returnvalue; |
|
|
634 | return &rv; |
701 | return &rv; |
635 | } |
702 | } |
636 | |
703 | |
637 | int |
704 | int |
638 | closePlugin () |
705 | closePlugin () |
… | |
… | |
1058 | const_iv (SK_SUMMONING) |
1125 | const_iv (SK_SUMMONING) |
1059 | const_iv (SK_PYROMANCY) |
1126 | const_iv (SK_PYROMANCY) |
1060 | const_iv (SK_EVOCATION) |
1127 | const_iv (SK_EVOCATION) |
1061 | const_iv (SK_SORCERY) |
1128 | const_iv (SK_SORCERY) |
1062 | const_iv (SK_TWO_HANDED_WEAPON) |
1129 | const_iv (SK_TWO_HANDED_WEAPON) |
|
|
1130 | const_iv (SK_SPARK_TOUCH) |
|
|
1131 | const_iv (SK_SHIVER) |
|
|
1132 | const_iv (SK_ACID_SPLASH) |
|
|
1133 | const_iv (SK_POISON_NAIL) |
1063 | |
1134 | |
1064 | const_iv (SOUND_NEW_PLAYER) |
1135 | const_iv (SOUND_NEW_PLAYER) |
1065 | const_iv (SOUND_FIRE_ARROW) |
1136 | const_iv (SOUND_FIRE_ARROW) |
1066 | const_iv (SOUND_LEARN_SPELL) |
1137 | const_iv (SOUND_LEARN_SPELL) |
1067 | const_iv (SOUND_FUMBLE_SPELL) |
1138 | const_iv (SOUND_FUMBLE_SPELL) |
… | |
… | |
1083 | const_iv (SOUND_CLOCK) |
1154 | const_iv (SOUND_CLOCK) |
1084 | const_iv (SOUND_TURN_HANDLE) |
1155 | const_iv (SOUND_TURN_HANDLE) |
1085 | const_iv (SOUND_FALL_HOLE) |
1156 | const_iv (SOUND_FALL_HOLE) |
1086 | const_iv (SOUND_DRINK_POISON) |
1157 | const_iv (SOUND_DRINK_POISON) |
1087 | const_iv (SOUND_CAST_SPELL_0) |
1158 | const_iv (SOUND_CAST_SPELL_0) |
|
|
1159 | |
|
|
1160 | const_iv (MAP_FLUSH) |
|
|
1161 | const_iv (MAP_PLAYER_UNIQUE) |
|
|
1162 | const_iv (MAP_BLOCK) |
|
|
1163 | const_iv (MAP_STYLE) |
|
|
1164 | const_iv (MAP_OVERLAY) |
|
|
1165 | |
|
|
1166 | const_iv (MAP_IN_MEMORY) |
|
|
1167 | const_iv (MAP_SWAPPED) |
|
|
1168 | const_iv (MAP_LOADING) |
|
|
1169 | const_iv (MAP_SAVING) |
1088 | }; |
1170 | }; |
1089 | |
1171 | |
1090 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1172 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1091 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1173 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1092 | |
1174 | |
… | |
… | |
1109 | const_event (CLOSE) |
1191 | const_event (CLOSE) |
1110 | const_event (TIMER) |
1192 | const_event (TIMER) |
1111 | const_event (MOVE) |
1193 | const_event (MOVE) |
1112 | |
1194 | |
1113 | const_event (BORN) |
1195 | const_event (BORN) |
1114 | const_event (CLOCK) |
1196 | //const_event (CLOCK) |
1115 | const_event (CRASH) |
1197 | const_event (CRASH) |
1116 | const_event (PLAYER_DEATH) |
1198 | const_event (PLAYER_DEATH) |
1117 | const_event (PLAYER_LOAD) |
1199 | const_event (PLAYER_LOAD) |
1118 | const_event (PLAYER_SAVE) |
1200 | const_event (PLAYER_SAVE) |
1119 | const_event (GKILL) |
1201 | const_event (GKILL) |
… | |
… | |
1129 | const_event (REMOVE) |
1211 | const_event (REMOVE) |
1130 | const_event (SHOUT) |
1212 | const_event (SHOUT) |
1131 | const_event (TELL) |
1213 | const_event (TELL) |
1132 | const_event (MUZZLE) |
1214 | const_event (MUZZLE) |
1133 | const_event (KICK) |
1215 | const_event (KICK) |
|
|
1216 | const_event (EXTCMD) |
1134 | //const_event (FREE_OB) |
1217 | //const_event (FREE_OB) |
1135 | }; |
1218 | }; |
1136 | |
1219 | |
1137 | AV *av = get_av ("cf::EVENT", 1); |
1220 | AV *av = get_av ("cf::EVENT", 1); |
1138 | |
1221 | |
… | |
… | |
1272 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1355 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1273 | { |
1356 | { |
1274 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1357 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1275 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1358 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1276 | } |
1359 | } |
|
|
1360 | |
|
|
1361 | //I_EVENT_API (PACKAGE); |
1277 | } |
1362 | } |
1278 | |
1363 | |
1279 | void |
1364 | void |
1280 | LOG (int level, char *msg) |
1365 | LOG (int level, char *msg) |
1281 | PROTOTYPE: $$ |
1366 | PROTOTYPE: $$ |
1282 | C_ARGS: level, "%s", msg |
1367 | C_ARGS: level, "%s", msg |
|
|
1368 | |
|
|
1369 | char *path_combine (char *base, char *path) |
|
|
1370 | PROTOTYPE: $$ |
|
|
1371 | |
|
|
1372 | char *path_combine_and_normalize (char *base, char *path) |
|
|
1373 | PROTOTYPE: $$ |
1283 | |
1374 | |
1284 | char * |
1375 | char * |
1285 | cf_get_maps_directory (char *path) |
1376 | cf_get_maps_directory (char *path) |
1286 | PROTOTYPE: $ |
1377 | PROTOTYPE: $ |
1287 | ALIAS: maps_directory = 0 |
1378 | ALIAS: maps_directory = 0 |
… | |
… | |
1456 | |
1547 | |
1457 | void cf_object_update (object *op, int flags) |
1548 | void cf_object_update (object *op, int flags) |
1458 | |
1549 | |
1459 | void cf_object_pickup (object *op, object *what) |
1550 | void cf_object_pickup (object *op, object *what) |
1460 | |
1551 | |
1461 | char *cf_object_get_key (object *op, char *keyname) |
|
|
1462 | ALIAS: key = 0 |
|
|
1463 | |
|
|
1464 | void cf_object_set_key (object *op, char *keyname, char *value) |
|
|
1465 | |
|
|
1466 | object *cf_create_object_by_name (const char *name) |
1552 | object *cf_create_object_by_name (const char *name) |
1467 | |
1553 | |
1468 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
1554 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
1469 | |
1555 | |
1470 | void player_lvl_adj (object *who, object *skill = 0) |
1556 | void player_lvl_adj (object *who, object *skill = 0) |
1471 | |
1557 | |
|
|
1558 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1472 | |
1559 | |
1473 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1560 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1474 | |
1561 | |
1475 | void cf_fix_object (object *pl) |
1562 | void cf_fix_object (object *pl) |
1476 | ALIAS: fix = 0 |
1563 | ALIAS: fix = 0 |
… | |
… | |
1492 | CODE: |
1579 | CODE: |
1493 | { |
1580 | { |
1494 | int unused_type; |
1581 | int unused_type; |
1495 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1582 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1496 | } |
1583 | } |
|
|
1584 | |
|
|
1585 | # syntatic sugar for easier use in event callbacks. |
|
|
1586 | const char *options (object *op) |
|
|
1587 | CODE: |
|
|
1588 | RETVAL = op->name; |
|
|
1589 | OUTPUT: |
|
|
1590 | RETVAL |
1497 | |
1591 | |
1498 | const char *get_ob_key_value (object *op, const char *key) |
1592 | const char *get_ob_key_value (object *op, const char *key) |
1499 | |
1593 | |
1500 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1594 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1501 | |
1595 | |
… | |
… | |
1538 | |
1632 | |
1539 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1633 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1540 | |
1634 | |
1541 | player *player (object *op) |
1635 | player *player (object *op) |
1542 | CODE: |
1636 | CODE: |
1543 | RETVAL = cf_player_find (cf_query_name (op)); |
1637 | RETVAL = op->contr; |
1544 | OUTPUT: RETVAL |
1638 | OUTPUT: RETVAL |
1545 | |
1639 | |
1546 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1640 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1547 | |
1641 | |
1548 | object *cf_player_send_inventory (object *op) |
1642 | object *cf_player_send_inventory (object *op) |
… | |
… | |
1565 | |
1659 | |
1566 | void cf_player_set_party (object *op, partylist *party) |
1660 | void cf_player_set_party (object *op, partylist *party) |
1567 | |
1661 | |
1568 | void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) |
1662 | void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) |
1569 | |
1663 | |
|
|
1664 | void kill_player (object *op) |
|
|
1665 | |
1570 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1666 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1571 | |
1667 | |
1572 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1668 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1573 | |
1669 | |
1574 | player *cf_player_find (char *name) |
1670 | player *cf_player_find (char *name) |
… | |
… | |
1593 | |
1689 | |
1594 | player *next (player *pl) |
1690 | player *next (player *pl) |
1595 | CODE: |
1691 | CODE: |
1596 | RETVAL = pl->next; |
1692 | RETVAL = pl->next; |
1597 | OUTPUT: RETVAL |
1693 | OUTPUT: RETVAL |
|
|
1694 | |
|
|
1695 | bool |
|
|
1696 | cell_visible (player *pl, int dx, int dy) |
|
|
1697 | CODE: |
|
|
1698 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
|
|
1699 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
|
|
1700 | OUTPUT: |
|
|
1701 | RETVAL |
|
|
1702 | |
|
|
1703 | void |
|
|
1704 | send (player *pl, SV *packet) |
|
|
1705 | CODE: |
|
|
1706 | { |
|
|
1707 | STRLEN len; |
|
|
1708 | char *buf = SvPVbyte (packet, len); |
|
|
1709 | |
|
|
1710 | Write_String_To_Socket (&pl->socket, buf, len); |
|
|
1711 | } |
|
|
1712 | |
|
|
1713 | int |
|
|
1714 | listening (player *pl, int new_value = -1) |
|
|
1715 | CODE: |
|
|
1716 | RETVAL = pl->listening; |
|
|
1717 | if (new_value >= 0) |
|
|
1718 | pl->listening = new_value; |
|
|
1719 | OUTPUT: |
|
|
1720 | RETVAL |
1598 | |
1721 | |
1599 | void get_savebed (player *pl) |
1722 | void get_savebed (player *pl) |
1600 | ALIAS: |
1723 | ALIAS: |
1601 | savebed = 0 |
1724 | savebed = 0 |
1602 | PPCODE: |
1725 | PPCODE: |
… | |
… | |
1618 | player *pl; |
1741 | player *pl; |
1619 | for (pl = first_player; pl; pl = pl->next) |
1742 | for (pl = first_player; pl; pl = pl->next) |
1620 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
1743 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
1621 | } |
1744 | } |
1622 | |
1745 | |
|
|
1746 | bool |
|
|
1747 | peaceful (player *pl, bool new_setting = 0) |
|
|
1748 | PROTOTYPE: $;$ |
|
|
1749 | CODE: |
|
|
1750 | RETVAL = pl->peaceful; |
|
|
1751 | if (items > 1) |
|
|
1752 | pl->peaceful = new_setting; |
|
|
1753 | OUTPUT: |
|
|
1754 | RETVAL |
|
|
1755 | |
1623 | living * |
1756 | living * |
1624 | orig_stats (player *pl) |
1757 | orig_stats (player *pl) |
1625 | CODE: |
1758 | CODE: |
1626 | RETVAL = &pl->orig_stats; |
1759 | RETVAL = &pl->orig_stats; |
1627 | OUTPUT: RETVAL |
1760 | OUTPUT: RETVAL |
… | |
… | |
1667 | |
1800 | |
1668 | void clean_tmp_map (mapstruct *map) |
1801 | void clean_tmp_map (mapstruct *map) |
1669 | |
1802 | |
1670 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1803 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1671 | |
1804 | |
|
|
1805 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
|
|
1806 | CODE: |
|
|
1807 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
|
|
1808 | OUTPUT: |
|
|
1809 | RETVAL |
|
|
1810 | |
|
|
1811 | char *tile_path (mapstruct *map, unsigned int dir) |
|
|
1812 | CODE: |
|
|
1813 | if (dir >= 4) |
|
|
1814 | XSRETURN_UNDEF; |
|
|
1815 | RETVAL = map->tile_path [dir]; |
|
|
1816 | OUTPUT: |
|
|
1817 | RETVAL |
|
|
1818 | |
1672 | mapstruct *cf_map_get_map (char *name) |
1819 | mapstruct *cf_map_get_map (char *name) |
1673 | PROTOTYPE: $ |
1820 | PROTOTYPE: $ |
1674 | ALIAS: map = 0 |
1821 | ALIAS: map = 0 |
1675 | |
1822 | |
|
|
1823 | mapstruct *has_been_loaded (char *name) |
|
|
1824 | PROTOTYPE: $ |
|
|
1825 | |
1676 | mapstruct *cf_map_get_first () |
1826 | mapstruct *cf_map_get_first () |
1677 | PROTOTYPE: |
1827 | PROTOTYPE: |
1678 | ALIAS: first = 0 |
1828 | ALIAS: first = 0 |
1679 | |
1829 | |
1680 | # whoever "designed" the plug-in api should have wasted |
1830 | # whoever "designed" the plug-in api should have wasted |
1681 | # his/her time with staying away form the project - would have |
1831 | # his/her time with staying away from the project - would have |
1682 | # saved others a lot of time, without doubt. |
1832 | # saved others a lot of time, without doubt. |
1683 | void set_path (mapstruct *where, char *path) |
1833 | void set_path (mapstruct *where, char *path) |
1684 | CODE: |
1834 | CODE: |
1685 | strcpy (where->path, path); |
1835 | strcpy (where->path, path); |
|
|
1836 | |
|
|
1837 | int in_memory (mapstruct *map) |
|
|
1838 | CODE: |
|
|
1839 | RETVAL = map->in_memory; |
|
|
1840 | OUTPUT: |
|
|
1841 | RETVAL |
1686 | |
1842 | |
1687 | bool unique (mapstruct *map) |
1843 | bool unique (mapstruct *map) |
1688 | CODE: |
1844 | CODE: |
1689 | RETVAL = map->unique; |
1845 | RETVAL = map->unique; |
1690 | OUTPUT: |
1846 | OUTPUT: |
… | |
… | |
1699 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1855 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1700 | |
1856 | |
1701 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1857 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1702 | C_ARGS: str, map, nx, ny |
1858 | C_ARGS: str, map, nx, ny |
1703 | |
1859 | |
1704 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
|
|
1705 | |
|
|
1706 | void |
1860 | void |
|
|
1861 | cf_map_normalise (mapstruct *map, int x, int y) |
|
|
1862 | PPCODE: |
|
|
1863 | { |
|
|
1864 | mapstruct *nmap = 0; |
|
|
1865 | I16 nx = 0, ny = 0; |
|
|
1866 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
1867 | |
|
|
1868 | EXTEND (SP, 4); |
|
|
1869 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
1870 | |
|
|
1871 | if (GIMME_V == G_ARRAY) |
|
|
1872 | { |
|
|
1873 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); |
|
|
1874 | PUSHs (sv_2mortal (newSViv (nx))); |
|
|
1875 | PUSHs (sv_2mortal (newSViv (ny))); |
|
|
1876 | } |
|
|
1877 | } |
|
|
1878 | |
|
|
1879 | void |
1707 | at (mapstruct *obj, unsigned int x, unsigned int y) |
1880 | at (mapstruct *map, unsigned int x, unsigned int y) |
1708 | PROTOTYPE: $$$ |
1881 | PROTOTYPE: $$$ |
1709 | INIT: |
|
|
1710 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY; |
|
|
1711 | PPCODE: |
1882 | PPCODE: |
1712 | { |
1883 | { |
1713 | object *o; |
1884 | object *o; |
1714 | |
1885 | mapstruct *nmap = 0; |
|
|
1886 | I16 nx, ny; |
|
|
1887 | |
|
|
1888 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
1889 | |
|
|
1890 | if (nmap) |
1715 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
1891 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
1716 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1892 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1717 | } |
1893 | } |
1718 | |
1894 | |
1719 | SV * |
1895 | SV * |
1720 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1896 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1721 | PROTOTYPE: $$$ |
1897 | PROTOTYPE: $$$ |