… | |
… | |
30 | |
30 | |
31 | #if HAVE_EXECINFO_H |
31 | #if HAVE_EXECINFO_H |
32 | # include <execinfo.h> |
32 | # include <execinfo.h> |
33 | #endif |
33 | #endif |
34 | |
34 | |
35 | #include <plugin_common.h> |
|
|
36 | #include <sounds.h> |
|
|
37 | #include <cstdarg> |
35 | #include <cstdarg> |
|
|
36 | |
|
|
37 | #include "global.h" |
|
|
38 | #include "loader.h" |
|
|
39 | #include "../random_maps/random_map.h" |
38 | #include <sproto.h> |
40 | #include <sproto.h> |
39 | |
|
|
40 | #include "loader.h" |
|
|
41 | #include "cfperl.h" |
|
|
42 | #include "shstr.h" |
|
|
43 | |
41 | |
44 | #include <unistd.h> |
42 | #include <unistd.h> |
45 | #if _POSIX_MEMLOCK |
43 | #if _POSIX_MEMLOCK |
46 | # include <sys/mman.h> |
44 | # include <sys/mman.h> |
47 | #endif |
45 | #endif |
… | |
… | |
67 | #else |
65 | #else |
68 | typedef double val64; |
66 | typedef double val64; |
69 | # define newSVval64 newSVnv |
67 | # define newSVval64 newSVnv |
70 | # define SvVAL64 SvNV |
68 | # define SvVAL64 SvNV |
71 | #endif |
69 | #endif |
72 | |
|
|
73 | static f_plug_api gethook = cfapi_get_hooks; |
|
|
74 | static f_plug_api object_insert = cfapi_object_insert; |
|
|
75 | |
70 | |
76 | static PerlInterpreter *perl; |
71 | static PerlInterpreter *perl; |
77 | |
72 | |
78 | tstamp NOW, runtime; |
73 | tstamp NOW, runtime; |
79 | |
74 | |
… | |
… | |
590 | va_end (ap); |
585 | va_end (ap); |
591 | |
586 | |
592 | return sv; |
587 | return sv; |
593 | } |
588 | } |
594 | |
589 | |
595 | static SV * |
|
|
596 | newSVcfapi (int type, ...) |
|
|
597 | { |
|
|
598 | SV *sv; |
|
|
599 | |
|
|
600 | va_list ap; |
|
|
601 | va_start (ap, type); |
|
|
602 | |
|
|
603 | switch (type) |
|
|
604 | { |
|
|
605 | case CFAPI_INT: sv = newSViv (*va_arg (ap, int * )); break; |
|
|
606 | case CFAPI_LONG: sv = newSVval64 (*va_arg (ap, sint64 *)); break; |
|
|
607 | case CFAPI_DOUBLE: sv = newSVnv (*va_arg (ap, double *)); break; |
|
|
608 | case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break; |
|
|
609 | case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break; |
|
|
610 | case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break; |
|
|
611 | case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break; |
|
|
612 | case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break; |
|
|
613 | case CFAPI_PPARTY: sv = newSVdt_va (ap, DT_PARTY ); break; |
|
|
614 | case CFAPI_PREGION: sv = newSVdt_va (ap, DT_REGION); break; |
|
|
615 | |
|
|
616 | default: |
|
|
617 | assert (("unhandled type in newSVcfapi", 0)); |
|
|
618 | } |
|
|
619 | |
|
|
620 | va_end (ap); |
|
|
621 | |
|
|
622 | return sv; |
|
|
623 | } |
|
|
624 | |
|
|
625 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
590 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
626 | |
591 | |
627 | SV * |
592 | SV * |
628 | registry (attachable *ext) |
593 | registry (attachable *ext) |
629 | { |
594 | { |
… | |
… | |
632 | |
597 | |
633 | return newRV_inc ((SV *)ext->cb); |
598 | return newRV_inc ((SV *)ext->cb); |
634 | } |
599 | } |
635 | |
600 | |
636 | ///////////////////////////////////////////////////////////////////////////// |
601 | ///////////////////////////////////////////////////////////////////////////// |
637 | |
|
|
638 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
|
|
639 | { |
|
|
640 | return 0; |
|
|
641 | } |
|
|
642 | |
|
|
643 | static CommArray_s rtn_cmd; |
|
|
644 | |
|
|
645 | static int |
|
|
646 | runPluginCommand (object *obj, char *params) |
|
|
647 | { |
|
|
648 | return -1; |
|
|
649 | } |
|
|
650 | |
|
|
651 | extern "C" void *cfperl_getPluginProperty (int *type, ...) |
|
|
652 | { |
|
|
653 | va_list args; |
|
|
654 | char *propname; |
|
|
655 | int i; |
|
|
656 | va_start (args, type); |
|
|
657 | propname = va_arg (args, char *); |
|
|
658 | //printf ("Property name: %s\n", propname); |
|
|
659 | |
|
|
660 | if (!strcmp (propname, "command?")) |
|
|
661 | return NULL; |
|
|
662 | else if (!strcmp (propname, "Identification")) |
|
|
663 | { |
|
|
664 | va_end (args); |
|
|
665 | return (void *)PLUGIN_NAME; |
|
|
666 | } |
|
|
667 | else if (!strcmp (propname, "FullName")) |
|
|
668 | { |
|
|
669 | va_end (args); |
|
|
670 | return (void *)PLUGIN_VERSION; |
|
|
671 | } |
|
|
672 | else |
|
|
673 | va_end (args); |
|
|
674 | |
|
|
675 | return NULL; |
|
|
676 | } |
|
|
677 | |
|
|
678 | extern "C" int cfperl_postInitPlugin () |
|
|
679 | { |
|
|
680 | int hooktype = 1; |
|
|
681 | int rtype = 0; |
|
|
682 | |
|
|
683 | cf_init_plugin (gethook); |
|
|
684 | |
|
|
685 | return 0; |
|
|
686 | } |
|
|
687 | |
|
|
688 | extern "C" int cfperl_closePlugin () |
|
|
689 | { |
|
|
690 | return 0; |
|
|
691 | } |
|
|
692 | |
602 | |
693 | void |
603 | void |
694 | cfperl_init () |
604 | cfperl_init () |
695 | { |
605 | { |
696 | PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); |
606 | PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); |
… | |
… | |
1981 | |
1891 | |
1982 | int need_identify (object *obj); |
1892 | int need_identify (object *obj); |
1983 | |
1893 | |
1984 | int apply_shop_mat (object *shop_mat, object *op); |
1894 | int apply_shop_mat (object *shop_mat, object *op); |
1985 | |
1895 | |
1986 | int move_player (object *op, int dir) |
|
|
1987 | CODE: |
|
|
1988 | RETVAL = move_player (op, dir); |
|
|
1989 | OUTPUT: |
|
|
1990 | RETVAL |
|
|
1991 | |
|
|
1992 | int move (object *op, int dir, object *originator = op) |
1896 | int move (object *op, int dir, object *originator = op) |
1993 | CODE: |
1897 | CODE: |
1994 | RETVAL = move_ob (op, dir, originator); |
1898 | RETVAL = move_ob (op, dir, originator); |
1995 | OUTPUT: |
1899 | OUTPUT: |
1996 | RETVAL |
1900 | RETVAL |
… | |
… | |
2002 | void apply_below (object *op) |
1906 | void apply_below (object *op) |
2003 | CODE: |
1907 | CODE: |
2004 | player_apply_below (op); |
1908 | player_apply_below (op); |
2005 | |
1909 | |
2006 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
1910 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
2007 | |
|
|
2008 | object *cf_object_present_archname_inside (object *op, utf8_string whatstr) |
|
|
2009 | |
|
|
2010 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
|
|
2011 | |
|
|
2012 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
|
|
2013 | |
1911 | |
2014 | #//TODO |
1912 | #//TODO |
2015 | object *clone_ (object *op, int recursive = 0) |
1913 | object *clone_ (object *op, int recursive = 0) |
2016 | CODE: |
1914 | CODE: |
2017 | if (recursive) |
1915 | if (recursive) |
… | |
… | |
2064 | |
1962 | |
2065 | void drop (object *who, object *op) |
1963 | void drop (object *who, object *op) |
2066 | |
1964 | |
2067 | void pick_up (object *who, object *op) |
1965 | void pick_up (object *who, object *op) |
2068 | |
1966 | |
2069 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
|
|
2070 | |
|
|
2071 | void update_object (object *op, int action) |
1967 | void update_object (object *op, int action) |
2072 | |
1968 | |
2073 | object *cf_create_object_by_name (utf8_string name) |
|
|
2074 | |
|
|
2075 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
1969 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
2076 | |
1970 | |
2077 | void player_lvl_adj (object *who, object *skill = 0) |
1971 | void player_lvl_adj (object *who, object *skill = 0) |
2078 | |
1972 | |
2079 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1973 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
… | |
… | |
2090 | |
1984 | |
2091 | void handle_apply_yield (object *op); |
1985 | void handle_apply_yield (object *op); |
2092 | |
1986 | |
2093 | |
1987 | |
2094 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1988 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2095 | |
|
|
2096 | object *cf_insert_ob_in_ob (object *ob, object *where) |
|
|
2097 | |
1989 | |
2098 | # no clean way to get an object from an archetype - stupid idiotic |
1990 | # no clean way to get an object from an archetype - stupid idiotic |
2099 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
1991 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2100 | |
1992 | |
2101 | object *new (utf8_string archetype = 0) |
1993 | object *new (utf8_string archetype = 0) |
… | |
… | |
2110 | # TODO: nuke |
2002 | # TODO: nuke |
2111 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2003 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2112 | PROTOTYPE: $$$$$$ |
2004 | PROTOTYPE: $$$$$$ |
2113 | CODE: |
2005 | CODE: |
2114 | { |
2006 | { |
2115 | int unused_type; |
2007 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2116 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
|
|
2117 | } |
2008 | } |
2118 | |
2009 | |
2119 | const_utf8_string get_ob_key_value (object *op, utf8_string key) |
2010 | const_utf8_string get_ob_key_value (object *op, utf8_string key) |
2120 | |
2011 | |
2121 | bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) |
2012 | bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) |
… | |
… | |
2134 | EXTEND (SP, 5); |
2025 | EXTEND (SP, 5); |
2135 | PUSHs (newSVuv (rv.distance)); |
2026 | PUSHs (newSVuv (rv.distance)); |
2136 | PUSHs (newSViv (rv.distance_x)); |
2027 | PUSHs (newSViv (rv.distance_x)); |
2137 | PUSHs (newSViv (rv.distance_y)); |
2028 | PUSHs (newSViv (rv.distance_y)); |
2138 | PUSHs (newSViv (rv.direction)); |
2029 | PUSHs (newSViv (rv.direction)); |
2139 | PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); |
2030 | PUSHs (to_sv (rv.part)); |
2140 | } |
2031 | } |
2141 | |
2032 | |
2142 | bool on_same_map_as (object *ob, object *other) |
2033 | bool on_same_map_as (object *ob, object *other) |
2143 | CODE: |
2034 | CODE: |
2144 | RETVAL = on_same_map (ob, other); |
2035 | RETVAL = on_same_map (ob, other); |
… | |
… | |
2164 | player *player (object *op) |
2055 | player *player (object *op) |
2165 | CODE: |
2056 | CODE: |
2166 | RETVAL = op->contr; |
2057 | RETVAL = op->contr; |
2167 | OUTPUT: RETVAL |
2058 | OUTPUT: RETVAL |
2168 | |
2059 | |
|
|
2060 | bool move_player (object *op, int dir) |
|
|
2061 | |
2169 | void check_score (object *op) |
2062 | void check_score (object *op) |
2170 | |
2063 | |
2171 | void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
2064 | void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
2172 | CODE: |
2065 | CODE: |
2173 | new_draw_info (flags, 0, op, txt); |
2066 | new_draw_info (flags, 0, op, txt); |
2174 | |
2067 | |
2175 | void kill_player (object *op) |
2068 | void kill_player (object *op) |
2176 | |
2069 | |
|
|
2070 | void esrv_send_item (object *pl, object *item) |
|
|
2071 | |
2177 | void esrv_update_item (object *op, int what, object *item) |
2072 | void esrv_update_item (object *pl, int what, object *item) |
2178 | C_ARGS: what, op, item |
2073 | C_ARGS: what, pl, item |
|
|
2074 | |
|
|
2075 | void esrv_del_item (object *pl, int tag) |
|
|
2076 | C_ARGS: pl->contr, tag |
2179 | |
2077 | |
2180 | int command_summon (object *op, utf8_string params) |
2078 | int command_summon (object *op, utf8_string params) |
2181 | |
2079 | |
2182 | int command_arrest (object *op, utf8_string params) |
2080 | int command_arrest (object *op, utf8_string params) |
2183 | |
2081 | |
… | |
… | |
2203 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2101 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
2204 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2102 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2205 | pl->orig_stats = pl->ob->stats; |
2103 | pl->orig_stats = pl->ob->stats; |
2206 | |
2104 | |
2207 | void clear_los (player *pl) |
2105 | void clear_los (player *pl) |
2208 | |
|
|
2209 | void cf_player_move (player *pl, int dir) |
|
|
2210 | |
2106 | |
2211 | bool |
2107 | bool |
2212 | cell_visible (player *pl, int dx, int dy) |
2108 | cell_visible (player *pl, int dx, int dy) |
2213 | CODE: |
2109 | CODE: |
2214 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2110 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
… | |
… | |
2432 | get_connection (maptile *map, long connection) |
2328 | get_connection (maptile *map, long connection) |
2433 | PPCODE: |
2329 | PPCODE: |
2434 | oblinkpt *obp = get_connection_links (map, connection); |
2330 | oblinkpt *obp = get_connection_links (map, connection); |
2435 | if (obp) |
2331 | if (obp) |
2436 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2332 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2437 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); |
2333 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2438 | |
|
|
2439 | object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags) |
|
|
2440 | |
|
|
2441 | object *cf_map_insert_object (maptile *where, object* op, int x, int y) |
|
|
2442 | |
|
|
2443 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
|
|
2444 | C_ARGS: str, map, nx, ny |
|
|
2445 | |
2334 | |
2446 | void |
2335 | void |
2447 | get_map_flags (maptile *map, int x, int y) |
2336 | get_map_flags (maptile *map, int x, int y) |
2448 | PPCODE: |
2337 | PPCODE: |
2449 | { |
2338 | { |
… | |
… | |
2454 | EXTEND (SP, 4); |
2343 | EXTEND (SP, 4); |
2455 | PUSHs (sv_2mortal (newSViv (flags))); |
2344 | PUSHs (sv_2mortal (newSViv (flags))); |
2456 | |
2345 | |
2457 | if (GIMME_V == G_ARRAY) |
2346 | if (GIMME_V == G_ARRAY) |
2458 | { |
2347 | { |
2459 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); |
2348 | PUSHs (sv_2mortal (to_sv (nmap))); |
2460 | PUSHs (sv_2mortal (newSViv (nx))); |
2349 | PUSHs (sv_2mortal (newSViv (nx))); |
2461 | PUSHs (sv_2mortal (newSViv (ny))); |
2350 | PUSHs (sv_2mortal (newSViv (ny))); |
2462 | } |
2351 | } |
2463 | } |
2352 | } |
2464 | |
2353 | |
… | |
… | |
2473 | |
2362 | |
2474 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2363 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2475 | |
2364 | |
2476 | if (nmap) |
2365 | if (nmap) |
2477 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2366 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2478 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2367 | XPUSHs (sv_2mortal (to_sv (o))); |
2479 | } |
2368 | } |
2480 | |
2369 | |
2481 | SV * |
2370 | SV * |
2482 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2371 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2483 | PROTOTYPE: $$$ |
2372 | PROTOTYPE: $$$ |
… | |
… | |
2492 | INIT: |
2381 | INIT: |
2493 | if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; |
2382 | if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; |
2494 | CODE: |
2383 | CODE: |
2495 | switch (ix) |
2384 | switch (ix) |
2496 | { |
2385 | { |
2497 | case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; |
2386 | case 0: RETVAL = to_sv (GET_MAP_OB (obj, x, y)); break; |
2498 | case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; |
2387 | case 1: RETVAL = to_sv (GET_MAP_TOP (obj, x, y)); break; |
2499 | case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; |
2388 | case 2: RETVAL = newSVuv (GET_MAP_FLAGS (obj, x, y)); break; |
2500 | case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; |
2389 | case 3: RETVAL = newSViv (GET_MAP_LIGHT (obj, x, y)); break; |
2501 | case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; |
2390 | case 4: RETVAL = newSVuv (GET_MAP_MOVE_BLOCK (obj, x, y)); break; |
2502 | case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; |
2391 | case 5: RETVAL = newSVuv (GET_MAP_MOVE_SLOW (obj, x, y)); break; |
2503 | case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; |
2392 | case 6: RETVAL = newSVuv (GET_MAP_MOVE_ON (obj, x, y)); break; |
2504 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2393 | case 7: RETVAL = newSVuv (GET_MAP_MOVE_OFF (obj, x, y)); break; |
2505 | } |
2394 | } |
2506 | OUTPUT: RETVAL |
2395 | OUTPUT: RETVAL |
2507 | |
2396 | |
2508 | void fix_walls (maptile *map, int x, int y) |
2397 | void fix_walls (maptile *map, int x, int y) |
2509 | |
2398 | |