… | |
… | |
108 | |
108 | |
109 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
109 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
110 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
110 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
111 | } |
111 | } |
112 | |
112 | |
113 | template<class extendable> |
113 | template<class attachable> |
114 | SV * |
114 | SV * |
115 | newSVextendable (extendable *obj, const char *klass) |
115 | newSVattachable (attachable *obj, const char *klass) |
116 | { |
116 | { |
117 | if (!obj) |
117 | if (!obj) |
118 | return &PL_sv_undef; |
118 | return &PL_sv_undef; |
119 | |
119 | |
120 | if (!obj->self) |
120 | if (!obj->self) |
… | |
… | |
227 | break; |
227 | break; |
228 | |
228 | |
229 | case DT_OBJECT: |
229 | case DT_OBJECT: |
230 | { |
230 | { |
231 | object *obj = va_arg (ap, object *); |
231 | object *obj = va_arg (ap, object *); |
232 | sv = newSVextendable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
232 | sv = newSVattachable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
233 | } |
233 | } |
234 | break; |
234 | break; |
235 | |
235 | |
236 | case DT_MAP: |
236 | case DT_MAP: |
237 | // va_arg (object *) when void * is passed is an XSI extension |
237 | // va_arg (object *) when void * is passed is an XSI extension |
238 | sv = newSVextendable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
238 | sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
239 | break; |
239 | break; |
240 | |
240 | |
241 | case DT_PLAYER: |
241 | case DT_PLAYER: |
242 | sv = newSVextendable (va_arg (ap, player *), "cf::player::wrap"); |
242 | sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap"); |
243 | break; |
243 | break; |
244 | |
244 | |
245 | case DT_ARCH: |
245 | case DT_ARCH: |
246 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
246 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
247 | break; |
247 | break; |
… | |
… | |
304 | } |
304 | } |
305 | |
305 | |
306 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
306 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
307 | |
307 | |
308 | SV * |
308 | SV * |
309 | registry_of (extendable_base *ext) |
309 | registry_of (attachable_base *ext) |
310 | { |
310 | { |
311 | if (!ext->cb) |
311 | if (!ext->cb) |
312 | ext->cb = newAV (); |
312 | ext->cb = newAV (); |
313 | |
313 | |
314 | return newRV_inc ((SV *)ext->cb); |
314 | return newRV_inc ((SV *)ext->cb); |
315 | } |
315 | } |
316 | |
316 | |
317 | void extendable_base::clear () |
317 | void attachable_base::clear () |
318 | { |
318 | { |
319 | //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D |
319 | //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D |
320 | |
320 | |
321 | if (self) SvREFCNT_dec (self); |
321 | if (self) SvREFCNT_dec (self); |
322 | if (cb) SvREFCNT_dec (cb); |
322 | if (cb) SvREFCNT_dec (cb); |
… | |
… | |
326 | self = 0; |
326 | self = 0; |
327 | cb = 0; |
327 | cb = 0; |
328 | attach = 0; |
328 | attach = 0; |
329 | } |
329 | } |
330 | |
330 | |
331 | void extendable_base::optimise () |
331 | void attachable_base::optimise () |
332 | { |
332 | { |
333 | if (!self) |
333 | if (!self) |
334 | return; |
334 | return; |
335 | |
335 | |
336 | HV *hv = (HV *)SvRV ((SV *)self); |
336 | HV *hv = (HV *)SvRV ((SV *)self); |
… | |
… | |
356 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
356 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
357 | PUTBACK; |
357 | PUTBACK; |
358 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
358 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
359 | FREETMPS; |
359 | FREETMPS; |
360 | LEAVE; |
360 | LEAVE; |
|
|
361 | |
|
|
362 | INVOKE_OBJECT (INSTANTIATE, this); |
361 | } |
363 | } |
362 | |
364 | |
363 | ///////////////////////////////////////////////////////////////////////////// |
365 | ///////////////////////////////////////////////////////////////////////////// |
|
|
366 | |
|
|
367 | void reattach (data_type type, void *obj) |
|
|
368 | { |
|
|
369 | dSP; |
|
|
370 | ENTER; |
|
|
371 | SAVETMPS; |
|
|
372 | PUSHMARK (SP); |
|
|
373 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
|
|
374 | PUTBACK; |
|
|
375 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
|
|
376 | FREETMPS; |
|
|
377 | LEAVE; |
|
|
378 | |
|
|
379 | switch (type) |
|
|
380 | { |
|
|
381 | case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; |
|
|
382 | case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; |
|
|
383 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
|
|
384 | } |
|
|
385 | } |
|
|
386 | |
|
|
387 | template<class subclass> |
|
|
388 | void reattach (attachable<subclass> *obj) |
|
|
389 | { |
|
|
390 | obj->optimise (); |
|
|
391 | |
|
|
392 | if (obj->self) |
|
|
393 | reattach (subclass::get_dt (), (subclass *)obj); |
|
|
394 | } |
364 | |
395 | |
365 | object_freezer::object_freezer (const char *filename) |
396 | object_freezer::object_freezer (const char *filename) |
366 | : filename (filename) |
397 | : filename (filename) |
367 | { |
398 | { |
368 | av = (AV *)newAV (); |
399 | av = (AV *)newAV (); |
369 | idx = 0; |
|
|
370 | av_extend ((AV *)av, 1024); |
|
|
371 | } |
400 | } |
372 | |
401 | |
373 | object_freezer::~object_freezer () |
402 | object_freezer::~object_freezer () |
374 | { |
403 | { |
375 | dSP; |
404 | dSP; |
… | |
… | |
382 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
411 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
383 | FREETMPS; |
412 | FREETMPS; |
384 | LEAVE; |
413 | LEAVE; |
385 | } |
414 | } |
386 | |
415 | |
387 | void object_freezer::put (extendable_base *ext) |
416 | void object_freezer::put (FILE *fp, attachable_base *ext) |
388 | { |
417 | { |
389 | ext->optimise (); |
418 | ext->optimise (); |
390 | |
419 | |
391 | if (ext->self) |
420 | if (ext->self) |
|
|
421 | { |
|
|
422 | int idx = AvFILLp ((AV *)av) + 1; |
392 | av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); |
423 | av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); |
393 | |
424 | fprintf (fp, "oid %d\n", idx); |
394 | ++idx; |
425 | } |
395 | } |
426 | } |
396 | |
427 | |
397 | object_thawer::object_thawer (const char *filename) |
428 | object_thawer::object_thawer (const char *filename) |
398 | { |
429 | { |
399 | av = 0; |
430 | av = 0; |
400 | idx = 0; |
|
|
401 | |
431 | |
402 | if (!filename) |
432 | if (!filename) |
403 | return; |
433 | return; |
404 | |
434 | |
405 | dSP; |
435 | dSP; |
… | |
… | |
419 | |
449 | |
420 | FREETMPS; |
450 | FREETMPS; |
421 | LEAVE; |
451 | LEAVE; |
422 | } |
452 | } |
423 | |
453 | |
424 | void object_thawer::get (data_type type, void *obj, extendable_base *ext) |
454 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
425 | { |
455 | { |
426 | if (!av) |
456 | if (!av || oid < 0) // this is actually an error of sorts |
427 | return; |
457 | return; |
428 | |
458 | |
429 | // we have to "re-instantiate"/reattach to an object, so nuke ext->attach |
459 | // we have to "re-instantiate"/reattach to an object, so nuke ext->attach |
430 | ext->clear (); |
460 | ext->clear (); |
431 | |
461 | |
432 | SV **svp = av_fetch ((AV *)av, idx, 0); |
462 | SV **svp = av_fetch ((AV *)av, oid, 0); |
433 | |
463 | |
434 | ++idx; |
|
|
435 | |
|
|
436 | if (!svp) |
|
|
437 | return; |
|
|
438 | |
|
|
439 | if (SvROK (*svp)) |
464 | if (!svp || !SvROK (*svp)) |
440 | { |
465 | { |
441 | ext->self = SvREFCNT_inc (*svp); |
466 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
442 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
467 | return; |
443 | |
|
|
444 | dSP; |
|
|
445 | ENTER; |
|
|
446 | SAVETMPS; |
|
|
447 | PUSHMARK (SP); |
|
|
448 | EXTEND (SP, 1); |
|
|
449 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
|
|
450 | PUTBACK; |
|
|
451 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
|
|
452 | FREETMPS; |
|
|
453 | LEAVE; |
|
|
454 | |
|
|
455 | if (ext->cb && type == DT_OBJECT) |
|
|
456 | INVOKE_OBJECT (REATTACH, (object *)obj); |
|
|
457 | } |
468 | } |
|
|
469 | |
|
|
470 | ext->self = *svp; *svp = &PL_sv_undef; |
|
|
471 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
|
|
472 | |
|
|
473 | reattach (type, obj); |
458 | } |
474 | } |
459 | |
475 | |
460 | object_thawer::~object_thawer () |
476 | object_thawer::~object_thawer () |
461 | { |
477 | { |
462 | if (av) |
478 | if (av) |
… | |
… | |
466 | ///////////////////////////////////////////////////////////////////////////// |
482 | ///////////////////////////////////////////////////////////////////////////// |
467 | |
483 | |
468 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
484 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
469 | { |
485 | { |
470 | gethook = gethooksptr; |
486 | gethook = gethooksptr; |
471 | printf (PLUGIN_VERSION " init\n"); |
|
|
472 | |
487 | |
473 | return 0; |
488 | return 0; |
474 | } |
489 | } |
475 | |
490 | |
476 | static CommArray_s rtn_cmd; |
491 | static CommArray_s rtn_cmd; |
… | |
… | |
557 | extern "C" int cfperl_postInitPlugin () |
572 | extern "C" int cfperl_postInitPlugin () |
558 | { |
573 | { |
559 | int hooktype = 1; |
574 | int hooktype = 1; |
560 | int rtype = 0; |
575 | int rtype = 0; |
561 | |
576 | |
562 | printf (PLUGIN_VERSION " post init\n"); |
|
|
563 | |
|
|
564 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
577 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
565 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
578 | 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"); |
579 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
567 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
580 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
568 | |
581 | |
… | |
… | |
621 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
634 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
622 | # define def(type,name) KLASS_ ## type, |
635 | # define def(type,name) KLASS_ ## type, |
623 | # include "eventinc.h" |
636 | # include "eventinc.h" |
624 | # undef def |
637 | # undef def |
625 | }; |
638 | }; |
|
|
639 | |
|
|
640 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
626 | |
641 | |
627 | static void |
642 | static void |
628 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
643 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
629 | { |
644 | { |
630 | // event must be in array |
645 | // event must be in array |
… | |
… | |
673 | // 2a. per-type callback |
688 | // 2a. per-type callback |
674 | // 4. global callbacks |
689 | // 4. global callbacks |
675 | |
690 | |
676 | gather_callbacks (callbacks, cb_global, event); |
691 | gather_callbacks (callbacks, cb_global, event); |
677 | |
692 | |
678 | switch (klass_of [event]) |
693 | switch (KLASS_OF (event)) |
679 | { |
694 | { |
680 | case KLASS_GLOBAL: |
695 | case KLASS_GLOBAL: |
681 | break; |
696 | break; |
682 | |
697 | |
683 | case KLASS_OBJECT: |
698 | case KLASS_OBJECT: |
… | |
… | |
686 | op = va_arg (ap, object *); |
701 | op = va_arg (ap, object *); |
687 | |
702 | |
688 | if (op->cb) |
703 | if (op->cb) |
689 | gather_callbacks (callbacks, (AV *)op->cb, event); |
704 | gather_callbacks (callbacks, (AV *)op->cb, event); |
690 | |
705 | |
|
|
706 | if (op->type) |
|
|
707 | { |
|
|
708 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
|
|
709 | { |
|
|
710 | SV *registry = AvARRAY (cb_type)[op->type + op->subtype * NUM_SUBTYPES]; |
|
|
711 | |
|
|
712 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
713 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
714 | } |
|
|
715 | |
|
|
716 | if (op->type <= AvFILLp (cb_type)) |
|
|
717 | { |
|
|
718 | SV *registry = AvARRAY (cb_type)[op->type]; |
|
|
719 | |
|
|
720 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
721 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
722 | } |
|
|
723 | } |
|
|
724 | |
691 | gather_callbacks (callbacks, cb_object, event); |
725 | 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 | |
726 | |
701 | break; |
727 | break; |
702 | |
728 | |
703 | case KLASS_PLAYER: |
729 | case KLASS_PLAYER: |
704 | dt = (data_type) va_arg (ap, int); |
730 | dt = (data_type) va_arg (ap, int); |
… | |
… | |
738 | EXTEND (SP, 3); |
764 | EXTEND (SP, 3); |
739 | |
765 | |
740 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
766 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
741 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
767 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
742 | |
768 | |
743 | switch (klass_of [event]) |
769 | switch (KLASS_OF (event)) |
744 | { |
770 | { |
745 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
771 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
746 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
772 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
747 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
773 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
748 | } |
774 | } |
… | |
… | |
938 | const_iv (BUILDER) |
964 | const_iv (BUILDER) |
939 | const_iv (MATERIAL) |
965 | const_iv (MATERIAL) |
940 | const_iv (ITEM_TRANSFORMER) |
966 | const_iv (ITEM_TRANSFORMER) |
941 | const_iv (QUEST) |
967 | const_iv (QUEST) |
942 | |
968 | |
|
|
969 | const_iv (NUM_SUBTYPES) |
|
|
970 | |
943 | const_iv (ST_BD_BUILD) |
971 | const_iv (ST_BD_BUILD) |
944 | const_iv (ST_BD_REMOVE) |
972 | const_iv (ST_BD_REMOVE) |
945 | |
973 | |
946 | const_iv (ST_MAT_FLOOR) |
974 | const_iv (ST_MAT_FLOOR) |
947 | const_iv (ST_MAT_WALL) |
975 | const_iv (ST_MAT_WALL) |
… | |
… | |
1288 | |
1316 | |
1289 | const_iv (KLASS_GLOBAL) |
1317 | const_iv (KLASS_GLOBAL) |
1290 | const_iv (KLASS_OBJECT) |
1318 | const_iv (KLASS_OBJECT) |
1291 | const_iv (KLASS_PLAYER) |
1319 | const_iv (KLASS_PLAYER) |
1292 | const_iv (KLASS_MAP) |
1320 | const_iv (KLASS_MAP) |
1293 | |
|
|
1294 | const_iv (EVENT_OBJECT_INSTANTIATE) |
|
|
1295 | }; |
1321 | }; |
1296 | |
1322 | |
1297 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1323 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1298 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1324 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1299 | |
1325 | |
1300 | static const struct { |
1326 | static const struct { |
1301 | const char *name; |
1327 | const char *name; |
|
|
1328 | int skip; |
1302 | IV klass; |
1329 | IV klass; |
1303 | IV iv; |
1330 | IV iv; |
1304 | } *eiv, event_iv[] = { |
1331 | } *eiv, event_iv[] = { |
1305 | # define def(klass,name) { # name, (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1332 | # define def(klass,name) { "EVENT_" # klass "_" # name, sizeof ("EVENT_" # klass), (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1306 | # include "eventinc.h" |
1333 | # include "eventinc.h" |
1307 | # undef def |
1334 | # undef def |
1308 | }; |
1335 | }; |
1309 | |
1336 | |
1310 | AV *av = get_av ("cf::EVENT", 1); |
1337 | AV *av = get_av ("cf::EVENT", 1); |
1311 | |
1338 | |
1312 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1339 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1313 | { |
1340 | { |
1314 | AV *event = newAV (); |
1341 | AV *event = newAV (); |
1315 | av_push (event, newSVpv ((char *)eiv->name, 0)); |
1342 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1316 | av_push (event, newSViv (eiv->klass)); |
1343 | av_push (event, newSViv (eiv->klass)); |
1317 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1344 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
|
|
1345 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1318 | } |
1346 | } |
1319 | |
1347 | |
1320 | static const struct { |
1348 | static const struct { |
1321 | int dtype; |
1349 | int dtype; |
1322 | const char *name; |
1350 | const char *name; |
… | |
… | |
1451 | { |
1479 | { |
1452 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1480 | 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); |
1481 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1454 | } |
1482 | } |
1455 | |
1483 | |
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); |
1484 | //I_EVENT_API (PACKAGE); |
|
|
1485 | } |
|
|
1486 | |
|
|
1487 | void _reload_1 () |
|
|
1488 | CODE: |
|
|
1489 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
|
|
1490 | cb_object = get_av ("cf::CB_OBJECT", 1); |
|
|
1491 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1492 | cb_type = get_av ("cf::CB_TYPE" , 1); |
|
|
1493 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1494 | |
|
|
1495 | void _reload_2 () |
|
|
1496 | CODE: |
|
|
1497 | { |
|
|
1498 | // reattach to all attachable objects in the game. |
|
|
1499 | for (player *pl = first_player; pl; pl = pl->next) |
|
|
1500 | reattach (pl); |
|
|
1501 | |
|
|
1502 | for (mapstruct *map = first_map; map; map = map->next) |
|
|
1503 | reattach (map); |
|
|
1504 | |
|
|
1505 | for (object *op = objects; op; op = op->next) |
|
|
1506 | reattach (op); |
1463 | } |
1507 | } |
1464 | |
1508 | |
1465 | NV floor (NV x) |
1509 | NV floor (NV x) |
1466 | |
1510 | |
1467 | NV ceil (NV x) |
1511 | NV ceil (NV x) |
… | |
… | |
1513 | |
1557 | |
1514 | int random_roll(int min, int max, object *op, int goodbad); |
1558 | int random_roll(int min, int max, object *op, int goodbad); |
1515 | |
1559 | |
1516 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1560 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1517 | |
1561 | |
1518 | int invoke (int event, SV *arg1, ...) |
1562 | int invoke (int event, ...) |
1519 | CODE: |
1563 | CODE: |
1520 | { |
1564 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1521 | // parse first arg and call invoke_object etc as seen fit |
1565 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 1; i < items; i++) av_push (av, ST (i)); |
1522 | //TODO |
1566 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
1523 | //cfperl_invoke (event, |
1567 | OUTPUT: RETVAL |
1524 | } |
|
|
1525 | |
1568 | |
1526 | int |
1569 | int |
1527 | exp_to_level (val64 exp) |
1570 | exp_to_level (val64 exp) |
1528 | CODE: |
1571 | CODE: |
1529 | { |
1572 | { |
… | |
… | |
1561 | else |
1604 | else |
1562 | XSRETURN_UNDEF; |
1605 | XSRETURN_UNDEF; |
1563 | OUTPUT: RETVAL |
1606 | OUTPUT: RETVAL |
1564 | |
1607 | |
1565 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1608 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
|
|
1609 | |
|
|
1610 | int invoke (object *op, int event, ...) |
|
|
1611 | CODE: |
|
|
1612 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
|
|
1613 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); |
|
|
1614 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
|
|
1615 | OUTPUT: RETVAL |
|
|
1616 | |
|
|
1617 | SV *registry (object *op) |
|
|
1618 | CODE: |
|
|
1619 | RETVAL = registry_of (op); |
|
|
1620 | OUTPUT: |
|
|
1621 | RETVAL |
1566 | |
1622 | |
1567 | SV * |
1623 | SV * |
1568 | get_property (object *obj, int type, int idx) |
1624 | get_property (object *obj, int type, int idx) |
1569 | CODE: |
1625 | CODE: |
1570 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
1626 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
… | |
… | |
1768 | { |
1824 | { |
1769 | int unused_type; |
1825 | int unused_type; |
1770 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1826 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1771 | } |
1827 | } |
1772 | |
1828 | |
1773 | SV *registry (object *op) |
|
|
1774 | CODE: |
|
|
1775 | RETVAL = registry_of (op); |
|
|
1776 | OUTPUT: |
|
|
1777 | RETVAL |
|
|
1778 | |
|
|
1779 | # syntatic sugar for easier use in event callbacks. |
1829 | # syntatic sugar for easier use in event callbacks. |
1780 | const char *options (object *op) |
1830 | const char *options (object *op) |
1781 | CODE: |
1831 | CODE: |
1782 | RETVAL = op->name; |
1832 | RETVAL = op->name; |
1783 | OUTPUT: |
1833 | OUTPUT: |
… | |
… | |
1854 | void cf_player_set_party (object *op, partylist *party) |
1904 | void cf_player_set_party (object *op, partylist *party) |
1855 | |
1905 | |
1856 | void kill_player (object *op) |
1906 | void kill_player (object *op) |
1857 | |
1907 | |
1858 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1908 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
|
|
1909 | |
|
|
1910 | int invoke (player *pl, int event, ...) |
|
|
1911 | CODE: |
|
|
1912 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
|
|
1913 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); |
|
|
1914 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
|
|
1915 | OUTPUT: RETVAL |
1859 | |
1916 | |
1860 | SV *registry (player *pl) |
1917 | SV *registry (player *pl) |
1861 | CODE: |
1918 | CODE: |
1862 | RETVAL = registry_of (pl); |
1919 | RETVAL = registry_of (pl); |
1863 | OUTPUT: |
1920 | OUTPUT: |
… | |
… | |
1987 | RETVAL = &pl->last_stats; |
2044 | RETVAL = &pl->last_stats; |
1988 | OUTPUT: RETVAL |
2045 | OUTPUT: RETVAL |
1989 | |
2046 | |
1990 | |
2047 | |
1991 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2048 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
|
|
2049 | |
|
|
2050 | int invoke (mapstruct *map, int event, ...) |
|
|
2051 | CODE: |
|
|
2052 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
|
|
2053 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); |
|
|
2054 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
|
|
2055 | OUTPUT: |
|
|
2056 | RETVAL |
1992 | |
2057 | |
1993 | SV *registry (mapstruct *map) |
2058 | SV *registry (mapstruct *map) |
1994 | CODE: |
2059 | CODE: |
1995 | RETVAL = registry_of (map); |
2060 | RETVAL = registry_of (map); |
1996 | OUTPUT: |
2061 | OUTPUT: |