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.119 by root, Sun Dec 31 10:28:36 2006 UTC vs.
Revision 1.186 by root, Sat Apr 14 07:23:00 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 = find_treasurelist (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::load_map_sync (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::load_map_sync", 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);
845 retval = 0; 891 retval = 0;
846 892
847 CALL_END; 893 CALL_END;
848 894
849 return retval; 895 return retval;
896}
897
898maptile *
899maptile::find_async (const char *path, maptile *origin)
900{
901 CALL_BEGIN (2);
902 CALL_ARG (path);
903 CALL_ARG (origin);
904 CALL_CALL ("cf::map::find_async", G_SCALAR);
905
906 maptile *retval;
907
908 if (count)
909 sv_to (POPs, retval);
910 else
911 retval = 0;
912
913 CALL_END;
914
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;
850} 925}
851 926
852void 927void
853maptile::change_all_map_light (int change) 928maptile::change_all_map_light (int change)
854{ 929{
874///////////////////////////////////////////////////////////////////////////// 949/////////////////////////////////////////////////////////////////////////////
875 950
876struct EventAPI *watcher_base::GEventAPI; 951struct EventAPI *watcher_base::GEventAPI;
877struct CoroAPI *coroapi::GCoroAPI; 952struct CoroAPI *coroapi::GCoroAPI;
878 953
954int coroapi::cede_counter;
955
879static void iw_dispatch (pe_event *ev) 956static void iw_dispatch (pe_event *ev)
880{ 957{
881 iw *w = (iw *)ev->ext_data; 958 iw *w = (iw *)ev->ext_data;
882 w->call (*w); 959 w->call (*w);
883} 960}
885void 962void
886iw::alloc () 963iw::alloc ()
887{ 964{
888 pe = GEventAPI->new_idle (0, 0); 965 pe = GEventAPI->new_idle (0, 0);
889 966
967 WaREENTRANT_off (pe);
890 pe->base.callback = (void *)iw_dispatch; 968 pe->base.callback = (void *)iw_dispatch;
891 pe->base.ext_data = (void *)this; 969 pe->base.ext_data = (void *)this;
892} 970}
893 971
894static void iow_dispatch (pe_event *ev) 972static void iow_dispatch (pe_event *ev)
900void 978void
901iow::alloc () 979iow::alloc ()
902{ 980{
903 pe = GEventAPI->new_io (0, 0); 981 pe = GEventAPI->new_io (0, 0);
904 982
983 WaREENTRANT_off (pe);
905 pe->base.callback = (void *)iow_dispatch; 984 pe->base.callback = (void *)iow_dispatch;
906 pe->base.ext_data = (void *)this; 985 pe->base.ext_data = (void *)this;
907 986
908 pe->fd = -1; 987 pe->fd = -1;
909 pe->poll = 0; 988 pe->poll = 0;
977# define const_iv(name) { # name, (IV)name }, 1056# define const_iv(name) { # name, (IV)name },
978 const_iv (llevError) 1057 const_iv (llevError)
979 const_iv (llevInfo) 1058 const_iv (llevInfo)
980 const_iv (llevDebug) 1059 const_iv (llevDebug)
981 const_iv (llevMonster) 1060 const_iv (llevMonster)
1061
1062 const_iv (Map0Cmd)
1063 const_iv (Map1Cmd)
1064 const_iv (Map1aCmd)
1065
1066 const_iv (MAP_CLIENT_X)
1067 const_iv (MAP_CLIENT_Y)
982 1068
983 const_iv (MAX_TIME) 1069 const_iv (MAX_TIME)
984 const_iv (PLAYER) 1070 const_iv (PLAYER)
985 const_iv (TRANSPORT) 1071 const_iv (TRANSPORT)
986 const_iv (ROD) 1072 const_iv (ROD)
1237 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1323 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1238 const_iv (FLAG_IS_WATER) 1324 const_iv (FLAG_IS_WATER)
1239 const_iv (FLAG_CONTENT_ON_GEN) 1325 const_iv (FLAG_CONTENT_ON_GEN)
1240 const_iv (FLAG_IS_A_TEMPLATE) 1326 const_iv (FLAG_IS_A_TEMPLATE)
1241 const_iv (FLAG_IS_BUILDABLE) 1327 const_iv (FLAG_IS_BUILDABLE)
1328 const_iv (FLAG_DESTROY_ON_DEATH)
1329 const_iv (FLAG_NO_MAP_SAVE)
1242 1330
1243 const_iv (NDI_BLACK) 1331 const_iv (NDI_BLACK)
1244 const_iv (NDI_WHITE) 1332 const_iv (NDI_WHITE)
1245 const_iv (NDI_NAVY) 1333 const_iv (NDI_NAVY)
1246 const_iv (NDI_RED) 1334 const_iv (NDI_RED)
1288 const_iv (P_BLOCKSVIEW) 1376 const_iv (P_BLOCKSVIEW)
1289 const_iv (P_PLAYER) 1377 const_iv (P_PLAYER)
1290 const_iv (P_NO_MAGIC) 1378 const_iv (P_NO_MAGIC)
1291 const_iv (P_IS_ALIVE) 1379 const_iv (P_IS_ALIVE)
1292 const_iv (P_NO_CLERIC) 1380 const_iv (P_NO_CLERIC)
1293 const_iv (P_NEED_UPDATE)
1294 const_iv (P_OUT_OF_MAP) 1381 const_iv (P_OUT_OF_MAP)
1295 const_iv (P_NEW_MAP) 1382 const_iv (P_NEW_MAP)
1383 const_iv (P_UPTODATE)
1296 1384
1297 const_iv (UP_OBJ_INSERT) 1385 const_iv (UP_OBJ_INSERT)
1298 const_iv (UP_OBJ_REMOVE) 1386 const_iv (UP_OBJ_REMOVE)
1299 const_iv (UP_OBJ_CHANGE) 1387 const_iv (UP_OBJ_CHANGE)
1300 const_iv (UP_OBJ_FACE) 1388 const_iv (UP_OBJ_FACE)
1431 const_iv (ATNR_BLIND) 1519 const_iv (ATNR_BLIND)
1432 const_iv (ATNR_INTERNAL) 1520 const_iv (ATNR_INTERNAL)
1433 const_iv (ATNR_LIFE_STEALING) 1521 const_iv (ATNR_LIFE_STEALING)
1434 const_iv (ATNR_DISEASE) 1522 const_iv (ATNR_DISEASE)
1435 1523
1436 const_iv (MAP_FLUSH)
1437 const_iv (MAP_PLAYER_UNIQUE)
1438 const_iv (MAP_BLOCK)
1439 const_iv (MAP_STYLE)
1440 const_iv (MAP_OVERLAY)
1441
1442 const_iv (MAP_IN_MEMORY) 1524 const_iv (MAP_IN_MEMORY)
1443 const_iv (MAP_SWAPPED) 1525 const_iv (MAP_SWAPPED)
1444 const_iv (MAP_LOADING) 1526 const_iv (MAP_LOADING)
1445 const_iv (MAP_SAVING) 1527 const_iv (MAP_SAVING)
1446 1528
1459 const_iv (ST_SETUP) 1541 const_iv (ST_SETUP)
1460 const_iv (ST_PLAYING) 1542 const_iv (ST_PLAYING)
1461 const_iv (ST_CUSTOM) 1543 const_iv (ST_CUSTOM)
1462 1544
1463 const_iv (ST_CHANGE_CLASS) 1545 const_iv (ST_CHANGE_CLASS)
1464 const_iv (ST_CONFIRM_QUIT)
1465 const_iv (ST_GET_PARTY_PASSWORD)
1466 1546
1467 const_iv (IO_HEADER) 1547 const_iv (IO_HEADER)
1468 const_iv (IO_OBJECTS) 1548 const_iv (IO_OBJECTS)
1469 const_iv (IO_UNIQUES) 1549 const_iv (IO_UNIQUES)
1470 1550
1524 1604
1525void _global_reattach () 1605void _global_reattach ()
1526 CODE: 1606 CODE:
1527{ 1607{
1528 // reattach to all attachable objects in the game. 1608 // reattach to all attachable objects in the game.
1529 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 1609 for_all_clients (ns)
1530 (*i)->reattach (); 1610 ns->reattach ();
1531 1611
1532 for_all_players (pl) 1612 for_all_objects (op)
1533 pl->reattach ();
1534
1535 //TODO
1536 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i)
1537 // i->second->reattach ();
1538
1539 for (object *op = object::first; op; op = op->next)
1540 op->reattach (); 1613 op->reattach ();
1541} 1614}
1542 1615
1543NV floor (NV x) 1616NV floor (NV x)
1544 1617
1545NV ceil (NV x) 1618NV ceil (NV x)
1619
1620NV rndm (...)
1621 CODE:
1622 switch (items)
1623 {
1624 case 0: RETVAL = rndm (); break;
1625 case 1: RETVAL = rndm (SvUV (ST (0))); break;
1626 case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break;
1627 default: croak ("cf::rndm requires none, one or two parameters."); break;
1628 }
1629 OUTPUT:
1630 RETVAL
1546 1631
1547void server_tick () 1632void server_tick ()
1548 CODE: 1633 CODE:
1549 runtime = SvNVx (sv_runtime); 1634 runtime = SvNVx (sv_runtime);
1550 server_tick (); 1635 server_tick ();
1551 1636
1552void 1637void
1553LOG (int level, char *msg) 1638LOG (int level, utf8_string msg)
1554 PROTOTYPE: $$ 1639 PROTOTYPE: $$
1555 C_ARGS: (LogLevel)level, "%s", msg 1640 C_ARGS: (LogLevel)level, "%s", msg
1556 1641
1557char *path_combine (char *base, char *path) 1642octet_string path_combine (octet_string base, octet_string path)
1558 PROTOTYPE: $$ 1643 PROTOTYPE: $$
1559 1644
1560char *path_combine_and_normalize (char *base, char *path) 1645octet_string path_combine_and_normalize (octet_string base, octet_string path)
1561 PROTOTYPE: $$ 1646 PROTOTYPE: $$
1562 1647
1563const char * 1648const_octet_string
1564get_maps_directory (char *path) 1649get_maps_directory (octet_string path)
1565 PROTOTYPE: $ 1650 PROTOTYPE: $
1566 ALIAS: maps_directory = 0 1651 ALIAS: maps_directory = 0
1567 CODE: 1652 CODE:
1568 RETVAL = create_pathname (path); 1653 RETVAL = create_pathname (path);
1569 OUTPUT: RETVAL 1654 OUTPUT: RETVAL
1571void 1656void
1572sub_generation_inc () 1657sub_generation_inc ()
1573 CODE: 1658 CODE:
1574 PL_sub_generation++; 1659 PL_sub_generation++;
1575 1660
1576char * 1661const_octet_string
1577mapdir () 1662mapdir ()
1578 PROTOTYPE: 1663 PROTOTYPE:
1579 ALIAS: 1664 ALIAS:
1580 mapdir = 0 1665 mapdir = 0
1581 uniquedir = 1 1666 uniquedir = 1
1595 case 5: RETVAL = settings.playerdir; break; 1680 case 5: RETVAL = settings.playerdir; break;
1596 case 6: RETVAL = settings.datadir ; break; 1681 case 6: RETVAL = settings.datadir ; break;
1597 } 1682 }
1598 OUTPUT: RETVAL 1683 OUTPUT: RETVAL
1599 1684
1685void abort ()
1686
1687void fork_abort (octet_string cause = "cf::fork_abort")
1688
1689void cleanup (octet_string cause, bool make_core = false)
1690
1600void emergency_save () 1691void emergency_save ()
1601 1692
1602void _exit (int status = 0) 1693void _exit (int status = EXIT_SUCCESS)
1603 1694
1695UV sv_2watcher (SV *w)
1696 CODE:
1697 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1698 OUTPUT:
1699 RETVAL
1700
1701#if _POSIX_MEMLOCK
1702
1703int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1704
1705int munlockall ()
1706
1707#endif
1708
1604int find_animation (char *text) 1709int find_animation (utf8_string text)
1605 PROTOTYPE: $ 1710 PROTOTYPE: $
1606 1711
1607int random_roll (int min, int max, object *op, int goodbad); 1712int random_roll (int min, int max, object *op, int goodbad);
1608 1713
1609const char *cost_string_from_value(uint64 cost, int approx = 0) 1714const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1610 1715
1611int 1716int
1612exp_to_level (val64 exp) 1717exp_to_level (val64 exp)
1613 CODE: 1718 CODE:
1614{ 1719{
1645 RETVAL = newSVpv (resist_plus[atnr], 0); 1750 RETVAL = newSVpv (resist_plus[atnr], 0);
1646 else 1751 else
1647 XSRETURN_UNDEF; 1752 XSRETURN_UNDEF;
1648 OUTPUT: RETVAL 1753 OUTPUT: RETVAL
1649 1754
1755bool
1756load_resource_file (octet_string filename)
1757
1650MODULE = cf PACKAGE = cf::attachable 1758MODULE = cf PACKAGE = cf::attachable
1651 1759
1652int 1760int
1653valid (SV *obj) 1761valid (SV *obj)
1654 CODE: 1762 CODE:
1655 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1763 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1656 OUTPUT: 1764 OUTPUT:
1657 RETVAL 1765 RETVAL
1658 1766
1659#bool
1660#destroyed (attachable *at)
1661#
1662#void 1767void
1663#destroy (attachable *at) 1768debug_trace (attachable *obj, bool on = true)
1769 CODE:
1770 obj->flags &= ~attachable::F_DEBUG_TRACE;
1771 if (on)
1772 obj->flags |= attachable::F_DEBUG_TRACE;
1773
1774int mortals_size ()
1775 CODE:
1776 RETVAL = attachable::mortals.size ();
1777 OUTPUT: RETVAL
1778
1779#object *mortals (U32 index)
1780# CODE:
1781# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0;
1782# OUTPUT: RETVAL
1783
1784INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h |
1664 1785
1665MODULE = cf PACKAGE = cf::global 1786MODULE = cf PACKAGE = cf::global
1666 1787
1667int invoke (SV *klass, int event, ...) 1788int invoke (SV *klass, int event, ...)
1668 CODE: 1789 CODE:
1672 RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); 1793 RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END);
1673 OUTPUT: RETVAL 1794 OUTPUT: RETVAL
1674 1795
1675MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1796MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1676 1797
1677INCLUDE: $PERL genacc object ../include/object.h | 1798INCLUDE: $PERL $srcdir/genacc object ../include/object.h |
1678 1799
1679int invoke (object *op, int event, ...) 1800int invoke (object *op, int event, ...)
1680 CODE: 1801 CODE:
1681 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); 1802 if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT");
1682 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 1803 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1684 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); 1805 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END);
1685 OUTPUT: RETVAL 1806 OUTPUT: RETVAL
1686 1807
1687SV *registry (object *op) 1808SV *registry (object *op)
1688 1809
1689void mortals () 1810int objects_size ()
1690 PPCODE: 1811 CODE:
1691 EXTEND (SP, object::mortals.size ());
1692 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1693 PUSHs (to_sv (*i));
1694
1695object *first ()
1696 CODE:
1697 RETVAL = object::first; 1812 RETVAL = objects.size ();
1813 OUTPUT: RETVAL
1814
1815object *objects (U32 index)
1816 CODE:
1817 RETVAL = index < objects.size () ? objects [index] : 0;
1818 OUTPUT: RETVAL
1819
1820int actives_size ()
1821 CODE:
1822 RETVAL = actives.size ();
1823 OUTPUT: RETVAL
1824
1825object *actives (U32 index)
1826 CODE:
1827 RETVAL = index < actives.size () ? actives [index] : 0;
1698 OUTPUT: RETVAL 1828 OUTPUT: RETVAL
1699 1829
1700# missing properties 1830# missing properties
1701 1831
1702object *head (object *op) 1832object *head (object *op)
1703 PROTOTYPE: $ 1833 PROTOTYPE: $
1704 CODE: 1834 CODE:
1705 RETVAL = op->head ? op->head : op; 1835 RETVAL = op->head_ ();
1706 OUTPUT: RETVAL 1836 OUTPUT: RETVAL
1707 1837
1708int is_head (object *op) 1838int is_head (object *op)
1709 PROTOTYPE: $ 1839 PROTOTYPE: $
1710 CODE: 1840 CODE:
1711 RETVAL = !op->head; 1841 RETVAL = op->head_ () == op;
1712 OUTPUT: RETVAL 1842 OUTPUT: RETVAL
1713 1843
1714void 1844void
1715inv (object *obj) 1845inv (object *obj)
1716 PROTOTYPE: $ 1846 PROTOTYPE: $
1724void 1854void
1725set_animation (object *op, int idx) 1855set_animation (object *op, int idx)
1726 CODE: 1856 CODE:
1727 SET_ANIMATION (op, idx); 1857 SET_ANIMATION (op, idx);
1728 1858
1859int
1860num_animations (object *op)
1861 CODE:
1862 RETVAL = NUM_ANIMATIONS (op);
1863 OUTPUT: RETVAL
1864
1729object *find_best_object_match (object *op, const char *match) 1865object *find_best_object_match (object *op, utf8_string match)
1730 1866
1731object *find_marked_object (object *op) 1867object *find_marked_object (object *op)
1732 1868
1733int need_identify (object *obj); 1869int need_identify (object *obj);
1734 1870
1735int apply_shop_mat (object *shop_mat, object *op); 1871int apply_shop_mat (object *shop_mat, object *op);
1872
1873int move_player (object *op, int dir)
1874 CODE:
1875 RETVAL = move_player (op, dir);
1876 OUTPUT:
1877 RETVAL
1736 1878
1737int move (object *op, int dir, object *originator = op) 1879int move (object *op, int dir, object *originator = op)
1738 CODE: 1880 CODE:
1739 RETVAL = move_ob (op, dir, originator); 1881 RETVAL = move_ob (op, dir, originator);
1740 OUTPUT: 1882 OUTPUT:
1746 1888
1747void apply_below (object *op) 1889void apply_below (object *op)
1748 CODE: 1890 CODE:
1749 player_apply_below (op); 1891 player_apply_below (op);
1750 1892
1893int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1894
1751object *cf_object_present_archname_inside (object *op, char *whatstr) 1895object *cf_object_present_archname_inside (object *op, utf8_string whatstr)
1752 1896
1753int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1897int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1754 1898
1755int cf_object_change_map (object *op, int x, int y, maptile *map) 1899int cf_object_change_map (object *op, int x, int y, maptile *map)
1756 1900
1776 RETVAL = pay_for_amount (amount, op); 1920 RETVAL = pay_for_amount (amount, op);
1777 OUTPUT: RETVAL 1921 OUTPUT: RETVAL
1778 1922
1779void pay_player (object *op, uint64 amount) 1923void pay_player (object *op, uint64 amount)
1780 1924
1781val64 pay_player_arch (object *op, const char *arch, uint64 amount) 1925val64 pay_player_arch (object *op, utf8_string arch, uint64 amount)
1782 1926
1783int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0) 1927int cast_spell (object *op, object *caster, int dir, object *spell_ob, utf8_string stringarg = 0)
1784 1928
1785void learn_spell (object *op, object *sp, int special_prayer = 0) 1929void learn_spell (object *op, object *sp, int special_prayer = 0)
1786 CODE: 1930 CODE:
1787 do_learn_spell (op, sp, special_prayer); 1931 do_learn_spell (op, sp, special_prayer);
1788 1932
1789void forget_spell (object *op, object *sp) 1933void forget_spell (object *op, object *sp)
1790 CODE: 1934 CODE:
1791 do_forget_spell (op, query_name (sp)); 1935 do_forget_spell (op, query_name (sp));
1792 1936
1793object *check_for_spell (object *op, char *spellname) 1937object *check_for_spell (object *op, utf8_string spellname)
1794 CODE: 1938 CODE:
1795 RETVAL = check_spell_known (op, spellname); 1939 RETVAL = check_spell_known (op, spellname);
1796 OUTPUT: RETVAL 1940 OUTPUT: RETVAL
1797 1941
1798int query_money (object *op) 1942int query_money (object *op)
1807 1951
1808void drop (object *who, object *op) 1952void drop (object *who, object *op)
1809 1953
1810void pick_up (object *who, object *op) 1954void pick_up (object *who, object *op)
1811 1955
1812object *cf_object_insert_object (object *op, object *container)
1813
1814object *cf_object_insert_in_ob (object *ob, object *where)
1815
1816int cf_object_teleport (object *op, maptile *map, int x, int y) 1956int cf_object_teleport (object *op, maptile *map, int x, int y)
1817 1957
1818void update_object (object *op, int action) 1958void update_object (object *op, int action)
1819 1959
1820object *cf_create_object_by_name (const char *name) 1960object *cf_create_object_by_name (utf8_string name)
1821 1961
1822void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1962void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0)
1823 1963
1824void player_lvl_adj (object *who, object *skill = 0) 1964void player_lvl_adj (object *who, object *skill = 0)
1825 1965
1826int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1966int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
1827 1967
1841object *cf_insert_ob_in_ob (object *ob, object *where) 1981object *cf_insert_ob_in_ob (object *ob, object *where)
1842 1982
1843# no clean way to get an object from an archetype - stupid idiotic 1983# no clean way to get an object from an archetype - stupid idiotic
1844# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1984# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1845 1985
1846object *new (const char *archetype = 0) 1986object *new (utf8_string archetype = 0)
1847 PROTOTYPE: ;$ 1987 PROTOTYPE: ;$
1848 CODE: 1988 CODE:
1849 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1989 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1850 OUTPUT: 1990 OUTPUT:
1851 RETVAL 1991 RETVAL
1856{ 1996{
1857 int unused_type; 1997 int unused_type;
1858 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 1998 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1859} 1999}
1860 2000
1861# syntatic sugar for easier use in event callbacks.
1862const char *options (object *op)
1863 CODE:
1864 RETVAL = op->name;
1865 OUTPUT:
1866 RETVAL
1867
1868player *contr (object *op) 2001player *contr (object *op)
1869 CODE: 2002 CODE:
1870 RETVAL = op->contr; 2003 RETVAL = op->contr;
1871 OUTPUT: RETVAL 2004 OUTPUT: RETVAL
1872 2005
1873const char *get_ob_key_value (object *op, const char *key) 2006const_utf8_string get_ob_key_value (object *op, utf8_string key)
1874 2007
1875bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 2008bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
1876 2009
1877object *get_nearest_player (object *ob) 2010object *get_nearest_player (object *ob)
1878 ALIAS: nearest_player = 0 2011 ALIAS: nearest_player = 0
1879 PREINIT: 2012 PREINIT:
1880 extern object *get_nearest_player (object *); 2013 extern object *get_nearest_player (object *);
1896bool on_same_map_as (object *ob, object *other) 2029bool on_same_map_as (object *ob, object *other)
1897 CODE: 2030 CODE:
1898 RETVAL = on_same_map (ob, other); 2031 RETVAL = on_same_map (ob, other);
1899 OUTPUT: RETVAL 2032 OUTPUT: RETVAL
1900 2033
1901const char * 2034const_utf8_string
1902base_name (object *op, int plural = op->nrof > 1) 2035base_name (object *op, int plural = op->nrof > 1)
1903 CODE: 2036 CODE:
1904 RETVAL = query_base_name (op, plural); 2037 RETVAL = query_base_name (op, plural);
1905 OUTPUT: RETVAL 2038 OUTPUT: RETVAL
1906 2039
1913 RETVAL = op->contr; 2046 RETVAL = op->contr;
1914 OUTPUT: RETVAL 2047 OUTPUT: RETVAL
1915 2048
1916void check_score (object *op) 2049void check_score (object *op)
1917 2050
1918void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2051void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2052 CODE:
2053 new_draw_info (flags, 0, op, txt);
1919 2054
1920object *cf_player_send_inventory (object *op) 2055object *cf_player_send_inventory (object *op)
1921 2056
1922char *cf_player_get_ip (object *op) 2057octet_string cf_player_get_ip (object *op)
1923 ALIAS: ip = 0 2058 ALIAS: ip = 0
1924 2059
1925object *cf_player_get_marked_item (object *op) 2060object *cf_player_get_marked_item (object *op)
1926 ALIAS: marked_item = 0 2061 ALIAS: marked_item = 0
1927 2062
1937void esrv_update_item (object *op, int what, object *item) 2072void esrv_update_item (object *op, int what, object *item)
1938 C_ARGS: what, op, item 2073 C_ARGS: what, op, item
1939 2074
1940void clear_los (object *op) 2075void clear_los (object *op)
1941 2076
1942int command_teleport (object *op, char *params)
1943
1944int command_summon (object *op, char *params) 2077int command_summon (object *op, utf8_string params)
1945 2078
1946int command_arrest (object *op, char *params) 2079int command_arrest (object *op, utf8_string params)
1947
1948int command_kick (object *op, char *params)
1949
1950int command_banish (object *op, char *params)
1951 2080
1952 2081
1953MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2082MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1954 2083
1955INCLUDE: $PERL genacc player ../include/player.h | 2084INCLUDE: $PERL $srcdir/genacc player ../include/player.h |
1956 2085
1957int invoke (player *pl, int event, ...) 2086int invoke (player *pl, int event, ...)
1958 CODE: 2087 CODE:
1959 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2088 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
1960 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2089 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1970 pl->ob->stats.hp = pl->ob->stats.maxhp; 2099 pl->ob->stats.hp = pl->ob->stats.maxhp;
1971 pl->ob->stats.sp = pl->ob->stats.maxsp; 2100 pl->ob->stats.sp = pl->ob->stats.maxsp;
1972 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2101 pl->ob->stats.grace = pl->ob->stats.maxgrace;
1973 pl->orig_stats = pl->ob->stats; 2102 pl->orig_stats = pl->ob->stats;
1974 2103
1975player *cf_player_find (char *name)
1976 PROTOTYPE: $
1977
1978void cf_player_move (player *pl, int dir) 2104void cf_player_move (player *pl, int dir)
1979 2105
1980void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2106void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1981
1982player *first ()
1983 CODE:
1984 RETVAL = first_player;
1985 OUTPUT: RETVAL
1986 2107
1987bool 2108bool
1988cell_visible (player *pl, int dx, int dy) 2109cell_visible (player *pl, int dx, int dy)
1989 CODE: 2110 CODE:
1990 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2111 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2027 if (y) sv_to (y, pl->bed_y); 2148 if (y) sv_to (y, pl->bed_y);
2028 2149
2029void 2150void
2030list () 2151list ()
2031 PPCODE: 2152 PPCODE:
2032 for (player *pl = first_player; pl; pl = pl->next) 2153 for_all_players (pl)
2033 XPUSHs (sv_2mortal (to_sv (pl))); 2154 XPUSHs (sv_2mortal (to_sv (pl)));
2034
2035bool
2036peaceful (player *pl, bool new_setting = 0)
2037 PROTOTYPE: $;$
2038 CODE:
2039 RETVAL = pl->peaceful;
2040 if (items > 1)
2041 pl->peaceful = new_setting;
2042 OUTPUT:
2043 RETVAL
2044
2045living *
2046orig_stats (player *pl)
2047 CODE:
2048 RETVAL = &pl->orig_stats;
2049 OUTPUT: RETVAL
2050
2051living *
2052last_stats (player *pl)
2053 CODE:
2054 RETVAL = &pl->last_stats;
2055 OUTPUT: RETVAL
2056 2155
2057 2156
2058MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 2157MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
2059 2158
2060int invoke (maptile *map, int event, ...) 2159int invoke (maptile *map, int event, ...)
2065 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); 2164 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END);
2066 OUTPUT: RETVAL 2165 OUTPUT: RETVAL
2067 2166
2068SV *registry (maptile *map) 2167SV *registry (maptile *map)
2069 2168
2070INCLUDE: $PERL genacc maptile ../include/map.h | 2169INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h |
2071 2170
2072void 2171void
2073maptile::instantiate () 2172maptile::instantiate ()
2074 2173
2075maptile *new () 2174maptile *new ()
2076 PROTOTYPE: 2175 PROTOTYPE:
2077 CODE: 2176 CODE:
2078 RETVAL = new maptile; 2177 RETVAL = new maptile;
2079 OUTPUT: 2178 OUTPUT:
2080 RETVAL 2179 RETVAL
2081
2082void
2083maptile::destroy ()
2084 2180
2085void 2181void
2086maptile::players () 2182maptile::players ()
2087 PPCODE: 2183 PPCODE:
2088 if (GIMME_V == G_SCALAR) 2184 if (GIMME_V == G_SCALAR)
2093 for_all_players (pl) 2189 for_all_players (pl)
2094 if (pl->ob && pl->ob->map == THIS) 2190 if (pl->ob && pl->ob->map == THIS)
2095 PUSHs (sv_2mortal (to_sv (pl->ob))); 2191 PUSHs (sv_2mortal (to_sv (pl->ob)));
2096 } 2192 }
2097 2193
2194void
2195maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2196 CODE:
2197{
2198 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2199 croak ("maptile::add_underlay: palette must be arrayref");
2200
2201 palette = SvRV (palette);
2202
2203 STRLEN idxlen;
2204 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2205
2206 for (int x = 0; x < THIS->width; ++x)
2207 for (int y = 0; y < THIS->height; ++y)
2208 {
2209 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2210 if (op->flag [FLAG_IS_FLOOR])
2211 goto skip_space;
2212
2213 {
2214 int offs = offset + y * stride + x;
2215 if (IN_RANGE_EXC (offs, 0, idxlen))
2216 {
2217 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2218 {
2219 object *ob = get_archetype (SvPVutf8_nolen (*elem));
2220 ob->flag [FLAG_NO_MAP_SAVE] = true;
2221 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2222 }
2223 }
2224 }
2225
2226 skip_space: ;
2227 }
2228}
2229
2230void
2231maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2232 CODE:
2233{
2234 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2235 croak ("maptile::set_regiondata: palette must be arrayref");
2236
2237 palette = SvRV (palette);
2238
2239 STRLEN idxlen;
2240 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2241
2242 region **regionmap = (region **)malloc (
2243 (av_len ((AV *)palette) + 1) * sizeof (region *));
2244 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2245
2246 for (int i = av_len ((AV *)palette) + 1; i--; )
2247 regionmap [i] = region::find (
2248 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2249
2250 for (int y = 0; y < THIS->height; ++y)
2251 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2252
2253 sfree (THIS->regions, THIS->size ());
2254 free (THIS->regionmap);
2255
2256 THIS->regions = regions;
2257 THIS->regionmap = regionmap;
2258}
2259
2098void play_sound_map (maptile *map, int x, int y, int sound_num) 2260void play_sound_map (maptile *map, int x, int y, int sound_num)
2099 2261
2100int out_of_map (maptile *map, int x, int y) 2262int out_of_map (maptile *map, int x, int y)
2101 2263
2102void 2264void
2118 2280
2119object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) 2281object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2120 C_ARGS: str, map, nx, ny 2282 C_ARGS: str, map, nx, ny
2121 2283
2122void 2284void
2123cf_map_normalise (maptile *map, int x, int y) 2285get_map_flags (maptile *map, int x, int y)
2124 PPCODE: 2286 PPCODE:
2125{ 2287{
2126 maptile *nmap = 0; 2288 maptile *nmap = 0;
2127 I16 nx = 0, ny = 0; 2289 I16 nx = 0, ny = 0;
2128 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2290 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2177 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; 2339 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break;
2178 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; 2340 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break;
2179 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; 2341 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break;
2180 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2342 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
2181 } 2343 }
2182 OUTPUT: 2344 OUTPUT: RETVAL
2183 RETVAL
2184 2345
2185void fix_walls (maptile *map, int x, int y) 2346void fix_walls (maptile *map, int x, int y)
2186 2347
2187void fix_walls_around (maptile *map, int x, int y) 2348void fix_walls_around (maptile *map, int x, int y)
2188 2349
2189# worst xs function of my life 2350# worst xs function of my life
2190maptile * 2351bool
2191_create_random_map (\ 2352_create_random_map (\
2192 char *path,\ 2353 maptile *self,\
2193 char *wallstyle,\ 2354 utf8_string wallstyle,\
2194 char *wall_name,\ 2355 utf8_string wall_name,\
2195 char *floorstyle,\ 2356 utf8_string floorstyle,\
2196 char *monsterstyle,\ 2357 utf8_string monsterstyle,\
2197 char *treasurestyle,\ 2358 utf8_string treasurestyle,\
2198 char *layoutstyle,\ 2359 utf8_string layoutstyle,\
2199 char *doorstyle,\ 2360 utf8_string doorstyle,\
2200 char *decorstyle,\ 2361 utf8_string decorstyle,\
2201 char *origin_map,\ 2362 utf8_string origin_map,\
2202 char *final_map,\ 2363 utf8_string final_map,\
2203 char *exitstyle,\ 2364 utf8_string exitstyle,\
2204 char *this_map,\ 2365 utf8_string this_map,\
2205 char *exit_on_final_map,\ 2366 utf8_string exit_on_final_map,\
2206 int Xsize,\ 2367 int xsize,\
2207 int Ysize,\ 2368 int ysize,\
2208 int expand2x,\ 2369 int expand2x,\
2209 int layoutoptions1,\ 2370 int layoutoptions1,\
2210 int layoutoptions2,\ 2371 int layoutoptions2,\
2211 int layoutoptions3,\ 2372 int layoutoptions3,\
2212 int symmetry,\ 2373 int symmetry,\
2217 int dungeon_depth,\ 2378 int dungeon_depth,\
2218 int decoroptions,\ 2379 int decoroptions,\
2219 int orientation,\ 2380 int orientation,\
2220 int origin_y,\ 2381 int origin_y,\
2221 int origin_x,\ 2382 int origin_x,\
2222 int random_seed,\ 2383 U32 random_seed,\
2223 val64 total_map_hp,\ 2384 val64 total_map_hp,\
2224 int map_layout_style,\ 2385 int map_layout_style,\
2225 int treasureoptions,\ 2386 int treasureoptions,\
2226 int symmetry_used,\ 2387 int symmetry_used,\
2227 region *region\ 2388 region *region,\
2389 utf8_string custom\
2228) 2390)
2229 CODE: 2391 CODE:
2230{ 2392{
2231 random_map_params rmp; 2393 random_map_params rmp;
2232 2394
2236 assign (rmp.monsterstyle , monsterstyle); 2398 assign (rmp.monsterstyle , monsterstyle);
2237 assign (rmp.treasurestyle , treasurestyle); 2399 assign (rmp.treasurestyle , treasurestyle);
2238 assign (rmp.layoutstyle , layoutstyle); 2400 assign (rmp.layoutstyle , layoutstyle);
2239 assign (rmp.doorstyle , doorstyle); 2401 assign (rmp.doorstyle , doorstyle);
2240 assign (rmp.decorstyle , decorstyle); 2402 assign (rmp.decorstyle , decorstyle);
2241 assign (rmp.origin_map , origin_map);
2242 assign (rmp.final_map , final_map);
2243 assign (rmp.exitstyle , exitstyle); 2403 assign (rmp.exitstyle , exitstyle);
2244 assign (rmp.this_map , this_map);
2245 assign (rmp.exit_on_final_map, exit_on_final_map); 2404 assign (rmp.exit_on_final_map, exit_on_final_map);
2246 2405
2406 rmp.origin_map = origin_map;
2407 rmp.final_map = final_map;
2408 rmp.this_map = this_map;
2247 rmp.Xsize = Xsize; 2409 rmp.xsize = xsize;
2248 rmp.Ysize = Ysize; 2410 rmp.ysize = ysize;
2249 rmp.expand2x = expand2x; 2411 rmp.expand2x = expand2x;
2250 rmp.layoutoptions1 = layoutoptions1; 2412 rmp.layoutoptions1 = layoutoptions1;
2251 rmp.layoutoptions2 = layoutoptions2; 2413 rmp.layoutoptions2 = layoutoptions2;
2252 rmp.layoutoptions3 = layoutoptions3; 2414 rmp.layoutoptions3 = layoutoptions3;
2253 rmp.symmetry = symmetry; 2415 rmp.symmetry = symmetry;
2264 rmp.total_map_hp = total_map_hp; 2426 rmp.total_map_hp = total_map_hp;
2265 rmp.map_layout_style = map_layout_style; 2427 rmp.map_layout_style = map_layout_style;
2266 rmp.treasureoptions = treasureoptions; 2428 rmp.treasureoptions = treasureoptions;
2267 rmp.symmetry_used = symmetry_used; 2429 rmp.symmetry_used = symmetry_used;
2268 rmp.region = region; 2430 rmp.region = region;
2431 rmp.custom = custom;
2269 2432
2270 RETVAL = generate_random_map (path, &rmp); 2433 RETVAL = self->generate_random_map (&rmp);
2271} 2434}
2272 OUTPUT: 2435 OUTPUT:
2273 RETVAL 2436 RETVAL
2274 2437
2275MODULE = cf PACKAGE = cf::arch 2438MODULE = cf PACKAGE = cf::arch
2276 2439
2277archetype *find (const char *name) 2440archetype *find (utf8_string name)
2278 CODE: 2441 CODE:
2279 RETVAL = archetype::find (name); 2442 RETVAL = archetype::find (name);
2280 OUTPUT: 2443 OUTPUT:
2281 RETVAL 2444 RETVAL
2282 2445
2284 PROTOTYPE: 2447 PROTOTYPE:
2285 CODE: 2448 CODE:
2286 RETVAL = first_archetype; 2449 RETVAL = first_archetype;
2287 OUTPUT: RETVAL 2450 OUTPUT: RETVAL
2288 2451
2289INCLUDE: $PERL genacc archetype ../include/object.h | 2452INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2290 2453
2291MODULE = cf PACKAGE = cf::party 2454MODULE = cf PACKAGE = cf::party
2292 2455
2293partylist *first () 2456partylist *first ()
2294 PROTOTYPE: 2457 PROTOTYPE:
2295 CODE: 2458 CODE:
2296 RETVAL = get_firstparty (); 2459 RETVAL = get_firstparty ();
2297 OUTPUT: RETVAL 2460 OUTPUT: RETVAL
2298 2461
2299INCLUDE: $PERL genacc partylist ../include/player.h | 2462INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h |
2300 2463
2301MODULE = cf PACKAGE = cf::region 2464MODULE = cf PACKAGE = cf::region
2302 2465
2303region *first () 2466void
2467list ()
2468 PPCODE:
2469 for_all_regions (rgn)
2470 XPUSHs (sv_2mortal (to_sv (rgn)));
2471
2472region *find (utf8_string name)
2304 PROTOTYPE: 2473 PROTOTYPE: $
2305 CODE: 2474 CODE:
2306 RETVAL = first_region; 2475 RETVAL = region::find (name);
2307 OUTPUT: RETVAL 2476 OUTPUT: RETVAL
2308 2477
2478region *find_fuzzy (utf8_string name)
2479 PROTOTYPE: $
2480 CODE:
2481 RETVAL = region::find_fuzzy (name);
2482 OUTPUT: RETVAL
2483
2484int specificity (region *rgn)
2485 CODE:
2486 RETVAL = 0;
2487 while (rgn = rgn->parent)
2488 RETVAL++;
2489 OUTPUT: RETVAL
2490
2309INCLUDE: $PERL genacc region ../include/map.h | 2491INCLUDE: $PERL $srcdir/genacc region ../include/map.h |
2310 2492
2311MODULE = cf PACKAGE = cf::living 2493MODULE = cf PACKAGE = cf::living
2312 2494
2313INCLUDE: $PERL genacc living ../include/living.h | 2495INCLUDE: $PERL $srcdir/genacc living ../include/living.h |
2314 2496
2315MODULE = cf PACKAGE = cf::settings 2497MODULE = cf PACKAGE = cf::settings
2316 2498
2317INCLUDE: $PERL genacc Settings ../include/global.h | 2499INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h |
2318 2500
2319MODULE = cf PACKAGE = cf::client 2501MODULE = cf PACKAGE = cf::client
2320 2502
2321INCLUDE: $PERL genacc client ../include/client.h | 2503INCLUDE: $PERL $srcdir/genacc client ../include/client.h |
2322 2504
2323int invoke (client *ns, int event, ...) 2505int invoke (client *ns, int event, ...)
2324 CODE: 2506 CODE:
2325 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); 2507 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2326 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2508 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2345 char *buf = SvPVbyte (packet, len); 2527 char *buf = SvPVbyte (packet, len);
2346 2528
2347 THIS->send_packet (buf, len); 2529 THIS->send_packet (buf, len);
2348} 2530}
2349 2531
2350void 2532MODULE = cf PACKAGE = cf::face PREFIX = face_
2351client::destroy ()
2352 2533
2534#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2535
2536faceidx face_find (utf8_string name, faceidx defidx = 0)
2537
2538faceidx alloc (utf8_string name)
2539 CODE:
2540{
2541 do
2542 {
2543 RETVAL = faces.size ();
2544 faces.resize (RETVAL + 1);
2545 }
2546 while (!RETVAL); // crude way to leave index 0
2547
2548 faces [RETVAL].name = name;
2549 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2550
2551 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2552 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2553}
2554 OUTPUT: RETVAL
2555
2556void set (faceidx idx, int visibility, int magicmap)
2557 CODE:
2558 faceinfo *f = face_info (idx);
2559 assert (f);
2560 f->visibility = visibility;
2561 f->magicmap = magicmap;
2562
2563void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2564 CODE:
2565 faceinfo *f = face_info (idx); assert (f);
2566 f->smooth = smooth;
2567 f->smoothlevel = smoothlevel;
2568
2569void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2570 CODE:
2571{
2572 facedata *d = face_data (idx, faceset);
2573 assert (d);
2574 sv_to (data, d->data);
2575 STRLEN clen;
2576 char *cdata = SvPVbyte (chksum, clen);
2577 clen = min (CHKSUM_SIZE, clen);
2578
2579 if (memcmp (d->chksum, cdata, clen))
2580 {
2581 memcpy (d->chksum, cdata, clen);
2582
2583 // invalidate existing client face info
2584 for_all_clients (ns)
2585 if (ns->faceset == faceset)
2586 {
2587 ns->faces_sent [idx] = false;
2588 ns->force_newmap = true;
2589 }
2590 }
2591}
2592
2593void invalidate (faceidx idx)
2594 CODE:
2595 for_all_clients (ns)
2596 {
2597 ns->faces_sent [idx] = false;
2598 ns->force_newmap = true;
2599 }
2600
2601void invalidate_all ()
2602 CODE:
2603 for_all_clients (ns)
2604 {
2605 ns->faces_sent.reset ();
2606 ns->force_newmap = true;
2607 }
2608
2609MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2610
2611#INCLUDE: $PERL $srcdir/genacc faceset ../include/anim.h |
2612
2613animidx anim_find (utf8_string name)
2614 CODE:
2615 RETVAL = animation::find (name).number;
2616 OUTPUT: RETVAL
2617
2618animidx set (utf8_string name, SV *frames, int facings = 1)
2619 CODE:
2620{
2621 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2622 croak ("frames must be an arrayref");
2623
2624 AV *av = (AV *)SvRV (frames);
2625
2626 animation *anim = &animation::find (name);
2627 if (anim->number)
2628 {
2629 anim->resize (av_len (av) + 1);
2630 anim->facings = facings;
2631 }
2632 else
2633 anim = &animation::create (name, av_len (av) + 1, facings);
2634
2635 for (int i = 0; i < anim->num_animations; ++i)
2636 anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1)));
2637}
2638 OUTPUT: RETVAL
2639
2640void invalidate_all ()
2641 CODE:
2642 for_all_clients (ns)
2643 ns->anims_sent.reset ();
2644

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines