… | |
… | |
28 | #include <perl.h> |
28 | #include <perl.h> |
29 | #include <XSUB.h> |
29 | #include <XSUB.h> |
30 | |
30 | |
31 | #undef save_long // clashes with libproto.h |
31 | #undef save_long // clashes with libproto.h |
32 | |
32 | |
33 | #define PLUGIN_NAME "cfperl" |
33 | #define PLUGIN_NAME "perl" |
34 | #define PLUGIN_VERSION "cfperl 0.0" |
34 | #define PLUGIN_VERSION "cfperl 0.0" |
35 | |
35 | |
36 | #ifndef __CEXTRACT__ |
36 | #ifndef __CEXTRACT__ |
37 | #include <plugin.h> |
37 | #include <plugin.h> |
38 | #endif |
38 | #endif |
… | |
… | |
52 | static f_plug_api gethook; |
52 | static f_plug_api gethook; |
53 | static f_plug_api registerGlobalEvent; |
53 | static f_plug_api registerGlobalEvent; |
54 | static f_plug_api unregisterGlobalEvent; |
54 | static f_plug_api unregisterGlobalEvent; |
55 | static f_plug_api systemDirectory; |
55 | static f_plug_api systemDirectory; |
56 | static f_plug_api object_set_property; |
56 | static f_plug_api object_set_property; |
|
|
57 | static f_plug_api map_get_map; |
57 | |
58 | |
58 | typedef struct |
59 | typedef struct |
59 | { |
60 | { |
60 | object* who; |
61 | object* who; |
61 | object* activator; |
62 | object* activator; |
62 | object* third; |
63 | object* third; |
63 | char message[1024]; |
64 | char message[1024]; |
64 | int fix; |
65 | int fix; |
65 | int event_code; |
66 | int event_code; |
66 | char options[1024]; |
67 | char extension[1024]; // name field, should invoke specific perl extension |
|
|
68 | char options[1024]; // slaying field of event_connectors |
67 | int returnvalue; |
69 | int returnvalue; |
68 | } CFPContext; |
70 | } CFPContext; |
69 | |
71 | |
70 | //static int current_command = -999; |
72 | //static int current_command = -999; |
71 | |
73 | |
|
|
74 | static HV *obj_cache; |
72 | static PerlInterpreter *perl; |
75 | static PerlInterpreter *perl; |
73 | |
76 | |
74 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
77 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
78 | |
|
|
79 | // garbage collect some perl objects, if possible |
|
|
80 | // all objects no longer referenced and empty are |
|
|
81 | // eligible for destruction. |
|
|
82 | void |
|
|
83 | clean_obj_cache () |
|
|
84 | { |
|
|
85 | static int count; |
|
|
86 | |
|
|
87 | if (++count & 7) |
|
|
88 | return; |
|
|
89 | |
|
|
90 | int todo = 1000; |
|
|
91 | do |
|
|
92 | { |
|
|
93 | I32 klen; |
|
|
94 | char *key; |
|
|
95 | HE *he = hv_iternext (obj_cache); |
|
|
96 | |
|
|
97 | if (he) |
|
|
98 | { |
|
|
99 | SV *sv = hv_iterval (obj_cache, he); |
|
|
100 | |
|
|
101 | // empty and unreferenced? nuke it |
|
|
102 | if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv)))) |
|
|
103 | { |
|
|
104 | hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); |
|
|
105 | todo++; |
|
|
106 | } |
|
|
107 | } |
|
|
108 | else |
|
|
109 | break; |
|
|
110 | } |
|
|
111 | while (--todo); |
|
|
112 | } |
75 | |
113 | |
76 | static SV * |
114 | static SV * |
77 | newSVptr (void *ptr, const char *klass) |
115 | newSVptr (void *ptr, const char *klass) |
78 | { |
116 | { |
|
|
117 | SV *sv; |
|
|
118 | |
79 | if (!ptr) |
119 | if (!ptr) |
80 | return &PL_sv_undef; |
120 | return &PL_sv_undef; |
81 | |
121 | |
|
|
122 | sv = newSV (0); |
|
|
123 | sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
|
|
124 | return sv_bless (newRV_noinc (sv), gv_stashpv (klass, 1)); |
|
|
125 | } |
|
|
126 | |
|
|
127 | static SV * |
|
|
128 | newSVptr_cached (void *ptr, const char *klass) |
|
|
129 | { |
|
|
130 | SV *sv, **he; |
|
|
131 | |
|
|
132 | if (!ptr) |
|
|
133 | return &PL_sv_undef; |
|
|
134 | |
|
|
135 | he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); |
|
|
136 | |
|
|
137 | if (he) |
|
|
138 | sv = *he; |
|
|
139 | else |
|
|
140 | { |
82 | HV *hv = newHV (); |
141 | HV *hv = newHV (); |
83 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
142 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
84 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
143 | sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
144 | hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); |
|
|
145 | } |
|
|
146 | |
|
|
147 | return newSVsv (sv); |
85 | } |
148 | } |
86 | |
149 | |
87 | static void |
150 | static void |
88 | clearSVptr (SV *sv) |
151 | clearSVptr (SV *sv) |
89 | { |
152 | { |
… | |
… | |
145 | sv = &PL_sv_undef; |
208 | sv = &PL_sv_undef; |
146 | else |
209 | else |
147 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
210 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
148 | { |
211 | { |
149 | case MAP: |
212 | case MAP: |
150 | sv = newSVptr (obj, "cf::object::map"); |
213 | sv = newSVptr_cached (obj, "cf::object::map"); |
151 | break; |
214 | break; |
152 | |
215 | |
153 | case PLAYER: |
216 | case PLAYER: |
154 | sv = newSVptr (obj, "cf::object::player"); |
217 | sv = newSVptr_cached (obj, "cf::object::player"); |
155 | break; |
218 | break; |
156 | |
219 | |
157 | default: |
220 | default: |
158 | sv = newSVptr (obj, "cf::object"); |
221 | sv = newSVptr_cached (obj, "cf::object"); |
159 | break; |
222 | break; |
160 | } |
223 | } |
161 | } |
224 | } |
162 | break; |
225 | break; |
163 | |
226 | |
… | |
… | |
191 | } |
254 | } |
192 | |
255 | |
193 | ///////////////////////////////////////////////////////////////////////////// |
256 | ///////////////////////////////////////////////////////////////////////////// |
194 | |
257 | |
195 | void |
258 | void |
196 | inject_event (CFPContext *context) |
259 | inject_event (const char *func, CFPContext *context) |
197 | { |
260 | { |
198 | dSP; |
261 | dSP; |
199 | |
262 | |
200 | ENTER; |
263 | ENTER; |
201 | SAVETMPS; |
264 | SAVETMPS; |
202 | |
265 | |
203 | PUSHMARK (SP); |
266 | PUSHMARK (SP); |
204 | |
|
|
205 | EXTEND (SP, 2); |
|
|
206 | //PUSHs (sv_2mortal (newSViv (type))); |
|
|
207 | |
267 | |
208 | HV *hv = newHV (); |
268 | HV *hv = newHV (); |
209 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
269 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
210 | hv_context (CFAPI_POBJECT, ,who); |
270 | hv_context (CFAPI_POBJECT, ,who); |
211 | hv_context (CFAPI_POBJECT, ,activator); |
271 | hv_context (CFAPI_POBJECT, ,activator); |
212 | hv_context (CFAPI_POBJECT, ,third); |
272 | hv_context (CFAPI_POBJECT, ,third); |
213 | hv_context (CFAPI_STRING , ,message); |
273 | hv_context (CFAPI_STRING , ,message); |
214 | hv_context (CFAPI_INT ,&,fix); |
274 | hv_context (CFAPI_INT ,&,fix); |
215 | hv_context (CFAPI_INT ,&,event_code); |
275 | hv_context (CFAPI_INT ,&,event_code); |
216 | hv_context (CFAPI_STRING , ,options); |
276 | hv_context (CFAPI_STRING , ,options); |
|
|
277 | hv_context (CFAPI_STRING , ,extension); |
217 | |
278 | |
218 | PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
279 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
219 | |
280 | |
220 | PUTBACK; |
281 | PUTBACK; |
221 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
282 | int count = call_pv (func, G_SCALAR | G_EVAL); |
222 | SPAGAIN; |
283 | SPAGAIN; |
223 | |
284 | |
224 | if (SvTRUE (ERRSV)) |
285 | if (SvTRUE (ERRSV)) |
225 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
286 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
226 | |
287 | |
… | |
… | |
336 | |
397 | |
337 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
398 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
338 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
399 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
339 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
400 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
340 | object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); |
401 | object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); |
|
|
402 | map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); |
|
|
403 | |
341 | cf_init_plugin (gethook); |
404 | cf_init_plugin (gethook); |
342 | |
405 | |
343 | /* Pick the global events you want to monitor from this plugin */ |
406 | /* Pick the global events you want to monitor from this plugin */ |
344 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
407 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
345 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
408 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
… | |
… | |
354 | registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener); |
417 | registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener); |
355 | registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); |
418 | registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); |
356 | registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); |
419 | registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); |
357 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
420 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
358 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
421 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
|
|
422 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
359 | |
423 | |
360 | char *argv[] = { |
424 | char *argv[] = { |
361 | "", |
425 | "", |
362 | "-e" |
426 | "-e" |
363 | "BEGIN {" |
427 | "BEGIN {" |
… | |
… | |
377 | |
441 | |
378 | perl_destruct (perl); |
442 | perl_destruct (perl); |
379 | perl_free (perl); |
443 | perl_free (perl); |
380 | perl = 0; |
444 | perl = 0; |
381 | } |
445 | } |
|
|
446 | else |
|
|
447 | { |
|
|
448 | obj_cache = newHV (); |
|
|
449 | } |
382 | |
450 | |
383 | return 0; |
451 | return 0; |
384 | } |
452 | } |
385 | |
453 | |
386 | void * |
454 | void * |
… | |
… | |
405 | { |
473 | { |
406 | case EVENT_CRASH: |
474 | case EVENT_CRASH: |
407 | printf ("Unimplemented for now\n"); |
475 | printf ("Unimplemented for now\n"); |
408 | break; |
476 | break; |
409 | |
477 | |
|
|
478 | case EVENT_MAPENTER: |
|
|
479 | case EVENT_MAPLEAVE: |
|
|
480 | case EVENT_FREE_OB: |
410 | case EVENT_BORN: |
481 | case EVENT_BORN: |
|
|
482 | case EVENT_REMOVE: |
411 | context.activator = va_arg (args, object *); |
483 | context.activator = va_arg (args, object *); |
412 | break; |
484 | break; |
413 | |
485 | |
414 | case EVENT_PLAYER_DEATH: |
486 | case EVENT_PLAYER_DEATH: |
415 | context.who = va_arg (args, object *); |
487 | context.who = va_arg (args, object *); |
… | |
… | |
419 | context.who = va_arg (args, object *); |
491 | context.who = va_arg (args, object *); |
420 | context.activator = va_arg (args, object *); |
492 | context.activator = va_arg (args, object *); |
421 | break; |
493 | break; |
422 | |
494 | |
423 | case EVENT_LOGIN: |
495 | case EVENT_LOGIN: |
424 | pl = va_arg (args, player *); |
|
|
425 | context.activator = pl->ob; |
|
|
426 | buf = va_arg (args, char *); |
|
|
427 | if (buf != 0) |
|
|
428 | strcpy (context.message, buf); |
|
|
429 | break; |
|
|
430 | |
|
|
431 | case EVENT_LOGOUT: |
496 | case EVENT_LOGOUT: |
432 | pl = va_arg (args, player *); |
497 | pl = va_arg (args, player *); |
433 | context.activator = pl->ob; |
498 | context.activator = pl->ob; |
434 | buf = va_arg (args, char *); |
499 | buf = va_arg (args, char *); |
435 | if (buf != 0) |
500 | if (buf != 0) |
436 | strcpy (context.message, buf); |
501 | strncpy (context.message, buf, sizeof (context.message)); |
437 | break; |
|
|
438 | |
|
|
439 | case EVENT_REMOVE: |
|
|
440 | context.activator = va_arg (args, object *); |
|
|
441 | break; |
502 | break; |
442 | |
503 | |
443 | case EVENT_SHOUT: |
504 | case EVENT_SHOUT: |
444 | context.activator = va_arg (args, object *); |
|
|
445 | buf = va_arg (args, char *); |
|
|
446 | if (buf != 0) |
|
|
447 | strcpy (context.message, buf); |
|
|
448 | break; |
|
|
449 | |
|
|
450 | case EVENT_MUZZLE: |
505 | case EVENT_MUZZLE: |
451 | context.activator = va_arg (args, object *); |
|
|
452 | buf = va_arg (args, char *); |
|
|
453 | if (buf != 0) |
|
|
454 | strcpy (context.message, buf); |
|
|
455 | break; |
|
|
456 | |
|
|
457 | case EVENT_KICK: |
506 | case EVENT_KICK: |
458 | context.activator = va_arg (args, object *); |
507 | context.activator = va_arg (args, object *); |
459 | buf = va_arg (args, char *); |
508 | buf = va_arg (args, char *); |
460 | if (buf != 0) |
509 | if (buf != 0) |
461 | strcpy (context.message, buf); |
510 | strncpy (context.message, buf, sizeof (context.message)); |
462 | break; |
|
|
463 | |
|
|
464 | case EVENT_MAPENTER: |
|
|
465 | context.activator = va_arg (args, object *); |
|
|
466 | break; |
|
|
467 | |
|
|
468 | case EVENT_MAPLEAVE: |
|
|
469 | context.activator = va_arg (args, object *); |
|
|
470 | break; |
511 | break; |
471 | |
512 | |
472 | case EVENT_CLOCK: |
513 | case EVENT_CLOCK: |
|
|
514 | clean_obj_cache (); |
|
|
515 | break; |
|
|
516 | |
|
|
517 | case EVENT_TELL: |
473 | break; |
518 | break; |
474 | |
519 | |
475 | case EVENT_MAPRESET: |
520 | case EVENT_MAPRESET: |
476 | buf = va_arg (args, char *); |
521 | buf = va_arg (args, char *); |
477 | if (buf != 0) |
522 | if (buf != 0) |
478 | strcpy (context.message, buf); |
523 | strncpy (context.message, buf, sizeof (context.message)); |
479 | break; |
|
|
480 | |
|
|
481 | case EVENT_TELL: |
|
|
482 | break; |
524 | break; |
483 | } |
525 | } |
484 | |
526 | |
485 | va_end (args); |
527 | va_end (args); |
486 | |
528 | |
487 | inject_event (&context); |
529 | if (context.event_code == EVENT_FREE_OB) |
|
|
530 | { |
|
|
531 | SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); |
|
|
532 | |
|
|
533 | if (sv) |
|
|
534 | clearSVptr (sv); |
|
|
535 | } |
|
|
536 | else |
|
|
537 | inject_event ("cf::inject_global_event", &context); |
488 | |
538 | |
489 | rv = context.returnvalue; |
539 | rv = context.returnvalue; |
490 | |
540 | |
491 | return &rv; |
541 | return &rv; |
492 | } |
542 | } |
… | |
… | |
508 | |
558 | |
509 | context.who = va_arg (args, object *); |
559 | context.who = va_arg (args, object *); |
510 | context.event_code = va_arg (args, int); |
560 | context.event_code = va_arg (args, int); |
511 | context.activator = va_arg (args, object *); |
561 | context.activator = va_arg (args, object *); |
512 | context.third = va_arg (args, object *); |
562 | context.third = va_arg (args, object *); |
|
|
563 | |
513 | buf = va_arg (args, char *); |
564 | buf = va_arg (args, char *); |
514 | |
|
|
515 | if (buf != 0) |
565 | if (buf != 0) |
516 | strcpy (context.message, buf); |
566 | strncpy (context.message, buf, sizeof (context.message)); |
517 | |
567 | |
518 | context.fix = va_arg (args, int); |
568 | context.fix = va_arg (args, int); |
|
|
569 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
519 | strcpy (context.options, va_arg (args, char *)); |
570 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
520 | context.returnvalue = 0; |
571 | context.returnvalue = 0; |
521 | va_end (args); |
572 | va_end (args); |
522 | |
573 | |
523 | inject_event (&context); |
574 | inject_event ("cf::inject_event", &context); |
524 | |
575 | |
525 | rv = context.returnvalue; |
576 | rv = context.returnvalue; |
526 | return &rv; |
577 | return &rv; |
527 | } |
578 | } |
528 | |
579 | |
… | |
… | |
834 | const_iv (F_CURSED) |
885 | const_iv (F_CURSED) |
835 | const_iv (F_DAMNED) |
886 | const_iv (F_DAMNED) |
836 | const_iv (F_OPEN) |
887 | const_iv (F_OPEN) |
837 | const_iv (F_NOPICK) |
888 | const_iv (F_NOPICK) |
838 | const_iv (F_LOCKED) |
889 | const_iv (F_LOCKED) |
|
|
890 | |
|
|
891 | const_iv (P_BLOCKSVIEW) |
|
|
892 | const_iv (P_NO_MAGIC) |
|
|
893 | const_iv (P_IS_ALIVE) |
|
|
894 | const_iv (P_NO_CLERIC) |
|
|
895 | const_iv (P_NEED_UPDATE) |
|
|
896 | const_iv (P_NO_ERROR) |
|
|
897 | const_iv (P_OUT_OF_MAP) |
|
|
898 | const_iv (P_NEW_MAP) |
|
|
899 | |
|
|
900 | const_iv (UP_OBJ_INSERT) |
|
|
901 | const_iv (UP_OBJ_REMOVE) |
|
|
902 | const_iv (UP_OBJ_CHANGE) |
|
|
903 | const_iv (UP_OBJ_FACE) |
|
|
904 | |
|
|
905 | const_iv (INS_NO_MERGE) |
|
|
906 | const_iv (INS_ABOVE_FLOOR_ONLY) |
|
|
907 | const_iv (INS_NO_WALK_ON) |
|
|
908 | const_iv (INS_ON_TOP) |
|
|
909 | const_iv (INS_BELOW_ORIGINATOR) |
|
|
910 | const_iv (INS_MAP_LOAD) |
|
|
911 | |
|
|
912 | const_iv (WILL_APPLY_HANDLE) |
|
|
913 | const_iv (WILL_APPLY_TREASURE) |
|
|
914 | const_iv (WILL_APPLY_EARTHWALL) |
|
|
915 | const_iv (WILL_APPLY_DOOR) |
|
|
916 | const_iv (WILL_APPLY_FOOD) |
839 | }; |
917 | }; |
840 | |
918 | |
841 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
919 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
842 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
920 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
843 | |
921 | |
… | |
… | |
857 | const_event (TIME) |
935 | const_event (TIME) |
858 | const_event (THROW) |
936 | const_event (THROW) |
859 | const_event (TRIGGER) |
937 | const_event (TRIGGER) |
860 | const_event (CLOSE) |
938 | const_event (CLOSE) |
861 | const_event (TIMER) |
939 | const_event (TIMER) |
|
|
940 | const_event (MOVE) |
862 | |
941 | |
863 | const_event (BORN) |
942 | const_event (BORN) |
864 | const_event (CLOCK) |
943 | const_event (CLOCK) |
865 | const_event (CRASH) |
944 | const_event (CRASH) |
866 | const_event (PLAYER_DEATH) |
945 | const_event (PLAYER_DEATH) |
… | |
… | |
873 | const_event (REMOVE) |
952 | const_event (REMOVE) |
874 | const_event (SHOUT) |
953 | const_event (SHOUT) |
875 | const_event (TELL) |
954 | const_event (TELL) |
876 | const_event (MUZZLE) |
955 | const_event (MUZZLE) |
877 | const_event (KICK) |
956 | const_event (KICK) |
|
|
957 | //const_event (FREE_OB) |
878 | }; |
958 | }; |
879 | |
959 | |
880 | AV *av = get_av ("cf::EVENT", 1); |
960 | AV *av = get_av ("cf::EVENT", 1); |
881 | |
961 | |
882 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
962 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
… | |
… | |
1082 | break; |
1162 | break; |
1083 | default: |
1163 | default: |
1084 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1164 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1085 | } |
1165 | } |
1086 | |
1166 | |
|
|
1167 | void |
|
|
1168 | inv (object *obj) |
|
|
1169 | PROTOTYPE: $ |
|
|
1170 | PPCODE: |
|
|
1171 | { |
|
|
1172 | object *o; |
|
|
1173 | for (o = obj->inv; o; o = o->below) |
|
|
1174 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
|
|
1175 | } |
|
|
1176 | |
1087 | int cf_object_get_resistance (object *op, int rtype) |
1177 | int cf_object_get_resistance (object *op, int rtype) |
1088 | ALIAS: resistance = 0 |
1178 | ALIAS: resistance = 0 |
1089 | |
1179 | |
1090 | int cf_object_get_flag (object *op, int flag) |
1180 | int cf_object_get_flag (object *op, int flag) |
1091 | ALIAS: flag = 0 |
1181 | ALIAS: flag = 0 |
1092 | |
1182 | |
1093 | void cf_object_set_flag (object *op, int flag, int value) |
1183 | void cf_object_set_flag (object *op, int flag, int value) |
1094 | |
1184 | |
1095 | void cf_object_move (object *op, object *originator, int dir) |
1185 | void cf_object_move (object *op, int dir, object *originator = op) |
1096 | |
1186 | |
1097 | void cf_object_apply (object *op, object *author, int flags) |
1187 | void cf_object_apply (object *op, object *author, int flags = 0) |
1098 | |
1188 | |
1099 | void cf_object_apply_below (object *op) |
1189 | void cf_object_apply_below (object *op) |
1100 | |
1190 | |
1101 | void cf_object_remove (object *op) |
1191 | void cf_object_remove (object *op) |
1102 | |
1192 | |
… | |
… | |
1183 | void cf_fix_object (object *pl) |
1273 | void cf_fix_object (object *pl) |
1184 | ALIAS: fix = 0 |
1274 | ALIAS: fix = 0 |
1185 | |
1275 | |
1186 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1276 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1187 | |
1277 | |
|
|
1278 | object *get_nearest_player (object *ob) |
|
|
1279 | ALIAS: nearest_player = 0 |
|
|
1280 | PREINIT: |
|
|
1281 | extern object *get_nearest_player (object *); |
|
|
1282 | |
|
|
1283 | void rangevector (object *ob, object *other, int flags = 0) |
|
|
1284 | PROTOTYPE: $$;$ |
|
|
1285 | PPCODE: |
|
|
1286 | { |
|
|
1287 | rv_vector rv; |
|
|
1288 | get_rangevector (ob, other, &rv, flags); |
|
|
1289 | EXTEND (SP, 5); |
|
|
1290 | PUSHs (newSVuv (rv.distance)); |
|
|
1291 | PUSHs (newSViv (rv.distance_x)); |
|
|
1292 | PUSHs (newSViv (rv.distance_y)); |
|
|
1293 | PUSHs (newSViv (rv.direction)); |
|
|
1294 | PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); |
|
|
1295 | } |
|
|
1296 | |
|
|
1297 | bool on_same_map_as (object *ob, object *other) |
|
|
1298 | CODE: |
|
|
1299 | RETVAL = on_same_map (ob, other); |
|
|
1300 | OUTPUT: RETVAL |
|
|
1301 | |
1188 | |
1302 | |
1189 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1303 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1190 | |
1304 | |
1191 | player *player (object *op) |
1305 | player *player (object *op) |
1192 | CODE: |
1306 | CODE: |
… | |
… | |
1223 | # nonstandard |
1337 | # nonstandard |
1224 | object *ob (player *pl) |
1338 | object *ob (player *pl) |
1225 | CODE: |
1339 | CODE: |
1226 | RETVAL = pl->ob; |
1340 | RETVAL = pl->ob; |
1227 | OUTPUT: RETVAL |
1341 | OUTPUT: RETVAL |
|
|
1342 | |
|
|
1343 | player *first () |
|
|
1344 | CODE: |
|
|
1345 | RETVAL = first_player; |
|
|
1346 | OUTPUT: RETVAL |
|
|
1347 | |
|
|
1348 | player *next (player *pl) |
|
|
1349 | CODE: |
|
|
1350 | RETVAL = pl->next; |
|
|
1351 | OUTPUT: RETVAL |
|
|
1352 | |
|
|
1353 | void |
|
|
1354 | list () |
|
|
1355 | PPCODE: |
|
|
1356 | { |
|
|
1357 | player *pl; |
|
|
1358 | for (pl = first_player; pl; pl = pl->next) |
|
|
1359 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
|
|
1360 | } |
1228 | |
1361 | |
1229 | |
1362 | |
1230 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1363 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1231 | |
1364 | |
1232 | SV * |
1365 | SV * |
… | |
… | |
1245 | break; |
1378 | break; |
1246 | default: |
1379 | default: |
1247 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1380 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1248 | } |
1381 | } |
1249 | |
1382 | |
|
|
1383 | mapstruct *new (int width, int height) |
|
|
1384 | PROTOTYPE: |
|
|
1385 | CODE: |
|
|
1386 | { |
|
|
1387 | int unused_type; |
|
|
1388 | RETVAL = map_get_map (&unused_type, 0, width, height); |
|
|
1389 | } |
|
|
1390 | OUTPUT: |
|
|
1391 | RETVAL |
|
|
1392 | |
1250 | mapstruct *cf_map_get_map (char *name) |
1393 | mapstruct *cf_map_get_map (char *name) |
1251 | PROTOTYPE: $ |
1394 | PROTOTYPE: $ |
1252 | ALIAS: map = 0 |
1395 | ALIAS: map = 0 |
1253 | |
1396 | |
1254 | mapstruct *cf_map_get_first () |
1397 | mapstruct *cf_map_get_first () |
… | |
… | |
1262 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1405 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1263 | C_ARGS: str, map, nx, ny |
1406 | C_ARGS: str, map, nx, ny |
1264 | |
1407 | |
1265 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
1408 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
1266 | |
1409 | |
|
|
1410 | void |
|
|
1411 | at (mapstruct *obj, unsigned int x, unsigned int y) |
|
|
1412 | PROTOTYPE: $$$ |
|
|
1413 | INIT: |
|
|
1414 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY; |
|
|
1415 | PPCODE: |
|
|
1416 | { |
|
|
1417 | object *o; |
|
|
1418 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
|
|
1419 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
|
|
1420 | } |
|
|
1421 | |
|
|
1422 | SV * |
|
|
1423 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
|
|
1424 | PROTOTYPE: $$$ |
|
|
1425 | ALIAS: |
|
|
1426 | top_at = 1 |
|
|
1427 | flags_at = 2 |
|
|
1428 | light_at = 3 |
|
|
1429 | move_block_at = 4 |
|
|
1430 | move_slow_at = 5 |
|
|
1431 | move_on_at = 6 |
|
|
1432 | move_off_at = 7 |
|
|
1433 | INIT: |
|
|
1434 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; |
|
|
1435 | CODE: |
|
|
1436 | switch (ix) |
|
|
1437 | { |
|
|
1438 | case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; |
|
|
1439 | case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; |
|
|
1440 | case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; |
|
|
1441 | case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; |
|
|
1442 | case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; |
|
|
1443 | case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; |
|
|
1444 | case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; |
|
|
1445 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
|
|
1446 | } |
|
|
1447 | OUTPUT: |
|
|
1448 | RETVAL |
1267 | |
1449 | |
1268 | |
1450 | |
1269 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
1451 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
1270 | |
1452 | |
1271 | archetype*cf_archetype_get_first() |
1453 | archetype *cf_archetype_get_first() |
1272 | PROTOTYPE: |
1454 | PROTOTYPE: |
1273 | ALIAS: first = 0 |
1455 | ALIAS: first = 0 |
1274 | |
1456 | |
1275 | archetype *cf_archetype_get_next (archetype *arch) |
1457 | archetype *cf_archetype_get_next (archetype *arch) |
1276 | ALIAS: next = 0 |
1458 | ALIAS: next = 0 |