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.118 by root, Sat Dec 30 20:32:30 2006 UTC vs.
Revision 1.188 by root, Mon Apr 16 11:09:32 2007 UTC

4 4
5/* 5/*
6 * This code is placed under the GNU General Public Licence (GPL) 6 * This code is placed under the GNU General Public Licence (GPL)
7 * 7 *
8 * Copyright (C) 2001-2005 by Chachkoff Yann 8 * Copyright (C) 2001-2005 by Chachkoff Yann
9 * Copyright (C) 2006 by Marc Lehmann <cf@schmorp.de> 9 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
29#include <plugin_common.h> 29#include <plugin_common.h>
30#include <sounds.h> 30#include <sounds.h>
31#include <cstdarg> 31#include <cstdarg>
32#include <sproto.h> 32#include <sproto.h>
33 33
34#include "loader.h"
34#include "cfperl.h" 35#include "cfperl.h"
35#include "shstr.h" 36#include "shstr.h"
37
38#include <unistd.h>
39#if _POSIX_MEMLOCK
40# include <sys/mman.h>
41#endif
36 42
37#include <EXTERN.h> 43#include <EXTERN.h>
38#include <perl.h> 44#include <perl.h>
39#include <XSUB.h> 45#include <XSUB.h>
40 46
43 49
44extern sint64 *levels; // the experience table 50extern sint64 *levels; // the experience table
45 51
46typedef object object_ornull; 52typedef object object_ornull;
47typedef maptile maptile_ornull; 53typedef maptile maptile_ornull;
54
55typedef char *octet_string;
56typedef char *utf8_string;
57typedef const char *const_octet_string;
58typedef const char *const_utf8_string;
48 59
49#if IVSIZE >= 8 60#if IVSIZE >= 8
50 typedef IV val64; 61 typedef IV val64;
51# define newSVval64 newSViv 62# define newSVval64 newSViv
52# define SvVAL64 SvIV 63# define SvVAL64 SvIV
94 105
95////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 106//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
96 107
97unordered_vector<attachable *> attachable::mortals; 108unordered_vector<attachable *> attachable::mortals;
98 109
99#if 0
100attachable *attachable::rc_first;
101
102attachable::attachable ()
103{
104 refcnt = 0;
105 rc_next = rc_first;
106 rc_first = this;
107}
108#endif
109
110attachable::~attachable () 110attachable::~attachable ()
111{ 111{
112 assert (!(flags & F_BORROWED));//D//TODO//remove when stable 112 flags |=0x3300;//D
113#if 0
114 assert (!rc_next);
115 assert (!refcnt); 113 assert (!self);
116#endif 114 assert (!cb);
115}
116
117int
118attachable::refcnt_cnt () const
119{
120 return refcnt + (self ? SvREFCNT (self) - 1 : 0);
121}
122
123void
124attachable::sever_self ()
125{
126 if (HV *self = this->self)
127 {
128 // keep a refcount because sv_unmagic might call attachable_free,
129 // which might clear self, causing sv_unmagic to crash on a now
130 // invalid object.
131 SvREFCNT_inc (self);
132 hv_clear (self);
133 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
134 SvREFCNT_dec (self);
135
136 // self *must* be null now because thats sv_unmagic's job.
137 assert (!this->self);
138 flags |= 0x80; // severed //D
139 }
140}
141
142void
143attachable::optimise ()
144{
145 if (self
146 && SvREFCNT (self) == 1
147 && !HvTOTALKEYS (self))
148 flags |= 0x40,//D
149 sever_self ();
117} 150}
118 151
119// check wether the object really is dead 152// check wether the object really is dead
120void 153void
121attachable::do_check () 154attachable::do_check ()
122{ 155{
123 if (refcnt > 0) 156 if (refcnt_cnt () > 0)
124 return; 157 return;
125 158
126 // try to unborrow the refcnt from perl 159 destroy ();
127 if (flags & F_BORROWED) 160}
161
162void
163attachable::do_destroy ()
164{
165 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
166
167 if (cb)
128 { 168 {
129 assert (self);//D//TODO//remove when stable
130 flags &= ~F_BORROWED;
131 refcnt_inc ();
132 SvREFCNT_dec (self); 169 SvREFCNT_dec (cb);
170 cb = 0;
133 } 171 }
134 172
135 if (refcnt > 0 || self) 173 if (self)
136 return; 174 sever_self ();
137 175
138 destroy (); 176 flags |= 0x20; //D
139}
140
141void
142attachable::do_destroy ()
143{
144 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
145
146 //TODO: call generic destroy callback
147 mortals.push_back (this); 177 mortals.push_back (this);
148} 178}
149 179
150void 180void
151attachable::destroy () 181attachable::destroy ()
155 185
156 flags |= F_DESTROYED; 186 flags |= F_DESTROYED;
157 do_destroy (); 187 do_destroy ();
158} 188}
159 189
190void
160void attachable::check_mortals () 191attachable::check_mortals ()
161{ 192{
162 for (int i = 0; i < mortals.size (); ) 193 static int i = 0;
194
195 for (;;)
163 { 196 {
197 if (i >= mortals.size ())
198 {
199 i = 0;
200
201 if (mortals.size () > 1000)
202 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
203
204 break;
205 }
206
164 attachable *obj = mortals [i]; 207 attachable *obj = mortals [i];
165 208
166 obj->refcnt_chk (); // unborrow from perl, if necessary 209 obj->refcnt_chk (); // unborrow from perl, if necessary
167 210
211 //if (obj->refcnt > 0 || obj->self)
168 if (obj->refcnt || obj->self) 212 if (obj->refcnt || obj->self)
169 { 213 {
170#if 0 214//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D
171 if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (),
172 obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D
173#endif
174
175 ++i; // further delay freeing 215 ++i; // further delay freeing
216
217 if (!(i & 0x3ff))
218 break;
176 }//D 219 }
177 else 220 else
178 { 221 {
179 //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D
180 mortals.erase (i); 222 mortals.erase (i);
181 delete obj; 223 delete obj;
182 } 224 }
183 } 225 }
184} 226}
209 251
210static int 252static int
211attachable_free (pTHX_ SV *sv, MAGIC *mg) 253attachable_free (pTHX_ SV *sv, MAGIC *mg)
212{ 254{
213 attachable *at = (attachable *)mg->mg_ptr; 255 attachable *at = (attachable *)mg->mg_ptr;
214 assert (!(at->flags & attachable::F_BORROWED));//D//TODO//remove when stable 256
257 //TODO: check if transaction behaviour is really required here
258 if (SV *self = (SV *)at->self)
259 {
215 at->self = 0; 260 at->self = 0;
261 SvREFCNT_dec (self);
262 }
263
216 // next line makes sense, but most objects still have refcnt 0 by default 264 // next line makes sense, but most objects still have refcnt 0 by default
217 //at->refcnt_chk (); 265 //at->refcnt_chk ();
218 return 0; 266 return 0;
219} 267}
220 268
228 276
229 if (!obj->self) 277 if (!obj->self)
230 { 278 {
231 obj->self = newHV (); 279 obj->self = newHV ();
232 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 280 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
281 obj->flags |= (obj->flags & 0xc0) << 8;
282 obj->flags &= ~0xc0;//D
283 obj->flags |= 0x10;//D
233 284
234 // borrow the refcnt from the object 285 // now bless the object _once_
235 obj->flags |= attachable::F_BORROWED; 286 return sv_bless (newRV_inc ((SV *)obj->self), stash);
236 obj->refcnt_dec ();
237 } 287 }
288 else
289 {
290 SV *sv = newRV_inc ((SV *)obj->self);
238 291
239 return sv_bless (newRV_inc ((SV *)obj->self), stash); 292 if (Gv_AMG (stash)) // handle overload correctly, as the perl core does not
293 SvAMAGIC_on (sv);
294
295 return sv;
296 }
240} 297}
241 298
242static void 299static void
243clearSVptr (SV *sv) 300clearSVptr (SV *sv)
244{ 301{
297inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 354inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
298 355
299inline SV *to_sv (object & v) { return to_sv (&v); } 356inline SV *to_sv (object & v) { return to_sv (&v); }
300inline SV *to_sv (living & v) { return to_sv (&v); } 357inline SV *to_sv (living & v) { return to_sv (&v); }
301 358
302//TODO:
303inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 359//inline SV *to_sv (faceinfo * v) { return to_sv (v->name); }
304inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 360inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
361inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); }
305 362
306inline SV *to_sv (UUID v) 363inline SV *to_sv (UUID v)
307{ 364{
308 char buf[128]; 365 char buf[128];
309 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); 366 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
310 return newSVpv (buf, 0); 367 return newSVpv (buf, 0);
311} 368}
312 369
313inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 370inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
314inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 371inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
328inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 385inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
329inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 386inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
330inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 387inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
331inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 388inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
332inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 389inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
390inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
333inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 391inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
334inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } 392inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
335inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 393inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
336 394
337inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO 395//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
338inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO 396inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
339 397
340template<class T> 398template<class T>
341inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 399inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
342 400
343template<int N> 401template<int N>
346inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } 404inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
347inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 405inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
348inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 406inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
349inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 407inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
350inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 408inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
409
410inline void sv_to (SV *sv, std::string &v)
411{
412 STRLEN len;
413 char *data = SvPVbyte (sv, len);
414 v.assign (data, len);
415}
351 416
352inline void sv_to (SV *sv, UUID &v) 417inline void sv_to (SV *sv, UUID &v)
353{ 418{
354 unsigned int version; 419 unsigned int version;
355 420
478{ 543{
479 if (!ext->cb) 544 if (!ext->cb)
480 ext->cb = newAV (); 545 ext->cb = newAV ();
481 546
482 return newRV_inc ((SV *)ext->cb); 547 return newRV_inc ((SV *)ext->cb);
483}
484
485#if 0
486void attachable::clear ()
487{
488 if (self)
489 {
490 // disconnect Perl from C, to avoid crashes
491 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
492
493 // clear the perl hash, might or might not be a good idea
494 hv_clear ((HV *)SvRV ((SV *)self));
495
496 SvREFCNT_dec (self);
497 self = 0;
498 }
499
500 if (cb)
501 {
502 SvREFCNT_dec (cb);
503 cb = 0;
504 }
505
506 attach = 0;
507}
508#endif
509
510void attachable::optimise ()
511{
512 if (self
513 && SvREFCNT (self) == 1
514 && !HvTOTALKEYS (self))
515 {
516 flags &= ~F_BORROWED;
517 refcnt_inc ();
518 SvREFCNT_dec ((SV *)self);
519 }
520} 548}
521 549
522///////////////////////////////////////////////////////////////////////////// 550/////////////////////////////////////////////////////////////////////////////
523 551
524extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 552extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
583 perl = perl_alloc (); 611 perl = perl_alloc ();
584 perl_construct (perl); 612 perl_construct (perl);
585 613
586 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 614 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
587 615
588 char *argv[] = { 616 const char *argv[] = {
589 "", 617 "",
590 "-e" 618 "-e"
591 "use Event; use Coro;" // required for bootstrap 619 "use Event; use Coro;" // required for bootstrap
592 "cf->bootstrap;" // required for datadir :*> 620 "cf->bootstrap;" // required for datadir :*>
593 "unshift @INC, cf::datadir ();" 621 "unshift @INC, cf::datadir ();"
594 "require cf;" 622 "require cf;"
595 }; 623 };
596 624
597 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 625 if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL)
626 || perl_run (perl))
598 { 627 {
599 printf ("unable to initialize perl-interpreter, aborting.\n"); 628 printf ("unable to initialize perl-interpreter, aborting.\n");
600 exit (EXIT_FAILURE); 629 exit (EXIT_FAILURE);
601 } 630 }
631
632 {
633 dSP;
634
635 PUSHMARK (SP);
636 PUTBACK;
637 call_pv ("cf::init", G_DISCARD | G_VOID);
638 }
602} 639}
603 640
604void cfperl_main () 641void cfperl_main ()
605{ 642{
606 dSP; 643 dSP;
820} 857}
821 858
822///////////////////////////////////////////////////////////////////////////// 859/////////////////////////////////////////////////////////////////////////////
823 860
824void 861void
825maptile::emergency_save () 862cfperl_emergency_save ()
826{ 863{
827 CALL_BEGIN (0); 864 CALL_BEGIN (0);
828 CALL_CALL ("cf::map::emergency_save", G_VOID); 865 CALL_CALL ("cf::emergency_save", G_VOID);
829 CALL_END; 866 CALL_END;
830} 867}
831 868
869void
870cfperl_cleanup (int make_core)
871{
872 CALL_BEGIN (1);
873 CALL_ARG (make_core);
874 CALL_CALL ("cf::post_cleanup", G_VOID);
875 CALL_END;
876}
877
832maptile * 878maptile *
833maptile::find_map (const char *path, maptile *origin) 879maptile::find_sync (const char *path, maptile *origin)
834{ 880{
835 CALL_BEGIN (2); 881 CALL_BEGIN (2);
836 CALL_ARG (path); 882 CALL_ARG (path);
837 CALL_ARG (origin); 883 CALL_ARG (origin);
838 CALL_CALL ("cf::map::find_map", G_SCALAR); 884 CALL_CALL ("cf::map::find_sync", G_SCALAR);
839 885
840 maptile *retval; 886 maptile *retval;
841 887
842 if (count) 888 if (count)
843 sv_to (POPs, retval); 889 sv_to (POPs, retval);
847 CALL_END; 893 CALL_END;
848 894
849 return retval; 895 return retval;
850} 896}
851 897
852void
853maptile::do_load ()
854{
855 CALL_BEGIN (1);
856 CALL_ARG (this);
857 CALL_CALL ("cf::map::do_load", G_VOID);
858 CALL_END;
859}
860
861maptile * 898maptile *
862maptile::customise_for (object *op) 899maptile::find_async (const char *path, maptile *origin)
863{ 900{
864 CALL_BEGIN (2); 901 CALL_BEGIN (2);
865 CALL_ARG (this); 902 CALL_ARG (path);
866 CALL_ARG (op); 903 CALL_ARG (origin);
867 CALL_CALL ("cf::map::customise_for", G_SCALAR); 904 CALL_CALL ("cf::map::find_async", G_SCALAR);
868 905
869 maptile *retval; 906 maptile *retval;
870 907
871 if (count) 908 if (count)
872 sv_to (POPs, retval); 909 sv_to (POPs, retval);
873 else 910 else
874 retval = 0; 911 retval = 0;
875 912
876 CALL_END; 913 CALL_END;
877 914
878 return retval ? retval : this; 915 return retval;
916}
917
918void
919maptile::do_load_sync ()
920{
921 CALL_BEGIN (1);
922 CALL_ARG (this);
923 CALL_CALL ("cf::map::do_load_sync", G_SCALAR);
924 CALL_END;
879} 925}
880 926
881void 927void
882maptile::change_all_map_light (int change) 928maptile::change_all_map_light (int change)
883{ 929{
903///////////////////////////////////////////////////////////////////////////// 949/////////////////////////////////////////////////////////////////////////////
904 950
905struct EventAPI *watcher_base::GEventAPI; 951struct EventAPI *watcher_base::GEventAPI;
906struct CoroAPI *coroapi::GCoroAPI; 952struct CoroAPI *coroapi::GCoroAPI;
907 953
954int coroapi::cede_counter;
955
956void
957coroapi::wait_for_tick ()
958{
959 CALL_BEGIN (0);
960 CALL_CALL ("cf::wait_for_tick", G_DISCARD);
961 CALL_END;
962}
963
964void
965coroapi::wait_for_tick_begin ()
966{
967 CALL_BEGIN (0);
968 CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD);
969 CALL_END;
970}
971
972static void
908static void iw_dispatch (pe_event *ev) 973iw_dispatch (pe_event *ev)
909{ 974{
910 iw *w = (iw *)ev->ext_data; 975 iw *w = (iw *)ev->ext_data;
911 w->call (*w); 976 w->call (*w);
912} 977}
913 978
914void 979void
915iw::alloc () 980iw::alloc ()
916{ 981{
917 pe = GEventAPI->new_idle (0, 0); 982 pe = GEventAPI->new_idle (0, 0);
918 983
984 WaREENTRANT_off (pe);
919 pe->base.callback = (void *)iw_dispatch; 985 pe->base.callback = (void *)iw_dispatch;
920 pe->base.ext_data = (void *)this; 986 pe->base.ext_data = (void *)this;
921} 987}
922 988
923static void iow_dispatch (pe_event *ev) 989static void iow_dispatch (pe_event *ev)
929void 995void
930iow::alloc () 996iow::alloc ()
931{ 997{
932 pe = GEventAPI->new_io (0, 0); 998 pe = GEventAPI->new_io (0, 0);
933 999
1000 WaREENTRANT_off (pe);
934 pe->base.callback = (void *)iow_dispatch; 1001 pe->base.callback = (void *)iow_dispatch;
935 pe->base.ext_data = (void *)this; 1002 pe->base.ext_data = (void *)this;
936 1003
937 pe->fd = -1; 1004 pe->fd = -1;
938 pe->poll = 0; 1005 pe->poll = 0;
1006# define const_iv(name) { # name, (IV)name }, 1073# define const_iv(name) { # name, (IV)name },
1007 const_iv (llevError) 1074 const_iv (llevError)
1008 const_iv (llevInfo) 1075 const_iv (llevInfo)
1009 const_iv (llevDebug) 1076 const_iv (llevDebug)
1010 const_iv (llevMonster) 1077 const_iv (llevMonster)
1078
1079 const_iv (Map0Cmd)
1080 const_iv (Map1Cmd)
1081 const_iv (Map1aCmd)
1082
1083 const_iv (MAP_CLIENT_X)
1084 const_iv (MAP_CLIENT_Y)
1011 1085
1012 const_iv (MAX_TIME) 1086 const_iv (MAX_TIME)
1013 const_iv (PLAYER) 1087 const_iv (PLAYER)
1014 const_iv (TRANSPORT) 1088 const_iv (TRANSPORT)
1015 const_iv (ROD) 1089 const_iv (ROD)
1266 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1340 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1267 const_iv (FLAG_IS_WATER) 1341 const_iv (FLAG_IS_WATER)
1268 const_iv (FLAG_CONTENT_ON_GEN) 1342 const_iv (FLAG_CONTENT_ON_GEN)
1269 const_iv (FLAG_IS_A_TEMPLATE) 1343 const_iv (FLAG_IS_A_TEMPLATE)
1270 const_iv (FLAG_IS_BUILDABLE) 1344 const_iv (FLAG_IS_BUILDABLE)
1345 const_iv (FLAG_DESTROY_ON_DEATH)
1346 const_iv (FLAG_NO_MAP_SAVE)
1271 1347
1272 const_iv (NDI_BLACK) 1348 const_iv (NDI_BLACK)
1273 const_iv (NDI_WHITE) 1349 const_iv (NDI_WHITE)
1274 const_iv (NDI_NAVY) 1350 const_iv (NDI_NAVY)
1275 const_iv (NDI_RED) 1351 const_iv (NDI_RED)
1317 const_iv (P_BLOCKSVIEW) 1393 const_iv (P_BLOCKSVIEW)
1318 const_iv (P_PLAYER) 1394 const_iv (P_PLAYER)
1319 const_iv (P_NO_MAGIC) 1395 const_iv (P_NO_MAGIC)
1320 const_iv (P_IS_ALIVE) 1396 const_iv (P_IS_ALIVE)
1321 const_iv (P_NO_CLERIC) 1397 const_iv (P_NO_CLERIC)
1322 const_iv (P_NEED_UPDATE)
1323 const_iv (P_OUT_OF_MAP) 1398 const_iv (P_OUT_OF_MAP)
1324 const_iv (P_NEW_MAP) 1399 const_iv (P_NEW_MAP)
1400 const_iv (P_UPTODATE)
1325 1401
1326 const_iv (UP_OBJ_INSERT) 1402 const_iv (UP_OBJ_INSERT)
1327 const_iv (UP_OBJ_REMOVE) 1403 const_iv (UP_OBJ_REMOVE)
1328 const_iv (UP_OBJ_CHANGE) 1404 const_iv (UP_OBJ_CHANGE)
1329 const_iv (UP_OBJ_FACE) 1405 const_iv (UP_OBJ_FACE)
1460 const_iv (ATNR_BLIND) 1536 const_iv (ATNR_BLIND)
1461 const_iv (ATNR_INTERNAL) 1537 const_iv (ATNR_INTERNAL)
1462 const_iv (ATNR_LIFE_STEALING) 1538 const_iv (ATNR_LIFE_STEALING)
1463 const_iv (ATNR_DISEASE) 1539 const_iv (ATNR_DISEASE)
1464 1540
1465 const_iv (MAP_FLUSH)
1466 const_iv (MAP_PLAYER_UNIQUE)
1467 const_iv (MAP_BLOCK)
1468 const_iv (MAP_STYLE)
1469 const_iv (MAP_OVERLAY)
1470
1471 const_iv (MAP_IN_MEMORY) 1541 const_iv (MAP_IN_MEMORY)
1472 const_iv (MAP_SWAPPED) 1542 const_iv (MAP_SWAPPED)
1473 const_iv (MAP_LOADING) 1543 const_iv (MAP_LOADING)
1474 const_iv (MAP_SAVING) 1544 const_iv (MAP_SAVING)
1475 1545
1488 const_iv (ST_SETUP) 1558 const_iv (ST_SETUP)
1489 const_iv (ST_PLAYING) 1559 const_iv (ST_PLAYING)
1490 const_iv (ST_CUSTOM) 1560 const_iv (ST_CUSTOM)
1491 1561
1492 const_iv (ST_CHANGE_CLASS) 1562 const_iv (ST_CHANGE_CLASS)
1493 const_iv (ST_CONFIRM_QUIT)
1494 const_iv (ST_GET_PARTY_PASSWORD)
1495 1563
1496 const_iv (IO_HEADER) 1564 const_iv (IO_HEADER)
1497 const_iv (IO_OBJECTS) 1565 const_iv (IO_OBJECTS)
1498 const_iv (IO_UNIQUES) 1566 const_iv (IO_UNIQUES)
1499 1567
1553 1621
1554void _global_reattach () 1622void _global_reattach ()
1555 CODE: 1623 CODE:
1556{ 1624{
1557 // reattach to all attachable objects in the game. 1625 // reattach to all attachable objects in the game.
1558 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 1626 for_all_clients (ns)
1559 (*i)->reattach (); 1627 ns->reattach ();
1560 1628
1561 for_all_players (pl) 1629 for_all_objects (op)
1562 pl->reattach ();
1563
1564 //TODO
1565 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i)
1566 // i->second->reattach ();
1567
1568 for (object *op = object::first; op; op = op->next)
1569 op->reattach (); 1630 op->reattach ();
1570} 1631}
1571 1632
1572NV floor (NV x) 1633NV floor (NV x)
1573 1634
1574NV ceil (NV x) 1635NV ceil (NV x)
1636
1637NV rndm (...)
1638 CODE:
1639 switch (items)
1640 {
1641 case 0: RETVAL = rndm (); break;
1642 case 1: RETVAL = rndm (SvUV (ST (0))); break;
1643 case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break;
1644 default: croak ("cf::rndm requires none, one or two parameters."); break;
1645 }
1646 OUTPUT:
1647 RETVAL
1575 1648
1576void server_tick () 1649void server_tick ()
1577 CODE: 1650 CODE:
1578 runtime = SvNVx (sv_runtime); 1651 runtime = SvNVx (sv_runtime);
1579 server_tick (); 1652 server_tick ();
1580 1653
1581void 1654void
1582LOG (int level, char *msg) 1655LOG (int level, utf8_string msg)
1583 PROTOTYPE: $$ 1656 PROTOTYPE: $$
1584 C_ARGS: (LogLevel)level, "%s", msg 1657 C_ARGS: (LogLevel)level, "%s", msg
1585 1658
1586char *path_combine (char *base, char *path) 1659octet_string path_combine (octet_string base, octet_string path)
1587 PROTOTYPE: $$ 1660 PROTOTYPE: $$
1588 1661
1589char *path_combine_and_normalize (char *base, char *path) 1662octet_string path_combine_and_normalize (octet_string base, octet_string path)
1590 PROTOTYPE: $$ 1663 PROTOTYPE: $$
1591 1664
1592const char * 1665const_octet_string
1593get_maps_directory (char *path) 1666get_maps_directory (octet_string path)
1594 PROTOTYPE: $ 1667 PROTOTYPE: $
1595 ALIAS: maps_directory = 0 1668 ALIAS: maps_directory = 0
1596 CODE: 1669 CODE:
1597 RETVAL = create_pathname (path); 1670 RETVAL = create_pathname (path);
1598 OUTPUT: RETVAL 1671 OUTPUT: RETVAL
1600void 1673void
1601sub_generation_inc () 1674sub_generation_inc ()
1602 CODE: 1675 CODE:
1603 PL_sub_generation++; 1676 PL_sub_generation++;
1604 1677
1605char * 1678const_octet_string
1606mapdir () 1679mapdir ()
1607 PROTOTYPE: 1680 PROTOTYPE:
1608 ALIAS: 1681 ALIAS:
1609 mapdir = 0 1682 mapdir = 0
1610 uniquedir = 1 1683 uniquedir = 1
1624 case 5: RETVAL = settings.playerdir; break; 1697 case 5: RETVAL = settings.playerdir; break;
1625 case 6: RETVAL = settings.datadir ; break; 1698 case 6: RETVAL = settings.datadir ; break;
1626 } 1699 }
1627 OUTPUT: RETVAL 1700 OUTPUT: RETVAL
1628 1701
1702void abort ()
1703
1704void fork_abort (octet_string cause = "cf::fork_abort")
1705
1706void cleanup (octet_string cause, bool make_core = false)
1707
1629void emergency_save () 1708void emergency_save ()
1630 1709
1631void _exit (int status = 0) 1710void _exit (int status = EXIT_SUCCESS)
1632 1711
1712UV sv_2watcher (SV *w)
1713 CODE:
1714 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1715 OUTPUT:
1716 RETVAL
1717
1718#if _POSIX_MEMLOCK
1719
1720int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1721
1722int munlockall ()
1723
1724#endif
1725
1633int find_animation (char *text) 1726int find_animation (utf8_string text)
1634 PROTOTYPE: $ 1727 PROTOTYPE: $
1635 1728
1636int random_roll (int min, int max, object *op, int goodbad); 1729int random_roll (int min, int max, object *op, int goodbad);
1637 1730
1638const char *cost_string_from_value(uint64 cost, int approx = 0) 1731const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1639 1732
1640int 1733int
1641exp_to_level (val64 exp) 1734exp_to_level (val64 exp)
1642 CODE: 1735 CODE:
1643{ 1736{
1674 RETVAL = newSVpv (resist_plus[atnr], 0); 1767 RETVAL = newSVpv (resist_plus[atnr], 0);
1675 else 1768 else
1676 XSRETURN_UNDEF; 1769 XSRETURN_UNDEF;
1677 OUTPUT: RETVAL 1770 OUTPUT: RETVAL
1678 1771
1772bool
1773load_resource_file (octet_string filename)
1774
1775bool
1776load_archetype_file (octet_string filename)
1777
1778bool
1779load_treasure_file (octet_string filename)
1780
1679MODULE = cf PACKAGE = cf::attachable 1781MODULE = cf PACKAGE = cf::attachable
1680 1782
1681int 1783int
1682valid (SV *obj) 1784valid (SV *obj)
1683 CODE: 1785 CODE:
1684 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1786 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1685 OUTPUT: 1787 OUTPUT:
1686 RETVAL 1788 RETVAL
1687 1789
1688#bool
1689#destroyed (attachable *at)
1690#
1691#void 1790void
1692#destroy (attachable *at) 1791debug_trace (attachable *obj, bool on = true)
1792 CODE:
1793 obj->flags &= ~attachable::F_DEBUG_TRACE;
1794 if (on)
1795 obj->flags |= attachable::F_DEBUG_TRACE;
1796
1797int mortals_size ()
1798 CODE:
1799 RETVAL = attachable::mortals.size ();
1800 OUTPUT: RETVAL
1801
1802#object *mortals (U32 index)
1803# CODE:
1804# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0;
1805# OUTPUT: RETVAL
1806
1807INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h |
1693 1808
1694MODULE = cf PACKAGE = cf::global 1809MODULE = cf PACKAGE = cf::global
1695 1810
1696int invoke (SV *klass, int event, ...) 1811int invoke (SV *klass, int event, ...)
1697 CODE: 1812 CODE:
1701 RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); 1816 RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END);
1702 OUTPUT: RETVAL 1817 OUTPUT: RETVAL
1703 1818
1704MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1819MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1705 1820
1706INCLUDE: $PERL genacc object ../include/object.h | 1821INCLUDE: $PERL $srcdir/genacc object ../include/object.h |
1707 1822
1708int invoke (object *op, int event, ...) 1823int invoke (object *op, int event, ...)
1709 CODE: 1824 CODE:
1710 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); 1825 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT");
1711 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 1826 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1713 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); 1828 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END);
1714 OUTPUT: RETVAL 1829 OUTPUT: RETVAL
1715 1830
1716SV *registry (object *op) 1831SV *registry (object *op)
1717 1832
1718void mortals () 1833int objects_size ()
1719 PPCODE: 1834 CODE:
1720 EXTEND (SP, object::mortals.size ());
1721 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1722 PUSHs (to_sv (*i));
1723
1724object *first ()
1725 CODE:
1726 RETVAL = object::first; 1835 RETVAL = objects.size ();
1836 OUTPUT: RETVAL
1837
1838object *objects (U32 index)
1839 CODE:
1840 RETVAL = index < objects.size () ? objects [index] : 0;
1841 OUTPUT: RETVAL
1842
1843int actives_size ()
1844 CODE:
1845 RETVAL = actives.size ();
1846 OUTPUT: RETVAL
1847
1848object *actives (U32 index)
1849 CODE:
1850 RETVAL = index < actives.size () ? actives [index] : 0;
1727 OUTPUT: RETVAL 1851 OUTPUT: RETVAL
1728 1852
1729# missing properties 1853# missing properties
1730 1854
1731object *head (object *op) 1855object *head (object *op)
1732 PROTOTYPE: $ 1856 PROTOTYPE: $
1733 CODE: 1857 CODE:
1734 RETVAL = op->head ? op->head : op; 1858 RETVAL = op->head_ ();
1735 OUTPUT: RETVAL 1859 OUTPUT: RETVAL
1736 1860
1737int is_head (object *op) 1861int is_head (object *op)
1738 PROTOTYPE: $ 1862 PROTOTYPE: $
1739 CODE: 1863 CODE:
1740 RETVAL = !op->head; 1864 RETVAL = op->head_ () == op;
1741 OUTPUT: RETVAL 1865 OUTPUT: RETVAL
1742 1866
1743void 1867void
1744inv (object *obj) 1868inv (object *obj)
1745 PROTOTYPE: $ 1869 PROTOTYPE: $
1753void 1877void
1754set_animation (object *op, int idx) 1878set_animation (object *op, int idx)
1755 CODE: 1879 CODE:
1756 SET_ANIMATION (op, idx); 1880 SET_ANIMATION (op, idx);
1757 1881
1882int
1883num_animations (object *op)
1884 CODE:
1885 RETVAL = NUM_ANIMATIONS (op);
1886 OUTPUT: RETVAL
1887
1758object *find_best_object_match (object *op, const char *match) 1888object *find_best_object_match (object *op, utf8_string match)
1759 1889
1760object *find_marked_object (object *op) 1890object *find_marked_object (object *op)
1761 1891
1762int need_identify (object *obj); 1892int need_identify (object *obj);
1763 1893
1764int apply_shop_mat (object *shop_mat, object *op); 1894int apply_shop_mat (object *shop_mat, object *op);
1895
1896int move_player (object *op, int dir)
1897 CODE:
1898 RETVAL = move_player (op, dir);
1899 OUTPUT:
1900 RETVAL
1765 1901
1766int move (object *op, int dir, object *originator = op) 1902int move (object *op, int dir, object *originator = op)
1767 CODE: 1903 CODE:
1768 RETVAL = move_ob (op, dir, originator); 1904 RETVAL = move_ob (op, dir, originator);
1769 OUTPUT: 1905 OUTPUT:
1775 1911
1776void apply_below (object *op) 1912void apply_below (object *op)
1777 CODE: 1913 CODE:
1778 player_apply_below (op); 1914 player_apply_below (op);
1779 1915
1916int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1917
1780object *cf_object_present_archname_inside (object *op, char *whatstr) 1918object *cf_object_present_archname_inside (object *op, utf8_string whatstr)
1781 1919
1782int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1920int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1783 1921
1784int cf_object_change_map (object *op, int x, int y, maptile *map) 1922int cf_object_change_map (object *op, int x, int y, maptile *map)
1785 1923
1805 RETVAL = pay_for_amount (amount, op); 1943 RETVAL = pay_for_amount (amount, op);
1806 OUTPUT: RETVAL 1944 OUTPUT: RETVAL
1807 1945
1808void pay_player (object *op, uint64 amount) 1946void pay_player (object *op, uint64 amount)
1809 1947
1810val64 pay_player_arch (object *op, const char *arch, uint64 amount) 1948val64 pay_player_arch (object *op, utf8_string arch, uint64 amount)
1811 1949
1812int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0) 1950int cast_spell (object *op, object *caster, int dir, object *spell_ob, utf8_string stringarg = 0)
1813 1951
1814void learn_spell (object *op, object *sp, int special_prayer = 0) 1952void learn_spell (object *op, object *sp, int special_prayer = 0)
1815 CODE: 1953 CODE:
1816 do_learn_spell (op, sp, special_prayer); 1954 do_learn_spell (op, sp, special_prayer);
1817 1955
1818void forget_spell (object *op, object *sp) 1956void forget_spell (object *op, object *sp)
1819 CODE: 1957 CODE:
1820 do_forget_spell (op, query_name (sp)); 1958 do_forget_spell (op, query_name (sp));
1821 1959
1822object *check_for_spell (object *op, char *spellname) 1960object *check_for_spell (object *op, utf8_string spellname)
1823 CODE: 1961 CODE:
1824 RETVAL = check_spell_known (op, spellname); 1962 RETVAL = check_spell_known (op, spellname);
1825 OUTPUT: RETVAL 1963 OUTPUT: RETVAL
1826 1964
1827int query_money (object *op) 1965int query_money (object *op)
1836 1974
1837void drop (object *who, object *op) 1975void drop (object *who, object *op)
1838 1976
1839void pick_up (object *who, object *op) 1977void pick_up (object *who, object *op)
1840 1978
1841object *cf_object_insert_object (object *op, object *container)
1842
1843object *cf_object_insert_in_ob (object *ob, object *where)
1844
1845int cf_object_teleport (object *op, maptile *map, int x, int y) 1979int cf_object_teleport (object *op, maptile *map, int x, int y)
1846 1980
1847void update_object (object *op, int action) 1981void update_object (object *op, int action)
1848 1982
1849object *cf_create_object_by_name (const char *name) 1983object *cf_create_object_by_name (utf8_string name)
1850 1984
1851void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1985void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0)
1852 1986
1853void player_lvl_adj (object *who, object *skill = 0) 1987void player_lvl_adj (object *who, object *skill = 0)
1854 1988
1855int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1989int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1856 1990
1870object *cf_insert_ob_in_ob (object *ob, object *where) 2004object *cf_insert_ob_in_ob (object *ob, object *where)
1871 2005
1872# no clean way to get an object from an archetype - stupid idiotic 2006# no clean way to get an object from an archetype - stupid idiotic
1873# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2007# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1874 2008
1875object *new (const char *archetype = 0) 2009object *new (utf8_string archetype = 0)
1876 PROTOTYPE: ;$ 2010 PROTOTYPE: ;$
1877 CODE: 2011 CODE:
1878 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 2012 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1879 OUTPUT: 2013 OUTPUT:
1880 RETVAL 2014 RETVAL
1885{ 2019{
1886 int unused_type; 2020 int unused_type;
1887 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 2021 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1888} 2022}
1889 2023
1890# syntatic sugar for easier use in event callbacks.
1891const char *options (object *op)
1892 CODE:
1893 RETVAL = op->name;
1894 OUTPUT:
1895 RETVAL
1896
1897player *contr (object *op) 2024player *contr (object *op)
1898 CODE: 2025 CODE:
1899 RETVAL = op->contr; 2026 RETVAL = op->contr;
1900 OUTPUT: RETVAL 2027 OUTPUT: RETVAL
1901 2028
1902const char *get_ob_key_value (object *op, const char *key) 2029const_utf8_string get_ob_key_value (object *op, utf8_string key)
1903 2030
1904bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 2031bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
1905 2032
1906object *get_nearest_player (object *ob) 2033object *get_nearest_player (object *ob)
1907 ALIAS: nearest_player = 0 2034 ALIAS: nearest_player = 0
1908 PREINIT: 2035 PREINIT:
1909 extern object *get_nearest_player (object *); 2036 extern object *get_nearest_player (object *);
1925bool on_same_map_as (object *ob, object *other) 2052bool on_same_map_as (object *ob, object *other)
1926 CODE: 2053 CODE:
1927 RETVAL = on_same_map (ob, other); 2054 RETVAL = on_same_map (ob, other);
1928 OUTPUT: RETVAL 2055 OUTPUT: RETVAL
1929 2056
1930const char * 2057const_utf8_string
1931base_name (object *op, int plural = op->nrof > 1) 2058base_name (object *op, int plural = op->nrof > 1)
1932 CODE: 2059 CODE:
1933 RETVAL = query_base_name (op, plural); 2060 RETVAL = query_base_name (op, plural);
1934 OUTPUT: RETVAL 2061 OUTPUT: RETVAL
1935 2062
1942 RETVAL = op->contr; 2069 RETVAL = op->contr;
1943 OUTPUT: RETVAL 2070 OUTPUT: RETVAL
1944 2071
1945void check_score (object *op) 2072void check_score (object *op)
1946 2073
1947void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2074void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2075 CODE:
2076 new_draw_info (flags, 0, op, txt);
1948 2077
1949object *cf_player_send_inventory (object *op) 2078object *cf_player_send_inventory (object *op)
1950 2079
1951char *cf_player_get_ip (object *op) 2080octet_string cf_player_get_ip (object *op)
1952 ALIAS: ip = 0 2081 ALIAS: ip = 0
1953 2082
1954object *cf_player_get_marked_item (object *op) 2083object *cf_player_get_marked_item (object *op)
1955 ALIAS: marked_item = 0 2084 ALIAS: marked_item = 0
1956 2085
1966void esrv_update_item (object *op, int what, object *item) 2095void esrv_update_item (object *op, int what, object *item)
1967 C_ARGS: what, op, item 2096 C_ARGS: what, op, item
1968 2097
1969void clear_los (object *op) 2098void clear_los (object *op)
1970 2099
1971int command_teleport (object *op, char *params)
1972
1973int command_summon (object *op, char *params) 2100int command_summon (object *op, utf8_string params)
1974 2101
1975int command_arrest (object *op, char *params) 2102int command_arrest (object *op, utf8_string params)
1976
1977int command_kick (object *op, char *params)
1978
1979int command_banish (object *op, char *params)
1980 2103
1981 2104
1982MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2105MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1983 2106
1984INCLUDE: $PERL genacc player ../include/player.h | 2107INCLUDE: $PERL $srcdir/genacc player ../include/player.h |
1985 2108
1986int invoke (player *pl, int event, ...) 2109int invoke (player *pl, int event, ...)
1987 CODE: 2110 CODE:
1988 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2111 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
1989 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2112 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1999 pl->ob->stats.hp = pl->ob->stats.maxhp; 2122 pl->ob->stats.hp = pl->ob->stats.maxhp;
2000 pl->ob->stats.sp = pl->ob->stats.maxsp; 2123 pl->ob->stats.sp = pl->ob->stats.maxsp;
2001 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2124 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2002 pl->orig_stats = pl->ob->stats; 2125 pl->orig_stats = pl->ob->stats;
2003 2126
2004player *cf_player_find (char *name)
2005 PROTOTYPE: $
2006
2007void cf_player_move (player *pl, int dir) 2127void cf_player_move (player *pl, int dir)
2008 2128
2009void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2129void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2010
2011player *first ()
2012 CODE:
2013 RETVAL = first_player;
2014 OUTPUT: RETVAL
2015 2130
2016bool 2131bool
2017cell_visible (player *pl, int dx, int dy) 2132cell_visible (player *pl, int dx, int dy)
2018 CODE: 2133 CODE:
2019 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2134 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2056 if (y) sv_to (y, pl->bed_y); 2171 if (y) sv_to (y, pl->bed_y);
2057 2172
2058void 2173void
2059list () 2174list ()
2060 PPCODE: 2175 PPCODE:
2061 for (player *pl = first_player; pl; pl = pl->next) 2176 for_all_players (pl)
2062 XPUSHs (sv_2mortal (to_sv (pl))); 2177 XPUSHs (sv_2mortal (to_sv (pl)));
2063
2064bool
2065peaceful (player *pl, bool new_setting = 0)
2066 PROTOTYPE: $;$
2067 CODE:
2068 RETVAL = pl->peaceful;
2069 if (items > 1)
2070 pl->peaceful = new_setting;
2071 OUTPUT:
2072 RETVAL
2073
2074living *
2075orig_stats (player *pl)
2076 CODE:
2077 RETVAL = &pl->orig_stats;
2078 OUTPUT: RETVAL
2079
2080living *
2081last_stats (player *pl)
2082 CODE:
2083 RETVAL = &pl->last_stats;
2084 OUTPUT: RETVAL
2085 2178
2086 2179
2087MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2180MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2088 2181
2089int invoke (maptile *map, int event, ...) 2182int invoke (maptile *map, int event, ...)
2094 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); 2187 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END);
2095 OUTPUT: RETVAL 2188 OUTPUT: RETVAL
2096 2189
2097SV *registry (maptile *map) 2190SV *registry (maptile *map)
2098 2191
2099INCLUDE: $PERL genacc maptile ../include/map.h | 2192INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h |
2100 2193
2101void 2194void
2102maptile::instantiate () 2195maptile::instantiate ()
2103 2196
2104maptile *new () 2197maptile *new ()
2105 PROTOTYPE: 2198 PROTOTYPE:
2106 CODE: 2199 CODE:
2107 RETVAL = new maptile; 2200 RETVAL = new maptile;
2108 OUTPUT: 2201 OUTPUT:
2109 RETVAL 2202 RETVAL
2110
2111void
2112maptile::destroy ()
2113 2203
2114void 2204void
2115maptile::players () 2205maptile::players ()
2116 PPCODE: 2206 PPCODE:
2117 if (GIMME_V == G_SCALAR) 2207 if (GIMME_V == G_SCALAR)
2122 for_all_players (pl) 2212 for_all_players (pl)
2123 if (pl->ob && pl->ob->map == THIS) 2213 if (pl->ob && pl->ob->map == THIS)
2124 PUSHs (sv_2mortal (to_sv (pl->ob))); 2214 PUSHs (sv_2mortal (to_sv (pl->ob)));
2125 } 2215 }
2126 2216
2217void
2218maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2219 CODE:
2220{
2221 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2222 croak ("maptile::add_underlay: palette must be arrayref");
2223
2224 palette = SvRV (palette);
2225
2226 STRLEN idxlen;
2227 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2228
2229 for (int x = 0; x < THIS->width; ++x)
2230 for (int y = 0; y < THIS->height; ++y)
2231 {
2232 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2233 if (op->flag [FLAG_IS_FLOOR])
2234 goto skip_space;
2235
2236 {
2237 int offs = offset + y * stride + x;
2238 if (IN_RANGE_EXC (offs, 0, idxlen))
2239 {
2240 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2241 {
2242 object *ob = get_archetype (SvPVutf8_nolen (*elem));
2243 ob->flag [FLAG_NO_MAP_SAVE] = true;
2244 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2245 }
2246 }
2247 }
2248
2249 skip_space: ;
2250 }
2251}
2252
2253void
2254maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2255 CODE:
2256{
2257 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2258 croak ("maptile::set_regiondata: palette must be arrayref");
2259
2260 palette = SvRV (palette);
2261
2262 STRLEN idxlen;
2263 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2264
2265 region **regionmap = (region **)malloc (
2266 (av_len ((AV *)palette) + 1) * sizeof (region *));
2267 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2268
2269 for (int i = av_len ((AV *)palette) + 1; i--; )
2270 regionmap [i] = region::find (
2271 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2272
2273 for (int y = 0; y < THIS->height; ++y)
2274 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2275
2276 sfree (THIS->regions, THIS->size ());
2277 free (THIS->regionmap);
2278
2279 THIS->regions = regions;
2280 THIS->regionmap = regionmap;
2281}
2282
2127void play_sound_map (maptile *map, int x, int y, int sound_num) 2283void play_sound_map (maptile *map, int x, int y, int sound_num)
2128 2284
2129int out_of_map (maptile *map, int x, int y) 2285int out_of_map (maptile *map, int x, int y)
2130 2286
2131void 2287void
2147 2303
2148object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) 2304object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2149 C_ARGS: str, map, nx, ny 2305 C_ARGS: str, map, nx, ny
2150 2306
2151void 2307void
2152cf_map_normalise (maptile *map, int x, int y) 2308get_map_flags (maptile *map, int x, int y)
2153 PPCODE: 2309 PPCODE:
2154{ 2310{
2155 maptile *nmap = 0; 2311 maptile *nmap = 0;
2156 I16 nx = 0, ny = 0; 2312 I16 nx = 0, ny = 0;
2157 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2313 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2206 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; 2362 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break;
2207 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; 2363 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break;
2208 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; 2364 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break;
2209 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2365 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
2210 } 2366 }
2211 OUTPUT: 2367 OUTPUT: RETVAL
2212 RETVAL
2213 2368
2214void fix_walls (maptile *map, int x, int y) 2369void fix_walls (maptile *map, int x, int y)
2215 2370
2216void fix_walls_around (maptile *map, int x, int y) 2371void fix_walls_around (maptile *map, int x, int y)
2217 2372
2218# worst xs function of my life 2373# worst xs function of my life
2219maptile * 2374bool
2220_create_random_map (\ 2375_create_random_map (\
2221 char *path,\ 2376 maptile *self,\
2222 char *wallstyle,\ 2377 utf8_string wallstyle,\
2223 char *wall_name,\ 2378 utf8_string wall_name,\
2224 char *floorstyle,\ 2379 utf8_string floorstyle,\
2225 char *monsterstyle,\ 2380 utf8_string monsterstyle,\
2226 char *treasurestyle,\ 2381 utf8_string treasurestyle,\
2227 char *layoutstyle,\ 2382 utf8_string layoutstyle,\
2228 char *doorstyle,\ 2383 utf8_string doorstyle,\
2229 char *decorstyle,\ 2384 utf8_string decorstyle,\
2230 char *origin_map,\ 2385 utf8_string origin_map,\
2231 char *final_map,\ 2386 utf8_string final_map,\
2232 char *exitstyle,\ 2387 utf8_string exitstyle,\
2233 char *this_map,\ 2388 utf8_string this_map,\
2234 char *exit_on_final_map,\ 2389 utf8_string exit_on_final_map,\
2235 int Xsize,\ 2390 int xsize,\
2236 int Ysize,\ 2391 int ysize,\
2237 int expand2x,\ 2392 int expand2x,\
2238 int layoutoptions1,\ 2393 int layoutoptions1,\
2239 int layoutoptions2,\ 2394 int layoutoptions2,\
2240 int layoutoptions3,\ 2395 int layoutoptions3,\
2241 int symmetry,\ 2396 int symmetry,\
2246 int dungeon_depth,\ 2401 int dungeon_depth,\
2247 int decoroptions,\ 2402 int decoroptions,\
2248 int orientation,\ 2403 int orientation,\
2249 int origin_y,\ 2404 int origin_y,\
2250 int origin_x,\ 2405 int origin_x,\
2251 int random_seed,\ 2406 U32 random_seed,\
2252 val64 total_map_hp,\ 2407 val64 total_map_hp,\
2253 int map_layout_style,\ 2408 int map_layout_style,\
2254 int treasureoptions,\ 2409 int treasureoptions,\
2255 int symmetry_used,\ 2410 int symmetry_used,\
2256 region *region\ 2411 region *region,\
2412 utf8_string custom\
2257) 2413)
2258 CODE: 2414 CODE:
2259{ 2415{
2260 random_map_params rmp; 2416 random_map_params rmp;
2261 2417
2265 assign (rmp.monsterstyle , monsterstyle); 2421 assign (rmp.monsterstyle , monsterstyle);
2266 assign (rmp.treasurestyle , treasurestyle); 2422 assign (rmp.treasurestyle , treasurestyle);
2267 assign (rmp.layoutstyle , layoutstyle); 2423 assign (rmp.layoutstyle , layoutstyle);
2268 assign (rmp.doorstyle , doorstyle); 2424 assign (rmp.doorstyle , doorstyle);
2269 assign (rmp.decorstyle , decorstyle); 2425 assign (rmp.decorstyle , decorstyle);
2270 assign (rmp.origin_map , origin_map);
2271 assign (rmp.final_map , final_map);
2272 assign (rmp.exitstyle , exitstyle); 2426 assign (rmp.exitstyle , exitstyle);
2273 assign (rmp.this_map , this_map);
2274 assign (rmp.exit_on_final_map, exit_on_final_map); 2427 assign (rmp.exit_on_final_map, exit_on_final_map);
2275 2428
2429 rmp.origin_map = origin_map;
2430 rmp.final_map = final_map;
2431 rmp.this_map = this_map;
2276 rmp.Xsize = Xsize; 2432 rmp.xsize = xsize;
2277 rmp.Ysize = Ysize; 2433 rmp.ysize = ysize;
2278 rmp.expand2x = expand2x; 2434 rmp.expand2x = expand2x;
2279 rmp.layoutoptions1 = layoutoptions1; 2435 rmp.layoutoptions1 = layoutoptions1;
2280 rmp.layoutoptions2 = layoutoptions2; 2436 rmp.layoutoptions2 = layoutoptions2;
2281 rmp.layoutoptions3 = layoutoptions3; 2437 rmp.layoutoptions3 = layoutoptions3;
2282 rmp.symmetry = symmetry; 2438 rmp.symmetry = symmetry;
2293 rmp.total_map_hp = total_map_hp; 2449 rmp.total_map_hp = total_map_hp;
2294 rmp.map_layout_style = map_layout_style; 2450 rmp.map_layout_style = map_layout_style;
2295 rmp.treasureoptions = treasureoptions; 2451 rmp.treasureoptions = treasureoptions;
2296 rmp.symmetry_used = symmetry_used; 2452 rmp.symmetry_used = symmetry_used;
2297 rmp.region = region; 2453 rmp.region = region;
2454 rmp.custom = custom;
2298 2455
2299 RETVAL = generate_random_map (path, &rmp); 2456 RETVAL = self->generate_random_map (&rmp);
2300} 2457}
2301 OUTPUT: 2458 OUTPUT:
2302 RETVAL 2459 RETVAL
2303 2460
2304MODULE = cf PACKAGE = cf::arch 2461MODULE = cf PACKAGE = cf::arch
2305 2462
2306archetype *find (const char *name) 2463archetype *find (utf8_string name)
2307 CODE: 2464 CODE:
2308 RETVAL = archetype::find (name); 2465 RETVAL = archetype::find (name);
2309 OUTPUT: 2466 OUTPUT:
2310 RETVAL 2467 RETVAL
2311 2468
2313 PROTOTYPE: 2470 PROTOTYPE:
2314 CODE: 2471 CODE:
2315 RETVAL = first_archetype; 2472 RETVAL = first_archetype;
2316 OUTPUT: RETVAL 2473 OUTPUT: RETVAL
2317 2474
2318INCLUDE: $PERL genacc archetype ../include/object.h | 2475INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2319 2476
2320MODULE = cf PACKAGE = cf::party 2477MODULE = cf PACKAGE = cf::party
2321 2478
2322partylist *first () 2479partylist *first ()
2323 PROTOTYPE: 2480 PROTOTYPE:
2324 CODE: 2481 CODE:
2325 RETVAL = get_firstparty (); 2482 RETVAL = get_firstparty ();
2326 OUTPUT: RETVAL 2483 OUTPUT: RETVAL
2327 2484
2328partylist *next (partylist *party) 2485INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h |
2486
2487MODULE = cf PACKAGE = cf::region
2488
2489void
2490list ()
2491 PPCODE:
2492 for_all_regions (rgn)
2493 XPUSHs (sv_2mortal (to_sv (rgn)));
2494
2495region *find (utf8_string name)
2496 PROTOTYPE: $
2329 CODE: 2497 CODE:
2330 RETVAL = party->next; 2498 RETVAL = region::find (name);
2331 OUTPUT: RETVAL 2499 OUTPUT: RETVAL
2332 2500
2333const char *name (partylist *party) 2501region *find_fuzzy (utf8_string name)
2502 PROTOTYPE: $
2334 CODE: 2503 CODE:
2335 RETVAL = party->partyname; 2504 RETVAL = region::find_fuzzy (name);
2336 OUTPUT: RETVAL 2505 OUTPUT: RETVAL
2337 2506
2338const char *password (partylist *party) 2507int specificity (region *rgn)
2339 CODE: 2508 CODE:
2340 RETVAL = party->passwd; 2509 RETVAL = 0;
2510 while (rgn = rgn->parent)
2511 RETVAL++;
2341 OUTPUT: RETVAL 2512 OUTPUT: RETVAL
2342 2513
2343MODULE = cf PACKAGE = cf::region 2514INCLUDE: $PERL $srcdir/genacc region ../include/map.h |
2344
2345region *first ()
2346 PROTOTYPE:
2347 CODE:
2348 RETVAL = first_region;
2349 OUTPUT: RETVAL
2350
2351region *next (region *reg)
2352 CODE:
2353 RETVAL = reg->next;
2354 OUTPUT: RETVAL
2355
2356const char *name (region *reg)
2357 CODE:
2358 RETVAL = reg->name;
2359 OUTPUT: RETVAL
2360
2361region *parent (region *reg)
2362 CODE:
2363 RETVAL = reg->parent;
2364 OUTPUT: RETVAL
2365
2366const char *longname (region *reg)
2367 CODE:
2368 RETVAL = reg->longname;
2369 OUTPUT: RETVAL
2370
2371const char *msg (region *reg)
2372 CODE:
2373 RETVAL = reg->msg;
2374 OUTPUT: RETVAL
2375 2515
2376MODULE = cf PACKAGE = cf::living 2516MODULE = cf PACKAGE = cf::living
2377 2517
2378INCLUDE: $PERL genacc living ../include/living.h | 2518INCLUDE: $PERL $srcdir/genacc living ../include/living.h |
2379 2519
2380MODULE = cf PACKAGE = cf::settings 2520MODULE = cf PACKAGE = cf::settings
2381 2521
2382INCLUDE: $PERL genacc Settings ../include/global.h | 2522INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h |
2383 2523
2384MODULE = cf PACKAGE = cf::client 2524MODULE = cf PACKAGE = cf::client
2385 2525
2386INCLUDE: $PERL genacc client ../include/client.h | 2526INCLUDE: $PERL $srcdir/genacc client ../include/client.h |
2387 2527
2388int invoke (client *ns, int event, ...) 2528int invoke (client *ns, int event, ...)
2389 CODE: 2529 CODE:
2390 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); 2530 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2391 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2531 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2410 char *buf = SvPVbyte (packet, len); 2550 char *buf = SvPVbyte (packet, len);
2411 2551
2412 THIS->send_packet (buf, len); 2552 THIS->send_packet (buf, len);
2413} 2553}
2414 2554
2415void 2555MODULE = cf PACKAGE = cf::face PREFIX = face_
2416client::destroy ()
2417 2556
2557#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2558
2559faceidx face_find (utf8_string name, faceidx defidx = 0)
2560
2561faceidx alloc (utf8_string name)
2562 CODE:
2563{
2564 do
2565 {
2566 RETVAL = faces.size ();
2567 faces.resize (RETVAL + 1);
2568 }
2569 while (!RETVAL); // crude way to leave index 0
2570
2571 faces [RETVAL].name = name;
2572 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2573
2574 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2575 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2576}
2577 OUTPUT: RETVAL
2578
2579void set (faceidx idx, int visibility, int magicmap)
2580 CODE:
2581 faceinfo *f = face_info (idx);
2582 assert (f);
2583 f->visibility = visibility;
2584 f->magicmap = magicmap;
2585
2586void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2587 CODE:
2588 faceinfo *f = face_info (idx); assert (f);
2589 f->smooth = smooth;
2590 f->smoothlevel = smoothlevel;
2591
2592void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2593 CODE:
2594{
2595 facedata *d = face_data (idx, faceset);
2596 assert (d);
2597 sv_to (data, d->data);
2598 STRLEN clen;
2599 char *cdata = SvPVbyte (chksum, clen);
2600 clen = min (CHKSUM_SIZE, clen);
2601
2602 if (memcmp (d->chksum, cdata, clen))
2603 {
2604 memcpy (d->chksum, cdata, clen);
2605
2606 // invalidate existing client face info
2607 for_all_clients (ns)
2608 if (ns->faceset == faceset)
2609 {
2610 ns->faces_sent [idx] = false;
2611 ns->force_newmap = true;
2612 }
2613 }
2614}
2615
2616void invalidate (faceidx idx)
2617 CODE:
2618 for_all_clients (ns)
2619 {
2620 ns->faces_sent [idx] = false;
2621 ns->force_newmap = true;
2622 }
2623
2624void invalidate_all ()
2625 CODE:
2626 for_all_clients (ns)
2627 {
2628 ns->faces_sent.reset ();
2629 ns->force_newmap = true;
2630 }
2631
2632MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2633
2634#INCLUDE: $PERL $srcdir/genacc faceset ../include/anim.h |
2635
2636animidx anim_find (utf8_string name)
2637 CODE:
2638 RETVAL = animation::find (name).number;
2639 OUTPUT: RETVAL
2640
2641animidx set (utf8_string name, SV *frames, int facings = 1)
2642 CODE:
2643{
2644 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2645 croak ("frames must be an arrayref");
2646
2647 AV *av = (AV *)SvRV (frames);
2648
2649 animation *anim = &animation::find (name);
2650 if (anim->number)
2651 {
2652 anim->resize (av_len (av) + 1);
2653 anim->facings = facings;
2654 }
2655 else
2656 anim = &animation::create (name, av_len (av) + 1, facings);
2657
2658 for (int i = 0; i < anim->num_animations; ++i)
2659 anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1)));
2660}
2661 OUTPUT: RETVAL
2662
2663void invalidate_all ()
2664 CODE:
2665 for_all_clients (ns)
2666 ns->anims_sent.reset ();
2667

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines