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 | |
… | |
… | |
42 | #else |
41 | #else |
43 | #define MODULEAPI |
42 | #define MODULEAPI |
44 | #endif |
43 | #endif |
45 | |
44 | |
46 | #include <plugin_common.h> |
45 | #include <plugin_common.h> |
|
|
46 | #include <sounds.h> |
47 | |
47 | |
48 | #include <stdarg.h> |
48 | #include <stdarg.h> |
49 | |
49 | |
|
|
50 | #include <sproto.h> |
|
|
51 | |
|
|
52 | //#include "EventAPI.h" |
50 | #include "perlxsi.c" |
53 | #include "perlxsi.c" |
|
|
54 | |
|
|
55 | extern sint64 *levels; // the experience table |
51 | |
56 | |
52 | typedef object object_ornull; |
57 | typedef object object_ornull; |
53 | typedef mapstruct mapstruct_ornull; |
58 | typedef mapstruct mapstruct_ornull; |
|
|
59 | |
|
|
60 | typedef double val64; |
|
|
61 | #define newSVval64 newSVnv |
|
|
62 | #define SvVAL64 SvNV |
54 | |
63 | |
55 | static f_plug_api gethook; |
64 | static f_plug_api gethook; |
56 | static f_plug_api registerGlobalEvent; |
65 | static f_plug_api registerGlobalEvent; |
57 | static f_plug_api unregisterGlobalEvent; |
66 | static f_plug_api unregisterGlobalEvent; |
58 | static f_plug_api systemDirectory; |
67 | static f_plug_api systemDirectory; |
… | |
… | |
64 | typedef struct |
73 | typedef struct |
65 | { |
74 | { |
66 | object* who; |
75 | object* who; |
67 | object* activator; |
76 | object* activator; |
68 | object* third; |
77 | object* third; |
|
|
78 | object* event; |
69 | mapstruct* map; |
79 | mapstruct* map; |
70 | char message[1024]; |
80 | char message[1024]; |
71 | int fix; // seems to be python-only, and should not be part of the API |
81 | int fix; // seems to be python-only, and should not be part of the API |
72 | int event_code; |
82 | int event_code; |
73 | char extension[1024]; // name field, should invoke specific perl extension |
83 | char extension[1024]; // name field, should invoke specific perl extension |
… | |
… | |
75 | int returnvalue; |
85 | int returnvalue; |
76 | } CFPContext; |
86 | } CFPContext; |
77 | |
87 | |
78 | static HV *obj_cache; |
88 | static HV *obj_cache; |
79 | static PerlInterpreter *perl; |
89 | static PerlInterpreter *perl; |
|
|
90 | |
|
|
91 | #define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value)))) |
|
|
92 | #define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype)) |
|
|
93 | #define PUSH_OB PUSHcfapi_va(POBJECT, object *) |
|
|
94 | #define PUSH_PL PUSHcfapi_va(PPLAYER, player *) |
|
|
95 | #define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) |
|
|
96 | #define PUSH_PV PUSHcfapi_va(STRING, const char *) |
|
|
97 | #define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) |
80 | |
98 | |
81 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
99 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | |
100 | |
83 | // garbage collect some perl objects, if possible |
101 | // garbage collect some perl objects, if possible |
84 | // all objects no longer referenced and empty are |
102 | // all objects no longer referenced and empty are |
… | |
… | |
216 | case CFAPI_INT: |
234 | case CFAPI_INT: |
217 | sv = newSViv (*va_arg (args, int *)); |
235 | sv = newSViv (*va_arg (args, int *)); |
218 | break; |
236 | break; |
219 | |
237 | |
220 | case CFAPI_LONG: |
238 | case CFAPI_LONG: |
221 | sv = newSViv (*va_arg (args, long *)); |
239 | sv = newSVval64 ((val64)*va_arg (args, sint64 *)); |
222 | break; |
240 | break; |
223 | |
241 | |
224 | case CFAPI_DOUBLE: |
242 | case CFAPI_DOUBLE: |
225 | sv = newSViv (*va_arg (args, double *)); |
243 | sv = newSVnv (*va_arg (args, double *)); |
226 | break; |
244 | break; |
227 | |
245 | |
228 | case CFAPI_STRING: |
246 | case CFAPI_STRING: |
229 | { |
247 | { |
230 | char *str = va_arg (args, char *); |
248 | char *str = va_arg (args, char *); |
… | |
… | |
237 | object *obj = va_arg (args, object *); |
255 | object *obj = va_arg (args, object *); |
238 | |
256 | |
239 | if (!obj) |
257 | if (!obj) |
240 | sv = &PL_sv_undef; |
258 | sv = &PL_sv_undef; |
241 | else |
259 | else |
242 | switch (*(int *)cf_object_get_property (obj, CFAPI_OBJECT_PROP_TYPE)) |
260 | switch (obj->type) |
243 | { |
261 | { |
244 | case MAP: |
262 | case MAP: |
245 | sv = newSVptr_cached (obj, "cf::object::map"); |
263 | sv = newSVptr_cached (obj, "cf::object::map::wrap"); |
246 | break; |
264 | break; |
247 | |
265 | |
248 | case PLAYER: |
266 | case PLAYER: |
249 | sv = newSVptr_cached (obj, "cf::object::player"); |
267 | sv = newSVptr_cached (obj, "cf::object::player::wrap"); |
250 | break; |
268 | break; |
251 | |
269 | |
252 | default: |
270 | default: |
253 | sv = newSVptr_cached (obj, "cf::object"); |
271 | sv = newSVptr_cached (obj, "cf::object::wrap"); |
254 | break; |
272 | break; |
255 | } |
273 | } |
256 | } |
274 | } |
257 | break; |
275 | break; |
258 | |
276 | |
259 | case CFAPI_PMAP: |
277 | case CFAPI_PMAP: |
260 | sv = newSVptr (va_arg (args, mapstruct *), "cf::map"); |
278 | sv = newSVptr (va_arg (args, mapstruct *), "cf::map::wrap"); |
261 | break; |
279 | break; |
262 | |
280 | |
263 | case CFAPI_PPLAYER: |
281 | case CFAPI_PPLAYER: |
264 | sv = newSVptr (va_arg (args, player *), "cf::player"); |
282 | sv = newSVptr (va_arg (args, player *), "cf::player::wrap"); |
265 | break; |
283 | break; |
266 | |
284 | |
267 | case CFAPI_PARCH: |
285 | case CFAPI_PARCH: |
268 | sv = newSVptr (va_arg (args, archetype *), "cf::arch"); |
286 | sv = newSVptr (va_arg (args, archetype *), "cf::arch::wrap"); |
269 | break; |
287 | break; |
270 | |
288 | |
271 | case CFAPI_PPARTY: |
289 | case CFAPI_PPARTY: |
272 | sv = newSVptr (va_arg (args, partylist *), "cf::party"); |
290 | sv = newSVptr (va_arg (args, partylist *), "cf::party::wrap"); |
273 | break; |
291 | break; |
274 | |
292 | |
275 | case CFAPI_PREGION: |
293 | case CFAPI_PREGION: |
276 | sv = newSVptr (va_arg (args, region *), "cf::region"); |
294 | sv = newSVptr (va_arg (args, region *), "cf::region::wrap"); |
277 | break; |
295 | break; |
278 | |
296 | |
279 | default: |
297 | default: |
280 | assert (("unhandled type in newSVcfapi", 0)); |
298 | assert (("unhandled type in newSVcfapi", 0)); |
281 | } |
299 | } |
… | |
… | |
285 | return sv; |
303 | return sv; |
286 | } |
304 | } |
287 | |
305 | |
288 | ///////////////////////////////////////////////////////////////////////////// |
306 | ///////////////////////////////////////////////////////////////////////////// |
289 | |
307 | |
290 | void |
308 | extern "C" int initPlugin (const char *iversion, f_plug_api gethooksptr) |
291 | inject_event (const char *func, CFPContext *context) |
309 | { |
|
|
310 | gethook = gethooksptr; |
|
|
311 | printf (PLUGIN_VERSION " init\n"); |
|
|
312 | |
|
|
313 | return 0; |
|
|
314 | } |
|
|
315 | |
|
|
316 | static CommArray_s rtn_cmd; |
|
|
317 | |
|
|
318 | int |
|
|
319 | runPluginCommand (object *obj, char *params) |
292 | { |
320 | { |
293 | dSP; |
321 | dSP; |
294 | |
322 | |
295 | ENTER; |
323 | ENTER; |
296 | SAVETMPS; |
324 | SAVETMPS; |
297 | |
325 | |
298 | PUSHMARK (SP); |
326 | PUSHMARK (SP); |
299 | |
327 | |
300 | HV *hv = newHV (); |
328 | EXTEND (SP, 3); |
301 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
329 | PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0))); |
302 | hv_context (CFAPI_POBJECT, ,who); |
330 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj))); |
303 | hv_context (CFAPI_POBJECT, ,activator); |
|
|
304 | hv_context (CFAPI_POBJECT, ,third); |
|
|
305 | hv_context (CFAPI_PMAP, ,map); |
|
|
306 | hv_context (CFAPI_STRING , ,message); |
|
|
307 | hv_context (CFAPI_INT ,&,fix); |
|
|
308 | hv_context (CFAPI_INT ,&,event_code); |
|
|
309 | hv_context (CFAPI_STRING , ,options); |
|
|
310 | hv_context (CFAPI_STRING , ,extension); |
|
|
311 | |
331 | |
312 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
332 | if (params) |
|
|
333 | PUSHs (sv_2mortal (newSVpv (params, 0))); |
313 | |
334 | |
314 | PUTBACK; |
335 | PUTBACK; |
315 | int count = call_pv (func, G_SCALAR | G_EVAL); |
336 | int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL); |
316 | SPAGAIN; |
337 | SPAGAIN; |
317 | |
338 | |
318 | if (SvTRUE (ERRSV)) |
339 | if (SvTRUE (ERRSV)) |
319 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
340 | LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV)); |
320 | |
341 | |
321 | context->returnvalue = count > 0 ? POPi : 0; |
342 | int returnvalue = count > 0 ? POPi : -1; |
322 | |
343 | |
323 | PUTBACK; |
344 | PUTBACK; |
324 | FREETMPS; |
345 | FREETMPS; |
325 | LEAVE; |
346 | LEAVE; |
326 | } |
|
|
327 | |
|
|
328 | ///////////////////////////////////////////////////////////////////////////// |
|
|
329 | |
|
|
330 | int |
|
|
331 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
|
|
332 | { |
|
|
333 | gethook = gethooksptr; |
|
|
334 | printf (PLUGIN_VERSION " init\n"); |
|
|
335 | |
|
|
336 | return 0; |
|
|
337 | } |
|
|
338 | |
|
|
339 | static CommArray_s rtn_cmd; |
|
|
340 | |
|
|
341 | int |
|
|
342 | runPluginCommand (object *obj, char *params) |
|
|
343 | { |
|
|
344 | dSP; |
|
|
345 | |
|
|
346 | ENTER; |
|
|
347 | SAVETMPS; |
|
|
348 | |
|
|
349 | PUSHMARK (SP); |
|
|
350 | |
|
|
351 | EXTEND (SP, 3); |
|
|
352 | PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0))); |
|
|
353 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj))); |
|
|
354 | |
|
|
355 | if (params) |
|
|
356 | PUSHs (sv_2mortal (newSVpv (params, 0))); |
|
|
357 | |
|
|
358 | PUTBACK; |
|
|
359 | int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL); |
|
|
360 | SPAGAIN; |
|
|
361 | |
|
|
362 | if (SvTRUE (ERRSV)) |
|
|
363 | LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV)); |
|
|
364 | |
|
|
365 | int returnvalue = count > 0 ? POPi : -1; |
|
|
366 | |
|
|
367 | PUTBACK; |
|
|
368 | FREETMPS; |
|
|
369 | LEAVE; |
|
|
370 | |
347 | |
371 | return returnvalue; |
348 | return returnvalue; |
372 | } |
349 | } |
373 | |
350 | |
374 | void * |
|
|
375 | getPluginProperty (int *type, ...) |
351 | extern "C" void *getPluginProperty (int *type, ...) |
376 | { |
352 | { |
377 | va_list args; |
353 | va_list args; |
378 | char *propname; |
354 | char *propname; |
379 | int i; |
355 | int i; |
380 | va_start (args, type); |
356 | va_start (args, type); |
… | |
… | |
403 | } |
379 | } |
404 | } |
380 | } |
405 | else if (!strcmp (propname, "Identification")) |
381 | else if (!strcmp (propname, "Identification")) |
406 | { |
382 | { |
407 | va_end (args); |
383 | va_end (args); |
408 | return PLUGIN_NAME; |
384 | return (void*) PLUGIN_NAME; |
409 | } |
385 | } |
410 | else if (!strcmp (propname, "FullName")) |
386 | else if (!strcmp (propname, "FullName")) |
411 | { |
387 | { |
412 | va_end (args); |
388 | va_end (args); |
413 | return PLUGIN_VERSION; |
389 | return (void*) PLUGIN_VERSION; |
414 | } |
390 | } |
415 | else |
391 | else |
416 | va_end (args); |
392 | va_end (args); |
417 | |
393 | |
418 | return NULL; |
394 | return NULL; |
419 | } |
395 | } |
420 | |
396 | |
421 | void *globalEventListener (int *type, ...); |
397 | void *globalEventListener (int *type, ...); |
422 | |
398 | |
423 | int |
399 | extern "C" int postInitPlugin () |
424 | postInitPlugin () |
|
|
425 | { |
400 | { |
426 | int hooktype = 1; |
401 | int hooktype = 1; |
427 | int rtype = 0; |
402 | int rtype = 0; |
428 | |
403 | |
429 | printf (PLUGIN_VERSION " post init\n"); |
404 | printf (PLUGIN_VERSION " post init\n"); |
430 | |
405 | |
431 | registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
406 | registerGlobalEvent = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_register_global_event"); |
432 | unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
407 | unregisterGlobalEvent = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); |
433 | systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); |
408 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
434 | object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); |
409 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
435 | map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); |
410 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
436 | object_insert = gethook (&rtype, hooktype, "cfapi_object_insert"); |
411 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
437 | |
412 | |
438 | cf_init_plugin (gethook); |
413 | cf_init_plugin (gethook); |
439 | |
414 | |
440 | /* Pick the global events you want to monitor from this plugin */ |
415 | /* Pick the global events you want to monitor from this plugin */ |
441 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
416 | registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); |
442 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
417 | registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); |
443 | //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener); |
418 | //registerGlobalEvent (NULL, EVENT_CRASH, PLUGIN_NAME, globalEventListener); |
|
|
419 | registerGlobalEvent (NULL, EVENT_FIND_UNARMED_SKILL, PLUGIN_NAME, globalEventListener); |
|
|
420 | registerGlobalEvent (NULL, EVENT_PLAYER_USE_SKILL, PLUGIN_NAME, globalEventListener); |
|
|
421 | registerGlobalEvent (NULL, EVENT_CAST_SPELL, PLUGIN_NAME, globalEventListener); |
|
|
422 | registerGlobalEvent (NULL, EVENT_MONSTER_USE_SKILL, PLUGIN_NAME, globalEventListener); |
444 | registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener); |
423 | registerGlobalEvent (NULL, EVENT_PLAYER_DEATH, PLUGIN_NAME, globalEventListener); |
445 | registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener); |
424 | registerGlobalEvent (NULL, EVENT_GKILL, PLUGIN_NAME, globalEventListener); |
446 | registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); |
425 | registerGlobalEvent (NULL, EVENT_LOGIN, PLUGIN_NAME, globalEventListener); |
447 | registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); |
426 | registerGlobalEvent (NULL, EVENT_LOGOUT, PLUGIN_NAME, globalEventListener); |
448 | registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); |
427 | registerGlobalEvent (NULL, EVENT_MAPENTER, PLUGIN_NAME, globalEventListener); |
… | |
… | |
456 | registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); |
435 | registerGlobalEvent (NULL, EVENT_SHOUT, PLUGIN_NAME, globalEventListener); |
457 | registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); |
436 | registerGlobalEvent (NULL, EVENT_TELL, PLUGIN_NAME, globalEventListener); |
458 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
437 | registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); |
459 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
438 | registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); |
460 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
439 | registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); |
|
|
440 | registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); |
|
|
441 | registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); |
|
|
442 | registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener); |
461 | |
443 | |
462 | char *argv[] = { |
444 | char *argv[] = { |
463 | "", |
445 | "", |
464 | "-e" |
446 | "-e" |
465 | "BEGIN {" |
447 | "BEGIN {" |
… | |
… | |
471 | }; |
453 | }; |
472 | |
454 | |
473 | perl = perl_alloc (); |
455 | perl = perl_alloc (); |
474 | perl_construct (perl); |
456 | perl_construct (perl); |
475 | |
457 | |
|
|
458 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
459 | |
476 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
460 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
477 | { |
461 | { |
478 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
462 | printf ("unable to initialize perl-interpreter, continuing without.\n"); |
479 | |
463 | |
480 | perl_destruct (perl); |
464 | perl_destruct (perl); |
… | |
… | |
491 | |
475 | |
492 | void * |
476 | void * |
493 | globalEventListener (int *type, ...) |
477 | globalEventListener (int *type, ...) |
494 | { |
478 | { |
495 | va_list args; |
479 | va_list args; |
496 | static int rv = 0; |
480 | static int rv; |
497 | CFPContext context; |
481 | int event_code; |
498 | char *buf; |
|
|
499 | player *pl; |
|
|
500 | object *op; |
|
|
501 | |
482 | |
502 | if (!perl) |
483 | if (!perl) |
503 | return; |
484 | return NULL; |
504 | |
|
|
505 | memset (&context, 0, sizeof (context)); |
|
|
506 | |
485 | |
507 | va_start (args, type); |
486 | va_start (args, type); |
508 | context.event_code = va_arg (args, int); |
487 | event_code = va_arg (args, int); |
509 | |
488 | |
510 | switch (context.event_code) |
489 | if (event_code == EVENT_FREE_OB) |
511 | { |
490 | { |
512 | case EVENT_CRASH: |
491 | player *pl; |
513 | printf ("Unimplemented for now\n"); |
492 | object *op; |
514 | break; |
493 | SV *sv; |
515 | |
494 | |
516 | case EVENT_MAPLOAD: |
|
|
517 | case EVENT_MAPOUT: |
|
|
518 | case EVENT_MAPIN: |
|
|
519 | case EVENT_MAPCLEAN: |
|
|
520 | context.map = va_arg (args, mapstruct *); |
|
|
521 | break; |
|
|
522 | |
|
|
523 | case EVENT_MAPENTER: |
|
|
524 | case EVENT_MAPLEAVE: |
|
|
525 | case EVENT_FREE_OB: |
|
|
526 | case EVENT_BORN: |
|
|
527 | case EVENT_REMOVE: |
|
|
528 | context.activator = va_arg (args, object *); |
|
|
529 | break; |
|
|
530 | |
|
|
531 | case EVENT_PLAYER_DEATH: |
|
|
532 | context.who = va_arg (args, object *); |
495 | op = va_arg (args, object *); |
533 | break; |
|
|
534 | |
|
|
535 | case EVENT_GKILL: |
|
|
536 | context.who = va_arg (args, object *); |
|
|
537 | context.activator = va_arg (args, object *); |
|
|
538 | break; |
|
|
539 | |
|
|
540 | case EVENT_LOGIN: |
|
|
541 | case EVENT_LOGOUT: |
|
|
542 | pl = va_arg (args, player *); |
|
|
543 | context.activator = pl->ob; |
|
|
544 | buf = va_arg (args, char *); |
|
|
545 | if (buf != 0) |
|
|
546 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
547 | break; |
|
|
548 | |
|
|
549 | case EVENT_SHOUT: |
|
|
550 | case EVENT_MUZZLE: |
|
|
551 | case EVENT_KICK: |
|
|
552 | context.activator = va_arg (args, object *); |
|
|
553 | buf = va_arg (args, char *); |
|
|
554 | if (buf != 0) |
|
|
555 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
556 | break; |
|
|
557 | |
|
|
558 | case EVENT_CLOCK: |
|
|
559 | clean_obj_cache (); |
|
|
560 | break; |
|
|
561 | |
|
|
562 | case EVENT_TELL: |
|
|
563 | break; |
|
|
564 | |
|
|
565 | case EVENT_MAPRESET: |
|
|
566 | /* stupid, should be the map itself, not "message"??? */ |
|
|
567 | buf = va_arg (args, char *); |
|
|
568 | if (buf != 0) |
|
|
569 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
570 | break; |
|
|
571 | } |
|
|
572 | |
|
|
573 | va_end (args); |
|
|
574 | |
|
|
575 | if (context.event_code == EVENT_FREE_OB) |
|
|
576 | { |
|
|
577 | SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); |
496 | sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0); |
578 | |
497 | |
579 | if (sv) |
498 | if (sv) |
580 | clearSVptr (sv); |
499 | clearSVptr (sv); |
|
|
500 | |
|
|
501 | rv = 0; |
|
|
502 | } |
|
|
503 | else if (event_code == EVENT_CLOCK) |
|
|
504 | { |
|
|
505 | dSP; |
|
|
506 | int i, count; |
|
|
507 | |
|
|
508 | clean_obj_cache (); |
|
|
509 | |
|
|
510 | ENTER; |
|
|
511 | SAVETMPS; |
|
|
512 | |
|
|
513 | // service up to 8 events per tick better would be |
|
|
514 | // to check for elapsed time and stop processing after |
|
|
515 | // 0.25 * server_tick or so |
|
|
516 | for (i = 9; --i; ) |
|
|
517 | { |
|
|
518 | PUSHMARK (SP); |
|
|
519 | XPUSHs (sv_2mortal (newSViv (0))); |
|
|
520 | PUTBACK; |
|
|
521 | count = call_pv ("Event::one_event", G_SCALAR | G_EVAL); |
|
|
522 | SPAGAIN; |
|
|
523 | |
|
|
524 | if (!count || !POPi) |
|
|
525 | break; |
|
|
526 | } |
|
|
527 | |
|
|
528 | FREETMPS; |
|
|
529 | LEAVE; |
581 | } |
530 | } |
582 | else |
531 | else |
583 | inject_event ("cf::inject_global_event", &context); |
532 | { |
|
|
533 | dSP; |
|
|
534 | |
|
|
535 | ENTER; |
|
|
536 | SAVETMPS; |
|
|
537 | |
|
|
538 | PUSHMARK (SP); |
|
|
539 | |
|
|
540 | EXTEND (SP, 10); |
|
|
541 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
542 | |
|
|
543 | switch (event_code) |
|
|
544 | { |
|
|
545 | case EVENT_CRASH: |
|
|
546 | break; |
|
|
547 | |
|
|
548 | case EVENT_PLAYER_LOAD: |
|
|
549 | case EVENT_PLAYER_SAVE: |
|
|
550 | PUSH_OB; |
|
|
551 | PUSH_PV; |
|
|
552 | break; |
|
|
553 | |
|
|
554 | case EVENT_MAPLOAD: |
|
|
555 | case EVENT_MAPOUT: |
|
|
556 | case EVENT_MAPIN: |
|
|
557 | case EVENT_MAPCLEAN: |
|
|
558 | case EVENT_MAPRESET: |
|
|
559 | PUSH_MAP; |
|
|
560 | break; |
|
|
561 | |
|
|
562 | case EVENT_MAPENTER: |
|
|
563 | case EVENT_MAPLEAVE: |
|
|
564 | case EVENT_BORN: |
|
|
565 | case EVENT_REMOVE: |
|
|
566 | case EVENT_PLAYER_DEATH: |
|
|
567 | PUSH_OB; |
|
|
568 | break; |
|
|
569 | |
|
|
570 | case EVENT_GKILL: |
|
|
571 | PUSH_OB; |
|
|
572 | PUSH_OB; |
|
|
573 | break; |
|
|
574 | |
|
|
575 | case EVENT_LOGIN: |
|
|
576 | case EVENT_LOGOUT: |
|
|
577 | PUSH_PL; |
|
|
578 | PUSH_PV; |
|
|
579 | break; |
|
|
580 | |
|
|
581 | case EVENT_SHOUT: |
|
|
582 | case EVENT_MUZZLE: |
|
|
583 | case EVENT_KICK: |
|
|
584 | PUSH_OB; |
|
|
585 | PUSH_PV; |
|
|
586 | break; |
|
|
587 | |
|
|
588 | case EVENT_FIND_UNARMED_SKILL: |
|
|
589 | PUSH_OB; |
|
|
590 | break; |
|
|
591 | |
|
|
592 | case EVENT_PLAYER_USE_SKILL: |
|
|
593 | case EVENT_MONSTER_USE_SKILL: |
|
|
594 | case EVENT_CAST_SPELL: |
|
|
595 | PUSH_OB; |
|
|
596 | PUSH_OB; |
|
|
597 | PUSH_OB; |
|
|
598 | PUSH_IV; |
|
|
599 | PUSH_PV; |
|
|
600 | break; |
|
|
601 | |
|
|
602 | case EVENT_EXTCMD: |
|
|
603 | PUSH_PL; |
|
|
604 | { |
|
|
605 | char *buf = va_arg (args, char *); |
|
|
606 | int len = va_arg (args, int); |
|
|
607 | PUSHs (sv_2mortal (newSVpvn (buf, len))); |
|
|
608 | } |
|
|
609 | break; |
|
|
610 | |
|
|
611 | case EVENT_TELL: |
|
|
612 | break; |
|
|
613 | } |
|
|
614 | |
|
|
615 | va_end (args); |
|
|
616 | |
|
|
617 | PUTBACK; |
|
|
618 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
|
|
619 | SPAGAIN; |
|
|
620 | |
|
|
621 | if (SvTRUE (ERRSV)) |
|
|
622 | LOG (llevError, "global event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
623 | |
|
|
624 | rv = count > 0 ? POPi : 0; |
|
|
625 | |
|
|
626 | PUTBACK; |
|
|
627 | FREETMPS; |
|
|
628 | LEAVE; |
|
|
629 | } |
|
|
630 | |
|
|
631 | return &rv; |
|
|
632 | } |
|
|
633 | |
|
|
634 | extern "C" void * eventListener (int *type, ...) |
|
|
635 | { |
|
|
636 | static int rv; |
|
|
637 | va_list args; |
|
|
638 | int event_code; |
|
|
639 | object *who, *activator, *third, *event; |
|
|
640 | char *message, *extension, *options; |
|
|
641 | |
|
|
642 | if (!perl) |
|
|
643 | return NULL; |
|
|
644 | |
|
|
645 | va_start (args, type); |
|
|
646 | who = va_arg (args, object *); |
|
|
647 | event_code = va_arg (args, int); |
|
|
648 | activator = va_arg (args, object *); |
|
|
649 | third = va_arg (args, object *); |
|
|
650 | message = va_arg (args, char *); |
|
|
651 | va_arg (args, int); // fix yourself |
|
|
652 | extension = va_arg (args, char *); |
|
|
653 | options = va_arg (args, char *); |
|
|
654 | event = va_arg (args, object *); |
|
|
655 | va_end (args); |
|
|
656 | |
|
|
657 | { |
|
|
658 | dSP; |
|
|
659 | |
|
|
660 | ENTER; |
|
|
661 | SAVETMPS; |
|
|
662 | |
|
|
663 | PUSHMARK (SP); |
|
|
664 | EXTEND (SP, 10); |
|
|
665 | |
|
|
666 | PUSHcfapi (STRING, extension); |
|
|
667 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
668 | |
|
|
669 | PUSHcfapi (POBJECT, event); |
|
|
670 | PUSHcfapi (POBJECT, who); |
|
|
671 | |
|
|
672 | switch (event_code) |
|
|
673 | { |
|
|
674 | case EVENT_STOP: // $ob (e.g. arrow) |
|
|
675 | case EVENT_TIME: // $ob |
|
|
676 | case EVENT_TIMER: // $ob |
|
|
677 | break; |
|
|
678 | |
|
|
679 | case EVENT_APPLY: // $ob, $who |
|
|
680 | case EVENT_DROP: // $ob, $who |
|
|
681 | case EVENT_CLOSE: // $ob, $who |
|
|
682 | case EVENT_DEATH: // $ob[, $killer] |
|
|
683 | case EVENT_MOVE: // $ob, $enemy |
|
|
684 | case EVENT_THROW: // $ob, $thrower |
|
|
685 | PUSHcfapi (POBJECT, activator); |
|
|
686 | break; |
|
|
687 | |
|
|
688 | case EVENT_DROP_ON: // $ob, $who, $what |
|
|
689 | case EVENT_ATTACK: // $ob, $who, $victim (?? please god enlighten me) |
|
|
690 | PUSHcfapi (POBJECT, activator); |
|
|
691 | PUSHcfapi (POBJECT, third); |
|
|
692 | break; |
|
|
693 | |
|
|
694 | case EVENT_TRIGGER: // $ob, $originator, [$victim], [$msg] |
|
|
695 | PUSHcfapi (POBJECT, activator); |
|
|
696 | PUSHcfapi (POBJECT, third); |
|
|
697 | PUSHcfapi (POBJECT, message); |
|
|
698 | break; |
|
|
699 | |
|
|
700 | case EVENT_SAY: // $ob, $who, $msg |
|
|
701 | PUSHcfapi (POBJECT, activator); |
|
|
702 | PUSHcfapi (STRING, message); |
|
|
703 | break; |
|
|
704 | |
|
|
705 | default: |
|
|
706 | LOG (llevError, "perl plugin called for unsupported event type %d", event_code); |
|
|
707 | break; |
|
|
708 | } |
|
|
709 | |
|
|
710 | PUTBACK; |
|
|
711 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
|
|
712 | SPAGAIN; |
|
|
713 | |
|
|
714 | if (SvTRUE (ERRSV)) |
|
|
715 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
716 | |
|
|
717 | rv = count > 0 ? POPi : 0; |
|
|
718 | |
|
|
719 | PUTBACK; |
|
|
720 | FREETMPS; |
|
|
721 | LEAVE; |
|
|
722 | } |
584 | |
723 | |
585 | rv = context.returnvalue; |
|
|
586 | |
|
|
587 | return &rv; |
724 | return &rv; |
588 | } |
725 | } |
589 | |
726 | |
590 | void * |
727 | extern "C" int closePlugin () |
591 | eventListener (int *type, ...) |
|
|
592 | { |
|
|
593 | static int rv = 0; |
|
|
594 | va_list args; |
|
|
595 | char *buf; |
|
|
596 | CFPContext context; |
|
|
597 | |
|
|
598 | if (!perl) |
|
|
599 | return; |
|
|
600 | |
|
|
601 | memset (&context, 0, sizeof (context)); |
|
|
602 | |
|
|
603 | va_start (args, type); |
|
|
604 | |
|
|
605 | context.who = va_arg (args, object *); |
|
|
606 | context.event_code = va_arg (args, int); |
|
|
607 | context.activator = va_arg (args, object *); |
|
|
608 | context.third = va_arg (args, object *); |
|
|
609 | |
|
|
610 | buf = va_arg (args, char *); |
|
|
611 | if (buf != 0) |
|
|
612 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
613 | |
|
|
614 | context.fix = va_arg (args, int); |
|
|
615 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
|
|
616 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
|
|
617 | context.returnvalue = 0; |
|
|
618 | va_end (args); |
|
|
619 | |
|
|
620 | inject_event ("cf::inject_event", &context); |
|
|
621 | |
|
|
622 | rv = context.returnvalue; |
|
|
623 | return &rv; |
|
|
624 | } |
|
|
625 | |
|
|
626 | int |
|
|
627 | closePlugin () |
|
|
628 | { |
728 | { |
629 | printf (PLUGIN_VERSION " closing\n"); |
729 | printf (PLUGIN_VERSION " closing\n"); |
630 | |
730 | |
631 | if (perl) |
731 | if (perl) |
632 | { |
732 | { |
… | |
… | |
653 | const_iv (llevInfo) |
753 | const_iv (llevInfo) |
654 | const_iv (llevDebug) |
754 | const_iv (llevDebug) |
655 | const_iv (llevMonster) |
755 | const_iv (llevMonster) |
656 | |
756 | |
657 | const_iv (PLAYER) |
757 | const_iv (PLAYER) |
|
|
758 | const_iv (TRANSPORT) |
658 | const_iv (ROD) |
759 | const_iv (ROD) |
659 | const_iv (TREASURE) |
760 | const_iv (TREASURE) |
660 | const_iv (POTION) |
761 | const_iv (POTION) |
661 | const_iv (FOOD) |
762 | const_iv (FOOD) |
662 | const_iv (POISON) |
763 | const_iv (POISON) |
… | |
… | |
667 | const_iv (BOW) |
768 | const_iv (BOW) |
668 | const_iv (WEAPON) |
769 | const_iv (WEAPON) |
669 | const_iv (ARMOUR) |
770 | const_iv (ARMOUR) |
670 | const_iv (PEDESTAL) |
771 | const_iv (PEDESTAL) |
671 | const_iv (ALTAR) |
772 | const_iv (ALTAR) |
672 | const_iv (CONFUSION) |
|
|
673 | const_iv (LOCKED_DOOR) |
773 | const_iv (LOCKED_DOOR) |
674 | const_iv (SPECIAL_KEY) |
774 | const_iv (SPECIAL_KEY) |
675 | const_iv (MAP) |
775 | const_iv (MAP) |
676 | const_iv (DOOR) |
776 | const_iv (DOOR) |
677 | const_iv (KEY) |
777 | const_iv (KEY) |
… | |
… | |
778 | const_iv (ITEM_TRANSFORMER) |
878 | const_iv (ITEM_TRANSFORMER) |
779 | const_iv (QUEST) |
879 | const_iv (QUEST) |
780 | |
880 | |
781 | const_iv (ST_BD_BUILD) |
881 | const_iv (ST_BD_BUILD) |
782 | const_iv (ST_BD_REMOVE) |
882 | const_iv (ST_BD_REMOVE) |
|
|
883 | |
783 | const_iv (ST_MAT_FLOOR) |
884 | const_iv (ST_MAT_FLOOR) |
784 | const_iv (ST_MAT_WALL) |
885 | const_iv (ST_MAT_WALL) |
785 | const_iv (ST_MAT_ITEM) |
886 | const_iv (ST_MAT_ITEM) |
786 | |
887 | |
787 | const_iv (AT_PHYSICAL) |
888 | const_iv (AT_PHYSICAL) |
… | |
… | |
959 | const_iv (F_DAMNED) |
1060 | const_iv (F_DAMNED) |
960 | const_iv (F_OPEN) |
1061 | const_iv (F_OPEN) |
961 | const_iv (F_NOPICK) |
1062 | const_iv (F_NOPICK) |
962 | const_iv (F_LOCKED) |
1063 | const_iv (F_LOCKED) |
963 | |
1064 | |
|
|
1065 | const_iv (F_BUY) |
|
|
1066 | const_iv (F_SHOP) |
|
|
1067 | const_iv (F_SELL) |
|
|
1068 | |
964 | const_iv (P_BLOCKSVIEW) |
1069 | const_iv (P_BLOCKSVIEW) |
965 | const_iv (P_NO_MAGIC) |
1070 | const_iv (P_NO_MAGIC) |
966 | const_iv (P_IS_ALIVE) |
1071 | const_iv (P_IS_ALIVE) |
967 | const_iv (P_NO_CLERIC) |
1072 | const_iv (P_NO_CLERIC) |
968 | const_iv (P_NEED_UPDATE) |
1073 | const_iv (P_NEED_UPDATE) |
… | |
… | |
988 | const_iv (WILL_APPLY_DOOR) |
1093 | const_iv (WILL_APPLY_DOOR) |
989 | const_iv (WILL_APPLY_FOOD) |
1094 | const_iv (WILL_APPLY_FOOD) |
990 | |
1095 | |
991 | const_iv (SAVE_MODE) |
1096 | const_iv (SAVE_MODE) |
992 | const_iv (SAVE_DIR_MODE) |
1097 | const_iv (SAVE_DIR_MODE) |
|
|
1098 | |
|
|
1099 | const_iv (M_PAPER) |
|
|
1100 | const_iv (M_IRON) |
|
|
1101 | const_iv (M_GLASS) |
|
|
1102 | const_iv (M_LEATHER) |
|
|
1103 | const_iv (M_WOOD) |
|
|
1104 | const_iv (M_ORGANIC) |
|
|
1105 | const_iv (M_STONE) |
|
|
1106 | const_iv (M_CLOTH) |
|
|
1107 | const_iv (M_ADAMANT) |
|
|
1108 | const_iv (M_LIQUID) |
|
|
1109 | const_iv (M_SOFT_METAL) |
|
|
1110 | const_iv (M_BONE) |
|
|
1111 | const_iv (M_ICE) |
|
|
1112 | const_iv (M_SPECIAL) |
|
|
1113 | |
|
|
1114 | const_iv (SK_EXP_ADD_SKILL) |
|
|
1115 | const_iv (SK_EXP_TOTAL) |
|
|
1116 | const_iv (SK_EXP_NONE) |
|
|
1117 | const_iv (SK_SUBTRACT_SKILL_EXP) |
|
|
1118 | |
|
|
1119 | const_iv (SK_LOCKPICKING) |
|
|
1120 | const_iv (SK_HIDING) |
|
|
1121 | const_iv (SK_SMITHERY) |
|
|
1122 | const_iv (SK_BOWYER) |
|
|
1123 | const_iv (SK_JEWELER) |
|
|
1124 | const_iv (SK_ALCHEMY) |
|
|
1125 | const_iv (SK_STEALING) |
|
|
1126 | const_iv (SK_LITERACY) |
|
|
1127 | const_iv (SK_BARGAINING) |
|
|
1128 | const_iv (SK_JUMPING) |
|
|
1129 | const_iv (SK_DET_MAGIC) |
|
|
1130 | const_iv (SK_ORATORY) |
|
|
1131 | const_iv (SK_SINGING) |
|
|
1132 | const_iv (SK_DET_CURSE) |
|
|
1133 | const_iv (SK_FIND_TRAPS) |
|
|
1134 | const_iv (SK_MEDITATION) |
|
|
1135 | const_iv (SK_PUNCHING) |
|
|
1136 | const_iv (SK_FLAME_TOUCH) |
|
|
1137 | const_iv (SK_KARATE) |
|
|
1138 | const_iv (SK_CLIMBING) |
|
|
1139 | const_iv (SK_WOODSMAN) |
|
|
1140 | const_iv (SK_INSCRIPTION) |
|
|
1141 | const_iv (SK_ONE_HANDED_WEAPON) |
|
|
1142 | const_iv (SK_MISSILE_WEAPON) |
|
|
1143 | const_iv (SK_THROWING) |
|
|
1144 | const_iv (SK_USE_MAGIC_ITEM) |
|
|
1145 | const_iv (SK_DISARM_TRAPS) |
|
|
1146 | const_iv (SK_SET_TRAP) |
|
|
1147 | const_iv (SK_THAUMATURGY) |
|
|
1148 | const_iv (SK_PRAYING) |
|
|
1149 | const_iv (SK_CLAWING) |
|
|
1150 | const_iv (SK_LEVITATION) |
|
|
1151 | const_iv (SK_SUMMONING) |
|
|
1152 | const_iv (SK_PYROMANCY) |
|
|
1153 | const_iv (SK_EVOCATION) |
|
|
1154 | const_iv (SK_SORCERY) |
|
|
1155 | const_iv (SK_TWO_HANDED_WEAPON) |
|
|
1156 | const_iv (SK_SPARK_TOUCH) |
|
|
1157 | const_iv (SK_SHIVER) |
|
|
1158 | const_iv (SK_ACID_SPLASH) |
|
|
1159 | const_iv (SK_POISON_NAIL) |
|
|
1160 | |
|
|
1161 | const_iv (SOUND_NEW_PLAYER) |
|
|
1162 | const_iv (SOUND_FIRE_ARROW) |
|
|
1163 | const_iv (SOUND_LEARN_SPELL) |
|
|
1164 | const_iv (SOUND_FUMBLE_SPELL) |
|
|
1165 | const_iv (SOUND_WAND_POOF) |
|
|
1166 | const_iv (SOUND_OPEN_DOOR) |
|
|
1167 | const_iv (SOUND_PUSH_PLAYER) |
|
|
1168 | const_iv (SOUND_PLAYER_HITS1) |
|
|
1169 | const_iv (SOUND_PLAYER_HITS2) |
|
|
1170 | const_iv (SOUND_PLAYER_HITS3) |
|
|
1171 | const_iv (SOUND_PLAYER_HITS4) |
|
|
1172 | const_iv (SOUND_PLAYER_IS_HIT1) |
|
|
1173 | const_iv (SOUND_PLAYER_IS_HIT2) |
|
|
1174 | const_iv (SOUND_PLAYER_IS_HIT3) |
|
|
1175 | const_iv (SOUND_PLAYER_KILLS) |
|
|
1176 | const_iv (SOUND_PET_IS_KILLED) |
|
|
1177 | const_iv (SOUND_PLAYER_DIES) |
|
|
1178 | const_iv (SOUND_OB_EVAPORATE) |
|
|
1179 | const_iv (SOUND_OB_EXPLODE) |
|
|
1180 | const_iv (SOUND_CLOCK) |
|
|
1181 | const_iv (SOUND_TURN_HANDLE) |
|
|
1182 | const_iv (SOUND_FALL_HOLE) |
|
|
1183 | const_iv (SOUND_DRINK_POISON) |
|
|
1184 | const_iv (SOUND_CAST_SPELL_0) |
|
|
1185 | |
|
|
1186 | const_iv (PREFER_LOW) |
|
|
1187 | const_iv (PREFER_HIGH) |
|
|
1188 | |
|
|
1189 | const_iv (ATNR_PHYSICAL) |
|
|
1190 | const_iv (ATNR_MAGIC) |
|
|
1191 | const_iv (ATNR_FIRE) |
|
|
1192 | const_iv (ATNR_ELECTRICITY) |
|
|
1193 | const_iv (ATNR_COLD) |
|
|
1194 | const_iv (ATNR_CONFUSION) |
|
|
1195 | const_iv (ATNR_ACID) |
|
|
1196 | const_iv (ATNR_DRAIN) |
|
|
1197 | const_iv (ATNR_WEAPONMAGIC) |
|
|
1198 | const_iv (ATNR_GHOSTHIT) |
|
|
1199 | const_iv (ATNR_POISON) |
|
|
1200 | const_iv (ATNR_SLOW) |
|
|
1201 | const_iv (ATNR_PARALYZE) |
|
|
1202 | const_iv (ATNR_TURN_UNDEAD) |
|
|
1203 | const_iv (ATNR_FEAR) |
|
|
1204 | const_iv (ATNR_CANCELLATION) |
|
|
1205 | const_iv (ATNR_DEPLETE) |
|
|
1206 | const_iv (ATNR_DEATH) |
|
|
1207 | const_iv (ATNR_CHAOS) |
|
|
1208 | const_iv (ATNR_COUNTERSPELL) |
|
|
1209 | const_iv (ATNR_GODPOWER) |
|
|
1210 | const_iv (ATNR_HOLYWORD) |
|
|
1211 | const_iv (ATNR_BLIND) |
|
|
1212 | const_iv (ATNR_INTERNAL) |
|
|
1213 | const_iv (ATNR_LIFE_STEALING) |
|
|
1214 | const_iv (ATNR_DISEASE) |
|
|
1215 | |
|
|
1216 | const_iv (MAP_FLUSH) |
|
|
1217 | const_iv (MAP_PLAYER_UNIQUE) |
|
|
1218 | const_iv (MAP_BLOCK) |
|
|
1219 | const_iv (MAP_STYLE) |
|
|
1220 | const_iv (MAP_OVERLAY) |
|
|
1221 | |
|
|
1222 | const_iv (MAP_IN_MEMORY) |
|
|
1223 | const_iv (MAP_SWAPPED) |
|
|
1224 | const_iv (MAP_LOADING) |
|
|
1225 | const_iv (MAP_SAVING) |
993 | }; |
1226 | }; |
994 | |
1227 | |
995 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1228 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
996 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1229 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
997 | |
1230 | |
… | |
… | |
1003 | const_event (NONE) |
1236 | const_event (NONE) |
1004 | const_event (APPLY) |
1237 | const_event (APPLY) |
1005 | const_event (ATTACK) |
1238 | const_event (ATTACK) |
1006 | const_event (DEATH) |
1239 | const_event (DEATH) |
1007 | const_event (DROP) |
1240 | const_event (DROP) |
|
|
1241 | const_event (DROP_ON) |
1008 | const_event (PICKUP) |
1242 | const_event (PICKUP) |
1009 | const_event (SAY) |
1243 | const_event (SAY) |
1010 | const_event (STOP) |
1244 | const_event (STOP) |
1011 | const_event (TIME) |
1245 | const_event (TIME) |
1012 | const_event (THROW) |
1246 | const_event (THROW) |
… | |
… | |
1014 | const_event (CLOSE) |
1248 | const_event (CLOSE) |
1015 | const_event (TIMER) |
1249 | const_event (TIMER) |
1016 | const_event (MOVE) |
1250 | const_event (MOVE) |
1017 | |
1251 | |
1018 | const_event (BORN) |
1252 | const_event (BORN) |
1019 | const_event (CLOCK) |
1253 | //const_event (CLOCK) |
1020 | const_event (CRASH) |
1254 | const_event (CRASH) |
1021 | const_event (PLAYER_DEATH) |
1255 | const_event (PLAYER_DEATH) |
|
|
1256 | const_event (PLAYER_LOAD) |
|
|
1257 | const_event (PLAYER_SAVE) |
1022 | const_event (GKILL) |
1258 | const_event (GKILL) |
1023 | const_event (LOGIN) |
1259 | const_event (LOGIN) |
1024 | const_event (LOGOUT) |
1260 | const_event (LOGOUT) |
1025 | const_event (MAPENTER) |
1261 | const_event (MAPENTER) |
1026 | const_event (MAPLEAVE) |
1262 | const_event (MAPLEAVE) |
1027 | const_event (MAPRESET) |
1263 | const_event (MAPRESET) |
1028 | const_event (MAPLOAD) |
1264 | const_event (MAPLOAD) |
1029 | const_event (MAPOUT) |
1265 | const_event (MAPOUT) |
1030 | const_event (MAPIN) |
1266 | const_event (MAPIN) |
|
|
1267 | const_event (MAPCLEAN) |
1031 | const_event (REMOVE) |
1268 | const_event (REMOVE) |
1032 | const_event (SHOUT) |
1269 | const_event (SHOUT) |
1033 | const_event (TELL) |
1270 | const_event (TELL) |
1034 | const_event (MUZZLE) |
1271 | const_event (MUZZLE) |
1035 | const_event (KICK) |
1272 | const_event (KICK) |
|
|
1273 | const_event (PLAYER_USE_SKILL) |
|
|
1274 | const_event (MONSTER_USE_SKILL) |
|
|
1275 | const_event (CAST_SPELL) |
|
|
1276 | const_event (FIND_UNARMED_SKILL) |
|
|
1277 | const_event (EXTCMD) |
1036 | //const_event (FREE_OB) |
1278 | //const_event (FREE_OB) |
1037 | }; |
1279 | }; |
1038 | |
1280 | |
1039 | AV *av = get_av ("cf::EVENT", 1); |
1281 | AV *av = get_av ("cf::EVENT", 1); |
1040 | |
1282 | |
… | |
… | |
1138 | prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED) |
1380 | prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED) |
1139 | prop (CFAPI_INT, OBJECT_PROP_FRIENDLY) |
1381 | prop (CFAPI_INT, OBJECT_PROP_FRIENDLY) |
1140 | prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) |
1382 | prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) |
1141 | prop (CFAPI_INT, OBJECT_PROP_MAGICAL) |
1383 | prop (CFAPI_INT, OBJECT_PROP_MAGICAL) |
1142 | prop (CFAPI_INT, OBJECT_PROP_LUCK) |
1384 | prop (CFAPI_INT, OBJECT_PROP_LUCK) |
1143 | prop (CFAPI_LONG, OBJECT_PROP_EXP) |
|
|
1144 | prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) |
1385 | prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) |
1145 | prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) |
1386 | prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) |
1146 | prop (CFAPI_INT, OBJECT_PROP_CHEATER) |
1387 | prop (CFAPI_INT, OBJECT_PROP_CHEATER) |
1147 | prop (CFAPI_INT, OBJECT_PROP_MERGEABLE) |
1388 | prop (CFAPI_INT, OBJECT_PROP_MERGEABLE) |
1148 | prop (CFAPI_INT, OBJECT_PROP_PICKABLE) |
1389 | prop (CFAPI_INT, OBJECT_PROP_PICKABLE) |
… | |
… | |
1175 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1416 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
1176 | { |
1417 | { |
1177 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1418 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1178 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1419 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1179 | } |
1420 | } |
|
|
1421 | |
|
|
1422 | //I_EVENT_API (PACKAGE); |
1180 | } |
1423 | } |
|
|
1424 | |
|
|
1425 | NV floor (NV x) |
|
|
1426 | |
|
|
1427 | NV ceil (NV x) |
1181 | |
1428 | |
1182 | void |
1429 | void |
1183 | LOG (int level, char *msg) |
1430 | LOG (int level, char *msg) |
1184 | PROTOTYPE: $$ |
1431 | PROTOTYPE: $$ |
1185 | C_ARGS: level, "%s", msg |
1432 | C_ARGS: (LogLevel)level, "%s", msg |
|
|
1433 | |
|
|
1434 | char *path_combine (char *base, char *path) |
|
|
1435 | PROTOTYPE: $$ |
|
|
1436 | |
|
|
1437 | char *path_combine_and_normalize (char *base, char *path) |
|
|
1438 | PROTOTYPE: $$ |
1186 | |
1439 | |
1187 | char * |
1440 | char * |
1188 | cf_get_maps_directory (char *path) |
1441 | cf_get_maps_directory (char *path) |
1189 | PROTOTYPE: $ |
1442 | PROTOTYPE: $ |
1190 | ALIAS: maps_directory = 0 |
1443 | ALIAS: maps_directory = 0 |
|
|
1444 | |
|
|
1445 | void |
|
|
1446 | sub_generation_inc () |
|
|
1447 | CODE: |
|
|
1448 | PL_sub_generation++; |
1191 | |
1449 | |
1192 | char * |
1450 | char * |
1193 | mapdir () |
1451 | mapdir () |
1194 | PROTOTYPE: |
1452 | PROTOTYPE: |
1195 | ALIAS: |
1453 | ALIAS: |
… | |
… | |
1209 | |
1467 | |
1210 | int |
1468 | int |
1211 | cf_find_animation (char *text) |
1469 | cf_find_animation (char *text) |
1212 | PROTOTYPE: $ |
1470 | PROTOTYPE: $ |
1213 | |
1471 | |
|
|
1472 | int random_roll(int min, int max, object *op, int goodbad); |
|
|
1473 | |
|
|
1474 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
|
|
1475 | |
|
|
1476 | int |
|
|
1477 | exp_to_level (val64 exp) |
|
|
1478 | CODE: |
|
|
1479 | { |
|
|
1480 | int i = 0; |
|
|
1481 | |
|
|
1482 | RETVAL = settings.max_level; |
|
|
1483 | |
|
|
1484 | for (i = 1; i <= settings.max_level; i++) |
|
|
1485 | { |
|
|
1486 | if (levels[i] > exp) |
|
|
1487 | { |
|
|
1488 | RETVAL = i - 1; |
|
|
1489 | break; |
|
|
1490 | } |
|
|
1491 | } |
|
|
1492 | } |
|
|
1493 | OUTPUT: RETVAL |
|
|
1494 | |
|
|
1495 | val64 |
|
|
1496 | level_to_min_exp (int level) |
|
|
1497 | CODE: |
|
|
1498 | if (level > settings.max_level) |
|
|
1499 | RETVAL = levels[settings.max_level]; |
|
|
1500 | else if (level < 1) |
|
|
1501 | RETVAL = 0; |
|
|
1502 | else |
|
|
1503 | RETVAL = levels[level]; |
|
|
1504 | OUTPUT: RETVAL |
|
|
1505 | |
|
|
1506 | SV * |
|
|
1507 | resistance_to_string (int atnr) |
|
|
1508 | CODE: |
|
|
1509 | if (atnr >= 0 && atnr < NROFATTACKS) |
|
|
1510 | RETVAL = newSVpv (resist_plus[atnr], 0); |
|
|
1511 | else |
|
|
1512 | XSRETURN_UNDEF; |
|
|
1513 | OUTPUT: RETVAL |
|
|
1514 | |
1214 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1515 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1215 | |
1516 | |
1216 | SV * |
1517 | SV * |
1217 | get_property (object *obj, int type, int idx) |
1518 | get_property (object *obj, int type, int idx) |
1218 | CODE: |
1519 | CODE: |
… | |
… | |
1226 | { |
1527 | { |
1227 | case CFAPI_INT: |
1528 | case CFAPI_INT: |
1228 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1529 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
1229 | break; |
1530 | break; |
1230 | case CFAPI_LONG: |
1531 | case CFAPI_LONG: |
1231 | cf_object_set_long_property (obj, idx, SvNV (newval)); |
1532 | cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval)); |
1232 | break; |
1533 | break; |
1233 | case CFAPI_DOUBLE: |
1534 | case CFAPI_DOUBLE: |
1234 | { |
1535 | { |
1235 | int unused_type; |
1536 | int unused_type; |
1236 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
1537 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
… | |
… | |
1262 | attacktype = 0 |
1563 | attacktype = 0 |
1263 | CODE: |
1564 | CODE: |
1264 | RETVAL = obj->attacktype; |
1565 | RETVAL = obj->attacktype; |
1265 | OUTPUT: RETVAL |
1566 | OUTPUT: RETVAL |
1266 | |
1567 | |
|
|
1568 | # missing in plug-in api, of course |
1267 | void |
1569 | void |
1268 | set_food (object *obj, int food) |
1570 | set_food (object *obj, int food) |
1269 | CODE: |
1571 | CODE: |
1270 | obj->stats.food = food; |
1572 | obj->stats.food = food; |
1271 | |
1573 | |
… | |
… | |
1293 | int cf_object_get_flag (object *op, int flag) |
1595 | int cf_object_get_flag (object *op, int flag) |
1294 | ALIAS: flag = 0 |
1596 | ALIAS: flag = 0 |
1295 | |
1597 | |
1296 | void cf_object_set_flag (object *op, int flag, int value) |
1598 | void cf_object_set_flag (object *op, int flag, int value) |
1297 | |
1599 | |
|
|
1600 | int need_identify (const object *obj); |
|
|
1601 | |
|
|
1602 | int apply_shop_mat (object *shop_mat, object *op); |
|
|
1603 | |
1298 | void cf_object_move (object *op, int dir, object *originator = op) |
1604 | void cf_object_move (object *op, int dir, object *originator = op) |
1299 | |
1605 | |
1300 | void cf_object_apply (object *op, object *author, int flags = 0) |
1606 | void cf_object_apply (object *op, object *author, int flags = 0) |
1301 | |
1607 | |
1302 | void cf_object_apply_below (object *op) |
1608 | void cf_object_apply_below (object *op) |
… | |
… | |
1305 | |
1611 | |
1306 | void cf_object_free (object *op) |
1612 | void cf_object_free (object *op) |
1307 | |
1613 | |
1308 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1614 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1309 | |
1615 | |
1310 | int cf_object_transfer (object *op, int x, int y, int r, object *orig) |
1616 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1311 | |
1617 | |
1312 | int cf_object_change_map (object *op, int x, int y, mapstruct *map) |
1618 | int cf_object_change_map (object *op, int x, int y, mapstruct *map) |
1313 | |
1619 | |
1314 | object *cf_object_clone (object *op, int clonetype = 0) |
1620 | object *cf_object_clone (object *op, int clonetype = 0) |
1315 | |
1621 | |
1316 | int cf_object_pay_item (object *op, object *buyer) |
1622 | int cf_object_pay_item (object *op, object *buyer) |
1317 | |
1623 | |
1318 | int cf_object_pay_amount (object *op, double amount) |
1624 | int cf_object_pay_amount (object *op, uint64 amount) |
|
|
1625 | |
|
|
1626 | void pay_player (object *op, uint64 amount) |
|
|
1627 | |
|
|
1628 | val64 pay_player_arch (object *op, const char *arch, uint64 amount) |
1319 | |
1629 | |
1320 | int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) |
1630 | int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) |
1321 | |
1631 | |
1322 | int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) |
1632 | int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) |
1323 | |
1633 | |
… | |
… | |
1358 | |
1668 | |
1359 | void cf_object_update (object *op, int flags) |
1669 | void cf_object_update (object *op, int flags) |
1360 | |
1670 | |
1361 | void cf_object_pickup (object *op, object *what) |
1671 | void cf_object_pickup (object *op, object *what) |
1362 | |
1672 | |
1363 | char *cf_object_get_key (object *op, char *keyname) |
|
|
1364 | ALIAS: key = 0 |
|
|
1365 | |
|
|
1366 | void cf_object_set_key (object *op, char *keyname, char *value) |
|
|
1367 | |
|
|
1368 | object *cf_create_object_by_name (const char *name) |
1673 | object *cf_create_object_by_name (const char *name) |
|
|
1674 | |
|
|
1675 | void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) |
|
|
1676 | |
|
|
1677 | void player_lvl_adj (object *who, object *skill = 0) |
|
|
1678 | |
|
|
1679 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
|
|
1680 | |
|
|
1681 | int calc_skill_exp (object *who, object *op, object *skill); |
|
|
1682 | |
|
|
1683 | void push_button (object *op); |
|
|
1684 | |
|
|
1685 | void use_trigger (object *op); |
|
|
1686 | |
|
|
1687 | void add_button_link (object *button, mapstruct *map, int connected); |
|
|
1688 | |
|
|
1689 | void remove_button_link (object *op); |
|
|
1690 | |
|
|
1691 | void |
|
|
1692 | cf_object_set_resistance (object *op, int rtype, int val) |
|
|
1693 | CODE: |
|
|
1694 | if (rtype >= 0 && rtype < NROFATTACKS) |
|
|
1695 | op->resist[rtype] = val; |
|
|
1696 | |
1369 | |
1697 | |
1370 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1698 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1371 | |
1699 | |
1372 | void cf_fix_object (object *pl) |
1700 | void cf_fix_object (object *pl) |
1373 | ALIAS: fix = 0 |
1701 | ALIAS: fix = 0 |
… | |
… | |
1389 | CODE: |
1717 | CODE: |
1390 | { |
1718 | { |
1391 | int unused_type; |
1719 | int unused_type; |
1392 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1720 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1393 | } |
1721 | } |
|
|
1722 | |
|
|
1723 | # syntatic sugar for easier use in event callbacks. |
|
|
1724 | const char *options (object *op) |
|
|
1725 | CODE: |
|
|
1726 | RETVAL = op->name; |
|
|
1727 | OUTPUT: |
|
|
1728 | RETVAL |
|
|
1729 | |
|
|
1730 | player *contr (object *op) |
|
|
1731 | CODE: |
|
|
1732 | RETVAL = op->contr; |
|
|
1733 | OUTPUT: RETVAL |
|
|
1734 | |
|
|
1735 | const char *get_ob_key_value (object *op, const char *key) |
|
|
1736 | |
|
|
1737 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1394 | |
1738 | |
1395 | object *get_nearest_player (object *ob) |
1739 | object *get_nearest_player (object *ob) |
1396 | ALIAS: nearest_player = 0 |
1740 | ALIAS: nearest_player = 0 |
1397 | PREINIT: |
1741 | PREINIT: |
1398 | extern object *get_nearest_player (object *); |
1742 | extern object *get_nearest_player (object *); |
… | |
… | |
1420 | base_name (object *ob, int plural) |
1764 | base_name (object *ob, int plural) |
1421 | CODE: |
1765 | CODE: |
1422 | RETVAL = cf_query_base_name (ob, plural); |
1766 | RETVAL = cf_query_base_name (ob, plural); |
1423 | OUTPUT: RETVAL |
1767 | OUTPUT: RETVAL |
1424 | |
1768 | |
|
|
1769 | living * |
|
|
1770 | stats (object *ob) |
|
|
1771 | CODE: |
|
|
1772 | RETVAL = &ob->stats; |
|
|
1773 | OUTPUT: RETVAL |
|
|
1774 | |
1425 | |
1775 | |
1426 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1776 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1427 | |
1777 | |
1428 | player *player (object *op) |
1778 | player *player (object *op) |
1429 | CODE: |
1779 | CODE: |
1430 | RETVAL = cf_player_find (cf_query_name (op)); |
1780 | RETVAL = op->contr; |
1431 | OUTPUT: RETVAL |
1781 | OUTPUT: RETVAL |
1432 | |
1782 | |
1433 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1783 | void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1434 | |
1784 | |
1435 | object *cf_player_send_inventory (object *op) |
1785 | object *cf_player_send_inventory (object *op) |
1436 | |
|
|
1437 | player *contr (object *op) |
|
|
1438 | CODE: |
|
|
1439 | RETVAL = op->contr; |
|
|
1440 | OUTPUT: RETVAL |
|
|
1441 | |
1786 | |
1442 | char *cf_player_get_ip (object *op) |
1787 | char *cf_player_get_ip (object *op) |
1443 | ALIAS: ip = 0 |
1788 | ALIAS: ip = 0 |
1444 | |
1789 | |
1445 | object *cf_player_get_marked_item (object *op) |
1790 | object *cf_player_get_marked_item (object *op) |
… | |
… | |
1450 | partylist *cf_player_get_party (object *op) |
1795 | partylist *cf_player_get_party (object *op) |
1451 | ALIAS: party = 0 |
1796 | ALIAS: party = 0 |
1452 | |
1797 | |
1453 | void cf_player_set_party (object *op, partylist *party) |
1798 | void cf_player_set_party (object *op, partylist *party) |
1454 | |
1799 | |
|
|
1800 | void kill_player (object *op) |
1455 | |
1801 | |
1456 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1802 | MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ |
1457 | |
1803 | |
1458 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1804 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1459 | |
1805 | |
… | |
… | |
1462 | |
1808 | |
1463 | void cf_player_move (player *pl, int dir) |
1809 | void cf_player_move (player *pl, int dir) |
1464 | |
1810 | |
1465 | void MapNewmapCmd (player *pl) |
1811 | void MapNewmapCmd (player *pl) |
1466 | |
1812 | |
|
|
1813 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
|
|
1814 | |
1467 | # nonstandard |
1815 | # nonstandard |
1468 | object *ob (player *pl) |
1816 | object *ob (player *pl) |
1469 | CODE: |
1817 | CODE: |
1470 | RETVAL = pl->ob; |
1818 | RETVAL = pl->ob; |
1471 | OUTPUT: RETVAL |
1819 | OUTPUT: RETVAL |
… | |
… | |
1477 | |
1825 | |
1478 | player *next (player *pl) |
1826 | player *next (player *pl) |
1479 | CODE: |
1827 | CODE: |
1480 | RETVAL = pl->next; |
1828 | RETVAL = pl->next; |
1481 | OUTPUT: RETVAL |
1829 | OUTPUT: RETVAL |
|
|
1830 | |
|
|
1831 | bool |
|
|
1832 | cell_visible (player *pl, int dx, int dy) |
|
|
1833 | CODE: |
|
|
1834 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
|
|
1835 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
|
|
1836 | OUTPUT: |
|
|
1837 | RETVAL |
|
|
1838 | |
|
|
1839 | void |
|
|
1840 | send (player *pl, SV *packet) |
|
|
1841 | CODE: |
|
|
1842 | { |
|
|
1843 | STRLEN len; |
|
|
1844 | char *buf = SvPVbyte (packet, len); |
|
|
1845 | |
|
|
1846 | Write_String_To_Socket (&pl->socket, buf, len); |
|
|
1847 | } |
|
|
1848 | |
|
|
1849 | int |
|
|
1850 | listening (player *pl, int new_value = -1) |
|
|
1851 | CODE: |
|
|
1852 | RETVAL = pl->listening; |
|
|
1853 | if (new_value >= 0) |
|
|
1854 | pl->listening = new_value; |
|
|
1855 | OUTPUT: |
|
|
1856 | RETVAL |
|
|
1857 | |
|
|
1858 | void get_savebed (player *pl) |
|
|
1859 | ALIAS: |
|
|
1860 | savebed = 0 |
|
|
1861 | PPCODE: |
|
|
1862 | EXTEND (SP, 3); |
|
|
1863 | PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
|
|
1864 | PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
|
|
1865 | PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
|
|
1866 | |
|
|
1867 | void set_savebed (player *pl, char *map_path, int x, int y) |
|
|
1868 | CODE: |
|
|
1869 | strcpy (pl->savebed_map, map_path); |
|
|
1870 | pl->bed_x = x; |
|
|
1871 | pl->bed_y = y; |
1482 | |
1872 | |
1483 | void |
1873 | void |
1484 | list () |
1874 | list () |
1485 | PPCODE: |
1875 | PPCODE: |
1486 | { |
1876 | { |
1487 | player *pl; |
1877 | player *pl; |
1488 | for (pl = first_player; pl; pl = pl->next) |
1878 | for (pl = first_player; pl; pl = pl->next) |
1489 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
1879 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
1490 | } |
1880 | } |
|
|
1881 | |
|
|
1882 | bool |
|
|
1883 | peaceful (player *pl, bool new_setting = 0) |
|
|
1884 | PROTOTYPE: $;$ |
|
|
1885 | CODE: |
|
|
1886 | RETVAL = pl->peaceful; |
|
|
1887 | if (items > 1) |
|
|
1888 | pl->peaceful = new_setting; |
|
|
1889 | OUTPUT: |
|
|
1890 | RETVAL |
|
|
1891 | |
|
|
1892 | living * |
|
|
1893 | orig_stats (player *pl) |
|
|
1894 | CODE: |
|
|
1895 | RETVAL = &pl->orig_stats; |
|
|
1896 | OUTPUT: RETVAL |
|
|
1897 | |
|
|
1898 | living * |
|
|
1899 | last_stats (player *pl) |
|
|
1900 | CODE: |
|
|
1901 | RETVAL = &pl->last_stats; |
|
|
1902 | OUTPUT: RETVAL |
1491 | |
1903 | |
1492 | |
1904 | |
1493 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1905 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1494 | |
1906 | |
1495 | SV * |
1907 | SV * |
… | |
… | |
1513 | mapstruct *new (int width, int height) |
1925 | mapstruct *new (int width, int height) |
1514 | PROTOTYPE: |
1926 | PROTOTYPE: |
1515 | CODE: |
1927 | CODE: |
1516 | { |
1928 | { |
1517 | int unused_type; |
1929 | int unused_type; |
1518 | RETVAL = map_get_map (&unused_type, 0, width, height); |
1930 | RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); |
1519 | } |
1931 | } |
|
|
1932 | OUTPUT: |
|
|
1933 | RETVAL |
|
|
1934 | |
|
|
1935 | void delete_map (mapstruct *map) |
|
|
1936 | |
|
|
1937 | void clean_tmp_map (mapstruct *map) |
|
|
1938 | |
|
|
1939 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
|
|
1940 | |
|
|
1941 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
|
|
1942 | CODE: |
|
|
1943 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
|
|
1944 | OUTPUT: |
|
|
1945 | RETVAL |
|
|
1946 | |
|
|
1947 | char *tile_path (mapstruct *map, unsigned int dir) |
|
|
1948 | CODE: |
|
|
1949 | if (dir >= 4) |
|
|
1950 | XSRETURN_UNDEF; |
|
|
1951 | RETVAL = map->tile_path [dir]; |
1520 | OUTPUT: |
1952 | OUTPUT: |
1521 | RETVAL |
1953 | RETVAL |
1522 | |
1954 | |
1523 | mapstruct *cf_map_get_map (char *name) |
1955 | mapstruct *cf_map_get_map (char *name) |
1524 | PROTOTYPE: $ |
1956 | PROTOTYPE: $ |
1525 | ALIAS: map = 0 |
1957 | ALIAS: map = 0 |
1526 | |
1958 | |
|
|
1959 | mapstruct *has_been_loaded (char *name) |
|
|
1960 | PROTOTYPE: $ |
|
|
1961 | |
1527 | mapstruct *cf_map_get_first () |
1962 | mapstruct *cf_map_get_first () |
1528 | PROTOTYPE: |
1963 | PROTOTYPE: |
1529 | ALIAS: first = 0 |
1964 | ALIAS: first = 0 |
1530 | |
1965 | |
|
|
1966 | # whoever "designed" the plug-in api should have wasted |
|
|
1967 | # his/her time with staying away from the project - would have |
|
|
1968 | # saved others a lot of time, without doubt. |
|
|
1969 | void set_path (mapstruct *where, char *path) |
|
|
1970 | CODE: |
|
|
1971 | strcpy (where->path, path); |
|
|
1972 | |
|
|
1973 | int in_memory (mapstruct *map) |
|
|
1974 | CODE: |
|
|
1975 | RETVAL = map->in_memory; |
|
|
1976 | OUTPUT: |
|
|
1977 | RETVAL |
|
|
1978 | |
|
|
1979 | bool unique (mapstruct *map) |
|
|
1980 | CODE: |
|
|
1981 | RETVAL = map->unique; |
|
|
1982 | OUTPUT: |
|
|
1983 | RETVAL |
|
|
1984 | |
|
|
1985 | void set_unique (mapstruct *map, bool unique) |
|
|
1986 | CODE: |
|
|
1987 | map->unique = unique; |
|
|
1988 | |
1531 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
1989 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
1532 | |
1990 | |
1533 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1991 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
1534 | |
1992 | |
1535 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1993 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
1536 | C_ARGS: str, map, nx, ny |
1994 | C_ARGS: str, map, nx, ny |
1537 | |
1995 | |
1538 | #int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) |
|
|
1539 | |
|
|
1540 | void |
1996 | void |
|
|
1997 | cf_map_normalise (mapstruct *map, int x, int y) |
|
|
1998 | PPCODE: |
|
|
1999 | { |
|
|
2000 | mapstruct *nmap = 0; |
|
|
2001 | I16 nx = 0, ny = 0; |
|
|
2002 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2003 | |
|
|
2004 | EXTEND (SP, 4); |
|
|
2005 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
2006 | |
|
|
2007 | if (GIMME_V == G_ARRAY) |
|
|
2008 | { |
|
|
2009 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); |
|
|
2010 | PUSHs (sv_2mortal (newSViv (nx))); |
|
|
2011 | PUSHs (sv_2mortal (newSViv (ny))); |
|
|
2012 | } |
|
|
2013 | } |
|
|
2014 | |
|
|
2015 | void |
1541 | at (mapstruct *obj, unsigned int x, unsigned int y) |
2016 | at (mapstruct *map, unsigned int x, unsigned int y) |
1542 | PROTOTYPE: $$$ |
2017 | PROTOTYPE: $$$ |
1543 | INIT: |
|
|
1544 | if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY; |
|
|
1545 | PPCODE: |
2018 | PPCODE: |
1546 | { |
2019 | { |
1547 | object *o; |
2020 | object *o; |
1548 | |
2021 | mapstruct *nmap = 0; |
|
|
2022 | I16 nx, ny; |
|
|
2023 | |
|
|
2024 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2025 | |
|
|
2026 | if (nmap) |
1549 | for (o = GET_MAP_OB (obj, x, y); o; o = o->above) |
2027 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
1550 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2028 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1551 | } |
2029 | } |
1552 | |
2030 | |
1553 | SV * |
2031 | SV * |
1554 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
2032 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
1555 | PROTOTYPE: $$$ |
2033 | PROTOTYPE: $$$ |
… | |
… | |
1648 | } |
2126 | } |
1649 | } |
2127 | } |
1650 | } |
2128 | } |
1651 | } |
2129 | } |
1652 | |
2130 | |
|
|
2131 | |
1653 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
2132 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
1654 | |
2133 | |
1655 | archetype *cf_archetype_get_first() |
2134 | archetype *cf_archetype_get_first() |
1656 | PROTOTYPE: |
2135 | PROTOTYPE: |
1657 | ALIAS: first = 0 |
2136 | ALIAS: first = 0 |
… | |
… | |
1666 | ALIAS: more = 0 |
2145 | ALIAS: more = 0 |
1667 | |
2146 | |
1668 | const char *cf_archetype_get_name (archetype *arch) |
2147 | const char *cf_archetype_get_name (archetype *arch) |
1669 | ALIAS: name = 0 |
2148 | ALIAS: name = 0 |
1670 | |
2149 | |
|
|
2150 | object *cf_archetype_get_clone (archetype *arch) |
|
|
2151 | ALIAS: clone = 0 |
|
|
2152 | |
1671 | MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ |
2153 | MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ |
1672 | |
2154 | |
1673 | partylist *cf_party_get_first () |
2155 | partylist *cf_party_get_first () |
1674 | PROTOTYPE: |
2156 | PROTOTYPE: |
1675 | ALIAS: first = 0 |
2157 | ALIAS: first = 0 |
… | |
… | |
1709 | |
2191 | |
1710 | const char *cf_region_get_message (region *reg) |
2192 | const char *cf_region_get_message (region *reg) |
1711 | ALIAS: message = 0 |
2193 | ALIAS: message = 0 |
1712 | |
2194 | |
1713 | |
2195 | |
|
|
2196 | MODULE = cf PACKAGE = cf::living PREFIX = cf_living_ |
|
|
2197 | |
|
|
2198 | val64 |
|
|
2199 | exp (living *liv, val64 new_val = 0) |
|
|
2200 | PROTOTYPE: $;$ |
|
|
2201 | ALIAS: |
|
|
2202 | Str = 1 |
|
|
2203 | Dex = 2 |
|
|
2204 | Con = 3 |
|
|
2205 | Wis = 4 |
|
|
2206 | Cha = 5 |
|
|
2207 | Int = 6 |
|
|
2208 | Pow = 7 |
|
|
2209 | wc = 8 |
|
|
2210 | ac = 9 |
|
|
2211 | hp = 10 |
|
|
2212 | maxhp = 11 |
|
|
2213 | sp = 12 |
|
|
2214 | maxsp = 13 |
|
|
2215 | grace = 14 |
|
|
2216 | maxgrace = 15 |
|
|
2217 | food = 16 |
|
|
2218 | dam = 17 |
|
|
2219 | luck = 18 |
|
|
2220 | CODE: |
|
|
2221 | # define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break |
|
|
2222 | switch (ix) |
|
|
2223 | { |
|
|
2224 | LIVING_ACC (exp , 0); |
|
|
2225 | LIVING_ACC (Str , 1); |
|
|
2226 | LIVING_ACC (Dex , 2); |
|
|
2227 | LIVING_ACC (Con , 3); |
|
|
2228 | LIVING_ACC (Wis , 4); |
|
|
2229 | LIVING_ACC (Cha , 5); |
|
|
2230 | LIVING_ACC (Int , 6); |
|
|
2231 | LIVING_ACC (Pow , 7); |
|
|
2232 | LIVING_ACC (wc , 8); |
|
|
2233 | LIVING_ACC (ac , 9); |
|
|
2234 | LIVING_ACC (hp , 10); |
|
|
2235 | LIVING_ACC (maxhp , 11); |
|
|
2236 | LIVING_ACC (sp , 12); |
|
|
2237 | LIVING_ACC (maxsp , 13); |
|
|
2238 | LIVING_ACC (grace , 14); |
|
|
2239 | LIVING_ACC (maxgrace, 15); |
|
|
2240 | LIVING_ACC (food , 16); |
|
|
2241 | LIVING_ACC (dam , 17); |
|
|
2242 | LIVING_ACC (luck , 18); |
|
|
2243 | } |
|
|
2244 | # undef LIVING_ACC |
|
|
2245 | OUTPUT: |
|
|
2246 | RETVAL |
|
|
2247 | |