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 | |
… | |
… | |
29 | #include <cstdarg> |
29 | #include <cstdarg> |
30 | #include <typeinfo> |
30 | #include <typeinfo> |
31 | |
31 | |
32 | #include "global.h" |
32 | #include "global.h" |
33 | #include "rmg.h" |
33 | #include "rmg.h" |
|
|
34 | #include "noise.h" |
34 | #include "evthread.h" |
35 | #include "evthread.h" |
35 | #include "sproto.h" |
36 | #include "sproto.h" |
36 | |
37 | |
37 | #include <unistd.h> |
38 | #include <unistd.h> |
38 | #if _POSIX_MEMLOCK |
39 | #if _POSIX_MEMLOCK |
… | |
… | |
66 | static int tick_inhibit; |
67 | static int tick_inhibit; |
67 | static int tick_pending; |
68 | static int tick_pending; |
68 | |
69 | |
69 | global gbl_ev; |
70 | global gbl_ev; |
70 | 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; |
71 | 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; |
72 | static AV *av_reflect; |
73 | static AV *av_reflect; |
73 | |
74 | |
74 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_TYPES> ev_want_type; |
76 | bitset<NUM_TYPES> ev_want_type; |
76 | |
77 | |
… | |
… | |
252 | { |
253 | { |
253 | static int last_mortalcount; |
254 | static int last_mortalcount; |
254 | if (mortals.size () != last_mortalcount) |
255 | if (mortals.size () != last_mortalcount) |
255 | { |
256 | { |
256 | last_mortalcount = mortals.size (); |
257 | last_mortalcount = mortals.size (); |
257 | LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); |
258 | object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
|
|
259 | |
|
|
260 | LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
|
|
261 | (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
258 | |
262 | |
259 | if (0) |
263 | if (0) |
260 | { |
264 | { |
261 | for (int j = 0; j < mortals.size (); ++j)//D |
265 | for (int j = 0; j < mortals.size (); ++j)//D |
262 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
266 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
… | |
… | |
621 | STRLEN len; |
625 | STRLEN len; |
622 | char *data = SvPVbyte (sv, len); |
626 | char *data = SvPVbyte (sv, len); |
623 | v.assign (data, len); |
627 | v.assign (data, len); |
624 | } |
628 | } |
625 | |
629 | |
|
|
630 | static inline void sv_to (SV *sv, refcnt_buf &v) |
|
|
631 | { |
|
|
632 | STRLEN len; |
|
|
633 | char *data = SvPVbyte (sv, len); |
|
|
634 | refcnt_buf buf (data, len); |
|
|
635 | v = buf; |
|
|
636 | } |
|
|
637 | |
626 | static inline void sv_to (SV *sv, UUID &v) |
638 | static inline void sv_to (SV *sv, UUID &v) |
627 | { |
639 | { |
628 | if (!v.parse (SvPV_nolen (sv))) |
640 | if (!v.parse (SvPV_nolen (sv))) |
629 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
641 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
630 | } |
642 | } |
… | |
… | |
1403 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1415 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1404 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1416 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1405 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1417 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1406 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1418 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1407 | |
1419 | |
1408 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1420 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1409 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1421 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1422 | sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1410 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1423 | sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV); |
1411 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1424 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1412 | |
1425 | |
1413 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1426 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1414 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1427 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1415 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1428 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1416 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1429 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1437 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1450 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1438 | |
1451 | |
1439 | _connect_to_perl_1 (); |
1452 | _connect_to_perl_1 (); |
1440 | |
1453 | |
1441 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1454 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1442 | |
|
|
1443 | //{ |
|
|
1444 | // require_pv ("Time::HiRes"); |
|
|
1445 | // |
|
|
1446 | // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
|
|
1447 | // if (!svp) croak ("Time::HiRes is required"); |
|
|
1448 | // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); |
|
|
1449 | // coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); |
|
|
1450 | //} |
|
|
1451 | |
1455 | |
1452 | static const struct { |
1456 | static const struct { |
1453 | const char *name; |
1457 | const char *name; |
1454 | IV iv; |
1458 | IV iv; |
1455 | } *civ, const_iv[] = { |
1459 | } *civ, const_iv[] = { |
… | |
… | |
1485 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1489 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1486 | |
1490 | |
1487 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1491 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1488 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1492 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1489 | |
1493 | |
1490 | const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
|
|
1491 | const_iv (MAP_INACTIVE) |
|
|
1492 | |
|
|
1493 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1494 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1494 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1495 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1495 | |
1496 | |
1496 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1497 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1497 | |
1498 | |
… | |
… | |
1529 | |
1530 | |
1530 | void _gv_clear (SV *gv) |
1531 | void _gv_clear (SV *gv) |
1531 | CODE: |
1532 | CODE: |
1532 | assert (SvTYPE (gv) == SVt_PVGV); |
1533 | assert (SvTYPE (gv) == SVt_PVGV); |
1533 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
1534 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
|
|
1535 | SvREFCNT_inc (gv); |
1534 | f (GvGP (gv)->gp_form); |
1536 | f (GvGP (gv)->gp_form); |
1535 | f (GvGP (gv)->gp_io); |
1537 | f (GvGP (gv)->gp_io); |
1536 | f (GvGP (gv)->gp_sv); |
1538 | f (GvGP (gv)->gp_sv); |
1537 | f (GvGP (gv)->gp_av); |
1539 | f (GvGP (gv)->gp_av); |
1538 | f (GvGP (gv)->gp_hv); |
1540 | f (GvGP (gv)->gp_hv); |
1539 | f (GvGP (gv)->gp_cv); |
1541 | f (GvGP (gv)->gp_cv); |
1540 | GvCVGEN (gv) = 0; |
1542 | GvCVGEN (gv) = 0; |
1541 | GvMULTI_off (gv); |
1543 | GvMULTI_off (gv); |
|
|
1544 | SvREFCNT_dec (gv); |
1542 | # undef f |
1545 | # undef f |
1543 | |
1546 | |
1544 | void _connect_to_perl_1 () |
1547 | void _connect_to_perl_1 () |
1545 | |
1548 | |
1546 | void _connect_to_perl_2 () |
1549 | void _connect_to_perl_2 () |
… | |
… | |
1557 | |
1560 | |
1558 | for_all_objects (op) |
1561 | for_all_objects (op) |
1559 | op->reattach (); |
1562 | op->reattach (); |
1560 | } |
1563 | } |
1561 | |
1564 | |
1562 | # support function for map-world.ext |
|
|
1563 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1564 | CODE: |
|
|
1565 | { |
|
|
1566 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1567 | croak ("_quantise called with invalid agruments"); |
|
|
1568 | |
|
|
1569 | plt_sv = SvRV (plt_sv); |
|
|
1570 | SV **plt = AvARRAY (plt_sv); |
|
|
1571 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1572 | |
|
|
1573 | STRLEN len; |
|
|
1574 | char *data = SvPVbyte (data_sv, len); |
|
|
1575 | char *dst = data; |
|
|
1576 | |
|
|
1577 | while (len >= 3) |
|
|
1578 | { |
|
|
1579 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1580 | { |
|
|
1581 | char *val = SvPVX (*val_sv); |
|
|
1582 | |
|
|
1583 | if (val [0] == data [0] |
|
|
1584 | && val [1] == data [1] |
|
|
1585 | && val [2] == data [2]) |
|
|
1586 | { |
|
|
1587 | *dst++ = val [3]; |
|
|
1588 | goto next; |
|
|
1589 | } |
|
|
1590 | } |
|
|
1591 | |
|
|
1592 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1593 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1594 | dst - SvPVX (data_sv), len); |
|
|
1595 | |
|
|
1596 | next: |
|
|
1597 | data += 3; |
|
|
1598 | len -= 3; |
|
|
1599 | } |
|
|
1600 | |
|
|
1601 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1602 | } |
|
|
1603 | |
|
|
1604 | void init_anim () |
1565 | void init_anim () |
1605 | |
1566 | |
1606 | void init_globals () |
1567 | void init_globals () |
1607 | |
1568 | |
1608 | void init_attackmess () |
1569 | void init_attackmess () |
1609 | |
1570 | |
1610 | void init_dynamic () |
1571 | void init_dynamic () |
1611 | |
1572 | |
1612 | void load_settings () |
1573 | void load_settings () |
1613 | |
1574 | |
1614 | void reload_exp_table () |
1575 | void _reload_exp_table () |
1615 | |
1576 | |
1616 | void reload_materials () |
1577 | void _reload_materials () |
1617 | |
1578 | |
1618 | void init_uuid () |
1579 | void init_uuid () |
1619 | CODE: |
1580 | CODE: |
1620 | UUID::init (); |
1581 | UUID::init (); |
1621 | |
1582 | |
… | |
… | |
1654 | { |
1615 | { |
1655 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1616 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1656 | coroapi::cede (); |
1617 | coroapi::cede (); |
1657 | } |
1618 | } |
1658 | |
1619 | |
1659 | void server_tick () |
1620 | void one_tick () |
1660 | CODE: |
1621 | CODE: |
1661 | { |
1622 | { |
1662 | ev_now_update (EV_DEFAULT); |
1623 | ev_now_update (EV_DEFAULT); |
1663 | NOW = ev_now (EV_DEFAULT); |
1624 | NOW = ev_now (EV_DEFAULT); |
1664 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1625 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1665 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1626 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1666 | runtime = SvNVX (sv_runtime); |
1627 | runtime = SvNVX (sv_runtime); |
1667 | |
1628 | |
|
|
1629 | one_tick (); |
|
|
1630 | |
1668 | server_tick (); |
1631 | ++server_tick; |
|
|
1632 | SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1669 | |
1633 | |
1670 | ev_now_update (EV_DEFAULT); |
1634 | ev_now_update (EV_DEFAULT); |
1671 | NOW = ev_now (EV_DEFAULT); |
1635 | NOW = ev_now (EV_DEFAULT); |
1672 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1636 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1637 | |
1673 | runtime += TICK; |
1638 | runtime += TICK; |
1674 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1639 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1675 | } |
1640 | } |
1676 | |
1641 | |
1677 | NV floor (NV x) |
1642 | NV floor (NV x) |
… | |
… | |
1826 | |
1791 | |
1827 | int exp_to_level (val64 exp) |
1792 | int exp_to_level (val64 exp) |
1828 | |
1793 | |
1829 | val64 level_to_min_exp (int level) |
1794 | val64 level_to_min_exp (int level) |
1830 | |
1795 | |
|
|
1796 | const_utf8_string |
|
|
1797 | spellpathnames (int idx) |
|
|
1798 | CODE: |
|
|
1799 | RETVAL = spellpathnames [idx]; |
|
|
1800 | OUTPUT: RETVAL |
|
|
1801 | |
1831 | SV * |
1802 | SV * |
1832 | attacktype_name (int atnr) |
1803 | attacktype_name (int atnr) |
1833 | CODE: |
1804 | CODE: |
1834 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1805 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1835 | ? newSVpv (attacktype_name [atnr], 0) |
1806 | ? newSVpv (attacktype_name [atnr], 0) |
… | |
… | |
2144 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2115 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2145 | |
2116 | |
2146 | object *new (utf8_string archetype = 0) |
2117 | object *new (utf8_string archetype = 0) |
2147 | PROTOTYPE: ;$ |
2118 | PROTOTYPE: ;$ |
2148 | CODE: |
2119 | CODE: |
2149 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
2120 | RETVAL = archetype |
|
|
2121 | ? archetype::get (archetype) |
|
|
2122 | : object::create (); |
2150 | OUTPUT: |
2123 | OUTPUT: |
2151 | RETVAL |
2124 | RETVAL |
2152 | |
2125 | |
2153 | object *generate (utf8_string arch, object *creator) |
2126 | object *generate (utf8_string arch, object *creator) |
2154 | CODE: |
2127 | CODE: |
2155 | object *obj = get_archetype (arch); |
2128 | object *obj = archetype::get (arch); |
2156 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2129 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2157 | RETVAL = obj; |
2130 | RETVAL = obj; |
2158 | OUTPUT: |
2131 | OUTPUT: |
2159 | RETVAL |
2132 | RETVAL |
2160 | |
2133 | |
… | |
… | |
2170 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2143 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2171 | |
2144 | |
2172 | if (RETVAL->destroyed ()) |
2145 | if (RETVAL->destroyed ()) |
2173 | RETVAL = 0; |
2146 | RETVAL = 0; |
2174 | } |
2147 | } |
|
|
2148 | OUTPUT: |
|
|
2149 | RETVAL |
2175 | |
2150 | |
2176 | shstr |
2151 | shstr |
2177 | object::kv_get (shstr key) |
2152 | object::kv_get (shstr key) |
|
|
2153 | CODE: |
|
|
2154 | RETVAL = THIS->kv.get (key); |
|
|
2155 | OUTPUT: |
|
|
2156 | RETVAL |
2178 | |
2157 | |
2179 | void |
2158 | void |
2180 | object::kv_del (shstr key) |
2159 | object::kv_del (shstr key) |
|
|
2160 | CODE: |
|
|
2161 | THIS->kv.del (key); |
2181 | |
2162 | |
2182 | void |
2163 | void |
2183 | object::kv_set (shstr key, shstr value) |
2164 | object::kv_set (shstr key, shstr value) |
|
|
2165 | CODE: |
|
|
2166 | THIS->kv.set (key, value); |
2184 | |
2167 | |
2185 | object *get_nearest_player (object *ob) |
2168 | object *get_nearest_player (object *ob) |
2186 | ALIAS: nearest_player = 0 |
2169 | ALIAS: nearest_player = 0 |
2187 | PREINIT: |
2170 | PREINIT: |
2188 | extern object *get_nearest_player (object *); |
2171 | extern object *get_nearest_player (object *); |
… | |
… | |
2391 | if (pl->ob && pl->ob->map == THIS) |
2374 | if (pl->ob && pl->ob->map == THIS) |
2392 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2375 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2393 | } |
2376 | } |
2394 | |
2377 | |
2395 | void |
2378 | void |
|
|
2379 | maptile::gen_quadmap (int x, int y, int z) |
|
|
2380 | CODE: |
|
|
2381 | gen_quadmap (THIS, x * 50, y * 50, z); |
|
|
2382 | |
|
|
2383 | void |
2396 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2384 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2397 | CODE: |
2385 | CODE: |
2398 | { |
2386 | { |
2399 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2387 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2400 | croak ("maptile::add_underlay: palette must be arrayref"); |
2388 | croak ("maptile::add_underlay: palette must be arrayref"); |
… | |
… | |
2416 | |
2404 | |
2417 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2405 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2418 | { |
2406 | { |
2419 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2407 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2420 | { |
2408 | { |
2421 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
2409 | object *ob = archetype::get (cfSvPVutf8_nolen (*elem)); |
2422 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2410 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2423 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2411 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2424 | |
2412 | |
2425 | if (ob->randomitems && !ob->above) |
2413 | if (ob->randomitems && !ob->above) |
2426 | { |
2414 | { |
… | |
… | |
2430 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2418 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2431 | // TODO: if this is a pickable object, then the item |
2419 | // TODO: if this is a pickable object, then the item |
2432 | // will at a bit weird - saving inside the player |
2420 | // will at a bit weird - saving inside the player |
2433 | // will clear the flag, but when the player drops |
2421 | // will clear the flag, but when the player drops |
2434 | // it without logging out, it keeps the flag. |
2422 | // it without logging out, it keeps the flag. |
2435 | // nobody ahs reported this, but this can be rather |
2423 | // nobody has reported this, but this can be rather |
2436 | // annoying on persistent maps. |
2424 | // annoying on persistent maps. |
2437 | } |
2425 | } |
2438 | } |
2426 | } |
2439 | } |
2427 | } |
2440 | } |
2428 | } |
2441 | |
|
|
2442 | skip: ; |
2429 | skip: ; |
2443 | } |
2430 | } |
2444 | } |
2431 | } |
2445 | |
2432 | |
2446 | void |
2433 | void |
… | |
… | |
2477 | for (int x = 0; x < THIS->width; ++x) |
2464 | for (int x = 0; x < THIS->width; ++x) |
2478 | for (int y = 0; y < THIS->height; ++y) |
2465 | for (int y = 0; y < THIS->height; ++y) |
2479 | { |
2466 | { |
2480 | region *rgn = THIS->region (x, y); |
2467 | region *rgn = THIS->region (x, y); |
2481 | |
2468 | |
2482 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2483 | if (object *op = THIS->at (x, y).top) |
2469 | if (object *op = THIS->at (x, y).top) |
2484 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2470 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2485 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2471 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2486 | } |
2472 | } |
2487 | |
2473 | |
… | |
… | |
2591 | archetype *archetypes (U32 index) |
2577 | archetype *archetypes (U32 index) |
2592 | CODE: |
2578 | CODE: |
2593 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2579 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2594 | OUTPUT: RETVAL |
2580 | OUTPUT: RETVAL |
2595 | |
2581 | |
|
|
2582 | int skillvec_size () |
|
|
2583 | CODE: |
|
|
2584 | RETVAL = skillvec.size (); |
|
|
2585 | OUTPUT: RETVAL |
|
|
2586 | |
|
|
2587 | archetype *skillvec (U32 index) |
|
|
2588 | CODE: |
|
|
2589 | RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0; |
|
|
2590 | OUTPUT: RETVAL |
|
|
2591 | |
2596 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2592 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2597 | |
2593 | |
2598 | MODULE = cf PACKAGE = cf::party |
2594 | MODULE = cf PACKAGE = cf::party |
2599 | |
2595 | |
2600 | partylist *first () |
2596 | partylist *first () |
… | |
… | |
2648 | list () |
2644 | list () |
2649 | PPCODE: |
2645 | PPCODE: |
2650 | EXTEND (SP, clients.size ()); |
2646 | EXTEND (SP, clients.size ()); |
2651 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2647 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2652 | PUSHs (sv_2mortal (to_sv (*i))); |
2648 | PUSHs (sv_2mortal (to_sv (*i))); |
|
|
2649 | |
|
|
2650 | STRLEN |
|
|
2651 | client::inbuf_append (SV *data) |
|
|
2652 | CODE: |
|
|
2653 | { |
|
|
2654 | STRLEN len; |
|
|
2655 | char *ptr = SvPVbyte (data, len); |
|
|
2656 | |
|
|
2657 | min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len); |
|
|
2658 | memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len); |
|
|
2659 | THIS->inbuf_len += len; |
|
|
2660 | |
|
|
2661 | THIS->inbuf_handle (); |
|
|
2662 | |
|
|
2663 | RETVAL = len; |
|
|
2664 | } |
|
|
2665 | OUTPUT: RETVAL |
2653 | |
2666 | |
2654 | void |
2667 | void |
2655 | client::send_packet (SV *packet) |
2668 | client::send_packet (SV *packet) |
2656 | CODE: |
2669 | CODE: |
2657 | { |
2670 | { |
… | |
… | |
2713 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2726 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2714 | |
2727 | |
2715 | faceidx alloc (utf8_string name) |
2728 | faceidx alloc (utf8_string name) |
2716 | CODE: |
2729 | CODE: |
2717 | { |
2730 | { |
2718 | do |
2731 | RETVAL = face_alloc (); |
2719 | { |
|
|
2720 | RETVAL = faces.size (); |
|
|
2721 | faces.resize (RETVAL + 1); |
|
|
2722 | } |
|
|
2723 | while (!RETVAL); // crude way to leave index 0 |
|
|
2724 | |
2732 | |
2725 | faces [RETVAL].name = name; |
2733 | faces [RETVAL].name = name; |
2726 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2734 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2727 | |
2735 | |
2728 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2736 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2729 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2737 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2730 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2738 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2731 | } |
2739 | } |
|
|
2740 | OUTPUT: RETVAL |
|
|
2741 | |
|
|
2742 | faceidx faces_size () |
|
|
2743 | CODE: |
|
|
2744 | RETVAL = faces.size (); |
2732 | OUTPUT: RETVAL |
2745 | OUTPUT: RETVAL |
2733 | |
2746 | |
2734 | void set_type (faceidx idx, int value) |
2747 | void set_type (faceidx idx, int value) |
2735 | ALIAS: |
2748 | ALIAS: |
2736 | set_type = 0 |
2749 | set_type = 0 |
… | |
… | |
2755 | faceinfo *f = face_info (idx); assert (f); |
2768 | faceinfo *f = face_info (idx); assert (f); |
2756 | facedata *d = f->face + faceset; |
2769 | facedata *d = f->face + faceset; |
2757 | sv_to (data, d->data); |
2770 | sv_to (data, d->data); |
2758 | STRLEN clen; |
2771 | STRLEN clen; |
2759 | char *cdata = SvPVbyte (chksum, clen); |
2772 | char *cdata = SvPVbyte (chksum, clen); |
2760 | clen = min (CHKSUM_MAXLEN, clen); |
|
|
2761 | |
2773 | |
|
|
2774 | assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN)); |
2762 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2775 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2763 | |
2776 | |
2764 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2777 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2765 | { |
2778 | { |
2766 | d->chksum_len = clen; |
2779 | d->chksum_len = clen; |
2767 | memcpy (d->chksum, cdata, clen); |
2780 | memcpy (d->chksum, cdata, clen); |
2768 | |
2781 | |
2769 | // invalidate existing client face info |
2782 | // invalidate existing client face info |
2770 | for_all_clients (ns) |
2783 | for_all_clients (ns) |
2771 | if (ns->faceset == faceset) |
2784 | ns->invalidate_face (idx); |
2772 | { |
|
|
2773 | ns->faces_sent [idx] = false; |
|
|
2774 | ns->force_newmap = true; |
|
|
2775 | } |
|
|
2776 | } |
2785 | } |
2777 | } |
2786 | } |
2778 | |
2787 | |
2779 | int get_data_size (faceidx idx, int faceset = 0) |
2788 | int get_data_size (faceidx idx, int faceset = 0) |
2780 | CODE: |
2789 | CODE: |
… | |
… | |
2782 | if (!d) XSRETURN_UNDEF; |
2791 | if (!d) XSRETURN_UNDEF; |
2783 | RETVAL = d->data.size (); |
2792 | RETVAL = d->data.size (); |
2784 | OUTPUT: |
2793 | OUTPUT: |
2785 | RETVAL |
2794 | RETVAL |
2786 | |
2795 | |
|
|
2796 | void set_meta (faceidx idx, SV *sv) |
|
|
2797 | CODE: |
|
|
2798 | { |
|
|
2799 | faceinfo *f = face_info (idx); assert (f); |
|
|
2800 | SvREFCNT_dec (f->meta_hv); |
|
|
2801 | f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0; |
|
|
2802 | } |
|
|
2803 | |
|
|
2804 | SV *mangle_chksum (SV *chksum) |
|
|
2805 | CODE: |
|
|
2806 | STRLEN len; |
|
|
2807 | char *data = SvPVbyte (chksum, len); |
|
|
2808 | RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN)); |
|
|
2809 | OUTPUT: |
|
|
2810 | RETVAL |
|
|
2811 | |
2787 | SV *get_chksum (faceidx idx, int faceset = 0) |
2812 | SV *get_chksum (faceidx idx, int faceset = 0) |
2788 | CODE: |
2813 | CODE: |
2789 | facedata *d = face_data (idx, faceset); |
2814 | facedata *d = face_data (idx, faceset); |
2790 | if (!d) XSRETURN_UNDEF; |
2815 | if (!d) XSRETURN_UNDEF; |
2791 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2816 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2792 | OUTPUT: |
2817 | OUTPUT: |
2793 | RETVAL |
2818 | RETVAL |
2794 | |
2819 | |
|
|
2820 | int get_type (faceidx idx) |
|
|
2821 | CODE: |
|
|
2822 | faceinfo *f = face_info (idx); |
|
|
2823 | if (!f) XSRETURN_UNDEF; |
|
|
2824 | RETVAL = f->type; |
|
|
2825 | OUTPUT: |
|
|
2826 | RETVAL |
|
|
2827 | |
|
|
2828 | SV *get_name (faceidx idx) |
|
|
2829 | CODE: |
|
|
2830 | faceinfo *f = face_info (idx); |
|
|
2831 | if (!f) XSRETURN_UNDEF; |
|
|
2832 | RETVAL = to_sv (f->name); |
|
|
2833 | OUTPUT: |
|
|
2834 | RETVAL |
|
|
2835 | |
2795 | SV *get_data (faceidx idx, int faceset = 0) |
2836 | SV *get_data (faceidx idx, int faceset = 0) |
2796 | CODE: |
2837 | CODE: |
2797 | facedata *d = face_data (idx, faceset); |
2838 | facedata *d = face_data (idx, faceset); |
2798 | if (!d) XSRETURN_UNDEF; |
2839 | if (!d) XSRETURN_UNDEF; |
2799 | RETVAL = newSVpvn (d->data.data (), d->data.length ()); |
2840 | RETVAL = newSVpvn (d->data, d->data.size ()); |
2800 | OUTPUT: |
2841 | OUTPUT: |
2801 | RETVAL |
2842 | RETVAL |
2802 | |
2843 | |
|
|
2844 | SV *get_meta (faceidx idx) |
|
|
2845 | CODE: |
|
|
2846 | faceinfo *f = face_info (idx); assert (f); |
|
|
2847 | if (!f || !f->meta_hv) XSRETURN_UNDEF; |
|
|
2848 | RETVAL = newRV_inc ((SV *)f->meta_hv); |
|
|
2849 | OUTPUT: |
|
|
2850 | RETVAL |
|
|
2851 | |
2803 | void invalidate (faceidx idx) |
2852 | void invalidate (faceidx idx) |
2804 | CODE: |
2853 | CODE: |
2805 | for_all_clients (ns) |
2854 | for_all_clients (ns) |
2806 | { |
2855 | ns->invalidate_face (idx); |
2807 | ns->faces_sent [idx] = false; |
|
|
2808 | ns->force_newmap = true; |
|
|
2809 | } |
|
|
2810 | |
2856 | |
2811 | void invalidate_all () |
2857 | void invalidate_all () |
2812 | CODE: |
2858 | CODE: |
2813 | for_all_clients (ns) |
2859 | for_all_clients (ns) |
2814 | { |
2860 | ns->invalidate_all_faces (); |
2815 | ns->faces_sent.reset (); |
|
|
2816 | ns->force_newmap = true; |
|
|
2817 | } |
|
|
2818 | |
2861 | |
2819 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2862 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2820 | |
2863 | |
2821 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2864 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2822 | |
2865 | |
… | |
… | |
2826 | OUTPUT: RETVAL |
2869 | OUTPUT: RETVAL |
2827 | |
2870 | |
2828 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2871 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2829 | CODE: |
2872 | CODE: |
2830 | { |
2873 | { |
2831 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2874 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2832 | croak ("frames must be an arrayref"); |
2875 | croak ("frames must be an arrayref"); |
2833 | |
2876 | |
2834 | AV *av = (AV *)SvRV (frames); |
2877 | AV *av = (AV *)SvRV (frames); |
2835 | |
2878 | |
2836 | animation *anim = &animation::find (name); |
2879 | animation *anim = &animation::find (name); |
2837 | if (anim->number) |
2880 | if (anim->number) |
2838 | { |
2881 | { |
2839 | anim->resize (av_len (av) + 1); |
2882 | anim->resize (av_len (av) + 1); |
2840 | anim->facings = facings; |
2883 | anim->facings = facings; |
2841 | } |
2884 | } |