… | |
… | |
46 | #include <sounds.h> |
46 | #include <sounds.h> |
47 | #include <cstdarg> |
47 | #include <cstdarg> |
48 | #include <sproto.h> |
48 | #include <sproto.h> |
49 | |
49 | |
50 | #include "cfperl.h" |
50 | #include "cfperl.h" |
|
|
51 | #include "shstr.h" |
51 | |
52 | |
52 | #include "perlxsi.c" |
53 | #include "perlxsi.c" |
53 | |
|
|
54 | static void *globalEventListener (int *type, ...); |
|
|
55 | |
54 | |
56 | extern sint64 *levels; // the experience table |
55 | extern sint64 *levels; // the experience table |
57 | |
56 | |
58 | typedef object object_ornull; |
57 | typedef object object_ornull; |
59 | typedef mapstruct mapstruct_ornull; |
58 | typedef mapstruct mapstruct_ornull; |
… | |
… | |
61 | typedef double val64; |
60 | typedef double val64; |
62 | #define newSVval64 newSVnv |
61 | #define newSVval64 newSVnv |
63 | #define SvVAL64 SvNV |
62 | #define SvVAL64 SvNV |
64 | |
63 | |
65 | static f_plug_api gethook; |
64 | static f_plug_api gethook; |
66 | static f_plug_api registerGlobalEvent; |
|
|
67 | static f_plug_api unregisterGlobalEvent; |
|
|
68 | static f_plug_api systemDirectory; |
65 | static f_plug_api systemDirectory; |
69 | static f_plug_api object_set_property; |
66 | static f_plug_api object_set_property; |
70 | static f_plug_api map_get_map; |
67 | static f_plug_api map_get_map; |
71 | static f_plug_api object_insert; |
68 | static f_plug_api object_insert; |
72 | |
69 | |
… | |
… | |
201 | { |
198 | { |
202 | SV *sv; |
199 | SV *sv; |
203 | |
200 | |
204 | switch (type) |
201 | switch (type) |
205 | { |
202 | { |
206 | // first three exist only for cfapi-compatibility |
|
|
207 | case DT_INT_PTR: |
|
|
208 | sv = newSViv (*va_arg (ap, int *)); |
|
|
209 | break; |
|
|
210 | |
|
|
211 | case DT_INT64_PTR: |
|
|
212 | sv = newSVval64 ((val64)*va_arg (ap, sint64 *)); |
|
|
213 | break; |
|
|
214 | |
|
|
215 | case DT_DOUBLE_PTR: |
|
|
216 | sv = newSVnv (*va_arg (ap, double *)); |
|
|
217 | break; |
|
|
218 | |
|
|
219 | case DT_INT: |
203 | case DT_INT: |
220 | sv = newSViv (va_arg (ap, int)); |
204 | sv = newSViv (va_arg (ap, int)); |
221 | break; |
205 | break; |
222 | |
206 | |
223 | case DT_INT64: |
207 | case DT_INT64: |
… | |
… | |
244 | break; |
228 | break; |
245 | |
229 | |
246 | case DT_OBJECT: |
230 | case DT_OBJECT: |
247 | { |
231 | { |
248 | object *obj = va_arg (ap, object *); |
232 | object *obj = va_arg (ap, object *); |
249 | sv = newSVextendable (obj, obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
233 | sv = newSVextendable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
250 | } |
234 | } |
251 | break; |
235 | break; |
252 | |
236 | |
253 | case DT_MAP: |
237 | case DT_MAP: |
254 | // va_arg (object *) when void * is passed is an XSI extension |
238 | // va_arg (object *) when void * is passed is an XSI extension |
… | |
… | |
298 | va_list ap; |
282 | va_list ap; |
299 | va_start (ap, type); |
283 | va_start (ap, type); |
300 | |
284 | |
301 | switch (type) |
285 | switch (type) |
302 | { |
286 | { |
303 | case CFAPI_INT: sv = newSVdt_va (ap, DT_INT_PTR ); break; |
287 | case CFAPI_INT: sv = newSViv (*va_arg (ap, int * )); break; |
304 | case CFAPI_LONG: sv = newSVdt_va (ap, DT_INT64_PTR ); break; |
288 | case CFAPI_LONG: sv = newSVval64 (*va_arg (ap, sint64 *)); break; |
305 | case CFAPI_DOUBLE: sv = newSVdt_va (ap, DT_DOUBLE_PTR); break; |
289 | case CFAPI_DOUBLE: sv = newSVnv (*va_arg (ap, double *)); break; |
306 | case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break; |
290 | case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break; |
307 | case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break; |
291 | case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break; |
308 | case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break; |
292 | case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break; |
309 | case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break; |
293 | case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break; |
310 | case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break; |
294 | case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break; |
… | |
… | |
320 | return sv; |
304 | return sv; |
321 | } |
305 | } |
322 | |
306 | |
323 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
307 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
324 | |
308 | |
|
|
309 | SV * |
|
|
310 | registry_of (extendable_base *obj) |
|
|
311 | { |
|
|
312 | if (!obj->cb) |
|
|
313 | obj->cb = newAV (); |
|
|
314 | |
|
|
315 | return newRV_inc ((SV *)obj->cb); |
|
|
316 | } |
|
|
317 | |
325 | void extendable_base::clear () |
318 | void extendable_base::clear () |
326 | { |
319 | { |
327 | //if (self) fprintf (stderr, "free_ob_self %p\n", this);//D |
320 | //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D |
|
|
321 | |
328 | if (self) SvREFCNT_dec (self), self = 0; |
322 | if (self) SvREFCNT_dec (self); |
329 | if (cb) SvREFCNT_dec (cb), cb = 0; |
323 | if (cb) SvREFCNT_dec (cb); |
|
|
324 | |
|
|
325 | if (attach) free_string (attach); |
|
|
326 | |
|
|
327 | self = 0; |
|
|
328 | cb = 0; |
|
|
329 | attach = 0; |
330 | } |
330 | } |
331 | |
331 | |
332 | void extendable_base::optimise () |
332 | void extendable_base::optimise () |
333 | { |
333 | { |
334 | // optional, and not used yet anyways |
334 | // optional, and not used yet anyways |
… | |
… | |
342 | } |
342 | } |
343 | |
343 | |
344 | void extendable_base::reattach (data_type type, void *self) |
344 | void extendable_base::reattach (data_type type, void *self) |
345 | { |
345 | { |
346 | dSP; |
346 | dSP; |
347 | |
|
|
348 | ENTER; |
347 | ENTER; |
349 | SAVETMPS; |
348 | SAVETMPS; |
350 | PUSHMARK (SP); |
349 | PUSHMARK (SP); |
351 | EXTEND (SP, 1); |
350 | EXTEND (SP, 1); |
352 | PUSHs (sv_2mortal (newSVdt (type, self))); |
351 | PUSHs (sv_2mortal (newSVdt (type, self))); |
353 | PUTBACK; |
352 | PUTBACK; |
354 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
353 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
355 | FREETMPS; |
354 | FREETMPS; |
356 | LEAVE; |
355 | LEAVE; |
357 | } |
|
|
358 | |
356 | |
359 | void extendable_base::instantiate (data_type type, void *self) |
357 | if (cb && type == DT_OBJECT) |
|
|
358 | INVOKE_OBJECT (LOAD, (object *)self); |
|
|
359 | } |
|
|
360 | |
|
|
361 | void |
|
|
362 | object::instantiate_ () |
360 | { |
363 | { |
361 | dSP; |
364 | dSP; |
362 | |
|
|
363 | ENTER; |
365 | ENTER; |
364 | SAVETMPS; |
366 | SAVETMPS; |
365 | PUSHMARK (SP); |
367 | PUSHMARK (SP); |
366 | EXTEND (SP, 1); |
368 | EXTEND (SP, 2); |
|
|
369 | PUSHs (sv_2mortal (newSVdt (DT_OBJECT, static_cast<object *>(this)))); |
367 | PUSHs (sv_2mortal (newSVdt (type, self))); |
370 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
368 | PUTBACK; |
371 | PUTBACK; |
369 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
372 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
370 | FREETMPS; |
|
|
371 | LEAVE; |
|
|
372 | } |
|
|
373 | |
|
|
374 | void extendable_base::clone (data_type type, void *self, void *dest) |
|
|
375 | { |
|
|
376 | dSP; |
|
|
377 | |
|
|
378 | ENTER; |
|
|
379 | SAVETMPS; |
|
|
380 | PUSHMARK (SP); |
|
|
381 | EXTEND (SP, 1); |
|
|
382 | PUSHs (sv_2mortal (newSVdt (type, self))); |
|
|
383 | PUSHs (sv_2mortal (newSVdt (type, dest))); |
|
|
384 | PUTBACK; |
|
|
385 | call_pv ("cf::clone", G_DISCARD | G_VOID | G_EVAL); |
|
|
386 | FREETMPS; |
373 | FREETMPS; |
387 | LEAVE; |
374 | LEAVE; |
388 | } |
375 | } |
389 | |
376 | |
390 | ///////////////////////////////////////////////////////////////////////////// |
377 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
483 | int hooktype = 1; |
470 | int hooktype = 1; |
484 | int rtype = 0; |
471 | int rtype = 0; |
485 | |
472 | |
486 | printf (PLUGIN_VERSION " post init\n"); |
473 | printf (PLUGIN_VERSION " post init\n"); |
487 | |
474 | |
488 | registerGlobalEvent = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
|
|
489 | unregisterGlobalEvent = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
|
|
490 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
475 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
491 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
476 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
492 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
477 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
493 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
478 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
494 | |
479 | |
495 | cf_init_plugin (gethook); |
480 | cf_init_plugin (gethook); |
496 | |
481 | |
497 | /* Pick the global events you want to monitor from this plugin */ |
|
|
498 | registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); |
|
|
499 | registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); |
|
|
500 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
|
|
501 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
|
|
502 | |
|
|
503 | return 0; |
482 | return 0; |
504 | } |
|
|
505 | |
|
|
506 | static void * |
|
|
507 | globalEventListener (int *type, ...) |
|
|
508 | { |
|
|
509 | va_list args; |
|
|
510 | static int rv; |
|
|
511 | int event_code; |
|
|
512 | |
|
|
513 | if (!perl) |
|
|
514 | return NULL; |
|
|
515 | |
|
|
516 | va_start (args, type); |
|
|
517 | event_code = va_arg (args, int); |
|
|
518 | |
|
|
519 | dSP; |
|
|
520 | |
|
|
521 | ENTER; |
|
|
522 | SAVETMPS; |
|
|
523 | |
|
|
524 | PUSHMARK (SP); |
|
|
525 | |
|
|
526 | EXTEND (SP, 10); |
|
|
527 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
528 | |
|
|
529 | switch (event_code) |
|
|
530 | { |
|
|
531 | case EVENT_CRASH: |
|
|
532 | break; |
|
|
533 | |
|
|
534 | case EVENT_SHOUT: |
|
|
535 | case EVENT_MUZZLE: |
|
|
536 | case EVENT_KICK: |
|
|
537 | PUSH_OB; |
|
|
538 | PUSH_PV; |
|
|
539 | break; |
|
|
540 | |
|
|
541 | case EVENT_TELL: |
|
|
542 | break; |
|
|
543 | } |
|
|
544 | |
|
|
545 | va_end (args); |
|
|
546 | |
|
|
547 | PUTBACK; |
|
|
548 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
|
|
549 | SPAGAIN; |
|
|
550 | |
|
|
551 | if (SvTRUE (ERRSV)) |
|
|
552 | LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
553 | |
|
|
554 | rv = count > 0 ? POPi : 0; |
|
|
555 | |
|
|
556 | PUTBACK; |
|
|
557 | FREETMPS; |
|
|
558 | LEAVE; |
|
|
559 | |
|
|
560 | return &rv; |
|
|
561 | } |
|
|
562 | |
|
|
563 | extern "C" void *cfperl_eventListener (int *type, ...) |
|
|
564 | { |
|
|
565 | static int rv; |
|
|
566 | va_list args; |
|
|
567 | int event_code; |
|
|
568 | object *who, *activator, *third, *event; |
|
|
569 | char *message, *extension, *options; |
|
|
570 | |
|
|
571 | if (!perl) |
|
|
572 | return NULL; |
|
|
573 | |
|
|
574 | va_start (args, type); |
|
|
575 | who = va_arg (args, object *); |
|
|
576 | event_code = va_arg (args, int); |
|
|
577 | activator = va_arg (args, object *); |
|
|
578 | third = va_arg (args, object *); |
|
|
579 | message = va_arg (args, char *); |
|
|
580 | va_arg (args, int); // fix yourself |
|
|
581 | extension = va_arg (args, char *); |
|
|
582 | options = va_arg (args, char *); |
|
|
583 | event = va_arg (args, object *); |
|
|
584 | va_end (args); |
|
|
585 | |
|
|
586 | { |
|
|
587 | dSP; |
|
|
588 | |
|
|
589 | ENTER; |
|
|
590 | SAVETMPS; |
|
|
591 | |
|
|
592 | PUSHMARK (SP); |
|
|
593 | EXTEND (SP, 10); |
|
|
594 | |
|
|
595 | PUSHcfapi (STRING, extension); |
|
|
596 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
597 | |
|
|
598 | PUSHcfapi (POBJECT, event); |
|
|
599 | PUSHcfapi (POBJECT, who); |
|
|
600 | |
|
|
601 | switch (event_code) |
|
|
602 | { |
|
|
603 | case EVENT_STOP: // $ob (e.g. arrow) |
|
|
604 | case EVENT_TIME: // $ob |
|
|
605 | case EVENT_TIMER: // $ob |
|
|
606 | break; |
|
|
607 | |
|
|
608 | case EVENT_APPLY: // $ob, $who |
|
|
609 | case EVENT_DROP: // $ob, $who |
|
|
610 | case EVENT_CLOSE: // $ob, $who |
|
|
611 | case EVENT_MOVE: // $ob, $enemy |
|
|
612 | case EVENT_THROW: // $ob, $thrower |
|
|
613 | PUSHcfapi (POBJECT, activator); |
|
|
614 | break; |
|
|
615 | |
|
|
616 | case EVENT_DROP_ON: // $ob, $who, $what |
|
|
617 | case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me) |
|
|
618 | PUSHcfapi (POBJECT, activator); |
|
|
619 | PUSHcfapi (POBJECT, third); |
|
|
620 | break; |
|
|
621 | |
|
|
622 | case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg] |
|
|
623 | PUSHcfapi (POBJECT, activator); |
|
|
624 | PUSHcfapi (POBJECT, third); |
|
|
625 | PUSHcfapi (POBJECT, message); |
|
|
626 | break; |
|
|
627 | |
|
|
628 | case EVENT_SAY: // $ob, $who, $msg |
|
|
629 | PUSHcfapi (POBJECT, activator); |
|
|
630 | PUSHcfapi (STRING, message); |
|
|
631 | break; |
|
|
632 | |
|
|
633 | default: |
|
|
634 | LOG (llevError, "perl plugin called for unsupported event type %d", event_code); |
|
|
635 | break; |
|
|
636 | } |
|
|
637 | |
|
|
638 | PUTBACK; |
|
|
639 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
|
|
640 | SPAGAIN; |
|
|
641 | |
|
|
642 | if (SvTRUE (ERRSV)) |
|
|
643 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
644 | |
|
|
645 | rv = count > 0 ? POPi : 0; |
|
|
646 | |
|
|
647 | PUTBACK; |
|
|
648 | FREETMPS; |
|
|
649 | LEAVE; |
|
|
650 | } |
|
|
651 | |
|
|
652 | return &rv; |
|
|
653 | } |
483 | } |
654 | |
484 | |
655 | extern "C" int cfperl_closePlugin () |
485 | extern "C" int cfperl_closePlugin () |
656 | { |
486 | { |
657 | return 0; |
487 | return 0; |
… | |
… | |
762 | break; |
592 | break; |
763 | |
593 | |
764 | case KLASS_OBJECT: |
594 | case KLASS_OBJECT: |
765 | dt = (data_type) va_arg (ap, int); |
595 | dt = (data_type) va_arg (ap, int); |
766 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
596 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
767 | |
|
|
768 | op = va_arg (ap, object *); |
597 | op = va_arg (ap, object *); |
769 | |
598 | |
|
|
599 | if (op->cb) |
|
|
600 | gather_callbacks (callbacks, (AV *)op->cb, event); |
|
|
601 | |
770 | gather_callbacks (callbacks, cb_object, event); |
602 | gather_callbacks (callbacks, cb_object, event); |
771 | //TODO: per-object |
|
|
772 | |
603 | |
773 | if (op->type > 0 && op->type <= AvFILLp (cb_type)) |
604 | if (op->type > 0 && op->type <= AvFILLp (cb_type)) |
774 | { |
605 | { |
775 | SV *registry = AvARRAY (cb_type)[op->type]; |
606 | SV *registry = AvARRAY (cb_type)[op->type]; |
776 | |
607 | |
… | |
… | |
781 | break; |
612 | break; |
782 | |
613 | |
783 | case KLASS_PLAYER: |
614 | case KLASS_PLAYER: |
784 | dt = (data_type) va_arg (ap, int); |
615 | dt = (data_type) va_arg (ap, int); |
785 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
616 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
786 | |
|
|
787 | pl = va_arg (ap, player *); |
617 | pl = va_arg (ap, player *); |
|
|
618 | |
|
|
619 | if (op->cb) |
|
|
620 | gather_callbacks (callbacks, (AV *)op->cb, event); |
|
|
621 | |
788 | gather_callbacks (callbacks, cb_player, event); |
622 | gather_callbacks (callbacks, cb_player, event); |
789 | break; |
623 | break; |
790 | |
624 | |
791 | case KLASS_MAP: |
625 | case KLASS_MAP: |
792 | dt = (data_type) va_arg (ap, int); |
626 | dt = (data_type) va_arg (ap, int); |
793 | assert (("first argument must be of type object", dt == DT_MAP)); |
627 | assert (("first argument must be of type object", dt == DT_MAP)); |
794 | |
|
|
795 | map = va_arg (ap, mapstruct *); |
628 | map = va_arg (ap, mapstruct *); |
|
|
629 | |
|
|
630 | if (op->cb) |
|
|
631 | gather_callbacks (callbacks, (AV *)op->cb, event); |
|
|
632 | |
796 | gather_callbacks (callbacks, cb_map, event); |
633 | gather_callbacks (callbacks, cb_map, event); |
797 | break; |
634 | break; |
798 | |
635 | |
799 | default: |
636 | default: |
800 | assert (("unsupported event klass in cfperl_invoke", 0)); |
637 | assert (("unsupported event klass in cfperl_invoke", 0)); |
… | |
… | |
826 | dt = (data_type) va_arg (ap, int); |
663 | dt = (data_type) va_arg (ap, int); |
827 | |
664 | |
828 | if (dt == DT_END) |
665 | if (dt == DT_END) |
829 | break; |
666 | break; |
830 | |
667 | |
|
|
668 | if (dt == DT_AV) |
|
|
669 | { |
|
|
670 | AV *av = va_arg (ap, AV *); |
|
|
671 | |
|
|
672 | for (int i = 0; i <= av_len (av); ++i) |
|
|
673 | XPUSHs (*av_fetch (av, i, 1)); |
|
|
674 | } |
|
|
675 | else |
831 | XPUSHs (sv_2mortal (newSVdt_va (ap, dt))); |
676 | XPUSHs (sv_2mortal (newSVdt_va (ap, dt))); |
832 | } |
677 | } |
833 | |
678 | |
834 | va_end (ap); |
679 | va_end (ap); |
835 | |
680 | |
836 | PUTBACK; |
681 | PUTBACK; |
837 | int count = call_pv ("cf::invoke", G_SCALAR | G_EVAL); |
682 | int count = call_pv ("cf::do_invoke", G_SCALAR | G_EVAL); |
838 | SPAGAIN; |
683 | SPAGAIN; |
839 | |
684 | |
840 | count = count > 0 ? POPi : 0; |
685 | count = count > 0 ? POPi : 0; |
841 | |
686 | |
842 | FREETMPS; |
687 | FREETMPS; |
843 | LEAVE; |
688 | LEAVE; |
844 | |
689 | |
845 | return count; |
690 | return count; |
|
|
691 | } |
|
|
692 | |
|
|
693 | SV * |
|
|
694 | cfperl_result (int idx) |
|
|
695 | { |
|
|
696 | AV *av = get_av ("cfperl::invoke_results", 0); |
|
|
697 | if (!av) |
|
|
698 | return &PL_sv_undef; |
|
|
699 | |
|
|
700 | SV **sv = av_fetch (av, idx, 0); |
|
|
701 | if (!sv) |
|
|
702 | return &PL_sv_undef; |
|
|
703 | |
|
|
704 | return *sv; |
|
|
705 | } |
|
|
706 | |
|
|
707 | int |
|
|
708 | cfperl_result_INT (int idx) |
|
|
709 | { |
|
|
710 | return SvIV (cfperl_result (idx)); |
846 | } |
711 | } |
847 | |
712 | |
848 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
713 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
849 | |
714 | |
850 | BOOT: |
715 | BOOT: |
… | |
… | |
1334 | |
1199 | |
1335 | const_iv (KLASS_GLOBAL) |
1200 | const_iv (KLASS_GLOBAL) |
1336 | const_iv (KLASS_OBJECT) |
1201 | const_iv (KLASS_OBJECT) |
1337 | const_iv (KLASS_PLAYER) |
1202 | const_iv (KLASS_PLAYER) |
1338 | const_iv (KLASS_MAP) |
1203 | const_iv (KLASS_MAP) |
|
|
1204 | |
|
|
1205 | const_iv (EVENT_OBJECT_INSTANTIATE) |
1339 | }; |
1206 | }; |
1340 | |
1207 | |
1341 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1208 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1342 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1209 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1343 | |
1210 | |
1344 | static const struct { |
1211 | static const struct { |
1345 | const char *name; |
1212 | const char *name; |
1346 | IV klass; |
1213 | IV klass; |
1347 | IV iv; |
1214 | IV iv; |
1348 | } *eiv, event_iv[] = { |
1215 | } *eiv, event_iv[] = { |
1349 | # define def(klass,name) { # name, (IV)KLASS_ ## klass, (IV)EV_ ## klass ## _ ## name }, |
1216 | # define def(klass,name) { # name, (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1350 | # include "eventinc.h" |
1217 | # include "eventinc.h" |
1351 | # undef def |
1218 | # undef def |
1352 | }; |
1219 | }; |
1353 | |
1220 | |
1354 | AV *av = get_av ("cf::EVENT", 1); |
1221 | AV *av = get_av ("cf::EVENT", 1); |
… | |
… | |
1358 | AV *event = newAV (); |
1225 | AV *event = newAV (); |
1359 | av_push (event, newSVpv ((char *)eiv->name, 0)); |
1226 | av_push (event, newSVpv ((char *)eiv->name, 0)); |
1360 | av_push (event, newSViv (eiv->klass)); |
1227 | av_push (event, newSViv (eiv->klass)); |
1361 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1228 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1362 | } |
1229 | } |
1363 | |
|
|
1364 | static const struct { |
|
|
1365 | const char *name; |
|
|
1366 | IV iv; |
|
|
1367 | } *event, event_list[] = { |
|
|
1368 | # define const_event(name) { # name, (IV)EVENT_ ## name }, |
|
|
1369 | const_event (NONE) |
|
|
1370 | const_event (APPLY) |
|
|
1371 | const_event (ATTACK) |
|
|
1372 | const_event (DROP) |
|
|
1373 | const_event (DROP_ON) |
|
|
1374 | const_event (PICKUP) |
|
|
1375 | const_event (SAY) |
|
|
1376 | const_event (STOP) |
|
|
1377 | const_event (TIME) |
|
|
1378 | const_event (THROW) |
|
|
1379 | const_event (TRIGGER) |
|
|
1380 | const_event (CLOSE) |
|
|
1381 | const_event (TIMER) |
|
|
1382 | const_event (MOVE) |
|
|
1383 | |
|
|
1384 | const_event (SHOUT) |
|
|
1385 | const_event (TELL) |
|
|
1386 | const_event (MUZZLE) |
|
|
1387 | const_event (KICK) |
|
|
1388 | }; |
|
|
1389 | |
|
|
1390 | av = get_av ("cf::PLUGIN_EVENT", 1); |
|
|
1391 | |
|
|
1392 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
|
|
1393 | av_store (av, event->iv, newSVpv ((char *)event->name, 0)); |
|
|
1394 | |
1230 | |
1395 | static const struct { |
1231 | static const struct { |
1396 | int dtype; |
1232 | int dtype; |
1397 | const char *name; |
1233 | const char *name; |
1398 | IV idx; |
1234 | IV idx; |
… | |
… | |
1588 | |
1424 | |
1589 | int random_roll(int min, int max, object *op, int goodbad); |
1425 | int random_roll(int min, int max, object *op, int goodbad); |
1590 | |
1426 | |
1591 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1427 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1592 | |
1428 | |
|
|
1429 | int invoke (int event, SV *arg1, ...) |
|
|
1430 | CODE: |
|
|
1431 | { |
|
|
1432 | // parse first arg and call invoke_object etc as seen fit |
|
|
1433 | //TODO |
|
|
1434 | //cfperl_invoke (event, |
|
|
1435 | } |
|
|
1436 | |
1593 | int |
1437 | int |
1594 | exp_to_level (val64 exp) |
1438 | exp_to_level (val64 exp) |
1595 | CODE: |
1439 | CODE: |
1596 | { |
1440 | { |
1597 | int i = 0; |
1441 | int i = 0; |
… | |
… | |
1835 | { |
1679 | { |
1836 | int unused_type; |
1680 | int unused_type; |
1837 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1681 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1838 | } |
1682 | } |
1839 | |
1683 | |
|
|
1684 | SV *registry (object *op) |
|
|
1685 | CODE: |
|
|
1686 | RETVAL = registry_of (op); |
|
|
1687 | OUTPUT: |
|
|
1688 | RETVAL |
|
|
1689 | |
1840 | # syntatic sugar for easier use in event callbacks. |
1690 | # syntatic sugar for easier use in event callbacks. |
1841 | const char *options (object *op) |
1691 | const char *options (object *op) |
1842 | CODE: |
1692 | CODE: |
1843 | RETVAL = op->name; |
1693 | RETVAL = op->name; |
1844 | OUTPUT: |
1694 | OUTPUT: |
… | |
… | |
1914 | |
1764 | |
1915 | void cf_player_set_party (object *op, partylist *party) |
1765 | void cf_player_set_party (object *op, partylist *party) |
1916 | |
1766 | |
1917 | void kill_player (object *op) |
1767 | void kill_player (object *op) |
1918 | |
1768 | |
1919 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
|
|
1920 | |
|
|
1921 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1769 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
|
|
1770 | |
|
|
1771 | SV *registry (player *pl) |
|
|
1772 | CODE: |
|
|
1773 | RETVAL = registry_of (pl); |
|
|
1774 | OUTPUT: |
|
|
1775 | RETVAL |
1922 | |
1776 | |
1923 | player *cf_player_find (char *name) |
1777 | player *cf_player_find (char *name) |
1924 | PROTOTYPE: $ |
1778 | PROTOTYPE: $ |
1925 | |
1779 | |
1926 | void cf_player_move (player *pl, int dir) |
1780 | void cf_player_move (player *pl, int dir) |
… | |
… | |
2044 | RETVAL = &pl->last_stats; |
1898 | RETVAL = &pl->last_stats; |
2045 | OUTPUT: RETVAL |
1899 | OUTPUT: RETVAL |
2046 | |
1900 | |
2047 | |
1901 | |
2048 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1902 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
|
|
1903 | |
|
|
1904 | SV *registry (mapstruct *map) |
|
|
1905 | CODE: |
|
|
1906 | RETVAL = registry_of (map); |
|
|
1907 | OUTPUT: |
|
|
1908 | RETVAL |
2049 | |
1909 | |
2050 | SV * |
1910 | SV * |
2051 | get_property (mapstruct *obj, int type, int idx) |
1911 | get_property (mapstruct *obj, int type, int idx) |
2052 | CODE: |
1912 | CODE: |
2053 | RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx)); |
1913 | RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx)); |