… | |
… | |
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; |
… | |
… | |
61 | #define newSVval64 newSVnv |
59 | #define newSVval64 newSVnv |
62 | #define SvVAL64 SvNV |
60 | #define SvVAL64 SvNV |
63 | |
61 | |
64 | static f_plug_api gethook = cfapi_get_hooks; |
62 | static f_plug_api gethook = cfapi_get_hooks; |
65 | static f_plug_api object_set_property = cfapi_object_set_property; |
63 | static f_plug_api object_set_property = cfapi_object_set_property; |
66 | static f_plug_api map_get_map = cfapi_map_get_map; |
|
|
67 | static f_plug_api object_insert = cfapi_object_insert; |
64 | static f_plug_api object_insert = cfapi_object_insert; |
|
|
65 | |
|
|
66 | static bool perl_booted; |
68 | |
67 | |
69 | /* 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 */ |
70 | typedef struct |
69 | typedef struct |
71 | { |
70 | { |
72 | object* who; |
71 | object* who; |
… | |
… | |
117 | return &PL_sv_undef; |
116 | return &PL_sv_undef; |
118 | |
117 | |
119 | if (!obj->self) |
118 | if (!obj->self) |
120 | obj->self = newSVptr (obj, klass); |
119 | obj->self = newSVptr (obj, klass); |
121 | |
120 | |
122 | return newSVsv (static_cast<SV *>(obj->self)); |
121 | return newSVsv (obj->self); |
123 | } |
122 | } |
124 | |
123 | |
125 | static void |
124 | static void |
126 | SVptr_cache_set (void *ptr, SV *sv) |
125 | SVptr_cache_set (void *ptr, SV *sv) |
127 | { |
126 | { |
… | |
… | |
316 | void attachable_base::clear () |
315 | void attachable_base::clear () |
317 | { |
316 | { |
318 | if (self) |
317 | if (self) |
319 | { |
318 | { |
320 | if (cb) |
319 | if (cb) |
321 | if (SvROK (*av_fetch ((AV *)cb, EVENT_OBJECT_DESTROY, 1))) |
320 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
322 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
321 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
323 | else if (SvROK (*av_fetch ((AV *)cb, EVENT_MAP_DESTROY, 1))) |
322 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
324 | INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); |
323 | INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); |
325 | |
324 | |
326 | // disconnect Perl from C, to avoid crashes |
325 | // disconnect Perl from C, to avoid crashes |
327 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
326 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
328 | |
327 | |
… | |
… | |
425 | this->filename = (SV *)newSVpv (filename, 0); |
424 | this->filename = (SV *)newSVpv (filename, 0); |
426 | |
425 | |
427 | char filename2 [4096]; |
426 | char filename2 [4096]; |
428 | snprintf (filename2, 4096, "%s~", filename); |
427 | snprintf (filename2, 4096, "%s~", filename); |
429 | |
428 | |
430 | fp = fopen (filename2, "w"); |
|
|
431 | |
|
|
432 | if (!fp) |
|
|
433 | LOG (llevError, "cannot open file '%s' for writing: %s\n", filename2, strerror (errno)); |
|
|
434 | |
|
|
435 | av = (AV *)newAV (); |
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 |
436 | } |
433 | } |
437 | |
434 | |
438 | object_freezer::~object_freezer () |
435 | object_freezer::~object_freezer () |
439 | { |
436 | { |
440 | if (fp) |
|
|
441 | { |
|
|
442 | fclose (fp); |
|
|
443 | |
|
|
444 | dSP; |
437 | dSP; |
445 | ENTER; |
438 | ENTER; |
446 | SAVETMPS; |
439 | SAVETMPS; |
447 | PUSHMARK (SP); |
440 | PUSHMARK (SP); |
448 | XPUSHs (sv_2mortal ((SV *)filename)); |
441 | XPUSHs (sv_2mortal ((SV *)filename)); |
|
|
442 | XPUSHs (sv_2mortal (newRV_noinc (text))); |
449 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
443 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
450 | PUTBACK; |
444 | PUTBACK; |
451 | 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); |
452 | FREETMPS; |
446 | FREETMPS; |
453 | LEAVE; |
447 | LEAVE; |
454 | } |
|
|
455 | else |
|
|
456 | SvREFCNT_dec ((SV *)filename); |
|
|
457 | } |
448 | } |
458 | |
449 | |
459 | void object_freezer::put (attachable_base *ext) |
450 | void object_freezer::put (attachable_base *ext) |
460 | { |
451 | { |
461 | ext->optimise (); |
452 | ext->optimise (); |
462 | |
453 | |
463 | if (ext->self) |
454 | if (ext->self) |
464 | { |
455 | { |
465 | int idx = AvFILLp ((AV *)av) + 1; |
456 | int idx = AvFILLp ((AV *)av) + 1; |
466 | av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); |
457 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
467 | fprintf (fp, "oid %d\n", idx); |
458 | |
|
|
459 | sv_catpvf (text, "oid %d\n", idx); |
468 | } |
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)); |
469 | } |
475 | } |
470 | |
476 | |
471 | object_thawer::object_thawer (const char *filename) |
477 | object_thawer::object_thawer (const char *filename) |
472 | { |
478 | { |
473 | av = 0; |
479 | av = 0; |
… | |
… | |
481 | { |
487 | { |
482 | LOG (llevError, "object_thawer: unable to open '%s': %s.\n", filename, strerror (errno)); |
488 | LOG (llevError, "object_thawer: unable to open '%s': %s.\n", filename, strerror (errno)); |
483 | return; |
489 | return; |
484 | } |
490 | } |
485 | |
491 | |
486 | if (perl) |
492 | if (perl_booted) |
487 | { |
493 | { |
488 | dSP; |
494 | dSP; |
489 | ENTER; |
495 | ENTER; |
490 | SAVETMPS; |
496 | SAVETMPS; |
491 | PUSHMARK (SP); |
497 | PUSHMARK (SP); |
… | |
… | |
495 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
501 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
496 | { |
502 | { |
497 | SPAGAIN; |
503 | SPAGAIN; |
498 | SV *sv = POPs; |
504 | SV *sv = POPs; |
499 | if (SvROK (sv)) |
505 | if (SvROK (sv)) |
500 | av = SvREFCNT_inc (SvRV (sv)); |
506 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
501 | } |
507 | } |
502 | |
508 | |
503 | FREETMPS; |
509 | FREETMPS; |
504 | LEAVE; |
510 | LEAVE; |
505 | } |
511 | } |
… | |
… | |
520 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
526 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
521 | return; |
527 | return; |
522 | } |
528 | } |
523 | |
529 | |
524 | ext->self = *svp; *svp = &PL_sv_undef; |
530 | ext->self = *svp; *svp = &PL_sv_undef; |
525 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
531 | sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
526 | |
532 | |
527 | reattach (type, obj); |
533 | reattach (type, obj); |
528 | } |
534 | } |
529 | |
535 | |
530 | object_thawer::~object_thawer () |
536 | object_thawer::~object_thawer () |
… | |
… | |
637 | } |
643 | } |
638 | |
644 | |
639 | void |
645 | void |
640 | cfperl_init () |
646 | cfperl_init () |
641 | { |
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 | |
642 | char *argv[] = { |
654 | char *argv[] = { |
643 | "", |
655 | "", |
644 | "-e" |
656 | "-e" |
645 | "BEGIN {" |
|
|
646 | " cf->bootstrap;" |
657 | "cf->bootstrap;" |
647 | " unshift @INC, cf::datadir ();" |
658 | "unshift @INC, cf::datadir ();" |
648 | "}" |
|
|
649 | "" |
|
|
650 | "use cf;" |
|
|
651 | }; |
659 | }; |
652 | |
|
|
653 | perl = perl_alloc (); |
|
|
654 | perl_construct (perl); |
|
|
655 | |
|
|
656 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
657 | |
660 | |
658 | 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)) |
659 | { |
662 | { |
660 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
663 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
661 | |
|
|
662 | exit (EXIT_FAILURE); |
664 | exit (EXIT_FAILURE); |
663 | //perl_destruct (perl); |
|
|
664 | //perl_free (perl); |
|
|
665 | //perl = 0; |
|
|
666 | //return; |
|
|
667 | } |
665 | } |
668 | |
666 | |
669 | 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); |
670 | } |
675 | } |
671 | |
676 | |
672 | void cfperl_main () |
677 | void cfperl_main () |
673 | { |
678 | { |
674 | dSP; |
679 | dSP; |
… | |
… | |
746 | dt = (data_type) va_arg (ap, int); |
751 | dt = (data_type) va_arg (ap, int); |
747 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
752 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
748 | op = va_arg (ap, object *); |
753 | op = va_arg (ap, object *); |
749 | |
754 | |
750 | if (op->cb) |
755 | if (op->cb) |
751 | gather_callbacks (callbacks, (AV *)op->cb, event); |
756 | gather_callbacks (callbacks, op->cb, event); |
752 | |
757 | |
753 | if (op->type) |
758 | if (op->type) |
754 | { |
759 | { |
755 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
760 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
756 | { |
761 | { |
… | |
… | |
777 | dt = (data_type) va_arg (ap, int); |
782 | dt = (data_type) va_arg (ap, int); |
778 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
783 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
779 | pl = va_arg (ap, player *); |
784 | pl = va_arg (ap, player *); |
780 | |
785 | |
781 | if (pl->cb) |
786 | if (pl->cb) |
782 | gather_callbacks (callbacks, (AV *)pl->cb, event); |
787 | gather_callbacks (callbacks, pl->cb, event); |
783 | |
788 | |
784 | gather_callbacks (callbacks, cb_player, event); |
789 | gather_callbacks (callbacks, cb_player, event); |
785 | break; |
790 | break; |
786 | |
791 | |
787 | case KLASS_MAP: |
792 | case KLASS_MAP: |
788 | dt = (data_type) va_arg (ap, int); |
793 | dt = (data_type) va_arg (ap, int); |
789 | assert (("first argument must be of type object", dt == DT_MAP)); |
794 | assert (("first argument must be of type object", dt == DT_MAP)); |
790 | map = va_arg (ap, mapstruct *); |
795 | map = va_arg (ap, mapstruct *); |
791 | |
796 | |
792 | if (map->cb) |
797 | if (map->cb) |
793 | gather_callbacks (callbacks, (AV *)map->cb, event); |
798 | gather_callbacks (callbacks, map->cb, event); |
794 | |
799 | |
795 | gather_callbacks (callbacks, cb_map, event); |
800 | gather_callbacks (callbacks, cb_map, event); |
796 | break; |
801 | break; |
797 | |
802 | |
798 | default: |
803 | default: |
… | |
… | |
1418 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1423 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1419 | prop (CFAPI_INT, MAP_PROP_SKY) |
1424 | prop (CFAPI_INT, MAP_PROP_SKY) |
1420 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1425 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1421 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1426 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1422 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1427 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1423 | prop (CFAPI_PMAP, MAP_PROP_NEXT) |
|
|
1424 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1428 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1425 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1429 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1426 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1430 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1427 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1431 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1428 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
1432 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
… | |
… | |
1840 | |
1844 | |
1841 | void cf_object_drop (object *op, object *author) |
1845 | void cf_object_drop (object *op, object *author) |
1842 | |
1846 | |
1843 | void cf_object_take (object *op, object *author) |
1847 | void cf_object_take (object *op, object *author) |
1844 | |
1848 | |
1845 | void cf_object_say (object *op, char *msg) |
|
|
1846 | |
|
|
1847 | void cf_object_speak (object *op, char *msg) |
|
|
1848 | |
|
|
1849 | object *cf_object_insert_object (object *op, object *container) |
1849 | object *cf_object_insert_object (object *op, object *container) |
1850 | |
1850 | |
1851 | const char *cf_object_get_msg (object *ob) |
1851 | const char *cf_object_get_msg (object *ob) |
1852 | ALIAS: msg = 0 |
1852 | ALIAS: msg = 0 |
1853 | |
1853 | |
… | |
… | |
2129 | OUTPUT: RETVAL |
2129 | OUTPUT: RETVAL |
2130 | |
2130 | |
2131 | |
2131 | |
2132 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2132 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2133 | |
2133 | |
2134 | void |
2134 | mapstruct *first () |
2135 | trigger (mapstruct *map, long connection, bool state = true) |
2135 | PROTOTYPE: |
2136 | CODE: |
|
|
2137 | activate_connection (map, connection, state); |
|
|
2138 | |
|
|
2139 | void |
|
|
2140 | get_connection (mapstruct *map, long connection) |
|
|
2141 | PPCODE: |
2136 | CODE: |
2142 | { |
2137 | RETVAL = first_map; |
2143 | oblinkpt *obp = get_connection_links (map, connection); |
2138 | OUTPUT: RETVAL |
2144 | if (obp) |
2139 | |
2145 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2140 | mapstruct *next (mapstruct *map) |
2146 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); |
2141 | PROTOTYPE: |
2147 | } |
2142 | CODE: |
|
|
2143 | RETVAL = map->next; |
|
|
2144 | OUTPUT: RETVAL |
2148 | |
2145 | |
2149 | int invoke (mapstruct *map, int event, ...) |
2146 | int invoke (mapstruct *map, int event, ...) |
2150 | CODE: |
2147 | CODE: |
2151 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2148 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2152 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2149 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2180 | |
2177 | |
2181 | mapstruct *new (int width, int height) |
2178 | mapstruct *new (int width, int height) |
2182 | PROTOTYPE: |
2179 | PROTOTYPE: |
2183 | CODE: |
2180 | CODE: |
2184 | { |
2181 | { |
2185 | int unused_type; |
2182 | RETVAL = get_empty_map (width, height); |
2186 | RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); |
|
|
2187 | } |
2183 | } |
2188 | OUTPUT: |
2184 | OUTPUT: |
2189 | RETVAL |
2185 | RETVAL |
2190 | |
2186 | |
2191 | void delete_map (mapstruct *map) |
2187 | void delete_map (mapstruct *map) |
… | |
… | |
2206 | XSRETURN_UNDEF; |
2202 | XSRETURN_UNDEF; |
2207 | RETVAL = map->tile_path [dir]; |
2203 | RETVAL = map->tile_path [dir]; |
2208 | OUTPUT: |
2204 | OUTPUT: |
2209 | RETVAL |
2205 | RETVAL |
2210 | |
2206 | |
2211 | mapstruct *cf_map_get_map (char *name) |
2207 | mapstruct *ready_map_name (char *name, int flags = 0) |
2212 | PROTOTYPE: $ |
2208 | PROTOTYPE: $;$ |
2213 | ALIAS: map = 0 |
2209 | ALIAS: |
|
|
2210 | find = 0 |
|
|
2211 | get_map = 1 |
2214 | |
2212 | |
2215 | mapstruct *has_been_loaded (char *name) |
2213 | mapstruct *has_been_loaded (char *name) |
2216 | PROTOTYPE: $ |
2214 | PROTOTYPE: $ |
2217 | |
|
|
2218 | mapstruct *cf_map_get_first () |
|
|
2219 | PROTOTYPE: |
|
|
2220 | ALIAS: first = 0 |
|
|
2221 | |
2215 | |
2222 | # whoever "designed" the plug-in api should have wasted |
2216 | # whoever "designed" the plug-in api should have wasted |
2223 | # his/her time with staying away from the project - would have |
2217 | # his/her time with staying away from the project - would have |
2224 | # saved others a lot of time, without doubt. |
2218 | # saved others a lot of time, without doubt. |
2225 | void set_path (mapstruct *where, char *path) |
2219 | void set_path (mapstruct *where, char *path) |
… | |
… | |
2239 | RETVAL |
2233 | RETVAL |
2240 | |
2234 | |
2241 | void set_unique (mapstruct *map, bool unique) |
2235 | void set_unique (mapstruct *map, bool unique) |
2242 | CODE: |
2236 | CODE: |
2243 | map->unique = unique; |
2237 | map->unique = unique; |
|
|
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))); |
2244 | |
2251 | |
2245 | 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) |
2246 | |
2253 | |
2247 | 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) |
2248 | |
2255 | |
… | |
… | |
2309 | case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; |
2316 | case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; |
2310 | 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; |
2311 | } |
2318 | } |
2312 | OUTPUT: |
2319 | OUTPUT: |
2313 | RETVAL |
2320 | RETVAL |
2314 | |
|
|
2315 | # "deserialise" perl map data into the map # TODO# compatibility cruft, remove |
|
|
2316 | void |
|
|
2317 | _set_obs (mapstruct *map, SV *sv) |
|
|
2318 | CODE: |
|
|
2319 | { |
|
|
2320 | object *o; |
|
|
2321 | AV *av; |
|
|
2322 | int x, y; |
|
|
2323 | AV *obs = (AV *)SvRV (sv); |
|
|
2324 | |
|
|
2325 | for (y = 0; y < MAP_HEIGHT (map); y++) |
|
|
2326 | for (x = 0; x < MAP_WIDTH (map); x++) |
|
|
2327 | { |
|
|
2328 | sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1); |
|
|
2329 | |
|
|
2330 | if (!SvROK (sv)) |
|
|
2331 | continue; |
|
|
2332 | |
|
|
2333 | av = (AV *)SvRV (sv); |
|
|
2334 | |
|
|
2335 | for (o = GET_MAP_OB (map, x, y); o; o = o->above) |
|
|
2336 | { |
|
|
2337 | sv = av_shift (av); |
|
|
2338 | |
|
|
2339 | if (SvROK (sv)) |
|
|
2340 | { |
|
|
2341 | sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0); |
|
|
2342 | SVptr_cache_set (o, sv); |
|
|
2343 | } |
|
|
2344 | } |
|
|
2345 | } |
|
|
2346 | } |
|
|
2347 | |
2321 | |
2348 | |
2322 | |
2349 | MODULE = cf PACKAGE = cf::arch |
2323 | MODULE = cf PACKAGE = cf::arch |
2350 | |
2324 | |
2351 | archetype *first() |
2325 | archetype *first() |