ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.384 by root, Fri Apr 30 21:00:40 2010 UTC vs.
Revision 1.407 by root, Sat Oct 15 00:58:14 2011 UTC

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
66static int tick_inhibit; 67static int tick_inhibit;
67static int tick_pending; 68static int tick_pending;
68 69
69global gbl_ev; 70global gbl_ev;
70static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 71static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
71static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; 72static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick;
72static AV *av_reflect; 73static AV *av_reflect;
73 74
74bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
75bitset<NUM_TYPES> ev_want_type; 76bitset<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
91static SV 93static SV
92 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
93 *cv_cf__can_merge, 95 *cv_cf__can_merge,
122 124
123 return sv; 125 return sv;
124} 126}
125#endif 127#endif
126 128
127static noinline utf8_string 129noinline utf8_string
128cfSvPVutf8_nolen (SV *sv) 130cfSvPVutf8_nolen (SV *sv)
129{ 131{
130 SvGETMAGIC (sv); 132 SvGETMAGIC (sv);
131 133
132 if (SvPOK (sv)) 134 if (SvPOK (sv))
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
354////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 359//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 360
356static SV * 361static SV *
357newSVptr (void *ptr, HV *stash, HV *hv) 362newSVptr (void *ptr, HV *stash, HV *hv)
358{ 363{
359 SV *sv;
360
361 if (!ptr) 364 if (!ptr)
362 return newSV (0); 365 return newSV (0);
363 366
364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 367 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
365 return sv_bless (newRV_noinc ((SV *)hv), stash); 368 return sv_bless (newRV_noinc ((SV *)hv), stash);
366} 369}
367 370
368static SV * 371static SV * noinline
369newSVptr (void *ptr, HV *stash) 372newSVptr (void *ptr, HV *stash)
370{ 373{
371 return newSVptr (ptr, stash, newHV ()); 374 return newSVptr (ptr, stash, newHV ());
372} 375}
373 376
388 return 0; 391 return 0;
389} 392}
390 393
391MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 394MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
392 395
393static SV * 396static SV * noinline
394newSVattachable (attachable *obj, HV *stash) 397newSVattachable (attachable *obj, HV *stash)
395{ 398{
396 if (!obj) 399 if (!obj)
397 return newSV (0); 400 return newSV (0);
398 401
532static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 535static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
533static inline SV *to_sv (float v) { return newSVnv (v); } 536static inline SV *to_sv (float v) { return newSVnv (v); }
534static inline SV *to_sv (double v) { return newSVnv (v); } 537static inline SV *to_sv (double v) { return newSVnv (v); }
535static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 538static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
536static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 539static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
540// gcc dislikes noilnine on to_sv
537static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 541static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
542static inline SV *to_sv (object * v) { return to_sv_ni (v); }
538static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 543static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
539static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 544static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
540static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 545static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
541static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 546static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
542static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 547static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
543static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 548static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
549static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
544 550
545static inline SV *to_sv (object & v) { return to_sv (&v); } 551static inline SV *to_sv (object & v) { return to_sv (&v); }
546static inline SV *to_sv (living & v) { return to_sv (&v); } 552static inline SV *to_sv (living & v) { return to_sv (&v); }
547 553
548static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 554static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
594static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 600static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
595static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 601static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
596static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 602static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
597static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 603static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
598static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 604static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
605static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
599static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 606static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
600static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 607static 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)]; }
603static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 610static 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
1558void _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
1599void init_anim () 1564void init_anim ()
1600 1565
1601void init_globals () 1566void init_globals ()
1602 1567
1603void init_experience ()
1604
1605void init_attackmess () 1568void init_attackmess ()
1606 1569
1607void init_dynamic () 1570void init_dynamic ()
1608 1571
1609void load_settings () 1572void load_settings ()
1610 1573
1574void reload_exp_table ()
1575
1611void load_materials () 1576void reload_materials ()
1612 1577
1613void init_uuid () 1578void init_uuid ()
1614 CODE: 1579 CODE:
1615 UUID::init (); 1580 UUID::init ();
1616 1581
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
1654void server_tick () 1619void 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
1672NV floor (NV x) 1641NV floor (NV x)
1771 1740
1772int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1741int 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
1781int munlockall () 1751int munlockall ()
1782 1752
1783#endif 1753#endif
1821int exp_to_level (val64 exp) 1791int exp_to_level (val64 exp)
1822 1792
1823val64 level_to_min_exp (int level) 1793val64 level_to_min_exp (int level)
1824 1794
1825SV * 1795SV *
1826resistance_to_string (int atnr) 1796attacktype_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
1803SV *
1804attacktype_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
1811SV *
1812resist_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
1819SV *
1820change_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
1834UUID 1827UUID
1835uuid_cur () 1828uuid_cur ()
1836 CODE: 1829 CODE:
1959int mortals_size () 1952int mortals_size ()
1960 CODE: 1953 CODE:
1961 RETVAL = attachable::mortals.size (); 1954 RETVAL = attachable::mortals.size ();
1962 OUTPUT: RETVAL 1955 OUTPUT: RETVAL
1963 1956
1964const_utf8_string slot_use_name (U32 slot) 1957const_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
2114object *new (utf8_string archetype = 0) 2110object *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
2121object *generate (utf8_string arch, object *creator) 2119object *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
2138 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2136 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2139 2137
2140 if (RETVAL->destroyed ()) 2138 if (RETVAL->destroyed ())
2141 RETVAL = 0; 2139 RETVAL = 0;
2142} 2140}
2141 OUTPUT:
2142 RETVAL
2143 2143
2144shstr 2144shstr
2145object::kv_get (shstr key) 2145object::kv_get (shstr key)
2146 CODE:
2147 RETVAL = THIS->kv.get (key);
2148 OUTPUT:
2149 RETVAL
2146 2150
2147void 2151void
2148object::kv_del (shstr key) 2152object::kv_del (shstr key)
2153 CODE:
2154 THIS->kv.del (key);
2149 2155
2150void 2156void
2151object::kv_set (shstr key, shstr value) 2157object::kv_set (shstr key, shstr value)
2158 CODE:
2159 THIS->kv.set (key, value);
2152 2160
2153object *get_nearest_player (object *ob) 2161object *get_nearest_player (object *ob)
2154 ALIAS: nearest_player = 0 2162 ALIAS: nearest_player = 0
2155 PREINIT: 2163 PREINIT:
2156 extern object *get_nearest_player (object *); 2164 extern object *get_nearest_player (object *);
2359 if (pl->ob && pl->ob->map == THIS) 2367 if (pl->ob && pl->ob->map == THIS)
2360 PUSHs (sv_2mortal (to_sv (pl->ob))); 2368 PUSHs (sv_2mortal (to_sv (pl->ob)));
2361 } 2369 }
2362 2370
2363void 2371void
2372maptile::gen_quadmap (int x, int y, int z)
2373 CODE:
2374 gen_quadmap (THIS, x * 50, y * 50, z);
2375
2376void
2364maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2377maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2365 CODE: 2378 CODE:
2366{ 2379{
2367 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2380 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2368 croak ("maptile::add_underlay: palette must be arrayref"); 2381 croak ("maptile::add_underlay: palette must be arrayref");
2384 2397
2385 if (IN_RANGE_EXC (offs, 0, idxlen)) 2398 if (IN_RANGE_EXC (offs, 0, idxlen))
2386 { 2399 {
2387 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2400 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2388 { 2401 {
2389 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2402 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2390 ob->flag [FLAG_NO_MAP_SAVE] = true; 2403 ob->flag [FLAG_NO_MAP_SAVE] = true;
2391 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2404 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2392 2405
2393 if (ob->randomitems && !ob->above) 2406 if (ob->randomitems && !ob->above)
2394 { 2407 {
2398 op->flag [FLAG_NO_MAP_SAVE] = true; 2411 op->flag [FLAG_NO_MAP_SAVE] = true;
2399 // TODO: if this is a pickable object, then the item 2412 // TODO: if this is a pickable object, then the item
2400 // will at a bit weird - saving inside the player 2413 // will at a bit weird - saving inside the player
2401 // will clear the flag, but when the player drops 2414 // will clear the flag, but when the player drops
2402 // it without logging out, it keeps the flag. 2415 // it without logging out, it keeps the flag.
2403 // nobody ahs reported this, but this can be rather 2416 // nobody has reported this, but this can be rather
2404 // annoying on persistent maps. 2417 // annoying on persistent maps.
2405 } 2418 }
2406 } 2419 }
2407 } 2420 }
2408 } 2421 }
2409
2410 skip: ; 2422 skip: ;
2411 } 2423 }
2412} 2424}
2413 2425
2414void 2426void
2445 for (int x = 0; x < THIS->width; ++x) 2457 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2458 for (int y = 0; y < THIS->height; ++y)
2447 { 2459 {
2448 region *rgn = THIS->region (x, y); 2460 region *rgn = THIS->region (x, y);
2449 2461
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) 2462 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2463 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2464 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2465 }
2455 2466
2534} 2545}
2535 OUTPUT: RETVAL 2546 OUTPUT: RETVAL
2536 2547
2537# worst xs function of my life 2548# worst xs function of my life
2538bool 2549bool
2539_create_random_map (\ 2550_create_random_map (maptile *self, SV *options)
2540 maptile *self,\
2541 utf8_string wallstyle,\
2542 utf8_string wall_name,\
2543 utf8_string floorstyle,\
2544 utf8_string monsterstyle,\
2545 utf8_string treasurestyle,\
2546 utf8_string layoutstyle,\
2547 utf8_string doorstyle,\
2548 utf8_string decorstyle,\
2549 utf8_string miningstyle,\
2550 utf8_string origin_map,\
2551 utf8_string final_map,\
2552 utf8_string exitstyle,\
2553 utf8_string this_map,\
2554 utf8_string exit_on_final_map,\
2555 int xsize,\
2556 int ysize,\
2557 int expand2x,\
2558 int layoutoptions1,\
2559 int layoutoptions2,\
2560 int layoutoptions3,\
2561 int symmetry,\
2562 int difficulty,\
2563 int difficulty_given,\
2564 float difficulty_increase,\
2565 int dungeon_level,\
2566 int dungeon_depth,\
2567 int decoroptions,\
2568 int orientation,\
2569 int origin_y,\
2570 int origin_x,\
2571 U32 random_seed,\
2572 val64 total_map_hp,\
2573 int map_layout_style,\
2574 int treasureoptions,\
2575 int symmetry_used,\
2576 region *region,\
2577 utf8_string custom\
2578)
2579 CODE: 2551 CODE:
2580{ 2552{
2581 random_map_params rmp; 2553 random_map_params rmp ((HV *)SvRV (options));
2582
2583 assign (rmp.wallstyle , wallstyle);
2584 assign (rmp.wall_name , wall_name);
2585 assign (rmp.floorstyle , floorstyle);
2586 assign (rmp.monsterstyle , monsterstyle);
2587 assign (rmp.treasurestyle , treasurestyle);
2588 assign (rmp.layoutstyle , layoutstyle);
2589 assign (rmp.doorstyle , doorstyle);
2590 assign (rmp.decorstyle , decorstyle);
2591 assign (rmp.miningstyle , miningstyle);
2592 assign (rmp.exitstyle , exitstyle);
2593 assign (rmp.exit_on_final_map, exit_on_final_map);
2594
2595 rmp.origin_map = origin_map;
2596 rmp.final_map = final_map;
2597 rmp.this_map = this_map;
2598 rmp.xsize = xsize;
2599 rmp.ysize = ysize;
2600 rmp.expand2x = expand2x;
2601 rmp.layoutoptions1 = layoutoptions1;
2602 rmp.layoutoptions2 = layoutoptions2;
2603 rmp.layoutoptions3 = layoutoptions3;
2604 rmp.symmetry = symmetry;
2605 rmp.difficulty = difficulty;
2606 rmp.difficulty_given = difficulty_given;
2607 rmp.difficulty_increase = difficulty_increase;
2608 rmp.dungeon_level = dungeon_level;
2609 rmp.dungeon_depth = dungeon_depth;
2610 rmp.decoroptions = decoroptions;
2611 rmp.orientation = orientation;
2612 rmp.origin_y = origin_y;
2613 rmp.origin_x = origin_x;
2614 rmp.random_seed = random_seed;
2615 rmp.total_map_hp = (uint64_t) total_map_hp;
2616 rmp.map_layout_style = map_layout_style;
2617 rmp.treasureoptions = treasureoptions;
2618 rmp.symmetry_used = symmetry_used;
2619 rmp.region = region;
2620 rmp.custom = custom;
2621
2622 RETVAL = self->generate_random_map (&rmp); 2554 RETVAL = self->generate_random_map (&rmp);
2623} 2555}
2624 OUTPUT: 2556 OUTPUT:
2625 RETVAL 2557 RETVAL
2626 2558
2798 2730
2799void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2731void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2800 CODE: 2732 CODE:
2801{ 2733{
2802 faceinfo *f = face_info (idx); assert (f); 2734 faceinfo *f = face_info (idx); assert (f);
2803 facedata *d = &(faceset ? f->data64 : f->data32); 2735 facedata *d = f->face + faceset;
2804 sv_to (data, d->data); 2736 sv_to (data, d->data);
2805 STRLEN clen; 2737 STRLEN clen;
2806 char *cdata = SvPVbyte (chksum, clen); 2738 char *cdata = SvPVbyte (chksum, clen);
2807 clen = min (CHKSUM_MAXLEN, clen); 2739 clen = min (CHKSUM_MAXLEN, clen);
2808 2740
2960 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2892 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2961 2893
2962 self->skip (); 2894 self->skip ();
2963 } 2895 }
2964 2896
2897MODULE = cf PACKAGE = cf::layout
2898
2899INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2900

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines