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 | |
|
|
53 | extern sint64 *levels; // the experience table |
52 | |
54 | |
53 | typedef object object_ornull; |
55 | typedef object object_ornull; |
54 | typedef mapstruct mapstruct_ornull; |
56 | typedef mapstruct mapstruct_ornull; |
55 | |
57 | |
56 | static f_plug_api gethook; |
58 | static f_plug_api gethook; |
… | |
… | |
78 | } CFPContext; |
80 | } CFPContext; |
79 | |
81 | |
80 | static HV *obj_cache; |
82 | static HV *obj_cache; |
81 | static PerlInterpreter *perl; |
83 | static PerlInterpreter *perl; |
82 | |
84 | |
|
|
85 | #define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value)))) |
83 | #define PUSHcfapi(type,ctype) PUSHs (sv_2mortal (newSVcfapi ((type), va_arg (args, ctype)))) |
86 | #define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype)) |
84 | #define PUSH_OB PUSHcfapi(CFAPI_POBJECT, object *) |
87 | #define PUSH_OB PUSHcfapi_va(POBJECT, object *) |
85 | #define PUSH_PL PUSHcfapi(CFAPI_PPLAYER, player *) |
88 | #define PUSH_PL PUSHcfapi_va(PPLAYER, player *) |
86 | #define PUSH_MAP PUSHcfapi(CFAPI_PMAP, mapstruct *) |
89 | #define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) |
87 | #define PUSH_PV PUSHcfapi(CFAPI_STRING, const char *) |
90 | #define PUSH_PV PUSHcfapi_va(STRING, const char *) |
88 | #define PUSH_IV PUSHcfapi(CFAPI_INT, int) |
91 | #define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) |
|
|
92 | |
|
|
93 | extern void pay_player(object *op, uint64 amount); |
|
|
94 | extern uint64 pay_player_arch(object *op, const char *arch, uint64 amount); |
89 | |
95 | |
90 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
96 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
91 | |
97 | |
92 | // garbage collect some perl objects, if possible |
98 | // garbage collect some perl objects, if possible |
93 | // all objects no longer referenced and empty are |
99 | // all objects no longer referenced and empty are |
… | |
… | |
229 | case CFAPI_LONG: |
235 | case CFAPI_LONG: |
230 | sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ |
236 | sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ |
231 | break; |
237 | break; |
232 | |
238 | |
233 | case CFAPI_DOUBLE: |
239 | case CFAPI_DOUBLE: |
234 | sv = newSViv (*va_arg (args, double *)); |
240 | sv = newSVnv (*va_arg (args, double *)); |
235 | break; |
241 | break; |
236 | |
242 | |
237 | case CFAPI_STRING: |
243 | case CFAPI_STRING: |
238 | { |
244 | { |
239 | char *str = va_arg (args, char *); |
245 | char *str = va_arg (args, char *); |
… | |
… | |
246 | object *obj = va_arg (args, object *); |
252 | object *obj = va_arg (args, object *); |
247 | |
253 | |
248 | if (!obj) |
254 | if (!obj) |
249 | sv = &PL_sv_undef; |
255 | sv = &PL_sv_undef; |
250 | else |
256 | else |
251 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
257 | switch (obj->type) |
252 | { |
258 | { |
253 | case MAP: |
259 | case MAP: |
254 | sv = newSVptr_cached (obj, "cf::object::map"); |
260 | sv = newSVptr_cached (obj, "cf::object::map"); |
255 | break; |
261 | break; |
256 | |
262 | |
… | |
… | |
292 | va_end (args); |
298 | va_end (args); |
293 | |
299 | |
294 | return sv; |
300 | return sv; |
295 | } |
301 | } |
296 | |
302 | |
297 | ///////////////////////////////////////////////////////////////////////////// |
|
|
298 | |
|
|
299 | void |
|
|
300 | inject_event (const char *func, CFPContext *context) |
|
|
301 | { |
|
|
302 | dSP; |
|
|
303 | |
|
|
304 | ENTER; |
|
|
305 | SAVETMPS; |
|
|
306 | |
|
|
307 | PUSHMARK (SP); |
|
|
308 | |
|
|
309 | EXTEND (SP, 10); |
|
|
310 | |
|
|
311 | HV *hv = newHV (); |
|
|
312 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
|
|
313 | hv_context (CFAPI_POBJECT, ,who); |
|
|
314 | hv_context (CFAPI_POBJECT, ,activator); |
|
|
315 | hv_context (CFAPI_POBJECT, ,third); |
|
|
316 | hv_context (CFAPI_POBJECT, ,event); |
|
|
317 | hv_context (CFAPI_PMAP, ,map); |
|
|
318 | hv_context (CFAPI_STRING , ,message); |
|
|
319 | hv_context (CFAPI_INT ,&,fix); |
|
|
320 | hv_context (CFAPI_INT ,&,event_code); |
|
|
321 | hv_context (CFAPI_STRING , ,options); |
|
|
322 | hv_context (CFAPI_STRING , ,extension); |
|
|
323 | |
|
|
324 | PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
325 | |
|
|
326 | PUTBACK; |
|
|
327 | int count = call_pv (func, G_SCALAR | G_EVAL); |
|
|
328 | SPAGAIN; |
|
|
329 | |
|
|
330 | if (SvTRUE (ERRSV)) |
|
|
331 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
|
|
332 | |
|
|
333 | context->returnvalue = count > 0 ? POPi : 0; |
|
|
334 | |
|
|
335 | PUTBACK; |
|
|
336 | FREETMPS; |
|
|
337 | LEAVE; |
|
|
338 | } |
|
|
339 | |
|
|
340 | ///////////////////////////////////////////////////////////////////////////// |
303 | ///////////////////////////////////////////////////////////////////////////// |
341 | |
304 | |
342 | int |
305 | int |
343 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
306 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
344 | { |
307 | { |
… | |
… | |
451 | |
414 | |
452 | /* Pick the global events you want to monitor from this plugin */ |
415 | /* Pick the global events you want to monitor from this plugin */ |
453 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
416 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
454 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
417 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
455 | //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener); |
418 | //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener); |
|
|
419 | registerGlobalEvent (NULL, EVENT_FIND_UNARMED_SKILL, PLUGIN_NAME, globalEventListener); |
|
|
420 | registerGlobalEvent (NULL, EVENT_PLAYER_USE_SKILL, PLUGIN_NAME, globalEventListener); |
|
|
421 | registerGlobalEvent (NULL, EVENT_MONSTER_USE_SKILL, PLUGIN_NAME, globalEventListener); |
456 | registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener); |
422 | registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener); |
457 | registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener); |
423 | registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener); |
458 | registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); |
424 | registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); |
459 | registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); |
425 | registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); |
460 | registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); |
426 | registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); |
… | |
… | |
470 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
436 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
471 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
437 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
472 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
438 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
473 | registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); |
439 | registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); |
474 | registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); |
440 | registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); |
|
|
441 | registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener); |
475 | |
442 | |
476 | char *argv[] = { |
443 | char *argv[] = { |
477 | "", |
444 | "", |
478 | "-e" |
445 | "-e" |
479 | "BEGIN {" |
446 | "BEGIN {" |
… | |
… | |
485 | }; |
452 | }; |
486 | |
453 | |
487 | perl = perl_alloc (); |
454 | perl = perl_alloc (); |
488 | perl_construct (perl); |
455 | perl_construct (perl); |
489 | |
456 | |
|
|
457 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
458 | |
490 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
459 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
491 | { |
460 | { |
492 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
461 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
493 | |
462 | |
494 | perl_destruct (perl); |
463 | perl_destruct (perl); |
… | |
… | |
528 | if (sv) |
497 | if (sv) |
529 | clearSVptr (sv); |
498 | clearSVptr (sv); |
530 | |
499 | |
531 | rv = 0; |
500 | rv = 0; |
532 | } |
501 | } |
|
|
502 | else if (event_code == EVENT_CLOCK) |
|
|
503 | { |
|
|
504 | dSP; |
|
|
505 | int i, count; |
|
|
506 | |
|
|
507 | clean_obj_cache (); |
|
|
508 | |
|
|
509 | ENTER; |
|
|
510 | SAVETMPS; |
|
|
511 | |
|
|
512 | // service up to 8 events per tick better would be |
|
|
513 | // to check for elapsed time and stop processing after |
|
|
514 | // 0.25 * server_tick or so |
|
|
515 | for (i = 9; --i; ) |
|
|
516 | { |
|
|
517 | PUSHMARK (SP); |
|
|
518 | XPUSHs (sv_2mortal (newSViv (0))); |
|
|
519 | PUTBACK; |
|
|
520 | count = call_pv ("Event::one_event", G_SCALAR | G_EVAL); |
|
|
521 | SPAGAIN; |
|
|
522 | |
|
|
523 | if (!count || !POPi) |
|
|
524 | break; |
|
|
525 | } |
|
|
526 | |
|
|
527 | FREETMPS; |
|
|
528 | LEAVE; |
|
|
529 | } |
533 | else |
530 | else |
534 | { |
531 | { |
535 | dSP; |
532 | dSP; |
536 | |
533 | |
537 | ENTER; |
534 | ENTER; |
… | |
… | |
585 | case EVENT_KICK: |
582 | case EVENT_KICK: |
586 | PUSH_OB; |
583 | PUSH_OB; |
587 | PUSH_PV; |
584 | PUSH_PV; |
588 | break; |
585 | break; |
589 | |
586 | |
|
|
587 | case EVENT_FIND_UNARMED_SKILL: |
|
|
588 | PUSH_OB; |
|
|
589 | break; |
|
|
590 | |
|
|
591 | case EVENT_PLAYER_USE_SKILL: |
|
|
592 | case EVENT_MONSTER_USE_SKILL: |
|
|
593 | PUSH_OB; |
|
|
594 | PUSH_OB; |
|
|
595 | PUSH_OB; |
|
|
596 | PUSH_IV; |
|
|
597 | PUSH_PV; |
|
|
598 | break; |
|
|
599 | |
590 | case EVENT_CLOCK: |
600 | case EVENT_EXTCMD: |
591 | clean_obj_cache (); |
601 | PUSH_PL; |
|
|
602 | { |
|
|
603 | char *buf = va_arg (args, char *); |
|
|
604 | int len = va_arg (args, int); |
|
|
605 | PUSHs (sv_2mortal (newSVpvn (buf, len))); |
|
|
606 | } |
592 | break; |
607 | break; |
593 | |
608 | |
594 | case EVENT_TELL: |
609 | case EVENT_TELL: |
595 | break; |
610 | break; |
596 | } |
611 | } |
… | |
… | |
600 | PUTBACK; |
615 | PUTBACK; |
601 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
616 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
602 | SPAGAIN; |
617 | SPAGAIN; |
603 | |
618 | |
604 | if (SvTRUE (ERRSV)) |
619 | if (SvTRUE (ERRSV)) |
605 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
620 | LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
606 | |
621 | |
607 | rv = count > 0 ? POPi : 0; |
622 | rv = count > 0 ? POPi : 0; |
608 | |
623 | |
609 | PUTBACK; |
624 | PUTBACK; |
610 | FREETMPS; |
625 | FREETMPS; |
… | |
… | |
615 | } |
630 | } |
616 | |
631 | |
617 | void * |
632 | void * |
618 | eventListener (int *type, ...) |
633 | eventListener (int *type, ...) |
619 | { |
634 | { |
620 | static int rv = 0; |
635 | static int rv; |
621 | va_list args; |
636 | va_list args; |
622 | char *buf; |
637 | int event_code; |
623 | CFPContext context; |
638 | object *who, *activator, *third, *event; |
|
|
639 | char *message, *extension, *options; |
624 | |
640 | |
625 | if (!perl) |
641 | if (!perl) |
626 | return; |
642 | return; |
627 | |
643 | |
628 | memset (&context, 0, sizeof (context)); |
|
|
629 | |
|
|
630 | va_start (args, type); |
644 | va_start (args, type); |
631 | |
|
|
632 | context.who = va_arg (args, object *); |
645 | who = va_arg (args, object *); |
633 | context.event_code = va_arg (args, int); |
646 | event_code = va_arg (args, int); |
634 | context.activator = va_arg (args, object *); |
647 | activator = va_arg (args, object *); |
635 | context.third = va_arg (args, object *); |
648 | third = va_arg (args, object *); |
636 | |
|
|
637 | buf = va_arg (args, char *); |
649 | message = va_arg (args, char *); |
638 | if (buf != 0) |
650 | va_arg (args, int); // fix yourself |
639 | strncpy (context.message, buf, sizeof (context.message)); |
651 | extension = va_arg (args, char *); |
640 | |
652 | options = va_arg (args, char *); |
641 | context.fix = va_arg (args, int); |
|
|
642 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
|
|
643 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
|
|
644 | context.event = va_arg (args, object *); |
653 | event = va_arg (args, object *); |
645 | va_end (args); |
654 | va_end (args); |
646 | |
655 | |
647 | context.returnvalue = 0; |
656 | { |
|
|
657 | dSP; |
648 | |
658 | |
649 | inject_event ("cf::inject_event", &context); |
659 | ENTER; |
|
|
660 | SAVETMPS; |
|
|
661 | |
|
|
662 | PUSHMARK (SP); |
|
|
663 | EXTEND (SP, 10); |
|
|
664 | |
|
|
665 | PUSHcfapi (STRING, extension); |
|
|
666 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
667 | |
|
|
668 | PUSHcfapi (POBJECT, event); |
|
|
669 | PUSHcfapi (POBJECT, who); |
|
|
670 | |
|
|
671 | switch (event_code) |
|
|
672 | { |
|
|
673 | case EVENT_STOP: // $ob (e.g. arrow) |
|
|
674 | case EVENT_TIME: // $ob |
|
|
675 | case EVENT_TIMER: // $ob |
|
|
676 | break; |
|
|
677 | |
|
|
678 | case EVENT_APPLY: // $ob, $who |
|
|
679 | case EVENT_DROP: // $ob, $who |
|
|
680 | case EVENT_CLOSE: // $ob, $who |
|
|
681 | case EVENT_DEATH: // $ob[, $killer] |
|
|
682 | case EVENT_MOVE: // $ob, $enemy |
|
|
683 | case EVENT_THROW: // $ob, $thrower |
|
|
684 | PUSHcfapi (POBJECT, activator); |
|
|
685 | break; |
|
|
686 | |
|
|
687 | case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me) |
|
|
688 | PUSHcfapi (POBJECT, activator); |
|
|
689 | PUSHcfapi (POBJECT, third); |
|
|
690 | break; |
|
|
691 | |
|
|
692 | case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg] |
|
|
693 | PUSHcfapi (POBJECT, activator); |
|
|
694 | PUSHcfapi (POBJECT, third); |
|
|
695 | PUSHcfapi (POBJECT, message); |
|
|
696 | break; |
|
|
697 | |
|
|
698 | case EVENT_SAY: // $ob, $who, $msg |
|
|
699 | PUSHcfapi (POBJECT, activator); |
|
|
700 | PUSHcfapi (STRING, message); |
|
|
701 | break; |
|
|
702 | |
|
|
703 | default: |
|
|
704 | LOG (llevError, "perl plugin called for unsupported event type %d", event_code); |
|
|
705 | break; |
|
|
706 | } |
|
|
707 | |
|
|
708 | PUTBACK; |
|
|
709 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
|
|
710 | SPAGAIN; |
|
|
711 | |
|
|
712 | if (SvTRUE (ERRSV)) |
|
|
713 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
714 | |
|
|
715 | rv = count > 0 ? POPi : 0; |
|
|
716 | |
|
|
717 | PUTBACK; |
|
|
718 | FREETMPS; |
|
|
719 | LEAVE; |
|
|
720 | } |
650 | |
721 | |
651 | rv = context.returnvalue; |
|
|
652 | return &rv; |
722 | return &rv; |
653 | } |
723 | } |
654 | |
724 | |
655 | int |
725 | int |
656 | closePlugin () |
726 | closePlugin () |
… | |
… | |
1076 | const_iv (SK_SUMMONING) |
1146 | const_iv (SK_SUMMONING) |
1077 | const_iv (SK_PYROMANCY) |
1147 | const_iv (SK_PYROMANCY) |
1078 | const_iv (SK_EVOCATION) |
1148 | const_iv (SK_EVOCATION) |
1079 | const_iv (SK_SORCERY) |
1149 | const_iv (SK_SORCERY) |
1080 | const_iv (SK_TWO_HANDED_WEAPON) |
1150 | const_iv (SK_TWO_HANDED_WEAPON) |
|
|
1151 | const_iv (SK_SPARK_TOUCH) |
|
|
1152 | const_iv (SK_SHIVER) |
|
|
1153 | const_iv (SK_ACID_SPLASH) |
|
|
1154 | const_iv (SK_POISON_NAIL) |
1081 | |
1155 | |
1082 | const_iv (SOUND_NEW_PLAYER) |
1156 | const_iv (SOUND_NEW_PLAYER) |
1083 | const_iv (SOUND_FIRE_ARROW) |
1157 | const_iv (SOUND_FIRE_ARROW) |
1084 | const_iv (SOUND_LEARN_SPELL) |
1158 | const_iv (SOUND_LEARN_SPELL) |
1085 | const_iv (SOUND_FUMBLE_SPELL) |
1159 | const_iv (SOUND_FUMBLE_SPELL) |
… | |
… | |
1101 | const_iv (SOUND_CLOCK) |
1175 | const_iv (SOUND_CLOCK) |
1102 | const_iv (SOUND_TURN_HANDLE) |
1176 | const_iv (SOUND_TURN_HANDLE) |
1103 | const_iv (SOUND_FALL_HOLE) |
1177 | const_iv (SOUND_FALL_HOLE) |
1104 | const_iv (SOUND_DRINK_POISON) |
1178 | const_iv (SOUND_DRINK_POISON) |
1105 | const_iv (SOUND_CAST_SPELL_0) |
1179 | const_iv (SOUND_CAST_SPELL_0) |
|
|
1180 | |
|
|
1181 | const_iv (PREFER_LOW) |
|
|
1182 | const_iv (PREFER_HIGH) |
|
|
1183 | |
|
|
1184 | const_iv (ATNR_PHYSICAL) |
|
|
1185 | const_iv (ATNR_MAGIC) |
|
|
1186 | const_iv (ATNR_FIRE) |
|
|
1187 | const_iv (ATNR_ELECTRICITY) |
|
|
1188 | const_iv (ATNR_COLD) |
|
|
1189 | const_iv (ATNR_CONFUSION) |
|
|
1190 | const_iv (ATNR_ACID) |
|
|
1191 | const_iv (ATNR_DRAIN) |
|
|
1192 | const_iv (ATNR_WEAPONMAGIC) |
|
|
1193 | const_iv (ATNR_GHOSTHIT) |
|
|
1194 | const_iv (ATNR_POISON) |
|
|
1195 | const_iv (ATNR_SLOW) |
|
|
1196 | const_iv (ATNR_PARALYZE) |
|
|
1197 | const_iv (ATNR_TURN_UNDEAD) |
|
|
1198 | const_iv (ATNR_FEAR) |
|
|
1199 | const_iv (ATNR_CANCELLATION) |
|
|
1200 | const_iv (ATNR_DEPLETE) |
|
|
1201 | const_iv (ATNR_DEATH) |
|
|
1202 | const_iv (ATNR_CHAOS) |
|
|
1203 | const_iv (ATNR_COUNTERSPELL) |
|
|
1204 | const_iv (ATNR_GODPOWER) |
|
|
1205 | const_iv (ATNR_HOLYWORD) |
|
|
1206 | const_iv (ATNR_BLIND) |
|
|
1207 | const_iv (ATNR_INTERNAL) |
|
|
1208 | const_iv (ATNR_LIFE_STEALING) |
|
|
1209 | const_iv (ATNR_DISEASE) |
|
|
1210 | |
|
|
1211 | const_iv (MAP_FLUSH) |
|
|
1212 | const_iv (MAP_PLAYER_UNIQUE) |
|
|
1213 | const_iv (MAP_BLOCK) |
|
|
1214 | const_iv (MAP_STYLE) |
|
|
1215 | const_iv (MAP_OVERLAY) |
|
|
1216 | |
|
|
1217 | const_iv (MAP_IN_MEMORY) |
|
|
1218 | const_iv (MAP_SWAPPED) |
|
|
1219 | const_iv (MAP_LOADING) |
|
|
1220 | const_iv (MAP_SAVING) |
1106 | }; |
1221 | }; |
1107 | |
1222 | |
1108 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1223 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1109 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1224 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1110 | |
1225 | |
… | |
… | |
1127 | const_event (CLOSE) |
1242 | const_event (CLOSE) |
1128 | const_event (TIMER) |
1243 | const_event (TIMER) |
1129 | const_event (MOVE) |
1244 | const_event (MOVE) |
1130 | |
1245 | |
1131 | const_event (BORN) |
1246 | const_event (BORN) |
1132 | const_event (CLOCK) |
1247 | //const_event (CLOCK) |
1133 | const_event (CRASH) |
1248 | const_event (CRASH) |
1134 | const_event (PLAYER_DEATH) |
1249 | const_event (PLAYER_DEATH) |
1135 | const_event (PLAYER_LOAD) |
1250 | const_event (PLAYER_LOAD) |
1136 | const_event (PLAYER_SAVE) |
1251 | const_event (PLAYER_SAVE) |
1137 | const_event (GKILL) |
1252 | const_event (GKILL) |
… | |
… | |
1147 | const_event (REMOVE) |
1262 | const_event (REMOVE) |
1148 | const_event (SHOUT) |
1263 | const_event (SHOUT) |
1149 | const_event (TELL) |
1264 | const_event (TELL) |
1150 | const_event (MUZZLE) |
1265 | const_event (MUZZLE) |
1151 | const_event (KICK) |
1266 | const_event (KICK) |
|
|
1267 | const_event (PLAYER_USE_SKILL) |
|
|
1268 | const_event (MONSTER_USE_SKILL) |
|
|
1269 | const_event (FIND_UNARMED_SKILL) |
|
|
1270 | const_event (EXTCMD) |
1152 | //const_event (FREE_OB) |
1271 | //const_event (FREE_OB) |
1153 | }; |
1272 | }; |
1154 | |
1273 | |
1155 | AV *av = get_av ("cf::EVENT", 1); |
1274 | AV *av = get_av ("cf::EVENT", 1); |
1156 | |
1275 | |
… | |
… | |
1290 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1409 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1291 | { |
1410 | { |
1292 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1411 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1293 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1412 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1294 | } |
1413 | } |
|
|
1414 | |
|
|
1415 | //I_EVENT_API (PACKAGE); |
1295 | } |
1416 | } |
1296 | |
1417 | |
1297 | void |
1418 | void |
1298 | LOG (int level, char *msg) |
1419 | LOG (int level, char *msg) |
1299 | PROTOTYPE: $$ |
1420 | PROTOTYPE: $$ |
1300 | C_ARGS: level, "%s", msg |
1421 | C_ARGS: level, "%s", msg |
|
|
1422 | |
|
|
1423 | char *path_combine (char *base, char *path) |
|
|
1424 | PROTOTYPE: $$ |
|
|
1425 | |
|
|
1426 | char *path_combine_and_normalize (char *base, char *path) |
|
|
1427 | PROTOTYPE: $$ |
1301 | |
1428 | |
1302 | char * |
1429 | char * |
1303 | cf_get_maps_directory (char *path) |
1430 | cf_get_maps_directory (char *path) |
1304 | PROTOTYPE: $ |
1431 | PROTOTYPE: $ |
1305 | ALIAS: maps_directory = 0 |
1432 | ALIAS: maps_directory = 0 |
… | |
… | |
1323 | OUTPUT: RETVAL |
1450 | OUTPUT: RETVAL |
1324 | |
1451 | |
1325 | int |
1452 | int |
1326 | cf_find_animation (char *text) |
1453 | cf_find_animation (char *text) |
1327 | PROTOTYPE: $ |
1454 | PROTOTYPE: $ |
|
|
1455 | |
|
|
1456 | int random_roll(int min, int max, object *op, int goodbad); |
|
|
1457 | |
|
|
1458 | int |
|
|
1459 | exp_to_level (double exp) |
|
|
1460 | CODE: |
|
|
1461 | int i = 0; |
|
|
1462 | RETVAL = 0; |
|
|
1463 | for (i = 1; i <= settings.max_level; i++) |
|
|
1464 | { |
|
|
1465 | if (levels[i] > exp) |
|
|
1466 | { |
|
|
1467 | RETVAL = i - 1; |
|
|
1468 | break; |
|
|
1469 | } |
|
|
1470 | } |
|
|
1471 | OUTPUT: RETVAL |
|
|
1472 | |
|
|
1473 | double |
|
|
1474 | level_to_min_exp (int level) |
|
|
1475 | CODE: |
|
|
1476 | RETVAL = 0; |
|
|
1477 | if (level > settings.max_level) |
|
|
1478 | RETVAL = levels[settings.max_level]; |
|
|
1479 | else if (level < 1) |
|
|
1480 | RETVAL = 0; |
|
|
1481 | else |
|
|
1482 | RETVAL = levels[level]; |
|
|
1483 | OUTPUT: RETVAL |
|
|
1484 | |
|
|
1485 | SV * |
|
|
1486 | resistance_to_string (int atnr) |
|
|
1487 | CODE: |
|
|
1488 | if (atnr >= 0 && atnr < NROFATTACKS) |
|
|
1489 | { |
|
|
1490 | RETVAL = newSVpv (resist_plus[atnr], 0); |
|
|
1491 | } |
|
|
1492 | else |
|
|
1493 | { |
|
|
1494 | XSRETURN_UNDEF; |
|
|
1495 | } |
|
|
1496 | OUTPUT: RETVAL |
1328 | |
1497 | |
1329 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1498 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1330 | |
1499 | |
1331 | SV * |
1500 | SV * |
1332 | get_property (object *obj, int type, int idx) |
1501 | get_property (object *obj, int type, int idx) |
… | |
… | |
1474 | |
1643 | |
1475 | void cf_object_update (object *op, int flags) |
1644 | void cf_object_update (object *op, int flags) |
1476 | |
1645 | |
1477 | void cf_object_pickup (object *op, object *what) |
1646 | void cf_object_pickup (object *op, object *what) |
1478 | |
1647 | |
|
|
1648 | object *cf_create_object_by_name (const char *name) |
|
|
1649 | |
|
|
1650 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
|
|
1651 | |
|
|
1652 | void pay_player (object *op, double amount) |
|
|
1653 | |
|
|
1654 | double pay_player_arch (object *op, const char *arch, double amount) |
|
|
1655 | |
|
|
1656 | void player_lvl_adj (object *who, object *skill = 0) |
|
|
1657 | |
|
|
1658 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
|
|
1659 | |
|
|
1660 | int calc_skill_exp (object *who, object *op, object *skill); |
|
|
1661 | |
1479 | char *cf_object_get_key (object *op, char *keyname) |
1662 | char *cf_object_get_key (object *op, char *keyname) |
1480 | ALIAS: key = 0 |
1663 | ALIAS: key = 0 |
1481 | |
1664 | |
1482 | void cf_object_set_key (object *op, char *keyname, char *value) |
1665 | void cf_object_set_key (object *op, char *keyname, char *value) |
1483 | |
1666 | |
1484 | object *cf_create_object_by_name (const char *name) |
1667 | void |
1485 | |
1668 | cf_object_set_resistance (object *op, int rtype, int val) |
1486 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
1669 | CODE: |
1487 | |
1670 | if (rtype >= 0 && rtype < NROFATTACKS) |
1488 | void player_lvl_adj (object *who, object *skill = 0) |
1671 | op->resist[rtype] = val; |
1489 | |
1672 | |
1490 | |
1673 | |
1491 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1674 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1492 | |
1675 | |
1493 | void cf_fix_object (object *pl) |
1676 | void cf_fix_object (object *pl) |
… | |
… | |
1510 | CODE: |
1693 | CODE: |
1511 | { |
1694 | { |
1512 | int unused_type; |
1695 | int unused_type; |
1513 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1696 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1514 | } |
1697 | } |
|
|
1698 | |
|
|
1699 | # syntatic sugar for easier use in event callbacks. |
|
|
1700 | const char *options (object *op) |
|
|
1701 | CODE: |
|
|
1702 | RETVAL = op->name; |
|
|
1703 | OUTPUT: |
|
|
1704 | RETVAL |
1515 | |
1705 | |
1516 | const char *get_ob_key_value (object *op, const char *key) |
1706 | const char *get_ob_key_value (object *op, const char *key) |
1517 | |
1707 | |
1518 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1708 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1519 | |
1709 | |
… | |
… | |
1556 | |
1746 | |
1557 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1747 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1558 | |
1748 | |
1559 | player *player (object *op) |
1749 | player *player (object *op) |
1560 | CODE: |
1750 | CODE: |
1561 | RETVAL = cf_player_find (cf_query_name (op)); |
1751 | RETVAL = op->contr; |
1562 | OUTPUT: RETVAL |
1752 | OUTPUT: RETVAL |
1563 | |
1753 | |
1564 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1754 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1565 | |
1755 | |
1566 | object *cf_player_send_inventory (object *op) |
1756 | object *cf_player_send_inventory (object *op) |
… | |
… | |
1583 | |
1773 | |
1584 | void cf_player_set_party (object *op, partylist *party) |
1774 | void cf_player_set_party (object *op, partylist *party) |
1585 | |
1775 | |
1586 | void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) |
1776 | void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) |
1587 | |
1777 | |
|
|
1778 | void kill_player (object *op) |
|
|
1779 | |
1588 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1780 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1589 | |
1781 | |
1590 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1782 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1591 | |
1783 | |
1592 | player *cf_player_find (char *name) |
1784 | player *cf_player_find (char *name) |
… | |
… | |
1611 | |
1803 | |
1612 | player *next (player *pl) |
1804 | player *next (player *pl) |
1613 | CODE: |
1805 | CODE: |
1614 | RETVAL = pl->next; |
1806 | RETVAL = pl->next; |
1615 | OUTPUT: RETVAL |
1807 | OUTPUT: RETVAL |
|
|
1808 | |
|
|
1809 | bool |
|
|
1810 | cell_visible (player *pl, int dx, int dy) |
|
|
1811 | CODE: |
|
|
1812 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
|
|
1813 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
|
|
1814 | OUTPUT: |
|
|
1815 | RETVAL |
|
|
1816 | |
|
|
1817 | void |
|
|
1818 | send (player *pl, SV *packet) |
|
|
1819 | CODE: |
|
|
1820 | { |
|
|
1821 | STRLEN len; |
|
|
1822 | char *buf = SvPVbyte (packet, len); |
|
|
1823 | |
|
|
1824 | Write_String_To_Socket (&pl->socket, buf, len); |
|
|
1825 | } |
|
|
1826 | |
|
|
1827 | int |
|
|
1828 | listening (player *pl, int new_value = -1) |
|
|
1829 | CODE: |
|
|
1830 | RETVAL = pl->listening; |
|
|
1831 | if (new_value >= 0) |
|
|
1832 | pl->listening = new_value; |
|
|
1833 | OUTPUT: |
|
|
1834 | RETVAL |
1616 | |
1835 | |
1617 | void get_savebed (player *pl) |
1836 | void get_savebed (player *pl) |
1618 | ALIAS: |
1837 | ALIAS: |
1619 | savebed = 0 |
1838 | savebed = 0 |
1620 | PPCODE: |
1839 | PPCODE: |
… | |
… | |
1695 | |
1914 | |
1696 | void clean_tmp_map (mapstruct *map) |
1915 | void clean_tmp_map (mapstruct *map) |
1697 | |
1916 | |
1698 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1917 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1699 | |
1918 | |
|
|
1919 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
|
|
1920 | CODE: |
|
|
1921 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
|
|
1922 | OUTPUT: |
|
|
1923 | RETVAL |
|
|
1924 | |
|
|
1925 | char *tile_path (mapstruct *map, unsigned int dir) |
|
|
1926 | CODE: |
|
|
1927 | if (dir >= 4) |
|
|
1928 | XSRETURN_UNDEF; |
|
|
1929 | RETVAL = map->tile_path [dir]; |
|
|
1930 | OUTPUT: |
|
|
1931 | RETVAL |
|
|
1932 | |
1700 | mapstruct *cf_map_get_map (char *name) |
1933 | mapstruct *cf_map_get_map (char *name) |
1701 | PROTOTYPE: $ |
1934 | PROTOTYPE: $ |
1702 | ALIAS: map = 0 |
1935 | ALIAS: map = 0 |
1703 | |
1936 | |
|
|
1937 | mapstruct *has_been_loaded (char *name) |
|
|
1938 | PROTOTYPE: $ |
|
|
1939 | |
1704 | mapstruct *cf_map_get_first () |
1940 | mapstruct *cf_map_get_first () |
1705 | PROTOTYPE: |
1941 | PROTOTYPE: |
1706 | ALIAS: first = 0 |
1942 | ALIAS: first = 0 |
1707 | |
1943 | |
1708 | # whoever "designed" the plug-in api should have wasted |
1944 | # whoever "designed" the plug-in api should have wasted |
1709 | # his/her time with staying away form the project - would have |
1945 | # his/her time with staying away from the project - would have |
1710 | # saved others a lot of time, without doubt. |
1946 | # saved others a lot of time, without doubt. |
1711 | void set_path (mapstruct *where, char *path) |
1947 | void set_path (mapstruct *where, char *path) |
1712 | CODE: |
1948 | CODE: |
1713 | strcpy (where->path, path); |
1949 | strcpy (where->path, path); |
|
|
1950 | |
|
|
1951 | int in_memory (mapstruct *map) |
|
|
1952 | CODE: |
|
|
1953 | RETVAL = map->in_memory; |
|
|
1954 | OUTPUT: |
|
|
1955 | RETVAL |
1714 | |
1956 | |
1715 | bool unique (mapstruct *map) |
1957 | bool unique (mapstruct *map) |
1716 | CODE: |
1958 | CODE: |
1717 | RETVAL = map->unique; |
1959 | RETVAL = map->unique; |
1718 | OUTPUT: |
1960 | OUTPUT: |
… | |
… | |
1727 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1969 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1728 | |
1970 | |
1729 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1971 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1730 | C_ARGS: str, map, nx, ny |
1972 | C_ARGS: str, map, nx, ny |
1731 | |
1973 | |
1732 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
|
|
1733 | |
|
|
1734 | void |
1974 | void |
|
|
1975 | cf_map_normalise (mapstruct *map, int x, int y) |
|
|
1976 | PPCODE: |
|
|
1977 | { |
|
|
1978 | mapstruct *nmap = 0; |
|
|
1979 | I16 nx = 0, ny = 0; |
|
|
1980 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
1981 | |
|
|
1982 | EXTEND (SP, 4); |
|
|
1983 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
1984 | |
|
|
1985 | if (GIMME_V == G_ARRAY) |
|
|
1986 | { |
|
|
1987 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); |
|
|
1988 | PUSHs (sv_2mortal (newSViv (nx))); |
|
|
1989 | PUSHs (sv_2mortal (newSViv (ny))); |
|
|
1990 | } |
|
|
1991 | } |
|
|
1992 | |
|
|
1993 | void |
1735 | at (mapstruct *obj, unsigned int x, unsigned int y) |
1994 | at (mapstruct *map, unsigned int x, unsigned int y) |
1736 | PROTOTYPE: $$$ |
1995 | PROTOTYPE: $$$ |
1737 | INIT: |
|
|
1738 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY; |
|
|
1739 | PPCODE: |
1996 | PPCODE: |
1740 | { |
1997 | { |
1741 | object *o; |
1998 | object *o; |
1742 | |
1999 | mapstruct *nmap = 0; |
|
|
2000 | I16 nx, ny; |
|
|
2001 | |
|
|
2002 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2003 | |
|
|
2004 | if (nmap) |
1743 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
2005 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
1744 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2006 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1745 | } |
2007 | } |
1746 | |
2008 | |
1747 | SV * |
2009 | SV * |
1748 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
2010 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1749 | PROTOTYPE: $$$ |
2011 | PROTOTYPE: $$$ |