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.369 by root, Wed Apr 14 02:31:24 2010 UTC vs.
Revision 1.396 by root, Sun Jan 23 23:35:30 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 "evthread.h" 34#include "evthread.h"
35#include "sproto.h" 35#include "sproto.h"
36 36
37#include <unistd.h> 37#include <unistd.h>
38#if _POSIX_MEMLOCK 38#if _POSIX_MEMLOCK
51#include <perl.h> 51#include <perl.h>
52#include <XSUB.h> 52#include <XSUB.h>
53 53
54#include "CoroAPI.h" 54#include "CoroAPI.h"
55#include "perlxsi.c" 55#include "perlxsi.c"
56
57extern sint64 *levels; // the experience table
58 56
59typedef object_thawer &object_thawer_ref; 57typedef object_thawer &object_thawer_ref;
60typedef object_freezer &object_freezer_ref; 58typedef object_freezer &object_freezer_ref;
61 59
62typedef std::string std__string; 60typedef std::string std__string;
85 *stash_cf_mapspace_wrap, 83 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 84 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 85 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 86 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 87 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 88 *stash_cf_living_wrap,
89 *stash_cf_layout_wrap,
90 *stash_ext_map_world;
91 91
92static SV 92static SV
93 *cv_cf_do_invoke, 93 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 94 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 95 *cv_cf_client_send_msg,
123 123
124 return sv; 124 return sv;
125} 125}
126#endif 126#endif
127 127
128static noinline utf8_string 128noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 129cfSvPVutf8_nolen (SV *sv)
130{ 130{
131 SvGETMAGIC (sv); 131 SvGETMAGIC (sv);
132 132
133 if (SvPOK (sv)) 133 if (SvPOK (sv))
353#endif 353#endif
354 354
355////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 355//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
356 356
357static SV * 357static SV *
358newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 358newSVptr (void *ptr, HV *stash, HV *hv)
359{ 359{
360 SV *sv;
361
362 if (!ptr) 360 if (!ptr)
363 return newSV (0); 361 return newSV (0);
364 362
365 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 363 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
366 return sv_bless (newRV_noinc ((SV *)hv), stash); 364 return sv_bless (newRV_noinc ((SV *)hv), stash);
365}
366
367static SV * noinline
368newSVptr (void *ptr, HV *stash)
369{
370 return newSVptr (ptr, stash, newHV ());
367} 371}
368 372
369static int 373static int
370attachable_free (pTHX_ SV *sv, MAGIC *mg) 374attachable_free (pTHX_ SV *sv, MAGIC *mg)
371{ 375{
383 return 0; 387 return 0;
384} 388}
385 389
386MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 390MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
387 391
388static SV * 392static SV * noinline
389newSVattachable (attachable *obj, HV *stash) 393newSVattachable (attachable *obj, HV *stash)
390{ 394{
391 if (!obj) 395 if (!obj)
392 return newSV (0); 396 return newSV (0);
393 397
479 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 483 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
480 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 484 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
481 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 485 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
482 && !sv_derived_from (sv, "cf::object"))) 486 && !sv_derived_from (sv, "cf::object")))
483 croak ("object of type cf::object expected"); 487 croak ("object of type cf::object expected");
488
489 return SvPTR_nc (sv);
490}
491
492static long noinline
493SvPTR_ornull_maptile (SV *sv)
494{
495 if (expect_false (!SvOK (sv))) return 0;
496
497 if (!SvROK (sv)
498 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
499 && SvSTASH (SvRV (sv)) != stash_ext_map_world
500 && !sv_derived_from (sv, "cf::map")))
501 croak ("object of type cf::map expected");
484 502
485 return SvPTR_nc (sv); 503 return SvPTR_nc (sv);
486} 504}
487 505
488static long noinline 506static long noinline
513static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 531static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
514static inline SV *to_sv (float v) { return newSVnv (v); } 532static inline SV *to_sv (float v) { return newSVnv (v); }
515static inline SV *to_sv (double v) { return newSVnv (v); } 533static inline SV *to_sv (double v) { return newSVnv (v); }
516static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 534static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
517static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 535static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
536// gcc dislikes noilnine on to_sv
518static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 537static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
538static inline SV *to_sv (object * v) { return to_sv_ni (v); }
519static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 539static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
520static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 540static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
521static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 541static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
522static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 542static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
523static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 543static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
524static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 544static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
545static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
525 546
526static inline SV *to_sv (object & v) { return to_sv (&v); } 547static inline SV *to_sv (object & v) { return to_sv (&v); }
527static inline SV *to_sv (living & v) { return to_sv (&v); } 548static inline SV *to_sv (living & v) { return to_sv (&v); }
528 549
529static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 550static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
565static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 586static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
566static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 587static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
567static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 588static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
568static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 589static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
569static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 590static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
570static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 591static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
571static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 592static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
572static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 593static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
594static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
573static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 595static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
574static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
575static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 596static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
576static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 597static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
577static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 598static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
578static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 599static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
579static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 600static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
601static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
580static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 602static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
581static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 603static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
582 604
583//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 605//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
584static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 606static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
695template<class type> 717template<class type>
696static void noinline 718static void noinline
697cf_obj_to (SV *arg, type &var) 719cf_obj_to (SV *arg, type &var)
698{ 720{
699 sv_to (arg, var); 721 sv_to (arg, var);
700 if (!var) 722 if (expect_false (!var))
701 croak ("must not pass invalid/null cf_obj here"); 723 croak ("must not pass invalid/null cf_obj here");
702} 724}
703 725
704template<class object> 726template<class object>
705static void noinline 727static void noinline
706cf_obj_ornull_to (SV *arg, object *&var) 728cf_obj_ornull_to (SV *arg, object *&var)
707{ 729{
708 if (SvOK (arg)) 730 if (SvOK (arg))
709 { 731 {
710 sv_to (arg, var); 732 sv_to (arg, var);
711 if (!var) 733 if (expect_false (!var))
712 croak ("unable to convert perl object to C++ object"); 734 croak ("unable to convert perl object to C++ object");
713 } 735 }
714 else 736 else
715 var = 0; 737 var = 0;
716} 738}
751 exit (EXIT_FAILURE); 773 exit (EXIT_FAILURE);
752 } 774 }
753 775
754 eval_pv ( 776 eval_pv (
755 "#line 1 'cfperl init'\n" 777 "#line 1 'cfperl init'\n"
756 "use EV ();\n" 778 "use EV ();\n" // required by bootstrap
757 "use Coro ();\n" 779 "use Coro ();\n" // required by bootstrap
758 "cf->bootstrap;\n" 780 "cf->bootstrap;\n" // required for cf::datadir
759 "unshift @INC, cf::datadir ();\n" 781 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
760 "require cf;\n", 782 "require cf;\n",
761 0 783 0
762 ); 784 );
763 785
764 if (SvTRUE (ERRSV)) 786 if (SvTRUE (ERRSV))
1378 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1400 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1379 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1401 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1380 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1402 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1381 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1382 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1383 1407
1384 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1408 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1385 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1409 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1386 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1410 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1387 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1411 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1435# include "attackinc.h" 1459# include "attackinc.h"
1436# undef def 1460# undef def
1437# define def(uc, flags) const_iv (SK_ ## uc) 1461# define def(uc, flags) const_iv (SK_ ## uc)
1438# include "skillinc.h" 1462# include "skillinc.h"
1439# undef def 1463# undef def
1440 1464# define def(name, use, nonuse) const_iv (body_ ## name)
1441 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1465# include "slotinc.h"
1442 const_iv (logBacktrace) 1466# undef def
1443
1444 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1445 1467
1446 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1468 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1447 1469
1448 const_iv (MAX_TIME) 1470 const_iv (MAX_TIME)
1449 const_iv (MAXSOCKBUF) 1471 const_iv (MAXSOCKBUF)
1474 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1496 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1475 1497
1476 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1498 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1477 }; 1499 };
1478 1500
1479 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1501 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1480 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1502 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1481 1503
1482 static const struct { 1504 static const struct {
1483 const char *name; 1505 const char *name;
1484 int skip; 1506 int skip;
1490# undef def 1512# undef def
1491 }; 1513 };
1492 1514
1493 AV *av = get_av ("cf::EVENT", 1); 1515 AV *av = get_av ("cf::EVENT", 1);
1494 1516
1495 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1517 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1496 { 1518 {
1497 AV *event = newAV (); 1519 AV *event = newAV ();
1498 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1520 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1499 av_push (event, newSViv (eiv->klass)); 1521 av_push (event, newSViv (eiv->klass));
1500 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1522 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1581 1603
1582void init_anim () 1604void init_anim ()
1583 1605
1584void init_globals () 1606void init_globals ()
1585 1607
1586void init_experience ()
1587
1588void init_attackmess () 1608void init_attackmess ()
1589 1609
1590void init_dynamic () 1610void init_dynamic ()
1591 1611
1592void load_settings () 1612void load_settings ()
1593 1613
1614void reload_exp_table ()
1615
1594void load_materials () 1616void reload_materials ()
1595 1617
1596void init_uuid () 1618void init_uuid ()
1597 CODE: 1619 CODE:
1598 UUID::init (); 1620 UUID::init ();
1599 1621
1754 1776
1755int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1777int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1756 INIT: 1778 INIT:
1757#if __GLIBC__ 1779#if __GLIBC__
1758 mallopt (M_TOP_PAD, 1024 * 1024); 1780 mallopt (M_TOP_PAD, 1024 * 1024);
1759 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1781 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1760 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1782 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1783 if (__GLIBC_MAJOR < 2 || (__GLIBC_MAJOR == 2 && __GLIBC_MINOR < 10))
1761 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1784 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1762#endif 1785#endif
1763 1786
1764int munlockall () 1787int munlockall ()
1765 1788
1766#endif 1789#endif
1799 1822
1800int random_roll (int min, int max, object *op, int goodbad); 1823int random_roll (int min, int max, object *op, int goodbad);
1801 1824
1802const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1825const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1803 1826
1804int
1805exp_to_level (val64 exp) 1827int exp_to_level (val64 exp)
1828
1829val64 level_to_min_exp (int level)
1830
1831SV *
1832attacktype_name (int atnr)
1806 CODE: 1833 CODE:
1807{ 1834 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1808 int i = 0; 1835 ? newSVpv (attacktype_name [atnr], 0)
1809 1836 : &PL_sv_undef;
1810 RETVAL = settings.max_level;
1811
1812 for (i = 1; i <= settings.max_level; i++)
1813 {
1814 if (levels[i] > exp)
1815 {
1816 RETVAL = i - 1;
1817 break;
1818 }
1819 }
1820}
1821 OUTPUT: RETVAL 1837 OUTPUT: RETVAL
1822 1838
1823val64
1824level_to_min_exp (int level)
1825 CODE:
1826 if (level > settings.max_level)
1827 RETVAL = levels[settings.max_level];
1828 else if (level < 1)
1829 RETVAL = 0;
1830 else
1831 RETVAL = levels[level];
1832 OUTPUT: RETVAL
1833
1834SV * 1839SV *
1835resistance_to_string (int atnr) 1840attacktype_desc (int atnr)
1836 CODE: 1841 CODE:
1837 if (atnr >= 0 && atnr < NROFATTACKS) 1842 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1843 ? newSVpv (attacktype_desc [atnr], 0)
1844 : &PL_sv_undef;
1845 OUTPUT: RETVAL
1846
1847SV *
1848resist_plus (int atnr)
1849 CODE:
1850 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1838 RETVAL = newSVpv (resist_plus[atnr], 0); 1851 ? newSVpv (resist_plus [atnr], 0)
1839 else 1852 : &PL_sv_undef;
1840 XSRETURN_UNDEF; 1853 OUTPUT: RETVAL
1854
1855SV *
1856change_resist_msg (int atnr)
1857 CODE:
1858 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1859 ? newSVpv (change_resist_msg [atnr], 0)
1860 : &PL_sv_undef;
1841 OUTPUT: RETVAL 1861 OUTPUT: RETVAL
1842 1862
1843UUID 1863UUID
1844uuid_cur () 1864uuid_cur ()
1845 CODE: 1865 CODE:
1895 CODE: 1915 CODE:
1896 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1916 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1897 OUTPUT: 1917 OUTPUT:
1898 RETVAL 1918 RETVAL
1899 1919
1920bool should_invoke (attachable *obj, int event)
1921 CODE:
1922 RETVAL = obj->should_invoke ((event_type)event);
1923 OUTPUT: RETVAL
1924
1900void 1925void
1901debug_trace (attachable *obj, bool on = true) 1926debug_trace (attachable *obj, bool on = true)
1902 CODE: 1927 CODE:
1903 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1928 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1904 if (on) 1929 if (on)
1963int mortals_size () 1988int mortals_size ()
1964 CODE: 1989 CODE:
1965 RETVAL = attachable::mortals.size (); 1990 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1991 OUTPUT: RETVAL
1967 1992
1968const_utf8_string slot_use_name (U32 slot) 1993const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1994 ALIAS:
1995 slot_name = 0
1996 slot_use_name = 1
1970 slot_nonuse_name = 1 1997 slot_nonuse_name = 2
1971 CODE: 1998 CODE:
1972{ 1999{
1973 if (slot >= NUM_BODY_LOCATIONS) 2000 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 2001 croak ("body slot index out of range");
1975 2002
1976 switch (ix) 2003 switch (ix)
1977 { 2004 {
2005 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 2006 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 2007 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 2008 }
1981} 2009}
1982 OUTPUT: 2010 OUTPUT:
1983 RETVAL 2011 RETVAL
1984 2012
2029 OUTPUT: 2057 OUTPUT:
2030 RETVAL 2058 RETVAL
2031 2059
2032object *find_best_object_match (object *op, utf8_string match) 2060object *find_best_object_match (object *op, utf8_string match)
2033 2061
2034object *find_marked_object (object *op)
2035
2036int need_identify (object *obj);
2037
2038int apply_shop_mat (object *shop_mat, object *op); 2062int apply_shop_mat (object *shop_mat, object *op);
2039 2063
2040int move (object *op, int dir, object *originator = op) 2064int move (object *op, int dir, object *originator = op)
2041 CODE: 2065 CODE:
2042 RETVAL = op->move (dir, originator); 2066 RETVAL = op->move (dir, originator);
2094 2118
2095void pick_up (object *who, object *op) 2119void pick_up (object *who, object *op)
2096 2120
2097void update_object (object *op, int action) 2121void update_object (object *op, int action)
2098 2122
2099void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2123void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2100 2124
2101void player_lvl_adj (object *who, object *skill = 0) 2125void player_lvl_adj (object *who, object *skill = 0)
2102 2126
2103int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2127int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2104 2128
2469 if (oblinkpt *obp = map->find_link (connection)) 2493 if (oblinkpt *obp = map->find_link (connection))
2470 for (objectlink *ol = obp->link; ol; ol = ol->next) 2494 for (objectlink *ol = obp->link; ol; ol = ol->next)
2471 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2495 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2472 2496
2473void 2497void
2474get_map_flags (maptile *map, int x, int y) 2498xy_normalise (maptile *map, int x, int y, int dir = 0)
2475 PPCODE: 2499 PPCODE:
2476{ 2500{
2477 maptile *nmap = 0; 2501 mapxy pos (map, x, y);
2478 I16 nx = 0, ny = 0; 2502 if (!pos.move (dir).normalise ())
2503 XSRETURN_EMPTY;
2479 2504
2480 PUTBACK;
2481 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2482 SPAGAIN;
2483
2484 EXTEND (SP, 4); 2505 EXTEND (SP, 3);
2485 PUSHs (sv_2mortal (newSViv (flags)));
2486
2487 if (GIMME_V == G_ARRAY)
2488 {
2489 PUSHs (sv_2mortal (to_sv (nmap))); 2506 PUSHs (sv_2mortal (to_sv (pos.m)));
2490 PUSHs (sv_2mortal (newSViv (nx))); 2507 PUSHs (sv_2mortal (to_sv (pos.x)));
2491 PUSHs (sv_2mortal (newSViv (ny))); 2508 PUSHs (sv_2mortal (to_sv (pos.y)));
2492 }
2493} 2509}
2494 2510
2495mapspace * 2511mapspace *
2496ms (maptile *map, unsigned int x, unsigned int y) 2512ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2497 PROTOTYPE: $$$ 2513 PROTOTYPE: $$$;$
2498 CODE: 2514 CODE:
2499{ 2515{
2500 maptile *nmap = 0; 2516 mapxy pos (map, x, y);
2501 I16 nx, ny; 2517 if (!pos.move (dir).normalise ())
2502
2503 PUTBACK;
2504 get_map_flags (map, &nmap, x, y, &nx, &ny);
2505 SPAGAIN;
2506
2507 if (!nmap)
2508 XSRETURN_UNDEF; 2518 XSRETURN_UNDEF;
2509 2519
2510 RETVAL = &nmap->at (nx, ny); 2520 RETVAL = &*pos;
2511} 2521}
2512 OUTPUT: 2522 OUTPUT:
2513 RETVAL 2523 RETVAL
2514 2524
2515void 2525void
2516at (maptile *map, unsigned int x, unsigned int y) 2526at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2517 PROTOTYPE: $$$ 2527 PROTOTYPE: $$$;$
2518 PPCODE: 2528 PPCODE:
2519{ 2529 mapxy pos (map, x, y);
2520 maptile *nmap = 0; 2530 if (pos.move (dir).normalise ())
2521 I16 nx, ny;
2522
2523 PUTBACK;
2524 get_map_flags (map, &nmap, x, y, &nx, &ny);
2525 SPAGAIN;
2526
2527 if (nmap)
2528 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2531 for (object *o = pos->bot; o; o = o->above)
2529 XPUSHs (sv_2mortal (to_sv (o))); 2532 XPUSHs (sv_2mortal (to_sv (o)));
2530}
2531 2533
2532SV * 2534SV *
2533bot_at (maptile *map, unsigned int x, unsigned int y) 2535bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2534 PROTOTYPE: $$$ 2536 PROTOTYPE: $$$;$
2535 ALIAS: 2537 ALIAS:
2536 top_at = 1 2538 top_at = 1
2537 flags_at = 2 2539 flags_at = 2
2538 light_at = 3 2540 light_at = 3
2539 move_block_at = 4 2541 move_block_at = 4
2540 move_slow_at = 5 2542 move_slow_at = 5
2541 move_on_at = 6 2543 move_on_at = 6
2542 move_off_at = 7 2544 move_off_at = 7
2543 CODE: 2545 CODE:
2544{ 2546{
2545 sint16 nx = x; 2547 mapxy pos (map, x, y);
2546 sint16 ny = y; 2548 if (!pos.move (dir).normalise ())
2547
2548 if (!xy_normalise (map, nx, ny))
2549 XSRETURN_UNDEF; 2549 XSRETURN_UNDEF;
2550 2550
2551 mapspace &ms = map->at (nx, ny); 2551 mapspace &ms = *pos;
2552 2552
2553 ms.update (); 2553 ms.update ();
2554 2554
2555 switch (ix) 2555 switch (ix)
2556 { 2556 {
2566} 2566}
2567 OUTPUT: RETVAL 2567 OUTPUT: RETVAL
2568 2568
2569# worst xs function of my life 2569# worst xs function of my life
2570bool 2570bool
2571_create_random_map (\ 2571_create_random_map (maptile *self, SV *options)
2572 maptile *self,\
2573 utf8_string wallstyle,\
2574 utf8_string wall_name,\
2575 utf8_string floorstyle,\
2576 utf8_string monsterstyle,\
2577 utf8_string treasurestyle,\
2578 utf8_string layoutstyle,\
2579 utf8_string doorstyle,\
2580 utf8_string decorstyle,\
2581 utf8_string miningstyle,\
2582 utf8_string origin_map,\
2583 utf8_string final_map,\
2584 utf8_string exitstyle,\
2585 utf8_string this_map,\
2586 utf8_string exit_on_final_map,\
2587 int xsize,\
2588 int ysize,\
2589 int expand2x,\
2590 int layoutoptions1,\
2591 int layoutoptions2,\
2592 int layoutoptions3,\
2593 int symmetry,\
2594 int difficulty,\
2595 int difficulty_given,\
2596 float difficulty_increase,\
2597 int dungeon_level,\
2598 int dungeon_depth,\
2599 int decoroptions,\
2600 int orientation,\
2601 int origin_y,\
2602 int origin_x,\
2603 U32 random_seed,\
2604 val64 total_map_hp,\
2605 int map_layout_style,\
2606 int treasureoptions,\
2607 int symmetry_used,\
2608 region *region,\
2609 utf8_string custom\
2610)
2611 CODE: 2572 CODE:
2612{ 2573{
2613 random_map_params rmp; 2574 random_map_params rmp ((HV *)SvRV (options));
2614
2615 assign (rmp.wallstyle , wallstyle);
2616 assign (rmp.wall_name , wall_name);
2617 assign (rmp.floorstyle , floorstyle);
2618 assign (rmp.monsterstyle , monsterstyle);
2619 assign (rmp.treasurestyle , treasurestyle);
2620 assign (rmp.layoutstyle , layoutstyle);
2621 assign (rmp.doorstyle , doorstyle);
2622 assign (rmp.decorstyle , decorstyle);
2623 assign (rmp.miningstyle , miningstyle);
2624 assign (rmp.exitstyle , exitstyle);
2625 assign (rmp.exit_on_final_map, exit_on_final_map);
2626
2627 rmp.origin_map = origin_map;
2628 rmp.final_map = final_map;
2629 rmp.this_map = this_map;
2630 rmp.xsize = xsize;
2631 rmp.ysize = ysize;
2632 rmp.expand2x = expand2x;
2633 rmp.layoutoptions1 = layoutoptions1;
2634 rmp.layoutoptions2 = layoutoptions2;
2635 rmp.layoutoptions3 = layoutoptions3;
2636 rmp.symmetry = symmetry;
2637 rmp.difficulty = difficulty;
2638 rmp.difficulty_given = difficulty_given;
2639 rmp.difficulty_increase = difficulty_increase;
2640 rmp.dungeon_level = dungeon_level;
2641 rmp.dungeon_depth = dungeon_depth;
2642 rmp.decoroptions = decoroptions;
2643 rmp.orientation = orientation;
2644 rmp.origin_y = origin_y;
2645 rmp.origin_x = origin_x;
2646 rmp.random_seed = random_seed;
2647 rmp.total_map_hp = (uint64_t) total_map_hp;
2648 rmp.map_layout_style = map_layout_style;
2649 rmp.treasureoptions = treasureoptions;
2650 rmp.symmetry_used = symmetry_used;
2651 rmp.region = region;
2652 rmp.custom = custom;
2653
2654 RETVAL = self->generate_random_map (&rmp); 2575 RETVAL = self->generate_random_map (&rmp);
2655} 2576}
2656 OUTPUT: 2577 OUTPUT:
2657 RETVAL 2578 RETVAL
2658 2579
2689void 2610void
2690list () 2611list ()
2691 PPCODE: 2612 PPCODE:
2692 for_all_regions (rgn) 2613 for_all_regions (rgn)
2693 XPUSHs (sv_2mortal (to_sv (rgn))); 2614 XPUSHs (sv_2mortal (to_sv (rgn)));
2694
2695region *find (utf8_string name)
2696 PROTOTYPE: $
2697 CODE:
2698 RETVAL = region::find (name);
2699 OUTPUT: RETVAL
2700 2615
2701int specificity (region *rgn) 2616int specificity (region *rgn)
2702 CODE: 2617 CODE:
2703 RETVAL = 0; 2618 RETVAL = 0;
2704 while (rgn = rgn->parent) 2619 while (rgn = rgn->parent)
2836 2751
2837void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2752void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2838 CODE: 2753 CODE:
2839{ 2754{
2840 faceinfo *f = face_info (idx); assert (f); 2755 faceinfo *f = face_info (idx); assert (f);
2841 facedata *d = &(faceset ? f->data64 : f->data32); 2756 facedata *d = f->face + faceset;
2842 sv_to (data, d->data); 2757 sv_to (data, d->data);
2843 STRLEN clen; 2758 STRLEN clen;
2844 char *cdata = SvPVbyte (chksum, clen); 2759 char *cdata = SvPVbyte (chksum, clen);
2845 clen = min (CHKSUM_MAXLEN, clen); 2760 clen = min (CHKSUM_MAXLEN, clen);
2846 2761
2954 sv_to (sv, self); 2869 sv_to (sv, self);
2955 delete self; 2870 delete self;
2956 2871
2957MODULE = cf PACKAGE = cf::object::thawer 2872MODULE = cf PACKAGE = cf::object::thawer
2958 2873
2959INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2874INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2875
2876bool
2877errors_are_fatal (bool fatal)
2878 CODE:
2879 RETVAL = object_thawer::errors_are_fatal;
2880 object_thawer::errors_are_fatal = fatal;
2881 OUTPUT:
2882 RETVAL
2960 2883
2961SV * 2884SV *
2962new_from_file (char *klass, octet_string path) 2885new_from_file (char *klass, octet_string path)
2963 CODE: 2886 CODE:
2964 object_thawer *f = new object_thawer (path); 2887 object_thawer *f = new object_thawer (path);
2990 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2913 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2991 2914
2992 self->skip (); 2915 self->skip ();
2993 } 2916 }
2994 2917
2918MODULE = cf PACKAGE = cf::layout
2919
2920INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2921

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines