… | |
… | |
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.1" |
35 | |
35 | |
36 | #ifndef __CEXTRACT__ |
36 | #ifndef __CEXTRACT__ |
37 | #include <plugin.h> |
37 | #include <plugin.h> |
38 | #endif |
38 | #endif |
39 | |
39 | |
… | |
… | |
46 | #include <plugin_common.h> |
46 | #include <plugin_common.h> |
47 | |
47 | |
48 | #include <stdarg.h> |
48 | #include <stdarg.h> |
49 | |
49 | |
50 | #include "perlxsi.c" |
50 | #include "perlxsi.c" |
|
|
51 | |
|
|
52 | typedef object object_ornull; |
|
|
53 | typedef mapstruct mapstruct_ornull; |
51 | |
54 | |
52 | static f_plug_api gethook; |
55 | static f_plug_api gethook; |
53 | static f_plug_api registerGlobalEvent; |
56 | static f_plug_api registerGlobalEvent; |
54 | static f_plug_api unregisterGlobalEvent; |
57 | static f_plug_api unregisterGlobalEvent; |
55 | static f_plug_api systemDirectory; |
58 | static f_plug_api systemDirectory; |
56 | static f_plug_api object_set_property; |
59 | static f_plug_api object_set_property; |
57 | static f_plug_api map_get_map; |
60 | static f_plug_api map_get_map; |
|
|
61 | static f_plug_api object_insert; |
58 | |
62 | |
59 | typedef struct |
63 | typedef struct |
60 | { |
64 | { |
61 | object* who; |
65 | object* who; |
62 | object* activator; |
66 | object* activator; |
63 | object* third; |
67 | object* third; |
64 | char message[1024]; |
68 | char message[1024]; |
65 | int fix; |
69 | int fix; |
66 | int event_code; |
70 | int event_code; |
67 | char options[1024]; |
71 | char extension[1024]; // name field, should invoke specific perl extension |
|
|
72 | char options[1024]; // slaying field of event_connectors |
68 | int returnvalue; |
73 | int returnvalue; |
69 | } CFPContext; |
74 | } CFPContext; |
70 | |
75 | |
71 | //static int current_command = -999; |
76 | //static int current_command = -999; |
72 | |
77 | |
|
|
78 | static HV *obj_cache; |
73 | static PerlInterpreter *perl; |
79 | static PerlInterpreter *perl; |
74 | |
80 | |
75 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
81 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
82 | |
|
|
83 | // garbage collect some perl objects, if possible |
|
|
84 | // all objects no longer referenced and empty are |
|
|
85 | // eligible for destruction. |
|
|
86 | void |
|
|
87 | clean_obj_cache () |
|
|
88 | { |
|
|
89 | static int count; |
|
|
90 | |
|
|
91 | if (++count & 7) |
|
|
92 | return; |
|
|
93 | |
|
|
94 | int todo = 1000; |
|
|
95 | do |
|
|
96 | { |
|
|
97 | I32 klen; |
|
|
98 | char *key; |
|
|
99 | HE *he = hv_iternext (obj_cache); |
|
|
100 | |
|
|
101 | if (he) |
|
|
102 | { |
|
|
103 | SV *sv = hv_iterval (obj_cache, he); |
|
|
104 | |
|
|
105 | // empty and unreferenced? nuke it |
|
|
106 | if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv)))) |
|
|
107 | { |
|
|
108 | hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); |
|
|
109 | todo++; |
|
|
110 | } |
|
|
111 | } |
|
|
112 | else |
|
|
113 | break; |
|
|
114 | } |
|
|
115 | while (--todo); |
|
|
116 | } |
76 | |
117 | |
77 | static SV * |
118 | static SV * |
78 | newSVptr (void *ptr, const char *klass) |
119 | newSVptr (void *ptr, const char *klass) |
79 | { |
120 | { |
|
|
121 | SV *sv; |
|
|
122 | |
80 | if (!ptr) |
123 | if (!ptr) |
81 | return &PL_sv_undef; |
124 | return &PL_sv_undef; |
82 | |
125 | |
|
|
126 | sv = newSV (0); |
|
|
127 | sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
|
|
128 | return sv_bless (newRV_noinc (sv), gv_stashpv (klass, 1)); |
|
|
129 | } |
|
|
130 | |
|
|
131 | static SV * |
|
|
132 | newSVptr_cached (void *ptr, const char *klass) |
|
|
133 | { |
|
|
134 | SV *sv, **he; |
|
|
135 | |
|
|
136 | if (!ptr) |
|
|
137 | return &PL_sv_undef; |
|
|
138 | |
|
|
139 | he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); |
|
|
140 | |
|
|
141 | if (he) |
|
|
142 | sv = *he; |
|
|
143 | else |
|
|
144 | { |
83 | HV *hv = newHV (); |
145 | HV *hv = newHV (); |
84 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
146 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
85 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
147 | sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
148 | hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); |
|
|
149 | } |
|
|
150 | |
|
|
151 | return newSVsv (sv); |
86 | } |
152 | } |
87 | |
153 | |
88 | static void |
154 | static void |
89 | clearSVptr (SV *sv) |
155 | clearSVptr (SV *sv) |
90 | { |
156 | { |
… | |
… | |
105 | |
171 | |
106 | if (!mg) |
172 | if (!mg) |
107 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
173 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
108 | |
174 | |
109 | return (long)mg->mg_ptr; |
175 | return (long)mg->mg_ptr; |
|
|
176 | } |
|
|
177 | |
|
|
178 | static long |
|
|
179 | SvPTR_ornull (SV *sv, const char *klass) |
|
|
180 | { |
|
|
181 | if (SvOK (sv)) |
|
|
182 | return SvPTR (sv, klass); |
|
|
183 | else |
|
|
184 | return 0; |
110 | } |
185 | } |
111 | |
186 | |
112 | SV * |
187 | SV * |
113 | newSVcfapi (int type, ...) |
188 | newSVcfapi (int type, ...) |
114 | { |
189 | { |
… | |
… | |
146 | sv = &PL_sv_undef; |
221 | sv = &PL_sv_undef; |
147 | else |
222 | else |
148 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
223 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
149 | { |
224 | { |
150 | case MAP: |
225 | case MAP: |
151 | sv = newSVptr (obj, "cf::object::map"); |
226 | sv = newSVptr_cached (obj, "cf::object::map"); |
152 | break; |
227 | break; |
153 | |
228 | |
154 | case PLAYER: |
229 | case PLAYER: |
155 | sv = newSVptr (obj, "cf::object::player"); |
230 | sv = newSVptr_cached (obj, "cf::object::player"); |
156 | break; |
231 | break; |
157 | |
232 | |
158 | default: |
233 | default: |
159 | sv = newSVptr (obj, "cf::object"); |
234 | sv = newSVptr_cached (obj, "cf::object"); |
160 | break; |
235 | break; |
161 | } |
236 | } |
162 | } |
237 | } |
163 | break; |
238 | break; |
164 | |
239 | |
… | |
… | |
192 | } |
267 | } |
193 | |
268 | |
194 | ///////////////////////////////////////////////////////////////////////////// |
269 | ///////////////////////////////////////////////////////////////////////////// |
195 | |
270 | |
196 | void |
271 | void |
197 | inject_event (CFPContext *context) |
272 | inject_event (const char *func, CFPContext *context) |
198 | { |
273 | { |
199 | dSP; |
274 | dSP; |
200 | |
275 | |
201 | ENTER; |
276 | ENTER; |
202 | SAVETMPS; |
277 | SAVETMPS; |
203 | |
278 | |
204 | PUSHMARK (SP); |
279 | PUSHMARK (SP); |
205 | |
|
|
206 | EXTEND (SP, 2); |
|
|
207 | //PUSHs (sv_2mortal (newSViv (type))); |
|
|
208 | |
280 | |
209 | HV *hv = newHV (); |
281 | HV *hv = newHV (); |
210 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
282 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
211 | hv_context (CFAPI_POBJECT, ,who); |
283 | hv_context (CFAPI_POBJECT, ,who); |
212 | hv_context (CFAPI_POBJECT, ,activator); |
284 | hv_context (CFAPI_POBJECT, ,activator); |
213 | hv_context (CFAPI_POBJECT, ,third); |
285 | hv_context (CFAPI_POBJECT, ,third); |
214 | hv_context (CFAPI_STRING , ,message); |
286 | hv_context (CFAPI_STRING , ,message); |
215 | hv_context (CFAPI_INT ,&,fix); |
287 | hv_context (CFAPI_INT ,&,fix); |
216 | hv_context (CFAPI_INT ,&,event_code); |
288 | hv_context (CFAPI_INT ,&,event_code); |
217 | hv_context (CFAPI_STRING , ,options); |
289 | hv_context (CFAPI_STRING , ,options); |
|
|
290 | hv_context (CFAPI_STRING , ,extension); |
218 | |
291 | |
219 | PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
292 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
220 | |
293 | |
221 | PUTBACK; |
294 | PUTBACK; |
222 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
295 | int count = call_pv (func, G_SCALAR | G_EVAL); |
223 | SPAGAIN; |
296 | SPAGAIN; |
224 | |
297 | |
225 | if (SvTRUE (ERRSV)) |
298 | if (SvTRUE (ERRSV)) |
226 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
299 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
227 | |
300 | |
… | |
… | |
338 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
411 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
339 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
412 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
340 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
413 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
341 | object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); |
414 | object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); |
342 | map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); |
415 | map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); |
|
|
416 | object_insert = gethook (&rtype, hooktype, "cfapi_object_insert"); |
343 | |
417 | |
344 | cf_init_plugin (gethook); |
418 | cf_init_plugin (gethook); |
345 | |
419 | |
346 | /* Pick the global events you want to monitor from this plugin */ |
420 | /* Pick the global events you want to monitor from this plugin */ |
347 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
421 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
… | |
… | |
357 | registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener); |
431 | registerGlobalEvent (NULL, EVENT_REMOVE, PLUGIN_NAME, globalEventListener); |
358 | registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); |
432 | registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); |
359 | registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); |
433 | registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); |
360 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
434 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
361 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
435 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
|
|
436 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
362 | |
437 | |
363 | char *argv[] = { |
438 | char *argv[] = { |
364 | "", |
439 | "", |
365 | "-e" |
440 | "-e" |
366 | "BEGIN {" |
441 | "BEGIN {" |
… | |
… | |
380 | |
455 | |
381 | perl_destruct (perl); |
456 | perl_destruct (perl); |
382 | perl_free (perl); |
457 | perl_free (perl); |
383 | perl = 0; |
458 | perl = 0; |
384 | } |
459 | } |
|
|
460 | else |
|
|
461 | { |
|
|
462 | obj_cache = newHV (); |
|
|
463 | } |
385 | |
464 | |
386 | return 0; |
465 | return 0; |
387 | } |
466 | } |
388 | |
467 | |
389 | void * |
468 | void * |
… | |
… | |
408 | { |
487 | { |
409 | case EVENT_CRASH: |
488 | case EVENT_CRASH: |
410 | printf ("Unimplemented for now\n"); |
489 | printf ("Unimplemented for now\n"); |
411 | break; |
490 | break; |
412 | |
491 | |
|
|
492 | case EVENT_MAPENTER: |
|
|
493 | case EVENT_MAPLEAVE: |
|
|
494 | case EVENT_FREE_OB: |
413 | case EVENT_BORN: |
495 | case EVENT_BORN: |
|
|
496 | case EVENT_REMOVE: |
414 | context.activator = va_arg (args, object *); |
497 | context.activator = va_arg (args, object *); |
415 | break; |
498 | break; |
416 | |
499 | |
417 | case EVENT_PLAYER_DEATH: |
500 | case EVENT_PLAYER_DEATH: |
418 | context.who = va_arg (args, object *); |
501 | context.who = va_arg (args, object *); |
… | |
… | |
422 | context.who = va_arg (args, object *); |
505 | context.who = va_arg (args, object *); |
423 | context.activator = va_arg (args, object *); |
506 | context.activator = va_arg (args, object *); |
424 | break; |
507 | break; |
425 | |
508 | |
426 | case EVENT_LOGIN: |
509 | case EVENT_LOGIN: |
427 | pl = va_arg (args, player *); |
|
|
428 | context.activator = pl->ob; |
|
|
429 | buf = va_arg (args, char *); |
|
|
430 | if (buf != 0) |
|
|
431 | strcpy (context.message, buf); |
|
|
432 | break; |
|
|
433 | |
|
|
434 | case EVENT_LOGOUT: |
510 | case EVENT_LOGOUT: |
435 | pl = va_arg (args, player *); |
511 | pl = va_arg (args, player *); |
436 | context.activator = pl->ob; |
512 | context.activator = pl->ob; |
437 | buf = va_arg (args, char *); |
513 | buf = va_arg (args, char *); |
438 | if (buf != 0) |
514 | if (buf != 0) |
439 | strcpy (context.message, buf); |
515 | strncpy (context.message, buf, sizeof (context.message)); |
440 | break; |
|
|
441 | |
|
|
442 | case EVENT_REMOVE: |
|
|
443 | context.activator = va_arg (args, object *); |
|
|
444 | break; |
516 | break; |
445 | |
517 | |
446 | case EVENT_SHOUT: |
518 | case EVENT_SHOUT: |
447 | context.activator = va_arg (args, object *); |
|
|
448 | buf = va_arg (args, char *); |
|
|
449 | if (buf != 0) |
|
|
450 | strcpy (context.message, buf); |
|
|
451 | break; |
|
|
452 | |
|
|
453 | case EVENT_MUZZLE: |
519 | case EVENT_MUZZLE: |
454 | context.activator = va_arg (args, object *); |
|
|
455 | buf = va_arg (args, char *); |
|
|
456 | if (buf != 0) |
|
|
457 | strcpy (context.message, buf); |
|
|
458 | break; |
|
|
459 | |
|
|
460 | case EVENT_KICK: |
520 | case EVENT_KICK: |
461 | context.activator = va_arg (args, object *); |
521 | context.activator = va_arg (args, object *); |
462 | buf = va_arg (args, char *); |
522 | buf = va_arg (args, char *); |
463 | if (buf != 0) |
523 | if (buf != 0) |
464 | strcpy (context.message, buf); |
524 | strncpy (context.message, buf, sizeof (context.message)); |
465 | break; |
|
|
466 | |
|
|
467 | case EVENT_MAPENTER: |
|
|
468 | context.activator = va_arg (args, object *); |
|
|
469 | break; |
|
|
470 | |
|
|
471 | case EVENT_MAPLEAVE: |
|
|
472 | context.activator = va_arg (args, object *); |
|
|
473 | break; |
525 | break; |
474 | |
526 | |
475 | case EVENT_CLOCK: |
527 | case EVENT_CLOCK: |
|
|
528 | clean_obj_cache (); |
|
|
529 | break; |
|
|
530 | |
|
|
531 | case EVENT_TELL: |
476 | break; |
532 | break; |
477 | |
533 | |
478 | case EVENT_MAPRESET: |
534 | case EVENT_MAPRESET: |
479 | buf = va_arg (args, char *); |
535 | buf = va_arg (args, char *); |
480 | if (buf != 0) |
536 | if (buf != 0) |
481 | strcpy (context.message, buf); |
537 | strncpy (context.message, buf, sizeof (context.message)); |
482 | break; |
|
|
483 | |
|
|
484 | case EVENT_TELL: |
|
|
485 | break; |
538 | break; |
486 | } |
539 | } |
487 | |
540 | |
488 | va_end (args); |
541 | va_end (args); |
489 | |
542 | |
490 | inject_event (&context); |
543 | if (context.event_code == EVENT_FREE_OB) |
|
|
544 | { |
|
|
545 | SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); |
|
|
546 | |
|
|
547 | if (sv) |
|
|
548 | clearSVptr (sv); |
|
|
549 | } |
|
|
550 | else |
|
|
551 | inject_event ("cf::inject_global_event", &context); |
491 | |
552 | |
492 | rv = context.returnvalue; |
553 | rv = context.returnvalue; |
493 | |
554 | |
494 | return &rv; |
555 | return &rv; |
495 | } |
556 | } |
… | |
… | |
511 | |
572 | |
512 | context.who = va_arg (args, object *); |
573 | context.who = va_arg (args, object *); |
513 | context.event_code = va_arg (args, int); |
574 | context.event_code = va_arg (args, int); |
514 | context.activator = va_arg (args, object *); |
575 | context.activator = va_arg (args, object *); |
515 | context.third = va_arg (args, object *); |
576 | context.third = va_arg (args, object *); |
|
|
577 | |
516 | buf = va_arg (args, char *); |
578 | buf = va_arg (args, char *); |
517 | |
|
|
518 | if (buf != 0) |
579 | if (buf != 0) |
519 | strcpy (context.message, buf); |
580 | strncpy (context.message, buf, sizeof (context.message)); |
520 | |
581 | |
521 | context.fix = va_arg (args, int); |
582 | context.fix = va_arg (args, int); |
|
|
583 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
522 | strcpy (context.options, va_arg (args, char *)); |
584 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
523 | context.returnvalue = 0; |
585 | context.returnvalue = 0; |
524 | va_end (args); |
586 | va_end (args); |
525 | |
587 | |
526 | inject_event (&context); |
588 | inject_event ("cf::inject_event", &context); |
527 | |
589 | |
528 | rv = context.returnvalue; |
590 | rv = context.returnvalue; |
529 | return &rv; |
591 | return &rv; |
530 | } |
592 | } |
531 | |
593 | |
… | |
… | |
846 | const_iv (P_NO_CLERIC) |
908 | const_iv (P_NO_CLERIC) |
847 | const_iv (P_NEED_UPDATE) |
909 | const_iv (P_NEED_UPDATE) |
848 | const_iv (P_NO_ERROR) |
910 | const_iv (P_NO_ERROR) |
849 | const_iv (P_OUT_OF_MAP) |
911 | const_iv (P_OUT_OF_MAP) |
850 | const_iv (P_NEW_MAP) |
912 | const_iv (P_NEW_MAP) |
|
|
913 | |
|
|
914 | const_iv (UP_OBJ_INSERT) |
|
|
915 | const_iv (UP_OBJ_REMOVE) |
|
|
916 | const_iv (UP_OBJ_CHANGE) |
|
|
917 | const_iv (UP_OBJ_FACE) |
|
|
918 | |
|
|
919 | const_iv (INS_NO_MERGE) |
|
|
920 | const_iv (INS_ABOVE_FLOOR_ONLY) |
|
|
921 | const_iv (INS_NO_WALK_ON) |
|
|
922 | const_iv (INS_ON_TOP) |
|
|
923 | const_iv (INS_BELOW_ORIGINATOR) |
|
|
924 | const_iv (INS_MAP_LOAD) |
|
|
925 | |
|
|
926 | const_iv (WILL_APPLY_HANDLE) |
|
|
927 | const_iv (WILL_APPLY_TREASURE) |
|
|
928 | const_iv (WILL_APPLY_EARTHWALL) |
|
|
929 | const_iv (WILL_APPLY_DOOR) |
|
|
930 | const_iv (WILL_APPLY_FOOD) |
851 | }; |
931 | }; |
852 | |
932 | |
853 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
933 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
854 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
934 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
855 | |
935 | |
… | |
… | |
869 | const_event (TIME) |
949 | const_event (TIME) |
870 | const_event (THROW) |
950 | const_event (THROW) |
871 | const_event (TRIGGER) |
951 | const_event (TRIGGER) |
872 | const_event (CLOSE) |
952 | const_event (CLOSE) |
873 | const_event (TIMER) |
953 | const_event (TIMER) |
|
|
954 | const_event (MOVE) |
874 | |
955 | |
875 | const_event (BORN) |
956 | const_event (BORN) |
876 | const_event (CLOCK) |
957 | const_event (CLOCK) |
877 | const_event (CRASH) |
958 | const_event (CRASH) |
878 | const_event (PLAYER_DEATH) |
959 | const_event (PLAYER_DEATH) |
… | |
… | |
885 | const_event (REMOVE) |
966 | const_event (REMOVE) |
886 | const_event (SHOUT) |
967 | const_event (SHOUT) |
887 | const_event (TELL) |
968 | const_event (TELL) |
888 | const_event (MUZZLE) |
969 | const_event (MUZZLE) |
889 | const_event (KICK) |
970 | const_event (KICK) |
|
|
971 | //const_event (FREE_OB) |
890 | }; |
972 | }; |
891 | |
973 | |
892 | AV *av = get_av ("cf::EVENT", 1); |
974 | AV *av = get_av ("cf::EVENT", 1); |
893 | |
975 | |
894 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
976 | for (event = event_list + sizeof (event_list) / sizeof (event_list [0]); event-- > event_list; ) |
… | |
… | |
1094 | break; |
1176 | break; |
1095 | default: |
1177 | default: |
1096 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1178 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
1097 | } |
1179 | } |
1098 | |
1180 | |
|
|
1181 | void |
|
|
1182 | inv (object *obj) |
|
|
1183 | PROTOTYPE: $ |
|
|
1184 | PPCODE: |
|
|
1185 | { |
|
|
1186 | object *o; |
|
|
1187 | for (o = obj->inv; o; o = o->below) |
|
|
1188 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
|
|
1189 | } |
|
|
1190 | |
1099 | int cf_object_get_resistance (object *op, int rtype) |
1191 | int cf_object_get_resistance (object *op, int rtype) |
1100 | ALIAS: resistance = 0 |
1192 | ALIAS: resistance = 0 |
1101 | |
1193 | |
1102 | int cf_object_get_flag (object *op, int flag) |
1194 | int cf_object_get_flag (object *op, int flag) |
1103 | ALIAS: flag = 0 |
1195 | ALIAS: flag = 0 |
1104 | |
1196 | |
1105 | void cf_object_set_flag (object *op, int flag, int value) |
1197 | void cf_object_set_flag (object *op, int flag, int value) |
1106 | |
1198 | |
1107 | void cf_object_move (object *op, object *originator, int dir) |
1199 | void cf_object_move (object *op, int dir, object *originator = op) |
1108 | |
1200 | |
1109 | void cf_object_apply (object *op, object *author, int flags) |
1201 | void cf_object_apply (object *op, object *author, int flags = 0) |
1110 | |
1202 | |
1111 | void cf_object_apply_below (object *op) |
1203 | void cf_object_apply_below (object *op) |
1112 | |
1204 | |
1113 | void cf_object_remove (object *op) |
1205 | void cf_object_remove (object *op) |
1114 | |
1206 | |
… | |
… | |
1118 | |
1210 | |
1119 | int cf_object_transfer (object *op, int x, int y, int r, object *orig) |
1211 | int cf_object_transfer (object *op, int x, int y, int r, object *orig) |
1120 | |
1212 | |
1121 | int cf_object_change_map (object *op, int x, int y, mapstruct *map) |
1213 | int cf_object_change_map (object *op, int x, int y, mapstruct *map) |
1122 | |
1214 | |
1123 | object *cf_object_clone (object *op, int clonetype) |
1215 | object *cf_object_clone (object *op, int clonetype = 0) |
1124 | |
1216 | |
1125 | int cf_object_pay_item (object *op, object *buyer) |
1217 | int cf_object_pay_item (object *op, object *buyer) |
1126 | |
1218 | |
1127 | int cf_object_pay_amount (object *op, double amount) |
1219 | int cf_object_pay_amount (object *op, double amount) |
1128 | |
1220 | |
… | |
… | |
1172 | char *cf_object_get_key (object *op, char *keyname) |
1264 | char *cf_object_get_key (object *op, char *keyname) |
1173 | ALIAS: key = 0 |
1265 | ALIAS: key = 0 |
1174 | |
1266 | |
1175 | void cf_object_set_key (object *op, char *keyname, char *value) |
1267 | void cf_object_set_key (object *op, char *keyname, char *value) |
1176 | |
1268 | |
1177 | char * |
|
|
1178 | base_name (object *ob, int plural) |
|
|
1179 | CODE: |
|
|
1180 | RETVAL = cf_query_base_name (ob, plural); |
|
|
1181 | OUTPUT: RETVAL |
|
|
1182 | |
|
|
1183 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1269 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1184 | |
1270 | |
|
|
1271 | void cf_fix_object (object *pl) |
|
|
1272 | ALIAS: fix = 0 |
|
|
1273 | |
|
|
1274 | object *cf_insert_ob_in_ob (object *ob, object *where) |
|
|
1275 | |
1185 | object *cf_create_object_by_name (const char *name = 0) |
1276 | object *create_object_by_name (const char *name = 0) |
1186 | PROTOTYPE: ;$ |
1277 | PROTOTYPE: ;$ |
1187 | ALIAS: |
1278 | ALIAS: |
1188 | create_object = 0 |
1279 | create_object = 0 |
1189 | new = 0 |
1280 | new = 0 |
1190 | CODE: |
1281 | CODE: |
1191 | RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); |
1282 | RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); |
1192 | OUTPUT: |
1283 | OUTPUT: |
1193 | RETVAL |
1284 | RETVAL |
1194 | |
1285 | |
1195 | void cf_fix_object (object *pl) |
1286 | object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) |
1196 | ALIAS: fix = 0 |
1287 | PROTOTYPE: $$$$$$ |
|
|
1288 | CODE: |
|
|
1289 | { |
|
|
1290 | int unused_type; |
|
|
1291 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
|
|
1292 | } |
1197 | |
1293 | |
1198 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1294 | object *get_nearest_player (object *ob) |
|
|
1295 | ALIAS: nearest_player = 0 |
|
|
1296 | PREINIT: |
|
|
1297 | extern object *get_nearest_player (object *); |
|
|
1298 | |
|
|
1299 | void rangevector (object *ob, object *other, int flags = 0) |
|
|
1300 | PROTOTYPE: $$;$ |
|
|
1301 | PPCODE: |
|
|
1302 | { |
|
|
1303 | rv_vector rv; |
|
|
1304 | get_rangevector (ob, other, &rv, flags); |
|
|
1305 | EXTEND (SP, 5); |
|
|
1306 | PUSHs (newSVuv (rv.distance)); |
|
|
1307 | PUSHs (newSViv (rv.distance_x)); |
|
|
1308 | PUSHs (newSViv (rv.distance_y)); |
|
|
1309 | PUSHs (newSViv (rv.direction)); |
|
|
1310 | PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); |
|
|
1311 | } |
|
|
1312 | |
|
|
1313 | bool on_same_map_as (object *ob, object *other) |
|
|
1314 | CODE: |
|
|
1315 | RETVAL = on_same_map (ob, other); |
|
|
1316 | OUTPUT: RETVAL |
|
|
1317 | |
|
|
1318 | char * |
|
|
1319 | base_name (object *ob, int plural) |
|
|
1320 | CODE: |
|
|
1321 | RETVAL = cf_query_base_name (ob, plural); |
|
|
1322 | OUTPUT: RETVAL |
1199 | |
1323 | |
1200 | |
1324 | |
1201 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1325 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1202 | |
1326 | |
1203 | player *player (object *op) |
1327 | player *player (object *op) |
… | |
… | |
1207 | |
1331 | |
1208 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1332 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1209 | |
1333 | |
1210 | object *cf_player_send_inventory (object *op) |
1334 | object *cf_player_send_inventory (object *op) |
1211 | |
1335 | |
|
|
1336 | player *contr (object *op) |
|
|
1337 | CODE: |
|
|
1338 | RETVAL = op->contr; |
|
|
1339 | OUTPUT: RETVAL |
|
|
1340 | |
1212 | char *cf_player_get_ip (object *op) |
1341 | char *cf_player_get_ip (object *op) |
1213 | ALIAS: ip = 0 |
1342 | ALIAS: ip = 0 |
1214 | |
1343 | |
1215 | object *cf_player_get_marked_item (object *op) |
1344 | object *cf_player_get_marked_item (object *op) |
1216 | ALIAS: marked_item = 0 |
1345 | ALIAS: marked_item = 0 |
… | |
… | |
1229 | |
1358 | |
1230 | player *cf_player_find (char *name) |
1359 | player *cf_player_find (char *name) |
1231 | PROTOTYPE: $ |
1360 | PROTOTYPE: $ |
1232 | |
1361 | |
1233 | void cf_player_move (player *pl, int dir) |
1362 | void cf_player_move (player *pl, int dir) |
|
|
1363 | |
|
|
1364 | void MapNewmapCmd (player *pl) |
1234 | |
1365 | |
1235 | # nonstandard |
1366 | # nonstandard |
1236 | object *ob (player *pl) |
1367 | object *ob (player *pl) |
1237 | CODE: |
1368 | CODE: |
1238 | RETVAL = pl->ob; |
1369 | RETVAL = pl->ob; |
1239 | OUTPUT: RETVAL |
1370 | OUTPUT: RETVAL |
|
|
1371 | |
|
|
1372 | player *first () |
|
|
1373 | CODE: |
|
|
1374 | RETVAL = first_player; |
|
|
1375 | OUTPUT: RETVAL |
|
|
1376 | |
|
|
1377 | player *next (player *pl) |
|
|
1378 | CODE: |
|
|
1379 | RETVAL = pl->next; |
|
|
1380 | OUTPUT: RETVAL |
|
|
1381 | |
|
|
1382 | void |
|
|
1383 | list () |
|
|
1384 | PPCODE: |
|
|
1385 | { |
|
|
1386 | player *pl; |
|
|
1387 | for (pl = first_player; pl; pl = pl->next) |
|
|
1388 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
|
|
1389 | } |
1240 | |
1390 | |
1241 | |
1391 | |
1242 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1392 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1243 | |
1393 | |
1244 | SV * |
1394 | SV * |
… | |
… | |
1284 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1434 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1285 | C_ARGS: str, map, nx, ny |
1435 | C_ARGS: str, map, nx, ny |
1286 | |
1436 | |
1287 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
1437 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
1288 | |
1438 | |
|
|
1439 | void |
1289 | SV *at (mapstruct *obj, unsigned int x, unsigned int y) |
1440 | at (mapstruct *obj, unsigned int x, unsigned int y) |
1290 | PROTOTYPE: $$$ |
1441 | PROTOTYPE: $$$ |
1291 | INIT: |
1442 | INIT: |
1292 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_UNDEF; |
1443 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY; |
1293 | PPCODE: |
1444 | PPCODE: |
1294 | { |
1445 | { |
1295 | object *o; |
1446 | object *o; |
1296 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
1447 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
1297 | XPUSHs (newSVcfapi (CFAPI_POBJECT, o)); |
1448 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1298 | } |
1449 | } |
1299 | |
1450 | |
|
|
1451 | SV * |
1300 | SV *bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1452 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1301 | PROTOTYPE: $$$ |
1453 | PROTOTYPE: $$$ |
1302 | ALIAS: |
1454 | ALIAS: |
1303 | top_at = 1 |
1455 | top_at = 1 |
1304 | flags_at = 2 |
1456 | flags_at = 2 |
1305 | light_at = 3 |
1457 | light_at = 3 |
… | |
… | |
1325 | RETVAL |
1477 | RETVAL |
1326 | |
1478 | |
1327 | |
1479 | |
1328 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
1480 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
1329 | |
1481 | |
1330 | archetype*cf_archetype_get_first() |
1482 | archetype *cf_archetype_get_first() |
1331 | PROTOTYPE: |
1483 | PROTOTYPE: |
1332 | ALIAS: first = 0 |
1484 | ALIAS: first = 0 |
1333 | |
1485 | |
1334 | archetype *cf_archetype_get_next (archetype *arch) |
1486 | archetype *cf_archetype_get_next (archetype *arch) |
1335 | ALIAS: next = 0 |
1487 | ALIAS: next = 0 |