… | |
… | |
28 | |
28 | |
29 | #include <cstdarg> |
29 | #include <cstdarg> |
30 | #include <typeinfo> |
30 | #include <typeinfo> |
31 | |
31 | |
32 | #include "global.h" |
32 | #include "global.h" |
33 | #include "../random_maps/random_map.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 | |
… | |
… | |
84 | *stash_cf_client_wrap, |
85 | *stash_cf_client_wrap, |
85 | *stash_cf_arch_wrap, |
86 | *stash_cf_arch_wrap, |
86 | *stash_cf_party_wrap, |
87 | *stash_cf_party_wrap, |
87 | *stash_cf_region_wrap, |
88 | *stash_cf_region_wrap, |
88 | *stash_cf_living_wrap, |
89 | *stash_cf_living_wrap, |
|
|
90 | *stash_cf_layout_wrap, |
89 | *stash_ext_map_world; |
91 | *stash_ext_map_world; |
90 | |
92 | |
91 | static SV |
93 | static SV |
92 | *cv_cf_do_invoke, |
94 | *cv_cf_do_invoke, |
93 | *cv_cf__can_merge, |
95 | *cv_cf__can_merge, |
… | |
… | |
251 | { |
253 | { |
252 | static int last_mortalcount; |
254 | static int last_mortalcount; |
253 | if (mortals.size () != last_mortalcount) |
255 | if (mortals.size () != last_mortalcount) |
254 | { |
256 | { |
255 | last_mortalcount = mortals.size (); |
257 | last_mortalcount = mortals.size (); |
256 | 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)"); |
257 | |
262 | |
258 | if (0) |
263 | if (0) |
259 | { |
264 | { |
260 | for (int j = 0; j < mortals.size (); ++j)//D |
265 | for (int j = 0; j < mortals.size (); ++j)//D |
261 | 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 |
… | |
… | |
539 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
544 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
540 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
545 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
541 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
546 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
542 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
547 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
543 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
548 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
|
|
549 | static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); } |
544 | |
550 | |
545 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
551 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
546 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
552 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
547 | |
553 | |
548 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
554 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
… | |
… | |
594 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
600 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
595 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
601 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
596 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
602 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
597 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
603 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
598 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
604 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
|
|
605 | static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); } |
599 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
606 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
600 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
607 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
601 | |
608 | |
602 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
609 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
603 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
610 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
… | |
… | |
1397 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1404 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1398 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1405 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1399 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1406 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1400 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1407 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1401 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1408 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
|
|
1409 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1402 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1410 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1403 | |
1411 | |
1404 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1412 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1405 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1413 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1414 | sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1406 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1415 | sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV); |
1407 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1416 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1408 | |
1417 | |
1409 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1418 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1410 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1419 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1411 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1420 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1412 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1421 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1455 | # include "attackinc.h" |
1464 | # include "attackinc.h" |
1456 | # undef def |
1465 | # undef def |
1457 | # define def(uc, flags) const_iv (SK_ ## uc) |
1466 | # define def(uc, flags) const_iv (SK_ ## uc) |
1458 | # include "skillinc.h" |
1467 | # include "skillinc.h" |
1459 | # undef def |
1468 | # undef def |
1460 | |
1469 | # define def(name, use, nonuse) const_iv (body_ ## name) |
1461 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1470 | # include "slotinc.h" |
|
|
1471 | # undef def |
1462 | |
1472 | |
1463 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1473 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1464 | |
1474 | |
1465 | const_iv (MAX_TIME) |
1475 | const_iv (MAX_TIME) |
1466 | const_iv (MAXSOCKBUF) |
1476 | const_iv (MAXSOCKBUF) |
… | |
… | |
1479 | |
1489 | |
1480 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1490 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1481 | |
1491 | |
1482 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1492 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1483 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1493 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1484 | |
|
|
1485 | const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
|
|
1486 | const_iv (MAP_INACTIVE) |
|
|
1487 | |
1494 | |
1488 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1495 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1489 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1496 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1490 | |
1497 | |
1491 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1498 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
… | |
… | |
1552 | |
1559 | |
1553 | for_all_objects (op) |
1560 | for_all_objects (op) |
1554 | op->reattach (); |
1561 | op->reattach (); |
1555 | } |
1562 | } |
1556 | |
1563 | |
1557 | # support function for map-world.ext |
|
|
1558 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1559 | CODE: |
|
|
1560 | { |
|
|
1561 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1562 | croak ("_quantise called with invalid agruments"); |
|
|
1563 | |
|
|
1564 | plt_sv = SvRV (plt_sv); |
|
|
1565 | SV **plt = AvARRAY (plt_sv); |
|
|
1566 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1567 | |
|
|
1568 | STRLEN len; |
|
|
1569 | char *data = SvPVbyte (data_sv, len); |
|
|
1570 | char *dst = data; |
|
|
1571 | |
|
|
1572 | while (len >= 3) |
|
|
1573 | { |
|
|
1574 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1575 | { |
|
|
1576 | char *val = SvPVX (*val_sv); |
|
|
1577 | |
|
|
1578 | if (val [0] == data [0] |
|
|
1579 | && val [1] == data [1] |
|
|
1580 | && val [2] == data [2]) |
|
|
1581 | { |
|
|
1582 | *dst++ = val [3]; |
|
|
1583 | goto next; |
|
|
1584 | } |
|
|
1585 | } |
|
|
1586 | |
|
|
1587 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1588 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1589 | dst - SvPVX (data_sv), len); |
|
|
1590 | |
|
|
1591 | next: |
|
|
1592 | data += 3; |
|
|
1593 | len -= 3; |
|
|
1594 | } |
|
|
1595 | |
|
|
1596 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1597 | } |
|
|
1598 | |
|
|
1599 | void init_anim () |
1564 | void init_anim () |
1600 | |
1565 | |
1601 | void init_globals () |
1566 | void init_globals () |
1602 | |
1567 | |
1603 | void init_attackmess () |
1568 | void init_attackmess () |
… | |
… | |
1649 | { |
1614 | { |
1650 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1615 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1651 | coroapi::cede (); |
1616 | coroapi::cede (); |
1652 | } |
1617 | } |
1653 | |
1618 | |
1654 | void server_tick () |
1619 | void one_tick () |
1655 | CODE: |
1620 | CODE: |
1656 | { |
1621 | { |
1657 | ev_now_update (EV_DEFAULT); |
1622 | ev_now_update (EV_DEFAULT); |
1658 | NOW = ev_now (EV_DEFAULT); |
1623 | NOW = ev_now (EV_DEFAULT); |
1659 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1624 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1660 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1625 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1661 | runtime = SvNVX (sv_runtime); |
1626 | runtime = SvNVX (sv_runtime); |
1662 | |
1627 | |
|
|
1628 | one_tick (); |
|
|
1629 | |
1663 | server_tick (); |
1630 | ++server_tick; |
|
|
1631 | SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1664 | |
1632 | |
1665 | ev_now_update (EV_DEFAULT); |
1633 | ev_now_update (EV_DEFAULT); |
1666 | NOW = ev_now (EV_DEFAULT); |
1634 | NOW = ev_now (EV_DEFAULT); |
1667 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1635 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1636 | |
1668 | runtime += TICK; |
1637 | runtime += TICK; |
1669 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1638 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1670 | } |
1639 | } |
1671 | |
1640 | |
1672 | NV floor (NV x) |
1641 | NV floor (NV x) |
… | |
… | |
1771 | |
1740 | |
1772 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1741 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1773 | INIT: |
1742 | INIT: |
1774 | #if __GLIBC__ |
1743 | #if __GLIBC__ |
1775 | mallopt (M_TOP_PAD, 1024 * 1024); |
1744 | mallopt (M_TOP_PAD, 1024 * 1024); |
1776 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); |
1745 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024); |
1777 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
1746 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
|
|
1747 | if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10)) |
1778 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1748 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1779 | #endif |
1749 | #endif |
1780 | |
1750 | |
1781 | int munlockall () |
1751 | int munlockall () |
1782 | |
1752 | |
1783 | #endif |
1753 | #endif |
… | |
… | |
1821 | int exp_to_level (val64 exp) |
1791 | int exp_to_level (val64 exp) |
1822 | |
1792 | |
1823 | val64 level_to_min_exp (int level) |
1793 | val64 level_to_min_exp (int level) |
1824 | |
1794 | |
1825 | SV * |
1795 | SV * |
1826 | resistance_to_string (int atnr) |
1796 | attacktype_name (int atnr) |
1827 | CODE: |
1797 | CODE: |
1828 | if (atnr >= 0 && atnr < NROFATTACKS) |
1798 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1799 | ? newSVpv (attacktype_name [atnr], 0) |
|
|
1800 | : &PL_sv_undef; |
|
|
1801 | OUTPUT: RETVAL |
|
|
1802 | |
|
|
1803 | SV * |
|
|
1804 | attacktype_desc (int atnr) |
|
|
1805 | CODE: |
|
|
1806 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1807 | ? newSVpv (attacktype_desc [atnr], 0) |
|
|
1808 | : &PL_sv_undef; |
|
|
1809 | OUTPUT: RETVAL |
|
|
1810 | |
|
|
1811 | SV * |
|
|
1812 | resist_plus (int atnr) |
|
|
1813 | CODE: |
|
|
1814 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1829 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1815 | ? newSVpv (resist_plus [atnr], 0) |
1830 | else |
1816 | : &PL_sv_undef; |
1831 | XSRETURN_UNDEF; |
1817 | OUTPUT: RETVAL |
|
|
1818 | |
|
|
1819 | SV * |
|
|
1820 | change_resist_msg (int atnr) |
|
|
1821 | CODE: |
|
|
1822 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1823 | ? newSVpv (change_resist_msg [atnr], 0) |
|
|
1824 | : &PL_sv_undef; |
1832 | OUTPUT: RETVAL |
1825 | OUTPUT: RETVAL |
1833 | |
1826 | |
1834 | UUID |
1827 | UUID |
1835 | uuid_cur () |
1828 | uuid_cur () |
1836 | CODE: |
1829 | CODE: |
… | |
… | |
1959 | int mortals_size () |
1952 | int mortals_size () |
1960 | CODE: |
1953 | CODE: |
1961 | RETVAL = attachable::mortals.size (); |
1954 | RETVAL = attachable::mortals.size (); |
1962 | OUTPUT: RETVAL |
1955 | OUTPUT: RETVAL |
1963 | |
1956 | |
1964 | const_utf8_string slot_use_name (U32 slot) |
1957 | const_utf8_string slot_name (U32 slot) |
1965 | ALIAS: |
1958 | ALIAS: |
|
|
1959 | slot_name = 0 |
|
|
1960 | slot_use_name = 1 |
1966 | slot_nonuse_name = 1 |
1961 | slot_nonuse_name = 2 |
1967 | CODE: |
1962 | CODE: |
1968 | { |
1963 | { |
1969 | if (slot >= NUM_BODY_LOCATIONS) |
1964 | if (slot >= NUM_BODY_LOCATIONS) |
1970 | croak ("body slot index out of range"); |
1965 | croak ("body slot index out of range"); |
1971 | |
1966 | |
1972 | switch (ix) |
1967 | switch (ix) |
1973 | { |
1968 | { |
|
|
1969 | case 0: RETVAL = body_locations[slot].name ; break; |
1974 | case 0: RETVAL = body_locations[slot].use_name; break; |
1970 | case 1: RETVAL = body_locations[slot].use_name ; break; |
1975 | case 1: RETVAL = body_locations[slot].nonuse_name; break; |
1971 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
1976 | } |
1972 | } |
1977 | } |
1973 | } |
1978 | OUTPUT: |
1974 | OUTPUT: |
1979 | RETVAL |
1975 | RETVAL |
1980 | |
1976 | |
… | |
… | |
2112 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2108 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2113 | |
2109 | |
2114 | object *new (utf8_string archetype = 0) |
2110 | object *new (utf8_string archetype = 0) |
2115 | PROTOTYPE: ;$ |
2111 | PROTOTYPE: ;$ |
2116 | CODE: |
2112 | CODE: |
2117 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
2113 | RETVAL = archetype |
|
|
2114 | ? archetype::get (archetype) |
|
|
2115 | : object::create (); |
2118 | OUTPUT: |
2116 | OUTPUT: |
2119 | RETVAL |
2117 | RETVAL |
2120 | |
2118 | |
2121 | object *generate (utf8_string arch, object *creator) |
2119 | object *generate (utf8_string arch, object *creator) |
2122 | CODE: |
2120 | CODE: |
2123 | object *obj = get_archetype (arch); |
2121 | object *obj = archetype::get (arch); |
2124 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2122 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2125 | RETVAL = obj; |
2123 | RETVAL = obj; |
2126 | OUTPUT: |
2124 | OUTPUT: |
2127 | RETVAL |
2125 | RETVAL |
2128 | |
2126 | |
… | |
… | |
2141 | RETVAL = 0; |
2139 | RETVAL = 0; |
2142 | } |
2140 | } |
2143 | |
2141 | |
2144 | shstr |
2142 | shstr |
2145 | object::kv_get (shstr key) |
2143 | object::kv_get (shstr key) |
|
|
2144 | CODE: |
|
|
2145 | RETVAL = THIS->kv.get (key); |
|
|
2146 | OUTPUT: |
|
|
2147 | RETVAL |
2146 | |
2148 | |
2147 | void |
2149 | void |
2148 | object::kv_del (shstr key) |
2150 | object::kv_del (shstr key) |
|
|
2151 | CODE: |
|
|
2152 | THIS->kv.del (key); |
2149 | |
2153 | |
2150 | void |
2154 | void |
2151 | object::kv_set (shstr key, shstr value) |
2155 | object::kv_set (shstr key, shstr value) |
|
|
2156 | CODE: |
|
|
2157 | THIS->kv.set (key, value); |
2152 | |
2158 | |
2153 | object *get_nearest_player (object *ob) |
2159 | object *get_nearest_player (object *ob) |
2154 | ALIAS: nearest_player = 0 |
2160 | ALIAS: nearest_player = 0 |
2155 | PREINIT: |
2161 | PREINIT: |
2156 | extern object *get_nearest_player (object *); |
2162 | extern object *get_nearest_player (object *); |
… | |
… | |
2359 | if (pl->ob && pl->ob->map == THIS) |
2365 | if (pl->ob && pl->ob->map == THIS) |
2360 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2366 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2361 | } |
2367 | } |
2362 | |
2368 | |
2363 | void |
2369 | void |
|
|
2370 | maptile::gen_quadmap (int x, int y, int z) |
|
|
2371 | CODE: |
|
|
2372 | gen_quadmap (THIS, x * 50, y * 50, z); |
|
|
2373 | |
|
|
2374 | void |
2364 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2375 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2365 | CODE: |
2376 | CODE: |
2366 | { |
2377 | { |
2367 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2378 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2368 | croak ("maptile::add_underlay: palette must be arrayref"); |
2379 | croak ("maptile::add_underlay: palette must be arrayref"); |
… | |
… | |
2384 | |
2395 | |
2385 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2396 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2386 | { |
2397 | { |
2387 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2398 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2388 | { |
2399 | { |
2389 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
2400 | object *ob = archetype::get (cfSvPVutf8_nolen (*elem)); |
2390 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2401 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2391 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2402 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2392 | |
2403 | |
2393 | if (ob->randomitems && !ob->above) |
2404 | if (ob->randomitems && !ob->above) |
2394 | { |
2405 | { |
… | |
… | |
2398 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2409 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2399 | // TODO: if this is a pickable object, then the item |
2410 | // TODO: if this is a pickable object, then the item |
2400 | // will at a bit weird - saving inside the player |
2411 | // will at a bit weird - saving inside the player |
2401 | // will clear the flag, but when the player drops |
2412 | // will clear the flag, but when the player drops |
2402 | // it without logging out, it keeps the flag. |
2413 | // it without logging out, it keeps the flag. |
2403 | // nobody ahs reported this, but this can be rather |
2414 | // nobody has reported this, but this can be rather |
2404 | // annoying on persistent maps. |
2415 | // annoying on persistent maps. |
2405 | } |
2416 | } |
2406 | } |
2417 | } |
2407 | } |
2418 | } |
2408 | } |
2419 | } |
2409 | |
|
|
2410 | skip: ; |
2420 | skip: ; |
2411 | } |
2421 | } |
2412 | } |
2422 | } |
2413 | |
2423 | |
2414 | void |
2424 | void |
… | |
… | |
2445 | for (int x = 0; x < THIS->width; ++x) |
2455 | for (int x = 0; x < THIS->width; ++x) |
2446 | for (int y = 0; y < THIS->height; ++y) |
2456 | for (int y = 0; y < THIS->height; ++y) |
2447 | { |
2457 | { |
2448 | region *rgn = THIS->region (x, y); |
2458 | region *rgn = THIS->region (x, y); |
2449 | |
2459 | |
2450 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2451 | if (object *op = THIS->at (x, y).top) |
2460 | if (object *op = THIS->at (x, y).top) |
2452 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2461 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2453 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2462 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2454 | } |
2463 | } |
2455 | |
2464 | |
… | |
… | |
2534 | } |
2543 | } |
2535 | OUTPUT: RETVAL |
2544 | OUTPUT: RETVAL |
2536 | |
2545 | |
2537 | # worst xs function of my life |
2546 | # worst xs function of my life |
2538 | bool |
2547 | bool |
2539 | _create_random_map (\ |
2548 | _create_random_map (maptile *self, SV *options) |
2540 | maptile *self,\ |
|
|
2541 | SV *options,\ |
|
|
2542 | val64 total_map_hp,\ |
|
|
2543 | region *region\ |
|
|
2544 | ) |
|
|
2545 | CODE: |
2549 | CODE: |
2546 | { |
2550 | { |
2547 | random_map_params rmp; |
2551 | random_map_params rmp ((HV *)SvRV (options)); |
2548 | |
|
|
2549 | rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options)); |
|
|
2550 | |
|
|
2551 | assign (rmp.wall_name , rmp.get_str ("wall_name")); |
|
|
2552 | assign (rmp.monsterstyle , rmp.get_str ("monsterstyle")); |
|
|
2553 | assign (rmp.layoutstyle , rmp.get_str ("layoutstyle")); |
|
|
2554 | assign (rmp.doorstyle , rmp.get_str ("doorstyle")); |
|
|
2555 | assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map")); |
|
|
2556 | |
|
|
2557 | rmp.origin_map = rmp.get_str ("origin_map"); |
|
|
2558 | rmp.origin_x = rmp.get_iv ("origin_x"); |
|
|
2559 | rmp.origin_y = rmp.get_iv ("origin_y"); |
|
|
2560 | rmp.final_map = rmp.get_str ("final_map"); |
|
|
2561 | rmp.this_map = rmp.get_str ("this_map"); |
|
|
2562 | rmp.xsize = rmp.get_iv ("xsize"); |
|
|
2563 | rmp.ysize = rmp.get_iv ("ysize"); |
|
|
2564 | rmp.expand2x = rmp.get_iv ("expand2x"); |
|
|
2565 | rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1"); |
|
|
2566 | rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2"); |
|
|
2567 | rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3"); |
|
|
2568 | rmp.symmetry = rmp.get_iv ("symmetry"); |
|
|
2569 | rmp.difficulty = rmp.get_iv ("difficulty"); |
|
|
2570 | rmp.difficulty_given = rmp.get_iv ("difficulty_given"); |
|
|
2571 | rmp.difficulty_increase = rmp.get_nv ("difficulty_increase"); |
|
|
2572 | rmp.dungeon_level = rmp.get_iv ("dungeon_level"); |
|
|
2573 | rmp.dungeon_depth = rmp.get_iv ("dungeon_depth"); |
|
|
2574 | rmp.orientation = rmp.get_iv ("orientation"); |
|
|
2575 | rmp.random_seed = rmp.get_uv ("random_seed"); |
|
|
2576 | rmp.total_map_hp = (uint64_t)total_map_hp; |
|
|
2577 | rmp.map_layout_style = rmp.get_iv ("map_layout_style"); |
|
|
2578 | rmp.symmetry_used = rmp.get_iv ("symmetry_used"); |
|
|
2579 | rmp.region = region; |
|
|
2580 | |
|
|
2581 | RETVAL = self->generate_random_map (&rmp); |
2552 | RETVAL = self->generate_random_map (&rmp); |
2582 | } |
2553 | } |
2583 | OUTPUT: |
2554 | OUTPUT: |
2584 | RETVAL |
2555 | RETVAL |
2585 | |
2556 | |
… | |
… | |
2757 | |
2728 | |
2758 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2729 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2759 | CODE: |
2730 | CODE: |
2760 | { |
2731 | { |
2761 | faceinfo *f = face_info (idx); assert (f); |
2732 | faceinfo *f = face_info (idx); assert (f); |
2762 | facedata *d = &(faceset ? f->data64 : f->data32); |
2733 | facedata *d = f->face + faceset; |
2763 | sv_to (data, d->data); |
2734 | sv_to (data, d->data); |
2764 | STRLEN clen; |
2735 | STRLEN clen; |
2765 | char *cdata = SvPVbyte (chksum, clen); |
2736 | char *cdata = SvPVbyte (chksum, clen); |
2766 | clen = min (CHKSUM_MAXLEN, clen); |
2737 | clen = min (CHKSUM_MAXLEN, clen); |
2767 | |
2738 | |
… | |
… | |
2919 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2890 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2920 | |
2891 | |
2921 | self->skip (); |
2892 | self->skip (); |
2922 | } |
2893 | } |
2923 | |
2894 | |
|
|
2895 | MODULE = cf PACKAGE = cf::layout |
|
|
2896 | |
|
|
2897 | INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
|
|
2898 | |