… | |
… | |
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 "autoconf.h" |
|
|
27 | |
26 | #define PLUGIN_NAME "perl" |
28 | #define PLUGIN_NAME "perl" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
29 | #define PLUGIN_VERSION "cfperl 0.5" |
28 | |
30 | |
29 | #define CEDES_PER_TICK 5 |
31 | #define CEDES_PER_TICK 5 |
|
|
32 | |
|
|
33 | #if HAVE_EXECINFO_H |
|
|
34 | # include <execinfo.h> |
|
|
35 | #endif |
30 | |
36 | |
31 | #include <plugin_common.h> |
37 | #include <plugin_common.h> |
32 | #include <sounds.h> |
38 | #include <sounds.h> |
33 | #include <cstdarg> |
39 | #include <cstdarg> |
34 | #include <sproto.h> |
40 | #include <sproto.h> |
… | |
… | |
180 | if (destroyed ()) |
186 | if (destroyed ()) |
181 | return; |
187 | return; |
182 | |
188 | |
183 | flags |= F_DESTROYED; |
189 | flags |= F_DESTROYED; |
184 | do_destroy (); |
190 | do_destroy (); |
|
|
191 | sever_self (); |
185 | } |
192 | } |
186 | |
193 | |
187 | void |
194 | void |
188 | attachable::check_mortals () |
195 | attachable::check_mortals () |
189 | { |
196 | { |
… | |
… | |
209 | LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
216 | LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
210 | obj->sever_self (); |
217 | obj->sever_self (); |
211 | } |
218 | } |
212 | #endif |
219 | #endif |
213 | |
220 | |
214 | if (obj->refcnt_cnt ()) |
221 | if (obj->refcnt) |
215 | { |
222 | { |
216 | ++i; // further delay freeing |
223 | ++i; // further delay freeing |
217 | |
224 | |
218 | if (!(i & 0x3ff)) |
225 | if (!(i & 0x3ff)) |
219 | break; |
226 | break; |
… | |
… | |
397 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
404 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
398 | |
405 | |
399 | template<int N> |
406 | template<int N> |
400 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
407 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
401 | |
408 | |
402 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
|
|
403 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
409 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
404 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
410 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
405 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
411 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
406 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
412 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
407 | |
413 | |
… | |
… | |
610 | perl_construct (perl); |
616 | perl_construct (perl); |
611 | |
617 | |
612 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
618 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
613 | |
619 | |
614 | const char *argv[] = { |
620 | const char *argv[] = { |
615 | "", |
621 | settings.argv [0], |
616 | "-e" |
622 | "-e" |
617 | "use Event; use Coro;" // required for bootstrap |
623 | "use Event; use Coro;" // required for bootstrap |
618 | "cf->bootstrap;" // required for datadir :*> |
624 | "cf->bootstrap;" // required for datadir :*> |
619 | "unshift @INC, cf::datadir ();" |
625 | "unshift @INC, cf::datadir ();" |
620 | "require cf;" |
626 | "require cf;" |
… | |
… | |
942 | CALL_ARG (exit); |
948 | CALL_ARG (exit); |
943 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
949 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
944 | CALL_END; |
950 | CALL_END; |
945 | } |
951 | } |
946 | |
952 | |
|
|
953 | void |
|
|
954 | log_backtrace (const char *msg) |
|
|
955 | { |
|
|
956 | #if HAVE_BACKTRACE |
|
|
957 | void *addr [20]; |
|
|
958 | int size = backtrace (addr, 20); |
|
|
959 | |
|
|
960 | CALL_BEGIN (size); |
|
|
961 | CALL_ARG (msg); |
|
|
962 | for (int i = 0; i < size; ++i) |
|
|
963 | CALL_ARG ((IV)addr [i]); |
|
|
964 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
|
|
965 | CALL_END; |
|
|
966 | #endif |
|
|
967 | } |
|
|
968 | |
947 | ///////////////////////////////////////////////////////////////////////////// |
969 | ///////////////////////////////////////////////////////////////////////////// |
948 | |
970 | |
949 | struct EventAPI *watcher_base::GEventAPI; |
971 | struct EventAPI *watcher_base::GEventAPI; |
950 | struct CoroAPI *coroapi::GCoroAPI; |
972 | struct CoroAPI *coroapi::GCoroAPI; |
951 | |
973 | |
… | |
… | |
1105 | const char *name; |
1127 | const char *name; |
1106 | IV iv; |
1128 | IV iv; |
1107 | } *civ, const_iv[] = { |
1129 | } *civ, const_iv[] = { |
1108 | # define const_iv(name) { # name, (IV)name }, |
1130 | # define const_iv(name) { # name, (IV)name }, |
1109 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
1131 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
|
|
1132 | const_iv (logBacktrace) |
1110 | |
1133 | |
1111 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1134 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1112 | |
1135 | |
1113 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1136 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1114 | |
1137 | |
1115 | const_iv (MAX_TIME) |
1138 | const_iv (MAX_TIME) |
|
|
1139 | |
|
|
1140 | const_iv (NUM_BODY_LOCATIONS) |
|
|
1141 | const_iv (body_range) const_iv (body_shield) const_iv (body_combat) |
|
|
1142 | const_iv (body_arm) const_iv (body_torso) const_iv (body_head) |
|
|
1143 | const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) |
|
|
1144 | const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand) |
|
|
1145 | const_iv (body_wrist) const_iv (body_waist) |
1116 | |
1146 | |
1117 | const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) |
1147 | const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) |
1118 | const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) |
1148 | const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) |
1119 | const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) |
1149 | const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) |
1120 | const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) |
1150 | const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) |
… | |
… | |
1386 | CODE: |
1416 | CODE: |
1387 | runtime = SvNVx (sv_runtime); |
1417 | runtime = SvNVx (sv_runtime); |
1388 | server_tick (); |
1418 | server_tick (); |
1389 | |
1419 | |
1390 | void |
1420 | void |
|
|
1421 | log_backtrace (utf8_string msg) |
|
|
1422 | |
|
|
1423 | void |
1391 | LOG (int level, utf8_string msg) |
1424 | LOG (int flags, utf8_string msg) |
1392 | PROTOTYPE: $$ |
1425 | PROTOTYPE: $$ |
1393 | C_ARGS: (LogLevel)level, "%s", msg |
1426 | C_ARGS: flags, "%s", msg |
1394 | |
1427 | |
1395 | octet_string path_combine (octet_string base, octet_string path) |
1428 | octet_string path_combine (octet_string base, octet_string path) |
1396 | PROTOTYPE: $$ |
1429 | PROTOTYPE: $$ |
1397 | |
1430 | |
1398 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1431 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
… | |
… | |
1435 | } |
1468 | } |
1436 | OUTPUT: RETVAL |
1469 | OUTPUT: RETVAL |
1437 | |
1470 | |
1438 | void abort () |
1471 | void abort () |
1439 | |
1472 | |
|
|
1473 | void reset_signals () |
|
|
1474 | |
1440 | void fork_abort (octet_string cause = "cf::fork_abort") |
1475 | void fork_abort (octet_string cause = "cf::fork_abort") |
1441 | |
1476 | |
1442 | void cleanup (octet_string cause, bool make_core = false) |
1477 | void cleanup (octet_string cause, bool make_core = false) |
1443 | |
1478 | |
1444 | void emergency_save () |
1479 | void emergency_save () |
… | |
… | |
1578 | object *actives (U32 index) |
1613 | object *actives (U32 index) |
1579 | CODE: |
1614 | CODE: |
1580 | RETVAL = index < actives.size () ? actives [index] : 0; |
1615 | RETVAL = index < actives.size () ? actives [index] : 0; |
1581 | OUTPUT: RETVAL |
1616 | OUTPUT: RETVAL |
1582 | |
1617 | |
|
|
1618 | const char *slot_save_name (U32 slot) |
|
|
1619 | ALIAS: |
|
|
1620 | slot_use_name = 1 |
|
|
1621 | slot_nonuse_name = 2 |
|
|
1622 | CODE: |
|
|
1623 | { |
|
|
1624 | if (slot >= NUM_BODY_LOCATIONS) |
|
|
1625 | croak ("body slot index out of range"); |
|
|
1626 | |
|
|
1627 | switch (ix) |
|
|
1628 | { |
|
|
1629 | case 0: RETVAL = body_locations[slot].save_name; break; |
|
|
1630 | case 1: RETVAL = body_locations[slot].use_name; break; |
|
|
1631 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
|
|
1632 | } |
|
|
1633 | } |
|
|
1634 | OUTPUT: |
|
|
1635 | RETVAL |
|
|
1636 | |
1583 | # missing properties |
1637 | # missing properties |
1584 | |
1638 | |
1585 | object *head (object *op) |
1639 | object *head (object *op) |
1586 | PROTOTYPE: $ |
1640 | PROTOTYPE: $ |
1587 | CODE: |
1641 | CODE: |
… | |
… | |
1612 | int |
1666 | int |
1613 | num_animations (object *op) |
1667 | num_animations (object *op) |
1614 | CODE: |
1668 | CODE: |
1615 | RETVAL = NUM_ANIMATIONS (op); |
1669 | RETVAL = NUM_ANIMATIONS (op); |
1616 | OUTPUT: RETVAL |
1670 | OUTPUT: RETVAL |
|
|
1671 | |
|
|
1672 | int slot_info (object *op, UV slot, int value = 0) |
|
|
1673 | ALIAS: |
|
|
1674 | slot_used = 1 |
|
|
1675 | CODE: |
|
|
1676 | { |
|
|
1677 | if (slot >= NUM_BODY_LOCATIONS) |
|
|
1678 | croak ("body slot index out of range"); |
|
|
1679 | |
|
|
1680 | RETVAL = ix ? op->slot[slot].info : op->slot[slot].used; |
|
|
1681 | |
|
|
1682 | if (items > 2) |
|
|
1683 | if (ix) |
|
|
1684 | op->slot[slot].info = value; |
|
|
1685 | else |
|
|
1686 | op->slot[slot].used = value; |
|
|
1687 | } |
|
|
1688 | OUTPUT: |
|
|
1689 | RETVAL |
1617 | |
1690 | |
1618 | object *find_best_object_match (object *op, utf8_string match) |
1691 | object *find_best_object_match (object *op, utf8_string match) |
1619 | |
1692 | |
1620 | object *find_marked_object (object *op) |
1693 | object *find_marked_object (object *op) |
1621 | |
1694 | |
… | |
… | |
1970 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2043 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
1971 | { |
2044 | { |
1972 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2045 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
1973 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2046 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
1974 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2047 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
|
|
2048 | |
|
|
2049 | if (ob->randomitems) |
|
|
2050 | { |
|
|
2051 | if (!ob->above) |
|
|
2052 | { |
|
|
2053 | ob->create_treasure (ob->randomitems); |
|
|
2054 | |
|
|
2055 | for (object *op = ob->above; op; op = op->above) |
|
|
2056 | op->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2057 | } |
|
|
2058 | |
|
|
2059 | ob->randomitems = 0; |
|
|
2060 | } |
1975 | } |
2061 | } |
1976 | } |
2062 | } |
1977 | } |
2063 | } |
1978 | |
2064 | |
1979 | skip_space: ; |
2065 | skip_space: ; |