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.286 by root, Sun May 4 14:12:38 2008 UTC vs.
Revision 1.303 by root, Tue Sep 23 04:29:11 2008 UTC

21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include "autoconf.h" 24#include "autoconf.h"
25 25
26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5"
28
29#if HAVE_EXECINFO_H 26#if HAVE_EXECINFO_H
30# include <execinfo.h> 27# include <execinfo.h>
31#endif 28#endif
32 29
33#include <cstdarg> 30#include <cstdarg>
31#include <typeinfo>
34 32
35#include "global.h" 33#include "global.h"
36#include "loader.h" 34#include "loader.h"
37#include "../random_maps/random_map.h" 35#include "../random_maps/random_map.h"
38#include "evthread.h" 36#include "evthread.h"
83 *stash_cf, 81 *stash_cf,
84 *stash_cf_object_wrap, 82 *stash_cf_object_wrap,
85 *stash_cf_object_player_wrap, 83 *stash_cf_object_player_wrap,
86 *stash_cf_player_wrap, 84 *stash_cf_player_wrap,
87 *stash_cf_map_wrap, 85 *stash_cf_map_wrap,
86 *stash_cf_mapspace_wrap,
88 *stash_cf_client_wrap, 87 *stash_cf_client_wrap,
89 *stash_cf_arch_wrap, 88 *stash_cf_arch_wrap,
90 *stash_cf_party_wrap, 89 *stash_cf_party_wrap,
91 *stash_cf_region_wrap, 90 *stash_cf_region_wrap,
92 *stash_cf_living_wrap; 91 *stash_cf_living_wrap;
431inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 430inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
432inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 431inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
433inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 432inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
434inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 433inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
435inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 434inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
435inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
436 436
437inline SV *to_sv (object & v) { return to_sv (&v); } 437inline SV *to_sv (object & v) { return to_sv (&v); }
438inline SV *to_sv (living & v) { return to_sv (&v); } 438inline SV *to_sv (living & v) { return to_sv (&v); }
439 439
440inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 440inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
441inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } 441inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); }
442 442
443inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); } 443inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); }
444
445inline SV *to_sv (dynbuf * v)
446{
447 SV *sv = newSV (0);
448
449 sv_upgrade (sv, SVt_PV);
450 SvGROW (sv, v->size () + 1);
451 SvPOK_only (sv);
452 v->linearise (SvPVX (sv));
453 SvCUR_set (sv, v->size ());
454 *SvEND (sv) = 0;
455
456 return sv;
457}
458
459inline SV *to_sv (dynbuf_text * v)
460{
461 SV *sv = to_sv (static_cast<dynbuf *> (v));
462 SvUTF8_on (sv);
463 return sv;
464}
444 465
445inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } 466inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; }
446inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 467inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
447inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 468inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
448inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 469inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
464inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 485inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
465inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } 486inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); }
466inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 487inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
467inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 488inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
468inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 489inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
490inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); }
469inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } 491inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); }
470inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } 492inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); }
471 493
472//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 494//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
473inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 495inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
605 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 627 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
606 628
607 const char *argv[] = { 629 const char *argv[] = {
608 settings.argv [0], 630 settings.argv [0],
609 "-e" 631 "-e"
610 "use EV; use Coro;" // required for bootstrap 632 "use EV ();"
611 "cf->bootstrap;" // required for datadir :*> 633 "use Coro ();"
634 "cf->bootstrap;"
612 "unshift @INC, cf::datadir ();" 635 "unshift @INC, cf::datadir ();"
613 "require cf;" 636 "require cf;"
614 }; 637 };
615 638
616 if (perl_parse (perl, xs_init, 2, (char **)argv, environ) 639 if (perl_parse (perl, xs_init, 2, (char **)argv, environ)
617 || perl_run (perl)) 640 || perl_run (perl))
618 { 641 {
619 printf ("unable to initialize perl-interpreter, aborting.\n"); 642 printf ("unable to initialize perl-interpreter, aborting.\n");
620 exit (EXIT_FAILURE); 643 exit (EXIT_FAILURE);
621 } 644 }
622
623 {
624 dSP;
625
626 PUSHMARK (SP);
627 PUTBACK;
628 call_pv ("cf::init", G_DISCARD | G_VOID);
629 }
630} 645}
631 646
632void cfperl_main () 647void cfperl_main ()
633{ 648{
634 dSP; 649 dSP;
1066 CALL_ARG (exit); 1081 CALL_ARG (exit);
1067 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1082 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
1068 CALL_END; 1083 CALL_END;
1069} 1084}
1070 1085
1086void
1087object::player_goto (const char *path, int x, int y)
1088{
1089 if (type != PLAYER)
1090 return;
1091
1092 CALL_BEGIN (4);
1093 CALL_ARG (this);
1094 CALL_ARG (path);
1095 CALL_ARG (x);
1096 CALL_ARG (y);
1097 CALL_CALL ("cf::object::player::goto", G_VOID);
1098 CALL_END;
1099}
1100
1071const char * 1101const char *
1072object::ref () const 1102object::ref () const
1073{ 1103{
1074 if (type == PLAYER) 1104 if (type == PLAYER)
1075 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1105 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1159 1189
1160 stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); 1190 stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1);
1161 stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); 1191 stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1);
1162 stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); 1192 stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1);
1163 stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); 1193 stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1);
1194 stash_cf_mapspace_wrap = gv_stashpv ("cf::mapspace::wrap" , 1);
1164 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1195 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1165 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1196 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1166 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1197 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1167 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1198 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1168 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1199 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1288 const_iv (FLAG_CURSED) const_iv (FLAG_DAMNED) const_iv (FLAG_SEE_ANYWHERE) const_iv (FLAG_KNOWN_MAGICAL) 1319 const_iv (FLAG_CURSED) const_iv (FLAG_DAMNED) const_iv (FLAG_SEE_ANYWHERE) const_iv (FLAG_KNOWN_MAGICAL)
1289 const_iv (FLAG_KNOWN_CURSED) const_iv (FLAG_CAN_USE_SKILL) const_iv (FLAG_BEEN_APPLIED) const_iv (FLAG_READY_SCROLL) 1320 const_iv (FLAG_KNOWN_CURSED) const_iv (FLAG_CAN_USE_SKILL) const_iv (FLAG_BEEN_APPLIED) const_iv (FLAG_READY_SCROLL)
1290 const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) 1321 const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED)
1291 const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON) 1322 const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON)
1292 const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON) 1323 const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON)
1293 const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_CLIENT_SENT) const_iv (FLAG_BERSERK) 1324 const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_DEBUG) const_iv (FLAG_BERSERK)
1294 const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL) 1325 const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL)
1295 const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER) 1326 const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER)
1296 const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) 1327 const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE)
1297 const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) 1328 const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE)
1298 1329
1299 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) 1330 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED)
1300 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) 1331 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN)
1301 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) 1332 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD)
1302 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) 1333 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE)
1303 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK) 1334 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK)
1304 const_iv (NDI_NOCREATE) const_iv (NDI_CLEAR) 1335 const_iv (NDI_NOCREATE) const_iv (NDI_CLEAR) const_iv (NDI_VERBATIM)
1305 1336
1306 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1337 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1307 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1338 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1308 1339
1309 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1340 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1361 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1392 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1362 const_iv (F_LOCKED) 1393 const_iv (F_LOCKED)
1363 1394
1364 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1395 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1365 1396
1366 const_iv (P_BLOCKSVIEW) const_iv (P_PLAYER) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE) 1397 const_iv (P_BLOCKSVIEW) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE)
1367 const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) 1398 const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE)
1368 1399
1369 const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) 1400 const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE)
1370 1401
1371 const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) 1402 const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON)
1469 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1500 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1470 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); 1501 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv));
1471 } 1502 }
1472} 1503}
1473 1504
1505void _gv_clear (SV *gv)
1506 CODE:
1507 assert (SvTYPE (gv) == SVt_PVGV);
1508# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1509 f (GvGP (gv)->gp_form);
1510 f (GvGP (gv)->gp_io);
1511 f (GvGP (gv)->gp_sv);
1512 f (GvGP (gv)->gp_av);
1513 f (GvGP (gv)->gp_hv);
1514 f (GvGP (gv)->gp_cv);
1515 GvCVGEN (gv) = 0;
1516 GvMULTI_off (gv);
1517# undef f
1518
1474void _connect_to_perl () 1519void _connect_to_perl ()
1475 1520
1476void _recalc_want () 1521void _recalc_want ()
1477 1522
1478void _global_reattach () 1523void _global_reattach ()
1525 len -= 3; 1570 len -= 3;
1526 } 1571 }
1527 1572
1528 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1573 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1529} 1574}
1575
1576void init_anim ()
1577
1578void init_globals ()
1579
1580void init_experience ()
1581
1582void init_attackmess ()
1583
1584void init_dynamic ()
1585
1586void init_block ()
1587
1588void load_settings ()
1589
1590void load_materials ()
1591
1592void init_uuid ()
1593 CODE:
1594 UUID::init ();
1595
1596void init_signals ()
1597
1598void init_commands ()
1599
1600void init_skills ()
1601
1602void init_beforeplay ()
1530 1603
1531void evthread_start (int aiofd) 1604void evthread_start (int aiofd)
1532 1605
1533void cede_to_tick () 1606void cede_to_tick ()
1534 CODE: 1607 CODE:
1672#if _POSIX_MEMLOCK 1745#if _POSIX_MEMLOCK
1673 1746
1674int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1747int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1675 INIT: 1748 INIT:
1676#if __GLIBC__ 1749#if __GLIBC__
1750 mallopt (M_TOP_PAD, 1024 * 1024);
1751 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128);
1752 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1677 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1753 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1678#endif 1754#endif
1679 1755
1680int munlockall () 1756int munlockall ()
1681 1757
1797 PUSHs (sv_2mortal (to_sv (archetype::find (coins [i])))); 1873 PUSHs (sv_2mortal (to_sv (archetype::find (coins [i]))));
1798 1874
1799bool 1875bool
1800load_resource_file_ (octet_string filename) 1876load_resource_file_ (octet_string filename)
1801 1877
1878void
1879fix_weight ()
1880
1802MODULE = cf PACKAGE = cf::attachable 1881MODULE = cf PACKAGE = cf::attachable
1803 1882
1804int 1883int
1805valid (SV *obj) 1884valid (SV *obj)
1806 CODE: 1885 CODE:
2067void rangevector (object *ob, object *other, int flags = 0) 2146void rangevector (object *ob, object *other, int flags = 0)
2068 PROTOTYPE: $$;$ 2147 PROTOTYPE: $$;$
2069 PPCODE: 2148 PPCODE:
2070{ 2149{
2071 rv_vector rv; 2150 rv_vector rv;
2151
2152 PUTBACK;
2072 get_rangevector (ob, other, &rv, flags); 2153 get_rangevector (ob, other, &rv, flags);
2154 SPAGAIN;
2155
2073 EXTEND (SP, 5); 2156 EXTEND (SP, 5);
2074 PUSHs (newSVuv (rv.distance)); 2157 PUSHs (newSVuv (rv.distance));
2075 PUSHs (newSViv (rv.distance_x)); 2158 PUSHs (newSViv (rv.distance_x));
2076 PUSHs (newSViv (rv.distance_y)); 2159 PUSHs (newSViv (rv.distance_y));
2077 PUSHs (newSViv (rv.direction)); 2160 PUSHs (newSViv (rv.direction));
2168 if (len > MAXSOCKBUF) 2251 if (len > MAXSOCKBUF)
2169 pl->failmsg ("[packet too long for client]"); 2252 pl->failmsg ("[packet too long for client]");
2170 else if (pl->ns) 2253 else if (pl->ns)
2171 pl->ns->send_packet (buf, len); 2254 pl->ns->send_packet (buf, len);
2172} 2255}
2173
2174int
2175listening (player *pl, int new_value = -1)
2176 CODE:
2177 RETVAL = pl->listening;
2178 if (new_value >= 0)
2179 pl->listening = new_value;
2180 OUTPUT:
2181 RETVAL
2182 2256
2183void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) 2257void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0)
2184 PROTOTYPE: $;$$$ 2258 PROTOTYPE: $;$$$
2185 PPCODE: 2259 PPCODE:
2186 if (GIMME_V != G_VOID) 2260 if (GIMME_V != G_VOID)
2341} 2415}
2342 2416
2343void 2417void
2344maptile::create_region_treasure () 2418maptile::create_region_treasure ()
2345 CODE: 2419 CODE:
2346{
2347 object *op = object::create ();
2348 op->type = FLOOR;
2349 op->map = THIS;
2350
2351 for (int x = 0; x < THIS->width; ++x) 2420 for (int x = 0; x < THIS->width; ++x)
2352 for (int y = 0; y < THIS->height; ++y) 2421 for (int y = 0; y < THIS->height; ++y)
2353 { 2422 {
2354 region *rgn = THIS->region (x, y); 2423 region *rgn = THIS->region (x, y);
2355 2424
2356 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D 2425 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2426 if (object *op = THIS->at (x, y).top)
2357 if (rgn->treasure && rndm () < rgn->treasure_density) 2427 if (rgn->treasure && rndm () < rgn->treasure_density)
2358 {
2359 op->x = x;
2360 op->y = y;
2361 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2428 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2362 }
2363 } 2429 }
2364
2365 op->destroy ();
2366}
2367 2430
2368int out_of_map (maptile *map, int x, int y) 2431int out_of_map (maptile *map, int x, int y)
2369 2432
2370void 2433void
2371trigger (maptile *map, long connection, bool state = true) 2434trigger (maptile *map, long connection, bool state = true)
2384get_map_flags (maptile *map, int x, int y) 2447get_map_flags (maptile *map, int x, int y)
2385 PPCODE: 2448 PPCODE:
2386{ 2449{
2387 maptile *nmap = 0; 2450 maptile *nmap = 0;
2388 I16 nx = 0, ny = 0; 2451 I16 nx = 0, ny = 0;
2452
2453 PUTBACK;
2389 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2454 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2455 SPAGAIN;
2390 2456
2391 EXTEND (SP, 4); 2457 EXTEND (SP, 4);
2392 PUSHs (sv_2mortal (newSViv (flags))); 2458 PUSHs (sv_2mortal (newSViv (flags)));
2393 2459
2394 if (GIMME_V == G_ARRAY) 2460 if (GIMME_V == G_ARRAY)
2397 PUSHs (sv_2mortal (newSViv (nx))); 2463 PUSHs (sv_2mortal (newSViv (nx)));
2398 PUSHs (sv_2mortal (newSViv (ny))); 2464 PUSHs (sv_2mortal (newSViv (ny)));
2399 } 2465 }
2400} 2466}
2401 2467
2468mapspace *
2469ms (maptile *map, unsigned int x, unsigned int y)
2470 PROTOTYPE: $$$
2471 CODE:
2472{
2473 maptile *nmap = 0;
2474 I16 nx, ny;
2475
2476 PUTBACK;
2477 get_map_flags (map, &nmap, x, y, &nx, &ny);
2478 SPAGAIN;
2479
2480 if (!nmap)
2481 XSRETURN_UNDEF;
2482
2483 RETVAL = &nmap->at (nx, ny);
2484}
2485 OUTPUT:
2486 RETVAL
2487
2402void 2488void
2403at (maptile *map, unsigned int x, unsigned int y) 2489at (maptile *map, unsigned int x, unsigned int y)
2404 PROTOTYPE: $$$ 2490 PROTOTYPE: $$$
2405 PPCODE: 2491 PPCODE:
2406{ 2492{
2407 object *o;
2408 maptile *nmap = 0; 2493 maptile *nmap = 0;
2409 I16 nx, ny; 2494 I16 nx, ny;
2410 2495
2496 PUTBACK;
2411 get_map_flags (map, &nmap, x, y, &nx, &ny); 2497 get_map_flags (map, &nmap, x, y, &nx, &ny);
2498 SPAGAIN;
2412 2499
2413 if (nmap) 2500 if (nmap)
2414 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2501 for (object *o = nmap->at (nx, ny).bot; o; o = o->above)
2415 XPUSHs (sv_2mortal (to_sv (o))); 2502 XPUSHs (sv_2mortal (to_sv (o)));
2416} 2503}
2417 2504
2418SV * 2505SV *
2419bot_at (maptile *obj, unsigned int x, unsigned int y) 2506bot_at (maptile *obj, unsigned int x, unsigned int y)
2532 RETVAL = self->generate_random_map (&rmp); 2619 RETVAL = self->generate_random_map (&rmp);
2533} 2620}
2534 OUTPUT: 2621 OUTPUT:
2535 RETVAL 2622 RETVAL
2536 2623
2624MODULE = cf PACKAGE = cf::mapspace
2625
2626INCLUDE: $PERL $srcdir/genacc mapspace ../include/map.h |
2627
2537MODULE = cf PACKAGE = cf::arch 2628MODULE = cf PACKAGE = cf::arch
2538 2629
2539int archetypes_size () 2630int archetypes_size ()
2540 CODE: 2631 CODE:
2541 RETVAL = archetypes.size (); 2632 RETVAL = archetypes.size ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines