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.375 by root, Sun Apr 18 05:08:14 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
83 *stash_cf_mapspace_wrap, 84 *stash_cf_mapspace_wrap,
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,
91 *stash_ext_map_world;
89 92
90static SV 93static SV
91 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
92 *cv_cf__can_merge, 95 *cv_cf__can_merge,
93 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
121 124
122 return sv; 125 return sv;
123} 126}
124#endif 127#endif
125 128
126static noinline utf8_string 129noinline utf8_string
127cfSvPVutf8_nolen (SV *sv) 130cfSvPVutf8_nolen (SV *sv)
128{ 131{
129 SvGETMAGIC (sv); 132 SvGETMAGIC (sv);
130 133
131 if (SvPOK (sv)) 134 if (SvPOK (sv))
351#endif 354#endif
352 355
353////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 356//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
354 357
355static SV * 358static SV *
356newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 359newSVptr (void *ptr, HV *stash, HV *hv)
357{ 360{
358 SV *sv;
359
360 if (!ptr) 361 if (!ptr)
361 return newSV (0); 362 return newSV (0);
362 363
363 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);
364 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 ());
365} 372}
366 373
367static int 374static int
368attachable_free (pTHX_ SV *sv, MAGIC *mg) 375attachable_free (pTHX_ SV *sv, MAGIC *mg)
369{ 376{
381 return 0; 388 return 0;
382} 389}
383 390
384MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 391MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
385 392
386static SV * 393static SV * noinline
387newSVattachable (attachable *obj, HV *stash) 394newSVattachable (attachable *obj, HV *stash)
388{ 395{
389 if (!obj) 396 if (!obj)
390 return newSV (0); 397 return newSV (0);
391 398
488{ 495{
489 if (expect_false (!SvOK (sv))) return 0; 496 if (expect_false (!SvOK (sv))) return 0;
490 497
491 if (!SvROK (sv) 498 if (!SvROK (sv)
492 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap 499 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
500 && SvSTASH (SvRV (sv)) != stash_ext_map_world
493 && !sv_derived_from (sv, "cf::map"))) 501 && !sv_derived_from (sv, "cf::map")))
494 croak ("object of type cf::map expected"); 502 croak ("object of type cf::map expected");
495 503
496 return SvPTR_nc (sv); 504 return SvPTR_nc (sv);
497} 505}
524static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 532static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
525static inline SV *to_sv (float v) { return newSVnv (v); } 533static inline SV *to_sv (float v) { return newSVnv (v); }
526static inline SV *to_sv (double v) { return newSVnv (v); } 534static inline SV *to_sv (double v) { return newSVnv (v); }
527static 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); }
528static 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
529static 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); }
530static 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); }
531static 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); }
532static 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); }
533static 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); }
534static 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); }
535static 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); }
536 547
537static inline SV *to_sv (object & v) { return to_sv (&v); } 548static inline SV *to_sv (object & v) { return to_sv (&v); }
538static inline SV *to_sv (living & v) { return to_sv (&v); } 549static inline SV *to_sv (living & v) { return to_sv (&v); }
539 550
540static 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 ()); }
586static 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"); }
587static 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"); }
588static 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"); }
589static 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"); }
590static 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"); }
591static 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"); }
592static 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" ); }
593 605
594//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)]; }
595static 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)); }
762 exit (EXIT_FAILURE); 774 exit (EXIT_FAILURE);
763 } 775 }
764 776
765 eval_pv ( 777 eval_pv (
766 "#line 1 'cfperl init'\n" 778 "#line 1 'cfperl init'\n"
767 "use EV ();\n" 779 "use EV ();\n" // required by bootstrap
768 "use Coro ();\n" 780 "use Coro ();\n" // required by bootstrap
769 "cf->bootstrap;\n" 781 "cf->bootstrap;\n" // required for cf::datadir
770 "unshift @INC, cf::datadir ();\n" 782 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
771 "require cf;\n", 783 "require cf;\n",
772 0 784 0
773 ); 785 );
774 786
775 if (SvTRUE (ERRSV)) 787 if (SvTRUE (ERRSV))
1389 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1401 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1390 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1402 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1391 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1403 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1392 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1393 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);
1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1394 1408
1395 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);
1396 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);
1397 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);
1398 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1412 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1446# include "attackinc.h" 1460# include "attackinc.h"
1447# undef def 1461# undef def
1448# define def(uc, flags) const_iv (SK_ ## uc) 1462# define def(uc, flags) const_iv (SK_ ## uc)
1449# include "skillinc.h" 1463# include "skillinc.h"
1450# undef def 1464# undef def
1451 1465# define def(name, use, nonuse) const_iv (body_ ## name)
1452 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1466# include "slotinc.h"
1453 const_iv (logBacktrace) 1467# undef def
1454
1455 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1456 1468
1457 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1469 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1458 1470
1459 const_iv (MAX_TIME) 1471 const_iv (MAX_TIME)
1460 const_iv (MAXSOCKBUF) 1472 const_iv (MAXSOCKBUF)
1485 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)
1486 1498
1487 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)
1488 }; 1500 };
1489 1501
1490 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; )
1491 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1503 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1492 1504
1493 static const struct { 1505 static const struct {
1494 const char *name; 1506 const char *name;
1495 int skip; 1507 int skip;
1501# undef def 1513# undef def
1502 }; 1514 };
1503 1515
1504 AV *av = get_av ("cf::EVENT", 1); 1516 AV *av = get_av ("cf::EVENT", 1);
1505 1517
1506 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; )
1507 { 1519 {
1508 AV *event = newAV (); 1520 AV *event = newAV ();
1509 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1521 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1510 av_push (event, newSViv (eiv->klass)); 1522 av_push (event, newSViv (eiv->klass));
1511 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1523 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1546 1558
1547 for_all_objects (op) 1559 for_all_objects (op)
1548 op->reattach (); 1560 op->reattach ();
1549} 1561}
1550 1562
1551# support function for map-world.ext
1552void _quantise (SV *data_sv, SV *plt_sv)
1553 CODE:
1554{
1555 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1556 croak ("_quantise called with invalid agruments");
1557
1558 plt_sv = SvRV (plt_sv);
1559 SV **plt = AvARRAY (plt_sv);
1560 int plt_count = AvFILL (plt_sv) + 1;
1561
1562 STRLEN len;
1563 char *data = SvPVbyte (data_sv, len);
1564 char *dst = data;
1565
1566 while (len >= 3)
1567 {
1568 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1569 {
1570 char *val = SvPVX (*val_sv);
1571
1572 if (val [0] == data [0]
1573 && val [1] == data [1]
1574 && val [2] == data [2])
1575 {
1576 *dst++ = val [3];
1577 goto next;
1578 }
1579 }
1580
1581 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1582 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1583 dst - SvPVX (data_sv), len);
1584
1585 next:
1586 data += 3;
1587 len -= 3;
1588 }
1589
1590 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1591}
1592
1593void init_anim () 1563void init_anim ()
1594 1564
1595void init_globals () 1565void init_globals ()
1596 1566
1597void init_experience ()
1598
1599void init_attackmess () 1567void init_attackmess ()
1600 1568
1601void init_dynamic () 1569void init_dynamic ()
1602 1570
1603void load_settings () 1571void load_settings ()
1604 1572
1573void reload_exp_table ()
1574
1605void load_materials () 1575void reload_materials ()
1606 1576
1607void init_uuid () 1577void init_uuid ()
1608 CODE: 1578 CODE:
1609 UUID::init (); 1579 UUID::init ();
1610 1580
1765 1735
1766int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1736int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1767 INIT: 1737 INIT:
1768#if __GLIBC__ 1738#if __GLIBC__
1769 mallopt (M_TOP_PAD, 1024 * 1024); 1739 mallopt (M_TOP_PAD, 1024 * 1024);
1770 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1740 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1771 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))
1772 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1743 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1773#endif 1744#endif
1774 1745
1775int munlockall () 1746int munlockall ()
1776 1747
1777#endif 1748#endif
1815int exp_to_level (val64 exp) 1786int exp_to_level (val64 exp)
1816 1787
1817val64 level_to_min_exp (int level) 1788val64 level_to_min_exp (int level)
1818 1789
1819SV * 1790SV *
1820resistance_to_string (int atnr) 1791attacktype_name (int atnr)
1821 CODE: 1792 CODE:
1822 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)
1823 RETVAL = newSVpv (resist_plus[atnr], 0); 1810 ? newSVpv (resist_plus [atnr], 0)
1824 else 1811 : &PL_sv_undef;
1825 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;
1826 OUTPUT: RETVAL 1820 OUTPUT: RETVAL
1827 1821
1828UUID 1822UUID
1829uuid_cur () 1823uuid_cur ()
1830 CODE: 1824 CODE:
1880 CODE: 1874 CODE:
1881 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1875 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1882 OUTPUT: 1876 OUTPUT:
1883 RETVAL 1877 RETVAL
1884 1878
1879bool should_invoke (attachable *obj, int event)
1880 CODE:
1881 RETVAL = obj->should_invoke ((event_type)event);
1882 OUTPUT: RETVAL
1883
1885void 1884void
1886debug_trace (attachable *obj, bool on = true) 1885debug_trace (attachable *obj, bool on = true)
1887 CODE: 1886 CODE:
1888 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1887 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1889 if (on) 1888 if (on)
1948int mortals_size () 1947int mortals_size ()
1949 CODE: 1948 CODE:
1950 RETVAL = attachable::mortals.size (); 1949 RETVAL = attachable::mortals.size ();
1951 OUTPUT: RETVAL 1950 OUTPUT: RETVAL
1952 1951
1953const_utf8_string slot_use_name (U32 slot) 1952const_utf8_string slot_name (U32 slot)
1954 ALIAS: 1953 ALIAS:
1954 slot_name = 0
1955 slot_use_name = 1
1955 slot_nonuse_name = 1 1956 slot_nonuse_name = 2
1956 CODE: 1957 CODE:
1957{ 1958{
1958 if (slot >= NUM_BODY_LOCATIONS) 1959 if (slot >= NUM_BODY_LOCATIONS)
1959 croak ("body slot index out of range"); 1960 croak ("body slot index out of range");
1960 1961
1961 switch (ix) 1962 switch (ix)
1962 { 1963 {
1964 case 0: RETVAL = body_locations[slot].name ; break;
1963 case 0: RETVAL = body_locations[slot].use_name; break; 1965 case 1: RETVAL = body_locations[slot].use_name ; break;
1964 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1966 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1965 } 1967 }
1966} 1968}
1967 OUTPUT: 1969 OUTPUT:
1968 RETVAL 1970 RETVAL
1969 1971
2075 2077
2076void pick_up (object *who, object *op) 2078void pick_up (object *who, object *op)
2077 2079
2078void update_object (object *op, int action) 2080void update_object (object *op, int action)
2079 2081
2080void 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)
2081 2083
2082void player_lvl_adj (object *who, object *skill = 0) 2084void player_lvl_adj (object *who, object *skill = 0)
2083 2085
2084int 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)
2085 2087
2130 RETVAL = 0; 2132 RETVAL = 0;
2131} 2133}
2132 2134
2133shstr 2135shstr
2134object::kv_get (shstr key) 2136object::kv_get (shstr key)
2137 CODE:
2138 RETVAL = THIS->kv.get (key);
2139 OUTPUT:
2140 RETVAL
2135 2141
2136void 2142void
2137object::kv_del (shstr key) 2143object::kv_del (shstr key)
2144 CODE:
2145 THIS->kv.del (key);
2138 2146
2139void 2147void
2140object::kv_set (shstr key, shstr value) 2148object::kv_set (shstr key, shstr value)
2149 CODE:
2150 THIS->kv.set (key, value);
2141 2151
2142object *get_nearest_player (object *ob) 2152object *get_nearest_player (object *ob)
2143 ALIAS: nearest_player = 0 2153 ALIAS: nearest_player = 0
2144 PREINIT: 2154 PREINIT:
2145 extern object *get_nearest_player (object *); 2155 extern object *get_nearest_player (object *);
2347 for_all_players (pl) 2357 for_all_players (pl)
2348 if (pl->ob && pl->ob->map == THIS) 2358 if (pl->ob && pl->ob->map == THIS)
2349 PUSHs (sv_2mortal (to_sv (pl->ob))); 2359 PUSHs (sv_2mortal (to_sv (pl->ob)));
2350 } 2360 }
2351 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
2352void 2420void
2353maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2354 CODE: 2422 CODE:
2355{ 2423{
2356 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2387 op->flag [FLAG_NO_MAP_SAVE] = true; 2455 op->flag [FLAG_NO_MAP_SAVE] = true;
2388 // TODO: if this is a pickable object, then the item 2456 // TODO: if this is a pickable object, then the item
2389 // will at a bit weird - saving inside the player 2457 // will at a bit weird - saving inside the player
2390 // will clear the flag, but when the player drops 2458 // will clear the flag, but when the player drops
2391 // it without logging out, it keeps the flag. 2459 // it without logging out, it keeps the flag.
2392 // nobody ahs reported this, but this can be rather 2460 // nobody has reported this, but this can be rather
2393 // annoying on persistent maps. 2461 // annoying on persistent maps.
2394 } 2462 }
2395 } 2463 }
2396 } 2464 }
2397 } 2465 }
2398
2399 skip: ; 2466 skip: ;
2400 } 2467 }
2401} 2468}
2402 2469
2403void 2470void
2434 for (int x = 0; x < THIS->width; ++x) 2501 for (int x = 0; x < THIS->width; ++x)
2435 for (int y = 0; y < THIS->height; ++y) 2502 for (int y = 0; y < THIS->height; ++y)
2436 { 2503 {
2437 region *rgn = THIS->region (x, y); 2504 region *rgn = THIS->region (x, y);
2438 2505
2439 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2440 if (object *op = THIS->at (x, y).top) 2506 if (object *op = THIS->at (x, y).top)
2441 if (rgn->treasure && rndm () < rgn->treasure_density) 2507 if (rgn->treasure && rndm () < rgn->treasure_density)
2442 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2508 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2443 } 2509 }
2444 2510
2450 if (oblinkpt *obp = map->find_link (connection)) 2516 if (oblinkpt *obp = map->find_link (connection))
2451 for (objectlink *ol = obp->link; ol; ol = ol->next) 2517 for (objectlink *ol = obp->link; ol; ol = ol->next)
2452 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2518 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2453 2519
2454void 2520void
2455get_map_flags (maptile *map, int x, int y) 2521xy_normalise (maptile *map, int x, int y, int dir = 0)
2456 PPCODE: 2522 PPCODE:
2457{ 2523{
2458 maptile *nmap = 0; 2524 mapxy pos (map, x, y);
2459 I16 nx = 0, ny = 0; 2525 if (!pos.move (dir).normalise ())
2526 XSRETURN_EMPTY;
2460 2527
2461 PUTBACK;
2462 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2463 SPAGAIN;
2464
2465 EXTEND (SP, 4); 2528 EXTEND (SP, 3);
2466 PUSHs (sv_2mortal (newSViv (flags)));
2467
2468 if (GIMME_V == G_ARRAY)
2469 {
2470 PUSHs (sv_2mortal (to_sv (nmap))); 2529 PUSHs (sv_2mortal (to_sv (pos.m)));
2471 PUSHs (sv_2mortal (newSViv (nx))); 2530 PUSHs (sv_2mortal (to_sv (pos.x)));
2472 PUSHs (sv_2mortal (newSViv (ny))); 2531 PUSHs (sv_2mortal (to_sv (pos.y)));
2473 }
2474} 2532}
2475 2533
2476mapspace * 2534mapspace *
2477ms (maptile *map, unsigned int x, unsigned int y) 2535ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2478 PROTOTYPE: $$$ 2536 PROTOTYPE: $$$;$
2479 CODE: 2537 CODE:
2480{ 2538{
2481 maptile *nmap = 0; 2539 mapxy pos (map, x, y);
2482 I16 nx, ny; 2540 if (!pos.move (dir).normalise ())
2483
2484 PUTBACK;
2485 get_map_flags (map, &nmap, x, y, &nx, &ny);
2486 SPAGAIN;
2487
2488 if (!nmap)
2489 XSRETURN_UNDEF; 2541 XSRETURN_UNDEF;
2490 2542
2491 RETVAL = &nmap->at (nx, ny); 2543 RETVAL = &*pos;
2492} 2544}
2493 OUTPUT: 2545 OUTPUT:
2494 RETVAL 2546 RETVAL
2495 2547
2496void 2548void
2497at (maptile *map, unsigned int x, unsigned int y) 2549at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2498 PROTOTYPE: $$$ 2550 PROTOTYPE: $$$;$
2499 PPCODE: 2551 PPCODE:
2500{ 2552 mapxy pos (map, x, y);
2501 maptile *nmap = 0; 2553 if (pos.move (dir).normalise ())
2502 I16 nx, ny;
2503
2504 PUTBACK;
2505 get_map_flags (map, &nmap, x, y, &nx, &ny);
2506 SPAGAIN;
2507
2508 if (nmap)
2509 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2554 for (object *o = pos->bot; o; o = o->above)
2510 XPUSHs (sv_2mortal (to_sv (o))); 2555 XPUSHs (sv_2mortal (to_sv (o)));
2511}
2512 2556
2513SV * 2557SV *
2514bot_at (maptile *map, unsigned int x, unsigned int y) 2558bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2515 PROTOTYPE: $$$ 2559 PROTOTYPE: $$$;$
2516 ALIAS: 2560 ALIAS:
2517 top_at = 1 2561 top_at = 1
2518 flags_at = 2 2562 flags_at = 2
2519 light_at = 3 2563 light_at = 3
2520 move_block_at = 4 2564 move_block_at = 4
2521 move_slow_at = 5 2565 move_slow_at = 5
2522 move_on_at = 6 2566 move_on_at = 6
2523 move_off_at = 7 2567 move_off_at = 7
2524 CODE: 2568 CODE:
2525{ 2569{
2526 sint16 nx = x; 2570 mapxy pos (map, x, y);
2527 sint16 ny = y; 2571 if (!pos.move (dir).normalise ())
2528
2529 if (!xy_normalise (map, nx, ny))
2530 XSRETURN_UNDEF; 2572 XSRETURN_UNDEF;
2531 2573
2532 mapspace &ms = map->at (nx, ny); 2574 mapspace &ms = *pos;
2533 2575
2534 ms.update (); 2576 ms.update ();
2535 2577
2536 switch (ix) 2578 switch (ix)
2537 { 2579 {
2547} 2589}
2548 OUTPUT: RETVAL 2590 OUTPUT: RETVAL
2549 2591
2550# worst xs function of my life 2592# worst xs function of my life
2551bool 2593bool
2552_create_random_map (\ 2594_create_random_map (maptile *self, SV *options)
2553 maptile *self,\
2554 utf8_string wallstyle,\
2555 utf8_string wall_name,\
2556 utf8_string floorstyle,\
2557 utf8_string monsterstyle,\
2558 utf8_string treasurestyle,\
2559 utf8_string layoutstyle,\
2560 utf8_string doorstyle,\
2561 utf8_string decorstyle,\
2562 utf8_string miningstyle,\
2563 utf8_string origin_map,\
2564 utf8_string final_map,\
2565 utf8_string exitstyle,\
2566 utf8_string this_map,\
2567 utf8_string exit_on_final_map,\
2568 int xsize,\
2569 int ysize,\
2570 int expand2x,\
2571 int layoutoptions1,\
2572 int layoutoptions2,\
2573 int layoutoptions3,\
2574 int symmetry,\
2575 int difficulty,\
2576 int difficulty_given,\
2577 float difficulty_increase,\
2578 int dungeon_level,\
2579 int dungeon_depth,\
2580 int decoroptions,\
2581 int orientation,\
2582 int origin_y,\
2583 int origin_x,\
2584 U32 random_seed,\
2585 val64 total_map_hp,\
2586 int map_layout_style,\
2587 int treasureoptions,\
2588 int symmetry_used,\
2589 region *region,\
2590 utf8_string custom\
2591)
2592 CODE: 2595 CODE:
2593{ 2596{
2594 random_map_params rmp; 2597 random_map_params rmp ((HV *)SvRV (options));
2595
2596 assign (rmp.wallstyle , wallstyle);
2597 assign (rmp.wall_name , wall_name);
2598 assign (rmp.floorstyle , floorstyle);
2599 assign (rmp.monsterstyle , monsterstyle);
2600 assign (rmp.treasurestyle , treasurestyle);
2601 assign (rmp.layoutstyle , layoutstyle);
2602 assign (rmp.doorstyle , doorstyle);
2603 assign (rmp.decorstyle , decorstyle);
2604 assign (rmp.miningstyle , miningstyle);
2605 assign (rmp.exitstyle , exitstyle);
2606 assign (rmp.exit_on_final_map, exit_on_final_map);
2607
2608 rmp.origin_map = origin_map;
2609 rmp.final_map = final_map;
2610 rmp.this_map = this_map;
2611 rmp.xsize = xsize;
2612 rmp.ysize = ysize;
2613 rmp.expand2x = expand2x;
2614 rmp.layoutoptions1 = layoutoptions1;
2615 rmp.layoutoptions2 = layoutoptions2;
2616 rmp.layoutoptions3 = layoutoptions3;
2617 rmp.symmetry = symmetry;
2618 rmp.difficulty = difficulty;
2619 rmp.difficulty_given = difficulty_given;
2620 rmp.difficulty_increase = difficulty_increase;
2621 rmp.dungeon_level = dungeon_level;
2622 rmp.dungeon_depth = dungeon_depth;
2623 rmp.decoroptions = decoroptions;
2624 rmp.orientation = orientation;
2625 rmp.origin_y = origin_y;
2626 rmp.origin_x = origin_x;
2627 rmp.random_seed = random_seed;
2628 rmp.total_map_hp = (uint64_t) total_map_hp;
2629 rmp.map_layout_style = map_layout_style;
2630 rmp.treasureoptions = treasureoptions;
2631 rmp.symmetry_used = symmetry_used;
2632 rmp.region = region;
2633 rmp.custom = custom;
2634
2635 RETVAL = self->generate_random_map (&rmp); 2598 RETVAL = self->generate_random_map (&rmp);
2636} 2599}
2637 OUTPUT: 2600 OUTPUT:
2638 RETVAL 2601 RETVAL
2639 2602
2670void 2633void
2671list () 2634list ()
2672 PPCODE: 2635 PPCODE:
2673 for_all_regions (rgn) 2636 for_all_regions (rgn)
2674 XPUSHs (sv_2mortal (to_sv (rgn))); 2637 XPUSHs (sv_2mortal (to_sv (rgn)));
2675
2676region *find (utf8_string name)
2677 PROTOTYPE: $
2678 CODE:
2679 RETVAL = region::find (name);
2680 OUTPUT: RETVAL
2681 2638
2682int specificity (region *rgn) 2639int specificity (region *rgn)
2683 CODE: 2640 CODE:
2684 RETVAL = 0; 2641 RETVAL = 0;
2685 while (rgn = rgn->parent) 2642 while (rgn = rgn->parent)
2817 2774
2818void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2819 CODE: 2776 CODE:
2820{ 2777{
2821 faceinfo *f = face_info (idx); assert (f); 2778 faceinfo *f = face_info (idx); assert (f);
2822 facedata *d = &(faceset ? f->data64 : f->data32); 2779 facedata *d = f->face + faceset;
2823 sv_to (data, d->data); 2780 sv_to (data, d->data);
2824 STRLEN clen; 2781 STRLEN clen;
2825 char *cdata = SvPVbyte (chksum, clen); 2782 char *cdata = SvPVbyte (chksum, clen);
2826 clen = min (CHKSUM_MAXLEN, clen); 2783 clen = min (CHKSUM_MAXLEN, clen);
2827 2784
2979 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2936 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2980 2937
2981 self->skip (); 2938 self->skip ();
2982 } 2939 }
2983 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