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.367 by root, Mon Apr 12 05:22:38 2010 UTC vs.
Revision 1.431 by root, Sat Dec 1 20:22:13 2018 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 (©) 2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2006,2007,2008,2009,2010,2012,2015 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 6 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 7 * 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 8 * 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 9 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 10 * option) any later version.
10 * 11 *
11 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the Affero GNU General Public License 17 * 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 18 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 19 * <http://www.gnu.org/licenses/>.
19 * 20 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 22 */
22 23
23#include "autoconf.h" 24#include "autoconf.h"
25
26#define CFPERL 1
24 27
25#if HAVE_EXECINFO_H 28#if HAVE_EXECINFO_H
26# include <execinfo.h> 29# include <execinfo.h>
27#endif 30#endif
28 31
29#include <cstdarg> 32#include <cstdarg>
30#include <typeinfo> 33#include <typeinfo>
31 34
32#include "global.h" 35#include "global.h"
33#include "../random_maps/random_map.h" 36#include "rmg.h"
37#include "noise.h"
34#include "evthread.h" 38#include "evthread.h"
35#include "sproto.h" 39#include "sproto.h"
36 40
37#include <unistd.h> 41#include <unistd.h>
38#if _POSIX_MEMLOCK 42#if _POSIX_MEMLOCK
52#include <XSUB.h> 56#include <XSUB.h>
53 57
54#include "CoroAPI.h" 58#include "CoroAPI.h"
55#include "perlxsi.c" 59#include "perlxsi.c"
56 60
57extern sint64 *levels; // the experience table
58
59typedef object_thawer &object_thawer_ref; 61typedef object_thawer &object_thawer_ref;
60typedef object_freezer &object_freezer_ref; 62typedef object_freezer &object_freezer_ref;
61 63
62typedef std::string std__string; 64typedef std::string std__string;
63 65
68static int tick_inhibit; 70static int tick_inhibit;
69static int tick_pending; 71static int tick_pending;
70 72
71global gbl_ev; 73global gbl_ev;
72static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 74static 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; 75static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick;
74static AV *av_reflect; 76static AV *av_reflect;
75 77
76bitset<NUM_EVENT_TYPES> ev_want_event; 78bitset<NUM_EVENT_TYPES> ev_want_event;
77bitset<NUM_TYPES> ev_want_type; 79bitset<NUM_TYPES> ev_want_type;
78 80
85 *stash_cf_mapspace_wrap, 87 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 88 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 89 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 90 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 91 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 92 *stash_cf_living_wrap,
93 *stash_cf_layout_wrap,
94 *stash_ext_map_world;
91 95
92static SV 96static SV
93 *cv_cf_do_invoke, 97 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 98 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 99 *cv_cf_client_send_msg,
100 *cv_cf_ix,
96 *cv_cf_tick, 101 *cv_cf_tick,
97 *cv_cf_match_match; 102 *cv_cf_match_match;
98 103
99#ifndef newSVpv_utf8 104#ifndef newSVpv_utf8
100static SV * 105static SV *
123 128
124 return sv; 129 return sv;
125} 130}
126#endif 131#endif
127 132
128static noinline utf8_string 133ecb_noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 134cfSvPVutf8_nolen (SV *sv)
130{ 135{
131 SvGETMAGIC (sv); 136 SvGETMAGIC (sv);
132 137
133 if (SvPOK (sv)) 138 if (SvPOK (sv))
252 { 257 {
253 static int last_mortalcount; 258 static int last_mortalcount;
254 if (mortals.size () != last_mortalcount) 259 if (mortals.size () != last_mortalcount)
255 { 260 {
256 last_mortalcount = mortals.size (); 261 last_mortalcount = mortals.size ();
257 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 262 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
263
264 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
265 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
258 266
259 if (0) 267 if (0)
260 { 268 {
261 for (int j = 0; j < mortals.size (); ++j)//D 269 for (int j = 0; j < mortals.size (); ++j)//D
262 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 270 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
353#endif 361#endif
354 362
355////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 363//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
356 364
357static SV * 365static SV *
358newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 366newSVptr (void *ptr, HV *stash, HV *hv)
359{ 367{
360 SV *sv;
361
362 if (!ptr) 368 if (!ptr)
363 return newSV (0); 369 return newSV (0);
364 370
365 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 371 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
366 return sv_bless (newRV_noinc ((SV *)hv), stash); 372 return sv_bless (newRV_noinc ((SV *)hv), stash);
373}
374
375ecb_noinline static SV *
376newSVptr (void *ptr, HV *stash)
377{
378 return newSVptr (ptr, stash, newHV ());
367} 379}
368 380
369static int 381static int
370attachable_free (pTHX_ SV *sv, MAGIC *mg) 382attachable_free (pTHX_ SV *sv, MAGIC *mg)
371{ 383{
383 return 0; 395 return 0;
384} 396}
385 397
386MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 398MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
387 399
388static SV * 400ecb_noinline static SV *
389newSVattachable (attachable *obj, HV *stash) 401newSVattachable (attachable *obj, HV *stash)
390{ 402{
391 if (!obj) 403 if (!obj)
392 return newSV (0); 404 return newSV (0);
393 405
447 croak ("object of type %s expected", klass); 459 croak ("object of type %s expected", klass);
448 460
449 return SvPTR_nc (sv); 461 return SvPTR_nc (sv);
450} 462}
451 463
452static long noinline 464ecb_noinline static long
453SvPTR_ornull (SV *sv, const char *klass) 465SvPTR_ornull (SV *sv, const char *klass)
454{ 466{
455 if (expect_false (!SvOK (sv))) return 0; 467 if (expect_false (!SvOK (sv))) return 0;
456 468
457 return SvPTR (sv, klass); 469 return SvPTR (sv, klass);
458} 470}
459 471
460static long noinline 472ecb_noinline static long
461SvPTR_ornull_client (SV *sv) 473SvPTR_ornull_client (SV *sv)
462{ 474{
463 if (expect_false (!SvOK (sv))) return 0; 475 if (expect_false (!SvOK (sv))) return 0;
464 476
465 if (!SvROK (sv) 477 if (!SvROK (sv)
468 croak ("object of type cf::client expected"); 480 croak ("object of type cf::client expected");
469 481
470 return SvPTR_nc (sv); 482 return SvPTR_nc (sv);
471} 483}
472 484
473static long noinline 485ecb_noinline static long
474SvPTR_ornull_object (SV *sv) 486SvPTR_ornull_object (SV *sv)
475{ 487{
476 if (expect_false (!SvOK (sv))) return 0; 488 if (expect_false (!SvOK (sv))) return 0;
477 489
478 if (!SvROK (sv) 490 if (!SvROK (sv)
483 croak ("object of type cf::object expected"); 495 croak ("object of type cf::object expected");
484 496
485 return SvPTR_nc (sv); 497 return SvPTR_nc (sv);
486} 498}
487 499
488static long noinline 500ecb_noinline static long
501SvPTR_ornull_maptile (SV *sv)
502{
503 if (expect_false (!SvOK (sv))) return 0;
504
505 if (!SvROK (sv)
506 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
507 && SvSTASH (SvRV (sv)) != stash_ext_map_world
508 && !sv_derived_from (sv, "cf::map")))
509 croak ("object of type cf::map expected");
510
511 return SvPTR_nc (sv);
512}
513
514ecb_noinline static long
489SvPTR_ornull_player (SV *sv) 515SvPTR_ornull_player (SV *sv)
490{ 516{
491 if (expect_false (!SvOK (sv))) return 0; 517 if (expect_false (!SvOK (sv))) return 0;
492 518
493 if (!SvROK (sv) 519 if (!SvROK (sv)
513static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 539static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
514static inline SV *to_sv (float v) { return newSVnv (v); } 540static inline SV *to_sv (float v) { return newSVnv (v); }
515static inline SV *to_sv (double v) { return newSVnv (v); } 541static inline SV *to_sv (double v) { return newSVnv (v); }
516static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 542static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
517static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 543static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
544// gcc dislikes noinline on to_sv
518static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 545ecb_noinline static SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
546static inline SV *to_sv (object * v) { return to_sv_ni (v); }
519static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 547static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
520static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 548static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
521static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 549static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
522static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 550static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
523static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 551static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
524static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 552static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
553static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
525 554
526static inline SV *to_sv (object & v) { return to_sv (&v); } 555static inline SV *to_sv (object & v) { return to_sv (&v); }
527static inline SV *to_sv (living & v) { return to_sv (&v); } 556static inline SV *to_sv (living & v) { return to_sv (&v); }
528 557
529static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 558static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
565static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 594static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
566static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 595static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
567static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 596static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
568static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 597static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
569static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 598static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
570static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 599static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
571static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 600static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
572static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 601static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
602static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
573static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 603static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
574static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
575static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 604static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
576static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 605static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
577static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 606static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
578static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 607static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
579static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 608static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
609static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
580static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 610static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
581static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 611static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
582 612
583//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 613//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
584static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 614static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
597static inline void sv_to (SV *sv, std::string &v) 627static inline void sv_to (SV *sv, std::string &v)
598{ 628{
599 STRLEN len; 629 STRLEN len;
600 char *data = SvPVbyte (sv, len); 630 char *data = SvPVbyte (sv, len);
601 v.assign (data, len); 631 v.assign (data, len);
632}
633
634static inline void sv_to (SV *sv, refcnt_buf &v)
635{
636 STRLEN len;
637 char *data = SvPVbyte (sv, len);
638 refcnt_buf buf (data, len);
639 v = buf;
602} 640}
603 641
604static inline void sv_to (SV *sv, UUID &v) 642static inline void sv_to (SV *sv, UUID &v)
605{ 643{
606 if (!v.parse (SvPV_nolen (sv))) 644 if (!v.parse (SvPV_nolen (sv)))
691 return sv; 729 return sv;
692} 730}
693 731
694// typemap support, mostly to avoid excessive inlining 732// typemap support, mostly to avoid excessive inlining
695template<class type> 733template<class type>
696static void noinline 734ecb_noinline static void
697cf_obj_to (SV *arg, type &var) 735cf_obj_to (SV *arg, type &var)
698{ 736{
699 sv_to (arg, var); 737 sv_to (arg, var);
700 if (!var) 738 if (expect_false (!var))
701 croak ("must not pass invalid/null cf_obj here"); 739 croak ("must not pass invalid/null cf_obj here");
702} 740}
703 741
704template<class object> 742template<class object>
705static void noinline 743ecb_noinline static void
706cf_obj_ornull_to (SV *arg, object *&var) 744cf_obj_ornull_to (SV *arg, object *&var)
707{ 745{
708 if (SvOK (arg)) 746 if (SvOK (arg))
709 { 747 {
710 sv_to (arg, var); 748 sv_to (arg, var);
711 if (!var) 749 if (expect_false (!var))
712 croak ("unable to convert perl object to C++ object"); 750 croak ("unable to convert perl object to C++ object");
713 } 751 }
714 else 752 else
715 var = 0; 753 var = 0;
716} 754}
751 exit (EXIT_FAILURE); 789 exit (EXIT_FAILURE);
752 } 790 }
753 791
754 eval_pv ( 792 eval_pv (
755 "#line 1 'cfperl init'\n" 793 "#line 1 'cfperl init'\n"
756 "use EV ();\n" 794 "use EV ();\n" // required by bootstrap
757 "use Coro ();\n" 795 "use Coro ();\n" // required by bootstrap
758 "cf->bootstrap;\n" 796 "cf->bootstrap;\n" // required for cf::datadir
759 "unshift @INC, cf::datadir ();\n" 797 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
760 "require cf;\n", 798 "require cf;\n",
761 0 799 0
762 ); 800 );
763 801
764 if (SvTRUE (ERRSV)) 802 if (SvTRUE (ERRSV))
802# undef def 840# undef def
803}; 841};
804 842
805#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) 843#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE)
806 844
807static void noinline 845ecb_noinline static void
808gather_callbacks (AV *&callbacks, AV *registry, event_type event) 846gather_callbacks (AV *&callbacks, AV *registry, event_type event)
809{ 847{
810 // event must be in array 848 // event must be in array
811 if (event >= 0 && event <= AvFILLp (registry)) 849 if (event >= 0 && event <= AvFILLp (registry))
812 { 850 {
898{ 936{
899 attachable::gather_callbacks (callbacks, event); 937 attachable::gather_callbacks (callbacks, event);
900 ::gather_callbacks (callbacks, cb_map, event); 938 ::gather_callbacks (callbacks, cb_map, event);
901} 939}
902 940
903static void noinline 941ecb_noinline static void
904_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) 942_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry)
905{ 943{
906 for (int event = 0; event <= AvFILLp (registry); ++event) 944 for (int event = 0; event <= AvFILLp (registry); ++event)
907 { 945 {
908 SV *cbs_ = AvARRAY (registry)[event]; 946 SV *cbs_ = AvARRAY (registry)[event];
1123 CALL_ARG (originator); 1161 CALL_ARG (originator);
1124 CALL_CALL ("cf::mapscript::activate", G_VOID); 1162 CALL_CALL ("cf::mapscript::activate", G_VOID);
1125 CALL_END; 1163 CALL_END;
1126} 1164}
1127 1165
1166void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1167{
1168 CALL_BEGIN (3);
1169 CALL_ARG (ns);
1170 CALL_ARG (set);
1171 CALL_ARG (idx);
1172 CALL_ARG (pri);
1173 CALL_CALL (cv_cf_ix, G_VOID);
1174 CALL_END;
1175}
1176
1128player * 1177player *
1129player::find (const_utf8_string name) 1178player::find (const_utf8_string name)
1130{ 1179{
1131 CALL_BEGIN (1); 1180 CALL_BEGIN (1);
1132 CALL_ARG (name); 1181 CALL_ARG (name);
1139 1188
1140 return retval; 1189 return retval;
1141} 1190}
1142 1191
1143maptile * 1192maptile *
1144find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1193find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1145{ 1194{
1146 CALL_BEGIN (3); 1195 CALL_BEGIN (4);
1147 CALL_ARG (dirname); 1196 CALL_ARG (dirname);
1148 CALL_ARG (stylename); 1197 CALL_ARG (stylename);
1149 CALL_ARG (difficulty); 1198 CALL_ARG (difficulty);
1199 CALL_ARG (recurse);
1150 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1200 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1151 1201
1152 maptile *retval = 0; 1202 maptile *retval = 0;
1153 if (count) sv_to (POPs, retval); 1203 if (count) sv_to (POPs, retval);
1154 1204
1225 CALL_ARG (y); 1275 CALL_ARG (y);
1226 CALL_CALL ("cf::object::player::goto", G_VOID); 1276 CALL_CALL ("cf::object::player::goto", G_VOID);
1227 CALL_END; 1277 CALL_END;
1228} 1278}
1229 1279
1230const_utf8_string 1280const_utf8_string
1231object::ref () const 1281object::ref () const
1232{ 1282{
1233 if (type == PLAYER) 1283 if (type == PLAYER)
1234 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1284 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1235 else 1285 else
1377 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1427 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1378 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1428 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1379 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1429 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1380 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1430 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1381 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1431 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1432 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1433 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1382 1434
1383 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1435 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1384 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1436 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1437 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1385 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1438 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1386 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1439 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1387 1440
1388 cb_global = get_av ("cf::CB_GLOBAL", 1); 1441 cb_global = get_av ("cf::CB_GLOBAL", 1);
1389 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1442 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1390 cb_object = get_av ("cf::CB_OBJECT", 1); 1443 cb_object = get_av ("cf::CB_OBJECT", 1);
1391 cb_player = get_av ("cf::CB_PLAYER", 1); 1444 cb_player = get_av ("cf::CB_PLAYER", 1);
1398_connect_to_perl_2 () 1451_connect_to_perl_2 ()
1399{ 1452{
1400 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1453 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1401 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1454 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1402 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1455 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1456 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1403 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1457 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1404 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1458 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1405} 1459}
1406 1460
1407MODULE = cf PACKAGE = cf PREFIX = cf_ 1461MODULE = cf PACKAGE = cf PREFIX = cf_
1412 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1466 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1413 1467
1414 _connect_to_perl_1 (); 1468 _connect_to_perl_1 ();
1415 1469
1416 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1470 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1417
1418 //{
1419 // require_pv ("Time::HiRes");
1420 //
1421 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1422 // if (!svp) croak ("Time::HiRes is required");
1423 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1424 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1425 //}
1426 1471
1427 static const struct { 1472 static const struct {
1428 const char *name; 1473 const char *name;
1429 IV iv; 1474 IV iv;
1430 } *civ, const_iv[] = { 1475 } *civ, const_iv[] = {
1434# include "attackinc.h" 1479# include "attackinc.h"
1435# undef def 1480# undef def
1436# define def(uc, flags) const_iv (SK_ ## uc) 1481# define def(uc, flags) const_iv (SK_ ## uc)
1437# include "skillinc.h" 1482# include "skillinc.h"
1438# undef def 1483# undef def
1439 1484# define def(name, use, nonuse) const_iv (body_ ## name)
1440 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1485# include "slotinc.h"
1441 const_iv (logBacktrace) 1486# undef def
1442
1443 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1444 1487
1445 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1488 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1446 1489
1447 const_iv (MAX_TIME) 1490 const_iv (MAX_TIME)
1448 const_iv (MAXSOCKBUF) 1491 const_iv (MAXSOCKBUF)
1462 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1505 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1463 1506
1464 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1507 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1465 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1508 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1466 1509
1467 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1468 const_iv (MAP_INACTIVE)
1469
1470 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1510 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1471 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1511 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1472 1512
1473 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1513 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1474 1514
1475 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1515 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1476 }; 1516 };
1477 1517
1478 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1518 for (civ = const_iv + ecb_array_length (const_iv); civ-- > const_iv; )
1479 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1519 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1480 1520
1481 static const struct { 1521 static const struct {
1482 const char *name; 1522 const char *name;
1483 int skip; 1523 int skip;
1489# undef def 1529# undef def
1490 }; 1530 };
1491 1531
1492 AV *av = get_av ("cf::EVENT", 1); 1532 AV *av = get_av ("cf::EVENT", 1);
1493 1533
1494 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1534 for (eiv = event_iv + ecb_array_length (event_iv); eiv-- > event_iv; )
1495 { 1535 {
1496 AV *event = newAV (); 1536 AV *event = newAV ();
1497 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1537 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1498 av_push (event, newSViv (eiv->klass)); 1538 av_push (event, newSViv (eiv->klass));
1499 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1539 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1506 1546
1507void _gv_clear (SV *gv) 1547void _gv_clear (SV *gv)
1508 CODE: 1548 CODE:
1509 assert (SvTYPE (gv) == SVt_PVGV); 1549 assert (SvTYPE (gv) == SVt_PVGV);
1510# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1550# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1551 SvREFCNT_inc (gv);
1511 f (GvGP (gv)->gp_form); 1552 f (GvGP (gv)->gp_form);
1512 f (GvGP (gv)->gp_io); 1553 f (GvGP (gv)->gp_io);
1513 f (GvGP (gv)->gp_sv); 1554 f (GvGP (gv)->gp_sv);
1514 f (GvGP (gv)->gp_av); 1555 f (GvGP (gv)->gp_av);
1515 f (GvGP (gv)->gp_hv); 1556 f (GvGP (gv)->gp_hv);
1516 f (GvGP (gv)->gp_cv); 1557 f (GvGP (gv)->gp_cv);
1517 GvCVGEN (gv) = 0; 1558 GvCVGEN (gv) = 0;
1518 GvMULTI_off (gv); 1559 GvMULTI_off (gv);
1560 SvREFCNT_dec (gv);
1519# undef f 1561# undef f
1520 1562
1521void _connect_to_perl_1 () 1563void _connect_to_perl_1 ()
1522 1564
1523void _connect_to_perl_2 () 1565void _connect_to_perl_2 ()
1534 1576
1535 for_all_objects (op) 1577 for_all_objects (op)
1536 op->reattach (); 1578 op->reattach ();
1537} 1579}
1538 1580
1539# support function for map-world.ext
1540void _quantise (SV *data_sv, SV *plt_sv)
1541 CODE:
1542{
1543 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1544 croak ("_quantise called with invalid agruments");
1545
1546 plt_sv = SvRV (plt_sv);
1547 SV **plt = AvARRAY (plt_sv);
1548 int plt_count = AvFILL (plt_sv) + 1;
1549
1550 STRLEN len;
1551 char *data = SvPVbyte (data_sv, len);
1552 char *dst = data;
1553
1554 while (len >= 3)
1555 {
1556 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1557 {
1558 char *val = SvPVX (*val_sv);
1559
1560 if (val [0] == data [0]
1561 && val [1] == data [1]
1562 && val [2] == data [2])
1563 {
1564 *dst++ = val [3];
1565 goto next;
1566 }
1567 }
1568
1569 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1570 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1571 dst - SvPVX (data_sv), len);
1572
1573 next:
1574 data += 3;
1575 len -= 3;
1576 }
1577
1578 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1579}
1580
1581void init_anim () 1581void init_anim ()
1582 1582
1583void init_globals () 1583void init_globals ()
1584 1584
1585void init_experience ()
1586
1587void init_attackmess () 1585void init_attackmess ()
1588 1586
1589void init_dynamic () 1587void init_dynamic ()
1590 1588
1591void load_settings () 1589void load_settings ()
1592 1590
1591void _reload_exp_table ()
1592
1593void load_materials () 1593void _reload_materials ()
1594 1594
1595void init_uuid () 1595void init_uuid ()
1596 CODE: 1596 CODE:
1597 UUID::init (); 1597 UUID::init ();
1598 1598
1609 coroapi::cede_to_tick (); 1609 coroapi::cede_to_tick ();
1610 1610
1611NV till_tick () 1611NV till_tick ()
1612 CODE: 1612 CODE:
1613 RETVAL = SvNVX (sv_next_tick) - now (); 1613 RETVAL = SvNVX (sv_next_tick) - now ();
1614 OUTPUT: 1614 OUTPUT: RETVAL
1615 RETVAL
1616 1615
1617int tick_inhibit () 1616int tick_inhibit ()
1618 CODE: 1617 CODE:
1619 RETVAL = tick_inhibit; 1618 RETVAL = tick_inhibit;
1620 OUTPUT: 1619 OUTPUT: RETVAL
1621 RETVAL
1622 1620
1623void tick_inhibit_inc () 1621void tick_inhibit_inc ()
1624 CODE: 1622 CODE:
1625 ++tick_inhibit; 1623 ++tick_inhibit;
1626 1624
1631 { 1629 {
1632 ev_async_send (EV_DEFAULT, &tick_watcher); 1630 ev_async_send (EV_DEFAULT, &tick_watcher);
1633 coroapi::cede (); 1631 coroapi::cede ();
1634 } 1632 }
1635 1633
1636void server_tick () 1634void one_tick ()
1637 CODE: 1635 CODE:
1638{ 1636{
1639 ev_now_update (EV_DEFAULT); 1637 ev_now_update (EV_DEFAULT);
1640 NOW = ev_now (EV_DEFAULT); 1638 NOW = ev_now (EV_DEFAULT);
1641 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1639 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1642 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1640 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1643 runtime = SvNVX (sv_runtime); 1641 runtime = SvNVX (sv_runtime);
1644 1642
1643 one_tick ();
1644
1645 server_tick (); 1645 ++server_tick;
1646 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1646 1647
1647 ev_now_update (EV_DEFAULT); 1648 ev_now_update (EV_DEFAULT);
1648 NOW = ev_now (EV_DEFAULT); 1649 NOW = ev_now (EV_DEFAULT);
1649 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1650 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1651
1650 runtime += TICK; 1652 runtime += TICK;
1651 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1653 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1652} 1654}
1653 1655
1654NV floor (NV x) 1656NV floor (NV x)
1658NV rndm (...) 1660NV rndm (...)
1659 ALIAS: 1661 ALIAS:
1660 rmg_rndm = 1 1662 rmg_rndm = 1
1661 CODE: 1663 CODE:
1662{ 1664{
1663 rand_gen &gen = ix ? rmg_rndm : rndm; 1665 rand_gen &gen = ix ? rmg_rndm : rndm;
1664 switch (items) 1666 switch (items)
1665 { 1667 {
1666 case 0: RETVAL = gen (); break; 1668 case 0: RETVAL = gen (); break;
1667 case 1: RETVAL = gen (SvUV (ST (0))); break; 1669 case 1: RETVAL = gen (SvUV (ST (0))); break;
1668 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1670 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1669 default: croak ("cf::rndm requires none, one or two parameters."); break; 1671 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1670 } 1672 }
1671} 1673}
1672 OUTPUT: 1674 OUTPUT: RETVAL
1673 RETVAL
1674 1675
1675NV clamp (NV value, NV min_value, NV max_value) 1676NV clamp (NV value, NV min_value, NV max_value)
1676 CODE: 1677 CODE:
1677 RETVAL = clamp (value, min_value, max_value); 1678 RETVAL = clamp (value, min_value, max_value);
1678 OUTPUT: 1679 OUTPUT: RETVAL
1679 RETVAL
1680 1680
1681NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) 1681NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1682 CODE: 1682 CODE:
1683 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1683 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1684 OUTPUT: 1684 OUTPUT: RETVAL
1685 RETVAL
1686 1685
1687const char *ordinal (int i) 1686const char *ordinal (int i)
1688 1687
1689void weaken (...) 1688void weaken (...)
1690 PROTOTYPE: @ 1689 PROTOTYPE: @
1753 1752
1754int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1753int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1755 INIT: 1754 INIT:
1756#if __GLIBC__ 1755#if __GLIBC__
1757 mallopt (M_TOP_PAD, 1024 * 1024); 1756 mallopt (M_TOP_PAD, 1024 * 1024);
1758 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1757 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1759 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1758 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1759 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1760 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1760 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1761#endif 1761#endif
1762 1762
1763int munlockall () 1763int munlockall ()
1764 1764
1765#endif 1765#endif
1788 EXTEND (SP, 5*2); 1788 EXTEND (SP, 5*2);
1789 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); 1789 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1790 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); 1790 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1791 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1791 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1792 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1792 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1793 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1794} 1793}
1795
1796int find_animation (utf8_string text)
1797 PROTOTYPE: $
1798 1794
1799int random_roll (int min, int max, object *op, int goodbad); 1795int random_roll (int min, int max, object *op, int goodbad);
1800 1796
1801const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1797const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1802 1798
1799int exp_to_level (val64 exp)
1800
1801val64 level_to_min_exp (int level)
1802
1803const_utf8_string
1804spellpathnames (int idx)
1805 CODE:
1806 RETVAL = spellpathnames [idx];
1807 OUTPUT: RETVAL
1808
1809SV *
1810attacktype_name (int atnr)
1811 CODE:
1812 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1813 ? newSVpv (attacktype_name [atnr], 0)
1814 : &PL_sv_undef;
1815 OUTPUT: RETVAL
1816
1817SV *
1818attacktype_desc (int atnr)
1819 CODE:
1820 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1821 ? newSVpv (attacktype_desc [atnr], 0)
1822 : &PL_sv_undef;
1823 OUTPUT: RETVAL
1824
1825SV *
1826resist_plus (int atnr)
1827 CODE:
1828 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 ? newSVpv (resist_plus [atnr], 0)
1830 : &PL_sv_undef;
1831 OUTPUT: RETVAL
1832
1833SV *
1834change_resist_msg (int atnr)
1835 CODE:
1836 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1837 ? newSVpv (change_resist_msg [atnr], 0)
1838 : &PL_sv_undef;
1839 OUTPUT: RETVAL
1840
1803int 1841int
1804exp_to_level (val64 exp) 1842skill_flags (int idx)
1805 CODE: 1843 CODE:
1806{ 1844 if (idx < 0 || idx >= ecb_array_length (skill_flags))
1807 int i = 0; 1845 croak ("skill_flags: index out of bounds");
1808 1846 RETVAL = skill_flags [idx];
1809 RETVAL = settings.max_level;
1810
1811 for (i = 1; i <= settings.max_level; i++)
1812 {
1813 if (levels[i] > exp)
1814 {
1815 RETVAL = i - 1;
1816 break;
1817 }
1818 }
1819}
1820 OUTPUT: RETVAL
1821
1822val64
1823level_to_min_exp (int level)
1824 CODE:
1825 if (level > settings.max_level)
1826 RETVAL = levels[settings.max_level];
1827 else if (level < 1)
1828 RETVAL = 0;
1829 else
1830 RETVAL = levels[level];
1831 OUTPUT: RETVAL 1847 OUTPUT: RETVAL
1832
1833SV *
1834resistance_to_string (int atnr)
1835 CODE:
1836 if (atnr >= 0 && atnr < NROFATTACKS)
1837 RETVAL = newSVpv (resist_plus[atnr], 0);
1838 else
1839 XSRETURN_UNDEF;
1840 OUTPUT: RETVAL
1841 1848
1842UUID 1849UUID
1843uuid_cur () 1850uuid_cur ()
1844 CODE: 1851 CODE:
1845 RETVAL = UUID::cur; 1852 RETVAL = UUID::cur;
1846 OUTPUT: 1853 OUTPUT: RETVAL
1847 RETVAL
1848 1854
1849UUID 1855UUID
1850uuid_gen () 1856uuid_gen ()
1851 CODE: 1857 CODE:
1852 RETVAL = UUID::gen (); 1858 RETVAL = UUID::gen ();
1853 OUTPUT: 1859 OUTPUT: RETVAL
1854 RETVAL
1855 1860
1856val64 1861val64
1857uuid_seq (UUID uuid) 1862uuid_seq (UUID uuid)
1858 CODE: 1863 CODE:
1859 RETVAL = uuid.seq; 1864 RETVAL = uuid.seq;
1860 OUTPUT: 1865 OUTPUT: RETVAL
1861 RETVAL
1862 1866
1863UUID 1867UUID
1864uuid_str (val64 seq) 1868uuid_str (val64 seq)
1865 CODE: 1869 CODE:
1866 RETVAL.seq = seq; 1870 RETVAL.seq = seq;
1867 OUTPUT: 1871 OUTPUT: RETVAL
1868 RETVAL
1869 1872
1870void 1873void
1871coin_names () 1874coin_names ()
1872 PPCODE: 1875 PPCODE:
1873 EXTEND (SP, NUM_COINS); 1876 EXTEND (SP, NUM_COINS);
1885load_resource_file_ (octet_string filename) 1888load_resource_file_ (octet_string filename)
1886 1889
1887void 1890void
1888fix_weight () 1891fix_weight ()
1889 1892
1893utf8_string
1894expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1895 PPCODE:
1896 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1897
1890MODULE = cf PACKAGE = cf::attachable 1898MODULE = cf PACKAGE = cf::attachable
1891 1899
1892int 1900int
1893valid (SV *obj) 1901valid (SV *obj)
1894 CODE: 1902 CODE:
1895 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1903 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1896 OUTPUT: 1904 OUTPUT: RETVAL
1897 RETVAL 1905
1906bool should_invoke (attachable *obj, int event)
1907 CODE:
1908 RETVAL = obj->should_invoke ((event_type)event);
1909 OUTPUT: RETVAL
1898 1910
1899void 1911void
1900debug_trace (attachable *obj, bool on = true) 1912debug_trace (attachable *obj, bool on = true)
1901 CODE: 1913 CODE:
1902 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1914 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1962int mortals_size () 1974int mortals_size ()
1963 CODE: 1975 CODE:
1964 RETVAL = attachable::mortals.size (); 1976 RETVAL = attachable::mortals.size ();
1965 OUTPUT: RETVAL 1977 OUTPUT: RETVAL
1966 1978
1967const_utf8_string slot_use_name (U32 slot) 1979const_utf8_string slot_name (U32 slot)
1968 ALIAS: 1980 ALIAS:
1981 slot_name = 0
1982 slot_use_name = 1
1969 slot_nonuse_name = 1 1983 slot_nonuse_name = 2
1970 CODE: 1984 CODE:
1971{ 1985{
1972 if (slot >= NUM_BODY_LOCATIONS) 1986 if (slot >= NUM_BODY_LOCATIONS)
1973 croak ("body slot index out of range"); 1987 croak ("body slot index out of range");
1974 1988
1975 switch (ix) 1989 switch (ix)
1976 { 1990 {
1991 case 0: RETVAL = body_locations[slot].name ; break;
1977 case 0: RETVAL = body_locations[slot].use_name; break; 1992 case 1: RETVAL = body_locations[slot].use_name ; break;
1978 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1993 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1979 } 1994 }
1980} 1995}
1981 OUTPUT: 1996 OUTPUT: RETVAL
1982 RETVAL
1983 1997
1984# missing properties 1998# missing properties
1985 1999
1986object *head (object *op) 2000object *head (object *op)
1987 PROTOTYPE: $ 2001 PROTOTYPE: $
1995 PPCODE: 2009 PPCODE:
1996{ 2010{
1997 for (object *o = obj->inv; o; o = o->below) 2011 for (object *o = obj->inv; o; o = o->below)
1998 XPUSHs (sv_2mortal (to_sv (o))); 2012 XPUSHs (sv_2mortal (to_sv (o)));
1999} 2013}
2000
2001void
2002set_animation (object *op, int idx)
2003 CODE:
2004 SET_ANIMATION (op, idx);
2005
2006int
2007num_animations (object *op)
2008 CODE:
2009 RETVAL = NUM_ANIMATIONS (op);
2010 OUTPUT: RETVAL
2011 2014
2012int slot_info (object *op, UV slot, int value = 0) 2015int slot_info (object *op, UV slot, int value = 0)
2013 ALIAS: 2016 ALIAS:
2014 slot_used = 1 2017 slot_used = 1
2015 CODE: 2018 CODE:
2023 if (ix) 2026 if (ix)
2024 op->slot[slot].used = value; 2027 op->slot[slot].used = value;
2025 else 2028 else
2026 op->slot[slot].info = value; 2029 op->slot[slot].info = value;
2027} 2030}
2028 OUTPUT: 2031 OUTPUT: RETVAL
2029 RETVAL
2030 2032
2031object *find_best_object_match (object *op, utf8_string match) 2033object *find_best_object_match (object *op, utf8_string match)
2032 2034
2033object *find_marked_object (object *op)
2034
2035int need_identify (object *obj);
2036
2037int apply_shop_mat (object *shop_mat, object *op); 2035int apply_shop_mat (object *shop_mat, object *op);
2038 2036
2039int move (object *op, int dir, object *originator = op) 2037int move (object *op, int dir, object *originator = op)
2040 CODE: 2038 CODE:
2041 RETVAL = op->move (dir, originator); 2039 RETVAL = op->move (dir, originator);
2042 OUTPUT: 2040 OUTPUT: RETVAL
2043 RETVAL
2044 2041
2045void apply_below (object *op) 2042void apply_below (object *op)
2046 CODE: 2043 CODE:
2047 player_apply_below (op); 2044 player_apply_below (op);
2048 2045
2093 2090
2094void pick_up (object *who, object *op) 2091void pick_up (object *who, object *op)
2095 2092
2096void update_object (object *op, int action) 2093void update_object (object *op, int action)
2097 2094
2098void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2095void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2099 2096
2100void player_lvl_adj (object *who, object *skill = 0) 2097void player_lvl_adj (object *who, object *skill = 0)
2101 2098
2102int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2099int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2103 2100
2112int convert_item (object *item, object *converter) 2109int convert_item (object *item, object *converter)
2113 2110
2114void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2111void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2115 2112
2116MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2113MODULE = cf PACKAGE = cf::object PREFIX = cf_
2117
2118# no clean way to get an object from an archetype - stupid idiotic
2119# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2120 2114
2121object *new (utf8_string archetype = 0) 2115object *new (utf8_string archetype = 0)
2122 PROTOTYPE: ;$ 2116 PROTOTYPE: ;$
2123 CODE: 2117 CODE:
2124 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2118 RETVAL = archetype
2119 ? archetype::get (archetype)
2120 : object::create ();
2125 OUTPUT: 2121 OUTPUT: RETVAL
2126 RETVAL
2127 2122
2128object *generate (utf8_string arch, object *creator) 2123object *generate (utf8_string arch, object *creator)
2129 CODE: 2124 CODE:
2130 object *obj = get_archetype (arch); 2125 object *obj = archetype::get (arch);
2131 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2126 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2132 RETVAL = obj; 2127 RETVAL = obj;
2133 OUTPUT: 2128 OUTPUT: RETVAL
2134 RETVAL
2135 2129
2136object *find_object (U32 tag) 2130object *find_object (U32 tag)
2137 2131
2138object *find_object_uuid (UUID i) 2132object *find_object_uuid (UUID i)
2139 2133
2145 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2139 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2146 2140
2147 if (RETVAL->destroyed ()) 2141 if (RETVAL->destroyed ())
2148 RETVAL = 0; 2142 RETVAL = 0;
2149} 2143}
2144 OUTPUT: RETVAL
2150 2145
2151shstr 2146shstr
2152object::kv_get (shstr key) 2147object::kv_get (shstr key)
2148 CODE:
2149 RETVAL = THIS->kv.get (key);
2150 OUTPUT: RETVAL
2153 2151
2154void 2152void
2155object::kv_del (shstr key) 2153object::kv_del (shstr key)
2154 CODE:
2155 THIS->kv.del (key);
2156 2156
2157void 2157void
2158object::kv_set (shstr key, shstr value) 2158object::kv_set (shstr key, shstr value)
2159 CODE:
2160 THIS->kv.set (key, value);
2159 2161
2160object *get_nearest_player (object *ob) 2162object *get_nearest_player (object *ob)
2161 ALIAS: nearest_player = 0 2163 ALIAS: nearest_player = 0
2162 PREINIT: 2164 PREINIT:
2163 extern object *get_nearest_player (object *); 2165 extern object *get_nearest_player (object *);
2252#d# TODO: replace by blocked_los accessor, fix code using this 2254#d# TODO: replace by blocked_los accessor, fix code using this
2253bool 2255bool
2254cell_visible (player *pl, int dx, int dy) 2256cell_visible (player *pl, int dx, int dy)
2255 CODE: 2257 CODE:
2256 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; 2258 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED;
2257 OUTPUT: 2259 OUTPUT: RETVAL
2258 RETVAL
2259 2260
2260void 2261void
2261send (player *pl, SV *packet) 2262send (player *pl, SV *packet)
2262 CODE: 2263 CODE:
2263{ 2264{
2339outdoor_darkness (int darkness = 0) 2340outdoor_darkness (int darkness = 0)
2340 CODE: 2341 CODE:
2341 RETVAL = maptile::outdoor_darkness; 2342 RETVAL = maptile::outdoor_darkness;
2342 if (items) 2343 if (items)
2343 maptile::outdoor_darkness = darkness; 2344 maptile::outdoor_darkness = darkness;
2344 OUTPUT: 2345 OUTPUT: RETVAL
2345 RETVAL
2346 2346
2347void 2347void
2348maptile::instantiate () 2348maptile::instantiate ()
2349 2349
2350maptile *new () 2350maptile *new ()
2351 PROTOTYPE: 2351 PROTOTYPE:
2352 CODE: 2352 CODE:
2353 RETVAL = new maptile; 2353 RETVAL = new maptile;
2354 OUTPUT: 2354 OUTPUT: RETVAL
2355 RETVAL
2356 2355
2357void 2356void
2358maptile::players () 2357maptile::players ()
2359 PPCODE: 2358 PPCODE:
2360 if (GIMME_V == G_SCALAR) 2359 if (GIMME_V == G_SCALAR)
2366 if (pl->ob && pl->ob->map == THIS) 2365 if (pl->ob && pl->ob->map == THIS)
2367 PUSHs (sv_2mortal (to_sv (pl->ob))); 2366 PUSHs (sv_2mortal (to_sv (pl->ob)));
2368 } 2367 }
2369 2368
2370void 2369void
2370maptile::gen_quadmap (int x, int y, int z)
2371 CODE:
2372 gen_quadmap (THIS, x * 50, y * 50, z);
2373
2374void
2371maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2375maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2372 CODE: 2376 CODE:
2373{ 2377{
2374 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2378 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2375 croak ("maptile::add_underlay: palette must be arrayref"); 2379 croak ("maptile::add_underlay: palette must be arrayref");
2376 2380
2377 palette = SvRV (palette); 2381 palette = SvRV (palette);
2378 2382
2379 STRLEN idxlen; 2383 STRLEN idxlen;
2380 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2384 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2381 2385
2382 for (int x = 0; x < THIS->width; ++x) 2386 for (int x = 0; x < THIS->width; ++x)
2383 for (int y = 0; y < THIS->height; ++y) 2387 for (int y = 0; y < THIS->height; ++y)
2384 { 2388 {
2385 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2389 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2391 2395
2392 if (IN_RANGE_EXC (offs, 0, idxlen)) 2396 if (IN_RANGE_EXC (offs, 0, idxlen))
2393 { 2397 {
2394 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2398 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2395 { 2399 {
2396 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2400 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2397 ob->flag [FLAG_NO_MAP_SAVE] = true; 2401 ob->flag [FLAG_NO_MAP_SAVE] = true;
2398 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2402 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2399 2403
2400 if (ob->randomitems && !ob->above) 2404 if (ob->randomitems && !ob->above)
2401 { 2405 {
2405 op->flag [FLAG_NO_MAP_SAVE] = true; 2409 op->flag [FLAG_NO_MAP_SAVE] = true;
2406 // TODO: if this is a pickable object, then the item 2410 // TODO: if this is a pickable object, then the item
2407 // will at a bit weird - saving inside the player 2411 // will at a bit weird - saving inside the player
2408 // will clear the flag, but when the player drops 2412 // will clear the flag, but when the player drops
2409 // it without logging out, it keeps the flag. 2413 // it without logging out, it keeps the flag.
2410 // nobody ahs reported this, but this can be rather 2414 // nobody has reported this, but this can be rather
2411 // annoying on persistent maps. 2415 // annoying on persistent maps.
2412 } 2416 }
2413 } 2417 }
2414 } 2418 }
2415 } 2419 }
2416
2417 skip: ; 2420 skip: ;
2418 } 2421 }
2419} 2422}
2420 2423
2421void 2424void
2426 croak ("maptile::set_regiondata: palette must be arrayref"); 2429 croak ("maptile::set_regiondata: palette must be arrayref");
2427 2430
2428 palette = SvRV (palette); 2431 palette = SvRV (palette);
2429 2432
2430 STRLEN idxlen; 2433 STRLEN idxlen;
2431 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2434 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2432 2435
2433 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2436 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2434 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2437 uint8 *regions = salloc<uint8_t> (THIS->size ());
2435 2438
2436 for (int i = av_len ((AV *)palette) + 1; i--; ) 2439 for (int i = av_len ((AV *)palette) + 1; i--; )
2437 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2440 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2438 2441
2439 for (int y = 0; y < THIS->height; ++y) 2442 for (int y = 0; y < THIS->height; ++y)
2452 for (int x = 0; x < THIS->width; ++x) 2455 for (int x = 0; x < THIS->width; ++x)
2453 for (int y = 0; y < THIS->height; ++y) 2456 for (int y = 0; y < THIS->height; ++y)
2454 { 2457 {
2455 region *rgn = THIS->region (x, y); 2458 region *rgn = THIS->region (x, y);
2456 2459
2457 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2458 if (object *op = THIS->at (x, y).top) 2460 if (object *op = THIS->at (x, y).top)
2459 if (rgn->treasure && rndm () < rgn->treasure_density) 2461 if (rgn->treasure && rndm () < rgn->treasure_density)
2460 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2462 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2461 } 2463 }
2462 2464
2468 if (oblinkpt *obp = map->find_link (connection)) 2470 if (oblinkpt *obp = map->find_link (connection))
2469 for (objectlink *ol = obp->link; ol; ol = ol->next) 2471 for (objectlink *ol = obp->link; ol; ol = ol->next)
2470 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2472 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2471 2473
2472void 2474void
2473get_map_flags (maptile *map, int x, int y) 2475xy_normalise (maptile *map, int x, int y, int dir = 0)
2474 PPCODE: 2476 PPCODE:
2475{ 2477{
2476 maptile *nmap = 0; 2478 mapxy pos (map, x, y);
2477 I16 nx = 0, ny = 0; 2479 if (!pos.move (dir).normalise ())
2480 XSRETURN_EMPTY;
2478 2481
2479 PUTBACK;
2480 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2481 SPAGAIN;
2482
2483 EXTEND (SP, 4); 2482 EXTEND (SP, 3);
2484 PUSHs (sv_2mortal (newSViv (flags)));
2485
2486 if (GIMME_V == G_ARRAY)
2487 {
2488 PUSHs (sv_2mortal (to_sv (nmap))); 2483 PUSHs (sv_2mortal (to_sv (pos.m)));
2489 PUSHs (sv_2mortal (newSViv (nx))); 2484 PUSHs (sv_2mortal (to_sv (pos.x)));
2490 PUSHs (sv_2mortal (newSViv (ny))); 2485 PUSHs (sv_2mortal (to_sv (pos.y)));
2491 }
2492} 2486}
2493 2487
2494mapspace * 2488mapspace *
2495ms (maptile *map, unsigned int x, unsigned int y) 2489ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2496 PROTOTYPE: $$$ 2490 PROTOTYPE: $$$;$
2497 CODE: 2491 CODE:
2498{ 2492{
2499 maptile *nmap = 0; 2493 mapxy pos (map, x, y);
2500 I16 nx, ny; 2494 if (!pos.move (dir).normalise ())
2501
2502 PUTBACK;
2503 get_map_flags (map, &nmap, x, y, &nx, &ny);
2504 SPAGAIN;
2505
2506 if (!nmap)
2507 XSRETURN_UNDEF; 2495 XSRETURN_UNDEF;
2508 2496
2509 RETVAL = &nmap->at (nx, ny);
2510}
2511 OUTPUT:
2512 RETVAL 2497 RETVAL = &*pos;
2498}
2499 OUTPUT: RETVAL
2513 2500
2514void 2501void
2515at (maptile *map, unsigned int x, unsigned int y) 2502at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2516 PROTOTYPE: $$$ 2503 PROTOTYPE: $$$;$
2517 PPCODE: 2504 PPCODE:
2518{ 2505 mapxy pos (map, x, y);
2519 maptile *nmap = 0; 2506 if (pos.move (dir).normalise ())
2520 I16 nx, ny;
2521
2522 PUTBACK;
2523 get_map_flags (map, &nmap, x, y, &nx, &ny);
2524 SPAGAIN;
2525
2526 if (nmap)
2527 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2507 for (object *o = pos->bot; o; o = o->above)
2528 XPUSHs (sv_2mortal (to_sv (o))); 2508 XPUSHs (sv_2mortal (to_sv (o)));
2529}
2530 2509
2531SV * 2510SV *
2532bot_at (maptile *map, unsigned int x, unsigned int y) 2511bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2533 PROTOTYPE: $$$ 2512 PROTOTYPE: $$$;$
2534 ALIAS: 2513 ALIAS:
2535 top_at = 1 2514 top_at = 1
2536 flags_at = 2 2515 flags_at = 2
2537 light_at = 3 2516 light_at = 3
2538 move_block_at = 4 2517 move_block_at = 4
2539 move_slow_at = 5 2518 move_slow_at = 5
2540 move_on_at = 6 2519 move_on_at = 6
2541 move_off_at = 7 2520 move_off_at = 7
2542 CODE: 2521 CODE:
2543{ 2522{
2544 sint16 nx = x; 2523 mapxy pos (map, x, y);
2545 sint16 ny = y; 2524 if (!pos.move (dir).normalise ())
2546
2547 if (!xy_normalise (map, nx, ny))
2548 XSRETURN_UNDEF; 2525 XSRETURN_UNDEF;
2549 2526
2550 mapspace &ms = map->at (nx, ny); 2527 mapspace &ms = *pos;
2551 2528
2552 ms.update (); 2529 ms.update ();
2553 2530
2554 switch (ix) 2531 switch (ix)
2555 { 2532 {
2565} 2542}
2566 OUTPUT: RETVAL 2543 OUTPUT: RETVAL
2567 2544
2568# worst xs function of my life 2545# worst xs function of my life
2569bool 2546bool
2570_create_random_map (\ 2547_create_random_map (maptile *self, SV *options)
2571 maptile *self,\
2572 utf8_string wallstyle,\
2573 utf8_string wall_name,\
2574 utf8_string floorstyle,\
2575 utf8_string monsterstyle,\
2576 utf8_string treasurestyle,\
2577 utf8_string layoutstyle,\
2578 utf8_string doorstyle,\
2579 utf8_string decorstyle,\
2580 utf8_string miningstyle,\
2581 utf8_string origin_map,\
2582 utf8_string final_map,\
2583 utf8_string exitstyle,\
2584 utf8_string this_map,\
2585 utf8_string exit_on_final_map,\
2586 int xsize,\
2587 int ysize,\
2588 int expand2x,\
2589 int layoutoptions1,\
2590 int layoutoptions2,\
2591 int layoutoptions3,\
2592 int symmetry,\
2593 int difficulty,\
2594 int difficulty_given,\
2595 float difficulty_increase,\
2596 int dungeon_level,\
2597 int dungeon_depth,\
2598 int decoroptions,\
2599 int orientation,\
2600 int origin_y,\
2601 int origin_x,\
2602 U32 random_seed,\
2603 val64 total_map_hp,\
2604 int map_layout_style,\
2605 int treasureoptions,\
2606 int symmetry_used,\
2607 region *region,\
2608 utf8_string custom\
2609)
2610 CODE: 2548 CODE:
2611{ 2549{
2612 random_map_params rmp; 2550 random_map_params rmp ((HV *)SvRV (options));
2613
2614 assign (rmp.wallstyle , wallstyle);
2615 assign (rmp.wall_name , wall_name);
2616 assign (rmp.floorstyle , floorstyle);
2617 assign (rmp.monsterstyle , monsterstyle);
2618 assign (rmp.treasurestyle , treasurestyle);
2619 assign (rmp.layoutstyle , layoutstyle);
2620 assign (rmp.doorstyle , doorstyle);
2621 assign (rmp.decorstyle , decorstyle);
2622 assign (rmp.miningstyle , miningstyle);
2623 assign (rmp.exitstyle , exitstyle);
2624 assign (rmp.exit_on_final_map, exit_on_final_map);
2625
2626 rmp.origin_map = origin_map;
2627 rmp.final_map = final_map;
2628 rmp.this_map = this_map;
2629 rmp.xsize = xsize;
2630 rmp.ysize = ysize;
2631 rmp.expand2x = expand2x;
2632 rmp.layoutoptions1 = layoutoptions1;
2633 rmp.layoutoptions2 = layoutoptions2;
2634 rmp.layoutoptions3 = layoutoptions3;
2635 rmp.symmetry = symmetry;
2636 rmp.difficulty = difficulty;
2637 rmp.difficulty_given = difficulty_given;
2638 rmp.difficulty_increase = difficulty_increase;
2639 rmp.dungeon_level = dungeon_level;
2640 rmp.dungeon_depth = dungeon_depth;
2641 rmp.decoroptions = decoroptions;
2642 rmp.orientation = orientation;
2643 rmp.origin_y = origin_y;
2644 rmp.origin_x = origin_x;
2645 rmp.random_seed = random_seed;
2646 rmp.total_map_hp = (uint64_t) total_map_hp;
2647 rmp.map_layout_style = map_layout_style;
2648 rmp.treasureoptions = treasureoptions;
2649 rmp.symmetry_used = symmetry_used;
2650 rmp.region = region;
2651 rmp.custom = custom;
2652
2653 RETVAL = self->generate_random_map (&rmp); 2551 RETVAL = self->generate_random_map (&rmp);
2654} 2552}
2655 OUTPUT: 2553 OUTPUT: RETVAL
2656 RETVAL
2657 2554
2658MODULE = cf PACKAGE = cf::mapspace 2555MODULE = cf PACKAGE = cf::mapspace
2659 2556
2660INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | 2557INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h |
2661 2558
2668 2565
2669archetype *archetypes (U32 index) 2566archetype *archetypes (U32 index)
2670 CODE: 2567 CODE:
2671 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2568 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2672 OUTPUT: RETVAL 2569 OUTPUT: RETVAL
2570
2571int skillvec_size ()
2572 CODE:
2573 RETVAL = skillvec.size ();
2574 OUTPUT: RETVAL
2575
2576archetype *skillvec (U32 index)
2577 CODE:
2578 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2579 OUTPUT: RETVAL
2580
2581void
2582find_by_type (int type)
2583 PPCODE:
2584 for_all_archetypes (arch)
2585 if (arch->type == type)
2586 XPUSHs (sv_2mortal (to_sv (arch)));
2673 2587
2674INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2588INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2675 2589
2676MODULE = cf PACKAGE = cf::party 2590MODULE = cf PACKAGE = cf::party
2677 2591
2689list () 2603list ()
2690 PPCODE: 2604 PPCODE:
2691 for_all_regions (rgn) 2605 for_all_regions (rgn)
2692 XPUSHs (sv_2mortal (to_sv (rgn))); 2606 XPUSHs (sv_2mortal (to_sv (rgn)));
2693 2607
2694region *find (utf8_string name)
2695 PROTOTYPE: $
2696 CODE:
2697 RETVAL = region::find (name);
2698 OUTPUT: RETVAL
2699
2700int specificity (region *rgn) 2608int specificity (region *rgn)
2701 CODE: 2609 CODE:
2702 RETVAL = 0; 2610 RETVAL = 0;
2703 while (rgn = rgn->parent) 2611 while (rgn = rgn->parent)
2704 RETVAL++; 2612 RETVAL++;
2732list () 2640list ()
2733 PPCODE: 2641 PPCODE:
2734 EXTEND (SP, clients.size ()); 2642 EXTEND (SP, clients.size ());
2735 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2643 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2736 PUSHs (sv_2mortal (to_sv (*i))); 2644 PUSHs (sv_2mortal (to_sv (*i)));
2645
2646STRLEN
2647client::inbuf_append (SV *data)
2648 CODE:
2649{
2650 STRLEN len;
2651 char *ptr = SvPVbyte (data, len);
2652
2653 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2654 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2655 THIS->inbuf_len += len;
2656
2657 THIS->inbuf_handle ();
2658
2659 RETVAL = len;
2660}
2661 OUTPUT: RETVAL
2737 2662
2738void 2663void
2739client::send_packet (SV *packet) 2664client::send_packet (SV *packet)
2740 CODE: 2665 CODE:
2741{ 2666{
2759 if (RETVAL) 2684 if (RETVAL)
2760 { 2685 {
2761 THIS->send_face (RETVAL, pri); 2686 THIS->send_face (RETVAL, pri);
2762 THIS->flush_fx (); 2687 THIS->flush_fx ();
2763 } 2688 }
2764 OUTPUT: 2689 OUTPUT: RETVAL
2765 RETVAL
2766 2690
2767int 2691int
2768client::fx_want (int idx, int value = -1) 2692client::fx_want (int idx, int value = -1)
2769 CODE: 2693 CODE:
2770 if (0 < idx && idx < FT_NUM) 2694 if (0 < idx && idx < FT_NUM)
2773 if (items > 2) 2697 if (items > 2)
2774 THIS->fx_want [idx] = value; 2698 THIS->fx_want [idx] = value;
2775 } 2699 }
2776 else 2700 else
2777 RETVAL = 0; 2701 RETVAL = 0;
2778 OUTPUT: 2702 OUTPUT: RETVAL
2779 RETVAL
2780 2703
2781MODULE = cf PACKAGE = cf::sound PREFIX = sound_ 2704MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2782 2705
2783faceidx sound_find (utf8_string name) 2706faceidx sound_find (utf8_string name)
2784 2707
2797faceidx face_find (utf8_string name, faceidx defidx = 0) 2720faceidx face_find (utf8_string name, faceidx defidx = 0)
2798 2721
2799faceidx alloc (utf8_string name) 2722faceidx alloc (utf8_string name)
2800 CODE: 2723 CODE:
2801{ 2724{
2802 do 2725 RETVAL = face_alloc ();
2803 {
2804 RETVAL = faces.size ();
2805 faces.resize (RETVAL + 1);
2806 }
2807 while (!RETVAL); // crude way to leave index 0
2808 2726
2809 faces [RETVAL].name = name; 2727 faces [RETVAL].name = name;
2810 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2728 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2811 2729
2812 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2730 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2813 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2731 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2732 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2814} 2733}
2734 OUTPUT: RETVAL
2735
2736faceidx faces_size ()
2737 CODE:
2738 RETVAL = faces.size ();
2815 OUTPUT: RETVAL 2739 OUTPUT: RETVAL
2816 2740
2817void set_type (faceidx idx, int value) 2741void set_type (faceidx idx, int value)
2818 ALIAS: 2742 ALIAS:
2819 set_type = 0 2743 set_type = 0
2830 case 2: f->magicmap = value; break; 2754 case 2: f->magicmap = value; break;
2831 case 3: f->smooth = value; break; 2755 case 3: f->smooth = value; break;
2832 case 4: f->smoothlevel = value; break; 2756 case 4: f->smoothlevel = value; break;
2833 } 2757 }
2834 2758
2835void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2759void set_csum (faceidx idx, int faceset, SV *chksum)
2836 CODE: 2760 CODE:
2837{ 2761{
2838 faceinfo *f = face_info (idx); assert (f); 2762 faceinfo *f = face_info (idx); assert (f);
2839 facedata *d = &(faceset ? f->data64 : f->data32); 2763 facedata *d = f->face + faceset;
2840 sv_to (data, d->data);
2841 STRLEN clen; 2764 STRLEN clen;
2842 char *cdata = SvPVbyte (chksum, clen); 2765 char *cdata = SvPVbyte (chksum, clen);
2843 clen = min (CHKSUM_MAXLEN, clen);
2844 2766
2767 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2845 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2768 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2846 2769
2847 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2770 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2848 { 2771 {
2849 d->chksum_len = clen; 2772 d->chksum_len = clen;
2850 memcpy (d->chksum, cdata, clen); 2773 memcpy (d->chksum, cdata, clen);
2851 2774
2852 // invalidate existing client face info 2775 // invalidate existing client face info
2853 for_all_clients (ns) 2776 for_all_clients (ns)
2854 if (ns->faceset == faceset) 2777 ns->invalidate_face (idx);
2855 {
2856 ns->faces_sent [idx] = false;
2857 ns->force_newmap = true;
2858 }
2859 } 2778 }
2860} 2779}
2861 2780
2862int get_data_size (faceidx idx, int faceset = 0) 2781SV *mangle_csum (SV *chksum)
2863 CODE: 2782 CODE:
2864 facedata *d = face_data (idx, faceset); 2783 STRLEN len;
2865 if (!d) XSRETURN_UNDEF; 2784 char *data = SvPVbyte (chksum, len);
2866 RETVAL = d->data.size (); 2785 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2867 OUTPUT: 2786 OUTPUT: RETVAL
2868 RETVAL
2869 2787
2870SV *get_chksum (faceidx idx, int faceset = 0) 2788SV *get_csum (faceidx idx, int faceset = 0)
2871 CODE: 2789 CODE:
2872 facedata *d = face_data (idx, faceset); 2790 facedata *d = face_data (idx, faceset);
2873 if (!d) XSRETURN_UNDEF; 2791 if (!d) XSRETURN_UNDEF;
2874 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2792 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2875 OUTPUT: 2793 OUTPUT: RETVAL
2876 RETVAL
2877 2794
2878SV *get_data (faceidx idx, int faceset = 0) 2795int get_type (faceidx idx)
2879 CODE: 2796 CODE:
2880 facedata *d = face_data (idx, faceset); 2797 faceinfo *f = face_info (idx);
2881 if (!d) XSRETURN_UNDEF; 2798 if (!f) XSRETURN_UNDEF;
2882 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2799 RETVAL = f->type;
2883 OUTPUT: 2800 OUTPUT: RETVAL
2884 RETVAL 2801
2802SV *get_name (faceidx idx)
2803 CODE:
2804 faceinfo *f = face_info (idx);
2805 if (!f) XSRETURN_UNDEF;
2806 RETVAL = to_sv (f->name);
2807 OUTPUT: RETVAL
2885 2808
2886void invalidate (faceidx idx) 2809void invalidate (faceidx idx)
2887 CODE: 2810 CODE:
2888 for_all_clients (ns) 2811 for_all_clients (ns)
2889 { 2812 ns->invalidate_face (idx);
2890 ns->faces_sent [idx] = false;
2891 ns->force_newmap = true;
2892 }
2893 2813
2894void invalidate_all () 2814void invalidate_all ()
2895 CODE: 2815 CODE:
2896 for_all_clients (ns) 2816 for_all_clients (ns)
2897 { 2817 ns->invalidate_all_faces ();
2898 ns->faces_sent.reset ();
2899 ns->force_newmap = true;
2900 }
2901 2818
2902MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2819MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2903 2820
2904#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2821#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2905 2822
2909 OUTPUT: RETVAL 2826 OUTPUT: RETVAL
2910 2827
2911animidx set (utf8_string name, SV *frames, int facings = 1) 2828animidx set (utf8_string name, SV *frames, int facings = 1)
2912 CODE: 2829 CODE:
2913{ 2830{
2914 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2831 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2915 croak ("frames must be an arrayref"); 2832 croak ("frames must be an arrayref");
2916 2833
2917 AV *av = (AV *)SvRV (frames); 2834 AV *av = (AV *)SvRV (frames);
2918 2835
2919 animation *anim = &animation::find (name); 2836 animation *anim = &animation::find (name);
2920 if (anim->number) 2837 if (anim->number)
2921 { 2838 {
2922 anim->resize (av_len (av) + 1); 2839 anim->resize (av_len (av) + 1);
2923 anim->facings = facings; 2840 anim->facings = facings;
2924 } 2841 }
2952 sv_to (sv, self); 2869 sv_to (sv, self);
2953 delete self; 2870 delete self;
2954 2871
2955MODULE = cf PACKAGE = cf::object::thawer 2872MODULE = cf PACKAGE = cf::object::thawer
2956 2873
2957INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2874INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2875
2876bool
2877errors_are_fatal (bool fatal)
2878 CODE:
2879 RETVAL = object_thawer::errors_are_fatal;
2880 object_thawer::errors_are_fatal = fatal;
2881 OUTPUT: RETVAL
2958 2882
2959SV * 2883SV *
2960new_from_file (char *klass, octet_string path) 2884new_from_file (char *klass, octet_string path)
2961 CODE: 2885 CODE:
2962 object_thawer *f = new object_thawer (path); 2886 object_thawer *f = new object_thawer (path);
2988 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2912 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2989 2913
2990 self->skip (); 2914 self->skip ();
2991 } 2915 }
2992 2916
2917MODULE = cf PACKAGE = cf::treasurelist
2918
2919# quick hack, because I didn't want to implement accessors for treasurelist.
2920# this asks for even more autogen, actually.
2921
2922void
2923expand (treasurelist *list)
2924 PPCODE:
2925 EXTEND (SP, 3);
2926 PUSHs (sv_2mortal (to_sv (list->name)));
2927 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2928 AV *av = newAV ();
2929 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2930 for (treasure *item = list->items; item; item = item->next)
2931 {
2932 AV *iav = newAV ();
2933 av_push (av, newRV_noinc ((SV *)iav));
2934
2935 av_extend (iav, 7);
2936 av_push (iav, to_sv (item->item));
2937 av_push (iav, to_sv (item->name));
2938 av_push (iav, to_sv (item->change_arch.name));
2939 av_push (iav, to_sv (item->change_arch.title));
2940 av_push (iav, to_sv (item->change_arch.slaying));
2941 av_push (iav, to_sv (item->chance));
2942 av_push (iav, to_sv (item->nrof));
2943 av_push (iav, to_sv (item->magic));
2944 }
2945
2946MODULE = cf PACKAGE = cf::layout
2947
2948INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2949

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines