1 | /*****************************************************************************/ |
|
|
2 | /* CrossFire, A Multiplayer game for the X Window System */ |
|
|
3 | /*****************************************************************************/ |
|
|
4 | |
|
|
5 | /* |
1 | /* |
|
|
2 | * CrossFire, A Multiplayer game |
|
|
3 | * |
6 | * This code is placed under the GNU General Public Licence (GPL) |
4 | * This code is placed under the GNU General Public Licence (GPL) |
7 | * |
5 | * |
8 | * Copyright (C) 2001-2005 by Chachkoff Yann |
6 | * Copyright (C) 2001-2005 by Chachkoff Yann |
9 | * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
7 | * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
10 | * |
8 | * |
… | |
… | |
21 | * You should have received a copy of the GNU General Public License |
19 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
20 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | */ |
22 | */ |
25 | |
23 | |
|
|
24 | #include "autoconf.h" |
|
|
25 | |
26 | #define PLUGIN_NAME "perl" |
26 | #define PLUGIN_NAME "perl" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
28 | |
28 | |
29 | #define CEDES_PER_TICK 5 |
29 | #define CEDES_PER_TICK 5 |
|
|
30 | |
|
|
31 | #if HAVE_EXECINFO_H |
|
|
32 | # include <execinfo.h> |
|
|
33 | #endif |
30 | |
34 | |
31 | #include <plugin_common.h> |
35 | #include <plugin_common.h> |
32 | #include <sounds.h> |
36 | #include <sounds.h> |
33 | #include <cstdarg> |
37 | #include <cstdarg> |
34 | #include <sproto.h> |
38 | #include <sproto.h> |
… | |
… | |
56 | |
60 | |
57 | typedef char *octet_string; |
61 | typedef char *octet_string; |
58 | typedef char *utf8_string; |
62 | typedef char *utf8_string; |
59 | typedef const char *const_octet_string; |
63 | typedef const char *const_octet_string; |
60 | typedef const char *const_utf8_string; |
64 | typedef const char *const_utf8_string; |
|
|
65 | |
|
|
66 | typedef std::string std__string; |
61 | |
67 | |
62 | #if IVSIZE >= 8 |
68 | #if IVSIZE >= 8 |
63 | typedef IV val64; |
69 | typedef IV val64; |
64 | # define newSVval64 newSViv |
70 | # define newSVval64 newSViv |
65 | # define SvVAL64 SvIV |
71 | # define SvVAL64 SvIV |
… | |
… | |
78 | double runtime; |
84 | double runtime; |
79 | |
85 | |
80 | global gbl_ev; |
86 | global gbl_ev; |
81 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
87 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
82 | static SV *sv_runtime, *sv_next_tick; |
88 | static SV *sv_runtime, *sv_next_tick; |
|
|
89 | |
|
|
90 | bitset<NUM_EVENT_TYPES> ev_want_event; |
|
|
91 | bitset<NUM_TYPES> ev_want_type; |
83 | |
92 | |
84 | static HV |
93 | static HV |
85 | *stash_cf, |
94 | *stash_cf, |
86 | *stash_cf_object_wrap, |
95 | *stash_cf_object_wrap, |
87 | *stash_cf_object_player_wrap, |
96 | *stash_cf_object_player_wrap, |
… | |
… | |
109 | |
118 | |
110 | unordered_vector<attachable *> attachable::mortals; |
119 | unordered_vector<attachable *> attachable::mortals; |
111 | |
120 | |
112 | attachable::~attachable () |
121 | attachable::~attachable () |
113 | { |
122 | { |
114 | flags |=0x3300;//D |
|
|
115 | assert (!self); |
123 | assert (!self); |
116 | assert (!cb); |
124 | assert (!cb); |
117 | } |
125 | } |
118 | |
126 | |
119 | int |
127 | int |
… | |
… | |
135 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
143 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
136 | SvREFCNT_dec (self); |
144 | SvREFCNT_dec (self); |
137 | |
145 | |
138 | // self *must* be null now because thats sv_unmagic's job. |
146 | // self *must* be null now because thats sv_unmagic's job. |
139 | assert (!this->self); |
147 | assert (!this->self); |
140 | flags |= 0x80; // severed //D |
|
|
141 | } |
148 | } |
142 | } |
149 | } |
143 | |
150 | |
144 | void |
151 | void |
145 | attachable::optimise () |
152 | attachable::optimise () |
146 | { |
153 | { |
147 | if (self |
154 | if (self |
148 | && SvREFCNT (self) == 1 |
155 | && SvREFCNT (self) == 1 |
149 | && !HvTOTALKEYS (self)) |
156 | && !HvTOTALKEYS (self)) |
150 | flags |= 0x40,//D |
|
|
151 | sever_self (); |
157 | sever_self (); |
152 | } |
158 | } |
153 | |
159 | |
154 | // check wether the object really is dead |
160 | // check wether the object really is dead |
155 | void |
161 | void |
… | |
… | |
170 | { |
176 | { |
171 | SvREFCNT_dec (cb); |
177 | SvREFCNT_dec (cb); |
172 | cb = 0; |
178 | cb = 0; |
173 | } |
179 | } |
174 | |
180 | |
175 | if (self) |
|
|
176 | sever_self (); |
|
|
177 | |
|
|
178 | flags |= 0x20; //D |
|
|
179 | mortals.push_back (this); |
181 | mortals.push_back (this); |
180 | } |
182 | } |
181 | |
183 | |
182 | void |
184 | void |
183 | attachable::destroy () |
185 | attachable::destroy () |
… | |
… | |
185 | if (destroyed ()) |
187 | if (destroyed ()) |
186 | return; |
188 | return; |
187 | |
189 | |
188 | flags |= F_DESTROYED; |
190 | flags |= F_DESTROYED; |
189 | do_destroy (); |
191 | do_destroy (); |
|
|
192 | sever_self (); |
190 | } |
193 | } |
191 | |
194 | |
192 | void |
195 | void |
193 | attachable::check_mortals () |
196 | attachable::check_mortals () |
194 | { |
197 | { |
… | |
… | |
199 | if (i >= mortals.size ()) |
202 | if (i >= mortals.size ()) |
200 | { |
203 | { |
201 | i = 0; |
204 | i = 0; |
202 | |
205 | |
203 | if (mortals.size () > 1000) |
206 | if (mortals.size () > 1000) |
204 | fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); |
207 | LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); |
205 | |
208 | |
206 | break; |
209 | break; |
207 | } |
210 | } |
208 | |
211 | |
209 | attachable *obj = mortals [i]; |
212 | attachable *obj = mortals [i]; |
210 | |
213 | |
211 | obj->refcnt_chk (); // unborrow from perl, if necessary |
214 | #if 0 |
212 | |
215 | if (obj->self)//D make this an assert later |
213 | //if (obj->refcnt > 0 || obj->self) |
|
|
214 | if (obj->refcnt || obj->self) |
|
|
215 | { |
216 | { |
216 | //printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D |
217 | LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
|
|
218 | obj->sever_self (); |
|
|
219 | } |
|
|
220 | #endif |
|
|
221 | |
|
|
222 | if (obj->refcnt) |
|
|
223 | { |
217 | ++i; // further delay freeing |
224 | ++i; // further delay freeing |
218 | |
225 | |
219 | if (!(i & 0x3ff)) |
226 | if (!(i & 0x3ff)) |
220 | break; |
227 | break; |
221 | } |
228 | } |
222 | else |
229 | else |
223 | { |
230 | { |
224 | mortals.erase (i); |
231 | mortals.erase (i); |
|
|
232 | obj->sever_self (); |
225 | delete obj; |
233 | delete obj; |
226 | } |
234 | } |
227 | } |
235 | } |
228 | } |
236 | } |
229 | |
237 | |
… | |
… | |
278 | |
286 | |
279 | if (!obj->self) |
287 | if (!obj->self) |
280 | { |
288 | { |
281 | obj->self = newHV (); |
289 | obj->self = newHV (); |
282 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
290 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
283 | obj->flags |= (obj->flags & 0xc0) << 8; |
|
|
284 | obj->flags &= ~0xc0;//D |
|
|
285 | obj->flags |= 0x10;//D |
|
|
286 | |
291 | |
287 | // now bless the object _once_ |
292 | // now bless the object _once_ |
288 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
293 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
289 | } |
294 | } |
290 | else |
295 | else |
… | |
… | |
356 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
361 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
357 | |
362 | |
358 | inline SV *to_sv (object & v) { return to_sv (&v); } |
363 | inline SV *to_sv (object & v) { return to_sv (&v); } |
359 | inline SV *to_sv (living & v) { return to_sv (&v); } |
364 | inline SV *to_sv (living & v) { return to_sv (&v); } |
360 | |
365 | |
361 | //inline SV *to_sv (faceinfo * v) { return to_sv (v->name); } |
|
|
362 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
363 | inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } |
366 | inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
|
|
367 | inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
364 | |
368 | |
365 | inline SV *to_sv (UUID v) |
369 | inline SV *to_sv (UUID v) |
366 | { |
370 | { |
367 | char buf[128]; |
371 | char buf[128]; |
368 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
372 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
… | |
… | |
401 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
405 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
402 | |
406 | |
403 | template<int N> |
407 | template<int N> |
404 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
408 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
405 | |
409 | |
406 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
|
|
407 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
410 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
408 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
411 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
409 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
412 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
410 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
413 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
411 | |
414 | |
… | |
… | |
614 | perl_construct (perl); |
617 | perl_construct (perl); |
615 | |
618 | |
616 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
619 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
617 | |
620 | |
618 | const char *argv[] = { |
621 | const char *argv[] = { |
619 | "", |
622 | settings.argv [0], |
620 | "-e" |
623 | "-e" |
621 | "use Event; use Coro;" // required for bootstrap |
624 | "use Event; use Coro;" // required for bootstrap |
622 | "cf->bootstrap;" // required for datadir :*> |
625 | "cf->bootstrap;" // required for datadir :*> |
623 | "unshift @INC, cf::datadir ();" |
626 | "unshift @INC, cf::datadir ();" |
624 | "require cf;" |
627 | "require cf;" |
… | |
… | |
715 | } |
718 | } |
716 | |
719 | |
717 | void |
720 | void |
718 | global::gather_callbacks (AV *&callbacks, event_type event) const |
721 | global::gather_callbacks (AV *&callbacks, event_type event) const |
719 | { |
722 | { |
720 | ::gather_callbacks (callbacks, cb_object, event); |
723 | ::gather_callbacks (callbacks, cb_global, event); |
721 | } |
724 | } |
722 | |
725 | |
723 | void |
726 | void |
724 | object::gather_callbacks (AV *&callbacks, event_type event) const |
727 | object::gather_callbacks (AV *&callbacks, event_type event) const |
725 | { |
728 | { |
726 | if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
729 | if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type)) |
727 | { |
730 | { |
728 | SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; |
731 | SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES]; |
729 | |
732 | |
730 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
733 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
731 | ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
734 | ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
732 | } |
735 | } |
733 | |
736 | |
… | |
… | |
769 | { |
772 | { |
770 | attachable::gather_callbacks (callbacks, event); |
773 | attachable::gather_callbacks (callbacks, event); |
771 | ::gather_callbacks (callbacks, cb_map, event); |
774 | ::gather_callbacks (callbacks, cb_map, event); |
772 | } |
775 | } |
773 | |
776 | |
|
|
777 | void |
|
|
778 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
|
|
779 | { |
|
|
780 | for (int event = 0; event <= AvFILLp (registry); ++event) |
|
|
781 | { |
|
|
782 | SV *cbs_ = AvARRAY (registry)[event]; |
|
|
783 | |
|
|
784 | // element must be list of callback entries |
|
|
785 | if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) |
|
|
786 | { |
|
|
787 | AV *cbs = (AV *)SvRV (cbs_); |
|
|
788 | |
|
|
789 | // no callback entries, no callbacks to call |
|
|
790 | if (AvFILLp (cbs) >= 0) |
|
|
791 | set.set (event); |
|
|
792 | } |
|
|
793 | } |
|
|
794 | } |
|
|
795 | |
|
|
796 | // very slow and inefficient way to recalculate the global want bitsets |
|
|
797 | void |
|
|
798 | _recalc_want () |
|
|
799 | { |
|
|
800 | ev_want_event.reset (); |
|
|
801 | |
|
|
802 | _recalc_want (ev_want_event, cb_global); |
|
|
803 | _recalc_want (ev_want_event, cb_attachable); |
|
|
804 | _recalc_want (ev_want_event, cb_object); |
|
|
805 | _recalc_want (ev_want_event, cb_client); |
|
|
806 | _recalc_want (ev_want_event, cb_player); |
|
|
807 | _recalc_want (ev_want_event, cb_map); |
|
|
808 | |
|
|
809 | ev_want_type.reset (); |
|
|
810 | |
|
|
811 | for (int type = 0; type <= AvFILLp (cb_type); ++type) |
|
|
812 | { |
|
|
813 | SV *cbs_ = AvARRAY (cb_type)[type]; |
|
|
814 | |
|
|
815 | // element must be list of callback entries |
|
|
816 | if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) |
|
|
817 | { |
|
|
818 | AV *cbs = (AV *)SvRV (cbs_); |
|
|
819 | |
|
|
820 | // no callback entries, no callbacks to call |
|
|
821 | if (AvFILLp (cbs) >= 0) |
|
|
822 | ev_want_type.set (type % NUM_TYPES); |
|
|
823 | } |
|
|
824 | } |
|
|
825 | } |
|
|
826 | |
774 | bool |
827 | bool |
775 | attachable::invoke (event_type event, ...) |
828 | attachable::vinvoke (event_type event, va_list &ap) |
776 | { |
829 | { |
777 | data_type dt; |
830 | data_type dt; |
778 | va_list ap; |
|
|
779 | |
|
|
780 | va_start (ap, event); |
|
|
781 | |
831 | |
782 | // callback call ordering should be: |
832 | // callback call ordering should be: |
783 | // 1. per-object callback |
833 | // 1. per-object callback |
784 | // 2. per-class object |
834 | // 2. per-class object |
785 | // 3. per-type callback |
835 | // 3. per-type callback |
… | |
… | |
944 | CALL_BEGIN (2); |
994 | CALL_BEGIN (2); |
945 | CALL_ARG (this); |
995 | CALL_ARG (this); |
946 | CALL_ARG (exit); |
996 | CALL_ARG (exit); |
947 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
997 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
948 | CALL_END; |
998 | CALL_END; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | void |
|
|
1002 | log_backtrace (const char *msg) |
|
|
1003 | { |
|
|
1004 | #if HAVE_BACKTRACE |
|
|
1005 | void *addr [20]; |
|
|
1006 | int size = backtrace (addr, 20); |
|
|
1007 | |
|
|
1008 | CALL_BEGIN (size); |
|
|
1009 | CALL_ARG (msg); |
|
|
1010 | for (int i = 0; i < size; ++i) |
|
|
1011 | CALL_ARG ((IV)addr [i]); |
|
|
1012 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
|
|
1013 | CALL_END; |
|
|
1014 | #endif |
949 | } |
1015 | } |
950 | |
1016 | |
951 | ///////////////////////////////////////////////////////////////////////////// |
1017 | ///////////////////////////////////////////////////////////////////////////// |
952 | |
1018 | |
953 | struct EventAPI *watcher_base::GEventAPI; |
1019 | struct EventAPI *watcher_base::GEventAPI; |
… | |
… | |
1109 | const char *name; |
1175 | const char *name; |
1110 | IV iv; |
1176 | IV iv; |
1111 | } *civ, const_iv[] = { |
1177 | } *civ, const_iv[] = { |
1112 | # define const_iv(name) { # name, (IV)name }, |
1178 | # define const_iv(name) { # name, (IV)name }, |
1113 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
1179 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
|
|
1180 | const_iv (logBacktrace) |
1114 | |
1181 | |
1115 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1182 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1116 | |
1183 | |
1117 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1184 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1118 | |
1185 | |
1119 | const_iv (MAX_TIME) |
1186 | const_iv (MAX_TIME) |
|
|
1187 | |
|
|
1188 | const_iv (NUM_BODY_LOCATIONS) |
|
|
1189 | const_iv (body_range) const_iv (body_shield) const_iv (body_combat) |
|
|
1190 | const_iv (body_arm) const_iv (body_torso) const_iv (body_head) |
|
|
1191 | const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) |
|
|
1192 | const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand) |
|
|
1193 | const_iv (body_wrist) const_iv (body_waist) |
1120 | |
1194 | |
1121 | const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) |
1195 | const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) |
1122 | const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) |
1196 | const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) |
1123 | const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) |
1197 | const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) |
1124 | const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) |
1198 | const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) |
… | |
… | |
1145 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1219 | const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) |
1146 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1220 | const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) |
1147 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1221 | const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) |
1148 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
1222 | const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) |
1149 | |
1223 | |
1150 | const_iv (NUM_SUBTYPES) |
1224 | const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) |
1151 | |
1225 | |
1152 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1226 | const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) |
1153 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
1227 | const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) |
1154 | |
1228 | |
1155 | const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) |
1229 | const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) |
… | |
… | |
1163 | const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) |
1237 | const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) |
1164 | const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) |
1238 | const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) |
1165 | const_iv (WEAP_BLUD) |
1239 | const_iv (WEAP_BLUD) |
1166 | |
1240 | |
1167 | const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) |
1241 | const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) |
1168 | const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) |
1242 | const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) |
1169 | const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) |
1243 | const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) |
1170 | const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) |
1244 | const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) |
1171 | const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) |
1245 | const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) |
1172 | const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) |
1246 | const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) |
1173 | const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) |
1247 | const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) |
… | |
… | |
1265 | |
1339 | |
1266 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1340 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1267 | |
1341 | |
1268 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1342 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1269 | |
1343 | |
1270 | const_iv (ST_CHANGE_CLASS) |
|
|
1271 | |
|
|
1272 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1344 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1273 | |
1345 | |
1274 | // random map generator |
1346 | // random map generator |
1275 | const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) |
1347 | const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) |
1276 | const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) |
1348 | const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) |
… | |
… | |
1279 | const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) |
1351 | const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) |
1280 | const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) |
1352 | const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) |
1281 | |
1353 | |
1282 | const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) |
1354 | const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) |
1283 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
1355 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
|
|
1356 | |
|
|
1357 | const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) |
|
|
1358 | const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) |
|
|
1359 | const_iv (GT_MINIMAL) |
1284 | }; |
1360 | }; |
1285 | |
1361 | |
1286 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1362 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1287 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1363 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1288 | |
1364 | |
… | |
… | |
1309 | } |
1385 | } |
1310 | } |
1386 | } |
1311 | |
1387 | |
1312 | void _connect_to_perl () |
1388 | void _connect_to_perl () |
1313 | |
1389 | |
|
|
1390 | void _recalc_want () |
|
|
1391 | |
1314 | void _global_reattach () |
1392 | void _global_reattach () |
1315 | CODE: |
1393 | CODE: |
1316 | { |
1394 | { |
1317 | // reattach to all attachable objects in the game. |
1395 | // reattach to all attachable objects in the game. |
1318 | for_all_clients (ns) |
1396 | for_all_clients (ns) |
… | |
… | |
1323 | } |
1401 | } |
1324 | |
1402 | |
1325 | void _post_tick () |
1403 | void _post_tick () |
1326 | CODE: |
1404 | CODE: |
1327 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
1405 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
|
|
1406 | |
|
|
1407 | # support function for map-world.ext |
|
|
1408 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1409 | CODE: |
|
|
1410 | { |
|
|
1411 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1412 | croak ("_quantise called with invalid agruments"); |
|
|
1413 | |
|
|
1414 | plt_sv = SvRV (plt_sv); |
|
|
1415 | SV **plt = AvARRAY (plt_sv); |
|
|
1416 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1417 | |
|
|
1418 | STRLEN len; |
|
|
1419 | char *data = SvPVbyte (data_sv, len); |
|
|
1420 | char *dst = data; |
|
|
1421 | |
|
|
1422 | while (len >= 3) |
|
|
1423 | { |
|
|
1424 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1425 | { |
|
|
1426 | char *val = SvPVX (*val_sv); |
|
|
1427 | |
|
|
1428 | if (val [0] == data [0] |
|
|
1429 | && val [1] == data [1] |
|
|
1430 | && val [2] == data [2]) |
|
|
1431 | { |
|
|
1432 | *dst++ = val [3]; |
|
|
1433 | goto next; |
|
|
1434 | } |
|
|
1435 | } |
|
|
1436 | |
|
|
1437 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1438 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1439 | dst - SvPVX (data_sv), len); |
|
|
1440 | |
|
|
1441 | next: |
|
|
1442 | data += 3; |
|
|
1443 | len -= 3; |
|
|
1444 | } |
|
|
1445 | |
|
|
1446 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1447 | } |
1328 | |
1448 | |
1329 | NV floor (NV x) |
1449 | NV floor (NV x) |
1330 | |
1450 | |
1331 | NV ceil (NV x) |
1451 | NV ceil (NV x) |
1332 | |
1452 | |
… | |
… | |
1340 | default: croak ("cf::rndm requires none, one or two parameters."); break; |
1460 | default: croak ("cf::rndm requires none, one or two parameters."); break; |
1341 | } |
1461 | } |
1342 | OUTPUT: |
1462 | OUTPUT: |
1343 | RETVAL |
1463 | RETVAL |
1344 | |
1464 | |
|
|
1465 | NV clamp (NV value, NV min_value, NV max_value) |
|
|
1466 | CODE: |
|
|
1467 | RETVAL = clamp (value, min_value, max_value); |
|
|
1468 | OUTPUT: |
|
|
1469 | RETVAL |
|
|
1470 | |
|
|
1471 | NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) |
|
|
1472 | CODE: |
|
|
1473 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
|
|
1474 | OUTPUT: |
|
|
1475 | RETVAL |
|
|
1476 | |
|
|
1477 | void cede_to_tick () |
|
|
1478 | CODE: |
|
|
1479 | coroapi::cede_to_tick (); |
|
|
1480 | |
1345 | void server_tick () |
1481 | void server_tick () |
1346 | CODE: |
1482 | CODE: |
1347 | runtime = SvNVx (sv_runtime); |
1483 | runtime = SvNVx (sv_runtime); |
1348 | server_tick (); |
1484 | server_tick (); |
1349 | |
1485 | |
1350 | void |
1486 | void |
|
|
1487 | log_backtrace (utf8_string msg) |
|
|
1488 | |
|
|
1489 | void |
1351 | LOG (int level, utf8_string msg) |
1490 | LOG (int flags, utf8_string msg) |
1352 | PROTOTYPE: $$ |
1491 | PROTOTYPE: $$ |
1353 | C_ARGS: (LogLevel)level, "%s", msg |
1492 | C_ARGS: flags, "%s", msg |
1354 | |
1493 | |
1355 | octet_string path_combine (octet_string base, octet_string path) |
1494 | octet_string path_combine (octet_string base, octet_string path) |
1356 | PROTOTYPE: $$ |
1495 | PROTOTYPE: $$ |
1357 | |
1496 | |
1358 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1497 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
… | |
… | |
1395 | } |
1534 | } |
1396 | OUTPUT: RETVAL |
1535 | OUTPUT: RETVAL |
1397 | |
1536 | |
1398 | void abort () |
1537 | void abort () |
1399 | |
1538 | |
|
|
1539 | void reset_signals () |
|
|
1540 | |
1400 | void fork_abort (octet_string cause = "cf::fork_abort") |
1541 | void fork_abort (octet_string cause = "cf::fork_abort") |
1401 | |
1542 | |
1402 | void cleanup (octet_string cause, bool make_core = false) |
1543 | void cleanup (octet_string cause, bool make_core = false) |
1403 | |
1544 | |
1404 | void emergency_save () |
1545 | void emergency_save () |
… | |
… | |
1466 | OUTPUT: RETVAL |
1607 | OUTPUT: RETVAL |
1467 | |
1608 | |
1468 | bool |
1609 | bool |
1469 | load_resource_file (octet_string filename) |
1610 | load_resource_file (octet_string filename) |
1470 | |
1611 | |
1471 | bool |
|
|
1472 | load_archetype_file (octet_string filename) |
|
|
1473 | |
|
|
1474 | bool |
|
|
1475 | load_treasure_file (octet_string filename) |
|
|
1476 | |
|
|
1477 | MODULE = cf PACKAGE = cf::attachable |
1612 | MODULE = cf PACKAGE = cf::attachable |
1478 | |
1613 | |
1479 | int |
1614 | int |
1480 | valid (SV *obj) |
1615 | valid (SV *obj) |
1481 | CODE: |
1616 | CODE: |
… | |
… | |
1544 | object *actives (U32 index) |
1679 | object *actives (U32 index) |
1545 | CODE: |
1680 | CODE: |
1546 | RETVAL = index < actives.size () ? actives [index] : 0; |
1681 | RETVAL = index < actives.size () ? actives [index] : 0; |
1547 | OUTPUT: RETVAL |
1682 | OUTPUT: RETVAL |
1548 | |
1683 | |
|
|
1684 | const char *slot_save_name (U32 slot) |
|
|
1685 | ALIAS: |
|
|
1686 | slot_use_name = 1 |
|
|
1687 | slot_nonuse_name = 2 |
|
|
1688 | CODE: |
|
|
1689 | { |
|
|
1690 | if (slot >= NUM_BODY_LOCATIONS) |
|
|
1691 | croak ("body slot index out of range"); |
|
|
1692 | |
|
|
1693 | switch (ix) |
|
|
1694 | { |
|
|
1695 | case 0: RETVAL = body_locations[slot].save_name; break; |
|
|
1696 | case 1: RETVAL = body_locations[slot].use_name; break; |
|
|
1697 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
|
|
1698 | } |
|
|
1699 | } |
|
|
1700 | OUTPUT: |
|
|
1701 | RETVAL |
|
|
1702 | |
1549 | # missing properties |
1703 | # missing properties |
1550 | |
1704 | |
1551 | object *head (object *op) |
1705 | object *head (object *op) |
1552 | PROTOTYPE: $ |
1706 | PROTOTYPE: $ |
1553 | CODE: |
1707 | CODE: |
… | |
… | |
1578 | int |
1732 | int |
1579 | num_animations (object *op) |
1733 | num_animations (object *op) |
1580 | CODE: |
1734 | CODE: |
1581 | RETVAL = NUM_ANIMATIONS (op); |
1735 | RETVAL = NUM_ANIMATIONS (op); |
1582 | OUTPUT: RETVAL |
1736 | OUTPUT: RETVAL |
|
|
1737 | |
|
|
1738 | int slot_info (object *op, UV slot, int value = 0) |
|
|
1739 | ALIAS: |
|
|
1740 | slot_used = 1 |
|
|
1741 | CODE: |
|
|
1742 | { |
|
|
1743 | if (slot >= NUM_BODY_LOCATIONS) |
|
|
1744 | croak ("body slot index out of range"); |
|
|
1745 | |
|
|
1746 | RETVAL = ix ? op->slot[slot].used : op->slot[slot].info; |
|
|
1747 | |
|
|
1748 | if (items > 2) |
|
|
1749 | if (ix) |
|
|
1750 | op->slot[slot].used = value; |
|
|
1751 | else |
|
|
1752 | op->slot[slot].info = value; |
|
|
1753 | } |
|
|
1754 | OUTPUT: |
|
|
1755 | RETVAL |
1583 | |
1756 | |
1584 | object *find_best_object_match (object *op, utf8_string match) |
1757 | object *find_best_object_match (object *op, utf8_string match) |
1585 | |
1758 | |
1586 | object *find_marked_object (object *op) |
1759 | object *find_marked_object (object *op) |
1587 | |
1760 | |
… | |
… | |
1936 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2109 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
1937 | { |
2110 | { |
1938 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2111 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
1939 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2112 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
1940 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2113 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
|
|
2114 | |
|
|
2115 | if (ob->randomitems) |
|
|
2116 | { |
|
|
2117 | if (!ob->above) |
|
|
2118 | { |
|
|
2119 | ob->create_treasure (ob->randomitems); |
|
|
2120 | |
|
|
2121 | for (object *op = ob->above; op; op = op->above) |
|
|
2122 | op->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2123 | } |
|
|
2124 | |
|
|
2125 | ob->randomitems = 0; |
|
|
2126 | } |
1941 | } |
2127 | } |
1942 | } |
2128 | } |
1943 | } |
2129 | } |
1944 | |
2130 | |
1945 | skip_space: ; |
2131 | skip_space: ; |
… | |
… | |
1972 | sfree (THIS->regions, THIS->size ()); |
2158 | sfree (THIS->regions, THIS->size ()); |
1973 | free (THIS->regionmap); |
2159 | free (THIS->regionmap); |
1974 | |
2160 | |
1975 | THIS->regions = regions; |
2161 | THIS->regions = regions; |
1976 | THIS->regionmap = regionmap; |
2162 | THIS->regionmap = regionmap; |
|
|
2163 | } |
|
|
2164 | |
|
|
2165 | void |
|
|
2166 | maptile::create_region_treasure () |
|
|
2167 | CODE: |
|
|
2168 | { |
|
|
2169 | object *op = object::create (); |
|
|
2170 | op->type = FLOOR; |
|
|
2171 | op->map = THIS; |
|
|
2172 | |
|
|
2173 | for (int x = 0; x < THIS->width; ++x) |
|
|
2174 | for (int y = 0; y < THIS->height; ++y) |
|
|
2175 | { |
|
|
2176 | region *rgn = THIS->region (x, y); |
|
|
2177 | |
|
|
2178 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2179 | if (rgn->treasure && rndm () < rgn->treasure_density) |
|
|
2180 | { |
|
|
2181 | op->x = x; |
|
|
2182 | op->y = y; |
|
|
2183 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
|
|
2184 | } |
|
|
2185 | } |
|
|
2186 | |
|
|
2187 | op->destroy (); |
1977 | } |
2188 | } |
1978 | |
2189 | |
1979 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2190 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
1980 | |
2191 | |
1981 | int out_of_map (maptile *map, int x, int y) |
2192 | int out_of_map (maptile *map, int x, int y) |
… | |
… | |
2205 | RETVAL = 0; |
2416 | RETVAL = 0; |
2206 | while (rgn = rgn->parent) |
2417 | while (rgn = rgn->parent) |
2207 | RETVAL++; |
2418 | RETVAL++; |
2208 | OUTPUT: RETVAL |
2419 | OUTPUT: RETVAL |
2209 | |
2420 | |
2210 | INCLUDE: $PERL $srcdir/genacc region ../include/map.h | |
2421 | INCLUDE: $PERL $srcdir/genacc region ../include/region.h | |
2211 | |
2422 | |
2212 | MODULE = cf PACKAGE = cf::living |
2423 | MODULE = cf PACKAGE = cf::living |
2213 | |
2424 | |
2214 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2425 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2215 | |
2426 | |