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.131 by root, Mon Jan 8 18:18:35 2007 UTC vs.
Revision 1.184 by root, Tue Apr 10 09:35:24 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"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
48 49
49extern sint64 *levels; // the experience table 50extern sint64 *levels; // the experience table
50 51
51typedef object object_ornull; 52typedef object object_ornull;
52typedef 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;
53 59
54#if IVSIZE >= 8 60#if IVSIZE >= 8
55 typedef IV val64; 61 typedef IV val64;
56# define newSVval64 newSViv 62# define newSVval64 newSViv
57# define SvVAL64 SvIV 63# define SvVAL64 SvIV
101 107
102unordered_vector<attachable *> attachable::mortals; 108unordered_vector<attachable *> attachable::mortals;
103 109
104attachable::~attachable () 110attachable::~attachable ()
105{ 111{
106 assert (!(flags & F_BORROWED)); 112 flags |=0x3300;//D
113 assert (!self);
114 assert (!cb);
107} 115}
108 116
109int 117int
110attachable::refcnt_cnt () const 118attachable::refcnt_cnt () const
111{ 119{
112 return refcnt + (self ? SvREFCNT (self) : 0); 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 }
113} 140}
114 141
115void 142void
116attachable::optimise () 143attachable::optimise ()
117{ 144{
118 if (self 145 if (self
119 && SvREFCNT (self) == 1 146 && SvREFCNT (self) == 1
120 && !HvTOTALKEYS (self)) 147 && !HvTOTALKEYS (self))
148 flags |= 0x40,//D
149 sever_self ();
150}
151
152// check wether the object really is dead
153void
154attachable::do_check ()
155{
156 if (refcnt_cnt () > 0)
157 return;
158
159 destroy ();
160}
161
162void
163attachable::do_destroy ()
164{
165 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
166
167 if (cb)
121 { 168 {
122 flags &= ~F_BORROWED;
123 refcnt_inc ();
124 SvREFCNT_dec ((SV *)self); 169 SvREFCNT_dec (cb);
170 cb = 0;
125 } 171 }
126}
127
128// check wether the object really is dead
129void
130attachable::do_check ()
131{
132 if (refcnt > 0)
133 return;
134
135 optimise ();
136 172
137 if (self) 173 if (self)
138 { 174 sever_self ();
139 if (refcnt + SvREFCNT (self) > 0)
140 return;
141 175
142 assert (flags & F_BORROWED); 176 flags |= 0x20; //D
143
144 flags &= ~F_BORROWED;
145 refcnt_inc ();
146 SvREFCNT_dec (self);
147 self = 0;
148 }
149
150 if (refcnt > 0)
151 return;
152
153 destroy ();
154}
155
156void
157attachable::do_destroy ()
158{
159 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
160
161 if (self)
162 hv_clear (self);
163
164 mortals.push_back (this); 177 mortals.push_back (this);
165} 178}
166 179
167void 180void
168attachable::destroy () 181attachable::destroy ()
175} 188}
176 189
177void 190void
178attachable::check_mortals () 191attachable::check_mortals ()
179{ 192{
180 for (int i = 0; i < mortals.size (); ) 193 static int i = 0;
194
195 for (;;)
181 { 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
182 attachable *obj = mortals [i]; 207 attachable *obj = mortals [i];
183 208
184 obj->refcnt_chk (); // unborrow from perl, if necessary 209 obj->refcnt_chk (); // unborrow from perl, if necessary
185 210
211 //if (obj->refcnt > 0 || obj->self)
186 if (obj->refcnt || obj->self) 212 if (obj->refcnt || obj->self)
187 { 213 {
188#if 0 214//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D
189 if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (),
190 obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D
191#endif
192
193 ++i; // further delay freeing 215 ++i; // further delay freeing
216
217 if (!(i & 0x3ff))
218 break;
194 }//D 219 }
195 else 220 else
196 { 221 {
197 //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D
198 mortals.erase (i); 222 mortals.erase (i);
199 delete obj; 223 delete obj;
200 } 224 }
201 } 225 }
202} 226}
227 251
228static int 252static int
229attachable_free (pTHX_ SV *sv, MAGIC *mg) 253attachable_free (pTHX_ SV *sv, MAGIC *mg)
230{ 254{
231 attachable *at = (attachable *)mg->mg_ptr; 255 attachable *at = (attachable *)mg->mg_ptr;
232 assert (!(at->flags & attachable::F_BORROWED)); 256
257 //TODO: check if transaction behaviour is really required here
258 if (SV *self = (SV *)at->self)
259 {
233 at->self = 0; 260 at->self = 0;
261 SvREFCNT_dec (self);
262 }
263
234 // 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
235 //at->refcnt_chk (); 265 //at->refcnt_chk ();
236 return 0; 266 return 0;
237} 267}
238 268
246 276
247 if (!obj->self) 277 if (!obj->self)
248 { 278 {
249 obj->self = newHV (); 279 obj->self = newHV ();
250 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);
251 281 obj->flags |= (obj->flags & 0xc0) << 8;
252 // borrow the refcnt from the object 282 obj->flags &= ~0xc0;//D
253 obj->flags |= attachable::F_BORROWED; 283 obj->flags |= 0x10;//D
254 obj->refcnt_dec ();
255 284
256 // now bless the object _once_ 285 // now bless the object _once_
257 return sv_bless (newRV_inc ((SV *)obj->self), stash); 286 return sv_bless (newRV_inc ((SV *)obj->self), stash);
258 } 287 }
259 else 288 else
289 {
260 return newRV_inc ((SV *)obj->self); 290 SV *sv = newRV_inc ((SV *)obj->self);
291
292 if (Gv_AMG (stash)) // handle overload correctly, as the perl core does not
293 SvAMAGIC_on (sv);
294
295 return sv;
296 }
261} 297}
262 298
263static void 299static void
264clearSVptr (SV *sv) 300clearSVptr (SV *sv)
265{ 301{
318inline 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); }
319 355
320inline SV *to_sv (object & v) { return to_sv (&v); } 356inline SV *to_sv (object & v) { return to_sv (&v); }
321inline SV *to_sv (living & v) { return to_sv (&v); } 357inline SV *to_sv (living & v) { return to_sv (&v); }
322 358
323//TODO:
324inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 359//inline SV *to_sv (faceinfo * v) { return to_sv (v->name); }
325inline 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 ()); }
326 362
327inline SV *to_sv (UUID v) 363inline SV *to_sv (UUID v)
328{ 364{
329 char buf[128]; 365 char buf[128];
330 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); 366 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
331 return newSVpv (buf, 0); 367 return newSVpv (buf, 0);
332} 368}
333 369
334inline 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; }
335inline 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; }
354inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 390inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
355inline 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"); }
356inline 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"); }
357inline 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"); }
358 394
359inline 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)]; }
360inline 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)); }
361 397
362template<class T> 398template<class T>
363inline 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; }
364 400
365template<int N> 401template<int N>
368inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } 404inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
369inline 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); }
370inline 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); }
371inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 407inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
372inline 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}
373 416
374inline void sv_to (SV *sv, UUID &v) 417inline void sv_to (SV *sv, UUID &v)
375{ 418{
376 unsigned int version; 419 unsigned int version;
377 420
501 if (!ext->cb) 544 if (!ext->cb)
502 ext->cb = newAV (); 545 ext->cb = newAV ();
503 546
504 return newRV_inc ((SV *)ext->cb); 547 return newRV_inc ((SV *)ext->cb);
505} 548}
506
507#if 0
508void attachable::clear ()
509{
510 if (self)
511 {
512 // disconnect Perl from C, to avoid crashes
513 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
514
515 // clear the perl hash, might or might not be a good idea
516 hv_clear ((HV *)SvRV ((SV *)self));
517
518 SvREFCNT_dec (self);
519 self = 0;
520 }
521
522 if (cb)
523 {
524 SvREFCNT_dec (cb);
525 cb = 0;
526 }
527
528 attach = 0;
529}
530#endif
531 549
532///////////////////////////////////////////////////////////////////////////// 550/////////////////////////////////////////////////////////////////////////////
533 551
534extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 552extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
535{ 553{
593 perl = perl_alloc (); 611 perl = perl_alloc ();
594 perl_construct (perl); 612 perl_construct (perl);
595 613
596 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 614 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
597 615
598 char *argv[] = { 616 const char *argv[] = {
599 "", 617 "",
600 "-e" 618 "-e"
601 "use Event; use Coro;" // required for bootstrap 619 "use Event; use Coro;" // required for bootstrap
602 "cf->bootstrap;" // required for datadir :*> 620 "cf->bootstrap;" // required for datadir :*>
603 "unshift @INC, cf::datadir ();" 621 "unshift @INC, cf::datadir ();"
604 "require cf;" 622 "require cf;"
605 }; 623 };
606 624
607 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))
608 { 627 {
609 printf ("unable to initialize perl-interpreter, aborting.\n"); 628 printf ("unable to initialize perl-interpreter, aborting.\n");
610 exit (EXIT_FAILURE); 629 exit (EXIT_FAILURE);
611 } 630 }
631
632 {
633 dSP;
634
635 PUSHMARK (SP);
636 PUTBACK;
637 call_pv ("cf::init", G_DISCARD | G_VOID);
638 }
612} 639}
613 640
614void cfperl_main () 641void cfperl_main ()
615{ 642{
616 dSP; 643 dSP;
830} 857}
831 858
832///////////////////////////////////////////////////////////////////////////// 859/////////////////////////////////////////////////////////////////////////////
833 860
834void 861void
835maptile::emergency_save () 862cfperl_emergency_save ()
836{ 863{
837 CALL_BEGIN (0); 864 CALL_BEGIN (0);
838 CALL_CALL ("cf::map::emergency_save", G_VOID); 865 CALL_CALL ("cf::emergency_save", G_VOID);
866 CALL_END;
867}
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);
839 CALL_END; 875 CALL_END;
840} 876}
841 877
842maptile * 878maptile *
843maptile::find_sync (const char *path, maptile *origin) 879maptile::find_sync (const char *path, maptile *origin)
844{ 880{
845 CALL_BEGIN (2); 881 CALL_BEGIN (2);
846 CALL_ARG (path); 882 CALL_ARG (path);
847 CALL_ARG (origin); 883 CALL_ARG (origin);
848 CALL_CALL ("cf::map::find_sync", G_SCALAR); 884 CALL_CALL ("cf::map::find_sync", G_SCALAR);
885
886 maptile *retval;
887
888 if (count)
889 sv_to (POPs, retval);
890 else
891 retval = 0;
892
893 CALL_END;
894
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);
849 905
850 maptile *retval; 906 maptile *retval;
851 907
852 if (count) 908 if (count)
853 sv_to (POPs, retval); 909 sv_to (POPs, retval);
906void 962void
907iw::alloc () 963iw::alloc ()
908{ 964{
909 pe = GEventAPI->new_idle (0, 0); 965 pe = GEventAPI->new_idle (0, 0);
910 966
967 WaREENTRANT_off (pe);
911 pe->base.callback = (void *)iw_dispatch; 968 pe->base.callback = (void *)iw_dispatch;
912 pe->base.ext_data = (void *)this; 969 pe->base.ext_data = (void *)this;
913} 970}
914 971
915static void iow_dispatch (pe_event *ev) 972static void iow_dispatch (pe_event *ev)
921void 978void
922iow::alloc () 979iow::alloc ()
923{ 980{
924 pe = GEventAPI->new_io (0, 0); 981 pe = GEventAPI->new_io (0, 0);
925 982
983 WaREENTRANT_off (pe);
926 pe->base.callback = (void *)iow_dispatch; 984 pe->base.callback = (void *)iow_dispatch;
927 pe->base.ext_data = (void *)this; 985 pe->base.ext_data = (void *)this;
928 986
929 pe->fd = -1; 987 pe->fd = -1;
930 pe->poll = 0; 988 pe->poll = 0;
998# define const_iv(name) { # name, (IV)name }, 1056# define const_iv(name) { # name, (IV)name },
999 const_iv (llevError) 1057 const_iv (llevError)
1000 const_iv (llevInfo) 1058 const_iv (llevInfo)
1001 const_iv (llevDebug) 1059 const_iv (llevDebug)
1002 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)
1003 1068
1004 const_iv (MAX_TIME) 1069 const_iv (MAX_TIME)
1005 const_iv (PLAYER) 1070 const_iv (PLAYER)
1006 const_iv (TRANSPORT) 1071 const_iv (TRANSPORT)
1007 const_iv (ROD) 1072 const_iv (ROD)
1258 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1323 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1259 const_iv (FLAG_IS_WATER) 1324 const_iv (FLAG_IS_WATER)
1260 const_iv (FLAG_CONTENT_ON_GEN) 1325 const_iv (FLAG_CONTENT_ON_GEN)
1261 const_iv (FLAG_IS_A_TEMPLATE) 1326 const_iv (FLAG_IS_A_TEMPLATE)
1262 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)
1263 1330
1264 const_iv (NDI_BLACK) 1331 const_iv (NDI_BLACK)
1265 const_iv (NDI_WHITE) 1332 const_iv (NDI_WHITE)
1266 const_iv (NDI_NAVY) 1333 const_iv (NDI_NAVY)
1267 const_iv (NDI_RED) 1334 const_iv (NDI_RED)
1452 const_iv (ATNR_BLIND) 1519 const_iv (ATNR_BLIND)
1453 const_iv (ATNR_INTERNAL) 1520 const_iv (ATNR_INTERNAL)
1454 const_iv (ATNR_LIFE_STEALING) 1521 const_iv (ATNR_LIFE_STEALING)
1455 const_iv (ATNR_DISEASE) 1522 const_iv (ATNR_DISEASE)
1456 1523
1457 const_iv (MAP_FLUSH)
1458 const_iv (MAP_PLAYER_UNIQUE)
1459 const_iv (MAP_BLOCK)
1460 const_iv (MAP_STYLE)
1461 const_iv (MAP_OVERLAY)
1462
1463 const_iv (MAP_IN_MEMORY) 1524 const_iv (MAP_IN_MEMORY)
1464 const_iv (MAP_SWAPPED) 1525 const_iv (MAP_SWAPPED)
1465 const_iv (MAP_LOADING) 1526 const_iv (MAP_LOADING)
1466 const_iv (MAP_SAVING) 1527 const_iv (MAP_SAVING)
1467 1528
1546{ 1607{
1547 // reattach to all attachable objects in the game. 1608 // reattach to all attachable objects in the game.
1548 for_all_clients (ns) 1609 for_all_clients (ns)
1549 ns->reattach (); 1610 ns->reattach ();
1550 1611
1551 for_all_players (pl)
1552 pl->reattach ();
1553
1554 //TODO
1555 //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i)
1556 // i->second->reattach ();
1557
1558 for_all_objects (op) 1612 for_all_objects (op)
1559 op->reattach (); 1613 op->reattach ();
1560} 1614}
1561 1615
1562NV floor (NV x) 1616NV floor (NV x)
1563 1617
1564NV ceil (NV x) 1618NV ceil (NV x)
1565 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
1631
1566void server_tick () 1632void server_tick ()
1567 CODE: 1633 CODE:
1568 runtime = SvNVx (sv_runtime); 1634 runtime = SvNVx (sv_runtime);
1569 server_tick (); 1635 server_tick ();
1570 1636
1571void 1637void
1572LOG (int level, char *msg) 1638LOG (int level, utf8_string msg)
1573 PROTOTYPE: $$ 1639 PROTOTYPE: $$
1574 C_ARGS: (LogLevel)level, "%s", msg 1640 C_ARGS: (LogLevel)level, "%s", msg
1575 1641
1576char *path_combine (char *base, char *path) 1642octet_string path_combine (octet_string base, octet_string path)
1577 PROTOTYPE: $$ 1643 PROTOTYPE: $$
1578 1644
1579char *path_combine_and_normalize (char *base, char *path) 1645octet_string path_combine_and_normalize (octet_string base, octet_string path)
1580 PROTOTYPE: $$ 1646 PROTOTYPE: $$
1581 1647
1582const char * 1648const_octet_string
1583get_maps_directory (char *path) 1649get_maps_directory (octet_string path)
1584 PROTOTYPE: $ 1650 PROTOTYPE: $
1585 ALIAS: maps_directory = 0 1651 ALIAS: maps_directory = 0
1586 CODE: 1652 CODE:
1587 RETVAL = create_pathname (path); 1653 RETVAL = create_pathname (path);
1588 OUTPUT: RETVAL 1654 OUTPUT: RETVAL
1590void 1656void
1591sub_generation_inc () 1657sub_generation_inc ()
1592 CODE: 1658 CODE:
1593 PL_sub_generation++; 1659 PL_sub_generation++;
1594 1660
1595char * 1661const_octet_string
1596mapdir () 1662mapdir ()
1597 PROTOTYPE: 1663 PROTOTYPE:
1598 ALIAS: 1664 ALIAS:
1599 mapdir = 0 1665 mapdir = 0
1600 uniquedir = 1 1666 uniquedir = 1
1616 } 1682 }
1617 OUTPUT: RETVAL 1683 OUTPUT: RETVAL
1618 1684
1619void abort () 1685void abort ()
1620 1686
1687void fork_abort (octet_string cause = "cf::fork_abort")
1688
1689void cleanup (octet_string cause, bool make_core = false)
1690
1621void emergency_save () 1691void emergency_save ()
1622 1692
1623void _exit (int status = 0) 1693void _exit (int status = EXIT_SUCCESS)
1694
1695UV sv_2watcher (SV *w)
1696 CODE:
1697 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1698 OUTPUT:
1699 RETVAL
1624 1700
1625#if _POSIX_MEMLOCK 1701#if _POSIX_MEMLOCK
1626 1702
1627int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1703int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1628 1704
1629int munlockall () 1705int munlockall ()
1630 1706
1631#endif 1707#endif
1632 1708
1633int find_animation (char *text) 1709int find_animation (utf8_string text)
1634 PROTOTYPE: $ 1710 PROTOTYPE: $
1635 1711
1636int random_roll (int min, int max, object *op, int goodbad); 1712int random_roll (int min, int max, object *op, int goodbad);
1637 1713
1638const char *cost_string_from_value(uint64 cost, int approx = 0) 1714const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1639 1715
1640int 1716int
1641exp_to_level (val64 exp) 1717exp_to_level (val64 exp)
1642 CODE: 1718 CODE:
1643{ 1719{
1674 RETVAL = newSVpv (resist_plus[atnr], 0); 1750 RETVAL = newSVpv (resist_plus[atnr], 0);
1675 else 1751 else
1676 XSRETURN_UNDEF; 1752 XSRETURN_UNDEF;
1677 OUTPUT: RETVAL 1753 OUTPUT: RETVAL
1678 1754
1755bool
1756load_resource_file (octet_string filename)
1757
1679MODULE = cf PACKAGE = cf::attachable 1758MODULE = cf PACKAGE = cf::attachable
1680 1759
1681int 1760int
1682valid (SV *obj) 1761valid (SV *obj)
1683 CODE: 1762 CODE:
1684 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1763 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1685 OUTPUT: 1764 OUTPUT:
1686 RETVAL 1765 RETVAL
1687 1766
1767void
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
1688INCLUDE: $PERL genacc attachable ../include/cfperl.h | 1784INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h |
1689 1785
1690MODULE = cf PACKAGE = cf::global 1786MODULE = cf PACKAGE = cf::global
1691 1787
1692int invoke (SV *klass, int event, ...) 1788int invoke (SV *klass, int event, ...)
1693 CODE: 1789 CODE:
1697 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);
1698 OUTPUT: RETVAL 1794 OUTPUT: RETVAL
1699 1795
1700MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1796MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1701 1797
1702INCLUDE: $PERL genacc object ../include/object.h | 1798INCLUDE: $PERL $srcdir/genacc object ../include/object.h |
1703 1799
1704int invoke (object *op, int event, ...) 1800int invoke (object *op, int event, ...)
1705 CODE: 1801 CODE:
1706 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");
1707 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 1803 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1709 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); 1805 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END);
1710 OUTPUT: RETVAL 1806 OUTPUT: RETVAL
1711 1807
1712SV *registry (object *op) 1808SV *registry (object *op)
1713 1809
1714void mortals () 1810int objects_size ()
1715 PPCODE: 1811 CODE:
1716 EXTEND (SP, object::mortals.size ());
1717 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1718 PUSHs (to_sv (*i));
1719
1720object *first ()
1721 CODE:
1722 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;
1723 OUTPUT: RETVAL 1828 OUTPUT: RETVAL
1724 1829
1725# missing properties 1830# missing properties
1726 1831
1727object *head (object *op) 1832object *head (object *op)
1728 PROTOTYPE: $ 1833 PROTOTYPE: $
1729 CODE: 1834 CODE:
1730 RETVAL = op->head ? op->head : op; 1835 RETVAL = op->head_ ();
1731 OUTPUT: RETVAL 1836 OUTPUT: RETVAL
1732 1837
1733int is_head (object *op) 1838int is_head (object *op)
1734 PROTOTYPE: $ 1839 PROTOTYPE: $
1735 CODE: 1840 CODE:
1736 RETVAL = !op->head; 1841 RETVAL = op->head_ () == op;
1737 OUTPUT: RETVAL 1842 OUTPUT: RETVAL
1738 1843
1739void 1844void
1740inv (object *obj) 1845inv (object *obj)
1741 PROTOTYPE: $ 1846 PROTOTYPE: $
1749void 1854void
1750set_animation (object *op, int idx) 1855set_animation (object *op, int idx)
1751 CODE: 1856 CODE:
1752 SET_ANIMATION (op, idx); 1857 SET_ANIMATION (op, idx);
1753 1858
1859int
1860num_animations (object *op)
1861 CODE:
1862 RETVAL = NUM_ANIMATIONS (op);
1863 OUTPUT: RETVAL
1864
1754object *find_best_object_match (object *op, const char *match) 1865object *find_best_object_match (object *op, utf8_string match)
1755 1866
1756object *find_marked_object (object *op) 1867object *find_marked_object (object *op)
1757 1868
1758int need_identify (object *obj); 1869int need_identify (object *obj);
1759 1870
1760int 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
1761 1878
1762int move (object *op, int dir, object *originator = op) 1879int move (object *op, int dir, object *originator = op)
1763 CODE: 1880 CODE:
1764 RETVAL = move_ob (op, dir, originator); 1881 RETVAL = move_ob (op, dir, originator);
1765 OUTPUT: 1882 OUTPUT:
1771 1888
1772void apply_below (object *op) 1889void apply_below (object *op)
1773 CODE: 1890 CODE:
1774 player_apply_below (op); 1891 player_apply_below (op);
1775 1892
1893int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1894
1776object *cf_object_present_archname_inside (object *op, char *whatstr) 1895object *cf_object_present_archname_inside (object *op, utf8_string whatstr)
1777 1896
1778int 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)
1779 1898
1780int 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)
1781 1900
1801 RETVAL = pay_for_amount (amount, op); 1920 RETVAL = pay_for_amount (amount, op);
1802 OUTPUT: RETVAL 1921 OUTPUT: RETVAL
1803 1922
1804void pay_player (object *op, uint64 amount) 1923void pay_player (object *op, uint64 amount)
1805 1924
1806val64 pay_player_arch (object *op, const char *arch, uint64 amount) 1925val64 pay_player_arch (object *op, utf8_string arch, uint64 amount)
1807 1926
1808int 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)
1809 1928
1810void learn_spell (object *op, object *sp, int special_prayer = 0) 1929void learn_spell (object *op, object *sp, int special_prayer = 0)
1811 CODE: 1930 CODE:
1812 do_learn_spell (op, sp, special_prayer); 1931 do_learn_spell (op, sp, special_prayer);
1813 1932
1814void forget_spell (object *op, object *sp) 1933void forget_spell (object *op, object *sp)
1815 CODE: 1934 CODE:
1816 do_forget_spell (op, query_name (sp)); 1935 do_forget_spell (op, query_name (sp));
1817 1936
1818object *check_for_spell (object *op, char *spellname) 1937object *check_for_spell (object *op, utf8_string spellname)
1819 CODE: 1938 CODE:
1820 RETVAL = check_spell_known (op, spellname); 1939 RETVAL = check_spell_known (op, spellname);
1821 OUTPUT: RETVAL 1940 OUTPUT: RETVAL
1822 1941
1823int query_money (object *op) 1942int query_money (object *op)
1832 1951
1833void drop (object *who, object *op) 1952void drop (object *who, object *op)
1834 1953
1835void pick_up (object *who, object *op) 1954void pick_up (object *who, object *op)
1836 1955
1837object *cf_object_insert_object (object *op, object *container)
1838
1839object *cf_object_insert_in_ob (object *ob, object *where)
1840
1841int cf_object_teleport (object *op, maptile *map, int x, int y) 1956int cf_object_teleport (object *op, maptile *map, int x, int y)
1842 1957
1843void update_object (object *op, int action) 1958void update_object (object *op, int action)
1844 1959
1845object *cf_create_object_by_name (const char *name) 1960object *cf_create_object_by_name (utf8_string name)
1846 1961
1847void 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)
1848 1963
1849void player_lvl_adj (object *who, object *skill = 0) 1964void player_lvl_adj (object *who, object *skill = 0)
1850 1965
1851int 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)
1852 1967
1866object *cf_insert_ob_in_ob (object *ob, object *where) 1981object *cf_insert_ob_in_ob (object *ob, object *where)
1867 1982
1868# 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
1869# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1984# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1870 1985
1871object *new (const char *archetype = 0) 1986object *new (utf8_string archetype = 0)
1872 PROTOTYPE: ;$ 1987 PROTOTYPE: ;$
1873 CODE: 1988 CODE:
1874 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1989 RETVAL = archetype ? get_archetype (archetype) : cf_create_object ();
1875 OUTPUT: 1990 OUTPUT:
1876 RETVAL 1991 RETVAL
1881{ 1996{
1882 int unused_type; 1997 int unused_type;
1883 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);
1884} 1999}
1885 2000
1886# syntatic sugar for easier use in event callbacks.
1887const char *options (object *op)
1888 CODE:
1889 RETVAL = op->name;
1890 OUTPUT:
1891 RETVAL
1892
1893player *contr (object *op) 2001player *contr (object *op)
1894 CODE: 2002 CODE:
1895 RETVAL = op->contr; 2003 RETVAL = op->contr;
1896 OUTPUT: RETVAL 2004 OUTPUT: RETVAL
1897 2005
1898const char *get_ob_key_value (object *op, const char *key) 2006const_utf8_string get_ob_key_value (object *op, utf8_string key)
1899 2007
1900bool 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)
1901 2009
1902object *get_nearest_player (object *ob) 2010object *get_nearest_player (object *ob)
1903 ALIAS: nearest_player = 0 2011 ALIAS: nearest_player = 0
1904 PREINIT: 2012 PREINIT:
1905 extern object *get_nearest_player (object *); 2013 extern object *get_nearest_player (object *);
1921bool on_same_map_as (object *ob, object *other) 2029bool on_same_map_as (object *ob, object *other)
1922 CODE: 2030 CODE:
1923 RETVAL = on_same_map (ob, other); 2031 RETVAL = on_same_map (ob, other);
1924 OUTPUT: RETVAL 2032 OUTPUT: RETVAL
1925 2033
1926const char * 2034const_utf8_string
1927base_name (object *op, int plural = op->nrof > 1) 2035base_name (object *op, int plural = op->nrof > 1)
1928 CODE: 2036 CODE:
1929 RETVAL = query_base_name (op, plural); 2037 RETVAL = query_base_name (op, plural);
1930 OUTPUT: RETVAL 2038 OUTPUT: RETVAL
1931 2039
1938 RETVAL = op->contr; 2046 RETVAL = op->contr;
1939 OUTPUT: RETVAL 2047 OUTPUT: RETVAL
1940 2048
1941void check_score (object *op) 2049void check_score (object *op)
1942 2050
1943void message (object *op, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2051void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1944 CODE: 2052 CODE:
1945 new_draw_info (flags, 0, op, txt); 2053 new_draw_info (flags, 0, op, txt);
1946 2054
1947object *cf_player_send_inventory (object *op) 2055object *cf_player_send_inventory (object *op)
1948 2056
1949char *cf_player_get_ip (object *op) 2057octet_string cf_player_get_ip (object *op)
1950 ALIAS: ip = 0 2058 ALIAS: ip = 0
1951 2059
1952object *cf_player_get_marked_item (object *op) 2060object *cf_player_get_marked_item (object *op)
1953 ALIAS: marked_item = 0 2061 ALIAS: marked_item = 0
1954 2062
1964void esrv_update_item (object *op, int what, object *item) 2072void esrv_update_item (object *op, int what, object *item)
1965 C_ARGS: what, op, item 2073 C_ARGS: what, op, item
1966 2074
1967void clear_los (object *op) 2075void clear_los (object *op)
1968 2076
1969int command_teleport (object *op, char *params)
1970
1971int command_summon (object *op, char *params) 2077int command_summon (object *op, utf8_string params)
1972 2078
1973int command_arrest (object *op, char *params) 2079int command_arrest (object *op, utf8_string params)
1974
1975int command_kick (object *op, char *params)
1976
1977int command_banish (object *op, char *params)
1978 2080
1979 2081
1980MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2082MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1981 2083
1982INCLUDE: $PERL genacc player ../include/player.h | 2084INCLUDE: $PERL $srcdir/genacc player ../include/player.h |
1983 2085
1984int invoke (player *pl, int event, ...) 2086int invoke (player *pl, int event, ...)
1985 CODE: 2087 CODE:
1986 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");
1987 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2089 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2000 pl->orig_stats = pl->ob->stats; 2102 pl->orig_stats = pl->ob->stats;
2001 2103
2002void cf_player_move (player *pl, int dir) 2104void cf_player_move (player *pl, int dir)
2003 2105
2004void 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);
2005
2006player *first ()
2007 CODE:
2008 RETVAL = first_player;
2009 OUTPUT: RETVAL
2010 2107
2011bool 2108bool
2012cell_visible (player *pl, int dx, int dy) 2109cell_visible (player *pl, int dx, int dy)
2013 CODE: 2110 CODE:
2014 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
2067 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); 2164 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END);
2068 OUTPUT: RETVAL 2165 OUTPUT: RETVAL
2069 2166
2070SV *registry (maptile *map) 2167SV *registry (maptile *map)
2071 2168
2072INCLUDE: $PERL genacc maptile ../include/map.h | 2169INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h |
2073 2170
2074void 2171void
2075maptile::instantiate () 2172maptile::instantiate ()
2076 2173
2077maptile *new () 2174maptile *new ()
2092 for_all_players (pl) 2189 for_all_players (pl)
2093 if (pl->ob && pl->ob->map == THIS) 2190 if (pl->ob && pl->ob->map == THIS)
2094 PUSHs (sv_2mortal (to_sv (pl->ob))); 2191 PUSHs (sv_2mortal (to_sv (pl->ob)));
2095 } 2192 }
2096 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
2097void 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)
2098 2261
2099int out_of_map (maptile *map, int x, int y) 2262int out_of_map (maptile *map, int x, int y)
2100 2263
2101void 2264void
2117 2280
2118object* 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)
2119 C_ARGS: str, map, nx, ny 2282 C_ARGS: str, map, nx, ny
2120 2283
2121void 2284void
2122cf_map_normalise (maptile *map, int x, int y) 2285get_map_flags (maptile *map, int x, int y)
2123 PPCODE: 2286 PPCODE:
2124{ 2287{
2125 maptile *nmap = 0; 2288 maptile *nmap = 0;
2126 I16 nx = 0, ny = 0; 2289 I16 nx = 0, ny = 0;
2127 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2290 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2182 2345
2183void fix_walls (maptile *map, int x, int y) 2346void fix_walls (maptile *map, int x, int y)
2184 2347
2185void fix_walls_around (maptile *map, int x, int y) 2348void fix_walls_around (maptile *map, int x, int y)
2186 2349
2187const char *
2188region_name (maptile *m)
2189 CODE:
2190 RETVAL = get_name_of_region_for_map (m);
2191 OUTPUT: RETVAL
2192
2193# worst xs function of my life 2350# worst xs function of my life
2194maptile * 2351bool
2195_create_random_map (\ 2352_create_random_map (\
2196 char *path,\ 2353 maptile *self,\
2197 char *wallstyle,\ 2354 utf8_string wallstyle,\
2198 char *wall_name,\ 2355 utf8_string wall_name,\
2199 char *floorstyle,\ 2356 utf8_string floorstyle,\
2200 char *monsterstyle,\ 2357 utf8_string monsterstyle,\
2201 char *treasurestyle,\ 2358 utf8_string treasurestyle,\
2202 char *layoutstyle,\ 2359 utf8_string layoutstyle,\
2203 char *doorstyle,\ 2360 utf8_string doorstyle,\
2204 char *decorstyle,\ 2361 utf8_string decorstyle,\
2205 char *origin_map,\ 2362 utf8_string origin_map,\
2206 char *final_map,\ 2363 utf8_string final_map,\
2207 char *exitstyle,\ 2364 utf8_string exitstyle,\
2208 char *this_map,\ 2365 utf8_string this_map,\
2209 char *exit_on_final_map,\ 2366 utf8_string exit_on_final_map,\
2210 int Xsize,\ 2367 int xsize,\
2211 int Ysize,\ 2368 int ysize,\
2212 int expand2x,\ 2369 int expand2x,\
2213 int layoutoptions1,\ 2370 int layoutoptions1,\
2214 int layoutoptions2,\ 2371 int layoutoptions2,\
2215 int layoutoptions3,\ 2372 int layoutoptions3,\
2216 int symmetry,\ 2373 int symmetry,\
2221 int dungeon_depth,\ 2378 int dungeon_depth,\
2222 int decoroptions,\ 2379 int decoroptions,\
2223 int orientation,\ 2380 int orientation,\
2224 int origin_y,\ 2381 int origin_y,\
2225 int origin_x,\ 2382 int origin_x,\
2226 int random_seed,\ 2383 U32 random_seed,\
2227 val64 total_map_hp,\ 2384 val64 total_map_hp,\
2228 int map_layout_style,\ 2385 int map_layout_style,\
2229 int treasureoptions,\ 2386 int treasureoptions,\
2230 int symmetry_used,\ 2387 int symmetry_used,\
2231 region *region\ 2388 region *region,\
2389 utf8_string custom\
2232) 2390)
2233 CODE: 2391 CODE:
2234{ 2392{
2235 random_map_params rmp; 2393 random_map_params rmp;
2236 2394
2246 assign (rmp.exit_on_final_map, exit_on_final_map); 2404 assign (rmp.exit_on_final_map, exit_on_final_map);
2247 2405
2248 rmp.origin_map = origin_map; 2406 rmp.origin_map = origin_map;
2249 rmp.final_map = final_map; 2407 rmp.final_map = final_map;
2250 rmp.this_map = this_map; 2408 rmp.this_map = this_map;
2251 rmp.Xsize = Xsize; 2409 rmp.xsize = xsize;
2252 rmp.Ysize = Ysize; 2410 rmp.ysize = ysize;
2253 rmp.expand2x = expand2x; 2411 rmp.expand2x = expand2x;
2254 rmp.layoutoptions1 = layoutoptions1; 2412 rmp.layoutoptions1 = layoutoptions1;
2255 rmp.layoutoptions2 = layoutoptions2; 2413 rmp.layoutoptions2 = layoutoptions2;
2256 rmp.layoutoptions3 = layoutoptions3; 2414 rmp.layoutoptions3 = layoutoptions3;
2257 rmp.symmetry = symmetry; 2415 rmp.symmetry = symmetry;
2268 rmp.total_map_hp = total_map_hp; 2426 rmp.total_map_hp = total_map_hp;
2269 rmp.map_layout_style = map_layout_style; 2427 rmp.map_layout_style = map_layout_style;
2270 rmp.treasureoptions = treasureoptions; 2428 rmp.treasureoptions = treasureoptions;
2271 rmp.symmetry_used = symmetry_used; 2429 rmp.symmetry_used = symmetry_used;
2272 rmp.region = region; 2430 rmp.region = region;
2431 rmp.custom = custom;
2273 2432
2274 RETVAL = generate_random_map (path, &rmp); 2433 RETVAL = self->generate_random_map (&rmp);
2275} 2434}
2276 OUTPUT: 2435 OUTPUT:
2277 RETVAL 2436 RETVAL
2278 2437
2279MODULE = cf PACKAGE = cf::arch 2438MODULE = cf PACKAGE = cf::arch
2280 2439
2281archetype *find (const char *name) 2440archetype *find (utf8_string name)
2282 CODE: 2441 CODE:
2283 RETVAL = archetype::find (name); 2442 RETVAL = archetype::find (name);
2284 OUTPUT: 2443 OUTPUT:
2285 RETVAL 2444 RETVAL
2286 2445
2288 PROTOTYPE: 2447 PROTOTYPE:
2289 CODE: 2448 CODE:
2290 RETVAL = first_archetype; 2449 RETVAL = first_archetype;
2291 OUTPUT: RETVAL 2450 OUTPUT: RETVAL
2292 2451
2293INCLUDE: $PERL genacc archetype ../include/object.h | 2452INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2294 2453
2295MODULE = cf PACKAGE = cf::party 2454MODULE = cf PACKAGE = cf::party
2296 2455
2297partylist *first () 2456partylist *first ()
2298 PROTOTYPE: 2457 PROTOTYPE:
2299 CODE: 2458 CODE:
2300 RETVAL = get_firstparty (); 2459 RETVAL = get_firstparty ();
2301 OUTPUT: RETVAL 2460 OUTPUT: RETVAL
2302 2461
2303INCLUDE: $PERL genacc partylist ../include/player.h | 2462INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h |
2304 2463
2305MODULE = cf PACKAGE = cf::region 2464MODULE = cf PACKAGE = cf::region
2306 2465
2307region *first () 2466void
2308 PROTOTYPE: 2467list ()
2309 CODE: 2468 PPCODE:
2310 RETVAL = first_region; 2469 for_all_regions (rgn)
2311 OUTPUT: RETVAL 2470 XPUSHs (sv_2mortal (to_sv (rgn)));
2312 2471
2313region *find (char *name) 2472region *find (utf8_string name)
2314 PROTOTYPE: $ 2473 PROTOTYPE: $
2315 CODE: 2474 CODE:
2316 RETVAL = get_region_by_name (name); 2475 RETVAL = region::find (name);
2317 OUTPUT: RETVAL 2476 OUTPUT: RETVAL
2318 2477
2478region *find_fuzzy (utf8_string name)
2479 PROTOTYPE: $
2480 CODE:
2481 RETVAL = region::find_fuzzy (name);
2482 OUTPUT: RETVAL
2483
2319INCLUDE: $PERL genacc region ../include/map.h | 2484INCLUDE: $PERL $srcdir/genacc region ../include/map.h |
2320 2485
2321MODULE = cf PACKAGE = cf::living 2486MODULE = cf PACKAGE = cf::living
2322 2487
2323INCLUDE: $PERL genacc living ../include/living.h | 2488INCLUDE: $PERL $srcdir/genacc living ../include/living.h |
2324 2489
2325MODULE = cf PACKAGE = cf::settings 2490MODULE = cf PACKAGE = cf::settings
2326 2491
2327INCLUDE: $PERL genacc Settings ../include/global.h | 2492INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h |
2328 2493
2329MODULE = cf PACKAGE = cf::client 2494MODULE = cf PACKAGE = cf::client
2330 2495
2331INCLUDE: $PERL genacc client ../include/client.h | 2496INCLUDE: $PERL $srcdir/genacc client ../include/client.h |
2332 2497
2333int invoke (client *ns, int event, ...) 2498int invoke (client *ns, int event, ...)
2334 CODE: 2499 CODE:
2335 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); 2500 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2336 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2501 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2355 char *buf = SvPVbyte (packet, len); 2520 char *buf = SvPVbyte (packet, len);
2356 2521
2357 THIS->send_packet (buf, len); 2522 THIS->send_packet (buf, len);
2358} 2523}
2359 2524
2525MODULE = cf PACKAGE = cf::face PREFIX = face_
2526
2527INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2528
2529faceidx face_find (utf8_string name, faceidx defidx = 0)
2530
2531faceidx alloc (utf8_string name)
2532 CODE:
2533{
2534 do
2535 {
2536 RETVAL = faces.size ();
2537 faces.resize (RETVAL + 1);
2538 }
2539 while (!RETVAL); // crude way to leave index 0
2540
2541 faces [RETVAL].name = name;
2542 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2543
2544 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2545 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2546}
2547 OUTPUT: RETVAL
2548
2549void set (faceidx idx, int visibility, int magicmap)
2550 CODE:
2551 faceinfo *f = face_info (idx);
2552 assert (f);
2553 f->visibility = visibility;
2554 f->magicmap = magicmap;
2555
2556void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2557 CODE:
2558 faceinfo *f = face_info (idx); assert (f);
2559 f->smooth = smooth;
2560 f->smoothlevel = smoothlevel;
2561
2562void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2563 CODE:
2564{
2565 facedata *d = face_data (idx, faceset);
2566 assert (d);
2567 sv_to (data, d->data);
2568 STRLEN clen;
2569 char *cdata = SvPVbyte (chksum, clen);
2570 clen = min (CHKSUM_SIZE, clen);
2571
2572 if (memcmp (d->chksum, cdata, clen))
2573 {
2574 memcpy (d->chksum, cdata, clen);
2575
2576 // invalidate existing client face info
2577 for_all_clients (ns)
2578 if (ns->faceset == faceset)
2579 {
2580 ns->faces_sent [idx] = false;
2581 ns->force_newmap = true;
2582 }
2583 }
2584}
2585
2586void invalidate (faceidx idx)
2587 CODE:
2588 for_all_clients (ns)
2589 {
2590 ns->faces_sent [idx] = false;
2591 ns->force_newmap = true;
2592 }
2593
2594void invalidate_all ()
2595 CODE:
2596 for_all_clients (ns)
2597 {
2598 ns->faces_sent.reset ();
2599 ns->force_newmap = true;
2600 }
2601

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines