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 | |
… | |
… | |
78 | } CFPContext; |
78 | } CFPContext; |
79 | |
79 | |
80 | static HV *obj_cache; |
80 | static HV *obj_cache; |
81 | static PerlInterpreter *perl; |
81 | static PerlInterpreter *perl; |
82 | |
82 | |
|
|
83 | #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)))) |
84 | #define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype)) |
84 | #define PUSH_OB PUSHcfapi(CFAPI_POBJECT, object *) |
85 | #define PUSH_OB PUSHcfapi_va(POBJECT, object *) |
85 | #define PUSH_PL PUSHcfapi(CFAPI_PPLAYER, player *) |
86 | #define PUSH_PL PUSHcfapi_va(PPLAYER, player *) |
86 | #define PUSH_MAP PUSHcfapi(CFAPI_PMAP, mapstruct *) |
87 | #define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) |
87 | #define PUSH_PV PUSHcfapi(CFAPI_STRING, const char *) |
88 | #define PUSH_PV PUSHcfapi_va(STRING, const char *) |
88 | #define PUSH_IV PUSHcfapi(CFAPI_INT, int) |
89 | #define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) |
|
|
90 | |
|
|
91 | extern void pay_player(object *op, uint64 amount); |
|
|
92 | extern uint64 pay_player_arch(object *op, const char *arch, uint64 amount); |
89 | |
93 | |
90 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
94 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
91 | |
95 | |
92 | // garbage collect some perl objects, if possible |
96 | // garbage collect some perl objects, if possible |
93 | // all objects no longer referenced and empty are |
97 | // all objects no longer referenced and empty are |
… | |
… | |
229 | case CFAPI_LONG: |
233 | case CFAPI_LONG: |
230 | sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ |
234 | sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ |
231 | break; |
235 | break; |
232 | |
236 | |
233 | case CFAPI_DOUBLE: |
237 | case CFAPI_DOUBLE: |
234 | sv = newSViv (*va_arg (args, double *)); |
238 | sv = newSVnv (*va_arg (args, double *)); |
235 | break; |
239 | break; |
236 | |
240 | |
237 | case CFAPI_STRING: |
241 | case CFAPI_STRING: |
238 | { |
242 | { |
239 | char *str = va_arg (args, char *); |
243 | char *str = va_arg (args, char *); |
… | |
… | |
246 | object *obj = va_arg (args, object *); |
250 | object *obj = va_arg (args, object *); |
247 | |
251 | |
248 | if (!obj) |
252 | if (!obj) |
249 | sv = &PL_sv_undef; |
253 | sv = &PL_sv_undef; |
250 | else |
254 | else |
251 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
255 | switch (obj->type) |
252 | { |
256 | { |
253 | case MAP: |
257 | case MAP: |
254 | sv = newSVptr_cached (obj, "cf::object::map"); |
258 | sv = newSVptr_cached (obj, "cf::object::map"); |
255 | break; |
259 | break; |
256 | |
260 | |
… | |
… | |
427 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
431 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
428 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
432 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
429 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
433 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
430 | registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); |
434 | registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); |
431 | registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); |
435 | registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); |
|
|
436 | registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener); |
432 | |
437 | |
433 | char *argv[] = { |
438 | char *argv[] = { |
434 | "", |
439 | "", |
435 | "-e" |
440 | "-e" |
436 | "BEGIN {" |
441 | "BEGIN {" |
… | |
… | |
442 | }; |
447 | }; |
443 | |
448 | |
444 | perl = perl_alloc (); |
449 | perl = perl_alloc (); |
445 | perl_construct (perl); |
450 | perl_construct (perl); |
446 | |
451 | |
|
|
452 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
453 | |
447 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
454 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
448 | { |
455 | { |
449 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
456 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
450 | |
457 | |
451 | perl_destruct (perl); |
458 | perl_destruct (perl); |
… | |
… | |
485 | if (sv) |
492 | if (sv) |
486 | clearSVptr (sv); |
493 | clearSVptr (sv); |
487 | |
494 | |
488 | rv = 0; |
495 | rv = 0; |
489 | } |
496 | } |
|
|
497 | else if (event_code == EVENT_CLOCK) |
|
|
498 | { |
|
|
499 | dSP; |
|
|
500 | int i, count; |
|
|
501 | |
|
|
502 | clean_obj_cache (); |
|
|
503 | |
|
|
504 | ENTER; |
|
|
505 | SAVETMPS; |
|
|
506 | |
|
|
507 | // service up to 8 events per tick better would be |
|
|
508 | // to check for elapsed time and stop processing after |
|
|
509 | // 0.25 * server_tick or so |
|
|
510 | for (i = 9; --i; ) |
|
|
511 | { |
|
|
512 | PUSHMARK (SP); |
|
|
513 | XPUSHs (sv_2mortal (newSViv (0))); |
|
|
514 | PUTBACK; |
|
|
515 | count = call_pv ("Event::one_event", G_SCALAR | G_EVAL); |
|
|
516 | SPAGAIN; |
|
|
517 | |
|
|
518 | if (!count || !POPi) |
|
|
519 | break; |
|
|
520 | } |
|
|
521 | |
|
|
522 | FREETMPS; |
|
|
523 | LEAVE; |
|
|
524 | } |
490 | else |
525 | else |
491 | { |
526 | { |
492 | dSP; |
527 | dSP; |
493 | |
528 | |
494 | ENTER; |
529 | ENTER; |
… | |
… | |
542 | case EVENT_KICK: |
577 | case EVENT_KICK: |
543 | PUSH_OB; |
578 | PUSH_OB; |
544 | PUSH_PV; |
579 | PUSH_PV; |
545 | break; |
580 | break; |
546 | |
581 | |
547 | case EVENT_CLOCK: |
582 | case EVENT_EXTCMD: |
548 | clean_obj_cache (); |
583 | PUSH_PL; |
|
|
584 | { |
|
|
585 | char *buf = va_arg (args, char *); |
|
|
586 | int len = va_arg (args, int); |
|
|
587 | PUSHs (sv_2mortal (newSVpvn (buf, len))); |
|
|
588 | } |
549 | break; |
589 | break; |
550 | |
590 | |
551 | case EVENT_TELL: |
591 | case EVENT_TELL: |
552 | break; |
592 | break; |
553 | } |
593 | } |
… | |
… | |
557 | PUTBACK; |
597 | PUTBACK; |
558 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
598 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
559 | SPAGAIN; |
599 | SPAGAIN; |
560 | |
600 | |
561 | if (SvTRUE (ERRSV)) |
601 | if (SvTRUE (ERRSV)) |
562 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
602 | LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
563 | |
603 | |
564 | rv = count > 0 ? POPi : 0; |
604 | rv = count > 0 ? POPi : 0; |
565 | |
605 | |
566 | PUTBACK; |
606 | PUTBACK; |
567 | FREETMPS; |
607 | FREETMPS; |
… | |
… | |
572 | } |
612 | } |
573 | |
613 | |
574 | void * |
614 | void * |
575 | eventListener (int *type, ...) |
615 | eventListener (int *type, ...) |
576 | { |
616 | { |
577 | static int rv = 0; |
617 | static int rv; |
578 | va_list args; |
618 | va_list args; |
579 | char *buf; |
619 | int event_code; |
580 | CFPContext context; |
620 | object *who, *activator, *third, *event; |
|
|
621 | char *message, *extension, *options; |
581 | |
622 | |
582 | if (!perl) |
623 | if (!perl) |
583 | return; |
624 | return; |
584 | |
625 | |
585 | memset (&context, 0, sizeof (context)); |
|
|
586 | |
|
|
587 | va_start (args, type); |
626 | va_start (args, type); |
588 | |
|
|
589 | context.who = va_arg (args, object *); |
627 | who = va_arg (args, object *); |
590 | context.event_code = va_arg (args, int); |
628 | event_code = va_arg (args, int); |
591 | context.activator = va_arg (args, object *); |
629 | activator = va_arg (args, object *); |
592 | context.third = va_arg (args, object *); |
630 | third = va_arg (args, object *); |
593 | |
|
|
594 | buf = va_arg (args, char *); |
631 | message = va_arg (args, char *); |
595 | if (buf != 0) |
632 | va_arg (args, int); // fix yourself |
596 | strncpy (context.message, buf, sizeof (context.message)); |
633 | extension = va_arg (args, char *); |
597 | |
634 | options = va_arg (args, char *); |
598 | context.fix = va_arg (args, int); |
|
|
599 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
|
|
600 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
|
|
601 | context.event = va_arg (args, object *); |
635 | event = va_arg (args, object *); |
602 | va_end (args); |
636 | va_end (args); |
603 | |
637 | |
604 | { |
638 | { |
605 | dSP; |
639 | dSP; |
606 | |
640 | |
607 | ENTER; |
641 | ENTER; |
608 | SAVETMPS; |
642 | SAVETMPS; |
609 | |
643 | |
610 | PUSHMARK (SP); |
644 | PUSHMARK (SP); |
611 | |
|
|
612 | EXTEND (SP, 10); |
645 | EXTEND (SP, 10); |
613 | |
646 | |
614 | HV *hv = newHV (); |
647 | PUSHcfapi (STRING, extension); |
615 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context.expr), 0) |
648 | PUSHs (sv_2mortal (newSViv (event_code))); |
616 | hv_context (CFAPI_POBJECT, ,who); |
|
|
617 | hv_context (CFAPI_POBJECT, ,activator); |
|
|
618 | hv_context (CFAPI_POBJECT, ,third); |
|
|
619 | hv_context (CFAPI_POBJECT, ,event); |
|
|
620 | hv_context (CFAPI_PMAP, ,map); |
|
|
621 | hv_context (CFAPI_STRING , ,message); |
|
|
622 | hv_context (CFAPI_INT ,&,fix); |
|
|
623 | hv_context (CFAPI_INT ,&,event_code); |
|
|
624 | hv_context (CFAPI_STRING , ,options); |
|
|
625 | hv_context (CFAPI_STRING , ,extension); |
|
|
626 | |
649 | |
627 | PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
650 | PUSHcfapi (POBJECT, event); |
|
|
651 | PUSHcfapi (POBJECT, who); |
|
|
652 | |
|
|
653 | switch (event_code) |
|
|
654 | { |
|
|
655 | case EVENT_STOP: // $ob (e.g. arrow) |
|
|
656 | case EVENT_TIME: // $ob |
|
|
657 | case EVENT_TIMER: // $ob |
|
|
658 | break; |
|
|
659 | |
|
|
660 | case EVENT_APPLY: // $ob, $who |
|
|
661 | case EVENT_DROP: // $ob, $who |
|
|
662 | case EVENT_CLOSE: // $ob, $who |
|
|
663 | case EVENT_DEATH: // $ob[, $killer] |
|
|
664 | case EVENT_MOVE: // $ob, $enemy |
|
|
665 | case EVENT_THROW: // $ob, $thrower |
|
|
666 | PUSHcfapi (POBJECT, activator); |
|
|
667 | break; |
|
|
668 | |
|
|
669 | case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me) |
|
|
670 | PUSHcfapi (POBJECT, activator); |
|
|
671 | PUSHcfapi (POBJECT, third); |
|
|
672 | break; |
|
|
673 | |
|
|
674 | case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg] |
|
|
675 | PUSHcfapi (POBJECT, activator); |
|
|
676 | PUSHcfapi (POBJECT, third); |
|
|
677 | PUSHcfapi (POBJECT, message); |
|
|
678 | break; |
|
|
679 | |
|
|
680 | case EVENT_SAY: // $ob, $who, $msg |
|
|
681 | PUSHcfapi (POBJECT, activator); |
|
|
682 | PUSHcfapi (STRING, message); |
|
|
683 | break; |
|
|
684 | |
|
|
685 | default: |
|
|
686 | LOG (llevError, "perl plugin called for unsupported event type %d", event_code); |
|
|
687 | break; |
|
|
688 | } |
628 | |
689 | |
629 | PUTBACK; |
690 | PUTBACK; |
630 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
691 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
631 | SPAGAIN; |
692 | SPAGAIN; |
632 | |
693 | |
633 | if (SvTRUE (ERRSV)) |
694 | if (SvTRUE (ERRSV)) |
634 | LOG (llevError, "event '%d' callback evaluation error: %s", context.event_code, SvPV_nolen (ERRSV)); |
695 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
635 | |
696 | |
636 | context.returnvalue = count > 0 ? POPi : 0; |
697 | rv = count > 0 ? POPi : 0; |
637 | |
698 | |
638 | PUTBACK; |
699 | PUTBACK; |
639 | FREETMPS; |
700 | FREETMPS; |
640 | LEAVE; |
701 | LEAVE; |
641 | } |
702 | } |
642 | |
703 | |
643 | rv = context.returnvalue; |
|
|
644 | return &rv; |
704 | return &rv; |
645 | } |
705 | } |
646 | |
706 | |
647 | int |
707 | int |
648 | closePlugin () |
708 | closePlugin () |
… | |
… | |
1068 | const_iv (SK_SUMMONING) |
1128 | const_iv (SK_SUMMONING) |
1069 | const_iv (SK_PYROMANCY) |
1129 | const_iv (SK_PYROMANCY) |
1070 | const_iv (SK_EVOCATION) |
1130 | const_iv (SK_EVOCATION) |
1071 | const_iv (SK_SORCERY) |
1131 | const_iv (SK_SORCERY) |
1072 | const_iv (SK_TWO_HANDED_WEAPON) |
1132 | const_iv (SK_TWO_HANDED_WEAPON) |
|
|
1133 | const_iv (SK_SPARK_TOUCH) |
|
|
1134 | const_iv (SK_SHIVER) |
|
|
1135 | const_iv (SK_ACID_SPLASH) |
|
|
1136 | const_iv (SK_POISON_NAIL) |
1073 | |
1137 | |
1074 | const_iv (SOUND_NEW_PLAYER) |
1138 | const_iv (SOUND_NEW_PLAYER) |
1075 | const_iv (SOUND_FIRE_ARROW) |
1139 | const_iv (SOUND_FIRE_ARROW) |
1076 | const_iv (SOUND_LEARN_SPELL) |
1140 | const_iv (SOUND_LEARN_SPELL) |
1077 | const_iv (SOUND_FUMBLE_SPELL) |
1141 | const_iv (SOUND_FUMBLE_SPELL) |
… | |
… | |
1093 | const_iv (SOUND_CLOCK) |
1157 | const_iv (SOUND_CLOCK) |
1094 | const_iv (SOUND_TURN_HANDLE) |
1158 | const_iv (SOUND_TURN_HANDLE) |
1095 | const_iv (SOUND_FALL_HOLE) |
1159 | const_iv (SOUND_FALL_HOLE) |
1096 | const_iv (SOUND_DRINK_POISON) |
1160 | const_iv (SOUND_DRINK_POISON) |
1097 | const_iv (SOUND_CAST_SPELL_0) |
1161 | const_iv (SOUND_CAST_SPELL_0) |
|
|
1162 | |
|
|
1163 | const_iv (MAP_FLUSH) |
|
|
1164 | const_iv (MAP_PLAYER_UNIQUE) |
|
|
1165 | const_iv (MAP_BLOCK) |
|
|
1166 | const_iv (MAP_STYLE) |
|
|
1167 | const_iv (MAP_OVERLAY) |
|
|
1168 | |
|
|
1169 | const_iv (MAP_IN_MEMORY) |
|
|
1170 | const_iv (MAP_SWAPPED) |
|
|
1171 | const_iv (MAP_LOADING) |
|
|
1172 | const_iv (MAP_SAVING) |
1098 | }; |
1173 | }; |
1099 | |
1174 | |
1100 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1175 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1101 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1176 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1102 | |
1177 | |
… | |
… | |
1119 | const_event (CLOSE) |
1194 | const_event (CLOSE) |
1120 | const_event (TIMER) |
1195 | const_event (TIMER) |
1121 | const_event (MOVE) |
1196 | const_event (MOVE) |
1122 | |
1197 | |
1123 | const_event (BORN) |
1198 | const_event (BORN) |
1124 | const_event (CLOCK) |
1199 | //const_event (CLOCK) |
1125 | const_event (CRASH) |
1200 | const_event (CRASH) |
1126 | const_event (PLAYER_DEATH) |
1201 | const_event (PLAYER_DEATH) |
1127 | const_event (PLAYER_LOAD) |
1202 | const_event (PLAYER_LOAD) |
1128 | const_event (PLAYER_SAVE) |
1203 | const_event (PLAYER_SAVE) |
1129 | const_event (GKILL) |
1204 | const_event (GKILL) |
… | |
… | |
1139 | const_event (REMOVE) |
1214 | const_event (REMOVE) |
1140 | const_event (SHOUT) |
1215 | const_event (SHOUT) |
1141 | const_event (TELL) |
1216 | const_event (TELL) |
1142 | const_event (MUZZLE) |
1217 | const_event (MUZZLE) |
1143 | const_event (KICK) |
1218 | const_event (KICK) |
|
|
1219 | const_event (EXTCMD) |
1144 | //const_event (FREE_OB) |
1220 | //const_event (FREE_OB) |
1145 | }; |
1221 | }; |
1146 | |
1222 | |
1147 | AV *av = get_av ("cf::EVENT", 1); |
1223 | AV *av = get_av ("cf::EVENT", 1); |
1148 | |
1224 | |
… | |
… | |
1282 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1358 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1283 | { |
1359 | { |
1284 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1360 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1285 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1361 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1286 | } |
1362 | } |
|
|
1363 | |
|
|
1364 | //I_EVENT_API (PACKAGE); |
1287 | } |
1365 | } |
1288 | |
1366 | |
1289 | void |
1367 | void |
1290 | LOG (int level, char *msg) |
1368 | LOG (int level, char *msg) |
1291 | PROTOTYPE: $$ |
1369 | PROTOTYPE: $$ |
1292 | C_ARGS: level, "%s", msg |
1370 | C_ARGS: level, "%s", msg |
|
|
1371 | |
|
|
1372 | char *path_combine (char *base, char *path) |
|
|
1373 | PROTOTYPE: $$ |
|
|
1374 | |
|
|
1375 | char *path_combine_and_normalize (char *base, char *path) |
|
|
1376 | PROTOTYPE: $$ |
1293 | |
1377 | |
1294 | char * |
1378 | char * |
1295 | cf_get_maps_directory (char *path) |
1379 | cf_get_maps_directory (char *path) |
1296 | PROTOTYPE: $ |
1380 | PROTOTYPE: $ |
1297 | ALIAS: maps_directory = 0 |
1381 | ALIAS: maps_directory = 0 |
… | |
… | |
1466 | |
1550 | |
1467 | void cf_object_update (object *op, int flags) |
1551 | void cf_object_update (object *op, int flags) |
1468 | |
1552 | |
1469 | void cf_object_pickup (object *op, object *what) |
1553 | void cf_object_pickup (object *op, object *what) |
1470 | |
1554 | |
1471 | char *cf_object_get_key (object *op, char *keyname) |
|
|
1472 | ALIAS: key = 0 |
|
|
1473 | |
|
|
1474 | void cf_object_set_key (object *op, char *keyname, char *value) |
|
|
1475 | |
|
|
1476 | object *cf_create_object_by_name (const char *name) |
1555 | object *cf_create_object_by_name (const char *name) |
1477 | |
1556 | |
1478 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
1557 | void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) |
1479 | |
1558 | |
|
|
1559 | void pay_player (object *op, double amount) |
|
|
1560 | |
|
|
1561 | double pay_player_arch (object *op, const char *arch, double amount) |
|
|
1562 | |
1480 | void player_lvl_adj (object *who, object *skill = 0) |
1563 | void player_lvl_adj (object *who, object *skill = 0) |
1481 | |
1564 | |
|
|
1565 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1482 | |
1566 | |
1483 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1567 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1484 | |
1568 | |
1485 | void cf_fix_object (object *pl) |
1569 | void cf_fix_object (object *pl) |
1486 | ALIAS: fix = 0 |
1570 | ALIAS: fix = 0 |
… | |
… | |
1502 | CODE: |
1586 | CODE: |
1503 | { |
1587 | { |
1504 | int unused_type; |
1588 | int unused_type; |
1505 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1589 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1506 | } |
1590 | } |
|
|
1591 | |
|
|
1592 | # syntatic sugar for easier use in event callbacks. |
|
|
1593 | const char *options (object *op) |
|
|
1594 | CODE: |
|
|
1595 | RETVAL = op->name; |
|
|
1596 | OUTPUT: |
|
|
1597 | RETVAL |
1507 | |
1598 | |
1508 | const char *get_ob_key_value (object *op, const char *key) |
1599 | const char *get_ob_key_value (object *op, const char *key) |
1509 | |
1600 | |
1510 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1601 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1511 | |
1602 | |
… | |
… | |
1548 | |
1639 | |
1549 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1640 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1550 | |
1641 | |
1551 | player *player (object *op) |
1642 | player *player (object *op) |
1552 | CODE: |
1643 | CODE: |
1553 | RETVAL = cf_player_find (cf_query_name (op)); |
1644 | RETVAL = op->contr; |
1554 | OUTPUT: RETVAL |
1645 | OUTPUT: RETVAL |
1555 | |
1646 | |
1556 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1647 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1557 | |
1648 | |
1558 | object *cf_player_send_inventory (object *op) |
1649 | object *cf_player_send_inventory (object *op) |
… | |
… | |
1575 | |
1666 | |
1576 | void cf_player_set_party (object *op, partylist *party) |
1667 | void cf_player_set_party (object *op, partylist *party) |
1577 | |
1668 | |
1578 | void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) |
1669 | void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) |
1579 | |
1670 | |
|
|
1671 | void kill_player (object *op) |
|
|
1672 | |
1580 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1673 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1581 | |
1674 | |
1582 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1675 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1583 | |
1676 | |
1584 | player *cf_player_find (char *name) |
1677 | player *cf_player_find (char *name) |
… | |
… | |
1603 | |
1696 | |
1604 | player *next (player *pl) |
1697 | player *next (player *pl) |
1605 | CODE: |
1698 | CODE: |
1606 | RETVAL = pl->next; |
1699 | RETVAL = pl->next; |
1607 | OUTPUT: RETVAL |
1700 | OUTPUT: RETVAL |
|
|
1701 | |
|
|
1702 | bool |
|
|
1703 | cell_visible (player *pl, int dx, int dy) |
|
|
1704 | CODE: |
|
|
1705 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
|
|
1706 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
|
|
1707 | OUTPUT: |
|
|
1708 | RETVAL |
|
|
1709 | |
|
|
1710 | void |
|
|
1711 | send (player *pl, SV *packet) |
|
|
1712 | CODE: |
|
|
1713 | { |
|
|
1714 | STRLEN len; |
|
|
1715 | char *buf = SvPVbyte (packet, len); |
|
|
1716 | |
|
|
1717 | Write_String_To_Socket (&pl->socket, buf, len); |
|
|
1718 | } |
|
|
1719 | |
|
|
1720 | int |
|
|
1721 | listening (player *pl, int new_value = -1) |
|
|
1722 | CODE: |
|
|
1723 | RETVAL = pl->listening; |
|
|
1724 | if (new_value >= 0) |
|
|
1725 | pl->listening = new_value; |
|
|
1726 | OUTPUT: |
|
|
1727 | RETVAL |
1608 | |
1728 | |
1609 | void get_savebed (player *pl) |
1729 | void get_savebed (player *pl) |
1610 | ALIAS: |
1730 | ALIAS: |
1611 | savebed = 0 |
1731 | savebed = 0 |
1612 | PPCODE: |
1732 | PPCODE: |
… | |
… | |
1687 | |
1807 | |
1688 | void clean_tmp_map (mapstruct *map) |
1808 | void clean_tmp_map (mapstruct *map) |
1689 | |
1809 | |
1690 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1810 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
1691 | |
1811 | |
|
|
1812 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
|
|
1813 | CODE: |
|
|
1814 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
|
|
1815 | OUTPUT: |
|
|
1816 | RETVAL |
|
|
1817 | |
|
|
1818 | char *tile_path (mapstruct *map, unsigned int dir) |
|
|
1819 | CODE: |
|
|
1820 | if (dir >= 4) |
|
|
1821 | XSRETURN_UNDEF; |
|
|
1822 | RETVAL = map->tile_path [dir]; |
|
|
1823 | OUTPUT: |
|
|
1824 | RETVAL |
|
|
1825 | |
1692 | mapstruct *cf_map_get_map (char *name) |
1826 | mapstruct *cf_map_get_map (char *name) |
1693 | PROTOTYPE: $ |
1827 | PROTOTYPE: $ |
1694 | ALIAS: map = 0 |
1828 | ALIAS: map = 0 |
1695 | |
1829 | |
|
|
1830 | mapstruct *has_been_loaded (char *name) |
|
|
1831 | PROTOTYPE: $ |
|
|
1832 | |
1696 | mapstruct *cf_map_get_first () |
1833 | mapstruct *cf_map_get_first () |
1697 | PROTOTYPE: |
1834 | PROTOTYPE: |
1698 | ALIAS: first = 0 |
1835 | ALIAS: first = 0 |
1699 | |
1836 | |
1700 | # whoever "designed" the plug-in api should have wasted |
1837 | # whoever "designed" the plug-in api should have wasted |
1701 | # his/her time with staying away form the project - would have |
1838 | # his/her time with staying away from the project - would have |
1702 | # saved others a lot of time, without doubt. |
1839 | # saved others a lot of time, without doubt. |
1703 | void set_path (mapstruct *where, char *path) |
1840 | void set_path (mapstruct *where, char *path) |
1704 | CODE: |
1841 | CODE: |
1705 | strcpy (where->path, path); |
1842 | strcpy (where->path, path); |
|
|
1843 | |
|
|
1844 | int in_memory (mapstruct *map) |
|
|
1845 | CODE: |
|
|
1846 | RETVAL = map->in_memory; |
|
|
1847 | OUTPUT: |
|
|
1848 | RETVAL |
1706 | |
1849 | |
1707 | bool unique (mapstruct *map) |
1850 | bool unique (mapstruct *map) |
1708 | CODE: |
1851 | CODE: |
1709 | RETVAL = map->unique; |
1852 | RETVAL = map->unique; |
1710 | OUTPUT: |
1853 | OUTPUT: |
… | |
… | |
1719 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1862 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1720 | |
1863 | |
1721 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1864 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1722 | C_ARGS: str, map, nx, ny |
1865 | C_ARGS: str, map, nx, ny |
1723 | |
1866 | |
1724 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
|
|
1725 | |
|
|
1726 | void |
1867 | void |
|
|
1868 | cf_map_normalise (mapstruct *map, int x, int y) |
|
|
1869 | PPCODE: |
|
|
1870 | { |
|
|
1871 | mapstruct *nmap = 0; |
|
|
1872 | I16 nx = 0, ny = 0; |
|
|
1873 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
1874 | |
|
|
1875 | EXTEND (SP, 4); |
|
|
1876 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
1877 | |
|
|
1878 | if (GIMME_V == G_ARRAY) |
|
|
1879 | { |
|
|
1880 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); |
|
|
1881 | PUSHs (sv_2mortal (newSViv (nx))); |
|
|
1882 | PUSHs (sv_2mortal (newSViv (ny))); |
|
|
1883 | } |
|
|
1884 | } |
|
|
1885 | |
|
|
1886 | void |
1727 | at (mapstruct *obj, unsigned int x, unsigned int y) |
1887 | at (mapstruct *map, unsigned int x, unsigned int y) |
1728 | PROTOTYPE: $$$ |
1888 | PROTOTYPE: $$$ |
1729 | INIT: |
|
|
1730 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY; |
|
|
1731 | PPCODE: |
1889 | PPCODE: |
1732 | { |
1890 | { |
1733 | object *o; |
1891 | object *o; |
1734 | |
1892 | mapstruct *nmap = 0; |
|
|
1893 | I16 nx, ny; |
|
|
1894 | |
|
|
1895 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
1896 | |
|
|
1897 | if (nmap) |
1735 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
1898 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
1736 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1899 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1737 | } |
1900 | } |
1738 | |
1901 | |
1739 | SV * |
1902 | SV * |
1740 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1903 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1741 | PROTOTYPE: $$$ |
1904 | PROTOTYPE: $$$ |