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.388 by root, Wed Jun 30 01:57:54 2010 UTC vs.
Revision 1.427 by root, Tue Nov 20 14:50:17 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.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "autoconf.h" 23#include "autoconf.h"
24 24
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,
94 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
97 *cv_cf_ix,
95 *cv_cf_tick, 98 *cv_cf_tick,
96 *cv_cf_match_match; 99 *cv_cf_match_match;
97 100
98#ifndef newSVpv_utf8 101#ifndef newSVpv_utf8
99static SV * 102static SV *
251 { 254 {
252 static int last_mortalcount; 255 static int last_mortalcount;
253 if (mortals.size () != last_mortalcount) 256 if (mortals.size () != last_mortalcount)
254 { 257 {
255 last_mortalcount = mortals.size (); 258 last_mortalcount = mortals.size ();
256 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 259 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
260
261 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
262 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
257 263
258 if (0) 264 if (0)
259 { 265 {
260 for (int j = 0; j < mortals.size (); ++j)//D 266 for (int j = 0; j < mortals.size (); ++j)//D
261 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 267 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
539static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 545static 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); } 546static 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); } 547static 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); } 548static 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); } 549static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
550static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
544 551
545static inline SV *to_sv (object & v) { return to_sv (&v); } 552static inline SV *to_sv (object & v) { return to_sv (&v); }
546static inline SV *to_sv (living & v) { return to_sv (&v); } 553static inline SV *to_sv (living & v) { return to_sv (&v); }
547 554
548static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 555static 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"); } 601static 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"); } 602static 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"); } 603static 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"); } 604static 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"); } 605static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
606static 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"); } 607static 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" ); } 608static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
601 609
602//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 610//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)); } 611static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
616static inline void sv_to (SV *sv, std::string &v) 624static inline void sv_to (SV *sv, std::string &v)
617{ 625{
618 STRLEN len; 626 STRLEN len;
619 char *data = SvPVbyte (sv, len); 627 char *data = SvPVbyte (sv, len);
620 v.assign (data, len); 628 v.assign (data, len);
629}
630
631static inline void sv_to (SV *sv, refcnt_buf &v)
632{
633 STRLEN len;
634 char *data = SvPVbyte (sv, len);
635 refcnt_buf buf (data, len);
636 v = buf;
621} 637}
622 638
623static inline void sv_to (SV *sv, UUID &v) 639static inline void sv_to (SV *sv, UUID &v)
624{ 640{
625 if (!v.parse (SvPV_nolen (sv))) 641 if (!v.parse (SvPV_nolen (sv)))
1142 CALL_ARG (originator); 1158 CALL_ARG (originator);
1143 CALL_CALL ("cf::mapscript::activate", G_VOID); 1159 CALL_CALL ("cf::mapscript::activate", G_VOID);
1144 CALL_END; 1160 CALL_END;
1145} 1161}
1146 1162
1163void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1164{
1165 CALL_BEGIN (3);
1166 CALL_ARG (ns);
1167 CALL_ARG (set);
1168 CALL_ARG (idx);
1169 CALL_ARG (pri);
1170 CALL_CALL (cv_cf_ix, G_VOID);
1171 CALL_END;
1172}
1173
1147player * 1174player *
1148player::find (const_utf8_string name) 1175player::find (const_utf8_string name)
1149{ 1176{
1150 CALL_BEGIN (1); 1177 CALL_BEGIN (1);
1151 CALL_ARG (name); 1178 CALL_ARG (name);
1245 CALL_ARG (y); 1272 CALL_ARG (y);
1246 CALL_CALL ("cf::object::player::goto", G_VOID); 1273 CALL_CALL ("cf::object::player::goto", G_VOID);
1247 CALL_END; 1274 CALL_END;
1248} 1275}
1249 1276
1250const_utf8_string 1277const_utf8_string
1251object::ref () const 1278object::ref () const
1252{ 1279{
1253 if (type == PLAYER) 1280 if (type == PLAYER)
1254 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1281 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1255 else 1282 else
1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1424 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1425 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1426 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1427 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1401 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1428 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1429 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1402 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1430 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1403 1431
1404 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1432 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); 1433 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1434 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); 1435 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); 1436 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1408 1437
1409 cb_global = get_av ("cf::CB_GLOBAL", 1); 1438 cb_global = get_av ("cf::CB_GLOBAL", 1);
1410 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1439 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1411 cb_object = get_av ("cf::CB_OBJECT", 1); 1440 cb_object = get_av ("cf::CB_OBJECT", 1);
1412 cb_player = get_av ("cf::CB_PLAYER", 1); 1441 cb_player = get_av ("cf::CB_PLAYER", 1);
1419_connect_to_perl_2 () 1448_connect_to_perl_2 ()
1420{ 1449{
1421 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1450 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1422 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1451 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1423 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1452 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1453 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1424 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1454 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1425 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1455 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1426} 1456}
1427 1457
1428MODULE = cf PACKAGE = cf PREFIX = cf_ 1458MODULE = cf PACKAGE = cf PREFIX = cf_
1433 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1463 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1434 1464
1435 _connect_to_perl_1 (); 1465 _connect_to_perl_1 ();
1436 1466
1437 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1467 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1438
1439 //{
1440 // require_pv ("Time::HiRes");
1441 //
1442 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1443 // if (!svp) croak ("Time::HiRes is required");
1444 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1445 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1446 //}
1447 1468
1448 static const struct { 1469 static const struct {
1449 const char *name; 1470 const char *name;
1450 IV iv; 1471 IV iv;
1451 } *civ, const_iv[] = { 1472 } *civ, const_iv[] = {
1455# include "attackinc.h" 1476# include "attackinc.h"
1456# undef def 1477# undef def
1457# define def(uc, flags) const_iv (SK_ ## uc) 1478# define def(uc, flags) const_iv (SK_ ## uc)
1458# include "skillinc.h" 1479# include "skillinc.h"
1459# undef def 1480# undef def
1460 1481# define def(name, use, nonuse) const_iv (body_ ## name)
1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1482# include "slotinc.h"
1483# undef def
1462 1484
1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1485 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1464 1486
1465 const_iv (MAX_TIME) 1487 const_iv (MAX_TIME)
1466 const_iv (MAXSOCKBUF) 1488 const_iv (MAXSOCKBUF)
1479 1501
1480 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1502 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1481 1503
1482 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1504 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) 1505 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 1506
1488 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1507 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) 1508 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1490 1509
1491 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1510 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1524 1543
1525void _gv_clear (SV *gv) 1544void _gv_clear (SV *gv)
1526 CODE: 1545 CODE:
1527 assert (SvTYPE (gv) == SVt_PVGV); 1546 assert (SvTYPE (gv) == SVt_PVGV);
1528# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1547# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1548 SvREFCNT_inc (gv);
1529 f (GvGP (gv)->gp_form); 1549 f (GvGP (gv)->gp_form);
1530 f (GvGP (gv)->gp_io); 1550 f (GvGP (gv)->gp_io);
1531 f (GvGP (gv)->gp_sv); 1551 f (GvGP (gv)->gp_sv);
1532 f (GvGP (gv)->gp_av); 1552 f (GvGP (gv)->gp_av);
1533 f (GvGP (gv)->gp_hv); 1553 f (GvGP (gv)->gp_hv);
1534 f (GvGP (gv)->gp_cv); 1554 f (GvGP (gv)->gp_cv);
1535 GvCVGEN (gv) = 0; 1555 GvCVGEN (gv) = 0;
1536 GvMULTI_off (gv); 1556 GvMULTI_off (gv);
1557 SvREFCNT_dec (gv);
1537# undef f 1558# undef f
1538 1559
1539void _connect_to_perl_1 () 1560void _connect_to_perl_1 ()
1540 1561
1541void _connect_to_perl_2 () 1562void _connect_to_perl_2 ()
1552 1573
1553 for_all_objects (op) 1574 for_all_objects (op)
1554 op->reattach (); 1575 op->reattach ();
1555} 1576}
1556 1577
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 () 1578void init_anim ()
1600 1579
1601void init_globals () 1580void init_globals ()
1602 1581
1603void init_attackmess () 1582void init_attackmess ()
1604 1583
1605void init_dynamic () 1584void init_dynamic ()
1606 1585
1607void load_settings () 1586void load_settings ()
1608 1587
1609void reload_exp_table () 1588void _reload_exp_table ()
1610 1589
1611void reload_materials () 1590void _reload_materials ()
1612 1591
1613void init_uuid () 1592void init_uuid ()
1614 CODE: 1593 CODE:
1615 UUID::init (); 1594 UUID::init ();
1616 1595
1627 coroapi::cede_to_tick (); 1606 coroapi::cede_to_tick ();
1628 1607
1629NV till_tick () 1608NV till_tick ()
1630 CODE: 1609 CODE:
1631 RETVAL = SvNVX (sv_next_tick) - now (); 1610 RETVAL = SvNVX (sv_next_tick) - now ();
1632 OUTPUT: 1611 OUTPUT: RETVAL
1633 RETVAL
1634 1612
1635int tick_inhibit () 1613int tick_inhibit ()
1636 CODE: 1614 CODE:
1637 RETVAL = tick_inhibit; 1615 RETVAL = tick_inhibit;
1638 OUTPUT: 1616 OUTPUT: RETVAL
1639 RETVAL
1640 1617
1641void tick_inhibit_inc () 1618void tick_inhibit_inc ()
1642 CODE: 1619 CODE:
1643 ++tick_inhibit; 1620 ++tick_inhibit;
1644 1621
1649 { 1626 {
1650 ev_async_send (EV_DEFAULT, &tick_watcher); 1627 ev_async_send (EV_DEFAULT, &tick_watcher);
1651 coroapi::cede (); 1628 coroapi::cede ();
1652 } 1629 }
1653 1630
1654void server_tick () 1631void one_tick ()
1655 CODE: 1632 CODE:
1656{ 1633{
1657 ev_now_update (EV_DEFAULT); 1634 ev_now_update (EV_DEFAULT);
1658 NOW = ev_now (EV_DEFAULT); 1635 NOW = ev_now (EV_DEFAULT);
1659 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1636 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1660 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1637 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1661 runtime = SvNVX (sv_runtime); 1638 runtime = SvNVX (sv_runtime);
1662 1639
1640 one_tick ();
1641
1663 server_tick (); 1642 ++server_tick;
1643 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1664 1644
1665 ev_now_update (EV_DEFAULT); 1645 ev_now_update (EV_DEFAULT);
1666 NOW = ev_now (EV_DEFAULT); 1646 NOW = ev_now (EV_DEFAULT);
1667 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1647 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1648
1668 runtime += TICK; 1649 runtime += TICK;
1669 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1650 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1670} 1651}
1671 1652
1672NV floor (NV x) 1653NV floor (NV x)
1676NV rndm (...) 1657NV rndm (...)
1677 ALIAS: 1658 ALIAS:
1678 rmg_rndm = 1 1659 rmg_rndm = 1
1679 CODE: 1660 CODE:
1680{ 1661{
1681 rand_gen &gen = ix ? rmg_rndm : rndm; 1662 rand_gen &gen = ix ? rmg_rndm : rndm;
1682 switch (items) 1663 switch (items)
1683 { 1664 {
1684 case 0: RETVAL = gen (); break; 1665 case 0: RETVAL = gen (); break;
1685 case 1: RETVAL = gen (SvUV (ST (0))); break; 1666 case 1: RETVAL = gen (SvUV (ST (0))); break;
1686 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1667 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1687 default: croak ("cf::rndm requires zero, one or two parameters."); break; 1668 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1688 } 1669 }
1689} 1670}
1690 OUTPUT: 1671 OUTPUT: RETVAL
1691 RETVAL
1692 1672
1693NV clamp (NV value, NV min_value, NV max_value) 1673NV clamp (NV value, NV min_value, NV max_value)
1694 CODE: 1674 CODE:
1695 RETVAL = clamp (value, min_value, max_value); 1675 RETVAL = clamp (value, min_value, max_value);
1696 OUTPUT: 1676 OUTPUT: RETVAL
1697 RETVAL
1698 1677
1699NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) 1678NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1700 CODE: 1679 CODE:
1701 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1680 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1702 OUTPUT: 1681 OUTPUT: RETVAL
1703 RETVAL
1704 1682
1705const char *ordinal (int i) 1683const char *ordinal (int i)
1706 1684
1707void weaken (...) 1685void weaken (...)
1708 PROTOTYPE: @ 1686 PROTOTYPE: @
1771 1749
1772int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1750int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1773 INIT: 1751 INIT:
1774#if __GLIBC__ 1752#if __GLIBC__
1775 mallopt (M_TOP_PAD, 1024 * 1024); 1753 mallopt (M_TOP_PAD, 1024 * 1024);
1776 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1754 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1777 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1755 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1756 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1778 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1757 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1779#endif 1758#endif
1780 1759
1781int munlockall () 1760int munlockall ()
1782 1761
1783#endif 1762#endif
1809 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1788 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1810 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1789 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1811 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); 1790 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1812} 1791}
1813 1792
1814int find_animation (utf8_string text)
1815 PROTOTYPE: $
1816
1817int random_roll (int min, int max, object *op, int goodbad); 1793int random_roll (int min, int max, object *op, int goodbad);
1818 1794
1819const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1795const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1820 1796
1821int exp_to_level (val64 exp) 1797int exp_to_level (val64 exp)
1822 1798
1823val64 level_to_min_exp (int level) 1799val64 level_to_min_exp (int level)
1824 1800
1801const_utf8_string
1802spellpathnames (int idx)
1803 CODE:
1804 RETVAL = spellpathnames [idx];
1805 OUTPUT: RETVAL
1806
1825SV * 1807SV *
1826resistance_to_string (int atnr) 1808attacktype_name (int atnr)
1827 CODE: 1809 CODE:
1828 if (atnr >= 0 && atnr < NROFATTACKS) 1810 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1811 ? newSVpv (attacktype_name [atnr], 0)
1830 else 1812 : &PL_sv_undef;
1831 XSRETURN_UNDEF;
1832 OUTPUT: RETVAL 1813 OUTPUT: RETVAL
1814
1815SV *
1816attacktype_desc (int atnr)
1817 CODE:
1818 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1819 ? newSVpv (attacktype_desc [atnr], 0)
1820 : &PL_sv_undef;
1821 OUTPUT: RETVAL
1822
1823SV *
1824resist_plus (int atnr)
1825 CODE:
1826 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1827 ? newSVpv (resist_plus [atnr], 0)
1828 : &PL_sv_undef;
1829 OUTPUT: RETVAL
1830
1831SV *
1832change_resist_msg (int atnr)
1833 CODE:
1834 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1835 ? newSVpv (change_resist_msg [atnr], 0)
1836 : &PL_sv_undef;
1837 OUTPUT: RETVAL
1838
1839int
1840skill_flags (int idx)
1841 CODE:
1842 if (idx < 0 || idx >= array_length (skill_flags))
1843 croak ("skill_flags: index out of bounds");
1844 RETVAL = skill_flags [idx];
1845 OUTPUT: RETVAL
1833 1846
1834UUID 1847UUID
1835uuid_cur () 1848uuid_cur ()
1836 CODE: 1849 CODE:
1837 RETVAL = UUID::cur; 1850 RETVAL = UUID::cur;
1838 OUTPUT: 1851 OUTPUT: RETVAL
1839 RETVAL
1840 1852
1841UUID 1853UUID
1842uuid_gen () 1854uuid_gen ()
1843 CODE: 1855 CODE:
1844 RETVAL = UUID::gen (); 1856 RETVAL = UUID::gen ();
1845 OUTPUT: 1857 OUTPUT: RETVAL
1846 RETVAL
1847 1858
1848val64 1859val64
1849uuid_seq (UUID uuid) 1860uuid_seq (UUID uuid)
1850 CODE: 1861 CODE:
1851 RETVAL = uuid.seq; 1862 RETVAL = uuid.seq;
1852 OUTPUT: 1863 OUTPUT: RETVAL
1853 RETVAL
1854 1864
1855UUID 1865UUID
1856uuid_str (val64 seq) 1866uuid_str (val64 seq)
1857 CODE: 1867 CODE:
1858 RETVAL.seq = seq; 1868 RETVAL.seq = seq;
1859 OUTPUT: 1869 OUTPUT: RETVAL
1860 RETVAL
1861 1870
1862void 1871void
1863coin_names () 1872coin_names ()
1864 PPCODE: 1873 PPCODE:
1865 EXTEND (SP, NUM_COINS); 1874 EXTEND (SP, NUM_COINS);
1877load_resource_file_ (octet_string filename) 1886load_resource_file_ (octet_string filename)
1878 1887
1879void 1888void
1880fix_weight () 1889fix_weight ()
1881 1890
1891utf8_string
1892expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1893 PPCODE:
1894 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1895
1882MODULE = cf PACKAGE = cf::attachable 1896MODULE = cf PACKAGE = cf::attachable
1883 1897
1884int 1898int
1885valid (SV *obj) 1899valid (SV *obj)
1886 CODE: 1900 CODE:
1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1901 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1888 OUTPUT: 1902 OUTPUT: RETVAL
1889 RETVAL
1890 1903
1891bool should_invoke (attachable *obj, int event) 1904bool should_invoke (attachable *obj, int event)
1892 CODE: 1905 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event); 1906 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL 1907 OUTPUT: RETVAL
1959int mortals_size () 1972int mortals_size ()
1960 CODE: 1973 CODE:
1961 RETVAL = attachable::mortals.size (); 1974 RETVAL = attachable::mortals.size ();
1962 OUTPUT: RETVAL 1975 OUTPUT: RETVAL
1963 1976
1964const_utf8_string slot_use_name (U32 slot) 1977const_utf8_string slot_name (U32 slot)
1965 ALIAS: 1978 ALIAS:
1979 slot_name = 0
1980 slot_use_name = 1
1966 slot_nonuse_name = 1 1981 slot_nonuse_name = 2
1967 CODE: 1982 CODE:
1968{ 1983{
1969 if (slot >= NUM_BODY_LOCATIONS) 1984 if (slot >= NUM_BODY_LOCATIONS)
1970 croak ("body slot index out of range"); 1985 croak ("body slot index out of range");
1971 1986
1972 switch (ix) 1987 switch (ix)
1973 { 1988 {
1989 case 0: RETVAL = body_locations[slot].name ; break;
1974 case 0: RETVAL = body_locations[slot].use_name; break; 1990 case 1: RETVAL = body_locations[slot].use_name ; break;
1975 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1991 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1976 } 1992 }
1977} 1993}
1978 OUTPUT: 1994 OUTPUT: RETVAL
1979 RETVAL
1980 1995
1981# missing properties 1996# missing properties
1982 1997
1983object *head (object *op) 1998object *head (object *op)
1984 PROTOTYPE: $ 1999 PROTOTYPE: $
2020 if (ix) 2035 if (ix)
2021 op->slot[slot].used = value; 2036 op->slot[slot].used = value;
2022 else 2037 else
2023 op->slot[slot].info = value; 2038 op->slot[slot].info = value;
2024} 2039}
2025 OUTPUT: 2040 OUTPUT: RETVAL
2026 RETVAL
2027 2041
2028object *find_best_object_match (object *op, utf8_string match) 2042object *find_best_object_match (object *op, utf8_string match)
2029 2043
2030int apply_shop_mat (object *shop_mat, object *op); 2044int apply_shop_mat (object *shop_mat, object *op);
2031 2045
2032int move (object *op, int dir, object *originator = op) 2046int move (object *op, int dir, object *originator = op)
2033 CODE: 2047 CODE:
2034 RETVAL = op->move (dir, originator); 2048 RETVAL = op->move (dir, originator);
2035 OUTPUT: 2049 OUTPUT: RETVAL
2036 RETVAL
2037 2050
2038void apply_below (object *op) 2051void apply_below (object *op)
2039 CODE: 2052 CODE:
2040 player_apply_below (op); 2053 player_apply_below (op);
2041 2054
2105int convert_item (object *item, object *converter) 2118int convert_item (object *item, object *converter)
2106 2119
2107void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2120void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2108 2121
2109MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2122MODULE = cf PACKAGE = cf::object PREFIX = cf_
2110
2111# no clean way to get an object from an archetype - stupid idiotic
2112# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2113 2123
2114object *new (utf8_string archetype = 0) 2124object *new (utf8_string archetype = 0)
2115 PROTOTYPE: ;$ 2125 PROTOTYPE: ;$
2116 CODE: 2126 CODE:
2117 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2127 RETVAL = archetype
2128 ? archetype::get (archetype)
2129 : object::create ();
2118 OUTPUT: 2130 OUTPUT: RETVAL
2119 RETVAL
2120 2131
2121object *generate (utf8_string arch, object *creator) 2132object *generate (utf8_string arch, object *creator)
2122 CODE: 2133 CODE:
2123 object *obj = get_archetype (arch); 2134 object *obj = archetype::get (arch);
2124 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2135 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2125 RETVAL = obj; 2136 RETVAL = obj;
2126 OUTPUT: 2137 OUTPUT: RETVAL
2127 RETVAL
2128 2138
2129object *find_object (U32 tag) 2139object *find_object (U32 tag)
2130 2140
2131object *find_object_uuid (UUID i) 2141object *find_object_uuid (UUID i)
2132 2142
2138 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2148 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2139 2149
2140 if (RETVAL->destroyed ()) 2150 if (RETVAL->destroyed ())
2141 RETVAL = 0; 2151 RETVAL = 0;
2142} 2152}
2153 OUTPUT: RETVAL
2143 2154
2144shstr 2155shstr
2145object::kv_get (shstr key) 2156object::kv_get (shstr key)
2157 CODE:
2158 RETVAL = THIS->kv.get (key);
2159 OUTPUT: RETVAL
2146 2160
2147void 2161void
2148object::kv_del (shstr key) 2162object::kv_del (shstr key)
2163 CODE:
2164 THIS->kv.del (key);
2149 2165
2150void 2166void
2151object::kv_set (shstr key, shstr value) 2167object::kv_set (shstr key, shstr value)
2168 CODE:
2169 THIS->kv.set (key, value);
2152 2170
2153object *get_nearest_player (object *ob) 2171object *get_nearest_player (object *ob)
2154 ALIAS: nearest_player = 0 2172 ALIAS: nearest_player = 0
2155 PREINIT: 2173 PREINIT:
2156 extern object *get_nearest_player (object *); 2174 extern object *get_nearest_player (object *);
2245#d# TODO: replace by blocked_los accessor, fix code using this 2263#d# TODO: replace by blocked_los accessor, fix code using this
2246bool 2264bool
2247cell_visible (player *pl, int dx, int dy) 2265cell_visible (player *pl, int dx, int dy)
2248 CODE: 2266 CODE:
2249 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; 2267 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED;
2250 OUTPUT: 2268 OUTPUT: RETVAL
2251 RETVAL
2252 2269
2253void 2270void
2254send (player *pl, SV *packet) 2271send (player *pl, SV *packet)
2255 CODE: 2272 CODE:
2256{ 2273{
2332outdoor_darkness (int darkness = 0) 2349outdoor_darkness (int darkness = 0)
2333 CODE: 2350 CODE:
2334 RETVAL = maptile::outdoor_darkness; 2351 RETVAL = maptile::outdoor_darkness;
2335 if (items) 2352 if (items)
2336 maptile::outdoor_darkness = darkness; 2353 maptile::outdoor_darkness = darkness;
2337 OUTPUT: 2354 OUTPUT: RETVAL
2338 RETVAL
2339 2355
2340void 2356void
2341maptile::instantiate () 2357maptile::instantiate ()
2342 2358
2343maptile *new () 2359maptile *new ()
2344 PROTOTYPE: 2360 PROTOTYPE:
2345 CODE: 2361 CODE:
2346 RETVAL = new maptile; 2362 RETVAL = new maptile;
2347 OUTPUT: 2363 OUTPUT: RETVAL
2348 RETVAL
2349 2364
2350void 2365void
2351maptile::players () 2366maptile::players ()
2352 PPCODE: 2367 PPCODE:
2353 if (GIMME_V == G_SCALAR) 2368 if (GIMME_V == G_SCALAR)
2359 if (pl->ob && pl->ob->map == THIS) 2374 if (pl->ob && pl->ob->map == THIS)
2360 PUSHs (sv_2mortal (to_sv (pl->ob))); 2375 PUSHs (sv_2mortal (to_sv (pl->ob)));
2361 } 2376 }
2362 2377
2363void 2378void
2379maptile::gen_quadmap (int x, int y, int z)
2380 CODE:
2381 gen_quadmap (THIS, x * 50, y * 50, z);
2382
2383void
2364maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2384maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2365 CODE: 2385 CODE:
2366{ 2386{
2367 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2387 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2368 croak ("maptile::add_underlay: palette must be arrayref"); 2388 croak ("maptile::add_underlay: palette must be arrayref");
2369 2389
2370 palette = SvRV (palette); 2390 palette = SvRV (palette);
2371 2391
2372 STRLEN idxlen; 2392 STRLEN idxlen;
2373 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2393 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2374 2394
2375 for (int x = 0; x < THIS->width; ++x) 2395 for (int x = 0; x < THIS->width; ++x)
2376 for (int y = 0; y < THIS->height; ++y) 2396 for (int y = 0; y < THIS->height; ++y)
2377 { 2397 {
2378 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2398 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2384 2404
2385 if (IN_RANGE_EXC (offs, 0, idxlen)) 2405 if (IN_RANGE_EXC (offs, 0, idxlen))
2386 { 2406 {
2387 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2407 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2388 { 2408 {
2389 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2409 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2390 ob->flag [FLAG_NO_MAP_SAVE] = true; 2410 ob->flag [FLAG_NO_MAP_SAVE] = true;
2391 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2411 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2392 2412
2393 if (ob->randomitems && !ob->above) 2413 if (ob->randomitems && !ob->above)
2394 { 2414 {
2398 op->flag [FLAG_NO_MAP_SAVE] = true; 2418 op->flag [FLAG_NO_MAP_SAVE] = true;
2399 // TODO: if this is a pickable object, then the item 2419 // TODO: if this is a pickable object, then the item
2400 // will at a bit weird - saving inside the player 2420 // will at a bit weird - saving inside the player
2401 // will clear the flag, but when the player drops 2421 // will clear the flag, but when the player drops
2402 // it without logging out, it keeps the flag. 2422 // it without logging out, it keeps the flag.
2403 // nobody ahs reported this, but this can be rather 2423 // nobody has reported this, but this can be rather
2404 // annoying on persistent maps. 2424 // annoying on persistent maps.
2405 } 2425 }
2406 } 2426 }
2407 } 2427 }
2408 } 2428 }
2409
2410 skip: ; 2429 skip: ;
2411 } 2430 }
2412} 2431}
2413 2432
2414void 2433void
2419 croak ("maptile::set_regiondata: palette must be arrayref"); 2438 croak ("maptile::set_regiondata: palette must be arrayref");
2420 2439
2421 palette = SvRV (palette); 2440 palette = SvRV (palette);
2422 2441
2423 STRLEN idxlen; 2442 STRLEN idxlen;
2424 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2443 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2425 2444
2426 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2445 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2427 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2446 uint8 *regions = salloc<uint8_t> (THIS->size ());
2428 2447
2429 for (int i = av_len ((AV *)palette) + 1; i--; ) 2448 for (int i = av_len ((AV *)palette) + 1; i--; )
2430 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2449 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2431 2450
2432 for (int y = 0; y < THIS->height; ++y) 2451 for (int y = 0; y < THIS->height; ++y)
2445 for (int x = 0; x < THIS->width; ++x) 2464 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2465 for (int y = 0; y < THIS->height; ++y)
2447 { 2466 {
2448 region *rgn = THIS->region (x, y); 2467 region *rgn = THIS->region (x, y);
2449 2468
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) 2469 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2470 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2471 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2472 }
2455 2473
2485 if (!pos.move (dir).normalise ()) 2503 if (!pos.move (dir).normalise ())
2486 XSRETURN_UNDEF; 2504 XSRETURN_UNDEF;
2487 2505
2488 RETVAL = &*pos; 2506 RETVAL = &*pos;
2489} 2507}
2490 OUTPUT: 2508 OUTPUT: RETVAL
2491 RETVAL
2492 2509
2493void 2510void
2494at (maptile *map, unsigned int x, unsigned int y, int dir = 0) 2511at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2495 PROTOTYPE: $$$;$ 2512 PROTOTYPE: $$$;$
2496 PPCODE: 2513 PPCODE:
2534} 2551}
2535 OUTPUT: RETVAL 2552 OUTPUT: RETVAL
2536 2553
2537# worst xs function of my life 2554# worst xs function of my life
2538bool 2555bool
2539_create_random_map (\ 2556_create_random_map (maptile *self, SV *options)
2540 maptile *self,\
2541 SV *options,\
2542 val64 total_map_hp,\
2543 region *region\
2544)
2545 CODE: 2557 CODE:
2546{ 2558{
2547 random_map_params rmp; 2559 random_map_params rmp ((HV *)SvRV (options));
2548
2549 rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options));
2550
2551 assign (rmp.wall_name , rmp.get_str ("wall_name"));
2552 assign (rmp.monsterstyle , rmp.get_str ("monsterstyle"));
2553 assign (rmp.layoutstyle , rmp.get_str ("layoutstyle"));
2554 assign (rmp.doorstyle , rmp.get_str ("doorstyle"));
2555 assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map"));
2556
2557 rmp.origin_map = rmp.get_str ("origin_map");
2558 rmp.origin_x = rmp.get_iv ("origin_x");
2559 rmp.origin_y = rmp.get_iv ("origin_y");
2560 rmp.final_map = rmp.get_str ("final_map");
2561 rmp.this_map = rmp.get_str ("this_map");
2562 rmp.xsize = rmp.get_iv ("xsize");
2563 rmp.ysize = rmp.get_iv ("ysize");
2564 rmp.expand2x = rmp.get_iv ("expand2x");
2565 rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1");
2566 rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2");
2567 rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3");
2568 rmp.symmetry = rmp.get_iv ("symmetry");
2569 rmp.difficulty = rmp.get_iv ("difficulty");
2570 rmp.difficulty_given = rmp.get_iv ("difficulty_given");
2571 rmp.difficulty_increase = rmp.get_nv ("difficulty_increase");
2572 rmp.dungeon_level = rmp.get_iv ("dungeon_level");
2573 rmp.dungeon_depth = rmp.get_iv ("dungeon_depth");
2574 rmp.orientation = rmp.get_iv ("orientation");
2575 rmp.random_seed = rmp.get_uv ("random_seed");
2576 rmp.total_map_hp = (uint64_t)total_map_hp;
2577 rmp.map_layout_style = rmp.get_iv ("map_layout_style");
2578 rmp.symmetry_used = rmp.get_iv ("symmetry_used");
2579 rmp.region = region;
2580
2581 RETVAL = self->generate_random_map (&rmp); 2560 RETVAL = self->generate_random_map (&rmp);
2582} 2561}
2583 OUTPUT: 2562 OUTPUT: RETVAL
2584 RETVAL
2585 2563
2586MODULE = cf PACKAGE = cf::mapspace 2564MODULE = cf PACKAGE = cf::mapspace
2587 2565
2588INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | 2566INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h |
2589 2567
2596 2574
2597archetype *archetypes (U32 index) 2575archetype *archetypes (U32 index)
2598 CODE: 2576 CODE:
2599 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2577 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2600 OUTPUT: RETVAL 2578 OUTPUT: RETVAL
2579
2580int skillvec_size ()
2581 CODE:
2582 RETVAL = skillvec.size ();
2583 OUTPUT: RETVAL
2584
2585archetype *skillvec (U32 index)
2586 CODE:
2587 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2588 OUTPUT: RETVAL
2589
2590void
2591find_by_type (int type)
2592 PPCODE:
2593 for_all_archetypes (arch)
2594 if (arch->type == type)
2595 XPUSHs (sv_2mortal (to_sv (arch)));
2601 2596
2602INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2597INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2603 2598
2604MODULE = cf PACKAGE = cf::party 2599MODULE = cf PACKAGE = cf::party
2605 2600
2654list () 2649list ()
2655 PPCODE: 2650 PPCODE:
2656 EXTEND (SP, clients.size ()); 2651 EXTEND (SP, clients.size ());
2657 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2652 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2658 PUSHs (sv_2mortal (to_sv (*i))); 2653 PUSHs (sv_2mortal (to_sv (*i)));
2654
2655STRLEN
2656client::inbuf_append (SV *data)
2657 CODE:
2658{
2659 STRLEN len;
2660 char *ptr = SvPVbyte (data, len);
2661
2662 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2663 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2664 THIS->inbuf_len += len;
2665
2666 THIS->inbuf_handle ();
2667
2668 RETVAL = len;
2669}
2670 OUTPUT: RETVAL
2659 2671
2660void 2672void
2661client::send_packet (SV *packet) 2673client::send_packet (SV *packet)
2662 CODE: 2674 CODE:
2663{ 2675{
2681 if (RETVAL) 2693 if (RETVAL)
2682 { 2694 {
2683 THIS->send_face (RETVAL, pri); 2695 THIS->send_face (RETVAL, pri);
2684 THIS->flush_fx (); 2696 THIS->flush_fx ();
2685 } 2697 }
2686 OUTPUT: 2698 OUTPUT: RETVAL
2687 RETVAL
2688 2699
2689int 2700int
2690client::fx_want (int idx, int value = -1) 2701client::fx_want (int idx, int value = -1)
2691 CODE: 2702 CODE:
2692 if (0 < idx && idx < FT_NUM) 2703 if (0 < idx && idx < FT_NUM)
2695 if (items > 2) 2706 if (items > 2)
2696 THIS->fx_want [idx] = value; 2707 THIS->fx_want [idx] = value;
2697 } 2708 }
2698 else 2709 else
2699 RETVAL = 0; 2710 RETVAL = 0;
2700 OUTPUT: 2711 OUTPUT: RETVAL
2701 RETVAL
2702 2712
2703MODULE = cf PACKAGE = cf::sound PREFIX = sound_ 2713MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2704 2714
2705faceidx sound_find (utf8_string name) 2715faceidx sound_find (utf8_string name)
2706 2716
2719faceidx face_find (utf8_string name, faceidx defidx = 0) 2729faceidx face_find (utf8_string name, faceidx defidx = 0)
2720 2730
2721faceidx alloc (utf8_string name) 2731faceidx alloc (utf8_string name)
2722 CODE: 2732 CODE:
2723{ 2733{
2724 do 2734 RETVAL = face_alloc ();
2725 {
2726 RETVAL = faces.size ();
2727 faces.resize (RETVAL + 1);
2728 }
2729 while (!RETVAL); // crude way to leave index 0
2730 2735
2731 faces [RETVAL].name = name; 2736 faces [RETVAL].name = name;
2732 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2737 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2733 2738
2734 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2739 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2735 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2740 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2736 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2741 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2737} 2742}
2743 OUTPUT: RETVAL
2744
2745faceidx faces_size ()
2746 CODE:
2747 RETVAL = faces.size ();
2738 OUTPUT: RETVAL 2748 OUTPUT: RETVAL
2739 2749
2740void set_type (faceidx idx, int value) 2750void set_type (faceidx idx, int value)
2741 ALIAS: 2751 ALIAS:
2742 set_type = 0 2752 set_type = 0
2753 case 2: f->magicmap = value; break; 2763 case 2: f->magicmap = value; break;
2754 case 3: f->smooth = value; break; 2764 case 3: f->smooth = value; break;
2755 case 4: f->smoothlevel = value; break; 2765 case 4: f->smoothlevel = value; break;
2756 } 2766 }
2757 2767
2758void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2768void set_csum (faceidx idx, int faceset, SV *chksum)
2759 CODE: 2769 CODE:
2760{ 2770{
2761 faceinfo *f = face_info (idx); assert (f); 2771 faceinfo *f = face_info (idx); assert (f);
2762 facedata *d = &(faceset ? f->data64 : f->data32); 2772 facedata *d = f->face + faceset;
2763 sv_to (data, d->data);
2764 STRLEN clen; 2773 STRLEN clen;
2765 char *cdata = SvPVbyte (chksum, clen); 2774 char *cdata = SvPVbyte (chksum, clen);
2766 clen = min (CHKSUM_MAXLEN, clen);
2767 2775
2776 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2768 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2777 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2769 2778
2770 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2779 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2771 { 2780 {
2772 d->chksum_len = clen; 2781 d->chksum_len = clen;
2773 memcpy (d->chksum, cdata, clen); 2782 memcpy (d->chksum, cdata, clen);
2774 2783
2775 // invalidate existing client face info 2784 // invalidate existing client face info
2776 for_all_clients (ns) 2785 for_all_clients (ns)
2777 if (ns->faceset == faceset) 2786 ns->invalidate_face (idx);
2778 {
2779 ns->faces_sent [idx] = false;
2780 ns->force_newmap = true;
2781 }
2782 } 2787 }
2783} 2788}
2784 2789
2785int get_data_size (faceidx idx, int faceset = 0) 2790SV *mangle_csum (SV *chksum)
2786 CODE: 2791 CODE:
2787 facedata *d = face_data (idx, faceset); 2792 STRLEN len;
2788 if (!d) XSRETURN_UNDEF; 2793 char *data = SvPVbyte (chksum, len);
2789 RETVAL = d->data.size (); 2794 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2790 OUTPUT: 2795 OUTPUT: RETVAL
2791 RETVAL
2792 2796
2793SV *get_chksum (faceidx idx, int faceset = 0) 2797SV *get_csum (faceidx idx, int faceset = 0)
2794 CODE: 2798 CODE:
2795 facedata *d = face_data (idx, faceset); 2799 facedata *d = face_data (idx, faceset);
2796 if (!d) XSRETURN_UNDEF; 2800 if (!d) XSRETURN_UNDEF;
2797 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2801 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2798 OUTPUT: 2802 OUTPUT: RETVAL
2799 RETVAL
2800 2803
2801SV *get_data (faceidx idx, int faceset = 0) 2804int get_type (faceidx idx)
2802 CODE: 2805 CODE:
2803 facedata *d = face_data (idx, faceset); 2806 faceinfo *f = face_info (idx);
2804 if (!d) XSRETURN_UNDEF; 2807 if (!f) XSRETURN_UNDEF;
2805 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2808 RETVAL = f->type;
2806 OUTPUT: 2809 OUTPUT: RETVAL
2807 RETVAL 2810
2811SV *get_name (faceidx idx)
2812 CODE:
2813 faceinfo *f = face_info (idx);
2814 if (!f) XSRETURN_UNDEF;
2815 RETVAL = to_sv (f->name);
2816 OUTPUT: RETVAL
2808 2817
2809void invalidate (faceidx idx) 2818void invalidate (faceidx idx)
2810 CODE: 2819 CODE:
2811 for_all_clients (ns) 2820 for_all_clients (ns)
2812 { 2821 ns->invalidate_face (idx);
2813 ns->faces_sent [idx] = false;
2814 ns->force_newmap = true;
2815 }
2816 2822
2817void invalidate_all () 2823void invalidate_all ()
2818 CODE: 2824 CODE:
2819 for_all_clients (ns) 2825 for_all_clients (ns)
2820 { 2826 ns->invalidate_all_faces ();
2821 ns->faces_sent.reset ();
2822 ns->force_newmap = true;
2823 }
2824 2827
2825MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2828MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2826 2829
2827#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2830#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2828 2831
2832 OUTPUT: RETVAL 2835 OUTPUT: RETVAL
2833 2836
2834animidx set (utf8_string name, SV *frames, int facings = 1) 2837animidx set (utf8_string name, SV *frames, int facings = 1)
2835 CODE: 2838 CODE:
2836{ 2839{
2837 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2840 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2838 croak ("frames must be an arrayref"); 2841 croak ("frames must be an arrayref");
2839 2842
2840 AV *av = (AV *)SvRV (frames); 2843 AV *av = (AV *)SvRV (frames);
2841 2844
2842 animation *anim = &animation::find (name); 2845 animation *anim = &animation::find (name);
2843 if (anim->number) 2846 if (anim->number)
2844 { 2847 {
2845 anim->resize (av_len (av) + 1); 2848 anim->resize (av_len (av) + 1);
2846 anim->facings = facings; 2849 anim->facings = facings;
2847 } 2850 }
2882bool 2885bool
2883errors_are_fatal (bool fatal) 2886errors_are_fatal (bool fatal)
2884 CODE: 2887 CODE:
2885 RETVAL = object_thawer::errors_are_fatal; 2888 RETVAL = object_thawer::errors_are_fatal;
2886 object_thawer::errors_are_fatal = fatal; 2889 object_thawer::errors_are_fatal = fatal;
2887 OUTPUT: 2890 OUTPUT: RETVAL
2888 RETVAL
2889 2891
2890SV * 2892SV *
2891new_from_file (char *klass, octet_string path) 2893new_from_file (char *klass, octet_string path)
2892 CODE: 2894 CODE:
2893 object_thawer *f = new object_thawer (path); 2895 object_thawer *f = new object_thawer (path);
2919 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2921 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2920 2922
2921 self->skip (); 2923 self->skip ();
2922 } 2924 }
2923 2925
2926MODULE = cf PACKAGE = cf::treasurelist
2927
2928# quick hack, because I didn't want to implement accessors for treasurelist.
2929# this asks for even more autogen, actually.
2930
2931void
2932expand (treasurelist *list)
2933 PPCODE:
2934 EXTEND (SP, 3);
2935 PUSHs (sv_2mortal (to_sv (list->name)));
2936 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2937 AV *av = newAV ();
2938 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2939 for (treasure *item = list->items; item; item = item->next)
2940 {
2941 AV *iav = newAV ();
2942 av_push (av, newRV_noinc ((SV *)iav));
2943
2944 av_extend (iav, 7);
2945 av_push (iav, to_sv (item->item));
2946 av_push (iav, to_sv (item->name));
2947 av_push (iav, to_sv (item->change_arch.name));
2948 av_push (iav, to_sv (item->change_arch.title));
2949 av_push (iav, to_sv (item->change_arch.slaying));
2950 av_push (iav, to_sv (item->chance));
2951 av_push (iav, to_sv (item->nrof));
2952 av_push (iav, to_sv (item->magic));
2953 }
2954
2955MODULE = cf PACKAGE = cf::layout
2956
2957INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2958

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines