… | |
… | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include "autoconf.h" |
24 | #include "autoconf.h" |
25 | |
25 | |
26 | #define PLUGIN_NAME "perl" |
|
|
27 | #define PLUGIN_VERSION "cfperl 0.5" |
|
|
28 | |
|
|
29 | #if HAVE_EXECINFO_H |
26 | #if HAVE_EXECINFO_H |
30 | # include <execinfo.h> |
27 | # include <execinfo.h> |
31 | #endif |
28 | #endif |
32 | |
29 | |
33 | #include <cstdarg> |
30 | #include <cstdarg> |
|
|
31 | #include <typeinfo> |
34 | |
32 | |
35 | #include "global.h" |
33 | #include "global.h" |
36 | #include "loader.h" |
34 | #include "loader.h" |
37 | #include "../random_maps/random_map.h" |
35 | #include "../random_maps/random_map.h" |
38 | #include "evthread.h" |
36 | #include "evthread.h" |
… | |
… | |
83 | *stash_cf, |
81 | *stash_cf, |
84 | *stash_cf_object_wrap, |
82 | *stash_cf_object_wrap, |
85 | *stash_cf_object_player_wrap, |
83 | *stash_cf_object_player_wrap, |
86 | *stash_cf_player_wrap, |
84 | *stash_cf_player_wrap, |
87 | *stash_cf_map_wrap, |
85 | *stash_cf_map_wrap, |
|
|
86 | *stash_cf_mapspace_wrap, |
88 | *stash_cf_client_wrap, |
87 | *stash_cf_client_wrap, |
89 | *stash_cf_arch_wrap, |
88 | *stash_cf_arch_wrap, |
90 | *stash_cf_party_wrap, |
89 | *stash_cf_party_wrap, |
91 | *stash_cf_region_wrap, |
90 | *stash_cf_region_wrap, |
92 | *stash_cf_living_wrap; |
91 | *stash_cf_living_wrap; |
… | |
… | |
431 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
430 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
432 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
431 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
433 | inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
432 | inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
434 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
433 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
435 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
434 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
|
|
435 | inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
436 | |
436 | |
437 | inline SV *to_sv (object & v) { return to_sv (&v); } |
437 | inline SV *to_sv (object & v) { return to_sv (&v); } |
438 | inline SV *to_sv (living & v) { return to_sv (&v); } |
438 | inline SV *to_sv (living & v) { return to_sv (&v); } |
439 | |
439 | |
440 | inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
440 | inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
… | |
… | |
464 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
464 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
465 | inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
465 | inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
466 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
466 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
467 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
467 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
468 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
468 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
|
|
469 | inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); } |
469 | inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } |
470 | inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } |
470 | inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } |
471 | inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } |
471 | |
472 | |
472 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
473 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
473 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
474 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
… | |
… | |
944 | CALL_CALL ("ext::books::make_book", G_VOID); |
945 | CALL_CALL ("ext::books::make_book", G_VOID); |
945 | CALL_END; |
946 | CALL_END; |
946 | } |
947 | } |
947 | |
948 | |
948 | void |
949 | void |
|
|
950 | cfperl_expand_cfpod (player *pl, std::string &msg) |
|
|
951 | { |
|
|
952 | CALL_BEGIN (2); |
|
|
953 | CALL_ARG (pl); |
|
|
954 | CALL_ARG_SV (newSVpvn_utf8 (msg.data (), msg.size ())); |
|
|
955 | CALL_CALL ("cf::player::expand_cfpod", G_SCALAR); |
|
|
956 | |
|
|
957 | if (count) |
|
|
958 | { |
|
|
959 | STRLEN len; |
|
|
960 | char *data = SvPVutf8 (TOPs, len); |
|
|
961 | msg.assign (data, len); |
|
|
962 | } |
|
|
963 | |
|
|
964 | CALL_END; |
|
|
965 | } |
|
|
966 | |
|
|
967 | void |
949 | cfperl_send_msg (client *ns, int color, const char *type, const char *msg) |
968 | cfperl_send_msg (client *ns, int color, const char *type, const char *msg) |
950 | { |
969 | { |
951 | CALL_BEGIN (4); |
970 | CALL_BEGIN (4); |
952 | CALL_ARG (ns); |
971 | CALL_ARG (ns); |
953 | CALL_ARG (type); |
972 | CALL_ARG (type); |
… | |
… | |
1174 | |
1193 | |
1175 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1194 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1176 | stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
1195 | stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
1177 | stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); |
1196 | stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); |
1178 | stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); |
1197 | stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); |
|
|
1198 | stash_cf_mapspace_wrap = gv_stashpv ("cf::mapspace::wrap" , 1); |
1179 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1199 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1180 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1200 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1181 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1201 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1182 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1202 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1183 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1203 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
… | |
… | |
1376 | const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) |
1396 | const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) |
1377 | const_iv (F_LOCKED) |
1397 | const_iv (F_LOCKED) |
1378 | |
1398 | |
1379 | const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) |
1399 | const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) |
1380 | |
1400 | |
1381 | const_iv (P_BLOCKSVIEW) const_iv (P_PLAYER) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE) |
1401 | const_iv (P_BLOCKSVIEW) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE) |
1382 | const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) |
1402 | const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) |
1383 | |
1403 | |
1384 | const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) |
1404 | const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) |
1385 | |
1405 | |
1386 | const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) |
1406 | const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) |
… | |
… | |
2085 | void rangevector (object *ob, object *other, int flags = 0) |
2105 | void rangevector (object *ob, object *other, int flags = 0) |
2086 | PROTOTYPE: $$;$ |
2106 | PROTOTYPE: $$;$ |
2087 | PPCODE: |
2107 | PPCODE: |
2088 | { |
2108 | { |
2089 | rv_vector rv; |
2109 | rv_vector rv; |
|
|
2110 | |
|
|
2111 | PUTBACK; |
2090 | get_rangevector (ob, other, &rv, flags); |
2112 | get_rangevector (ob, other, &rv, flags); |
|
|
2113 | SPAGAIN; |
|
|
2114 | |
2091 | EXTEND (SP, 5); |
2115 | EXTEND (SP, 5); |
2092 | PUSHs (newSVuv (rv.distance)); |
2116 | PUSHs (newSVuv (rv.distance)); |
2093 | PUSHs (newSViv (rv.distance_x)); |
2117 | PUSHs (newSViv (rv.distance_x)); |
2094 | PUSHs (newSViv (rv.distance_y)); |
2118 | PUSHs (newSViv (rv.distance_y)); |
2095 | PUSHs (newSViv (rv.direction)); |
2119 | PUSHs (newSViv (rv.direction)); |
… | |
… | |
2186 | if (len > MAXSOCKBUF) |
2210 | if (len > MAXSOCKBUF) |
2187 | pl->failmsg ("[packet too long for client]"); |
2211 | pl->failmsg ("[packet too long for client]"); |
2188 | else if (pl->ns) |
2212 | else if (pl->ns) |
2189 | pl->ns->send_packet (buf, len); |
2213 | pl->ns->send_packet (buf, len); |
2190 | } |
2214 | } |
2191 | |
|
|
2192 | int |
|
|
2193 | listening (player *pl, int new_value = -1) |
|
|
2194 | CODE: |
|
|
2195 | RETVAL = pl->listening; |
|
|
2196 | if (new_value >= 0) |
|
|
2197 | pl->listening = new_value; |
|
|
2198 | OUTPUT: |
|
|
2199 | RETVAL |
|
|
2200 | |
2215 | |
2201 | void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) |
2216 | void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) |
2202 | PROTOTYPE: $;$$$ |
2217 | PROTOTYPE: $;$$$ |
2203 | PPCODE: |
2218 | PPCODE: |
2204 | if (GIMME_V != G_VOID) |
2219 | if (GIMME_V != G_VOID) |
… | |
… | |
2402 | get_map_flags (maptile *map, int x, int y) |
2417 | get_map_flags (maptile *map, int x, int y) |
2403 | PPCODE: |
2418 | PPCODE: |
2404 | { |
2419 | { |
2405 | maptile *nmap = 0; |
2420 | maptile *nmap = 0; |
2406 | I16 nx = 0, ny = 0; |
2421 | I16 nx = 0, ny = 0; |
|
|
2422 | |
|
|
2423 | PUTBACK; |
2407 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2424 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2425 | SPAGAIN; |
2408 | |
2426 | |
2409 | EXTEND (SP, 4); |
2427 | EXTEND (SP, 4); |
2410 | PUSHs (sv_2mortal (newSViv (flags))); |
2428 | PUSHs (sv_2mortal (newSViv (flags))); |
2411 | |
2429 | |
2412 | if (GIMME_V == G_ARRAY) |
2430 | if (GIMME_V == G_ARRAY) |
… | |
… | |
2415 | PUSHs (sv_2mortal (newSViv (nx))); |
2433 | PUSHs (sv_2mortal (newSViv (nx))); |
2416 | PUSHs (sv_2mortal (newSViv (ny))); |
2434 | PUSHs (sv_2mortal (newSViv (ny))); |
2417 | } |
2435 | } |
2418 | } |
2436 | } |
2419 | |
2437 | |
|
|
2438 | mapspace * |
|
|
2439 | ms (maptile *map, unsigned int x, unsigned int y) |
|
|
2440 | PROTOTYPE: $$$ |
|
|
2441 | CODE: |
|
|
2442 | { |
|
|
2443 | maptile *nmap = 0; |
|
|
2444 | I16 nx, ny; |
|
|
2445 | |
|
|
2446 | PUTBACK; |
|
|
2447 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2448 | SPAGAIN; |
|
|
2449 | |
|
|
2450 | if (!nmap) |
|
|
2451 | XSRETURN_UNDEF; |
|
|
2452 | |
|
|
2453 | RETVAL = &nmap->at (nx, ny); |
|
|
2454 | } |
|
|
2455 | OUTPUT: |
|
|
2456 | RETVAL |
|
|
2457 | |
2420 | void |
2458 | void |
2421 | at (maptile *map, unsigned int x, unsigned int y) |
2459 | at (maptile *map, unsigned int x, unsigned int y) |
2422 | PROTOTYPE: $$$ |
2460 | PROTOTYPE: $$$ |
2423 | PPCODE: |
2461 | PPCODE: |
2424 | { |
2462 | { |
2425 | object *o; |
|
|
2426 | maptile *nmap = 0; |
2463 | maptile *nmap = 0; |
2427 | I16 nx, ny; |
2464 | I16 nx, ny; |
2428 | |
2465 | |
|
|
2466 | PUTBACK; |
2429 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2467 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2468 | SPAGAIN; |
2430 | |
2469 | |
2431 | if (nmap) |
2470 | if (nmap) |
2432 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2471 | for (object *o = nmap->at (nx, ny).bot; o; o = o->above) |
2433 | XPUSHs (sv_2mortal (to_sv (o))); |
2472 | XPUSHs (sv_2mortal (to_sv (o))); |
2434 | } |
2473 | } |
2435 | |
2474 | |
2436 | SV * |
2475 | SV * |
2437 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2476 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
… | |
… | |
2550 | RETVAL = self->generate_random_map (&rmp); |
2589 | RETVAL = self->generate_random_map (&rmp); |
2551 | } |
2590 | } |
2552 | OUTPUT: |
2591 | OUTPUT: |
2553 | RETVAL |
2592 | RETVAL |
2554 | |
2593 | |
|
|
2594 | MODULE = cf PACKAGE = cf::mapspace |
|
|
2595 | |
|
|
2596 | INCLUDE: $PERL $srcdir/genacc mapspace ../include/map.h | |
|
|
2597 | |
2555 | MODULE = cf PACKAGE = cf::arch |
2598 | MODULE = cf PACKAGE = cf::arch |
2556 | |
2599 | |
2557 | int archetypes_size () |
2600 | int archetypes_size () |
2558 | CODE: |
2601 | CODE: |
2559 | RETVAL = archetypes.size (); |
2602 | RETVAL = archetypes.size (); |