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.409 by root, Wed Jan 4 02:48:57 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
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)); }
616static inline void sv_to (SV *sv, std::string &v) 623static inline void sv_to (SV *sv, std::string &v)
617{ 624{
618 STRLEN len; 625 STRLEN len;
619 char *data = SvPVbyte (sv, len); 626 char *data = SvPVbyte (sv, len);
620 v.assign (data, len); 627 v.assign (data, len);
628}
629
630static inline void sv_to (SV *sv, refcnt_buf &v)
631{
632 STRLEN len;
633 char *data = SvPVbyte (sv, len);
634 refcnt_buf buf (data, len);
635 v = buf;
621} 636}
622 637
623static inline void sv_to (SV *sv, UUID &v) 638static inline void sv_to (SV *sv, UUID &v)
624{ 639{
625 if (!v.parse (SvPV_nolen (sv))) 640 if (!v.parse (SvPV_nolen (sv)))
1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1412 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1413 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1414 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1415 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1401 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1416 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1417 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1402 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1418 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1403 1419
1404 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1420 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1405 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1421 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1422 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1406 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1423 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1407 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1424 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1408 1425
1409 cb_global = get_av ("cf::CB_GLOBAL", 1); 1426 cb_global = get_av ("cf::CB_GLOBAL", 1);
1410 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1427 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1411 cb_object = get_av ("cf::CB_OBJECT", 1); 1428 cb_object = get_av ("cf::CB_OBJECT", 1);
1412 cb_player = get_av ("cf::CB_PLAYER", 1); 1429 cb_player = get_av ("cf::CB_PLAYER", 1);
1455# include "attackinc.h" 1472# include "attackinc.h"
1456# undef def 1473# undef def
1457# define def(uc, flags) const_iv (SK_ ## uc) 1474# define def(uc, flags) const_iv (SK_ ## uc)
1458# include "skillinc.h" 1475# include "skillinc.h"
1459# undef def 1476# undef def
1460 1477# define def(name, use, nonuse) const_iv (body_ ## name)
1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1478# include "slotinc.h"
1479# undef def
1462 1480
1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1481 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1464 1482
1465 const_iv (MAX_TIME) 1483 const_iv (MAX_TIME)
1466 const_iv (MAXSOCKBUF) 1484 const_iv (MAXSOCKBUF)
1479 1497
1480 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1498 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1481 1499
1482 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1500 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) 1501 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 1502
1488 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1503 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) 1504 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1490 1505
1491 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1506 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1552 1567
1553 for_all_objects (op) 1568 for_all_objects (op)
1554 op->reattach (); 1569 op->reattach ();
1555} 1570}
1556 1571
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 () 1572void init_anim ()
1600 1573
1601void init_globals () 1574void init_globals ()
1602 1575
1603void init_experience ()
1604
1605void init_attackmess () 1576void init_attackmess ()
1606 1577
1607void init_dynamic () 1578void init_dynamic ()
1608 1579
1609void load_settings () 1580void load_settings ()
1610 1581
1582void reload_exp_table ()
1583
1611void load_materials () 1584void reload_materials ()
1612 1585
1613void init_uuid () 1586void init_uuid ()
1614 CODE: 1587 CODE:
1615 UUID::init (); 1588 UUID::init ();
1616 1589
1649 { 1622 {
1650 ev_async_send (EV_DEFAULT, &tick_watcher); 1623 ev_async_send (EV_DEFAULT, &tick_watcher);
1651 coroapi::cede (); 1624 coroapi::cede ();
1652 } 1625 }
1653 1626
1654void server_tick () 1627void one_tick ()
1655 CODE: 1628 CODE:
1656{ 1629{
1657 ev_now_update (EV_DEFAULT); 1630 ev_now_update (EV_DEFAULT);
1658 NOW = ev_now (EV_DEFAULT); 1631 NOW = ev_now (EV_DEFAULT);
1659 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1632 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1660 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1633 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1661 runtime = SvNVX (sv_runtime); 1634 runtime = SvNVX (sv_runtime);
1662 1635
1636 one_tick ();
1637
1663 server_tick (); 1638 ++server_tick;
1639 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1664 1640
1665 ev_now_update (EV_DEFAULT); 1641 ev_now_update (EV_DEFAULT);
1666 NOW = ev_now (EV_DEFAULT); 1642 NOW = ev_now (EV_DEFAULT);
1667 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1643 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1644
1668 runtime += TICK; 1645 runtime += TICK;
1669 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1646 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1670} 1647}
1671 1648
1672NV floor (NV x) 1649NV floor (NV x)
1771 1748
1772int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1749int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1773 INIT: 1750 INIT:
1774#if __GLIBC__ 1751#if __GLIBC__
1775 mallopt (M_TOP_PAD, 1024 * 1024); 1752 mallopt (M_TOP_PAD, 1024 * 1024);
1776 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1753 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1777 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1754 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1755 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1778 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1756 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1779#endif 1757#endif
1780 1758
1781int munlockall () 1759int munlockall ()
1782 1760
1783#endif 1761#endif
1821int exp_to_level (val64 exp) 1799int exp_to_level (val64 exp)
1822 1800
1823val64 level_to_min_exp (int level) 1801val64 level_to_min_exp (int level)
1824 1802
1825SV * 1803SV *
1826resistance_to_string (int atnr) 1804attacktype_name (int atnr)
1827 CODE: 1805 CODE:
1828 if (atnr >= 0 && atnr < NROFATTACKS) 1806 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1807 ? newSVpv (attacktype_name [atnr], 0)
1808 : &PL_sv_undef;
1809 OUTPUT: RETVAL
1810
1811SV *
1812attacktype_desc (int atnr)
1813 CODE:
1814 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1815 ? newSVpv (attacktype_desc [atnr], 0)
1816 : &PL_sv_undef;
1817 OUTPUT: RETVAL
1818
1819SV *
1820resist_plus (int atnr)
1821 CODE:
1822 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1823 ? newSVpv (resist_plus [atnr], 0)
1830 else 1824 : &PL_sv_undef;
1831 XSRETURN_UNDEF; 1825 OUTPUT: RETVAL
1826
1827SV *
1828change_resist_msg (int atnr)
1829 CODE:
1830 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1831 ? newSVpv (change_resist_msg [atnr], 0)
1832 : &PL_sv_undef;
1832 OUTPUT: RETVAL 1833 OUTPUT: RETVAL
1833 1834
1834UUID 1835UUID
1835uuid_cur () 1836uuid_cur ()
1836 CODE: 1837 CODE:
1959int mortals_size () 1960int mortals_size ()
1960 CODE: 1961 CODE:
1961 RETVAL = attachable::mortals.size (); 1962 RETVAL = attachable::mortals.size ();
1962 OUTPUT: RETVAL 1963 OUTPUT: RETVAL
1963 1964
1964const_utf8_string slot_use_name (U32 slot) 1965const_utf8_string slot_name (U32 slot)
1965 ALIAS: 1966 ALIAS:
1967 slot_name = 0
1968 slot_use_name = 1
1966 slot_nonuse_name = 1 1969 slot_nonuse_name = 2
1967 CODE: 1970 CODE:
1968{ 1971{
1969 if (slot >= NUM_BODY_LOCATIONS) 1972 if (slot >= NUM_BODY_LOCATIONS)
1970 croak ("body slot index out of range"); 1973 croak ("body slot index out of range");
1971 1974
1972 switch (ix) 1975 switch (ix)
1973 { 1976 {
1977 case 0: RETVAL = body_locations[slot].name ; break;
1974 case 0: RETVAL = body_locations[slot].use_name; break; 1978 case 1: RETVAL = body_locations[slot].use_name ; break;
1975 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1979 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1976 } 1980 }
1977} 1981}
1978 OUTPUT: 1982 OUTPUT:
1979 RETVAL 1983 RETVAL
1980 1984
2112# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2116# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2113 2117
2114object *new (utf8_string archetype = 0) 2118object *new (utf8_string archetype = 0)
2115 PROTOTYPE: ;$ 2119 PROTOTYPE: ;$
2116 CODE: 2120 CODE:
2117 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2121 RETVAL = archetype
2122 ? archetype::get (archetype)
2123 : object::create ();
2118 OUTPUT: 2124 OUTPUT:
2119 RETVAL 2125 RETVAL
2120 2126
2121object *generate (utf8_string arch, object *creator) 2127object *generate (utf8_string arch, object *creator)
2122 CODE: 2128 CODE:
2123 object *obj = get_archetype (arch); 2129 object *obj = archetype::get (arch);
2124 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2130 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2125 RETVAL = obj; 2131 RETVAL = obj;
2126 OUTPUT: 2132 OUTPUT:
2127 RETVAL 2133 RETVAL
2128 2134
2138 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2144 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2139 2145
2140 if (RETVAL->destroyed ()) 2146 if (RETVAL->destroyed ())
2141 RETVAL = 0; 2147 RETVAL = 0;
2142} 2148}
2149 OUTPUT:
2150 RETVAL
2143 2151
2144shstr 2152shstr
2145object::kv_get (shstr key) 2153object::kv_get (shstr key)
2154 CODE:
2155 RETVAL = THIS->kv.get (key);
2156 OUTPUT:
2157 RETVAL
2146 2158
2147void 2159void
2148object::kv_del (shstr key) 2160object::kv_del (shstr key)
2161 CODE:
2162 THIS->kv.del (key);
2149 2163
2150void 2164void
2151object::kv_set (shstr key, shstr value) 2165object::kv_set (shstr key, shstr value)
2166 CODE:
2167 THIS->kv.set (key, value);
2152 2168
2153object *get_nearest_player (object *ob) 2169object *get_nearest_player (object *ob)
2154 ALIAS: nearest_player = 0 2170 ALIAS: nearest_player = 0
2155 PREINIT: 2171 PREINIT:
2156 extern object *get_nearest_player (object *); 2172 extern object *get_nearest_player (object *);
2359 if (pl->ob && pl->ob->map == THIS) 2375 if (pl->ob && pl->ob->map == THIS)
2360 PUSHs (sv_2mortal (to_sv (pl->ob))); 2376 PUSHs (sv_2mortal (to_sv (pl->ob)));
2361 } 2377 }
2362 2378
2363void 2379void
2380maptile::gen_quadmap (int x, int y, int z)
2381 CODE:
2382 gen_quadmap (THIS, x * 50, y * 50, z);
2383
2384void
2364maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2385maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2365 CODE: 2386 CODE:
2366{ 2387{
2367 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2388 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2368 croak ("maptile::add_underlay: palette must be arrayref"); 2389 croak ("maptile::add_underlay: palette must be arrayref");
2384 2405
2385 if (IN_RANGE_EXC (offs, 0, idxlen)) 2406 if (IN_RANGE_EXC (offs, 0, idxlen))
2386 { 2407 {
2387 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2408 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2388 { 2409 {
2389 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2410 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2390 ob->flag [FLAG_NO_MAP_SAVE] = true; 2411 ob->flag [FLAG_NO_MAP_SAVE] = true;
2391 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2412 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2392 2413
2393 if (ob->randomitems && !ob->above) 2414 if (ob->randomitems && !ob->above)
2394 { 2415 {
2398 op->flag [FLAG_NO_MAP_SAVE] = true; 2419 op->flag [FLAG_NO_MAP_SAVE] = true;
2399 // TODO: if this is a pickable object, then the item 2420 // TODO: if this is a pickable object, then the item
2400 // will at a bit weird - saving inside the player 2421 // will at a bit weird - saving inside the player
2401 // will clear the flag, but when the player drops 2422 // will clear the flag, but when the player drops
2402 // it without logging out, it keeps the flag. 2423 // it without logging out, it keeps the flag.
2403 // nobody ahs reported this, but this can be rather 2424 // nobody has reported this, but this can be rather
2404 // annoying on persistent maps. 2425 // annoying on persistent maps.
2405 } 2426 }
2406 } 2427 }
2407 } 2428 }
2408 } 2429 }
2409
2410 skip: ; 2430 skip: ;
2411 } 2431 }
2412} 2432}
2413 2433
2414void 2434void
2445 for (int x = 0; x < THIS->width; ++x) 2465 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2466 for (int y = 0; y < THIS->height; ++y)
2447 { 2467 {
2448 region *rgn = THIS->region (x, y); 2468 region *rgn = THIS->region (x, y);
2449 2469
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) 2470 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2471 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2472 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2473 }
2455 2474
2534} 2553}
2535 OUTPUT: RETVAL 2554 OUTPUT: RETVAL
2536 2555
2537# worst xs function of my life 2556# worst xs function of my life
2538bool 2557bool
2539_create_random_map (\ 2558_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: 2559 CODE:
2580{ 2560{
2581 random_map_params rmp; 2561 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); 2562 RETVAL = self->generate_random_map (&rmp);
2623} 2563}
2624 OUTPUT: 2564 OUTPUT:
2625 RETVAL 2565 RETVAL
2626 2566
2760faceidx face_find (utf8_string name, faceidx defidx = 0) 2700faceidx face_find (utf8_string name, faceidx defidx = 0)
2761 2701
2762faceidx alloc (utf8_string name) 2702faceidx alloc (utf8_string name)
2763 CODE: 2703 CODE:
2764{ 2704{
2765 do 2705 RETVAL = face_alloc ();
2766 {
2767 RETVAL = faces.size ();
2768 faces.resize (RETVAL + 1);
2769 }
2770 while (!RETVAL); // crude way to leave index 0
2771 2706
2772 faces [RETVAL].name = name; 2707 faces [RETVAL].name = name;
2773 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2708 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2774 2709
2775 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2710 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2798 2733
2799void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2734void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2800 CODE: 2735 CODE:
2801{ 2736{
2802 faceinfo *f = face_info (idx); assert (f); 2737 faceinfo *f = face_info (idx); assert (f);
2803 facedata *d = &(faceset ? f->data64 : f->data32); 2738 facedata *d = f->face + faceset;
2804 sv_to (data, d->data); 2739 sv_to (data, d->data);
2805 STRLEN clen; 2740 STRLEN clen;
2806 char *cdata = SvPVbyte (chksum, clen); 2741 char *cdata = SvPVbyte (chksum, clen);
2807 clen = min (CHKSUM_MAXLEN, clen); 2742 clen = min (CHKSUM_MAXLEN, clen);
2808 2743
2829 if (!d) XSRETURN_UNDEF; 2764 if (!d) XSRETURN_UNDEF;
2830 RETVAL = d->data.size (); 2765 RETVAL = d->data.size ();
2831 OUTPUT: 2766 OUTPUT:
2832 RETVAL 2767 RETVAL
2833 2768
2769void set_meta (faceidx idx, SV *sv)
2770 CODE:
2771{
2772 faceinfo *f = face_info (idx); assert (f);
2773 SvREFCNT_dec (f->meta_hv);
2774 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2775}
2776
2834SV *get_chksum (faceidx idx, int faceset = 0) 2777SV *get_chksum (faceidx idx, int faceset = 0)
2835 CODE: 2778 CODE:
2836 facedata *d = face_data (idx, faceset); 2779 facedata *d = face_data (idx, faceset);
2837 if (!d) XSRETURN_UNDEF; 2780 if (!d) XSRETURN_UNDEF;
2838 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2781 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2841 2784
2842SV *get_data (faceidx idx, int faceset = 0) 2785SV *get_data (faceidx idx, int faceset = 0)
2843 CODE: 2786 CODE:
2844 facedata *d = face_data (idx, faceset); 2787 facedata *d = face_data (idx, faceset);
2845 if (!d) XSRETURN_UNDEF; 2788 if (!d) XSRETURN_UNDEF;
2846 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2789 RETVAL = newSVpvn (d->data, d->data.size ());
2847 OUTPUT: 2790 OUTPUT:
2848 RETVAL 2791 RETVAL
2849 2792
2793SV *get_meta (faceidx idx)
2794 CODE:
2795 faceinfo *f = face_info (idx); assert (f);
2796 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2797 RETVAL = newRV_inc ((SV *)f->meta_hv);
2798 OUTPUT:
2799 RETVAL
2800
2850void invalidate (faceidx idx) 2801void invalidate (faceidx idx)
2851 CODE: 2802 CODE:
2852 for_all_clients (ns) 2803 for_all_clients (ns)
2853 { 2804 ns->invalidate_face (idx);
2854 ns->faces_sent [idx] = false;
2855 ns->force_newmap = true;
2856 }
2857 2805
2858void invalidate_all () 2806void invalidate_all ()
2859 CODE: 2807 CODE:
2860 for_all_clients (ns) 2808 for_all_clients (ns)
2861 { 2809 ns->invalidate_all_faces ();
2862 ns->faces_sent.reset ();
2863 ns->force_newmap = true;
2864 }
2865 2810
2866MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2811MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2867 2812
2868#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2813#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2869 2814
2960 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2905 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2961 2906
2962 self->skip (); 2907 self->skip ();
2963 } 2908 }
2964 2909
2910MODULE = cf PACKAGE = cf::layout
2911
2912INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2913

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines