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.361 by root, Tue Apr 6 22:59:28 2010 UTC vs.
Revision 1.414 by root, Tue Oct 30 17:07:50 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
52#include <XSUB.h> 53#include <XSUB.h>
53 54
54#include "CoroAPI.h" 55#include "CoroAPI.h"
55#include "perlxsi.c" 56#include "perlxsi.c"
56 57
57extern sint64 *levels; // the experience table
58
59typedef object_thawer &object_thawer_ref; 58typedef object_thawer &object_thawer_ref;
60typedef object_freezer &object_freezer_ref; 59typedef object_freezer &object_freezer_ref;
61 60
62typedef std::string std__string; 61typedef std::string std__string;
63 62
68static int tick_inhibit; 67static int tick_inhibit;
69static int tick_pending; 68static int tick_pending;
70 69
71global gbl_ev; 70global gbl_ev;
72static 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;
73static 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;
74static AV *av_reflect; 73static AV *av_reflect;
75 74
76bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
77bitset<NUM_TYPES> ev_want_type; 76bitset<NUM_TYPES> ev_want_type;
78 77
85 *stash_cf_mapspace_wrap, 84 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 85 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 86 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 87 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 88 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 89 *stash_cf_living_wrap,
90 *stash_cf_layout_wrap,
91 *stash_ext_map_world;
91 92
92static SV 93static SV
93 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 95 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
123 124
124 return sv; 125 return sv;
125} 126}
126#endif 127#endif
127 128
128static noinline utf8_string 129noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 130cfSvPVutf8_nolen (SV *sv)
130{ 131{
131 SvGETMAGIC (sv); 132 SvGETMAGIC (sv);
132 133
133 if (SvPOK (sv)) 134 if (SvPOK (sv))
230 do_destroy (); 231 do_destroy ();
231 sever_self (); 232 sever_self ();
232} 233}
233 234
234void 235void
236attachable::do_delete ()
237{
238 delete this;
239}
240
241void
235attachable::check_mortals () 242attachable::check_mortals ()
236{ 243{
237 static int i = 0; 244 static int i = 0;
238 245
239 for (;;) 246 for (;;)
246 { 253 {
247 static int last_mortalcount; 254 static int last_mortalcount;
248 if (mortals.size () != last_mortalcount) 255 if (mortals.size () != last_mortalcount)
249 { 256 {
250 last_mortalcount = mortals.size (); 257 last_mortalcount = mortals.size ();
251 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 258 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
259
260 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
261 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
252 262
253 if (0) 263 if (0)
254 { 264 {
255 for (int j = 0; j < mortals.size (); ++j)//D 265 for (int j = 0; j < mortals.size (); ++j)//D
256 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 266 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
267
257 fprintf (stderr, "\n");//D 268 fprintf (stderr, "\n");//D
258 } 269 }
259 } 270 }
260 } 271 }
261 272
281 } 292 }
282 else 293 else
283 { 294 {
284 mortals.erase (i); 295 mortals.erase (i);
285 obj->sever_self (); 296 obj->sever_self ();
286 delete obj; 297 obj->do_delete ();
287 } 298 }
288 } 299 }
289} 300}
290 301
291void 302void
346#endif 357#endif
347 358
348////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 359//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
349 360
350static SV * 361static SV *
351newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 362newSVptr (void *ptr, HV *stash, HV *hv)
352{ 363{
353 SV *sv;
354
355 if (!ptr) 364 if (!ptr)
356 return newSV (0); 365 return newSV (0);
357 366
358 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 367 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
359 return sv_bless (newRV_noinc ((SV *)hv), stash); 368 return sv_bless (newRV_noinc ((SV *)hv), stash);
369}
370
371static SV * noinline
372newSVptr (void *ptr, HV *stash)
373{
374 return newSVptr (ptr, stash, newHV ());
360} 375}
361 376
362static int 377static int
363attachable_free (pTHX_ SV *sv, MAGIC *mg) 378attachable_free (pTHX_ SV *sv, MAGIC *mg)
364{ 379{
376 return 0; 391 return 0;
377} 392}
378 393
379MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 394MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
380 395
381static SV * 396static SV * noinline
382newSVattachable (attachable *obj, HV *stash) 397newSVattachable (attachable *obj, HV *stash)
383{ 398{
384 if (!obj) 399 if (!obj)
385 return newSV (0); 400 return newSV (0);
386 401
472 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 487 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
473 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 488 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
474 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 489 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
475 && !sv_derived_from (sv, "cf::object"))) 490 && !sv_derived_from (sv, "cf::object")))
476 croak ("object of type cf::object expected"); 491 croak ("object of type cf::object expected");
492
493 return SvPTR_nc (sv);
494}
495
496static long noinline
497SvPTR_ornull_maptile (SV *sv)
498{
499 if (expect_false (!SvOK (sv))) return 0;
500
501 if (!SvROK (sv)
502 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
503 && SvSTASH (SvRV (sv)) != stash_ext_map_world
504 && !sv_derived_from (sv, "cf::map")))
505 croak ("object of type cf::map expected");
477 506
478 return SvPTR_nc (sv); 507 return SvPTR_nc (sv);
479} 508}
480 509
481static long noinline 510static long noinline
506static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 535static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
507static inline SV *to_sv (float v) { return newSVnv (v); } 536static inline SV *to_sv (float v) { return newSVnv (v); }
508static inline SV *to_sv (double v) { return newSVnv (v); } 537static inline SV *to_sv (double v) { return newSVnv (v); }
509static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 538static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
510static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 539static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
540// gcc dislikes noilnine on to_sv
511static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 541static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
542static inline SV *to_sv (object * v) { return to_sv_ni (v); }
512static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 543static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
513static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 544static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
514static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 545static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
515static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 546static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
516static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 547static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
517static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 548static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
549static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
518 550
519static inline SV *to_sv (object & v) { return to_sv (&v); } 551static inline SV *to_sv (object & v) { return to_sv (&v); }
520static inline SV *to_sv (living & v) { return to_sv (&v); } 552static inline SV *to_sv (living & v) { return to_sv (&v); }
521 553
522static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 554static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
558static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 590static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
559static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 591static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
560static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 592static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
561static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 593static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
562static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 594static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
563static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 595static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
564static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 596static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
565static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 597static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
598static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
566static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 599static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
567static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
568static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 600static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
569static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 601static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
570static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 602static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
571static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 603static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
572static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 604static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
605static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
573static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 606static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
574static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 607static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
575 608
576//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 609//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
577static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 610static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
590static inline void sv_to (SV *sv, std::string &v) 623static inline void sv_to (SV *sv, std::string &v)
591{ 624{
592 STRLEN len; 625 STRLEN len;
593 char *data = SvPVbyte (sv, len); 626 char *data = SvPVbyte (sv, len);
594 v.assign (data, len); 627 v.assign (data, len);
628}
629
630static inline void sv_to (SV *sv, refcnt_buf &v)
631{
632 STRLEN len;
633 char *data = SvPVbyte (sv, len);
634 refcnt_buf buf (data, len);
635 v = buf;
595} 636}
596 637
597static inline void sv_to (SV *sv, UUID &v) 638static inline void sv_to (SV *sv, UUID &v)
598{ 639{
599 if (!v.parse (SvPV_nolen (sv))) 640 if (!v.parse (SvPV_nolen (sv)))
688template<class type> 729template<class type>
689static void noinline 730static void noinline
690cf_obj_to (SV *arg, type &var) 731cf_obj_to (SV *arg, type &var)
691{ 732{
692 sv_to (arg, var); 733 sv_to (arg, var);
693 if (!var) 734 if (expect_false (!var))
694 croak ("must not pass invalid/null cf_obj here"); 735 croak ("must not pass invalid/null cf_obj here");
695} 736}
696 737
697template<class object> 738template<class object>
698static void noinline 739static void noinline
699cf_obj_ornull_to (SV *arg, object *&var) 740cf_obj_ornull_to (SV *arg, object *&var)
700{ 741{
701 if (SvOK (arg)) 742 if (SvOK (arg))
702 { 743 {
703 sv_to (arg, var); 744 sv_to (arg, var);
704 if (!var) 745 if (expect_false (!var))
705 croak ("unable to convert perl object to C++ object"); 746 croak ("unable to convert perl object to C++ object");
706 } 747 }
707 else 748 else
708 var = 0; 749 var = 0;
709} 750}
744 exit (EXIT_FAILURE); 785 exit (EXIT_FAILURE);
745 } 786 }
746 787
747 eval_pv ( 788 eval_pv (
748 "#line 1 'cfperl init'\n" 789 "#line 1 'cfperl init'\n"
749 "use EV ();\n" 790 "use EV ();\n" // required by bootstrap
750 "use Coro ();\n" 791 "use Coro ();\n" // required by bootstrap
751 "cf->bootstrap;\n" 792 "cf->bootstrap;\n" // required for cf::datadir
752 "unshift @INC, cf::datadir ();\n" 793 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
753 "require cf;\n", 794 "require cf;\n",
754 0 795 0
755 ); 796 );
756 797
757 if (SvTRUE (ERRSV)) 798 if (SvTRUE (ERRSV))
1132 1173
1133 return retval; 1174 return retval;
1134} 1175}
1135 1176
1136maptile * 1177maptile *
1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1178find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1138{ 1179{
1139 CALL_BEGIN (3); 1180 CALL_BEGIN (4);
1140 CALL_ARG (dirname); 1181 CALL_ARG (dirname);
1141 CALL_ARG (stylename); 1182 CALL_ARG (stylename);
1142 CALL_ARG (difficulty); 1183 CALL_ARG (difficulty);
1184 CALL_ARG (recurse);
1143 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1185 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1144 1186
1145 maptile *retval = 0; 1187 maptile *retval = 0;
1146 if (count) sv_to (POPs, retval); 1188 if (count) sv_to (POPs, retval);
1147 1189
1224object::ref () const 1266object::ref () const
1225{ 1267{
1226 if (type == PLAYER) 1268 if (type == PLAYER)
1227 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1269 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1228 else 1270 else
1271 // TODO: should be able to save references within the same map, at least
1229 return 0; 1272 return 0;
1230} 1273}
1231 1274
1232object * 1275object *
1233object::deref (const_utf8_string ref) 1276object::deref (const_utf8_string ref)
1369 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1412 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1370 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1413 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1371 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1414 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1372 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1415 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1373 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1416 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1417 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1418 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1374 1419
1375 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1420 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1376 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1421 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1422 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1377 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1423 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1378 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1424 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1379 1425
1380 cb_global = get_av ("cf::CB_GLOBAL", 1); 1426 cb_global = get_av ("cf::CB_GLOBAL", 1);
1381 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1427 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1382 cb_object = get_av ("cf::CB_OBJECT", 1); 1428 cb_object = get_av ("cf::CB_OBJECT", 1);
1383 cb_player = get_av ("cf::CB_PLAYER", 1); 1429 cb_player = get_av ("cf::CB_PLAYER", 1);
1426# include "attackinc.h" 1472# include "attackinc.h"
1427# undef def 1473# undef def
1428# define def(uc, flags) const_iv (SK_ ## uc) 1474# define def(uc, flags) const_iv (SK_ ## uc)
1429# include "skillinc.h" 1475# include "skillinc.h"
1430# undef def 1476# undef def
1431 1477# define def(name, use, nonuse) const_iv (body_ ## name)
1432 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1478# include "slotinc.h"
1433 const_iv (logBacktrace) 1479# undef def
1434
1435 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1436 1480
1437 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1481 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1438 1482
1439 const_iv (MAX_TIME) 1483 const_iv (MAX_TIME)
1440 const_iv (MAXSOCKBUF) 1484 const_iv (MAXSOCKBUF)
1454 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1498 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1455 1499
1456 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1500 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1457 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1501 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1458 1502
1459 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1460 const_iv (MAP_INACTIVE)
1461
1462 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1503 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1463 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1504 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1464 1505
1465 const_iv (VERSION_CS) const_iv (VERSION_SC)
1466
1467 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1506 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1468 1507
1469 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1508 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1470 }; 1509 };
1471 1510
1472 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1511 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1473 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1512 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1474 1513
1475 static const struct { 1514 static const struct {
1476 const char *name; 1515 const char *name;
1477 int skip; 1516 int skip;
1483# undef def 1522# undef def
1484 }; 1523 };
1485 1524
1486 AV *av = get_av ("cf::EVENT", 1); 1525 AV *av = get_av ("cf::EVENT", 1);
1487 1526
1488 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1527 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1489 { 1528 {
1490 AV *event = newAV (); 1529 AV *event = newAV ();
1491 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1530 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1492 av_push (event, newSViv (eiv->klass)); 1531 av_push (event, newSViv (eiv->klass));
1493 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1532 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1500 1539
1501void _gv_clear (SV *gv) 1540void _gv_clear (SV *gv)
1502 CODE: 1541 CODE:
1503 assert (SvTYPE (gv) == SVt_PVGV); 1542 assert (SvTYPE (gv) == SVt_PVGV);
1504# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1543# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1544 SvREFCNT_inc (gv);
1505 f (GvGP (gv)->gp_form); 1545 f (GvGP (gv)->gp_form);
1506 f (GvGP (gv)->gp_io); 1546 f (GvGP (gv)->gp_io);
1507 f (GvGP (gv)->gp_sv); 1547 f (GvGP (gv)->gp_sv);
1508 f (GvGP (gv)->gp_av); 1548 f (GvGP (gv)->gp_av);
1509 f (GvGP (gv)->gp_hv); 1549 f (GvGP (gv)->gp_hv);
1510 f (GvGP (gv)->gp_cv); 1550 f (GvGP (gv)->gp_cv);
1511 GvCVGEN (gv) = 0; 1551 GvCVGEN (gv) = 0;
1512 GvMULTI_off (gv); 1552 GvMULTI_off (gv);
1553 SvREFCNT_dec (gv);
1513# undef f 1554# undef f
1514 1555
1515void _connect_to_perl_1 () 1556void _connect_to_perl_1 ()
1516 1557
1517void _connect_to_perl_2 () 1558void _connect_to_perl_2 ()
1528 1569
1529 for_all_objects (op) 1570 for_all_objects (op)
1530 op->reattach (); 1571 op->reattach ();
1531} 1572}
1532 1573
1533# support function for map-world.ext
1534void _quantise (SV *data_sv, SV *plt_sv)
1535 CODE:
1536{
1537 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1538 croak ("_quantise called with invalid agruments");
1539
1540 plt_sv = SvRV (plt_sv);
1541 SV **plt = AvARRAY (plt_sv);
1542 int plt_count = AvFILL (plt_sv) + 1;
1543
1544 STRLEN len;
1545 char *data = SvPVbyte (data_sv, len);
1546 char *dst = data;
1547
1548 while (len >= 3)
1549 {
1550 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1551 {
1552 char *val = SvPVX (*val_sv);
1553
1554 if (val [0] == data [0]
1555 && val [1] == data [1]
1556 && val [2] == data [2])
1557 {
1558 *dst++ = val [3];
1559 goto next;
1560 }
1561 }
1562
1563 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1564 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1565 dst - SvPVX (data_sv), len);
1566
1567 next:
1568 data += 3;
1569 len -= 3;
1570 }
1571
1572 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1573}
1574
1575void init_anim () 1574void init_anim ()
1576 1575
1577void init_globals () 1576void init_globals ()
1578 1577
1579void init_experience ()
1580
1581void init_attackmess () 1578void init_attackmess ()
1582 1579
1583void init_dynamic () 1580void init_dynamic ()
1584 1581
1585void load_settings () 1582void load_settings ()
1586 1583
1584void reload_exp_table ()
1585
1587void load_materials () 1586void reload_materials ()
1588 1587
1589void init_uuid () 1588void init_uuid ()
1590 CODE: 1589 CODE:
1591 UUID::init (); 1590 UUID::init ();
1592 1591
1625 { 1624 {
1626 ev_async_send (EV_DEFAULT, &tick_watcher); 1625 ev_async_send (EV_DEFAULT, &tick_watcher);
1627 coroapi::cede (); 1626 coroapi::cede ();
1628 } 1627 }
1629 1628
1630void server_tick () 1629void one_tick ()
1631 CODE: 1630 CODE:
1632{ 1631{
1633 ev_now_update (EV_DEFAULT); 1632 ev_now_update (EV_DEFAULT);
1634 NOW = ev_now (EV_DEFAULT); 1633 NOW = ev_now (EV_DEFAULT);
1635 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1634 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1636 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1635 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1637 runtime = SvNVX (sv_runtime); 1636 runtime = SvNVX (sv_runtime);
1638 1637
1638 one_tick ();
1639
1639 server_tick (); 1640 ++server_tick;
1641 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1640 1642
1641 ev_now_update (EV_DEFAULT); 1643 ev_now_update (EV_DEFAULT);
1642 NOW = ev_now (EV_DEFAULT); 1644 NOW = ev_now (EV_DEFAULT);
1643 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1645 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1646
1644 runtime += TICK; 1647 runtime += TICK;
1645 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1648 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1646} 1649}
1647 1650
1648NV floor (NV x) 1651NV floor (NV x)
1658 switch (items) 1661 switch (items)
1659 { 1662 {
1660 case 0: RETVAL = gen (); break; 1663 case 0: RETVAL = gen (); break;
1661 case 1: RETVAL = gen (SvUV (ST (0))); break; 1664 case 1: RETVAL = gen (SvUV (ST (0))); break;
1662 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1665 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1663 default: croak ("cf::rndm requires none, one or two parameters."); break; 1666 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1664 } 1667 }
1665} 1668}
1666 OUTPUT: 1669 OUTPUT:
1667 RETVAL 1670 RETVAL
1668 1671
1684 PROTOTYPE: @ 1687 PROTOTYPE: @
1685 CODE: 1688 CODE:
1686 while (items > 0) 1689 while (items > 0)
1687 sv_rvweaken (ST (--items)); 1690 sv_rvweaken (ST (--items));
1688 1691
1689void 1692void log_suspend ()
1693
1694void log_resume ()
1695
1690log_backtrace (utf8_string msg) 1696void log_backtrace (utf8_string msg)
1691 1697
1692void
1693LOG (int flags, utf8_string msg) 1698void LOG (int flags, utf8_string msg)
1694 PROTOTYPE: $$ 1699 PROTOTYPE: $$
1695 C_ARGS: flags, "%s", msg 1700 C_ARGS: flags, "%s", msg
1696 1701
1697octet_string path_combine (octet_string base, octet_string path) 1702octet_string path_combine (octet_string base, octet_string path)
1698 PROTOTYPE: $$ 1703 PROTOTYPE: $$
1745 1750
1746int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1751int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1747 INIT: 1752 INIT:
1748#if __GLIBC__ 1753#if __GLIBC__
1749 mallopt (M_TOP_PAD, 1024 * 1024); 1754 mallopt (M_TOP_PAD, 1024 * 1024);
1750 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1755 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1751 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1756 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1757 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1752 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1758 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1753#endif 1759#endif
1754 1760
1755int munlockall () 1761int munlockall ()
1756 1762
1757#endif 1763#endif
1790 1796
1791int random_roll (int min, int max, object *op, int goodbad); 1797int random_roll (int min, int max, object *op, int goodbad);
1792 1798
1793const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1799const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1794 1800
1795int
1796exp_to_level (val64 exp) 1801int exp_to_level (val64 exp)
1802
1803val64 level_to_min_exp (int level)
1804
1805SV *
1806attacktype_name (int atnr)
1797 CODE: 1807 CODE:
1798{ 1808 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1799 int i = 0; 1809 ? newSVpv (attacktype_name [atnr], 0)
1800 1810 : &PL_sv_undef;
1801 RETVAL = settings.max_level;
1802
1803 for (i = 1; i <= settings.max_level; i++)
1804 {
1805 if (levels[i] > exp)
1806 {
1807 RETVAL = i - 1;
1808 break;
1809 }
1810 }
1811}
1812 OUTPUT: RETVAL 1811 OUTPUT: RETVAL
1813 1812
1814val64
1815level_to_min_exp (int level)
1816 CODE:
1817 if (level > settings.max_level)
1818 RETVAL = levels[settings.max_level];
1819 else if (level < 1)
1820 RETVAL = 0;
1821 else
1822 RETVAL = levels[level];
1823 OUTPUT: RETVAL
1824
1825SV * 1813SV *
1826resistance_to_string (int atnr) 1814attacktype_desc (int atnr)
1827 CODE: 1815 CODE:
1828 if (atnr >= 0 && atnr < NROFATTACKS) 1816 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1817 ? newSVpv (attacktype_desc [atnr], 0)
1818 : &PL_sv_undef;
1819 OUTPUT: RETVAL
1820
1821SV *
1822resist_plus (int atnr)
1823 CODE:
1824 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1825 ? newSVpv (resist_plus [atnr], 0)
1830 else 1826 : &PL_sv_undef;
1831 XSRETURN_UNDEF; 1827 OUTPUT: RETVAL
1828
1829SV *
1830change_resist_msg (int atnr)
1831 CODE:
1832 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 ? newSVpv (change_resist_msg [atnr], 0)
1834 : &PL_sv_undef;
1832 OUTPUT: RETVAL 1835 OUTPUT: RETVAL
1833 1836
1834UUID 1837UUID
1835uuid_cur () 1838uuid_cur ()
1836 CODE: 1839 CODE:
1886 CODE: 1889 CODE:
1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1890 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1888 OUTPUT: 1891 OUTPUT:
1889 RETVAL 1892 RETVAL
1890 1893
1894bool should_invoke (attachable *obj, int event)
1895 CODE:
1896 RETVAL = obj->should_invoke ((event_type)event);
1897 OUTPUT: RETVAL
1898
1891void 1899void
1892debug_trace (attachable *obj, bool on = true) 1900debug_trace (attachable *obj, bool on = true)
1893 CODE: 1901 CODE:
1894 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1902 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1895 if (on) 1903 if (on)
1954int mortals_size () 1962int mortals_size ()
1955 CODE: 1963 CODE:
1956 RETVAL = attachable::mortals.size (); 1964 RETVAL = attachable::mortals.size ();
1957 OUTPUT: RETVAL 1965 OUTPUT: RETVAL
1958 1966
1959const_utf8_string slot_use_name (U32 slot) 1967const_utf8_string slot_name (U32 slot)
1960 ALIAS: 1968 ALIAS:
1969 slot_name = 0
1970 slot_use_name = 1
1961 slot_nonuse_name = 1 1971 slot_nonuse_name = 2
1962 CODE: 1972 CODE:
1963{ 1973{
1964 if (slot >= NUM_BODY_LOCATIONS) 1974 if (slot >= NUM_BODY_LOCATIONS)
1965 croak ("body slot index out of range"); 1975 croak ("body slot index out of range");
1966 1976
1967 switch (ix) 1977 switch (ix)
1968 { 1978 {
1979 case 0: RETVAL = body_locations[slot].name ; break;
1969 case 0: RETVAL = body_locations[slot].use_name; break; 1980 case 1: RETVAL = body_locations[slot].use_name ; break;
1970 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1981 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1971 } 1982 }
1972} 1983}
1973 OUTPUT: 1984 OUTPUT:
1974 RETVAL 1985 RETVAL
1975 1986
2020 OUTPUT: 2031 OUTPUT:
2021 RETVAL 2032 RETVAL
2022 2033
2023object *find_best_object_match (object *op, utf8_string match) 2034object *find_best_object_match (object *op, utf8_string match)
2024 2035
2025object *find_marked_object (object *op)
2026
2027int need_identify (object *obj);
2028
2029int apply_shop_mat (object *shop_mat, object *op); 2036int apply_shop_mat (object *shop_mat, object *op);
2030 2037
2031int move (object *op, int dir, object *originator = op) 2038int move (object *op, int dir, object *originator = op)
2032 CODE: 2039 CODE:
2033 RETVAL = op->move (dir, originator); 2040 RETVAL = op->move (dir, originator);
2085 2092
2086void pick_up (object *who, object *op) 2093void pick_up (object *who, object *op)
2087 2094
2088void update_object (object *op, int action) 2095void update_object (object *op, int action)
2089 2096
2090void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2097void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2091 2098
2092void player_lvl_adj (object *who, object *skill = 0) 2099void player_lvl_adj (object *who, object *skill = 0)
2093 2100
2094int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2101int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2095 2102
2111# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2118# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2112 2119
2113object *new (utf8_string archetype = 0) 2120object *new (utf8_string archetype = 0)
2114 PROTOTYPE: ;$ 2121 PROTOTYPE: ;$
2115 CODE: 2122 CODE:
2116 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2123 RETVAL = archetype
2124 ? archetype::get (archetype)
2125 : object::create ();
2117 OUTPUT: 2126 OUTPUT:
2118 RETVAL 2127 RETVAL
2119 2128
2120object *generate (utf8_string arch, object *creator) 2129object *generate (utf8_string arch, object *creator)
2121 CODE: 2130 CODE:
2122 object *obj = get_archetype (arch); 2131 object *obj = archetype::get (arch);
2123 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2132 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2124 RETVAL = obj; 2133 RETVAL = obj;
2125 OUTPUT: 2134 OUTPUT:
2126 RETVAL 2135 RETVAL
2127 2136
2137 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2146 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2138 2147
2139 if (RETVAL->destroyed ()) 2148 if (RETVAL->destroyed ())
2140 RETVAL = 0; 2149 RETVAL = 0;
2141} 2150}
2151 OUTPUT:
2152 RETVAL
2142 2153
2143shstr 2154shstr
2144object::kv_get (shstr key) 2155object::kv_get (shstr key)
2156 CODE:
2157 RETVAL = THIS->kv.get (key);
2158 OUTPUT:
2159 RETVAL
2145 2160
2146void 2161void
2147object::kv_del (shstr key) 2162object::kv_del (shstr key)
2163 CODE:
2164 THIS->kv.del (key);
2148 2165
2149void 2166void
2150object::kv_set (shstr key, shstr value) 2167object::kv_set (shstr key, shstr value)
2168 CODE:
2169 THIS->kv.set (key, value);
2151 2170
2152object *get_nearest_player (object *ob) 2171object *get_nearest_player (object *ob)
2153 ALIAS: nearest_player = 0 2172 ALIAS: nearest_player = 0
2154 PREINIT: 2173 PREINIT:
2155 extern object *get_nearest_player (object *); 2174 extern object *get_nearest_player (object *);
2158 PROTOTYPE: $$;$ 2177 PROTOTYPE: $$;$
2159 PPCODE: 2178 PPCODE:
2160{ 2179{
2161 rv_vector rv; 2180 rv_vector rv;
2162 2181
2163 PUTBACK;
2164 get_rangevector (ob, other, &rv, flags); 2182 get_rangevector (ob, other, &rv, flags);
2165 SPAGAIN;
2166 2183
2167 EXTEND (SP, 5); 2184 EXTEND (SP, 5);
2168 PUSHs (newSVuv (rv.distance)); 2185 PUSHs (sv_2mortal (newSVuv (rv.distance)));
2169 PUSHs (newSViv (rv.distance_x)); 2186 PUSHs (sv_2mortal (newSViv (rv.distance_x)));
2170 PUSHs (newSViv (rv.distance_y)); 2187 PUSHs (sv_2mortal (newSViv (rv.distance_y)));
2171 PUSHs (newSViv (rv.direction)); 2188 PUSHs (sv_2mortal (newSViv (rv.direction)));
2172 PUSHs (to_sv (rv.part)); 2189 PUSHs (sv_2mortal (to_sv (rv.part)));
2173} 2190}
2174 2191
2175bool on_same_map_as (object *ob, object *other) 2192bool on_same_map_as (object *ob, object *other)
2176 CODE: 2193 CODE:
2177 RETVAL = on_same_map (ob, other); 2194 RETVAL = on_same_map (ob, other);
2360 if (pl->ob && pl->ob->map == THIS) 2377 if (pl->ob && pl->ob->map == THIS)
2361 PUSHs (sv_2mortal (to_sv (pl->ob))); 2378 PUSHs (sv_2mortal (to_sv (pl->ob)));
2362 } 2379 }
2363 2380
2364void 2381void
2382maptile::gen_quadmap (int x, int y, int z)
2383 CODE:
2384 gen_quadmap (THIS, x * 50, y * 50, z);
2385
2386void
2365maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2387maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2366 CODE: 2388 CODE:
2367{ 2389{
2368 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2390 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2369 croak ("maptile::add_underlay: palette must be arrayref"); 2391 croak ("maptile::add_underlay: palette must be arrayref");
2385 2407
2386 if (IN_RANGE_EXC (offs, 0, idxlen)) 2408 if (IN_RANGE_EXC (offs, 0, idxlen))
2387 { 2409 {
2388 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2410 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2389 { 2411 {
2390 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2412 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2391 ob->flag [FLAG_NO_MAP_SAVE] = true; 2413 ob->flag [FLAG_NO_MAP_SAVE] = true;
2392 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2414 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2393 2415
2394 if (ob->randomitems && !ob->above) 2416 if (ob->randomitems && !ob->above)
2395 { 2417 {
2399 op->flag [FLAG_NO_MAP_SAVE] = true; 2421 op->flag [FLAG_NO_MAP_SAVE] = true;
2400 // TODO: if this is a pickable object, then the item 2422 // TODO: if this is a pickable object, then the item
2401 // will at a bit weird - saving inside the player 2423 // will at a bit weird - saving inside the player
2402 // will clear the flag, but when the player drops 2424 // will clear the flag, but when the player drops
2403 // it without logging out, it keeps the flag. 2425 // it without logging out, it keeps the flag.
2404 // nobody ahs reported this, but this can be rather 2426 // nobody has reported this, but this can be rather
2405 // annoying on persistent maps. 2427 // annoying on persistent maps.
2406 } 2428 }
2407 } 2429 }
2408 } 2430 }
2409 } 2431 }
2410
2411 skip: ; 2432 skip: ;
2412 } 2433 }
2413} 2434}
2414 2435
2415void 2436void
2446 for (int x = 0; x < THIS->width; ++x) 2467 for (int x = 0; x < THIS->width; ++x)
2447 for (int y = 0; y < THIS->height; ++y) 2468 for (int y = 0; y < THIS->height; ++y)
2448 { 2469 {
2449 region *rgn = THIS->region (x, y); 2470 region *rgn = THIS->region (x, y);
2450 2471
2451 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2452 if (object *op = THIS->at (x, y).top) 2472 if (object *op = THIS->at (x, y).top)
2453 if (rgn->treasure && rndm () < rgn->treasure_density) 2473 if (rgn->treasure && rndm () < rgn->treasure_density)
2454 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2474 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2455 } 2475 }
2456 2476
2462 if (oblinkpt *obp = map->find_link (connection)) 2482 if (oblinkpt *obp = map->find_link (connection))
2463 for (objectlink *ol = obp->link; ol; ol = ol->next) 2483 for (objectlink *ol = obp->link; ol; ol = ol->next)
2464 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2484 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2465 2485
2466void 2486void
2467get_map_flags (maptile *map, int x, int y) 2487xy_normalise (maptile *map, int x, int y, int dir = 0)
2468 PPCODE: 2488 PPCODE:
2469{ 2489{
2470 maptile *nmap = 0; 2490 mapxy pos (map, x, y);
2471 I16 nx = 0, ny = 0; 2491 if (!pos.move (dir).normalise ())
2492 XSRETURN_EMPTY;
2472 2493
2473 PUTBACK;
2474 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2475 SPAGAIN;
2476
2477 EXTEND (SP, 4); 2494 EXTEND (SP, 3);
2478 PUSHs (sv_2mortal (newSViv (flags)));
2479
2480 if (GIMME_V == G_ARRAY)
2481 {
2482 PUSHs (sv_2mortal (to_sv (nmap))); 2495 PUSHs (sv_2mortal (to_sv (pos.m)));
2483 PUSHs (sv_2mortal (newSViv (nx))); 2496 PUSHs (sv_2mortal (to_sv (pos.x)));
2484 PUSHs (sv_2mortal (newSViv (ny))); 2497 PUSHs (sv_2mortal (to_sv (pos.y)));
2485 }
2486} 2498}
2487 2499
2488mapspace * 2500mapspace *
2489ms (maptile *map, unsigned int x, unsigned int y) 2501ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2490 PROTOTYPE: $$$ 2502 PROTOTYPE: $$$;$
2491 CODE: 2503 CODE:
2492{ 2504{
2493 maptile *nmap = 0; 2505 mapxy pos (map, x, y);
2494 I16 nx, ny; 2506 if (!pos.move (dir).normalise ())
2495
2496 PUTBACK;
2497 get_map_flags (map, &nmap, x, y, &nx, &ny);
2498 SPAGAIN;
2499
2500 if (!nmap)
2501 XSRETURN_UNDEF; 2507 XSRETURN_UNDEF;
2502 2508
2503 RETVAL = &nmap->at (nx, ny); 2509 RETVAL = &*pos;
2504} 2510}
2505 OUTPUT: 2511 OUTPUT:
2506 RETVAL 2512 RETVAL
2507 2513
2508void 2514void
2509at (maptile *map, unsigned int x, unsigned int y) 2515at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2510 PROTOTYPE: $$$ 2516 PROTOTYPE: $$$;$
2511 PPCODE: 2517 PPCODE:
2512{ 2518 mapxy pos (map, x, y);
2513 maptile *nmap = 0; 2519 if (pos.move (dir).normalise ())
2514 I16 nx, ny;
2515
2516 PUTBACK;
2517 get_map_flags (map, &nmap, x, y, &nx, &ny);
2518 SPAGAIN;
2519
2520 if (nmap)
2521 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2520 for (object *o = pos->bot; o; o = o->above)
2522 XPUSHs (sv_2mortal (to_sv (o))); 2521 XPUSHs (sv_2mortal (to_sv (o)));
2523}
2524 2522
2525SV * 2523SV *
2526bot_at (maptile *map, unsigned int x, unsigned int y) 2524bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2527 PROTOTYPE: $$$ 2525 PROTOTYPE: $$$;$
2528 ALIAS: 2526 ALIAS:
2529 top_at = 1 2527 top_at = 1
2530 flags_at = 2 2528 flags_at = 2
2531 light_at = 3 2529 light_at = 3
2532 move_block_at = 4 2530 move_block_at = 4
2533 move_slow_at = 5 2531 move_slow_at = 5
2534 move_on_at = 6 2532 move_on_at = 6
2535 move_off_at = 7 2533 move_off_at = 7
2536 CODE: 2534 CODE:
2537{ 2535{
2538 sint16 nx = x; 2536 mapxy pos (map, x, y);
2539 sint16 ny = y; 2537 if (!pos.move (dir).normalise ())
2540
2541 if (!xy_normalise (map, nx, ny))
2542 XSRETURN_UNDEF; 2538 XSRETURN_UNDEF;
2543 2539
2544 mapspace &ms = map->at (nx, ny); 2540 mapspace &ms = *pos;
2545 2541
2546 ms.update (); 2542 ms.update ();
2547 2543
2548 switch (ix) 2544 switch (ix)
2549 { 2545 {
2559} 2555}
2560 OUTPUT: RETVAL 2556 OUTPUT: RETVAL
2561 2557
2562# worst xs function of my life 2558# worst xs function of my life
2563bool 2559bool
2564_create_random_map (\ 2560_create_random_map (maptile *self, SV *options)
2565 maptile *self,\
2566 utf8_string wallstyle,\
2567 utf8_string wall_name,\
2568 utf8_string floorstyle,\
2569 utf8_string monsterstyle,\
2570 utf8_string treasurestyle,\
2571 utf8_string layoutstyle,\
2572 utf8_string doorstyle,\
2573 utf8_string decorstyle,\
2574 utf8_string miningstyle,\
2575 utf8_string origin_map,\
2576 utf8_string final_map,\
2577 utf8_string exitstyle,\
2578 utf8_string this_map,\
2579 utf8_string exit_on_final_map,\
2580 int xsize,\
2581 int ysize,\
2582 int expand2x,\
2583 int layoutoptions1,\
2584 int layoutoptions2,\
2585 int layoutoptions3,\
2586 int symmetry,\
2587 int difficulty,\
2588 int difficulty_given,\
2589 float difficulty_increase,\
2590 int dungeon_level,\
2591 int dungeon_depth,\
2592 int decoroptions,\
2593 int orientation,\
2594 int origin_y,\
2595 int origin_x,\
2596 U32 random_seed,\
2597 val64 total_map_hp,\
2598 int map_layout_style,\
2599 int treasureoptions,\
2600 int symmetry_used,\
2601 region *region,\
2602 utf8_string custom\
2603)
2604 CODE: 2561 CODE:
2605{ 2562{
2606 random_map_params rmp; 2563 random_map_params rmp ((HV *)SvRV (options));
2607
2608 assign (rmp.wallstyle , wallstyle);
2609 assign (rmp.wall_name , wall_name);
2610 assign (rmp.floorstyle , floorstyle);
2611 assign (rmp.monsterstyle , monsterstyle);
2612 assign (rmp.treasurestyle , treasurestyle);
2613 assign (rmp.layoutstyle , layoutstyle);
2614 assign (rmp.doorstyle , doorstyle);
2615 assign (rmp.decorstyle , decorstyle);
2616 assign (rmp.miningstyle , miningstyle);
2617 assign (rmp.exitstyle , exitstyle);
2618 assign (rmp.exit_on_final_map, exit_on_final_map);
2619
2620 rmp.origin_map = origin_map;
2621 rmp.final_map = final_map;
2622 rmp.this_map = this_map;
2623 rmp.xsize = xsize;
2624 rmp.ysize = ysize;
2625 rmp.expand2x = expand2x;
2626 rmp.layoutoptions1 = layoutoptions1;
2627 rmp.layoutoptions2 = layoutoptions2;
2628 rmp.layoutoptions3 = layoutoptions3;
2629 rmp.symmetry = symmetry;
2630 rmp.difficulty = difficulty;
2631 rmp.difficulty_given = difficulty_given;
2632 rmp.difficulty_increase = difficulty_increase;
2633 rmp.dungeon_level = dungeon_level;
2634 rmp.dungeon_depth = dungeon_depth;
2635 rmp.decoroptions = decoroptions;
2636 rmp.orientation = orientation;
2637 rmp.origin_y = origin_y;
2638 rmp.origin_x = origin_x;
2639 rmp.random_seed = random_seed;
2640 rmp.total_map_hp = (uint64_t) total_map_hp;
2641 rmp.map_layout_style = map_layout_style;
2642 rmp.treasureoptions = treasureoptions;
2643 rmp.symmetry_used = symmetry_used;
2644 rmp.region = region;
2645 rmp.custom = custom;
2646
2647 RETVAL = self->generate_random_map (&rmp); 2564 RETVAL = self->generate_random_map (&rmp);
2648} 2565}
2649 OUTPUT: 2566 OUTPUT:
2650 RETVAL 2567 RETVAL
2651 2568
2683list () 2600list ()
2684 PPCODE: 2601 PPCODE:
2685 for_all_regions (rgn) 2602 for_all_regions (rgn)
2686 XPUSHs (sv_2mortal (to_sv (rgn))); 2603 XPUSHs (sv_2mortal (to_sv (rgn)));
2687 2604
2688region *find (utf8_string name)
2689 PROTOTYPE: $
2690 CODE:
2691 RETVAL = region::find (name);
2692 OUTPUT: RETVAL
2693
2694int specificity (region *rgn) 2605int specificity (region *rgn)
2695 CODE: 2606 CODE:
2696 RETVAL = 0; 2607 RETVAL = 0;
2697 while (rgn = rgn->parent) 2608 while (rgn = rgn->parent)
2698 RETVAL++; 2609 RETVAL++;
2726list () 2637list ()
2727 PPCODE: 2638 PPCODE:
2728 EXTEND (SP, clients.size ()); 2639 EXTEND (SP, clients.size ());
2729 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2640 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2730 PUSHs (sv_2mortal (to_sv (*i))); 2641 PUSHs (sv_2mortal (to_sv (*i)));
2642
2643STRLEN
2644client::inbuf_append (SV *data)
2645 CODE:
2646{
2647 STRLEN len;
2648 char *ptr = SvPVbyte (data, len);
2649
2650 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2651 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2652 THIS->inbuf_len += len;
2653
2654 THIS->inbuf_handle ();
2655
2656 RETVAL = len;
2657}
2658 OUTPUT: RETVAL
2731 2659
2732void 2660void
2733client::send_packet (SV *packet) 2661client::send_packet (SV *packet)
2734 CODE: 2662 CODE:
2735{ 2663{
2791faceidx face_find (utf8_string name, faceidx defidx = 0) 2719faceidx face_find (utf8_string name, faceidx defidx = 0)
2792 2720
2793faceidx alloc (utf8_string name) 2721faceidx alloc (utf8_string name)
2794 CODE: 2722 CODE:
2795{ 2723{
2796 do 2724 RETVAL = face_alloc ();
2797 {
2798 RETVAL = faces.size ();
2799 faces.resize (RETVAL + 1);
2800 }
2801 while (!RETVAL); // crude way to leave index 0
2802 2725
2803 faces [RETVAL].name = name; 2726 faces [RETVAL].name = name;
2804 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2727 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2805 2728
2806 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2729 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2807 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2730 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2731 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2808} 2732}
2733 OUTPUT: RETVAL
2734
2735faceidx faces_size ()
2736 CODE:
2737 RETVAL = faces.size ();
2809 OUTPUT: RETVAL 2738 OUTPUT: RETVAL
2810 2739
2811void set_type (faceidx idx, int value) 2740void set_type (faceidx idx, int value)
2812 ALIAS: 2741 ALIAS:
2813 set_type = 0 2742 set_type = 0
2828 2757
2829void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2758void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2830 CODE: 2759 CODE:
2831{ 2760{
2832 faceinfo *f = face_info (idx); assert (f); 2761 faceinfo *f = face_info (idx); assert (f);
2833 facedata *d = &(faceset ? f->data64 : f->data32); 2762 facedata *d = f->face + faceset;
2834 sv_to (data, d->data); 2763 sv_to (data, d->data);
2835 STRLEN clen; 2764 STRLEN clen;
2836 char *cdata = SvPVbyte (chksum, clen); 2765 char *cdata = SvPVbyte (chksum, clen);
2837 clen = min (CHKSUM_MAXLEN, clen); 2766 clen = min (CHKSUM_MAXLEN, clen);
2838 2767
2859 if (!d) XSRETURN_UNDEF; 2788 if (!d) XSRETURN_UNDEF;
2860 RETVAL = d->data.size (); 2789 RETVAL = d->data.size ();
2861 OUTPUT: 2790 OUTPUT:
2862 RETVAL 2791 RETVAL
2863 2792
2793void set_meta (faceidx idx, SV *sv)
2794 CODE:
2795{
2796 faceinfo *f = face_info (idx); assert (f);
2797 SvREFCNT_dec (f->meta_hv);
2798 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2799}
2800
2864SV *get_chksum (faceidx idx, int faceset = 0) 2801SV *get_chksum (faceidx idx, int faceset = 0)
2865 CODE: 2802 CODE:
2866 facedata *d = face_data (idx, faceset); 2803 facedata *d = face_data (idx, faceset);
2867 if (!d) XSRETURN_UNDEF; 2804 if (!d) XSRETURN_UNDEF;
2868 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2805 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2869 OUTPUT: 2806 OUTPUT:
2870 RETVAL 2807 RETVAL
2871 2808
2809int get_type (faceidx idx)
2810 CODE:
2811 faceinfo *f = face_info (idx);
2812 if (!f) XSRETURN_UNDEF;
2813 RETVAL = f->type;
2814 OUTPUT:
2815 RETVAL
2816
2872SV *get_data (faceidx idx, int faceset = 0) 2817SV *get_data (faceidx idx, int faceset = 0)
2873 CODE: 2818 CODE:
2874 facedata *d = face_data (idx, faceset); 2819 facedata *d = face_data (idx, faceset);
2875 if (!d) XSRETURN_UNDEF; 2820 if (!d) XSRETURN_UNDEF;
2876 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2821 RETVAL = newSVpvn (d->data, d->data.size ());
2877 OUTPUT: 2822 OUTPUT:
2878 RETVAL 2823 RETVAL
2879 2824
2825SV *get_meta (faceidx idx)
2826 CODE:
2827 faceinfo *f = face_info (idx); assert (f);
2828 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2829 RETVAL = newRV_inc ((SV *)f->meta_hv);
2830 OUTPUT:
2831 RETVAL
2832
2880void invalidate (faceidx idx) 2833void invalidate (faceidx idx)
2881 CODE: 2834 CODE:
2882 for_all_clients (ns) 2835 for_all_clients (ns)
2883 { 2836 ns->invalidate_face (idx);
2884 ns->faces_sent [idx] = false;
2885 ns->force_newmap = true;
2886 }
2887 2837
2888void invalidate_all () 2838void invalidate_all ()
2889 CODE: 2839 CODE:
2890 for_all_clients (ns) 2840 for_all_clients (ns)
2891 { 2841 ns->invalidate_all_faces ();
2892 ns->faces_sent.reset ();
2893 ns->force_newmap = true;
2894 }
2895 2842
2896MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2843MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2897 2844
2898#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2845#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2899 2846
2903 OUTPUT: RETVAL 2850 OUTPUT: RETVAL
2904 2851
2905animidx set (utf8_string name, SV *frames, int facings = 1) 2852animidx set (utf8_string name, SV *frames, int facings = 1)
2906 CODE: 2853 CODE:
2907{ 2854{
2908 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2855 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2909 croak ("frames must be an arrayref"); 2856 croak ("frames must be an arrayref");
2910 2857
2911 AV *av = (AV *)SvRV (frames); 2858 AV *av = (AV *)SvRV (frames);
2912 2859
2913 animation *anim = &animation::find (name); 2860 animation *anim = &animation::find (name);
2914 if (anim->number) 2861 if (anim->number)
2915 { 2862 {
2916 anim->resize (av_len (av) + 1); 2863 anim->resize (av_len (av) + 1);
2917 anim->facings = facings; 2864 anim->facings = facings;
2918 } 2865 }
2946 sv_to (sv, self); 2893 sv_to (sv, self);
2947 delete self; 2894 delete self;
2948 2895
2949MODULE = cf PACKAGE = cf::object::thawer 2896MODULE = cf PACKAGE = cf::object::thawer
2950 2897
2951INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2898INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2899
2900bool
2901errors_are_fatal (bool fatal)
2902 CODE:
2903 RETVAL = object_thawer::errors_are_fatal;
2904 object_thawer::errors_are_fatal = fatal;
2905 OUTPUT:
2906 RETVAL
2952 2907
2953SV * 2908SV *
2954new_from_file (char *klass, octet_string path) 2909new_from_file (char *klass, octet_string path)
2955 CODE: 2910 CODE:
2956 object_thawer *f = new object_thawer (path); 2911 object_thawer *f = new object_thawer (path);
2982 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2937 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2983 2938
2984 self->skip (); 2939 self->skip ();
2985 } 2940 }
2986 2941
2942MODULE = cf PACKAGE = cf::layout
2943
2944INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines