1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
10 | * |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | * |
15 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
19 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
21 | */ |
22 | |
22 | |
23 | #include "autoconf.h" |
23 | #include "autoconf.h" |
24 | |
24 | |
… | |
… | |
67 | static int tick_inhibit; |
67 | static int tick_inhibit; |
68 | static int tick_pending; |
68 | static int tick_pending; |
69 | |
69 | |
70 | global gbl_ev; |
70 | global gbl_ev; |
71 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
71 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
72 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
72 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick; |
73 | static AV *av_reflect; |
73 | static AV *av_reflect; |
74 | |
74 | |
75 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_EVENT_TYPES> ev_want_event; |
76 | bitset<NUM_TYPES> ev_want_type; |
76 | bitset<NUM_TYPES> ev_want_type; |
77 | |
77 | |
… | |
… | |
92 | |
92 | |
93 | static SV |
93 | static SV |
94 | *cv_cf_do_invoke, |
94 | *cv_cf_do_invoke, |
95 | *cv_cf__can_merge, |
95 | *cv_cf__can_merge, |
96 | *cv_cf_client_send_msg, |
96 | *cv_cf_client_send_msg, |
|
|
97 | *cv_cf_ix, |
97 | *cv_cf_tick, |
98 | *cv_cf_tick, |
98 | *cv_cf_match_match; |
99 | *cv_cf_match_match; |
99 | |
100 | |
100 | #ifndef newSVpv_utf8 |
101 | #ifndef newSVpv_utf8 |
101 | static SV * |
102 | static SV * |
… | |
… | |
253 | { |
254 | { |
254 | static int last_mortalcount; |
255 | static int last_mortalcount; |
255 | if (mortals.size () != last_mortalcount) |
256 | if (mortals.size () != last_mortalcount) |
256 | { |
257 | { |
257 | last_mortalcount = mortals.size (); |
258 | last_mortalcount = mortals.size (); |
258 | LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); |
259 | object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
|
|
260 | |
|
|
261 | LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
|
|
262 | (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
259 | |
263 | |
260 | if (0) |
264 | if (0) |
261 | { |
265 | { |
262 | for (int j = 0; j < mortals.size (); ++j)//D |
266 | for (int j = 0; j < mortals.size (); ++j)//D |
263 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
267 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
… | |
… | |
622 | STRLEN len; |
626 | STRLEN len; |
623 | char *data = SvPVbyte (sv, len); |
627 | char *data = SvPVbyte (sv, len); |
624 | v.assign (data, len); |
628 | v.assign (data, len); |
625 | } |
629 | } |
626 | |
630 | |
|
|
631 | static inline void sv_to (SV *sv, refcnt_buf &v) |
|
|
632 | { |
|
|
633 | STRLEN len; |
|
|
634 | char *data = SvPVbyte (sv, len); |
|
|
635 | refcnt_buf buf (data, len); |
|
|
636 | v = buf; |
|
|
637 | } |
|
|
638 | |
627 | static inline void sv_to (SV *sv, UUID &v) |
639 | static inline void sv_to (SV *sv, UUID &v) |
628 | { |
640 | { |
629 | if (!v.parse (SvPV_nolen (sv))) |
641 | if (!v.parse (SvPV_nolen (sv))) |
630 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
642 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
631 | } |
643 | } |
… | |
… | |
1146 | CALL_ARG (originator); |
1158 | CALL_ARG (originator); |
1147 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1159 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1148 | CALL_END; |
1160 | CALL_END; |
1149 | } |
1161 | } |
1150 | |
1162 | |
|
|
1163 | void cfperl_ix (client *ns, int set, faceidx idx, int pri) |
|
|
1164 | { |
|
|
1165 | CALL_BEGIN (3); |
|
|
1166 | CALL_ARG (ns); |
|
|
1167 | CALL_ARG (set); |
|
|
1168 | CALL_ARG (idx); |
|
|
1169 | CALL_ARG (pri); |
|
|
1170 | CALL_CALL (cv_cf_ix, G_VOID); |
|
|
1171 | CALL_END; |
|
|
1172 | } |
|
|
1173 | |
1151 | player * |
1174 | player * |
1152 | player::find (const_utf8_string name) |
1175 | player::find (const_utf8_string name) |
1153 | { |
1176 | { |
1154 | CALL_BEGIN (1); |
1177 | CALL_BEGIN (1); |
1155 | CALL_ARG (name); |
1178 | CALL_ARG (name); |
… | |
… | |
1404 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1427 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1405 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1428 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1406 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1429 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1407 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1430 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1408 | |
1431 | |
1409 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1432 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1410 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1433 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1434 | sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1411 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1435 | sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV); |
1412 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1436 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1413 | |
1437 | |
1414 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1438 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1415 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1439 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1416 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1440 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1417 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1441 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1424 | _connect_to_perl_2 () |
1448 | _connect_to_perl_2 () |
1425 | { |
1449 | { |
1426 | cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
1450 | cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
1427 | cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
1451 | cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
1428 | cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
1452 | cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
|
|
1453 | cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix); |
1429 | cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
1454 | cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
1430 | cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
1455 | cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
1431 | } |
1456 | } |
1432 | |
1457 | |
1433 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1458 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
… | |
… | |
1438 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1463 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1439 | |
1464 | |
1440 | _connect_to_perl_1 (); |
1465 | _connect_to_perl_1 (); |
1441 | |
1466 | |
1442 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1467 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1443 | |
|
|
1444 | //{ |
|
|
1445 | // require_pv ("Time::HiRes"); |
|
|
1446 | // |
|
|
1447 | // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
|
|
1448 | // if (!svp) croak ("Time::HiRes is required"); |
|
|
1449 | // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); |
|
|
1450 | // coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); |
|
|
1451 | //} |
|
|
1452 | |
1468 | |
1453 | static const struct { |
1469 | static const struct { |
1454 | const char *name; |
1470 | const char *name; |
1455 | IV iv; |
1471 | IV iv; |
1456 | } *civ, const_iv[] = { |
1472 | } *civ, const_iv[] = { |
… | |
… | |
1527 | |
1543 | |
1528 | void _gv_clear (SV *gv) |
1544 | void _gv_clear (SV *gv) |
1529 | CODE: |
1545 | CODE: |
1530 | assert (SvTYPE (gv) == SVt_PVGV); |
1546 | assert (SvTYPE (gv) == SVt_PVGV); |
1531 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
1547 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
|
|
1548 | SvREFCNT_inc (gv); |
1532 | f (GvGP (gv)->gp_form); |
1549 | f (GvGP (gv)->gp_form); |
1533 | f (GvGP (gv)->gp_io); |
1550 | f (GvGP (gv)->gp_io); |
1534 | f (GvGP (gv)->gp_sv); |
1551 | f (GvGP (gv)->gp_sv); |
1535 | f (GvGP (gv)->gp_av); |
1552 | f (GvGP (gv)->gp_av); |
1536 | f (GvGP (gv)->gp_hv); |
1553 | f (GvGP (gv)->gp_hv); |
1537 | f (GvGP (gv)->gp_cv); |
1554 | f (GvGP (gv)->gp_cv); |
1538 | GvCVGEN (gv) = 0; |
1555 | GvCVGEN (gv) = 0; |
1539 | GvMULTI_off (gv); |
1556 | GvMULTI_off (gv); |
|
|
1557 | SvREFCNT_dec (gv); |
1540 | # undef f |
1558 | # undef f |
1541 | |
1559 | |
1542 | void _connect_to_perl_1 () |
1560 | void _connect_to_perl_1 () |
1543 | |
1561 | |
1544 | void _connect_to_perl_2 () |
1562 | void _connect_to_perl_2 () |
… | |
… | |
1565 | |
1583 | |
1566 | void init_dynamic () |
1584 | void init_dynamic () |
1567 | |
1585 | |
1568 | void load_settings () |
1586 | void load_settings () |
1569 | |
1587 | |
1570 | void reload_exp_table () |
1588 | void _reload_exp_table () |
1571 | |
1589 | |
1572 | void reload_materials () |
1590 | void _reload_materials () |
1573 | |
1591 | |
1574 | void init_uuid () |
1592 | void init_uuid () |
1575 | CODE: |
1593 | CODE: |
1576 | UUID::init (); |
1594 | UUID::init (); |
1577 | |
1595 | |
… | |
… | |
1610 | { |
1628 | { |
1611 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1629 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1612 | coroapi::cede (); |
1630 | coroapi::cede (); |
1613 | } |
1631 | } |
1614 | |
1632 | |
1615 | void server_tick () |
1633 | void one_tick () |
1616 | CODE: |
1634 | CODE: |
1617 | { |
1635 | { |
1618 | ev_now_update (EV_DEFAULT); |
1636 | ev_now_update (EV_DEFAULT); |
1619 | NOW = ev_now (EV_DEFAULT); |
1637 | NOW = ev_now (EV_DEFAULT); |
1620 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1638 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1621 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1639 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1622 | runtime = SvNVX (sv_runtime); |
1640 | runtime = SvNVX (sv_runtime); |
1623 | |
1641 | |
|
|
1642 | one_tick (); |
|
|
1643 | |
1624 | server_tick (); |
1644 | ++server_tick; |
|
|
1645 | SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1625 | |
1646 | |
1626 | ev_now_update (EV_DEFAULT); |
1647 | ev_now_update (EV_DEFAULT); |
1627 | NOW = ev_now (EV_DEFAULT); |
1648 | NOW = ev_now (EV_DEFAULT); |
1628 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1649 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1650 | |
1629 | runtime += TICK; |
1651 | runtime += TICK; |
1630 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1652 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1631 | } |
1653 | } |
1632 | |
1654 | |
1633 | NV floor (NV x) |
1655 | NV floor (NV x) |
… | |
… | |
1637 | NV rndm (...) |
1659 | NV rndm (...) |
1638 | ALIAS: |
1660 | ALIAS: |
1639 | rmg_rndm = 1 |
1661 | rmg_rndm = 1 |
1640 | CODE: |
1662 | CODE: |
1641 | { |
1663 | { |
1642 | rand_gen &gen = ix ? rmg_rndm : rndm; |
1664 | rand_gen &gen = ix ? rmg_rndm : rndm; |
1643 | switch (items) |
1665 | switch (items) |
1644 | { |
1666 | { |
1645 | case 0: RETVAL = gen (); break; |
1667 | case 0: RETVAL = gen (); break; |
1646 | case 1: RETVAL = gen (SvUV (ST (0))); break; |
1668 | case 1: RETVAL = gen (SvUV (ST (0))); break; |
1647 | case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; |
1669 | case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; |
… | |
… | |
1771 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1793 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1772 | PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
1794 | PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
1773 | PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); |
1795 | PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); |
1774 | } |
1796 | } |
1775 | |
1797 | |
1776 | int find_animation (utf8_string text) |
|
|
1777 | PROTOTYPE: $ |
|
|
1778 | |
|
|
1779 | int random_roll (int min, int max, object *op, int goodbad); |
1798 | int random_roll (int min, int max, object *op, int goodbad); |
1780 | |
1799 | |
1781 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1800 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1782 | |
1801 | |
1783 | int exp_to_level (val64 exp) |
1802 | int exp_to_level (val64 exp) |
1784 | |
1803 | |
1785 | val64 level_to_min_exp (int level) |
1804 | val64 level_to_min_exp (int level) |
|
|
1805 | |
|
|
1806 | const_utf8_string |
|
|
1807 | spellpathnames (int idx) |
|
|
1808 | CODE: |
|
|
1809 | RETVAL = spellpathnames [idx]; |
|
|
1810 | OUTPUT: RETVAL |
1786 | |
1811 | |
1787 | SV * |
1812 | SV * |
1788 | attacktype_name (int atnr) |
1813 | attacktype_name (int atnr) |
1789 | CODE: |
1814 | CODE: |
1790 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1815 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
… | |
… | |
1862 | load_resource_file_ (octet_string filename) |
1887 | load_resource_file_ (octet_string filename) |
1863 | |
1888 | |
1864 | void |
1889 | void |
1865 | fix_weight () |
1890 | fix_weight () |
1866 | |
1891 | |
|
|
1892 | utf8_string |
|
|
1893 | expand_cfpod (int hintmode, int gender, const_utf8_string cfpod) |
|
|
1894 | PPCODE: |
|
|
1895 | XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod))); |
|
|
1896 | |
1867 | MODULE = cf PACKAGE = cf::attachable |
1897 | MODULE = cf PACKAGE = cf::attachable |
1868 | |
1898 | |
1869 | int |
1899 | int |
1870 | valid (SV *obj) |
1900 | valid (SV *obj) |
1871 | CODE: |
1901 | CODE: |
… | |
… | |
2093 | int convert_item (object *item, object *converter) |
2123 | int convert_item (object *item, object *converter) |
2094 | |
2124 | |
2095 | void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); |
2125 | void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); |
2096 | |
2126 | |
2097 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2127 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2098 | |
|
|
2099 | # no clean way to get an object from an archetype - stupid idiotic |
|
|
2100 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
|
|
2101 | |
2128 | |
2102 | object *new (utf8_string archetype = 0) |
2129 | object *new (utf8_string archetype = 0) |
2103 | PROTOTYPE: ;$ |
2130 | PROTOTYPE: ;$ |
2104 | CODE: |
2131 | CODE: |
2105 | RETVAL = archetype |
2132 | RETVAL = archetype |
… | |
… | |
2128 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2155 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2129 | |
2156 | |
2130 | if (RETVAL->destroyed ()) |
2157 | if (RETVAL->destroyed ()) |
2131 | RETVAL = 0; |
2158 | RETVAL = 0; |
2132 | } |
2159 | } |
|
|
2160 | OUTPUT: |
|
|
2161 | RETVAL |
2133 | |
2162 | |
2134 | shstr |
2163 | shstr |
2135 | object::kv_get (shstr key) |
2164 | object::kv_get (shstr key) |
2136 | CODE: |
2165 | CODE: |
2137 | RETVAL = THIS->kv.get (key); |
2166 | RETVAL = THIS->kv.get (key); |
… | |
… | |
2371 | croak ("maptile::add_underlay: palette must be arrayref"); |
2400 | croak ("maptile::add_underlay: palette must be arrayref"); |
2372 | |
2401 | |
2373 | palette = SvRV (palette); |
2402 | palette = SvRV (palette); |
2374 | |
2403 | |
2375 | STRLEN idxlen; |
2404 | STRLEN idxlen; |
2376 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2405 | const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen); |
2377 | |
2406 | |
2378 | for (int x = 0; x < THIS->width; ++x) |
2407 | for (int x = 0; x < THIS->width; ++x) |
2379 | for (int y = 0; y < THIS->height; ++y) |
2408 | for (int y = 0; y < THIS->height; ++y) |
2380 | { |
2409 | { |
2381 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
2410 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
… | |
… | |
2421 | croak ("maptile::set_regiondata: palette must be arrayref"); |
2450 | croak ("maptile::set_regiondata: palette must be arrayref"); |
2422 | |
2451 | |
2423 | palette = SvRV (palette); |
2452 | palette = SvRV (palette); |
2424 | |
2453 | |
2425 | STRLEN idxlen; |
2454 | STRLEN idxlen; |
2426 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2455 | const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen); |
2427 | |
2456 | |
2428 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2457 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2429 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2458 | uint8 *regions = salloc<uint8_t> (THIS->size ()); |
2430 | |
2459 | |
2431 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2460 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2432 | regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2461 | regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2433 | |
2462 | |
2434 | for (int y = 0; y < THIS->height; ++y) |
2463 | for (int y = 0; y < THIS->height; ++y) |
… | |
… | |
2560 | archetype *archetypes (U32 index) |
2589 | archetype *archetypes (U32 index) |
2561 | CODE: |
2590 | CODE: |
2562 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2591 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2563 | OUTPUT: RETVAL |
2592 | OUTPUT: RETVAL |
2564 | |
2593 | |
|
|
2594 | int skillvec_size () |
|
|
2595 | CODE: |
|
|
2596 | RETVAL = skillvec.size (); |
|
|
2597 | OUTPUT: RETVAL |
|
|
2598 | |
|
|
2599 | archetype *skillvec (U32 index) |
|
|
2600 | CODE: |
|
|
2601 | RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0; |
|
|
2602 | OUTPUT: RETVAL |
|
|
2603 | |
|
|
2604 | void |
|
|
2605 | find_by_type (int type) |
|
|
2606 | PPCODE: |
|
|
2607 | for_all_archetypes (arch) |
|
|
2608 | if (arch->type == type) |
|
|
2609 | XPUSHs (sv_2mortal (to_sv (arch))); |
|
|
2610 | |
2565 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2611 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2566 | |
2612 | |
2567 | MODULE = cf PACKAGE = cf::party |
2613 | MODULE = cf PACKAGE = cf::party |
2568 | |
2614 | |
2569 | partylist *first () |
2615 | partylist *first () |
… | |
… | |
2617 | list () |
2663 | list () |
2618 | PPCODE: |
2664 | PPCODE: |
2619 | EXTEND (SP, clients.size ()); |
2665 | EXTEND (SP, clients.size ()); |
2620 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2666 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2621 | PUSHs (sv_2mortal (to_sv (*i))); |
2667 | PUSHs (sv_2mortal (to_sv (*i))); |
|
|
2668 | |
|
|
2669 | STRLEN |
|
|
2670 | client::inbuf_append (SV *data) |
|
|
2671 | CODE: |
|
|
2672 | { |
|
|
2673 | STRLEN len; |
|
|
2674 | char *ptr = SvPVbyte (data, len); |
|
|
2675 | |
|
|
2676 | min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len); |
|
|
2677 | memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len); |
|
|
2678 | THIS->inbuf_len += len; |
|
|
2679 | |
|
|
2680 | THIS->inbuf_handle (); |
|
|
2681 | |
|
|
2682 | RETVAL = len; |
|
|
2683 | } |
|
|
2684 | OUTPUT: RETVAL |
2622 | |
2685 | |
2623 | void |
2686 | void |
2624 | client::send_packet (SV *packet) |
2687 | client::send_packet (SV *packet) |
2625 | CODE: |
2688 | CODE: |
2626 | { |
2689 | { |
… | |
… | |
2682 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2745 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2683 | |
2746 | |
2684 | faceidx alloc (utf8_string name) |
2747 | faceidx alloc (utf8_string name) |
2685 | CODE: |
2748 | CODE: |
2686 | { |
2749 | { |
2687 | do |
2750 | RETVAL = face_alloc (); |
2688 | { |
|
|
2689 | RETVAL = faces.size (); |
|
|
2690 | faces.resize (RETVAL + 1); |
|
|
2691 | } |
|
|
2692 | while (!RETVAL); // crude way to leave index 0 |
|
|
2693 | |
2751 | |
2694 | faces [RETVAL].name = name; |
2752 | faces [RETVAL].name = name; |
2695 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2753 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2696 | |
2754 | |
2697 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2755 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2698 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2756 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2699 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2757 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2700 | } |
2758 | } |
|
|
2759 | OUTPUT: RETVAL |
|
|
2760 | |
|
|
2761 | faceidx faces_size () |
|
|
2762 | CODE: |
|
|
2763 | RETVAL = faces.size (); |
2701 | OUTPUT: RETVAL |
2764 | OUTPUT: RETVAL |
2702 | |
2765 | |
2703 | void set_type (faceidx idx, int value) |
2766 | void set_type (faceidx idx, int value) |
2704 | ALIAS: |
2767 | ALIAS: |
2705 | set_type = 0 |
2768 | set_type = 0 |
… | |
… | |
2716 | case 2: f->magicmap = value; break; |
2779 | case 2: f->magicmap = value; break; |
2717 | case 3: f->smooth = value; break; |
2780 | case 3: f->smooth = value; break; |
2718 | case 4: f->smoothlevel = value; break; |
2781 | case 4: f->smoothlevel = value; break; |
2719 | } |
2782 | } |
2720 | |
2783 | |
2721 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2784 | void set_csum (faceidx idx, int faceset, SV *chksum) |
2722 | CODE: |
2785 | CODE: |
2723 | { |
2786 | { |
2724 | faceinfo *f = face_info (idx); assert (f); |
2787 | faceinfo *f = face_info (idx); assert (f); |
2725 | facedata *d = f->face + faceset; |
2788 | facedata *d = f->face + faceset; |
2726 | sv_to (data, d->data); |
|
|
2727 | STRLEN clen; |
2789 | STRLEN clen; |
2728 | char *cdata = SvPVbyte (chksum, clen); |
2790 | char *cdata = SvPVbyte (chksum, clen); |
2729 | clen = min (CHKSUM_MAXLEN, clen); |
|
|
2730 | |
2791 | |
|
|
2792 | assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN)); |
2731 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2793 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2732 | |
2794 | |
2733 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2795 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2734 | { |
2796 | { |
2735 | d->chksum_len = clen; |
2797 | d->chksum_len = clen; |
2736 | memcpy (d->chksum, cdata, clen); |
2798 | memcpy (d->chksum, cdata, clen); |
2737 | |
2799 | |
2738 | // invalidate existing client face info |
2800 | // invalidate existing client face info |
2739 | for_all_clients (ns) |
2801 | for_all_clients (ns) |
2740 | if (ns->faceset == faceset) |
2802 | ns->invalidate_face (idx); |
2741 | { |
|
|
2742 | ns->faces_sent [idx] = false; |
|
|
2743 | ns->force_newmap = true; |
|
|
2744 | } |
|
|
2745 | } |
2803 | } |
2746 | } |
2804 | } |
2747 | |
2805 | |
2748 | int get_data_size (faceidx idx, int faceset = 0) |
2806 | SV *mangle_csum (SV *chksum) |
2749 | CODE: |
2807 | CODE: |
2750 | facedata *d = face_data (idx, faceset); |
2808 | STRLEN len; |
2751 | if (!d) XSRETURN_UNDEF; |
2809 | char *data = SvPVbyte (chksum, len); |
2752 | RETVAL = d->data.size (); |
2810 | RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN)); |
2753 | OUTPUT: |
2811 | OUTPUT: |
2754 | RETVAL |
2812 | RETVAL |
2755 | |
2813 | |
2756 | SV *get_chksum (faceidx idx, int faceset = 0) |
2814 | SV *get_csum (faceidx idx, int faceset = 0) |
2757 | CODE: |
2815 | CODE: |
2758 | facedata *d = face_data (idx, faceset); |
2816 | facedata *d = face_data (idx, faceset); |
2759 | if (!d) XSRETURN_UNDEF; |
2817 | if (!d) XSRETURN_UNDEF; |
2760 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2818 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2761 | OUTPUT: |
2819 | OUTPUT: |
2762 | RETVAL |
2820 | RETVAL |
2763 | |
2821 | |
2764 | SV *get_data (faceidx idx, int faceset = 0) |
2822 | int get_type (faceidx idx) |
2765 | CODE: |
2823 | CODE: |
2766 | facedata *d = face_data (idx, faceset); |
2824 | faceinfo *f = face_info (idx); |
2767 | if (!d) XSRETURN_UNDEF; |
2825 | if (!f) XSRETURN_UNDEF; |
2768 | RETVAL = newSVpvn (d->data.data (), d->data.length ()); |
2826 | RETVAL = f->type; |
2769 | OUTPUT: |
2827 | OUTPUT: |
2770 | RETVAL |
2828 | RETVAL |
2771 | |
2829 | |
|
|
2830 | SV *get_name (faceidx idx) |
|
|
2831 | CODE: |
|
|
2832 | faceinfo *f = face_info (idx); |
|
|
2833 | if (!f) XSRETURN_UNDEF; |
|
|
2834 | RETVAL = to_sv (f->name); |
|
|
2835 | OUTPUT: |
|
|
2836 | RETVAL |
|
|
2837 | |
2772 | void invalidate (faceidx idx) |
2838 | void invalidate (faceidx idx) |
2773 | CODE: |
2839 | CODE: |
2774 | for_all_clients (ns) |
2840 | for_all_clients (ns) |
2775 | { |
2841 | ns->invalidate_face (idx); |
2776 | ns->faces_sent [idx] = false; |
|
|
2777 | ns->force_newmap = true; |
|
|
2778 | } |
|
|
2779 | |
2842 | |
2780 | void invalidate_all () |
2843 | void invalidate_all () |
2781 | CODE: |
2844 | CODE: |
2782 | for_all_clients (ns) |
2845 | for_all_clients (ns) |
2783 | { |
2846 | ns->invalidate_all_faces (); |
2784 | ns->faces_sent.reset (); |
|
|
2785 | ns->force_newmap = true; |
|
|
2786 | } |
|
|
2787 | |
2847 | |
2788 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2848 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2789 | |
2849 | |
2790 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2850 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2791 | |
2851 | |
… | |
… | |
2795 | OUTPUT: RETVAL |
2855 | OUTPUT: RETVAL |
2796 | |
2856 | |
2797 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2857 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2798 | CODE: |
2858 | CODE: |
2799 | { |
2859 | { |
2800 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2860 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2801 | croak ("frames must be an arrayref"); |
2861 | croak ("frames must be an arrayref"); |
2802 | |
2862 | |
2803 | AV *av = (AV *)SvRV (frames); |
2863 | AV *av = (AV *)SvRV (frames); |
2804 | |
2864 | |
2805 | animation *anim = &animation::find (name); |
2865 | animation *anim = &animation::find (name); |
2806 | if (anim->number) |
2866 | if (anim->number) |
2807 | { |
2867 | { |
2808 | anim->resize (av_len (av) + 1); |
2868 | anim->resize (av_len (av) + 1); |
2809 | anim->facings = facings; |
2869 | anim->facings = facings; |
2810 | } |
2870 | } |
… | |
… | |
2882 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2942 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2883 | |
2943 | |
2884 | self->skip (); |
2944 | self->skip (); |
2885 | } |
2945 | } |
2886 | |
2946 | |
|
|
2947 | MODULE = cf PACKAGE = cf::treasurelist |
|
|
2948 | |
|
|
2949 | # quick hack, because I didn't want to implement accessors for treasurelist. |
|
|
2950 | # this asks for even more autogen, actually. |
|
|
2951 | |
|
|
2952 | void |
|
|
2953 | expand (treasurelist *list) |
|
|
2954 | PPCODE: |
|
|
2955 | EXTEND (SP, 3); |
|
|
2956 | PUSHs (sv_2mortal (to_sv (list->name))); |
|
|
2957 | PUSHs (sv_2mortal (to_sv (list->total_chance))); |
|
|
2958 | AV *av = newAV (); |
|
|
2959 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
2960 | for (treasure *item = list->items; item; item = item->next) |
|
|
2961 | { |
|
|
2962 | AV *iav = newAV (); |
|
|
2963 | av_push (av, newRV_noinc ((SV *)iav)); |
|
|
2964 | |
|
|
2965 | av_extend (iav, 7); |
|
|
2966 | av_push (iav, to_sv (item->item)); |
|
|
2967 | av_push (iav, to_sv (item->name)); |
|
|
2968 | av_push (iav, to_sv (item->change_arch.name)); |
|
|
2969 | av_push (iav, to_sv (item->change_arch.title)); |
|
|
2970 | av_push (iav, to_sv (item->change_arch.slaying)); |
|
|
2971 | av_push (iav, to_sv (item->chance)); |
|
|
2972 | av_push (iav, to_sv (item->nrof)); |
|
|
2973 | av_push (iav, to_sv (item->magic)); |
|
|
2974 | } |
|
|
2975 | |
2887 | MODULE = cf PACKAGE = cf::layout |
2976 | MODULE = cf PACKAGE = cf::layout |
2888 | |
2977 | |
2889 | INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
2978 | INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
2890 | |
2979 | |