… | |
… | |
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 | |
49 | extern sint64 *levels; // the experience table |
50 | extern sint64 *levels; // the experience table |
50 | |
51 | |
51 | typedef object object_ornull; |
52 | typedef object object_ornull; |
52 | typedef maptile maptile_ornull; |
53 | typedef maptile maptile_ornull; |
|
|
54 | |
|
|
55 | typedef char *octet_string; |
|
|
56 | typedef char *utf8_string; |
|
|
57 | typedef const char *const_octet_string; |
|
|
58 | typedef 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 | |
102 | unordered_vector<attachable *> attachable::mortals; |
108 | unordered_vector<attachable *> attachable::mortals; |
103 | |
109 | |
104 | attachable::~attachable () |
110 | attachable::~attachable () |
105 | { |
111 | { |
|
|
112 | flags |=0x3300;//D |
106 | assert (!self); |
113 | assert (!self); |
|
|
114 | assert (!cb); |
107 | } |
115 | } |
108 | |
116 | |
109 | int |
117 | int |
110 | attachable::refcnt_cnt () const |
118 | attachable::refcnt_cnt () const |
111 | { |
119 | { |
112 | return refcnt + (self ? SvREFCNT (self) : 0); |
120 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
|
|
121 | } |
|
|
122 | |
|
|
123 | void |
|
|
124 | attachable::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 | |
115 | void |
142 | void |
116 | attachable::optimise () |
143 | attachable::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 |
|
|
153 | void |
|
|
154 | attachable::do_check () |
|
|
155 | { |
|
|
156 | if (refcnt_cnt () > 0) |
|
|
157 | return; |
|
|
158 | |
|
|
159 | destroy (); |
|
|
160 | } |
|
|
161 | |
|
|
162 | void |
|
|
163 | attachable::do_destroy () |
|
|
164 | { |
|
|
165 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
|
|
166 | |
|
|
167 | if (cb) |
121 | { |
168 | { |
122 | refcnt_inc (); |
|
|
123 | SvREFCNT_dec ((SV *)self); |
169 | SvREFCNT_dec (cb); |
|
|
170 | cb = 0; |
124 | } |
171 | } |
125 | } |
|
|
126 | |
|
|
127 | // check wether the object really is dead |
|
|
128 | void |
|
|
129 | attachable::do_check () |
|
|
130 | { |
|
|
131 | if (refcnt > 0 || refcnt_cnt () > 0) |
|
|
132 | return; |
|
|
133 | |
|
|
134 | destroy (); |
|
|
135 | |
172 | |
136 | if (self) |
173 | if (self) |
137 | { |
174 | sever_self (); |
138 | hv_clear (self); |
|
|
139 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
140 | SvREFCNT_dec (self); |
|
|
141 | self = 0; |
|
|
142 | } |
|
|
143 | } |
|
|
144 | |
175 | |
145 | void |
176 | flags |= 0x20; //D |
146 | attachable::do_destroy () |
|
|
147 | { |
|
|
148 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
|
|
149 | |
|
|
150 | if (self) |
|
|
151 | hv_clear (self); |
|
|
152 | |
|
|
153 | mortals.push_back (this); |
177 | mortals.push_back (this); |
154 | } |
178 | } |
155 | |
179 | |
156 | void |
180 | void |
157 | attachable::destroy () |
181 | attachable::destroy () |
… | |
… | |
164 | } |
188 | } |
165 | |
189 | |
166 | void |
190 | void |
167 | attachable::check_mortals () |
191 | attachable::check_mortals () |
168 | { |
192 | { |
169 | for (int i = 0; i < mortals.size (); ) |
193 | static int i = 0; |
|
|
194 | |
|
|
195 | for (;;) |
170 | { |
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 | |
171 | attachable *obj = mortals [i]; |
207 | attachable *obj = mortals [i]; |
172 | |
208 | |
173 | obj->refcnt_chk (); // unborrow from perl, if necessary |
209 | obj->refcnt_chk (); // unborrow from perl, if necessary |
174 | |
210 | |
|
|
211 | //if (obj->refcnt > 0 || obj->self) |
175 | if (obj->refcnt || obj->self) |
212 | if (obj->refcnt || obj->self) |
176 | { |
213 | { |
177 | #if 0 |
214 | //printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D |
178 | if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (), |
|
|
179 | obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D |
|
|
180 | #endif |
|
|
181 | |
|
|
182 | ++i; // further delay freeing |
215 | ++i; // further delay freeing |
|
|
216 | |
|
|
217 | if (!(i & 0x3ff)) |
|
|
218 | break; |
183 | }//D |
219 | } |
184 | else |
220 | else |
185 | { |
221 | { |
186 | //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D |
|
|
187 | mortals.erase (i); |
222 | mortals.erase (i); |
188 | delete obj; |
223 | delete obj; |
189 | } |
224 | } |
190 | } |
225 | } |
191 | } |
226 | } |
… | |
… | |
216 | |
251 | |
217 | static int |
252 | static int |
218 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
253 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
219 | { |
254 | { |
220 | attachable *at = (attachable *)mg->mg_ptr; |
255 | attachable *at = (attachable *)mg->mg_ptr; |
|
|
256 | |
|
|
257 | //TODO: check if transaction behaviour is really required here |
|
|
258 | if (SV *self = (SV *)at->self) |
|
|
259 | { |
221 | at->self = 0; |
260 | at->self = 0; |
|
|
261 | SvREFCNT_dec (self); |
|
|
262 | } |
|
|
263 | |
222 | // 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 |
223 | //at->refcnt_chk (); |
265 | //at->refcnt_chk (); |
224 | return 0; |
266 | return 0; |
225 | } |
267 | } |
226 | |
268 | |
… | |
… | |
234 | |
276 | |
235 | if (!obj->self) |
277 | if (!obj->self) |
236 | { |
278 | { |
237 | obj->self = newHV (); |
279 | obj->self = newHV (); |
238 | 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); |
239 | |
281 | obj->flags |= (obj->flags & 0xc0) << 8; |
240 | // borrow the refcnt from the object |
282 | obj->flags &= ~0xc0;//D |
241 | // it is important thta no refcnt_chk is being executed here |
283 | obj->flags |= 0x10;//D |
242 | obj->refcnt_dec (); |
|
|
243 | |
284 | |
244 | // now bless the object _once_ |
285 | // now bless the object _once_ |
245 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
286 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
246 | } |
287 | } |
247 | else |
288 | else |
… | |
… | |
313 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
354 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
314 | |
355 | |
315 | inline SV *to_sv (object & v) { return to_sv (&v); } |
356 | inline SV *to_sv (object & v) { return to_sv (&v); } |
316 | inline SV *to_sv (living & v) { return to_sv (&v); } |
357 | inline SV *to_sv (living & v) { return to_sv (&v); } |
317 | |
358 | |
318 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
359 | //inline SV *to_sv (faceinfo * v) { return to_sv (v->name); } |
319 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
360 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
361 | inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } |
320 | |
362 | |
321 | inline SV *to_sv (UUID v) |
363 | inline SV *to_sv (UUID v) |
322 | { |
364 | { |
323 | char buf[128]; |
365 | char buf[128]; |
324 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
366 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
325 | return newSVpv (buf, 0); |
367 | return newSVpv (buf, 0); |
326 | } |
368 | } |
327 | |
369 | |
328 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
370 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
329 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
371 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
… | |
… | |
348 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
390 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
349 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
391 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
350 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
392 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
351 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
393 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
352 | |
394 | |
353 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } |
395 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
354 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } |
396 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } |
355 | |
397 | |
356 | template<class T> |
398 | template<class T> |
357 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
399 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
358 | |
400 | |
… | |
… | |
362 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
404 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
363 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
405 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
364 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
406 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
365 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
407 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
366 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
408 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
|
|
409 | |
|
|
410 | inline void sv_to (SV *sv, std::string &v) |
|
|
411 | { |
|
|
412 | STRLEN len; |
|
|
413 | char *data = SvPVbyte (sv, len); |
|
|
414 | v.assign (data, len); |
|
|
415 | } |
367 | |
416 | |
368 | inline void sv_to (SV *sv, UUID &v) |
417 | inline void sv_to (SV *sv, UUID &v) |
369 | { |
418 | { |
370 | unsigned int version; |
419 | unsigned int version; |
371 | |
420 | |
… | |
… | |
562 | perl = perl_alloc (); |
611 | perl = perl_alloc (); |
563 | perl_construct (perl); |
612 | perl_construct (perl); |
564 | |
613 | |
565 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
614 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
566 | |
615 | |
567 | char *argv[] = { |
616 | const char *argv[] = { |
568 | "", |
617 | "", |
569 | "-e" |
618 | "-e" |
570 | "use Event; use Coro;" // required for bootstrap |
619 | "use Event; use Coro;" // required for bootstrap |
571 | "cf->bootstrap;" // required for datadir :*> |
620 | "cf->bootstrap;" // required for datadir :*> |
572 | "unshift @INC, cf::datadir ();" |
621 | "unshift @INC, cf::datadir ();" |
573 | "require cf;" |
622 | "require cf;" |
574 | }; |
623 | }; |
575 | |
624 | |
576 | 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)) |
577 | { |
627 | { |
578 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
628 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
579 | exit (EXIT_FAILURE); |
629 | exit (EXIT_FAILURE); |
580 | } |
630 | } |
|
|
631 | |
|
|
632 | { |
|
|
633 | dSP; |
|
|
634 | |
|
|
635 | PUSHMARK (SP); |
|
|
636 | PUTBACK; |
|
|
637 | call_pv ("cf::init", G_DISCARD | G_VOID); |
|
|
638 | } |
581 | } |
639 | } |
582 | |
640 | |
583 | void cfperl_main () |
641 | void cfperl_main () |
584 | { |
642 | { |
585 | dSP; |
643 | dSP; |
… | |
… | |
806 | CALL_BEGIN (0); |
864 | CALL_BEGIN (0); |
807 | CALL_CALL ("cf::emergency_save", G_VOID); |
865 | CALL_CALL ("cf::emergency_save", G_VOID); |
808 | CALL_END; |
866 | CALL_END; |
809 | } |
867 | } |
810 | |
868 | |
|
|
869 | void |
|
|
870 | cfperl_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 | |
811 | maptile * |
878 | maptile * |
812 | maptile::find_sync (const char *path, maptile *origin) |
879 | maptile::find_sync (const char *path, maptile *origin) |
813 | { |
880 | { |
814 | CALL_BEGIN (2); |
881 | CALL_BEGIN (2); |
815 | CALL_ARG (path); |
882 | CALL_ARG (path); |
… | |
… | |
895 | void |
962 | void |
896 | iw::alloc () |
963 | iw::alloc () |
897 | { |
964 | { |
898 | pe = GEventAPI->new_idle (0, 0); |
965 | pe = GEventAPI->new_idle (0, 0); |
899 | |
966 | |
|
|
967 | WaREENTRANT_off (pe); |
900 | pe->base.callback = (void *)iw_dispatch; |
968 | pe->base.callback = (void *)iw_dispatch; |
901 | pe->base.ext_data = (void *)this; |
969 | pe->base.ext_data = (void *)this; |
902 | } |
970 | } |
903 | |
971 | |
904 | static void iow_dispatch (pe_event *ev) |
972 | static void iow_dispatch (pe_event *ev) |
… | |
… | |
910 | void |
978 | void |
911 | iow::alloc () |
979 | iow::alloc () |
912 | { |
980 | { |
913 | pe = GEventAPI->new_io (0, 0); |
981 | pe = GEventAPI->new_io (0, 0); |
914 | |
982 | |
|
|
983 | WaREENTRANT_off (pe); |
915 | pe->base.callback = (void *)iow_dispatch; |
984 | pe->base.callback = (void *)iow_dispatch; |
916 | pe->base.ext_data = (void *)this; |
985 | pe->base.ext_data = (void *)this; |
917 | |
986 | |
918 | pe->fd = -1; |
987 | pe->fd = -1; |
919 | pe->poll = 0; |
988 | pe->poll = 0; |
… | |
… | |
987 | # define const_iv(name) { # name, (IV)name }, |
1056 | # define const_iv(name) { # name, (IV)name }, |
988 | const_iv (llevError) |
1057 | const_iv (llevError) |
989 | const_iv (llevInfo) |
1058 | const_iv (llevInfo) |
990 | const_iv (llevDebug) |
1059 | const_iv (llevDebug) |
991 | 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) |
992 | |
1068 | |
993 | const_iv (MAX_TIME) |
1069 | const_iv (MAX_TIME) |
994 | const_iv (PLAYER) |
1070 | const_iv (PLAYER) |
995 | const_iv (TRANSPORT) |
1071 | const_iv (TRANSPORT) |
996 | const_iv (ROD) |
1072 | const_iv (ROD) |
… | |
… | |
1248 | const_iv (FLAG_IS_WATER) |
1324 | const_iv (FLAG_IS_WATER) |
1249 | const_iv (FLAG_CONTENT_ON_GEN) |
1325 | const_iv (FLAG_CONTENT_ON_GEN) |
1250 | const_iv (FLAG_IS_A_TEMPLATE) |
1326 | const_iv (FLAG_IS_A_TEMPLATE) |
1251 | const_iv (FLAG_IS_BUILDABLE) |
1327 | const_iv (FLAG_IS_BUILDABLE) |
1252 | const_iv (FLAG_DESTROY_ON_DEATH) |
1328 | const_iv (FLAG_DESTROY_ON_DEATH) |
1253 | const_iv (FLAG_NO_SAVE) |
1329 | const_iv (FLAG_NO_MAP_SAVE) |
1254 | |
1330 | |
1255 | const_iv (NDI_BLACK) |
1331 | const_iv (NDI_BLACK) |
1256 | const_iv (NDI_WHITE) |
1332 | const_iv (NDI_WHITE) |
1257 | const_iv (NDI_NAVY) |
1333 | const_iv (NDI_NAVY) |
1258 | const_iv (NDI_RED) |
1334 | const_iv (NDI_RED) |
… | |
… | |
1443 | const_iv (ATNR_BLIND) |
1519 | const_iv (ATNR_BLIND) |
1444 | const_iv (ATNR_INTERNAL) |
1520 | const_iv (ATNR_INTERNAL) |
1445 | const_iv (ATNR_LIFE_STEALING) |
1521 | const_iv (ATNR_LIFE_STEALING) |
1446 | const_iv (ATNR_DISEASE) |
1522 | const_iv (ATNR_DISEASE) |
1447 | |
1523 | |
1448 | const_iv (MAP_FLUSH) |
|
|
1449 | const_iv (MAP_PLAYER_UNIQUE) |
|
|
1450 | const_iv (MAP_BLOCK) |
|
|
1451 | const_iv (MAP_STYLE) |
|
|
1452 | const_iv (MAP_OVERLAY) |
|
|
1453 | |
|
|
1454 | const_iv (MAP_IN_MEMORY) |
1524 | const_iv (MAP_IN_MEMORY) |
1455 | const_iv (MAP_SWAPPED) |
1525 | const_iv (MAP_SWAPPED) |
1456 | const_iv (MAP_LOADING) |
1526 | const_iv (MAP_LOADING) |
1457 | const_iv (MAP_SAVING) |
1527 | const_iv (MAP_SAVING) |
1458 | |
1528 | |
… | |
… | |
1537 | { |
1607 | { |
1538 | // reattach to all attachable objects in the game. |
1608 | // reattach to all attachable objects in the game. |
1539 | for_all_clients (ns) |
1609 | for_all_clients (ns) |
1540 | ns->reattach (); |
1610 | ns->reattach (); |
1541 | |
1611 | |
1542 | for_all_players (pl) |
|
|
1543 | pl->reattach (); |
|
|
1544 | |
|
|
1545 | //TODO |
|
|
1546 | //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) |
|
|
1547 | // i->second->reattach (); |
|
|
1548 | |
|
|
1549 | for_all_objects (op) |
1612 | for_all_objects (op) |
1550 | op->reattach (); |
1613 | op->reattach (); |
1551 | } |
1614 | } |
1552 | |
1615 | |
1553 | NV floor (NV x) |
1616 | NV floor (NV x) |
… | |
… | |
1570 | CODE: |
1633 | CODE: |
1571 | runtime = SvNVx (sv_runtime); |
1634 | runtime = SvNVx (sv_runtime); |
1572 | server_tick (); |
1635 | server_tick (); |
1573 | |
1636 | |
1574 | void |
1637 | void |
1575 | LOG (int level, char *msg) |
1638 | LOG (int level, utf8_string msg) |
1576 | PROTOTYPE: $$ |
1639 | PROTOTYPE: $$ |
1577 | C_ARGS: (LogLevel)level, "%s", msg |
1640 | C_ARGS: (LogLevel)level, "%s", msg |
1578 | |
1641 | |
1579 | char *path_combine (char *base, char *path) |
1642 | octet_string path_combine (octet_string base, octet_string path) |
1580 | PROTOTYPE: $$ |
1643 | PROTOTYPE: $$ |
1581 | |
1644 | |
1582 | char *path_combine_and_normalize (char *base, char *path) |
1645 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1583 | PROTOTYPE: $$ |
1646 | PROTOTYPE: $$ |
1584 | |
1647 | |
1585 | const char * |
1648 | const_octet_string |
1586 | get_maps_directory (char *path) |
1649 | get_maps_directory (octet_string path) |
1587 | PROTOTYPE: $ |
1650 | PROTOTYPE: $ |
1588 | ALIAS: maps_directory = 0 |
1651 | ALIAS: maps_directory = 0 |
1589 | CODE: |
1652 | CODE: |
1590 | RETVAL = create_pathname (path); |
1653 | RETVAL = create_pathname (path); |
1591 | OUTPUT: RETVAL |
1654 | OUTPUT: RETVAL |
… | |
… | |
1593 | void |
1656 | void |
1594 | sub_generation_inc () |
1657 | sub_generation_inc () |
1595 | CODE: |
1658 | CODE: |
1596 | PL_sub_generation++; |
1659 | PL_sub_generation++; |
1597 | |
1660 | |
1598 | char * |
1661 | const_octet_string |
1599 | mapdir () |
1662 | mapdir () |
1600 | PROTOTYPE: |
1663 | PROTOTYPE: |
1601 | ALIAS: |
1664 | ALIAS: |
1602 | mapdir = 0 |
1665 | mapdir = 0 |
1603 | uniquedir = 1 |
1666 | uniquedir = 1 |
… | |
… | |
1619 | } |
1682 | } |
1620 | OUTPUT: RETVAL |
1683 | OUTPUT: RETVAL |
1621 | |
1684 | |
1622 | void abort () |
1685 | void abort () |
1623 | |
1686 | |
1624 | void fork_abort (char *cause = "cf::fork_abort") |
1687 | void fork_abort (octet_string cause = "cf::fork_abort") |
1625 | |
1688 | |
1626 | void cleanup (const char *cause, bool make_core = false) |
1689 | void cleanup (octet_string cause, bool make_core = false) |
1627 | |
1690 | |
1628 | void emergency_save () |
1691 | void emergency_save () |
1629 | |
1692 | |
1630 | void _exit (int status = 0) |
1693 | void _exit (int status = EXIT_SUCCESS) |
|
|
1694 | |
|
|
1695 | UV sv_2watcher (SV *w) |
|
|
1696 | CODE: |
|
|
1697 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
|
|
1698 | OUTPUT: |
|
|
1699 | RETVAL |
1631 | |
1700 | |
1632 | #if _POSIX_MEMLOCK |
1701 | #if _POSIX_MEMLOCK |
1633 | |
1702 | |
1634 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1703 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1635 | |
1704 | |
1636 | int munlockall () |
1705 | int munlockall () |
1637 | |
1706 | |
1638 | #endif |
1707 | #endif |
1639 | |
1708 | |
1640 | int find_animation (char *text) |
1709 | int find_animation (utf8_string text) |
1641 | PROTOTYPE: $ |
1710 | PROTOTYPE: $ |
1642 | |
1711 | |
1643 | int random_roll (int min, int max, object *op, int goodbad); |
1712 | int random_roll (int min, int max, object *op, int goodbad); |
1644 | |
1713 | |
1645 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1714 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1646 | |
1715 | |
1647 | int |
1716 | int |
1648 | exp_to_level (val64 exp) |
1717 | exp_to_level (val64 exp) |
1649 | CODE: |
1718 | CODE: |
1650 | { |
1719 | { |
… | |
… | |
1681 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1750 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1682 | else |
1751 | else |
1683 | XSRETURN_UNDEF; |
1752 | XSRETURN_UNDEF; |
1684 | OUTPUT: RETVAL |
1753 | OUTPUT: RETVAL |
1685 | |
1754 | |
|
|
1755 | bool |
|
|
1756 | load_resource_file (octet_string filename) |
|
|
1757 | |
1686 | MODULE = cf PACKAGE = cf::attachable |
1758 | MODULE = cf PACKAGE = cf::attachable |
1687 | |
1759 | |
1688 | int |
1760 | int |
1689 | valid (SV *obj) |
1761 | valid (SV *obj) |
1690 | CODE: |
1762 | CODE: |
1691 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1763 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1692 | OUTPUT: |
1764 | OUTPUT: |
1693 | RETVAL |
1765 | RETVAL |
1694 | |
1766 | |
|
|
1767 | void |
|
|
1768 | debug_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 | |
|
|
1774 | int 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 | |
1695 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1784 | INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | |
1696 | |
1785 | |
1697 | MODULE = cf PACKAGE = cf::global |
1786 | MODULE = cf PACKAGE = cf::global |
1698 | |
1787 | |
1699 | int invoke (SV *klass, int event, ...) |
1788 | int invoke (SV *klass, int event, ...) |
1700 | CODE: |
1789 | CODE: |
… | |
… | |
1704 | 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); |
1705 | OUTPUT: RETVAL |
1794 | OUTPUT: RETVAL |
1706 | |
1795 | |
1707 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1796 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1708 | |
1797 | |
1709 | INCLUDE: $PERL genacc object ../include/object.h | |
1798 | INCLUDE: $PERL $srcdir/genacc object ../include/object.h | |
1710 | |
1799 | |
1711 | int invoke (object *op, int event, ...) |
1800 | int invoke (object *op, int event, ...) |
1712 | CODE: |
1801 | CODE: |
1713 | 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"); |
1714 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1803 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
1716 | RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1805 | RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1717 | OUTPUT: RETVAL |
1806 | OUTPUT: RETVAL |
1718 | |
1807 | |
1719 | SV *registry (object *op) |
1808 | SV *registry (object *op) |
1720 | |
1809 | |
1721 | void mortals () |
|
|
1722 | PPCODE: |
|
|
1723 | EXTEND (SP, object::mortals.size ()); |
|
|
1724 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
|
|
1725 | PUSHs (to_sv (*i)); |
|
|
1726 | |
|
|
1727 | int objects_size () |
1810 | int objects_size () |
1728 | CODE: |
1811 | CODE: |
1729 | RETVAL = objects.size (); |
1812 | RETVAL = objects.size (); |
1730 | OUTPUT: RETVAL |
1813 | OUTPUT: RETVAL |
1731 | |
1814 | |
… | |
… | |
1771 | void |
1854 | void |
1772 | set_animation (object *op, int idx) |
1855 | set_animation (object *op, int idx) |
1773 | CODE: |
1856 | CODE: |
1774 | SET_ANIMATION (op, idx); |
1857 | SET_ANIMATION (op, idx); |
1775 | |
1858 | |
|
|
1859 | int |
|
|
1860 | num_animations (object *op) |
|
|
1861 | CODE: |
|
|
1862 | RETVAL = NUM_ANIMATIONS (op); |
|
|
1863 | OUTPUT: RETVAL |
|
|
1864 | |
1776 | object *find_best_object_match (object *op, const char *match) |
1865 | object *find_best_object_match (object *op, utf8_string match) |
1777 | |
1866 | |
1778 | object *find_marked_object (object *op) |
1867 | object *find_marked_object (object *op) |
1779 | |
1868 | |
1780 | int need_identify (object *obj); |
1869 | int need_identify (object *obj); |
1781 | |
1870 | |
1782 | int apply_shop_mat (object *shop_mat, object *op); |
1871 | int apply_shop_mat (object *shop_mat, object *op); |
|
|
1872 | |
|
|
1873 | int move_player (object *op, int dir) |
|
|
1874 | CODE: |
|
|
1875 | RETVAL = move_player (op, dir); |
|
|
1876 | OUTPUT: |
|
|
1877 | RETVAL |
1783 | |
1878 | |
1784 | int move (object *op, int dir, object *originator = op) |
1879 | int move (object *op, int dir, object *originator = op) |
1785 | CODE: |
1880 | CODE: |
1786 | RETVAL = move_ob (op, dir, originator); |
1881 | RETVAL = move_ob (op, dir, originator); |
1787 | OUTPUT: |
1882 | OUTPUT: |
… | |
… | |
1793 | |
1888 | |
1794 | void apply_below (object *op) |
1889 | void apply_below (object *op) |
1795 | CODE: |
1890 | CODE: |
1796 | player_apply_below (op); |
1891 | player_apply_below (op); |
1797 | |
1892 | |
|
|
1893 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
|
|
1894 | |
1798 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1895 | object *cf_object_present_archname_inside (object *op, utf8_string whatstr) |
1799 | |
1896 | |
1800 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1897 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1801 | |
1898 | |
1802 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
1899 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
1803 | |
1900 | |
… | |
… | |
1823 | RETVAL = pay_for_amount (amount, op); |
1920 | RETVAL = pay_for_amount (amount, op); |
1824 | OUTPUT: RETVAL |
1921 | OUTPUT: RETVAL |
1825 | |
1922 | |
1826 | void pay_player (object *op, uint64 amount) |
1923 | void pay_player (object *op, uint64 amount) |
1827 | |
1924 | |
1828 | val64 pay_player_arch (object *op, const char *arch, uint64 amount) |
1925 | val64 pay_player_arch (object *op, utf8_string arch, uint64 amount) |
1829 | |
1926 | |
1830 | int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0) |
1927 | int cast_spell (object *op, object *caster, int dir, object *spell_ob, utf8_string stringarg = 0) |
1831 | |
1928 | |
1832 | void learn_spell (object *op, object *sp, int special_prayer = 0) |
1929 | void learn_spell (object *op, object *sp, int special_prayer = 0) |
1833 | CODE: |
1930 | CODE: |
1834 | do_learn_spell (op, sp, special_prayer); |
1931 | do_learn_spell (op, sp, special_prayer); |
1835 | |
1932 | |
1836 | void forget_spell (object *op, object *sp) |
1933 | void forget_spell (object *op, object *sp) |
1837 | CODE: |
1934 | CODE: |
1838 | do_forget_spell (op, query_name (sp)); |
1935 | do_forget_spell (op, query_name (sp)); |
1839 | |
1936 | |
1840 | object *check_for_spell (object *op, char *spellname) |
1937 | object *check_for_spell (object *op, utf8_string spellname) |
1841 | CODE: |
1938 | CODE: |
1842 | RETVAL = check_spell_known (op, spellname); |
1939 | RETVAL = check_spell_known (op, spellname); |
1843 | OUTPUT: RETVAL |
1940 | OUTPUT: RETVAL |
1844 | |
1941 | |
1845 | int query_money (object *op) |
1942 | int query_money (object *op) |
… | |
… | |
1858 | |
1955 | |
1859 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1956 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1860 | |
1957 | |
1861 | void update_object (object *op, int action) |
1958 | void update_object (object *op, int action) |
1862 | |
1959 | |
1863 | object *cf_create_object_by_name (const char *name) |
1960 | object *cf_create_object_by_name (utf8_string name) |
1864 | |
1961 | |
1865 | void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) |
1962 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
1866 | |
1963 | |
1867 | void player_lvl_adj (object *who, object *skill = 0) |
1964 | void player_lvl_adj (object *who, object *skill = 0) |
1868 | |
1965 | |
1869 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1966 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1870 | |
1967 | |
… | |
… | |
1884 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1981 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1885 | |
1982 | |
1886 | # 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 |
1887 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
1984 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
1888 | |
1985 | |
1889 | object *new (const char *archetype = 0) |
1986 | object *new (utf8_string archetype = 0) |
1890 | PROTOTYPE: ;$ |
1987 | PROTOTYPE: ;$ |
1891 | CODE: |
1988 | CODE: |
1892 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
1989 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
1893 | OUTPUT: |
1990 | OUTPUT: |
1894 | RETVAL |
1991 | RETVAL |
… | |
… | |
1899 | { |
1996 | { |
1900 | int unused_type; |
1997 | int unused_type; |
1901 | 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); |
1902 | } |
1999 | } |
1903 | |
2000 | |
1904 | # syntatic sugar for easier use in event callbacks. |
|
|
1905 | const char *options (object *op) |
|
|
1906 | CODE: |
|
|
1907 | RETVAL = op->name; |
|
|
1908 | OUTPUT: |
|
|
1909 | RETVAL |
|
|
1910 | |
|
|
1911 | player *contr (object *op) |
2001 | player *contr (object *op) |
1912 | CODE: |
2002 | CODE: |
1913 | RETVAL = op->contr; |
2003 | RETVAL = op->contr; |
1914 | OUTPUT: RETVAL |
2004 | OUTPUT: RETVAL |
1915 | |
2005 | |
1916 | const char *get_ob_key_value (object *op, const char *key) |
2006 | const_utf8_string get_ob_key_value (object *op, utf8_string key) |
1917 | |
2007 | |
1918 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
2008 | bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) |
1919 | |
2009 | |
1920 | object *get_nearest_player (object *ob) |
2010 | object *get_nearest_player (object *ob) |
1921 | ALIAS: nearest_player = 0 |
2011 | ALIAS: nearest_player = 0 |
1922 | PREINIT: |
2012 | PREINIT: |
1923 | extern object *get_nearest_player (object *); |
2013 | extern object *get_nearest_player (object *); |
… | |
… | |
1939 | bool on_same_map_as (object *ob, object *other) |
2029 | bool on_same_map_as (object *ob, object *other) |
1940 | CODE: |
2030 | CODE: |
1941 | RETVAL = on_same_map (ob, other); |
2031 | RETVAL = on_same_map (ob, other); |
1942 | OUTPUT: RETVAL |
2032 | OUTPUT: RETVAL |
1943 | |
2033 | |
1944 | const char * |
2034 | const_utf8_string |
1945 | base_name (object *op, int plural = op->nrof > 1) |
2035 | base_name (object *op, int plural = op->nrof > 1) |
1946 | CODE: |
2036 | CODE: |
1947 | RETVAL = query_base_name (op, plural); |
2037 | RETVAL = query_base_name (op, plural); |
1948 | OUTPUT: RETVAL |
2038 | OUTPUT: RETVAL |
1949 | |
2039 | |
… | |
… | |
1956 | RETVAL = op->contr; |
2046 | RETVAL = op->contr; |
1957 | OUTPUT: RETVAL |
2047 | OUTPUT: RETVAL |
1958 | |
2048 | |
1959 | void check_score (object *op) |
2049 | void check_score (object *op) |
1960 | |
2050 | |
1961 | void message (object *op, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
2051 | void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
1962 | CODE: |
2052 | CODE: |
1963 | new_draw_info (flags, 0, op, txt); |
2053 | new_draw_info (flags, 0, op, txt); |
1964 | |
2054 | |
1965 | object *cf_player_send_inventory (object *op) |
2055 | object *cf_player_send_inventory (object *op) |
1966 | |
2056 | |
1967 | char *cf_player_get_ip (object *op) |
2057 | octet_string cf_player_get_ip (object *op) |
1968 | ALIAS: ip = 0 |
2058 | ALIAS: ip = 0 |
1969 | |
2059 | |
1970 | object *cf_player_get_marked_item (object *op) |
2060 | object *cf_player_get_marked_item (object *op) |
1971 | ALIAS: marked_item = 0 |
2061 | ALIAS: marked_item = 0 |
1972 | |
2062 | |
… | |
… | |
1982 | void esrv_update_item (object *op, int what, object *item) |
2072 | void esrv_update_item (object *op, int what, object *item) |
1983 | C_ARGS: what, op, item |
2073 | C_ARGS: what, op, item |
1984 | |
2074 | |
1985 | void clear_los (object *op) |
2075 | void clear_los (object *op) |
1986 | |
2076 | |
1987 | int command_summon (object *op, char *params) |
2077 | int command_summon (object *op, utf8_string params) |
1988 | |
2078 | |
1989 | int command_arrest (object *op, char *params) |
2079 | int command_arrest (object *op, utf8_string params) |
1990 | |
|
|
1991 | int command_kick (object *op, char *params) |
|
|
1992 | |
|
|
1993 | int command_banish (object *op, char *params) |
|
|
1994 | |
2080 | |
1995 | |
2081 | |
1996 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2082 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1997 | |
2083 | |
1998 | INCLUDE: $PERL genacc player ../include/player.h | |
2084 | INCLUDE: $PERL $srcdir/genacc player ../include/player.h | |
1999 | |
2085 | |
2000 | int invoke (player *pl, int event, ...) |
2086 | int invoke (player *pl, int event, ...) |
2001 | CODE: |
2087 | CODE: |
2002 | 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"); |
2003 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2089 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2016 | pl->orig_stats = pl->ob->stats; |
2102 | pl->orig_stats = pl->ob->stats; |
2017 | |
2103 | |
2018 | void cf_player_move (player *pl, int dir) |
2104 | void cf_player_move (player *pl, int dir) |
2019 | |
2105 | |
2020 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2106 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2021 | |
|
|
2022 | player *first () |
|
|
2023 | CODE: |
|
|
2024 | RETVAL = first_player; |
|
|
2025 | OUTPUT: RETVAL |
|
|
2026 | |
2107 | |
2027 | bool |
2108 | bool |
2028 | cell_visible (player *pl, int dx, int dy) |
2109 | cell_visible (player *pl, int dx, int dy) |
2029 | CODE: |
2110 | CODE: |
2030 | 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 |
… | |
… | |
2083 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2164 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2084 | OUTPUT: RETVAL |
2165 | OUTPUT: RETVAL |
2085 | |
2166 | |
2086 | SV *registry (maptile *map) |
2167 | SV *registry (maptile *map) |
2087 | |
2168 | |
2088 | INCLUDE: $PERL genacc maptile ../include/map.h | |
2169 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2089 | |
2170 | |
2090 | void |
2171 | void |
2091 | maptile::instantiate () |
2172 | maptile::instantiate () |
2092 | |
2173 | |
2093 | maptile *new () |
2174 | maptile *new () |
… | |
… | |
2107 | EXTEND (SP, THIS->players); |
2188 | EXTEND (SP, THIS->players); |
2108 | for_all_players (pl) |
2189 | for_all_players (pl) |
2109 | if (pl->ob && pl->ob->map == THIS) |
2190 | if (pl->ob && pl->ob->map == THIS) |
2110 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2191 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2111 | } |
2192 | } |
|
|
2193 | |
|
|
2194 | void |
|
|
2195 | maptile::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 | |
|
|
2230 | void |
|
|
2231 | maptile::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 | } |
2112 | |
2259 | |
2113 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2260 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2114 | |
2261 | |
2115 | int out_of_map (maptile *map, int x, int y) |
2262 | int out_of_map (maptile *map, int x, int y) |
2116 | |
2263 | |
… | |
… | |
2198 | |
2345 | |
2199 | void fix_walls (maptile *map, int x, int y) |
2346 | void fix_walls (maptile *map, int x, int y) |
2200 | |
2347 | |
2201 | void fix_walls_around (maptile *map, int x, int y) |
2348 | void fix_walls_around (maptile *map, int x, int y) |
2202 | |
2349 | |
2203 | const char * |
|
|
2204 | region_name (maptile *m) |
|
|
2205 | CODE: |
|
|
2206 | RETVAL = get_name_of_region_for_map (m); |
|
|
2207 | OUTPUT: RETVAL |
|
|
2208 | |
|
|
2209 | # worst xs function of my life |
2350 | # worst xs function of my life |
2210 | bool |
2351 | bool |
2211 | _create_random_map (\ |
2352 | _create_random_map (\ |
2212 | maptile *self,\ |
2353 | maptile *self,\ |
2213 | char *wallstyle,\ |
2354 | utf8_string wallstyle,\ |
2214 | char *wall_name,\ |
2355 | utf8_string wall_name,\ |
2215 | char *floorstyle,\ |
2356 | utf8_string floorstyle,\ |
2216 | char *monsterstyle,\ |
2357 | utf8_string monsterstyle,\ |
2217 | char *treasurestyle,\ |
2358 | utf8_string treasurestyle,\ |
2218 | char *layoutstyle,\ |
2359 | utf8_string layoutstyle,\ |
2219 | char *doorstyle,\ |
2360 | utf8_string doorstyle,\ |
2220 | char *decorstyle,\ |
2361 | utf8_string decorstyle,\ |
2221 | char *origin_map,\ |
2362 | utf8_string origin_map,\ |
2222 | char *final_map,\ |
2363 | utf8_string final_map,\ |
2223 | char *exitstyle,\ |
2364 | utf8_string exitstyle,\ |
2224 | char *this_map,\ |
2365 | utf8_string this_map,\ |
2225 | char *exit_on_final_map,\ |
2366 | utf8_string exit_on_final_map,\ |
2226 | int Xsize,\ |
2367 | int xsize,\ |
2227 | int Ysize,\ |
2368 | int ysize,\ |
2228 | int expand2x,\ |
2369 | int expand2x,\ |
2229 | int layoutoptions1,\ |
2370 | int layoutoptions1,\ |
2230 | int layoutoptions2,\ |
2371 | int layoutoptions2,\ |
2231 | int layoutoptions3,\ |
2372 | int layoutoptions3,\ |
2232 | int symmetry,\ |
2373 | int symmetry,\ |
… | |
… | |
2237 | int dungeon_depth,\ |
2378 | int dungeon_depth,\ |
2238 | int decoroptions,\ |
2379 | int decoroptions,\ |
2239 | int orientation,\ |
2380 | int orientation,\ |
2240 | int origin_y,\ |
2381 | int origin_y,\ |
2241 | int origin_x,\ |
2382 | int origin_x,\ |
2242 | int random_seed,\ |
2383 | U32 random_seed,\ |
2243 | val64 total_map_hp,\ |
2384 | val64 total_map_hp,\ |
2244 | int map_layout_style,\ |
2385 | int map_layout_style,\ |
2245 | int treasureoptions,\ |
2386 | int treasureoptions,\ |
2246 | int symmetry_used,\ |
2387 | int symmetry_used,\ |
2247 | region *region,\ |
2388 | region *region,\ |
2248 | char *custom\ |
2389 | utf8_string custom\ |
2249 | ) |
2390 | ) |
2250 | CODE: |
2391 | CODE: |
2251 | { |
2392 | { |
2252 | random_map_params rmp; |
2393 | random_map_params rmp; |
2253 | |
2394 | |
… | |
… | |
2263 | assign (rmp.exit_on_final_map, exit_on_final_map); |
2404 | assign (rmp.exit_on_final_map, exit_on_final_map); |
2264 | |
2405 | |
2265 | rmp.origin_map = origin_map; |
2406 | rmp.origin_map = origin_map; |
2266 | rmp.final_map = final_map; |
2407 | rmp.final_map = final_map; |
2267 | rmp.this_map = this_map; |
2408 | rmp.this_map = this_map; |
2268 | rmp.Xsize = Xsize; |
2409 | rmp.xsize = xsize; |
2269 | rmp.Ysize = Ysize; |
2410 | rmp.ysize = ysize; |
2270 | rmp.expand2x = expand2x; |
2411 | rmp.expand2x = expand2x; |
2271 | rmp.layoutoptions1 = layoutoptions1; |
2412 | rmp.layoutoptions1 = layoutoptions1; |
2272 | rmp.layoutoptions2 = layoutoptions2; |
2413 | rmp.layoutoptions2 = layoutoptions2; |
2273 | rmp.layoutoptions3 = layoutoptions3; |
2414 | rmp.layoutoptions3 = layoutoptions3; |
2274 | rmp.symmetry = symmetry; |
2415 | rmp.symmetry = symmetry; |
… | |
… | |
2294 | OUTPUT: |
2435 | OUTPUT: |
2295 | RETVAL |
2436 | RETVAL |
2296 | |
2437 | |
2297 | MODULE = cf PACKAGE = cf::arch |
2438 | MODULE = cf PACKAGE = cf::arch |
2298 | |
2439 | |
2299 | archetype *find (const char *name) |
2440 | archetype *find (utf8_string name) |
2300 | CODE: |
2441 | CODE: |
2301 | RETVAL = archetype::find (name); |
2442 | RETVAL = archetype::find (name); |
2302 | OUTPUT: |
2443 | OUTPUT: |
2303 | RETVAL |
2444 | RETVAL |
2304 | |
2445 | |
… | |
… | |
2306 | PROTOTYPE: |
2447 | PROTOTYPE: |
2307 | CODE: |
2448 | CODE: |
2308 | RETVAL = first_archetype; |
2449 | RETVAL = first_archetype; |
2309 | OUTPUT: RETVAL |
2450 | OUTPUT: RETVAL |
2310 | |
2451 | |
2311 | INCLUDE: $PERL genacc archetype ../include/object.h | |
2452 | INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | |
2312 | |
2453 | |
2313 | MODULE = cf PACKAGE = cf::party |
2454 | MODULE = cf PACKAGE = cf::party |
2314 | |
2455 | |
2315 | partylist *first () |
2456 | partylist *first () |
2316 | PROTOTYPE: |
2457 | PROTOTYPE: |
2317 | CODE: |
2458 | CODE: |
2318 | RETVAL = get_firstparty (); |
2459 | RETVAL = get_firstparty (); |
2319 | OUTPUT: RETVAL |
2460 | OUTPUT: RETVAL |
2320 | |
2461 | |
2321 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2462 | INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h | |
2322 | |
2463 | |
2323 | MODULE = cf PACKAGE = cf::region |
2464 | MODULE = cf PACKAGE = cf::region |
2324 | |
2465 | |
2325 | region *first () |
2466 | void |
2326 | PROTOTYPE: |
2467 | list () |
2327 | CODE: |
2468 | PPCODE: |
2328 | RETVAL = first_region; |
2469 | for_all_regions (rgn) |
2329 | OUTPUT: RETVAL |
2470 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2330 | |
2471 | |
2331 | region *find (char *name) |
2472 | region *find (utf8_string name) |
2332 | PROTOTYPE: $ |
2473 | PROTOTYPE: $ |
2333 | CODE: |
2474 | CODE: |
2334 | RETVAL = get_region_by_name (name); |
2475 | RETVAL = region::find (name); |
2335 | OUTPUT: RETVAL |
2476 | OUTPUT: RETVAL |
2336 | |
2477 | |
|
|
2478 | region *find_fuzzy (utf8_string name) |
|
|
2479 | PROTOTYPE: $ |
|
|
2480 | CODE: |
|
|
2481 | RETVAL = region::find_fuzzy (name); |
|
|
2482 | OUTPUT: RETVAL |
|
|
2483 | |
|
|
2484 | int specificity (region *rgn) |
|
|
2485 | CODE: |
|
|
2486 | RETVAL = 0; |
|
|
2487 | while (rgn = rgn->parent) |
|
|
2488 | RETVAL++; |
|
|
2489 | OUTPUT: RETVAL |
|
|
2490 | |
2337 | INCLUDE: $PERL genacc region ../include/map.h | |
2491 | INCLUDE: $PERL $srcdir/genacc region ../include/map.h | |
2338 | |
2492 | |
2339 | MODULE = cf PACKAGE = cf::living |
2493 | MODULE = cf PACKAGE = cf::living |
2340 | |
2494 | |
2341 | INCLUDE: $PERL genacc living ../include/living.h | |
2495 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2342 | |
2496 | |
2343 | MODULE = cf PACKAGE = cf::settings |
2497 | MODULE = cf PACKAGE = cf::settings |
2344 | |
2498 | |
2345 | INCLUDE: $PERL genacc Settings ../include/global.h | |
2499 | INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h | |
2346 | |
2500 | |
2347 | MODULE = cf PACKAGE = cf::client |
2501 | MODULE = cf PACKAGE = cf::client |
2348 | |
2502 | |
2349 | INCLUDE: $PERL genacc client ../include/client.h | |
2503 | INCLUDE: $PERL $srcdir/genacc client ../include/client.h | |
2350 | |
2504 | |
2351 | int invoke (client *ns, int event, ...) |
2505 | int invoke (client *ns, int event, ...) |
2352 | CODE: |
2506 | CODE: |
2353 | 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"); |
2354 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2508 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2373 | char *buf = SvPVbyte (packet, len); |
2527 | char *buf = SvPVbyte (packet, len); |
2374 | |
2528 | |
2375 | THIS->send_packet (buf, len); |
2529 | THIS->send_packet (buf, len); |
2376 | } |
2530 | } |
2377 | |
2531 | |
|
|
2532 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
|
|
2533 | |
|
|
2534 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
|
|
2535 | |
|
|
2536 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
|
|
2537 | |
|
|
2538 | faceidx 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 | |
|
|
2556 | void 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 | |
|
|
2563 | void 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 | |
|
|
2569 | void 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 | |
|
|
2593 | void invalidate (faceidx idx) |
|
|
2594 | CODE: |
|
|
2595 | for_all_clients (ns) |
|
|
2596 | { |
|
|
2597 | ns->faces_sent [idx] = false; |
|
|
2598 | ns->force_newmap = true; |
|
|
2599 | } |
|
|
2600 | |
|
|
2601 | void invalidate_all () |
|
|
2602 | CODE: |
|
|
2603 | for_all_clients (ns) |
|
|
2604 | { |
|
|
2605 | ns->faces_sent.reset (); |
|
|
2606 | ns->force_newmap = true; |
|
|
2607 | } |
|
|
2608 | |
|
|
2609 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
|
|
2610 | |
|
|
2611 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/anim.h | |
|
|
2612 | |
|
|
2613 | animidx anim_find (utf8_string name) |
|
|
2614 | CODE: |
|
|
2615 | RETVAL = animation::find (name).number; |
|
|
2616 | OUTPUT: RETVAL |
|
|
2617 | |
|
|
2618 | animidx 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 | |
|
|
2640 | void invalidate_all () |
|
|
2641 | CODE: |
|
|
2642 | for_all_clients (ns) |
|
|
2643 | ns->anims_sent.reset (); |
|
|
2644 | |