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.378 by root, Wed Apr 21 03:29:27 2010 UTC vs.
Revision 1.402 by root, Sun May 1 13:18:24 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
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))
352#endif 354#endif
353 355
354////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 356//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 357
356static SV * 358static SV *
357newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 359newSVptr (void *ptr, HV *stash, HV *hv)
358{ 360{
359 SV *sv;
360
361 if (!ptr) 361 if (!ptr)
362 return newSV (0); 362 return newSV (0);
363 363
364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
365 return sv_bless (newRV_noinc ((SV *)hv), stash); 365 return sv_bless (newRV_noinc ((SV *)hv), stash);
366}
367
368static SV * noinline
369newSVptr (void *ptr, HV *stash)
370{
371 return newSVptr (ptr, stash, newHV ());
366} 372}
367 373
368static int 374static int
369attachable_free (pTHX_ SV *sv, MAGIC *mg) 375attachable_free (pTHX_ SV *sv, MAGIC *mg)
370{ 376{
382 return 0; 388 return 0;
383} 389}
384 390
385MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 391MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
386 392
387static SV * 393static SV * noinline
388newSVattachable (attachable *obj, HV *stash) 394newSVattachable (attachable *obj, HV *stash)
389{ 395{
390 if (!obj) 396 if (!obj)
391 return newSV (0); 397 return newSV (0);
392 398
526static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 532static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
527static inline SV *to_sv (float v) { return newSVnv (v); } 533static inline SV *to_sv (float v) { return newSVnv (v); }
528static inline SV *to_sv (double v) { return newSVnv (v); } 534static inline SV *to_sv (double v) { return newSVnv (v); }
529static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 535static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
530static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 536static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
537// gcc dislikes noilnine on to_sv
531static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 538static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
539static inline SV *to_sv (object * v) { return to_sv_ni (v); }
532static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 540static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
533static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 541static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
534static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 542static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
535static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 543static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
536static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 544static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
537static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 545static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
546static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
538 547
539static inline SV *to_sv (object & v) { return to_sv (&v); } 548static inline SV *to_sv (object & v) { return to_sv (&v); }
540static inline SV *to_sv (living & v) { return to_sv (&v); } 549static inline SV *to_sv (living & v) { return to_sv (&v); }
541 550
542static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 551static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
588static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 597static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
589static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 598static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
590static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 599static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
591static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 600static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
592static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 601static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
602static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
593static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 603static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
594static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 604static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
595 605
596//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 606//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
597static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 607static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
764 exit (EXIT_FAILURE); 774 exit (EXIT_FAILURE);
765 } 775 }
766 776
767 eval_pv ( 777 eval_pv (
768 "#line 1 'cfperl init'\n" 778 "#line 1 'cfperl init'\n"
769 "use EV ();\n" 779 "use EV ();\n" // required by bootstrap
770 "use Coro ();\n" 780 "use Coro ();\n" // required by bootstrap
771 "cf->bootstrap;\n" 781 "cf->bootstrap;\n" // required for cf::datadir
772 "unshift @INC, cf::datadir ();\n" 782 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
773 "require cf;\n", 783 "require cf;\n",
774 0 784 0
775 ); 785 );
776 786
777 if (SvTRUE (ERRSV)) 787 if (SvTRUE (ERRSV))
1391 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1401 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1392 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1402 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1393 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1403 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1394 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1395 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1396 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1397 1408
1398 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1409 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1399 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1410 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1400 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1411 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1449# include "attackinc.h" 1460# include "attackinc.h"
1450# undef def 1461# undef def
1451# define def(uc, flags) const_iv (SK_ ## uc) 1462# define def(uc, flags) const_iv (SK_ ## uc)
1452# include "skillinc.h" 1463# include "skillinc.h"
1453# undef def 1464# undef def
1454 1465# define def(name, use, nonuse) const_iv (body_ ## name)
1455 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1466# include "slotinc.h"
1456 const_iv (logBacktrace) 1467# undef def
1457
1458 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1459 1468
1460 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1469 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1461 1470
1462 const_iv (MAX_TIME) 1471 const_iv (MAX_TIME)
1463 const_iv (MAXSOCKBUF) 1472 const_iv (MAXSOCKBUF)
1488 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)
1489 1498
1490 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1499 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1491 }; 1500 };
1492 1501
1493 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1502 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1494 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1503 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1495 1504
1496 static const struct { 1505 static const struct {
1497 const char *name; 1506 const char *name;
1498 int skip; 1507 int skip;
1504# undef def 1513# undef def
1505 }; 1514 };
1506 1515
1507 AV *av = get_av ("cf::EVENT", 1); 1516 AV *av = get_av ("cf::EVENT", 1);
1508 1517
1509 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1518 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1510 { 1519 {
1511 AV *event = newAV (); 1520 AV *event = newAV ();
1512 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1521 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1513 av_push (event, newSViv (eiv->klass)); 1522 av_push (event, newSViv (eiv->klass));
1514 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1523 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1549 1558
1550 for_all_objects (op) 1559 for_all_objects (op)
1551 op->reattach (); 1560 op->reattach ();
1552} 1561}
1553 1562
1554# support function for map-world.ext
1555void _quantise (SV *data_sv, SV *plt_sv)
1556 CODE:
1557{
1558 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1559 croak ("_quantise called with invalid agruments");
1560
1561 plt_sv = SvRV (plt_sv);
1562 SV **plt = AvARRAY (plt_sv);
1563 int plt_count = AvFILL (plt_sv) + 1;
1564
1565 STRLEN len;
1566 char *data = SvPVbyte (data_sv, len);
1567 char *dst = data;
1568
1569 while (len >= 3)
1570 {
1571 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1572 {
1573 char *val = SvPVX (*val_sv);
1574
1575 if (val [0] == data [0]
1576 && val [1] == data [1]
1577 && val [2] == data [2])
1578 {
1579 *dst++ = val [3];
1580 goto next;
1581 }
1582 }
1583
1584 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1585 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1586 dst - SvPVX (data_sv), len);
1587
1588 next:
1589 data += 3;
1590 len -= 3;
1591 }
1592
1593 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1594}
1595
1596void init_anim () 1563void init_anim ()
1597 1564
1598void init_globals () 1565void init_globals ()
1599 1566
1600void init_experience ()
1601
1602void init_attackmess () 1567void init_attackmess ()
1603 1568
1604void init_dynamic () 1569void init_dynamic ()
1605 1570
1606void load_settings () 1571void load_settings ()
1607 1572
1573void reload_exp_table ()
1574
1608void load_materials () 1575void reload_materials ()
1609 1576
1610void init_uuid () 1577void init_uuid ()
1611 CODE: 1578 CODE:
1612 UUID::init (); 1579 UUID::init ();
1613 1580
1768 1735
1769int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1736int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1770 INIT: 1737 INIT:
1771#if __GLIBC__ 1738#if __GLIBC__
1772 mallopt (M_TOP_PAD, 1024 * 1024); 1739 mallopt (M_TOP_PAD, 1024 * 1024);
1773 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1740 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1774 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1741 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1742 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1775 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1743 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1776#endif 1744#endif
1777 1745
1778int munlockall () 1746int munlockall ()
1779 1747
1780#endif 1748#endif
1818int exp_to_level (val64 exp) 1786int exp_to_level (val64 exp)
1819 1787
1820val64 level_to_min_exp (int level) 1788val64 level_to_min_exp (int level)
1821 1789
1822SV * 1790SV *
1823resistance_to_string (int atnr) 1791attacktype_name (int atnr)
1824 CODE: 1792 CODE:
1825 if (atnr >= 0 && atnr < NROFATTACKS) 1793 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1794 ? newSVpv (attacktype_name [atnr], 0)
1795 : &PL_sv_undef;
1796 OUTPUT: RETVAL
1797
1798SV *
1799attacktype_desc (int atnr)
1800 CODE:
1801 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1802 ? newSVpv (attacktype_desc [atnr], 0)
1803 : &PL_sv_undef;
1804 OUTPUT: RETVAL
1805
1806SV *
1807resist_plus (int atnr)
1808 CODE:
1809 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1826 RETVAL = newSVpv (resist_plus[atnr], 0); 1810 ? newSVpv (resist_plus [atnr], 0)
1827 else 1811 : &PL_sv_undef;
1828 XSRETURN_UNDEF; 1812 OUTPUT: RETVAL
1813
1814SV *
1815change_resist_msg (int atnr)
1816 CODE:
1817 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1818 ? newSVpv (change_resist_msg [atnr], 0)
1819 : &PL_sv_undef;
1829 OUTPUT: RETVAL 1820 OUTPUT: RETVAL
1830 1821
1831UUID 1822UUID
1832uuid_cur () 1823uuid_cur ()
1833 CODE: 1824 CODE:
1956int mortals_size () 1947int mortals_size ()
1957 CODE: 1948 CODE:
1958 RETVAL = attachable::mortals.size (); 1949 RETVAL = attachable::mortals.size ();
1959 OUTPUT: RETVAL 1950 OUTPUT: RETVAL
1960 1951
1961const_utf8_string slot_use_name (U32 slot) 1952const_utf8_string slot_name (U32 slot)
1962 ALIAS: 1953 ALIAS:
1954 slot_name = 0
1955 slot_use_name = 1
1963 slot_nonuse_name = 1 1956 slot_nonuse_name = 2
1964 CODE: 1957 CODE:
1965{ 1958{
1966 if (slot >= NUM_BODY_LOCATIONS) 1959 if (slot >= NUM_BODY_LOCATIONS)
1967 croak ("body slot index out of range"); 1960 croak ("body slot index out of range");
1968 1961
1969 switch (ix) 1962 switch (ix)
1970 { 1963 {
1964 case 0: RETVAL = body_locations[slot].name ; break;
1971 case 0: RETVAL = body_locations[slot].use_name; break; 1965 case 1: RETVAL = body_locations[slot].use_name ; break;
1972 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1966 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1973 } 1967 }
1974} 1968}
1975 OUTPUT: 1969 OUTPUT:
1976 RETVAL 1970 RETVAL
1977 1971
2083 2077
2084void pick_up (object *who, object *op) 2078void pick_up (object *who, object *op)
2085 2079
2086void update_object (object *op, int action) 2080void update_object (object *op, int action)
2087 2081
2088void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2082void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2089 2083
2090void player_lvl_adj (object *who, object *skill = 0) 2084void player_lvl_adj (object *who, object *skill = 0)
2091 2085
2092int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2086int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2093 2087
2138 RETVAL = 0; 2132 RETVAL = 0;
2139} 2133}
2140 2134
2141shstr 2135shstr
2142object::kv_get (shstr key) 2136object::kv_get (shstr key)
2137 CODE:
2138 RETVAL = THIS->kv.get (key);
2139 OUTPUT:
2140 RETVAL
2143 2141
2144void 2142void
2145object::kv_del (shstr key) 2143object::kv_del (shstr key)
2144 CODE:
2145 THIS->kv.del (key);
2146 2146
2147void 2147void
2148object::kv_set (shstr key, shstr value) 2148object::kv_set (shstr key, shstr value)
2149 CODE:
2150 THIS->kv.set (key, value);
2149 2151
2150object *get_nearest_player (object *ob) 2152object *get_nearest_player (object *ob)
2151 ALIAS: nearest_player = 0 2153 ALIAS: nearest_player = 0
2152 PREINIT: 2154 PREINIT:
2153 extern object *get_nearest_player (object *); 2155 extern object *get_nearest_player (object *);
2355 for_all_players (pl) 2357 for_all_players (pl)
2356 if (pl->ob && pl->ob->map == THIS) 2358 if (pl->ob && pl->ob->map == THIS)
2357 PUSHs (sv_2mortal (to_sv (pl->ob))); 2359 PUSHs (sv_2mortal (to_sv (pl->ob)));
2358 } 2360 }
2359 2361
2362#if 0
2363
2364void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt)
2366 CODE:
2367{
2368 static frac_gen<vec2d> frac;
2369
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref");
2372
2373 biome_plt = SvRV (biome_plt);
2374
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map);
2376
2377 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y)
2379 {
2380 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip;
2383
2384 {
2385 float fx = mx * THIS->width + x;
2386 float fy = my * THIS->height + y;
2387
2388 int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15);
2389 int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15);
2390
2391 rain = lerp (rain, 0, 15, 0, temp);
2392 printf ("rain %d\n", temp);//D
2393
2394 int biome = bmap [rain * 16 + temp];
2395
2396 //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D
2397#if 1
2398 if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0))
2399 {
2400 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2401 ob->flag [FLAG_NO_MAP_SAVE] = true;
2402 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2403
2404 if (ob->randomitems && !ob->above)
2405 {
2406 ob->create_treasure (ob->randomitems);
2407
2408 for (object *op = ob->above; op; op = op->above)
2409 op->flag [FLAG_NO_MAP_SAVE] = true;
2410 }
2411 }
2412#endif
2413 }
2414 skip: ;
2415 }
2416}
2417
2418#endif
2419
2360void 2420void
2361maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2362 CODE: 2422 CODE:
2363{ 2423{
2364 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2395 op->flag [FLAG_NO_MAP_SAVE] = true; 2455 op->flag [FLAG_NO_MAP_SAVE] = true;
2396 // TODO: if this is a pickable object, then the item 2456 // TODO: if this is a pickable object, then the item
2397 // will at a bit weird - saving inside the player 2457 // will at a bit weird - saving inside the player
2398 // will clear the flag, but when the player drops 2458 // will clear the flag, but when the player drops
2399 // it without logging out, it keeps the flag. 2459 // it without logging out, it keeps the flag.
2400 // nobody ahs reported this, but this can be rather 2460 // nobody has reported this, but this can be rather
2401 // annoying on persistent maps. 2461 // annoying on persistent maps.
2402 } 2462 }
2403 } 2463 }
2404 } 2464 }
2405 } 2465 }
2406
2407 skip: ; 2466 skip: ;
2408 } 2467 }
2409} 2468}
2410 2469
2411void 2470void
2442 for (int x = 0; x < THIS->width; ++x) 2501 for (int x = 0; x < THIS->width; ++x)
2443 for (int y = 0; y < THIS->height; ++y) 2502 for (int y = 0; y < THIS->height; ++y)
2444 { 2503 {
2445 region *rgn = THIS->region (x, y); 2504 region *rgn = THIS->region (x, y);
2446 2505
2447 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2448 if (object *op = THIS->at (x, y).top) 2506 if (object *op = THIS->at (x, y).top)
2449 if (rgn->treasure && rndm () < rgn->treasure_density) 2507 if (rgn->treasure && rndm () < rgn->treasure_density)
2450 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2508 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2451 } 2509 }
2452 2510
2531} 2589}
2532 OUTPUT: RETVAL 2590 OUTPUT: RETVAL
2533 2591
2534# worst xs function of my life 2592# worst xs function of my life
2535bool 2593bool
2536_create_random_map (\ 2594_create_random_map (maptile *self, SV *options)
2537 maptile *self,\
2538 utf8_string wallstyle,\
2539 utf8_string wall_name,\
2540 utf8_string floorstyle,\
2541 utf8_string monsterstyle,\
2542 utf8_string treasurestyle,\
2543 utf8_string layoutstyle,\
2544 utf8_string doorstyle,\
2545 utf8_string decorstyle,\
2546 utf8_string miningstyle,\
2547 utf8_string origin_map,\
2548 utf8_string final_map,\
2549 utf8_string exitstyle,\
2550 utf8_string this_map,\
2551 utf8_string exit_on_final_map,\
2552 int xsize,\
2553 int ysize,\
2554 int expand2x,\
2555 int layoutoptions1,\
2556 int layoutoptions2,\
2557 int layoutoptions3,\
2558 int symmetry,\
2559 int difficulty,\
2560 int difficulty_given,\
2561 float difficulty_increase,\
2562 int dungeon_level,\
2563 int dungeon_depth,\
2564 int decoroptions,\
2565 int orientation,\
2566 int origin_y,\
2567 int origin_x,\
2568 U32 random_seed,\
2569 val64 total_map_hp,\
2570 int map_layout_style,\
2571 int treasureoptions,\
2572 int symmetry_used,\
2573 region *region,\
2574 utf8_string custom\
2575)
2576 CODE: 2595 CODE:
2577{ 2596{
2578 random_map_params rmp; 2597 random_map_params rmp ((HV *)SvRV (options));
2579
2580 assign (rmp.wallstyle , wallstyle);
2581 assign (rmp.wall_name , wall_name);
2582 assign (rmp.floorstyle , floorstyle);
2583 assign (rmp.monsterstyle , monsterstyle);
2584 assign (rmp.treasurestyle , treasurestyle);
2585 assign (rmp.layoutstyle , layoutstyle);
2586 assign (rmp.doorstyle , doorstyle);
2587 assign (rmp.decorstyle , decorstyle);
2588 assign (rmp.miningstyle , miningstyle);
2589 assign (rmp.exitstyle , exitstyle);
2590 assign (rmp.exit_on_final_map, exit_on_final_map);
2591
2592 rmp.origin_map = origin_map;
2593 rmp.final_map = final_map;
2594 rmp.this_map = this_map;
2595 rmp.xsize = xsize;
2596 rmp.ysize = ysize;
2597 rmp.expand2x = expand2x;
2598 rmp.layoutoptions1 = layoutoptions1;
2599 rmp.layoutoptions2 = layoutoptions2;
2600 rmp.layoutoptions3 = layoutoptions3;
2601 rmp.symmetry = symmetry;
2602 rmp.difficulty = difficulty;
2603 rmp.difficulty_given = difficulty_given;
2604 rmp.difficulty_increase = difficulty_increase;
2605 rmp.dungeon_level = dungeon_level;
2606 rmp.dungeon_depth = dungeon_depth;
2607 rmp.decoroptions = decoroptions;
2608 rmp.orientation = orientation;
2609 rmp.origin_y = origin_y;
2610 rmp.origin_x = origin_x;
2611 rmp.random_seed = random_seed;
2612 rmp.total_map_hp = (uint64_t) total_map_hp;
2613 rmp.map_layout_style = map_layout_style;
2614 rmp.treasureoptions = treasureoptions;
2615 rmp.symmetry_used = symmetry_used;
2616 rmp.region = region;
2617 rmp.custom = custom;
2618
2619 RETVAL = self->generate_random_map (&rmp); 2598 RETVAL = self->generate_random_map (&rmp);
2620} 2599}
2621 OUTPUT: 2600 OUTPUT:
2622 RETVAL 2601 RETVAL
2623 2602
2654void 2633void
2655list () 2634list ()
2656 PPCODE: 2635 PPCODE:
2657 for_all_regions (rgn) 2636 for_all_regions (rgn)
2658 XPUSHs (sv_2mortal (to_sv (rgn))); 2637 XPUSHs (sv_2mortal (to_sv (rgn)));
2659
2660region *find (utf8_string name)
2661 PROTOTYPE: $
2662 CODE:
2663 RETVAL = region::find (name);
2664 OUTPUT: RETVAL
2665 2638
2666int specificity (region *rgn) 2639int specificity (region *rgn)
2667 CODE: 2640 CODE:
2668 RETVAL = 0; 2641 RETVAL = 0;
2669 while (rgn = rgn->parent) 2642 while (rgn = rgn->parent)
2801 2774
2802void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2803 CODE: 2776 CODE:
2804{ 2777{
2805 faceinfo *f = face_info (idx); assert (f); 2778 faceinfo *f = face_info (idx); assert (f);
2806 facedata *d = &(faceset ? f->data64 : f->data32); 2779 facedata *d = f->face + faceset;
2807 sv_to (data, d->data); 2780 sv_to (data, d->data);
2808 STRLEN clen; 2781 STRLEN clen;
2809 char *cdata = SvPVbyte (chksum, clen); 2782 char *cdata = SvPVbyte (chksum, clen);
2810 clen = min (CHKSUM_MAXLEN, clen); 2783 clen = min (CHKSUM_MAXLEN, clen);
2811 2784
2963 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2936 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2964 2937
2965 self->skip (); 2938 self->skip ();
2966 } 2939 }
2967 2940
2941MODULE = cf PACKAGE = cf::layout
2942
2943INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2944

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines