… | |
… | |
21 | * You should have received a copy of the GNU General Public License |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | */ |
24 | */ |
25 | |
25 | |
26 | #include <EXTERN.h> |
|
|
27 | #include <perl.h> |
|
|
28 | #include <XSUB.h> |
|
|
29 | |
|
|
30 | #undef save_long // clashes with libproto.h |
|
|
31 | |
|
|
32 | #define PLUGIN_NAME "perl" |
26 | #define PLUGIN_NAME "perl" |
33 | #define PLUGIN_VERSION "cfperl 0.5" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
34 | |
28 | |
35 | #ifndef __CEXTRACT__ |
29 | #ifndef __CEXTRACT__ |
36 | #include <plugin.h> |
30 | #include <plugin.h> |
… | |
… | |
48 | #include <sproto.h> |
42 | #include <sproto.h> |
49 | |
43 | |
50 | #include "cfperl.h" |
44 | #include "cfperl.h" |
51 | #include "shstr.h" |
45 | #include "shstr.h" |
52 | |
46 | |
|
|
47 | #include <EXTERN.h> |
|
|
48 | #include <perl.h> |
|
|
49 | #include <XSUB.h> |
|
|
50 | |
53 | #include "perlxsi.c" |
51 | #include "perlxsi.c" |
54 | |
52 | |
55 | extern sint64 *levels; // the experience table |
53 | extern sint64 *levels; // the experience table |
56 | |
54 | |
57 | typedef object object_ornull; |
55 | typedef object object_ornull; |
… | |
… | |
59 | |
57 | |
60 | typedef double val64; |
58 | typedef double val64; |
61 | #define newSVval64 newSVnv |
59 | #define newSVval64 newSVnv |
62 | #define SvVAL64 SvNV |
60 | #define SvVAL64 SvNV |
63 | |
61 | |
64 | static f_plug_api gethook; |
62 | static f_plug_api gethook = cfapi_get_hooks; |
65 | static f_plug_api systemDirectory; |
63 | static f_plug_api object_set_property = cfapi_object_set_property; |
66 | static f_plug_api object_set_property; |
64 | static f_plug_api object_insert = cfapi_object_insert; |
67 | static f_plug_api map_get_map; |
65 | |
68 | static f_plug_api object_insert; |
66 | static bool perl_booted; |
69 | |
67 | |
70 | /* this is a stupid way to do things, and awkward to use for plug-in authors */ |
68 | /* this is a stupid way to do things, and awkward to use for plug-in authors */ |
71 | typedef struct |
69 | typedef struct |
72 | { |
70 | { |
73 | object* who; |
71 | object* who; |
… | |
… | |
108 | |
106 | |
109 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
107 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
110 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
108 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
111 | } |
109 | } |
112 | |
110 | |
113 | template<class extendable> |
111 | template<class attachable> |
114 | SV * |
112 | SV * |
115 | newSVextendable (extendable *obj, const char *klass) |
113 | newSVattachable (attachable *obj, const char *klass) |
116 | { |
114 | { |
117 | if (!obj) |
115 | if (!obj) |
118 | return &PL_sv_undef; |
116 | return &PL_sv_undef; |
119 | |
117 | |
120 | if (!obj->self) |
118 | if (!obj->self) |
121 | obj->self = newSVptr (obj, klass); |
119 | obj->self = newSVptr (obj, klass); |
122 | |
120 | |
123 | return newSVsv (static_cast<SV *>(obj->self)); |
121 | return newSVsv (obj->self); |
124 | } |
122 | } |
125 | |
123 | |
126 | static void |
124 | static void |
127 | SVptr_cache_set (void *ptr, SV *sv) |
125 | SVptr_cache_set (void *ptr, SV *sv) |
128 | { |
126 | { |
… | |
… | |
227 | break; |
225 | break; |
228 | |
226 | |
229 | case DT_OBJECT: |
227 | case DT_OBJECT: |
230 | { |
228 | { |
231 | object *obj = va_arg (ap, object *); |
229 | object *obj = va_arg (ap, object *); |
232 | sv = newSVextendable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
230 | sv = newSVattachable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
233 | } |
231 | } |
234 | break; |
232 | break; |
235 | |
233 | |
236 | case DT_MAP: |
234 | case DT_MAP: |
237 | // va_arg (object *) when void * is passed is an XSI extension |
235 | // va_arg (object *) when void * is passed is an XSI extension |
238 | sv = newSVextendable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
236 | sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
239 | break; |
237 | break; |
240 | |
238 | |
241 | case DT_PLAYER: |
239 | case DT_PLAYER: |
242 | sv = newSVextendable (va_arg (ap, player *), "cf::player::wrap"); |
240 | sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap"); |
243 | break; |
241 | break; |
244 | |
242 | |
245 | case DT_ARCH: |
243 | case DT_ARCH: |
246 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
244 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
247 | break; |
245 | break; |
… | |
… | |
304 | } |
302 | } |
305 | |
303 | |
306 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
304 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
307 | |
305 | |
308 | SV * |
306 | SV * |
309 | registry_of (extendable_base *ext) |
307 | registry_of (attachable_base *ext) |
310 | { |
308 | { |
311 | if (!ext->cb) |
309 | if (!ext->cb) |
312 | ext->cb = newAV (); |
310 | ext->cb = newAV (); |
313 | |
311 | |
314 | return newRV_inc ((SV *)ext->cb); |
312 | return newRV_inc ((SV *)ext->cb); |
315 | } |
313 | } |
316 | |
314 | |
317 | void extendable_base::clear () |
315 | void attachable_base::clear () |
318 | { |
316 | { |
319 | //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D |
317 | if (self) |
|
|
318 | { |
|
|
319 | if (cb) |
|
|
320 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
|
|
321 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
|
|
322 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
|
|
323 | INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); |
320 | |
324 | |
|
|
325 | // disconnect Perl from C, to avoid crashes |
|
|
326 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
|
|
327 | |
|
|
328 | // clear the perl hash, might or might not be a good idea |
|
|
329 | hv_clear ((HV *)SvRV ((SV *)self)); |
|
|
330 | |
321 | if (self) SvREFCNT_dec (self); |
331 | SvREFCNT_dec (self); |
|
|
332 | self = 0; |
|
|
333 | } |
|
|
334 | |
|
|
335 | if (cb) |
|
|
336 | { |
322 | if (cb) SvREFCNT_dec (cb); |
337 | SvREFCNT_dec (cb); |
|
|
338 | cb = 0; |
|
|
339 | } |
323 | |
340 | |
|
|
341 | if (attach) |
|
|
342 | { |
324 | if (attach) free_string (attach); |
343 | free_string (attach); |
325 | |
|
|
326 | self = 0; |
|
|
327 | cb = 0; |
|
|
328 | attach = 0; |
344 | attach = 0; |
|
|
345 | } |
329 | } |
346 | } |
330 | |
347 | |
331 | void extendable_base::optimise () |
348 | void attachable_base::optimise () |
332 | { |
349 | { |
333 | if (!self) |
350 | if (!self) |
334 | return; |
351 | return; |
335 | |
352 | |
336 | HV *hv = (HV *)SvRV ((SV *)self); |
353 | HV *hv = (HV *)SvRV ((SV *)self); |
… | |
… | |
342 | SvREFCNT_dec ((SV *)self); |
359 | SvREFCNT_dec ((SV *)self); |
343 | self = 0; |
360 | self = 0; |
344 | } |
361 | } |
345 | } |
362 | } |
346 | |
363 | |
347 | void |
364 | void attachable_base::instantiate (data_type type, void *obj) |
348 | object::instantiate_ () |
|
|
349 | { |
365 | { |
350 | dSP; |
366 | dSP; |
351 | ENTER; |
367 | ENTER; |
352 | SAVETMPS; |
368 | SAVETMPS; |
353 | PUSHMARK (SP); |
369 | PUSHMARK (SP); |
354 | EXTEND (SP, 2); |
370 | EXTEND (SP, 2); |
355 | PUSHs (sv_2mortal (newSVdt (DT_OBJECT, static_cast<object *>(this)))); |
371 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
356 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
372 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
|
|
373 | |
|
|
374 | free_string (attach); |
|
|
375 | attach = 0; |
|
|
376 | |
357 | PUTBACK; |
377 | PUTBACK; |
358 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
378 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
359 | FREETMPS; |
379 | FREETMPS; |
360 | LEAVE; |
380 | LEAVE; |
|
|
381 | |
|
|
382 | switch (type) |
|
|
383 | { |
|
|
384 | case DT_OBJECT: INVOKE_OBJECT (INSTANTIATE, obj); break; |
|
|
385 | case DT_MAP: INVOKE_MAP (INSTANTIATE, obj); break; |
|
|
386 | } |
361 | } |
387 | } |
362 | |
388 | |
363 | ///////////////////////////////////////////////////////////////////////////// |
389 | ///////////////////////////////////////////////////////////////////////////// |
364 | |
390 | |
365 | object_freezer::object_freezer (const char *filename) |
391 | void reattach (data_type type, void *obj) |
366 | : filename (filename) |
|
|
367 | { |
392 | { |
368 | av = (AV *)newAV (); |
393 | //TODO only do this when the object has _attachment's |
369 | idx = 0; |
|
|
370 | av_extend ((AV *)av, 1024); |
|
|
371 | } |
|
|
372 | |
394 | |
373 | object_freezer::~object_freezer () |
|
|
374 | { |
|
|
375 | dSP; |
395 | dSP; |
376 | ENTER; |
396 | ENTER; |
377 | SAVETMPS; |
397 | SAVETMPS; |
378 | PUSHMARK (SP); |
398 | PUSHMARK (SP); |
|
|
399 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
|
|
400 | PUTBACK; |
|
|
401 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
|
|
402 | FREETMPS; |
|
|
403 | LEAVE; |
|
|
404 | |
|
|
405 | switch (type) |
|
|
406 | { |
|
|
407 | case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; |
|
|
408 | case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; |
|
|
409 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
|
|
410 | } |
|
|
411 | } |
|
|
412 | |
|
|
413 | template<class subclass> |
|
|
414 | void reattach (attachable<subclass> *obj) |
|
|
415 | { |
|
|
416 | obj->optimise (); |
|
|
417 | |
|
|
418 | if (obj->self) |
|
|
419 | reattach (subclass::get_dt (), (subclass *)obj); |
|
|
420 | } |
|
|
421 | |
|
|
422 | object_freezer::object_freezer (const char *filename) |
|
|
423 | { |
|
|
424 | this->filename = (SV *)newSVpv (filename, 0); |
|
|
425 | |
|
|
426 | char filename2 [4096]; |
|
|
427 | snprintf (filename2, 4096, "%s~", filename); |
|
|
428 | |
|
|
429 | av = newAV (); |
|
|
430 | |
|
|
431 | // TODO: fast dynbuf implementation... yeah, we need obstacks |
|
|
432 | text = newSV (10 * 1024 * 1024); // only temporarily used, so be generous |
|
|
433 | } |
|
|
434 | |
|
|
435 | object_freezer::~object_freezer () |
|
|
436 | { |
|
|
437 | dSP; |
|
|
438 | ENTER; |
|
|
439 | SAVETMPS; |
|
|
440 | PUSHMARK (SP); |
379 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
441 | XPUSHs (sv_2mortal ((SV *)filename)); |
|
|
442 | XPUSHs (sv_2mortal (newRV_noinc (text))); |
380 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
443 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
381 | PUTBACK; |
444 | PUTBACK; |
382 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
445 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
383 | FREETMPS; |
446 | FREETMPS; |
384 | LEAVE; |
447 | LEAVE; |
385 | } |
448 | } |
386 | |
449 | |
387 | void object_freezer::put (extendable_base *ext) |
450 | void object_freezer::put (attachable_base *ext) |
388 | { |
451 | { |
389 | ext->optimise (); |
452 | ext->optimise (); |
390 | |
453 | |
391 | if (ext->self) |
454 | if (ext->self) |
|
|
455 | { |
|
|
456 | int idx = AvFILLp ((AV *)av) + 1; |
392 | av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); |
457 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
393 | |
458 | |
394 | ++idx; |
459 | sv_catpvf (text, "oid %d\n", idx); |
|
|
460 | } |
|
|
461 | } |
|
|
462 | |
|
|
463 | int fprintf (object_freezer &freezer, const char *format, ...) |
|
|
464 | { |
|
|
465 | va_list ap; |
|
|
466 | |
|
|
467 | va_start (ap, format); |
|
|
468 | sv_vcatpvfn (freezer.text, format, strlen (format), &ap, 0, 0, 0); |
|
|
469 | va_end (ap); |
|
|
470 | } |
|
|
471 | |
|
|
472 | int fputs (const char *s, object_freezer &freezer) |
|
|
473 | { |
|
|
474 | sv_catpvn (freezer.text, s, strlen (s)); |
395 | } |
475 | } |
396 | |
476 | |
397 | object_thawer::object_thawer (const char *filename) |
477 | object_thawer::object_thawer (const char *filename) |
398 | { |
478 | { |
399 | av = 0; |
479 | av = 0; |
400 | idx = 0; |
480 | fp = 0; |
401 | |
481 | |
402 | if (!filename) |
482 | if (!filename) |
403 | return; |
483 | return; |
404 | |
484 | |
405 | dSP; |
485 | fp = fopen (filename, "r"); |
406 | ENTER; |
486 | if (!fp) |
407 | SAVETMPS; |
|
|
408 | PUSHMARK (SP); |
|
|
409 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
|
|
410 | PUTBACK; |
|
|
411 | |
|
|
412 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
|
|
413 | { |
487 | { |
414 | SPAGAIN; |
488 | LOG (llevError, "object_thawer: unable to open '%s': %s.\n", filename, strerror (errno)); |
415 | SV *sv = POPs; |
489 | return; |
416 | if (SvROK (sv)) |
|
|
417 | av = SvREFCNT_inc (SvRV (sv)); |
|
|
418 | } |
490 | } |
419 | |
491 | |
420 | FREETMPS; |
492 | if (perl_booted) |
421 | LEAVE; |
|
|
422 | } |
|
|
423 | |
|
|
424 | void object_thawer::get (data_type type, void *obj, extendable_base *ext) |
|
|
425 | { |
|
|
426 | if (!av) |
|
|
427 | return; |
|
|
428 | |
|
|
429 | // we have to "re-instantiate"/reattach to an object, so nuke ext->attach |
|
|
430 | ext->clear (); |
|
|
431 | |
|
|
432 | SV **svp = av_fetch ((AV *)av, idx, 0); |
|
|
433 | |
|
|
434 | ++idx; |
|
|
435 | |
|
|
436 | if (!svp) |
|
|
437 | return; |
|
|
438 | |
|
|
439 | if (SvROK (*svp)) |
|
|
440 | { |
493 | { |
441 | ext->self = SvREFCNT_inc (*svp); |
|
|
442 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
|
|
443 | |
|
|
444 | dSP; |
494 | dSP; |
445 | ENTER; |
495 | ENTER; |
446 | SAVETMPS; |
496 | SAVETMPS; |
447 | PUSHMARK (SP); |
497 | PUSHMARK (SP); |
448 | EXTEND (SP, 1); |
|
|
449 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
498 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
450 | PUTBACK; |
499 | PUTBACK; |
451 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
500 | |
|
|
501 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
|
|
502 | { |
|
|
503 | SPAGAIN; |
|
|
504 | SV *sv = POPs; |
|
|
505 | if (SvROK (sv)) |
|
|
506 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
|
|
507 | } |
|
|
508 | |
452 | FREETMPS; |
509 | FREETMPS; |
453 | LEAVE; |
510 | LEAVE; |
454 | |
|
|
455 | if (ext->cb && type == DT_OBJECT) |
|
|
456 | INVOKE_OBJECT (REATTACH, (object *)obj); |
|
|
457 | } |
511 | } |
458 | } |
512 | } |
459 | |
513 | |
|
|
514 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
|
|
515 | { |
|
|
516 | if (!av || oid < 0) // this is actually an error of sorts |
|
|
517 | return; |
|
|
518 | |
|
|
519 | // we have to "re-instantiate"/reattach to an object, so nuke ext->attach |
|
|
520 | ext->clear (); |
|
|
521 | |
|
|
522 | SV **svp = av_fetch ((AV *)av, oid, 0); |
|
|
523 | |
|
|
524 | if (!svp || !SvROK (*svp)) |
|
|
525 | { |
|
|
526 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
|
|
527 | return; |
|
|
528 | } |
|
|
529 | |
|
|
530 | ext->self = *svp; *svp = &PL_sv_undef; |
|
|
531 | sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
|
|
532 | |
|
|
533 | reattach (type, obj); |
|
|
534 | } |
|
|
535 | |
460 | object_thawer::~object_thawer () |
536 | object_thawer::~object_thawer () |
461 | { |
537 | { |
462 | if (av) |
538 | if (fp) fclose (fp); |
463 | SvREFCNT_dec ((SV *)av); |
539 | if (av) SvREFCNT_dec ((AV *)av); |
464 | } |
540 | } |
465 | |
541 | |
466 | ///////////////////////////////////////////////////////////////////////////// |
542 | ///////////////////////////////////////////////////////////////////////////// |
467 | |
543 | |
468 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
544 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
469 | { |
545 | { |
470 | gethook = gethooksptr; |
|
|
471 | printf (PLUGIN_VERSION " init\n"); |
|
|
472 | |
|
|
473 | return 0; |
546 | return 0; |
474 | } |
547 | } |
475 | |
548 | |
476 | static CommArray_s rtn_cmd; |
549 | static CommArray_s rtn_cmd; |
477 | |
550 | |
… | |
… | |
557 | extern "C" int cfperl_postInitPlugin () |
630 | extern "C" int cfperl_postInitPlugin () |
558 | { |
631 | { |
559 | int hooktype = 1; |
632 | int hooktype = 1; |
560 | int rtype = 0; |
633 | int rtype = 0; |
561 | |
634 | |
562 | printf (PLUGIN_VERSION " post init\n"); |
|
|
563 | |
|
|
564 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
|
|
565 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
|
|
566 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
|
|
567 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
|
|
568 | |
|
|
569 | cf_init_plugin (gethook); |
635 | cf_init_plugin (gethook); |
570 | |
636 | |
571 | return 0; |
637 | return 0; |
572 | } |
638 | } |
573 | |
639 | |
… | |
… | |
577 | } |
643 | } |
578 | |
644 | |
579 | void |
645 | void |
580 | cfperl_init () |
646 | cfperl_init () |
581 | { |
647 | { |
|
|
648 | PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); |
|
|
649 | perl = perl_alloc (); |
|
|
650 | perl_construct (perl); |
|
|
651 | |
|
|
652 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
653 | |
582 | char *argv[] = { |
654 | char *argv[] = { |
583 | "", |
655 | "", |
584 | "-e" |
656 | "-e" |
585 | "BEGIN {" |
|
|
586 | " cf->bootstrap;" |
657 | "cf->bootstrap;" |
587 | " unshift @INC, cf::datadir ();" |
658 | "unshift @INC, cf::datadir ();" |
588 | "}" |
|
|
589 | "" |
|
|
590 | "use cf;" |
|
|
591 | }; |
659 | }; |
592 | |
|
|
593 | perl = perl_alloc (); |
|
|
594 | perl_construct (perl); |
|
|
595 | |
|
|
596 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
597 | |
660 | |
598 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
661 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
599 | { |
662 | { |
600 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
663 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
601 | |
|
|
602 | exit (EXIT_FAILURE); |
664 | exit (EXIT_FAILURE); |
603 | //perl_destruct (perl); |
|
|
604 | //perl_free (perl); |
|
|
605 | //perl = 0; |
|
|
606 | //return; |
|
|
607 | } |
665 | } |
608 | |
666 | |
609 | obj_cache = newHV (); |
667 | obj_cache = newHV (); |
|
|
668 | } |
|
|
669 | |
|
|
670 | void cfperl_boot () |
|
|
671 | { |
|
|
672 | perl_booted = true; |
|
|
673 | |
|
|
674 | eval_pv ("require cf", 1); |
610 | } |
675 | } |
611 | |
676 | |
612 | void cfperl_main () |
677 | void cfperl_main () |
613 | { |
678 | { |
614 | dSP; |
679 | dSP; |
… | |
… | |
621 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
686 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
622 | # define def(type,name) KLASS_ ## type, |
687 | # define def(type,name) KLASS_ ## type, |
623 | # include "eventinc.h" |
688 | # include "eventinc.h" |
624 | # undef def |
689 | # undef def |
625 | }; |
690 | }; |
|
|
691 | |
|
|
692 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
626 | |
693 | |
627 | static void |
694 | static void |
628 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
695 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
629 | { |
696 | { |
630 | // event must be in array |
697 | // event must be in array |
… | |
… | |
673 | // 2a. per-type callback |
740 | // 2a. per-type callback |
674 | // 4. global callbacks |
741 | // 4. global callbacks |
675 | |
742 | |
676 | gather_callbacks (callbacks, cb_global, event); |
743 | gather_callbacks (callbacks, cb_global, event); |
677 | |
744 | |
678 | switch (klass_of [event]) |
745 | switch (KLASS_OF (event)) |
679 | { |
746 | { |
680 | case KLASS_GLOBAL: |
747 | case KLASS_GLOBAL: |
681 | break; |
748 | break; |
682 | |
749 | |
683 | case KLASS_OBJECT: |
750 | case KLASS_OBJECT: |
684 | dt = (data_type) va_arg (ap, int); |
751 | dt = (data_type) va_arg (ap, int); |
685 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
752 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
686 | op = va_arg (ap, object *); |
753 | op = va_arg (ap, object *); |
687 | |
754 | |
688 | if (op->cb) |
755 | if (op->cb) |
689 | gather_callbacks (callbacks, (AV *)op->cb, event); |
756 | gather_callbacks (callbacks, op->cb, event); |
|
|
757 | |
|
|
758 | if (op->type) |
|
|
759 | { |
|
|
760 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
|
|
761 | { |
|
|
762 | SV *registry = AvARRAY (cb_type)[op->type + op->subtype * NUM_SUBTYPES]; |
|
|
763 | |
|
|
764 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
765 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
766 | } |
|
|
767 | |
|
|
768 | if (op->type <= AvFILLp (cb_type)) |
|
|
769 | { |
|
|
770 | SV *registry = AvARRAY (cb_type)[op->type]; |
|
|
771 | |
|
|
772 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
773 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
774 | } |
|
|
775 | } |
690 | |
776 | |
691 | gather_callbacks (callbacks, cb_object, event); |
777 | gather_callbacks (callbacks, cb_object, event); |
692 | |
|
|
693 | if (op->type > 0 && op->type <= AvFILLp (cb_type)) |
|
|
694 | { |
|
|
695 | SV *registry = AvARRAY (cb_type)[op->type]; |
|
|
696 | |
|
|
697 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
698 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
699 | } |
|
|
700 | |
778 | |
701 | break; |
779 | break; |
702 | |
780 | |
703 | case KLASS_PLAYER: |
781 | case KLASS_PLAYER: |
704 | dt = (data_type) va_arg (ap, int); |
782 | dt = (data_type) va_arg (ap, int); |
705 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
783 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
706 | pl = va_arg (ap, player *); |
784 | pl = va_arg (ap, player *); |
707 | |
785 | |
708 | if (pl->cb) |
786 | if (pl->cb) |
709 | gather_callbacks (callbacks, (AV *)pl->cb, event); |
787 | gather_callbacks (callbacks, pl->cb, event); |
710 | |
788 | |
711 | gather_callbacks (callbacks, cb_player, event); |
789 | gather_callbacks (callbacks, cb_player, event); |
712 | break; |
790 | break; |
713 | |
791 | |
714 | case KLASS_MAP: |
792 | case KLASS_MAP: |
715 | dt = (data_type) va_arg (ap, int); |
793 | dt = (data_type) va_arg (ap, int); |
716 | assert (("first argument must be of type object", dt == DT_MAP)); |
794 | assert (("first argument must be of type object", dt == DT_MAP)); |
717 | map = va_arg (ap, mapstruct *); |
795 | map = va_arg (ap, mapstruct *); |
718 | |
796 | |
719 | if (map->cb) |
797 | if (map->cb) |
720 | gather_callbacks (callbacks, (AV *)map->cb, event); |
798 | gather_callbacks (callbacks, map->cb, event); |
721 | |
799 | |
722 | gather_callbacks (callbacks, cb_map, event); |
800 | gather_callbacks (callbacks, cb_map, event); |
723 | break; |
801 | break; |
724 | |
802 | |
725 | default: |
803 | default: |
… | |
… | |
738 | EXTEND (SP, 3); |
816 | EXTEND (SP, 3); |
739 | |
817 | |
740 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
818 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
741 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
819 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
742 | |
820 | |
743 | switch (klass_of [event]) |
821 | switch (KLASS_OF (event)) |
744 | { |
822 | { |
745 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
823 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
746 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
824 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
747 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
825 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
748 | } |
826 | } |
… | |
… | |
938 | const_iv (BUILDER) |
1016 | const_iv (BUILDER) |
939 | const_iv (MATERIAL) |
1017 | const_iv (MATERIAL) |
940 | const_iv (ITEM_TRANSFORMER) |
1018 | const_iv (ITEM_TRANSFORMER) |
941 | const_iv (QUEST) |
1019 | const_iv (QUEST) |
942 | |
1020 | |
|
|
1021 | const_iv (NUM_SUBTYPES) |
|
|
1022 | |
943 | const_iv (ST_BD_BUILD) |
1023 | const_iv (ST_BD_BUILD) |
944 | const_iv (ST_BD_REMOVE) |
1024 | const_iv (ST_BD_REMOVE) |
945 | |
1025 | |
946 | const_iv (ST_MAT_FLOOR) |
1026 | const_iv (ST_MAT_FLOOR) |
947 | const_iv (ST_MAT_WALL) |
1027 | const_iv (ST_MAT_WALL) |
… | |
… | |
1288 | |
1368 | |
1289 | const_iv (KLASS_GLOBAL) |
1369 | const_iv (KLASS_GLOBAL) |
1290 | const_iv (KLASS_OBJECT) |
1370 | const_iv (KLASS_OBJECT) |
1291 | const_iv (KLASS_PLAYER) |
1371 | const_iv (KLASS_PLAYER) |
1292 | const_iv (KLASS_MAP) |
1372 | const_iv (KLASS_MAP) |
1293 | |
|
|
1294 | const_iv (EVENT_OBJECT_INSTANTIATE) |
|
|
1295 | }; |
1373 | }; |
1296 | |
1374 | |
1297 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1375 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1298 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1376 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1299 | |
1377 | |
1300 | static const struct { |
1378 | static const struct { |
1301 | const char *name; |
1379 | const char *name; |
|
|
1380 | int skip; |
1302 | IV klass; |
1381 | IV klass; |
1303 | IV iv; |
1382 | IV iv; |
1304 | } *eiv, event_iv[] = { |
1383 | } *eiv, event_iv[] = { |
1305 | # define def(klass,name) { # name, (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1384 | # define def(klass,name) { "EVENT_" # klass "_" # name, sizeof ("EVENT_" # klass), (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1306 | # include "eventinc.h" |
1385 | # include "eventinc.h" |
1307 | # undef def |
1386 | # undef def |
1308 | }; |
1387 | }; |
1309 | |
1388 | |
1310 | AV *av = get_av ("cf::EVENT", 1); |
1389 | AV *av = get_av ("cf::EVENT", 1); |
1311 | |
1390 | |
1312 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1391 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1313 | { |
1392 | { |
1314 | AV *event = newAV (); |
1393 | AV *event = newAV (); |
1315 | av_push (event, newSVpv ((char *)eiv->name, 0)); |
1394 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1316 | av_push (event, newSViv (eiv->klass)); |
1395 | av_push (event, newSViv (eiv->klass)); |
1317 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1396 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
|
|
1397 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1318 | } |
1398 | } |
1319 | |
1399 | |
1320 | static const struct { |
1400 | static const struct { |
1321 | int dtype; |
1401 | int dtype; |
1322 | const char *name; |
1402 | const char *name; |
… | |
… | |
1343 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1423 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1344 | prop (CFAPI_INT, MAP_PROP_SKY) |
1424 | prop (CFAPI_INT, MAP_PROP_SKY) |
1345 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1425 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1346 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1426 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1347 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1427 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1348 | prop (CFAPI_PMAP, MAP_PROP_NEXT) |
|
|
1349 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1428 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1350 | prop (CFAPI_POBJECT, OBJECT_PROP_OB_ABOVE) |
|
|
1351 | prop (CFAPI_POBJECT, OBJECT_PROP_OB_BELOW) |
|
|
1352 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1429 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1353 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1430 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1354 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1431 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1355 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
1432 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
1356 | prop (CFAPI_POBJECT, OBJECT_PROP_HEAD) |
|
|
1357 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
1433 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
1358 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
1434 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
1359 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
1435 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
1360 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
1436 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
1361 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
1437 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
… | |
… | |
1451 | { |
1527 | { |
1452 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1528 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1453 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1529 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1454 | } |
1530 | } |
1455 | |
1531 | |
1456 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
|
|
1457 | cb_object = get_av ("cf::CB_OBJECT", 1); |
|
|
1458 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1459 | cb_type = get_av ("cf::CB_TYPE" , 1); |
|
|
1460 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1461 | |
|
|
1462 | //I_EVENT_API (PACKAGE); |
1532 | //I_EVENT_API (PACKAGE); |
|
|
1533 | } |
|
|
1534 | |
|
|
1535 | void _reload_1 () |
|
|
1536 | CODE: |
|
|
1537 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
|
|
1538 | cb_object = get_av ("cf::CB_OBJECT", 1); |
|
|
1539 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1540 | cb_type = get_av ("cf::CB_TYPE" , 1); |
|
|
1541 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1542 | |
|
|
1543 | void _reload_2 () |
|
|
1544 | CODE: |
|
|
1545 | { |
|
|
1546 | // reattach to all attachable objects in the game. |
|
|
1547 | for (player *pl = first_player; pl; pl = pl->next) |
|
|
1548 | reattach (pl); |
|
|
1549 | |
|
|
1550 | for (mapstruct *map = first_map; map; map = map->next) |
|
|
1551 | reattach (map); |
|
|
1552 | |
|
|
1553 | for (object *op = objects; op; op = op->next) |
|
|
1554 | reattach (op); |
1463 | } |
1555 | } |
1464 | |
1556 | |
1465 | NV floor (NV x) |
1557 | NV floor (NV x) |
1466 | |
1558 | |
1467 | NV ceil (NV x) |
1559 | NV ceil (NV x) |
… | |
… | |
1477 | PROTOTYPE: $$ |
1569 | PROTOTYPE: $$ |
1478 | |
1570 | |
1479 | char *path_combine_and_normalize (char *base, char *path) |
1571 | char *path_combine_and_normalize (char *base, char *path) |
1480 | PROTOTYPE: $$ |
1572 | PROTOTYPE: $$ |
1481 | |
1573 | |
1482 | char * |
1574 | const char * |
1483 | cf_get_maps_directory (char *path) |
1575 | get_maps_directory (char *path) |
1484 | PROTOTYPE: $ |
1576 | PROTOTYPE: $ |
1485 | ALIAS: maps_directory = 0 |
1577 | ALIAS: maps_directory = 0 |
|
|
1578 | CODE: |
|
|
1579 | RETVAL = create_pathname (path); |
|
|
1580 | OUTPUT: RETVAL |
1486 | |
1581 | |
1487 | void |
1582 | void |
1488 | sub_generation_inc () |
1583 | sub_generation_inc () |
1489 | CODE: |
1584 | CODE: |
1490 | PL_sub_generation++; |
1585 | PL_sub_generation++; |
… | |
… | |
1499 | confdir = 3 |
1594 | confdir = 3 |
1500 | localdir = 4 |
1595 | localdir = 4 |
1501 | playerdir = 5 |
1596 | playerdir = 5 |
1502 | datadir = 6 |
1597 | datadir = 6 |
1503 | CODE: |
1598 | CODE: |
1504 | { |
1599 | switch (ix) |
1505 | int unused_type; |
1600 | { |
1506 | RETVAL = (char *)systemDirectory (&unused_type, ix); |
1601 | case 0: RETVAL = settings.mapdir ; break; |
1507 | } |
1602 | case 1: RETVAL = settings.uniquedir; break; |
|
|
1603 | case 2: RETVAL = settings.tmpdir ; break; |
|
|
1604 | case 3: RETVAL = settings.confdir ; break; |
|
|
1605 | case 4: RETVAL = settings.localdir ; break; |
|
|
1606 | case 5: RETVAL = settings.playerdir; break; |
|
|
1607 | case 6: RETVAL = settings.datadir ; break; |
|
|
1608 | } |
1508 | OUTPUT: RETVAL |
1609 | OUTPUT: RETVAL |
1509 | |
1610 | |
1510 | int |
1611 | int |
1511 | cf_find_animation (char *text) |
1612 | cf_find_animation (char *text) |
1512 | PROTOTYPE: $ |
1613 | PROTOTYPE: $ |
1513 | |
1614 | |
1514 | int random_roll(int min, int max, object *op, int goodbad); |
1615 | int random_roll(int min, int max, object *op, int goodbad); |
1515 | |
1616 | |
1516 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1617 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1517 | |
1618 | |
1518 | int invoke (int event, SV *arg1, ...) |
1619 | int invoke (int event, ...) |
1519 | CODE: |
1620 | CODE: |
1520 | { |
1621 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1521 | // parse first arg and call invoke_object etc as seen fit |
1622 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1522 | //TODO |
1623 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1523 | //cfperl_invoke (event, |
1624 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
1524 | } |
1625 | OUTPUT: RETVAL |
1525 | |
1626 | |
1526 | int |
1627 | int |
1527 | exp_to_level (val64 exp) |
1628 | exp_to_level (val64 exp) |
1528 | CODE: |
1629 | CODE: |
1529 | { |
1630 | { |
… | |
… | |
1560 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1661 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1561 | else |
1662 | else |
1562 | XSRETURN_UNDEF; |
1663 | XSRETURN_UNDEF; |
1563 | OUTPUT: RETVAL |
1664 | OUTPUT: RETVAL |
1564 | |
1665 | |
|
|
1666 | int |
|
|
1667 | _valid (SV *obj) |
|
|
1668 | CODE: |
|
|
1669 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
|
|
1670 | OUTPUT: |
|
|
1671 | RETVAL |
|
|
1672 | |
1565 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1673 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
|
|
1674 | |
|
|
1675 | int invoke (object *op, int event, ...) |
|
|
1676 | CODE: |
|
|
1677 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
|
|
1678 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1679 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
1680 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
|
|
1681 | OUTPUT: RETVAL |
|
|
1682 | |
|
|
1683 | SV *registry (object *op) |
|
|
1684 | CODE: |
|
|
1685 | RETVAL = registry_of (op); |
|
|
1686 | OUTPUT: |
|
|
1687 | RETVAL |
|
|
1688 | |
|
|
1689 | object *head (object *op) |
|
|
1690 | PROTOTYPE: $ |
|
|
1691 | ALIAS: |
|
|
1692 | more = 1 |
|
|
1693 | above = 2 |
|
|
1694 | below = 3 |
|
|
1695 | CODE: |
|
|
1696 | switch (ix) |
|
|
1697 | { |
|
|
1698 | case 0: RETVAL = op->head ? op->head : op; break; // DOH! |
|
|
1699 | case 1: RETVAL = op->more; break; |
|
|
1700 | case 2: RETVAL = op->above; break; |
|
|
1701 | case 3: RETVAL = op->below; break; |
|
|
1702 | } |
|
|
1703 | OUTPUT: |
|
|
1704 | RETVAL |
1566 | |
1705 | |
1567 | SV * |
1706 | SV * |
1568 | get_property (object *obj, int type, int idx) |
1707 | get_property (object *obj, int type, int idx) |
1569 | CODE: |
1708 | CODE: |
1570 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
1709 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
… | |
… | |
1649 | |
1788 | |
1650 | int need_identify (const object *obj); |
1789 | int need_identify (const object *obj); |
1651 | |
1790 | |
1652 | int apply_shop_mat (object *shop_mat, object *op); |
1791 | int apply_shop_mat (object *shop_mat, object *op); |
1653 | |
1792 | |
1654 | void cf_object_move (object *op, int dir, object *originator = op) |
1793 | int move (object *op, int dir, object *originator = op) |
|
|
1794 | CODE: |
|
|
1795 | RETVAL = move_ob (op, dir, originator); |
|
|
1796 | OUTPUT: |
|
|
1797 | RETVAL |
1655 | |
1798 | |
1656 | void cf_object_apply (object *op, object *author, int flags = 0) |
1799 | void cf_object_apply (object *op, object *author, int flags = 0) |
1657 | |
1800 | |
1658 | void cf_object_apply_below (object *op) |
1801 | void cf_object_apply_below (object *op) |
1659 | |
1802 | |
… | |
… | |
1700 | int cf_object_out_of_map (object *op, int x, int y) |
1843 | int cf_object_out_of_map (object *op, int x, int y) |
1701 | |
1844 | |
1702 | void cf_object_drop (object *op, object *author) |
1845 | void cf_object_drop (object *op, object *author) |
1703 | |
1846 | |
1704 | void cf_object_take (object *op, object *author) |
1847 | void cf_object_take (object *op, object *author) |
1705 | |
|
|
1706 | void cf_object_say (object *op, char *msg) |
|
|
1707 | |
|
|
1708 | void cf_object_speak (object *op, char *msg) |
|
|
1709 | |
1848 | |
1710 | object *cf_object_insert_object (object *op, object *container) |
1849 | object *cf_object_insert_object (object *op, object *container) |
1711 | |
1850 | |
1712 | const char *cf_object_get_msg (object *ob) |
1851 | const char *cf_object_get_msg (object *ob) |
1713 | ALIAS: msg = 0 |
1852 | ALIAS: msg = 0 |
… | |
… | |
1767 | CODE: |
1906 | CODE: |
1768 | { |
1907 | { |
1769 | int unused_type; |
1908 | int unused_type; |
1770 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1909 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1771 | } |
1910 | } |
1772 | |
|
|
1773 | SV *registry (object *op) |
|
|
1774 | CODE: |
|
|
1775 | RETVAL = registry_of (op); |
|
|
1776 | OUTPUT: |
|
|
1777 | RETVAL |
|
|
1778 | |
1911 | |
1779 | # syntatic sugar for easier use in event callbacks. |
1912 | # syntatic sugar for easier use in event callbacks. |
1780 | const char *options (object *op) |
1913 | const char *options (object *op) |
1781 | CODE: |
1914 | CODE: |
1782 | RETVAL = op->name; |
1915 | RETVAL = op->name; |
… | |
… | |
1855 | |
1988 | |
1856 | void kill_player (object *op) |
1989 | void kill_player (object *op) |
1857 | |
1990 | |
1858 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1991 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1859 | |
1992 | |
|
|
1993 | int invoke (player *pl, int event, ...) |
|
|
1994 | CODE: |
|
|
1995 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
|
|
1996 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1997 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
1998 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
|
|
1999 | OUTPUT: RETVAL |
|
|
2000 | |
1860 | SV *registry (player *pl) |
2001 | SV *registry (player *pl) |
1861 | CODE: |
2002 | CODE: |
1862 | RETVAL = registry_of (pl); |
2003 | RETVAL = registry_of (pl); |
1863 | OUTPUT: |
2004 | OUTPUT: |
1864 | RETVAL |
2005 | RETVAL |
… | |
… | |
1988 | OUTPUT: RETVAL |
2129 | OUTPUT: RETVAL |
1989 | |
2130 | |
1990 | |
2131 | |
1991 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2132 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1992 | |
2133 | |
|
|
2134 | mapstruct *first () |
|
|
2135 | PROTOTYPE: |
|
|
2136 | CODE: |
|
|
2137 | RETVAL = first_map; |
|
|
2138 | OUTPUT: RETVAL |
|
|
2139 | |
|
|
2140 | mapstruct *next (mapstruct *map) |
|
|
2141 | PROTOTYPE: |
|
|
2142 | CODE: |
|
|
2143 | RETVAL = map->next; |
|
|
2144 | OUTPUT: RETVAL |
|
|
2145 | |
|
|
2146 | int invoke (mapstruct *map, int event, ...) |
|
|
2147 | CODE: |
|
|
2148 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
|
|
2149 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
2150 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
2151 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
|
|
2152 | OUTPUT: RETVAL |
|
|
2153 | |
1993 | SV *registry (mapstruct *map) |
2154 | SV *registry (mapstruct *map) |
1994 | CODE: |
2155 | CODE: |
1995 | RETVAL = registry_of (map); |
2156 | RETVAL = registry_of (map); |
1996 | OUTPUT: |
2157 | OUTPUT: |
1997 | RETVAL |
2158 | RETVAL |
… | |
… | |
2016 | |
2177 | |
2017 | mapstruct *new (int width, int height) |
2178 | mapstruct *new (int width, int height) |
2018 | PROTOTYPE: |
2179 | PROTOTYPE: |
2019 | CODE: |
2180 | CODE: |
2020 | { |
2181 | { |
2021 | int unused_type; |
2182 | RETVAL = get_empty_map (width, height); |
2022 | RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); |
|
|
2023 | } |
2183 | } |
2024 | OUTPUT: |
2184 | OUTPUT: |
2025 | RETVAL |
2185 | RETVAL |
2026 | |
2186 | |
2027 | void delete_map (mapstruct *map) |
2187 | void delete_map (mapstruct *map) |
… | |
… | |
2042 | XSRETURN_UNDEF; |
2202 | XSRETURN_UNDEF; |
2043 | RETVAL = map->tile_path [dir]; |
2203 | RETVAL = map->tile_path [dir]; |
2044 | OUTPUT: |
2204 | OUTPUT: |
2045 | RETVAL |
2205 | RETVAL |
2046 | |
2206 | |
2047 | mapstruct *cf_map_get_map (char *name) |
2207 | mapstruct *ready_map_name (char *name, int flags = 0) |
2048 | PROTOTYPE: $ |
2208 | PROTOTYPE: $;$ |
2049 | ALIAS: map = 0 |
2209 | ALIAS: |
|
|
2210 | find = 0 |
|
|
2211 | get_map = 1 |
2050 | |
2212 | |
2051 | mapstruct *has_been_loaded (char *name) |
2213 | mapstruct *has_been_loaded (char *name) |
2052 | PROTOTYPE: $ |
2214 | PROTOTYPE: $ |
2053 | |
|
|
2054 | mapstruct *cf_map_get_first () |
|
|
2055 | PROTOTYPE: |
|
|
2056 | ALIAS: first = 0 |
|
|
2057 | |
2215 | |
2058 | # whoever "designed" the plug-in api should have wasted |
2216 | # whoever "designed" the plug-in api should have wasted |
2059 | # his/her time with staying away from the project - would have |
2217 | # his/her time with staying away from the project - would have |
2060 | # saved others a lot of time, without doubt. |
2218 | # saved others a lot of time, without doubt. |
2061 | void set_path (mapstruct *where, char *path) |
2219 | void set_path (mapstruct *where, char *path) |
… | |
… | |
2076 | |
2234 | |
2077 | void set_unique (mapstruct *map, bool unique) |
2235 | void set_unique (mapstruct *map, bool unique) |
2078 | CODE: |
2236 | CODE: |
2079 | map->unique = unique; |
2237 | map->unique = unique; |
2080 | |
2238 | |
|
|
2239 | void |
|
|
2240 | trigger (mapstruct *map, long connection, bool state = true) |
|
|
2241 | CODE: |
|
|
2242 | activate_connection (map, connection, state); |
|
|
2243 | |
|
|
2244 | void |
|
|
2245 | get_connection (mapstruct *map, long connection) |
|
|
2246 | PPCODE: |
|
|
2247 | oblinkpt *obp = get_connection_links (map, connection); |
|
|
2248 | if (obp) |
|
|
2249 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
|
|
2250 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); |
|
|
2251 | |
2081 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2252 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2082 | |
2253 | |
2083 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2254 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2084 | |
2255 | |
2085 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
2256 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
… | |
… | |
2089 | cf_map_normalise (mapstruct *map, int x, int y) |
2260 | cf_map_normalise (mapstruct *map, int x, int y) |
2090 | PPCODE: |
2261 | PPCODE: |
2091 | { |
2262 | { |
2092 | mapstruct *nmap = 0; |
2263 | mapstruct *nmap = 0; |
2093 | I16 nx = 0, ny = 0; |
2264 | I16 nx = 0, ny = 0; |
2094 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2265 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2095 | |
2266 | |
2096 | EXTEND (SP, 4); |
2267 | EXTEND (SP, 4); |
2097 | PUSHs (sv_2mortal (newSViv (flags))); |
2268 | PUSHs (sv_2mortal (newSViv (flags))); |
2098 | |
2269 | |
2099 | if (GIMME_V == G_ARRAY) |
2270 | if (GIMME_V == G_ARRAY) |
… | |
… | |
2111 | { |
2282 | { |
2112 | object *o; |
2283 | object *o; |
2113 | mapstruct *nmap = 0; |
2284 | mapstruct *nmap = 0; |
2114 | I16 nx, ny; |
2285 | I16 nx, ny; |
2115 | |
2286 | |
2116 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2287 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2117 | |
2288 | |
2118 | if (nmap) |
2289 | if (nmap) |
2119 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2290 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2120 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2291 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2121 | } |
2292 | } |
… | |
… | |
2146 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2317 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2147 | } |
2318 | } |
2148 | OUTPUT: |
2319 | OUTPUT: |
2149 | RETVAL |
2320 | RETVAL |
2150 | |
2321 | |
2151 | # "deserialise" perl map data into the map # TODO# compatibility cruft, remove |
|
|
2152 | void |
|
|
2153 | _set_obs (mapstruct *map, SV *sv) |
|
|
2154 | CODE: |
|
|
2155 | { |
|
|
2156 | object *o; |
|
|
2157 | AV *av; |
|
|
2158 | int x, y; |
|
|
2159 | AV *obs = (AV *)SvRV (sv); |
|
|
2160 | |
2322 | |
2161 | for (y = 0; y < MAP_HEIGHT (map); y++) |
2323 | MODULE = cf PACKAGE = cf::arch |
2162 | for (x = 0; x < MAP_WIDTH (map); x++) |
|
|
2163 | { |
|
|
2164 | sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1); |
|
|
2165 | |
2324 | |
2166 | if (!SvROK (sv)) |
2325 | archetype *first() |
2167 | continue; |
|
|
2168 | |
|
|
2169 | av = (AV *)SvRV (sv); |
|
|
2170 | |
|
|
2171 | for (o = GET_MAP_OB (map, x, y); o; o = o->above) |
|
|
2172 | { |
|
|
2173 | sv = av_shift (av); |
|
|
2174 | |
|
|
2175 | if (SvROK (sv)) |
|
|
2176 | { |
|
|
2177 | sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0); |
|
|
2178 | SVptr_cache_set (o, sv); |
|
|
2179 | } |
|
|
2180 | } |
|
|
2181 | } |
|
|
2182 | } |
|
|
2183 | |
|
|
2184 | |
|
|
2185 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
|
|
2186 | |
|
|
2187 | archetype *cf_archetype_get_first() |
|
|
2188 | PROTOTYPE: |
2326 | PROTOTYPE: |
2189 | ALIAS: first = 0 |
2327 | CODE: |
|
|
2328 | RETVAL = first_archetype; |
|
|
2329 | OUTPUT: RETVAL |
2190 | |
2330 | |
2191 | archetype *cf_archetype_get_next (archetype *arch) |
2331 | archetype *next (archetype *arch) |
2192 | ALIAS: next = 0 |
2332 | CODE: |
|
|
2333 | RETVAL = arch->next; |
|
|
2334 | OUTPUT: RETVAL |
2193 | |
2335 | |
2194 | archetype *cf_archetype_get_head (archetype *arch) |
2336 | archetype *head (archetype *arch) |
2195 | ALIAS: head = 0 |
2337 | CODE: |
|
|
2338 | RETVAL = arch->head; |
|
|
2339 | OUTPUT: RETVAL |
2196 | |
2340 | |
2197 | archetype *cf_archetype_get_more (archetype *arch) |
2341 | archetype *more (archetype *arch) |
2198 | ALIAS: more = 0 |
2342 | CODE: |
|
|
2343 | RETVAL = arch->more; |
|
|
2344 | OUTPUT: RETVAL |
2199 | |
2345 | |
2200 | const char *cf_archetype_get_name (archetype *arch) |
2346 | const char *name (archetype *arch) |
2201 | ALIAS: name = 0 |
2347 | CODE: |
|
|
2348 | RETVAL = arch->name; |
|
|
2349 | OUTPUT: RETVAL |
2202 | |
2350 | |
2203 | object *cf_archetype_get_clone (archetype *arch) |
2351 | object *clone (archetype *arch) |
2204 | ALIAS: clone = 0 |
2352 | CODE: |
|
|
2353 | RETVAL = &arch->clone; |
|
|
2354 | OUTPUT: RETVAL |
2205 | |
2355 | |
2206 | MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ |
2356 | MODULE = cf PACKAGE = cf::party |
2207 | |
2357 | |
2208 | partylist *cf_party_get_first () |
2358 | partylist *first () |
2209 | PROTOTYPE: |
2359 | PROTOTYPE: |
2210 | ALIAS: first = 0 |
2360 | CODE: |
|
|
2361 | RETVAL = get_firstparty (); |
|
|
2362 | OUTPUT: RETVAL |
2211 | |
2363 | |
2212 | partylist *cf_party_get_next (partylist *party) |
2364 | partylist *next (partylist *party) |
2213 | ALIAS: next = 0 |
2365 | CODE: |
|
|
2366 | RETVAL = party->next; |
|
|
2367 | OUTPUT: RETVAL |
2214 | |
2368 | |
2215 | const char *cf_party_get_name (partylist *party) |
2369 | const char *name (partylist *party) |
|
|
2370 | CODE: |
|
|
2371 | RETVAL = party->partyname; |
|
|
2372 | OUTPUT: RETVAL |
2216 | |
2373 | |
2217 | const char *cf_party_get_password (partylist *party) |
2374 | const char *password (partylist *party) |
2218 | ALIAS: password = 0 |
2375 | CODE: |
|
|
2376 | RETVAL = party->passwd; |
|
|
2377 | OUTPUT: RETVAL |
2219 | |
2378 | |
2220 | player *cf_party_get_first_player (partylist *party) |
2379 | MODULE = cf PACKAGE = cf::region |
2221 | ALIAS: first_player = 0 |
|
|
2222 | |
2380 | |
2223 | player *cf_party_get_next_player (partylist *party, player *op) |
2381 | region *first () |
2224 | ALIAS: next_player = 0 |
|
|
2225 | |
|
|
2226 | |
|
|
2227 | MODULE = cf PACKAGE = cf::region PREFIX = cf_region_ |
|
|
2228 | |
|
|
2229 | region *cf_region_get_first () |
|
|
2230 | PROTOTYPE: |
2382 | PROTOTYPE: |
2231 | ALIAS: first = 0 |
2383 | CODE: |
|
|
2384 | RETVAL = first_region; |
|
|
2385 | OUTPUT: RETVAL |
2232 | |
2386 | |
|
|
2387 | region *next (region *reg) |
|
|
2388 | CODE: |
|
|
2389 | RETVAL = reg->next; |
|
|
2390 | OUTPUT: RETVAL |
|
|
2391 | |
|
|
2392 | const char *name (region *reg) |
|
|
2393 | CODE: |
|
|
2394 | RETVAL = reg->name; |
|
|
2395 | OUTPUT: RETVAL |
|
|
2396 | |
|
|
2397 | region *parent (region *reg) |
|
|
2398 | CODE: |
|
|
2399 | RETVAL = reg->parent; |
|
|
2400 | OUTPUT: RETVAL |
|
|
2401 | |
2233 | const char *cf_region_get_name (region *reg) |
2402 | const char *longname (region *reg) |
2234 | ALIAS: name = 0 |
2403 | CODE: |
|
|
2404 | RETVAL = reg->longname; |
|
|
2405 | OUTPUT: RETVAL |
2235 | |
2406 | |
2236 | region *cf_region_get_next (region *reg) |
2407 | const char *msg (region *reg) |
2237 | ALIAS: next = 0 |
2408 | CODE: |
|
|
2409 | RETVAL = reg->msg; |
|
|
2410 | OUTPUT: RETVAL |
2238 | |
2411 | |
2239 | region *cf_region_get_parent (region *reg) |
2412 | MODULE = cf PACKAGE = cf::living |
2240 | ALIAS: parent = 0 |
|
|
2241 | |
|
|
2242 | const char *cf_region_get_longname (region *reg) |
|
|
2243 | ALIAS: longname = 0 |
|
|
2244 | |
|
|
2245 | const char *cf_region_get_message (region *reg) |
|
|
2246 | ALIAS: message = 0 |
|
|
2247 | |
|
|
2248 | |
|
|
2249 | MODULE = cf PACKAGE = cf::living PREFIX = cf_living_ |
|
|
2250 | |
2413 | |
2251 | val64 |
2414 | val64 |
2252 | exp (living *liv, val64 new_val = 0) |
2415 | exp (living *liv, val64 new_val = 0) |
2253 | PROTOTYPE: $;$ |
2416 | PROTOTYPE: $;$ |
2254 | ALIAS: |
2417 | ALIAS: |