… | |
… | |
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@schmorpd.e> |
9 | * Copyright (C) 2006 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. |
… | |
… | |
24 | */ |
24 | */ |
25 | |
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 | #ifndef __CEXTRACT__ |
|
|
30 | #include <plugin.h> |
|
|
31 | #endif |
|
|
32 | |
|
|
33 | #undef MODULEAPI |
|
|
34 | #ifdef WIN32 |
|
|
35 | #else |
|
|
36 | #define MODULEAPI |
|
|
37 | #endif |
|
|
38 | |
|
|
39 | #include <plugin_common.h> |
29 | #include <plugin_common.h> |
40 | #include <sounds.h> |
30 | #include <sounds.h> |
41 | #include <cstdarg> |
31 | #include <cstdarg> |
42 | #include <sproto.h> |
32 | #include <sproto.h> |
43 | |
33 | |
… | |
… | |
50 | |
40 | |
51 | #include "perlxsi.c" |
41 | #include "perlxsi.c" |
52 | |
42 | |
53 | extern sint64 *levels; // the experience table |
43 | extern sint64 *levels; // the experience table |
54 | |
44 | |
55 | typedef object object_ornull; |
45 | typedef object object_ornull; |
56 | typedef mapstruct mapstruct_ornull; |
46 | typedef maptile maptile_ornull; |
57 | |
47 | |
|
|
48 | #if IVSIZE >= 8 |
|
|
49 | typedef IV val64; |
|
|
50 | # define newSVval64 newSViv |
|
|
51 | # define SvVAL64 SvIV |
|
|
52 | #else |
58 | typedef double val64; |
53 | typedef double val64; |
59 | #define newSVval64 newSVnv |
54 | # define newSVval64 newSVnv |
60 | #define SvVAL64 SvNV |
55 | # define SvVAL64 SvNV |
|
|
56 | #endif |
61 | |
57 | |
62 | static f_plug_api gethook = cfapi_get_hooks; |
58 | static f_plug_api gethook = cfapi_get_hooks; |
63 | static f_plug_api object_set_property = cfapi_object_set_property; |
59 | static f_plug_api object_set_property = cfapi_object_set_property; |
64 | static f_plug_api object_insert = cfapi_object_insert; |
60 | static f_plug_api object_insert = cfapi_object_insert; |
65 | |
61 | |
66 | static bool perl_booted; |
|
|
67 | |
|
|
68 | /* this is a stupid way to do things, and awkward to use for plug-in authors */ |
|
|
69 | typedef struct |
|
|
70 | { |
|
|
71 | object* who; |
|
|
72 | object* activator; |
|
|
73 | object* third; |
|
|
74 | object* event; |
|
|
75 | mapstruct* map; |
|
|
76 | char message[1024]; |
|
|
77 | int fix; // seems to be python-only, and should not be part of the API |
|
|
78 | int event_code; |
|
|
79 | char extension[1024]; // name field, should invoke specific perl extension |
|
|
80 | char options[1024]; // slaying field of event_connectors |
|
|
81 | int returnvalue; |
|
|
82 | } CFPContext; |
|
|
83 | |
|
|
84 | static HV *obj_cache; |
|
|
85 | static PerlInterpreter *perl; |
62 | static PerlInterpreter *perl; |
86 | |
63 | |
87 | static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; |
64 | static AV *cb_global, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
88 | |
|
|
89 | #define PUSHcfapi(type,value) PUSHs (sv_2mortal (newSVcfapi (CFAPI_ ## type, (value)))) |
|
|
90 | #define PUSHcfapi_va(type,ctype) PUSHcfapi (type, va_arg (args, ctype)) |
|
|
91 | #define PUSH_OB PUSHcfapi_va(POBJECT, object *) |
|
|
92 | #define PUSH_PL PUSHcfapi_va(PPLAYER, player *) |
|
|
93 | #define PUSH_MAP PUSHcfapi_va(PMAP, mapstruct *) |
|
|
94 | #define PUSH_PV PUSHcfapi_va(STRING, const char *) |
|
|
95 | #define PUSH_IV PUSHs (sv_2mortal (newSViv (va_arg (args, int)))) |
|
|
96 | |
65 | |
97 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
66 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
98 | |
67 | |
99 | static SV * |
68 | static SV * |
100 | newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) |
69 | newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) |
… | |
… | |
117 | |
86 | |
118 | if (!obj->self) |
87 | if (!obj->self) |
119 | obj->self = newSVptr (obj, klass); |
88 | obj->self = newSVptr (obj, klass); |
120 | |
89 | |
121 | return newSVsv (obj->self); |
90 | return newSVsv (obj->self); |
122 | } |
|
|
123 | |
|
|
124 | static void |
|
|
125 | SVptr_cache_set (void *ptr, SV *sv) |
|
|
126 | { |
|
|
127 | hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); |
|
|
128 | } |
|
|
129 | |
|
|
130 | static SV * |
|
|
131 | SVptr_cache_get (void *ptr) |
|
|
132 | { |
|
|
133 | SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0); |
|
|
134 | |
|
|
135 | return he ? *he : 0; |
|
|
136 | } |
|
|
137 | |
|
|
138 | static SV * |
|
|
139 | newSVptr_cached (void *ptr, const char *klass) |
|
|
140 | { |
|
|
141 | SV *sv; |
|
|
142 | |
|
|
143 | if (!ptr) |
|
|
144 | return &PL_sv_undef; |
|
|
145 | |
|
|
146 | sv = SVptr_cache_get (ptr); |
|
|
147 | |
|
|
148 | if (!sv) |
|
|
149 | { |
|
|
150 | HV *hv = newHV (); |
|
|
151 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
|
|
152 | sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
153 | |
|
|
154 | SVptr_cache_set (ptr, sv); |
|
|
155 | } |
|
|
156 | |
|
|
157 | return newSVsv (sv); |
|
|
158 | } |
91 | } |
159 | |
92 | |
160 | static void |
93 | static void |
161 | clearSVptr (SV *sv) |
94 | clearSVptr (SV *sv) |
162 | { |
95 | { |
… | |
… | |
186 | { |
119 | { |
187 | if (SvOK (sv)) |
120 | if (SvOK (sv)) |
188 | return SvPTR (sv, klass); |
121 | return SvPTR (sv, klass); |
189 | else |
122 | else |
190 | return 0; |
123 | return 0; |
|
|
124 | } |
|
|
125 | |
|
|
126 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } |
|
|
127 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
|
|
128 | inline SV *to_sv (bool v) { return newSViv (v); } |
|
|
129 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
|
|
130 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
|
|
131 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
|
|
132 | inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
|
|
133 | inline SV *to_sv ( signed int v) { return newSViv (v); } |
|
|
134 | inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
|
|
135 | inline SV *to_sv ( signed long v) { return newSViv (v); } |
|
|
136 | inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
|
|
137 | inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
|
|
138 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
|
|
139 | inline SV *to_sv (float v) { return newSVnv (v); } |
|
|
140 | inline SV *to_sv (double v) { return newSVnv (v); } |
|
|
141 | inline SV *to_sv (client * v) { return newSVattachable (v, "cf::client::wrap"); } |
|
|
142 | inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } |
|
|
143 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } |
|
|
144 | inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); } |
|
|
145 | inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } |
|
|
146 | inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } |
|
|
147 | inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } |
|
|
148 | inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } |
|
|
149 | |
|
|
150 | inline SV *to_sv (object & v) { return to_sv (&v); } |
|
|
151 | inline SV *to_sv (living & v) { return to_sv (&v); } |
|
|
152 | |
|
|
153 | //TODO: |
|
|
154 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
|
|
155 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
156 | |
|
|
157 | inline SV *to_sv (UUID v) |
|
|
158 | { |
|
|
159 | char buf[128]; |
|
|
160 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
|
|
161 | return newSVpv (buf, 0); |
|
|
162 | } |
|
|
163 | |
|
|
164 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
|
|
165 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
|
|
166 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
|
|
167 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
|
|
168 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
|
|
169 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
|
|
170 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
|
|
171 | inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
|
|
172 | inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
|
|
173 | inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
|
|
174 | inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
|
|
175 | inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
|
|
176 | inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
|
|
177 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
|
|
178 | inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
|
|
179 | inline void sv_to (SV *sv, client * &v) { v = (client *)SvPTR_ornull (sv, "cf::client"); } |
|
|
180 | inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); } |
|
|
181 | inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); } |
|
|
182 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); } |
|
|
183 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)SvPTR_ornull (sv, "cf::map"); } |
|
|
184 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
|
|
185 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
|
|
186 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
|
|
187 | |
|
|
188 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
|
|
189 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO |
|
|
190 | |
|
|
191 | template<class T> |
|
|
192 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
|
|
193 | |
|
|
194 | template<int N> |
|
|
195 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
|
|
196 | |
|
|
197 | inline void sv_to (SV *sv, UUID &v) |
|
|
198 | { |
|
|
199 | unsigned int version; |
|
|
200 | |
|
|
201 | if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) |
|
|
202 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
191 | } |
203 | } |
192 | |
204 | |
193 | static SV * |
205 | static SV * |
194 | newSVdt_va (va_list &ap, data_type type) |
206 | newSVdt_va (va_list &ap, data_type type) |
195 | { |
207 | { |
… | |
… | |
223 | sv = str ? newSVpv (str, len) : &PL_sv_undef; |
235 | sv = str ? newSVpv (str, len) : &PL_sv_undef; |
224 | } |
236 | } |
225 | break; |
237 | break; |
226 | |
238 | |
227 | case DT_OBJECT: |
239 | case DT_OBJECT: |
228 | { |
240 | sv = to_sv (va_arg (ap, object *)); |
229 | object *obj = va_arg (ap, object *); |
|
|
230 | sv = newSVattachable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
|
|
231 | } |
|
|
232 | break; |
241 | break; |
233 | |
242 | |
234 | case DT_MAP: |
243 | case DT_MAP: |
235 | // va_arg (object *) when void * is passed is an XSI extension |
244 | // va_arg (object *) when void * is passed is an XSI extension |
236 | sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
245 | sv = to_sv (va_arg (ap, maptile *)); |
237 | break; |
246 | break; |
238 | |
247 | |
|
|
248 | case DT_CLIENT: |
|
|
249 | sv = to_sv (va_arg (ap, client *)); |
|
|
250 | break; |
|
|
251 | |
239 | case DT_PLAYER: |
252 | case DT_PLAYER: |
240 | sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap"); |
253 | sv = to_sv (va_arg (ap, player *)); |
241 | break; |
254 | break; |
242 | |
255 | |
243 | case DT_ARCH: |
256 | case DT_ARCH: |
244 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
257 | sv = to_sv (va_arg (ap, archetype *)); |
245 | break; |
258 | break; |
246 | |
259 | |
247 | case DT_PARTY: |
260 | case DT_PARTY: |
248 | sv = newSVptr (va_arg (ap, partylist *), "cf::party::wrap"); |
261 | sv = to_sv (va_arg (ap, partylist *)); |
249 | break; |
262 | break; |
250 | |
263 | |
251 | case DT_REGION: |
264 | case DT_REGION: |
252 | sv = newSVptr (va_arg (ap, region *), "cf::region::wrap"); |
265 | sv = to_sv (va_arg (ap, region *)); |
253 | break; |
266 | break; |
254 | |
267 | |
255 | default: |
268 | default: |
256 | assert (("unhandled type in newSVdt_va", 0)); |
269 | assert (("unhandled type in newSVdt_va", 0)); |
257 | } |
270 | } |
… | |
… | |
302 | } |
315 | } |
303 | |
316 | |
304 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
317 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
305 | |
318 | |
306 | SV * |
319 | SV * |
307 | registry_of (attachable_base *ext) |
320 | registry (attachable_base *ext) |
308 | { |
321 | { |
309 | if (!ext->cb) |
322 | if (!ext->cb) |
310 | ext->cb = newAV (); |
323 | ext->cb = newAV (); |
311 | |
324 | |
312 | return newRV_inc ((SV *)ext->cb); |
325 | return newRV_inc ((SV *)ext->cb); |
… | |
… | |
318 | { |
331 | { |
319 | if (cb) |
332 | if (cb) |
320 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
333 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
321 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
334 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
322 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
335 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
323 | INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); |
336 | INVOKE_MAP (DESTROY, static_cast<maptile *>(this)); |
324 | |
337 | |
325 | // disconnect Perl from C, to avoid crashes |
338 | // disconnect Perl from C, to avoid crashes |
326 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
339 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
327 | |
340 | |
328 | // clear the perl hash, might or might not be a good idea |
341 | // clear the perl hash, might or might not be a good idea |
… | |
… | |
336 | { |
349 | { |
337 | SvREFCNT_dec (cb); |
350 | SvREFCNT_dec (cb); |
338 | cb = 0; |
351 | cb = 0; |
339 | } |
352 | } |
340 | |
353 | |
341 | if (attach) |
|
|
342 | { |
|
|
343 | free_string (attach); |
|
|
344 | attach = 0; |
354 | attach = 0; |
345 | } |
|
|
346 | } |
355 | } |
347 | |
356 | |
348 | void attachable_base::optimise () |
357 | void attachable_base::optimise () |
349 | { |
358 | { |
350 | if (!self) |
359 | if (!self) |
… | |
… | |
352 | |
361 | |
353 | HV *hv = (HV *)SvRV ((SV *)self); |
362 | HV *hv = (HV *)SvRV ((SV *)self); |
354 | |
363 | |
355 | if (SvREFCNT ((SV *)self) == 1 |
364 | if (SvREFCNT ((SV *)self) == 1 |
356 | && SvREFCNT ((SV *)hv) == 1 |
365 | && SvREFCNT ((SV *)hv) == 1 |
357 | && !HvKEYS (hv)) |
366 | && !HvTOTALKEYS (hv)) |
358 | { |
367 | { |
359 | SvREFCNT_dec ((SV *)self); |
368 | SvREFCNT_dec ((SV *)self); |
360 | self = 0; |
369 | self = 0; |
361 | } |
370 | } |
362 | } |
371 | } |
… | |
… | |
369 | PUSHMARK (SP); |
378 | PUSHMARK (SP); |
370 | EXTEND (SP, 2); |
379 | EXTEND (SP, 2); |
371 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
380 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
372 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
381 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
373 | |
382 | |
374 | free_string (attach); |
|
|
375 | attach = 0; |
383 | attach = 0; |
376 | |
384 | |
377 | PUTBACK; |
385 | PUTBACK; |
378 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
386 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
379 | FREETMPS; |
387 | FREETMPS; |
… | |
… | |
404 | |
412 | |
405 | switch (type) |
413 | switch (type) |
406 | { |
414 | { |
407 | case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; |
415 | case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; |
408 | case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; |
416 | case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; |
|
|
417 | case DT_CLIENT: INVOKE_CLIENT (REATTACH, obj); break; |
409 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
418 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
410 | } |
419 | } |
411 | } |
420 | } |
412 | |
421 | |
413 | template<class subclass> |
422 | template<class subclass> |
414 | void reattach (attachable<subclass> *obj) |
423 | void reattach (attachable<subclass> *obj) |
415 | { |
424 | { |
416 | obj->optimise (); |
425 | obj->optimise (); |
417 | |
426 | |
418 | if (obj->self) |
427 | if (obj->self) |
419 | reattach (subclass::get_dt (), (subclass *)obj); |
428 | reattach ((data_type) cftype<subclass>::dt, (subclass *)obj); |
420 | } |
429 | } |
421 | |
430 | |
|
|
431 | #include "kw_hash.h" |
|
|
432 | |
422 | object_freezer::object_freezer (const char *filename) |
433 | object_freezer::object_freezer () |
|
|
434 | : dynbuf (128 * 1024, 64 * 1024) |
423 | { |
435 | { |
424 | this->filename = (SV *)newSVpv (filename, 0); |
|
|
425 | |
|
|
426 | char filename2 [4096]; |
|
|
427 | snprintf (filename2, 4096, "%s~", filename); |
|
|
428 | |
|
|
429 | av = newAV (); |
436 | av = newAV (); |
430 | |
|
|
431 | // TODO: fast dynbuf implementation... yeah, we need obstacks |
|
|
432 | text = newSV (10 * 1024 * 1024); // only temporarily used, so be generous |
|
|
433 | } |
437 | } |
434 | |
438 | |
435 | object_freezer::~object_freezer () |
439 | object_freezer::~object_freezer () |
|
|
440 | { |
|
|
441 | SvREFCNT_dec (av); |
|
|
442 | } |
|
|
443 | |
|
|
444 | void object_freezer::put (attachable_base *ext) |
|
|
445 | { |
|
|
446 | ext->optimise (); |
|
|
447 | |
|
|
448 | if (ext->self) |
|
|
449 | { |
|
|
450 | int idx = AvFILLp ((AV *)av) + 1; |
|
|
451 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
|
|
452 | |
|
|
453 | add ((void *)"oid ", 4); |
|
|
454 | add ((sint32)idx); |
|
|
455 | add ('\n'); |
|
|
456 | } |
|
|
457 | } |
|
|
458 | |
|
|
459 | bool object_freezer::save (const char *filename) |
436 | { |
460 | { |
437 | dSP; |
461 | dSP; |
438 | ENTER; |
462 | ENTER; |
439 | SAVETMPS; |
463 | SAVETMPS; |
440 | PUSHMARK (SP); |
464 | PUSHMARK (SP); |
|
|
465 | EXTEND (SP, 3); |
441 | XPUSHs (sv_2mortal ((SV *)filename)); |
466 | PUSHs (sv_2mortal (newSVpv (filename, 0))); |
442 | XPUSHs (sv_2mortal (newRV_noinc (text))); |
467 | PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); |
443 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
468 | PUSHs (sv_2mortal (newRV_inc ((SV *)av))); |
444 | PUTBACK; |
469 | PUTBACK; |
445 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
470 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
446 | FREETMPS; |
471 | FREETMPS; |
447 | LEAVE; |
472 | LEAVE; |
448 | } |
473 | } |
449 | |
474 | |
450 | void object_freezer::put (attachable_base *ext) |
475 | char *object_freezer::as_string () |
451 | { |
476 | { |
452 | ext->optimise (); |
477 | dSP; |
|
|
478 | ENTER; |
|
|
479 | SAVETMPS; |
|
|
480 | PUSHMARK (SP); |
|
|
481 | EXTEND (SP, 3); |
|
|
482 | PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); |
|
|
483 | PUSHs (sv_2mortal (newRV_inc ((SV *)av))); |
|
|
484 | PUTBACK; |
453 | |
485 | |
454 | if (ext->self) |
486 | char *res = call_pv ("cf::object_freezer_as_string", G_SCALAR | G_EVAL) > 0 |
455 | { |
487 | ? strdup (SvPVbyte_nolen (POPs)) |
456 | int idx = AvFILLp ((AV *)av) + 1; |
488 | : strdup ("[fatal error]"); |
457 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
|
|
458 | |
489 | |
459 | sv_catpvf (text, "oid %d\n", idx); |
490 | FREETMPS; |
460 | } |
491 | LEAVE; |
|
|
492 | |
|
|
493 | return res; |
461 | } |
494 | } |
462 | |
495 | |
463 | int fprintf (object_freezer &freezer, const char *format, ...) |
496 | int fprintf (object_freezer &freezer, const char *format, ...) |
464 | { |
497 | { |
465 | va_list ap; |
498 | va_list ap; |
466 | |
499 | |
467 | va_start (ap, format); |
500 | va_start (ap, format); |
468 | sv_vcatpvfn (freezer.text, format, strlen (format), &ap, 0, 0, 0); |
501 | |
|
|
502 | int len = vsnprintf ((char *)freezer.force (1024), 1024, format, ap); |
|
|
503 | |
|
|
504 | if (len >= 0) |
|
|
505 | freezer.alloc (len); |
|
|
506 | |
469 | va_end (ap); |
507 | va_end (ap); |
470 | } |
508 | } |
471 | |
509 | |
472 | int fputs (const char *s, object_freezer &freezer) |
510 | int fputs (const char *s, object_freezer &freezer) |
473 | { |
511 | { |
474 | sv_catpvn (freezer.text, s, strlen (s)); |
512 | freezer.add (s); |
475 | } |
513 | } |
|
|
514 | |
|
|
515 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
476 | |
516 | |
477 | object_thawer::object_thawer (const char *filename) |
517 | object_thawer::object_thawer (const char *filename) |
478 | { |
518 | { |
|
|
519 | static const char eof[] = "\n\n\n\0\0\0"; |
|
|
520 | |
479 | av = 0; |
521 | av = 0; |
480 | fp = 0; |
522 | text = 0; |
|
|
523 | line = 0; |
481 | |
524 | |
482 | if (!filename) |
525 | if (filename) |
483 | return; |
|
|
484 | |
|
|
485 | fp = fopen (filename, "r"); |
|
|
486 | if (!fp) |
|
|
487 | { |
|
|
488 | LOG (llevError, "object_thawer: unable to open '%s': %s.\n", filename, strerror (errno)); |
|
|
489 | return; |
|
|
490 | } |
|
|
491 | |
|
|
492 | if (perl_booted) |
|
|
493 | { |
526 | { |
494 | dSP; |
527 | dSP; |
495 | ENTER; |
528 | ENTER; |
496 | SAVETMPS; |
529 | SAVETMPS; |
497 | PUSHMARK (SP); |
530 | PUSHMARK (SP); |
498 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
531 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
499 | PUTBACK; |
532 | PUTBACK; |
500 | |
533 | |
501 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
534 | if (2 == call_pv ("cf::object_thawer_load", G_ARRAY | G_EVAL)) |
502 | { |
535 | { |
503 | SPAGAIN; |
536 | SPAGAIN; |
|
|
537 | |
|
|
538 | // second value - perl objects |
|
|
539 | { |
504 | SV *sv = POPs; |
540 | SV *sv = POPs; |
505 | if (SvROK (sv)) |
541 | if (SvROK (sv)) |
506 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
542 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
|
|
543 | } |
|
|
544 | |
|
|
545 | // first value - text part, pad with 3 zeroes |
|
|
546 | { |
|
|
547 | SV *sv = POPs; |
|
|
548 | STRLEN len; |
|
|
549 | char *sv_ = SvPVbyte (sv, len); |
|
|
550 | text = newSV (len + sizeof (eof)); |
|
|
551 | SvCUR_set (text, len); |
|
|
552 | memcpy (SvPVX (text), sv_, len); |
|
|
553 | memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure |
|
|
554 | |
|
|
555 | line = SvPVX (text); |
|
|
556 | } |
507 | } |
557 | } |
508 | |
558 | |
|
|
559 | PUTBACK; |
509 | FREETMPS; |
560 | FREETMPS; |
510 | LEAVE; |
561 | LEAVE; |
511 | } |
562 | } |
|
|
563 | } |
|
|
564 | |
|
|
565 | object_thawer::object_thawer (const char *data, AV *perlav) |
|
|
566 | { |
|
|
567 | av = perlav; |
|
|
568 | text = newSVpv (data, 0); |
|
|
569 | sv_catpv (text, thawer_eof); |
|
|
570 | line = SvPVbyte_nolen (text); |
512 | } |
571 | } |
513 | |
572 | |
514 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
573 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
515 | { |
574 | { |
516 | if (!av || oid < 0) // this is actually an error of sorts |
575 | if (!av || oid < 0) // this is actually an error of sorts |
… | |
… | |
533 | reattach (type, obj); |
592 | reattach (type, obj); |
534 | } |
593 | } |
535 | |
594 | |
536 | object_thawer::~object_thawer () |
595 | object_thawer::~object_thawer () |
537 | { |
596 | { |
538 | if (fp) fclose (fp); |
597 | if (text) SvREFCNT_dec (text); |
539 | if (av) SvREFCNT_dec ((AV *)av); |
598 | if (av) SvREFCNT_dec (av); |
|
|
599 | } |
|
|
600 | |
|
|
601 | char *fgets (char *s, int n, object_thawer &thawer) |
|
|
602 | { |
|
|
603 | char *p = thawer.line; |
|
|
604 | char *q = s; |
|
|
605 | |
|
|
606 | if (!p) |
|
|
607 | return 0; |
|
|
608 | |
|
|
609 | while (--n) |
|
|
610 | { |
|
|
611 | if (!*p) |
|
|
612 | break; |
|
|
613 | |
|
|
614 | *q++ = *p; |
|
|
615 | |
|
|
616 | if (*p++ == '\n') |
|
|
617 | break; |
|
|
618 | } |
|
|
619 | |
|
|
620 | *q = 0; |
|
|
621 | thawer.line = p; |
|
|
622 | |
|
|
623 | return s == q ? 0 : s; |
|
|
624 | } |
|
|
625 | |
|
|
626 | keyword object_thawer::get_kv () |
|
|
627 | { |
|
|
628 | if (!line) |
|
|
629 | return KW_EOF; |
|
|
630 | |
|
|
631 | for (;;) |
|
|
632 | { |
|
|
633 | char *p = line; |
|
|
634 | |
|
|
635 | if (!*p) |
|
|
636 | return KW_EOF; |
|
|
637 | |
|
|
638 | // parse keyword |
|
|
639 | while (*p > ' ') |
|
|
640 | p++; |
|
|
641 | |
|
|
642 | int klen = p - line; |
|
|
643 | |
|
|
644 | if (*p++ != '\n') |
|
|
645 | { |
|
|
646 | // parse value |
|
|
647 | while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 |
|
|
648 | ++p; |
|
|
649 | |
|
|
650 | last_value = p; |
|
|
651 | |
|
|
652 | while (*p != '\n') |
|
|
653 | p++; |
|
|
654 | |
|
|
655 | *p++ = 0; |
|
|
656 | } |
|
|
657 | else |
|
|
658 | last_value = 0; |
|
|
659 | |
|
|
660 | line [klen] = 0; |
|
|
661 | keyword_idx *kw = kw_lex::match (line, klen); |
|
|
662 | |
|
|
663 | //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D |
|
|
664 | |
|
|
665 | if (kw) |
|
|
666 | { |
|
|
667 | line = p; |
|
|
668 | return kw->index; |
|
|
669 | } |
|
|
670 | else if (!*line || *line == '#') |
|
|
671 | { |
|
|
672 | // empty/comment line |
|
|
673 | line = p; |
|
|
674 | } |
|
|
675 | else |
|
|
676 | return KW_ERROR; |
|
|
677 | } |
|
|
678 | } |
|
|
679 | |
|
|
680 | void object_thawer::get (shstr &sh) const |
|
|
681 | { |
|
|
682 | if (last_value) |
|
|
683 | sh = last_value; |
|
|
684 | else |
|
|
685 | { |
|
|
686 | sh = "<value missing>"; |
|
|
687 | LOG (llevError, "keyword requires value: <%s>\n", line);//TODO: add filename |
|
|
688 | } |
|
|
689 | } |
|
|
690 | |
|
|
691 | void object_thawer::get_ml (keyword kend, shstr &sh) |
|
|
692 | { |
|
|
693 | char kw[128]; |
|
|
694 | |
|
|
695 | int klen = keyword_len [kend]; |
|
|
696 | |
|
|
697 | kw [0] = '\n'; |
|
|
698 | memcpy (kw + 1, keyword_str [kend], klen); |
|
|
699 | kw [klen + 1] = '\n'; |
|
|
700 | kw [klen + 2] = 0; |
|
|
701 | |
|
|
702 | // first test for completely empty msg... "endXXX\n" |
|
|
703 | if (!strncmp (line, kw + 1, klen + 1)) |
|
|
704 | { |
|
|
705 | sh = 0; |
|
|
706 | |
|
|
707 | line += klen + 1; |
|
|
708 | |
|
|
709 | return; |
|
|
710 | } |
|
|
711 | else |
|
|
712 | { |
|
|
713 | // multi-line strings are delimited by "\nendXXX\n" or "endXXX\n" (NULL) |
|
|
714 | |
|
|
715 | char *end = strstr (line, kw); |
|
|
716 | |
|
|
717 | if (!end) |
|
|
718 | { |
|
|
719 | sh = 0; |
|
|
720 | return; |
|
|
721 | } |
|
|
722 | |
|
|
723 | *end = 0; |
|
|
724 | sh = line; |
|
|
725 | |
|
|
726 | line = end + keyword_len [kend] + 1; |
|
|
727 | |
|
|
728 | while (*line++ != '\n') |
|
|
729 | ; |
|
|
730 | } |
|
|
731 | } |
|
|
732 | |
|
|
733 | sint32 object_thawer::get_sint32 () const |
|
|
734 | { |
|
|
735 | char *p = last_value; |
|
|
736 | |
|
|
737 | if (!p) |
|
|
738 | return 0; |
|
|
739 | |
|
|
740 | sint32 val = 0; |
|
|
741 | bool negate; |
|
|
742 | |
|
|
743 | if (*p == '-') |
|
|
744 | { |
|
|
745 | negate = true; |
|
|
746 | ++p; |
|
|
747 | } |
|
|
748 | else |
|
|
749 | negate = false; |
|
|
750 | |
|
|
751 | do |
|
|
752 | { |
|
|
753 | val *= 10; |
|
|
754 | val += *p++ - '0'; |
|
|
755 | } |
|
|
756 | while (*p); |
|
|
757 | |
|
|
758 | return negate ? -val : val; |
|
|
759 | } |
|
|
760 | |
|
|
761 | sint64 object_thawer::get_sint64 () const |
|
|
762 | { |
|
|
763 | return last_value ? atoll (last_value) : 0; |
|
|
764 | } |
|
|
765 | |
|
|
766 | double object_thawer::get_double () const |
|
|
767 | { |
|
|
768 | return last_value ? atof (last_value) : 0; |
540 | } |
769 | } |
541 | |
770 | |
542 | ///////////////////////////////////////////////////////////////////////////// |
771 | ///////////////////////////////////////////////////////////////////////////// |
543 | |
772 | |
544 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
773 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
… | |
… | |
549 | static CommArray_s rtn_cmd; |
778 | static CommArray_s rtn_cmd; |
550 | |
779 | |
551 | static int |
780 | static int |
552 | runPluginCommand (object *obj, char *params) |
781 | runPluginCommand (object *obj, char *params) |
553 | { |
782 | { |
554 | dSP; |
783 | return -1; |
555 | |
|
|
556 | ENTER; |
|
|
557 | SAVETMPS; |
|
|
558 | |
|
|
559 | PUSHMARK (SP); |
|
|
560 | |
|
|
561 | EXTEND (SP, 3); |
|
|
562 | PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0))); |
|
|
563 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj))); |
|
|
564 | |
|
|
565 | if (params) |
|
|
566 | PUSHs (sv_2mortal (newSVpv (params, 0))); |
|
|
567 | |
|
|
568 | PUTBACK; |
|
|
569 | int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL); |
|
|
570 | SPAGAIN; |
|
|
571 | |
|
|
572 | if (SvTRUE (ERRSV)) |
|
|
573 | LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV)); |
|
|
574 | |
|
|
575 | int returnvalue = count > 0 ? POPi : -1; |
|
|
576 | |
|
|
577 | PUTBACK; |
|
|
578 | FREETMPS; |
|
|
579 | LEAVE; |
|
|
580 | |
|
|
581 | return returnvalue; |
|
|
582 | } |
784 | } |
583 | |
785 | |
584 | extern "C" void *cfperl_getPluginProperty (int *type, ...) |
786 | extern "C" void *cfperl_getPluginProperty (int *type, ...) |
585 | { |
787 | { |
586 | va_list args; |
788 | va_list args; |
… | |
… | |
589 | va_start (args, type); |
791 | va_start (args, type); |
590 | propname = va_arg (args, char *); |
792 | propname = va_arg (args, char *); |
591 | //printf ("Property name: %s\n", propname); |
793 | //printf ("Property name: %s\n", propname); |
592 | |
794 | |
593 | if (!strcmp (propname, "command?")) |
795 | if (!strcmp (propname, "command?")) |
594 | { |
|
|
595 | if (!perl) |
|
|
596 | return NULL; |
796 | return NULL; |
597 | |
|
|
598 | const char *cmdname = va_arg (args, const char *); |
|
|
599 | HV *hv = get_hv ("cf::COMMAND", 1); |
|
|
600 | SV **svp = hv_fetch (hv, cmdname, strlen (cmdname) + 1, 0); |
|
|
601 | |
|
|
602 | va_end (args); |
|
|
603 | |
|
|
604 | if (svp) |
|
|
605 | { |
|
|
606 | // this is totaly broken, should stash it into %COMMAND |
|
|
607 | rtn_cmd.name = cmdname; |
|
|
608 | rtn_cmd.time = SvNV (*svp); |
|
|
609 | rtn_cmd.func = runPluginCommand; |
|
|
610 | |
|
|
611 | return &rtn_cmd; |
|
|
612 | } |
|
|
613 | } |
|
|
614 | else if (!strcmp (propname, "Identification")) |
797 | else if (!strcmp (propname, "Identification")) |
615 | { |
798 | { |
616 | va_end (args); |
799 | va_end (args); |
617 | return (void*) PLUGIN_NAME; |
800 | return (void *)PLUGIN_NAME; |
618 | } |
801 | } |
619 | else if (!strcmp (propname, "FullName")) |
802 | else if (!strcmp (propname, "FullName")) |
620 | { |
803 | { |
621 | va_end (args); |
804 | va_end (args); |
622 | return (void*) PLUGIN_VERSION; |
805 | return (void *)PLUGIN_VERSION; |
623 | } |
806 | } |
624 | else |
807 | else |
625 | va_end (args); |
808 | va_end (args); |
626 | |
809 | |
627 | return NULL; |
810 | return NULL; |
… | |
… | |
652 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
835 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
653 | |
836 | |
654 | char *argv[] = { |
837 | char *argv[] = { |
655 | "", |
838 | "", |
656 | "-e" |
839 | "-e" |
657 | "cf->bootstrap;" |
840 | "use Event;" // required for bootstrap |
|
|
841 | "cf->bootstrap;" // required for datadir :*> |
658 | "unshift @INC, cf::datadir ();" |
842 | "unshift @INC, cf::datadir ();" |
|
|
843 | "require cf;" |
659 | }; |
844 | }; |
660 | |
845 | |
661 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
846 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
662 | { |
847 | { |
663 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
848 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
664 | exit (EXIT_FAILURE); |
849 | exit (EXIT_FAILURE); |
665 | } |
850 | } |
666 | |
|
|
667 | obj_cache = newHV (); |
|
|
668 | } |
|
|
669 | |
|
|
670 | void cfperl_boot () |
|
|
671 | { |
|
|
672 | perl_booted = true; |
|
|
673 | |
|
|
674 | eval_pv ("require cf", 1); |
|
|
675 | } |
851 | } |
676 | |
852 | |
677 | void cfperl_main () |
853 | void cfperl_main () |
678 | { |
854 | { |
679 | dSP; |
855 | dSP; |
… | |
… | |
730 | |
906 | |
731 | AV *callbacks = 0; |
907 | AV *callbacks = 0; |
732 | |
908 | |
733 | object *op; |
909 | object *op; |
734 | player *pl; |
910 | player *pl; |
735 | mapstruct *map; |
911 | maptile *map; |
|
|
912 | client *ns; |
736 | |
913 | |
737 | // callback call ordering is: |
914 | // callback call ordering is: |
738 | // 1. per-object callback (NYI) |
915 | // 1. per-object callback |
739 | // 2. per-class object |
916 | // 2. per-class object |
740 | // 2a. per-type callback |
917 | // 3. per-type callback |
741 | // 4. global callbacks |
918 | // 4. global callbacks |
742 | |
919 | |
743 | gather_callbacks (callbacks, cb_global, event); |
920 | gather_callbacks (callbacks, cb_global, event); |
744 | |
921 | |
745 | switch (KLASS_OF (event)) |
922 | switch (KLASS_OF (event)) |
… | |
… | |
790 | break; |
967 | break; |
791 | |
968 | |
792 | case KLASS_MAP: |
969 | case KLASS_MAP: |
793 | dt = (data_type) va_arg (ap, int); |
970 | dt = (data_type) va_arg (ap, int); |
794 | assert (("first argument must be of type object", dt == DT_MAP)); |
971 | assert (("first argument must be of type object", dt == DT_MAP)); |
795 | map = va_arg (ap, mapstruct *); |
972 | map = va_arg (ap, maptile *); |
796 | |
973 | |
797 | if (map->cb) |
974 | if (map->cb) |
798 | gather_callbacks (callbacks, map->cb, event); |
975 | gather_callbacks (callbacks, map->cb, event); |
799 | |
976 | |
800 | gather_callbacks (callbacks, cb_map, event); |
977 | gather_callbacks (callbacks, cb_map, event); |
|
|
978 | break; |
|
|
979 | |
|
|
980 | case KLASS_CLIENT: |
|
|
981 | dt = (data_type) va_arg (ap, int); |
|
|
982 | assert (("first argument must be of type client", dt == DT_CLIENT)); |
|
|
983 | ns = va_arg (ap, client *); |
|
|
984 | |
|
|
985 | if (ns->cb) |
|
|
986 | gather_callbacks (callbacks, ns->cb, event); |
|
|
987 | |
|
|
988 | gather_callbacks (callbacks, cb_client, event); |
801 | break; |
989 | break; |
802 | |
990 | |
803 | default: |
991 | default: |
804 | assert (("unsupported event klass in cfperl_invoke", 0)); |
992 | assert (("unsupported event klass in cfperl_invoke", 0)); |
805 | } |
993 | } |
… | |
… | |
820 | |
1008 | |
821 | switch (KLASS_OF (event)) |
1009 | switch (KLASS_OF (event)) |
822 | { |
1010 | { |
823 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
1011 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
824 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
1012 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
|
|
1013 | case KLASS_CLIENT: PUSHs (sv_2mortal (newSVdt (DT_CLIENT, ns))); break; |
825 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
1014 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
826 | } |
1015 | } |
827 | |
1016 | |
828 | for (;;) |
1017 | for (;;) |
829 | { |
1018 | { |
… | |
… | |
875 | cfperl_result_INT (int idx) |
1064 | cfperl_result_INT (int idx) |
876 | { |
1065 | { |
877 | return SvIV (cfperl_result (idx)); |
1066 | return SvIV (cfperl_result (idx)); |
878 | } |
1067 | } |
879 | |
1068 | |
|
|
1069 | double |
|
|
1070 | cfperl_result_DOUBLE (int idx) |
|
|
1071 | { |
|
|
1072 | return SvNV (cfperl_result (idx)); |
|
|
1073 | } |
|
|
1074 | |
|
|
1075 | ///////////////////////////////////////////////////////////////////////////// |
|
|
1076 | |
|
|
1077 | struct EventAPI *watcher_base::GEventAPI; |
|
|
1078 | |
|
|
1079 | static void iw_dispatch (pe_event *ev) |
|
|
1080 | { |
|
|
1081 | iw *w = (iw *)ev->ext_data; |
|
|
1082 | w->call (*w); |
|
|
1083 | } |
|
|
1084 | |
|
|
1085 | void |
|
|
1086 | iw::alloc () |
|
|
1087 | { |
|
|
1088 | pe = GEventAPI->new_idle (0, 0); |
|
|
1089 | |
|
|
1090 | pe->base.callback = (void *)iw_dispatch; |
|
|
1091 | pe->base.ext_data = (void *)this; |
|
|
1092 | } |
|
|
1093 | |
|
|
1094 | static void iow_dispatch (pe_event *ev) |
|
|
1095 | { |
|
|
1096 | iow *w = (iow *)ev->ext_data; |
|
|
1097 | w->call (*w, ((pe_ioevent *)ev)->got); |
|
|
1098 | } |
|
|
1099 | |
|
|
1100 | void |
|
|
1101 | iow::alloc () |
|
|
1102 | { |
|
|
1103 | pe = GEventAPI->new_io (0, 0); |
|
|
1104 | |
|
|
1105 | pe->base.callback = (void *)iow_dispatch; |
|
|
1106 | pe->base.ext_data = (void *)this; |
|
|
1107 | |
|
|
1108 | pe->fd = -1; |
|
|
1109 | pe->poll = 0; |
|
|
1110 | } |
|
|
1111 | |
|
|
1112 | void |
|
|
1113 | iow::fd (int fd) |
|
|
1114 | { |
|
|
1115 | pe->fd = fd; |
|
|
1116 | } |
|
|
1117 | |
|
|
1118 | int |
|
|
1119 | iow::poll () |
|
|
1120 | { |
|
|
1121 | return pe->poll; |
|
|
1122 | } |
|
|
1123 | |
|
|
1124 | void |
|
|
1125 | iow::poll (int events) |
|
|
1126 | { |
|
|
1127 | if (pe->poll != events) |
|
|
1128 | { |
|
|
1129 | if (pe->poll) stop (); |
|
|
1130 | pe->poll = events; |
|
|
1131 | if (pe->poll) start (); |
|
|
1132 | } |
|
|
1133 | } |
|
|
1134 | |
880 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1135 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
881 | |
1136 | |
882 | BOOT: |
1137 | BOOT: |
883 | { |
1138 | { |
884 | HV *stash = gv_stashpv ("cf", 1); |
1139 | HV *stash = gv_stashpv ("cf", 1); |
|
|
1140 | |
|
|
1141 | I_EVENT_API (PACKAGE); |
|
|
1142 | watcher_base::GEventAPI = GEventAPI; |
|
|
1143 | |
|
|
1144 | newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
885 | |
1145 | |
886 | static const struct { |
1146 | static const struct { |
887 | const char *name; |
1147 | const char *name; |
888 | IV iv; |
1148 | IV iv; |
889 | } *civ, const_iv[] = { |
1149 | } *civ, const_iv[] = { |
… | |
… | |
901 | const_iv (POTION) |
1161 | const_iv (POTION) |
902 | const_iv (FOOD) |
1162 | const_iv (FOOD) |
903 | const_iv (POISON) |
1163 | const_iv (POISON) |
904 | const_iv (BOOK) |
1164 | const_iv (BOOK) |
905 | const_iv (CLOCK) |
1165 | const_iv (CLOCK) |
906 | const_iv (LIGHTNING) |
|
|
907 | const_iv (ARROW) |
1166 | const_iv (ARROW) |
908 | const_iv (BOW) |
1167 | const_iv (BOW) |
909 | const_iv (WEAPON) |
1168 | const_iv (WEAPON) |
910 | const_iv (ARMOUR) |
1169 | const_iv (ARMOUR) |
911 | const_iv (PEDESTAL) |
1170 | const_iv (PEDESTAL) |
… | |
… | |
931 | const_iv (AMULET) |
1190 | const_iv (AMULET) |
932 | const_iv (PLAYERMOVER) |
1191 | const_iv (PLAYERMOVER) |
933 | const_iv (TELEPORTER) |
1192 | const_iv (TELEPORTER) |
934 | const_iv (CREATOR) |
1193 | const_iv (CREATOR) |
935 | const_iv (SKILL) |
1194 | const_iv (SKILL) |
936 | const_iv (EXPERIENCE) |
|
|
937 | const_iv (EARTHWALL) |
1195 | const_iv (EARTHWALL) |
938 | const_iv (GOLEM) |
1196 | const_iv (GOLEM) |
939 | const_iv (THROWN_OBJ) |
1197 | const_iv (THROWN_OBJ) |
940 | const_iv (BLINDNESS) |
1198 | const_iv (BLINDNESS) |
941 | const_iv (GOD) |
1199 | const_iv (GOD) |
… | |
… | |
961 | const_iv (FLOOR) |
1219 | const_iv (FLOOR) |
962 | const_iv (FLESH) |
1220 | const_iv (FLESH) |
963 | const_iv (INORGANIC) |
1221 | const_iv (INORGANIC) |
964 | const_iv (SKILL_TOOL) |
1222 | const_iv (SKILL_TOOL) |
965 | const_iv (LIGHTER) |
1223 | const_iv (LIGHTER) |
966 | const_iv (TRAP_PART) |
|
|
967 | const_iv (WALL) |
1224 | const_iv (BUILDABLE_WALL) |
968 | const_iv (LIGHT_SOURCE) |
|
|
969 | const_iv (MISC_OBJECT) |
1225 | const_iv (MISC_OBJECT) |
970 | const_iv (MONSTER) |
|
|
971 | const_iv (SPAWN_GENERATOR) |
|
|
972 | const_iv (LAMP) |
1226 | const_iv (LAMP) |
973 | const_iv (DUPLICATOR) |
1227 | const_iv (DUPLICATOR) |
974 | const_iv (TOOL) |
|
|
975 | const_iv (SPELLBOOK) |
1228 | const_iv (SPELLBOOK) |
976 | const_iv (BUILDFAC) |
|
|
977 | const_iv (CLOAK) |
1229 | const_iv (CLOAK) |
978 | const_iv (SPINNER) |
1230 | const_iv (SPINNER) |
979 | const_iv (GATE) |
1231 | const_iv (GATE) |
980 | const_iv (BUTTON) |
1232 | const_iv (BUTTON) |
981 | const_iv (CF_HANDLE) |
1233 | const_iv (CF_HANDLE) |
… | |
… | |
988 | const_iv (SPELL_EFFECT) |
1240 | const_iv (SPELL_EFFECT) |
989 | const_iv (CONVERTER) |
1241 | const_iv (CONVERTER) |
990 | const_iv (BRACERS) |
1242 | const_iv (BRACERS) |
991 | const_iv (POISONING) |
1243 | const_iv (POISONING) |
992 | const_iv (SAVEBED) |
1244 | const_iv (SAVEBED) |
993 | const_iv (POISONCLOUD) |
|
|
994 | const_iv (FIREHOLES) |
|
|
995 | const_iv (WAND) |
1245 | const_iv (WAND) |
996 | const_iv (SCROLL) |
1246 | const_iv (SCROLL) |
997 | const_iv (DIRECTOR) |
1247 | const_iv (DIRECTOR) |
998 | const_iv (GIRDLE) |
1248 | const_iv (GIRDLE) |
999 | const_iv (FORCE) |
1249 | const_iv (FORCE) |
… | |
… | |
1014 | const_iv (DISEASE) |
1264 | const_iv (DISEASE) |
1015 | const_iv (SYMPTOM) |
1265 | const_iv (SYMPTOM) |
1016 | const_iv (BUILDER) |
1266 | const_iv (BUILDER) |
1017 | const_iv (MATERIAL) |
1267 | const_iv (MATERIAL) |
1018 | const_iv (ITEM_TRANSFORMER) |
1268 | const_iv (ITEM_TRANSFORMER) |
1019 | const_iv (QUEST) |
|
|
1020 | |
1269 | |
1021 | const_iv (NUM_SUBTYPES) |
1270 | const_iv (NUM_SUBTYPES) |
1022 | |
1271 | |
1023 | const_iv (ST_BD_BUILD) |
1272 | const_iv (ST_BD_BUILD) |
1024 | const_iv (ST_BD_REMOVE) |
1273 | const_iv (ST_BD_REMOVE) |
… | |
… | |
1052 | const_iv (AT_BLIND) |
1301 | const_iv (AT_BLIND) |
1053 | const_iv (AT_INTERNAL) |
1302 | const_iv (AT_INTERNAL) |
1054 | const_iv (AT_LIFE_STEALING) |
1303 | const_iv (AT_LIFE_STEALING) |
1055 | const_iv (AT_DISEASE) |
1304 | const_iv (AT_DISEASE) |
1056 | |
1305 | |
1057 | const_iv (QUEST_IN_PROGRESS) |
|
|
1058 | const_iv (QUEST_DONE_QUEST) |
|
|
1059 | const_iv (QUEST_DONE_TASK) |
|
|
1060 | const_iv (QUEST_START_QUEST) |
|
|
1061 | const_iv (QUEST_END_QUEST) |
|
|
1062 | const_iv (QUEST_START_TASK) |
|
|
1063 | const_iv (QUEST_END_TASK) |
|
|
1064 | const_iv (QUEST_OVERRIDE) |
|
|
1065 | const_iv (QUEST_ON_ACTIVATE) |
|
|
1066 | |
|
|
1067 | const_iv (WEAP_HIT) |
1306 | const_iv (WEAP_HIT) |
1068 | const_iv (WEAP_SLASH) |
1307 | const_iv (WEAP_SLASH) |
1069 | const_iv (WEAP_PIERCE) |
1308 | const_iv (WEAP_PIERCE) |
1070 | const_iv (WEAP_CLEAVE) |
1309 | const_iv (WEAP_CLEAVE) |
1071 | const_iv (WEAP_SLICE) |
1310 | const_iv (WEAP_SLICE) |
… | |
… | |
1087 | const_iv (FLAG_MONSTER) |
1326 | const_iv (FLAG_MONSTER) |
1088 | const_iv (FLAG_FRIENDLY) |
1327 | const_iv (FLAG_FRIENDLY) |
1089 | const_iv (FLAG_GENERATOR) |
1328 | const_iv (FLAG_GENERATOR) |
1090 | const_iv (FLAG_IS_THROWN) |
1329 | const_iv (FLAG_IS_THROWN) |
1091 | const_iv (FLAG_AUTO_APPLY) |
1330 | const_iv (FLAG_AUTO_APPLY) |
1092 | const_iv (FLAG_TREASURE) |
|
|
1093 | const_iv (FLAG_PLAYER_SOLD) |
1331 | const_iv (FLAG_PLAYER_SOLD) |
1094 | const_iv (FLAG_SEE_INVISIBLE) |
1332 | const_iv (FLAG_SEE_INVISIBLE) |
1095 | const_iv (FLAG_CAN_ROLL) |
1333 | const_iv (FLAG_CAN_ROLL) |
1096 | const_iv (FLAG_OVERLAY_FLOOR) |
1334 | const_iv (FLAG_OVERLAY_FLOOR) |
1097 | const_iv (FLAG_IS_TURNABLE) |
1335 | const_iv (FLAG_IS_TURNABLE) |
… | |
… | |
1192 | const_iv (NDI_MAX_COLOR) |
1430 | const_iv (NDI_MAX_COLOR) |
1193 | const_iv (NDI_COLOR_MASK) |
1431 | const_iv (NDI_COLOR_MASK) |
1194 | const_iv (NDI_UNIQUE) |
1432 | const_iv (NDI_UNIQUE) |
1195 | const_iv (NDI_ALL) |
1433 | const_iv (NDI_ALL) |
1196 | |
1434 | |
|
|
1435 | const_iv (UPD_LOCATION) |
|
|
1436 | const_iv (UPD_FLAGS) |
|
|
1437 | const_iv (UPD_WEIGHT) |
|
|
1438 | const_iv (UPD_FACE) |
|
|
1439 | const_iv (UPD_NAME) |
|
|
1440 | const_iv (UPD_ANIM) |
|
|
1441 | const_iv (UPD_ANIMSPEED) |
|
|
1442 | const_iv (UPD_NROF) |
|
|
1443 | |
|
|
1444 | const_iv (UPD_SP_MANA) |
|
|
1445 | const_iv (UPD_SP_GRACE) |
|
|
1446 | const_iv (UPD_SP_DAMAGE) |
|
|
1447 | |
1197 | const_iv (F_APPLIED) |
1448 | const_iv (F_APPLIED) |
1198 | const_iv (F_LOCATION) |
1449 | const_iv (F_LOCATION) |
1199 | const_iv (F_UNPAID) |
1450 | const_iv (F_UNPAID) |
1200 | const_iv (F_MAGIC) |
1451 | const_iv (F_MAGIC) |
1201 | const_iv (F_CURSED) |
1452 | const_iv (F_CURSED) |
… | |
… | |
1207 | const_iv (F_BUY) |
1458 | const_iv (F_BUY) |
1208 | const_iv (F_SHOP) |
1459 | const_iv (F_SHOP) |
1209 | const_iv (F_SELL) |
1460 | const_iv (F_SELL) |
1210 | |
1461 | |
1211 | const_iv (P_BLOCKSVIEW) |
1462 | const_iv (P_BLOCKSVIEW) |
|
|
1463 | const_iv (P_PLAYER) |
1212 | const_iv (P_NO_MAGIC) |
1464 | const_iv (P_NO_MAGIC) |
1213 | const_iv (P_IS_ALIVE) |
1465 | const_iv (P_IS_ALIVE) |
1214 | const_iv (P_NO_CLERIC) |
1466 | const_iv (P_NO_CLERIC) |
1215 | const_iv (P_NEED_UPDATE) |
1467 | const_iv (P_NEED_UPDATE) |
1216 | const_iv (P_NO_ERROR) |
|
|
1217 | const_iv (P_OUT_OF_MAP) |
1468 | const_iv (P_OUT_OF_MAP) |
1218 | const_iv (P_NEW_MAP) |
1469 | const_iv (P_NEW_MAP) |
1219 | |
1470 | |
1220 | const_iv (UP_OBJ_INSERT) |
1471 | const_iv (UP_OBJ_INSERT) |
1221 | const_iv (UP_OBJ_REMOVE) |
1472 | const_iv (UP_OBJ_REMOVE) |
… | |
… | |
1255 | |
1506 | |
1256 | const_iv (SK_EXP_ADD_SKILL) |
1507 | const_iv (SK_EXP_ADD_SKILL) |
1257 | const_iv (SK_EXP_TOTAL) |
1508 | const_iv (SK_EXP_TOTAL) |
1258 | const_iv (SK_EXP_NONE) |
1509 | const_iv (SK_EXP_NONE) |
1259 | const_iv (SK_SUBTRACT_SKILL_EXP) |
1510 | const_iv (SK_SUBTRACT_SKILL_EXP) |
|
|
1511 | const_iv (SK_EXP_SKILL_ONLY) |
1260 | |
1512 | |
1261 | const_iv (SK_LOCKPICKING) |
1513 | const_iv (SK_LOCKPICKING) |
1262 | const_iv (SK_HIDING) |
1514 | const_iv (SK_HIDING) |
1263 | const_iv (SK_SMITHERY) |
1515 | const_iv (SK_SMITHERY) |
1264 | const_iv (SK_BOWYER) |
1516 | const_iv (SK_BOWYER) |
… | |
… | |
1366 | const_iv (MAP_LOADING) |
1618 | const_iv (MAP_LOADING) |
1367 | const_iv (MAP_SAVING) |
1619 | const_iv (MAP_SAVING) |
1368 | |
1620 | |
1369 | const_iv (KLASS_GLOBAL) |
1621 | const_iv (KLASS_GLOBAL) |
1370 | const_iv (KLASS_OBJECT) |
1622 | const_iv (KLASS_OBJECT) |
|
|
1623 | const_iv (KLASS_CLIENT) |
1371 | const_iv (KLASS_PLAYER) |
1624 | const_iv (KLASS_PLAYER) |
1372 | const_iv (KLASS_MAP) |
1625 | const_iv (KLASS_MAP) |
|
|
1626 | |
|
|
1627 | const_iv (CS_QUERY_YESNO) |
|
|
1628 | const_iv (CS_QUERY_SINGLECHAR) |
|
|
1629 | const_iv (CS_QUERY_HIDEINPUT) |
|
|
1630 | |
|
|
1631 | const_iv (ST_DEAD) |
|
|
1632 | const_iv (ST_SETUP) |
|
|
1633 | const_iv (ST_PLAYING) |
|
|
1634 | const_iv (ST_CUSTOM) |
|
|
1635 | |
|
|
1636 | const_iv (ST_CHANGE_CLASS) |
|
|
1637 | const_iv (ST_CONFIRM_QUIT) |
|
|
1638 | const_iv (ST_GET_PARTY_PASSWORD) |
1373 | }; |
1639 | }; |
1374 | |
1640 | |
1375 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1641 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1376 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1642 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1377 | |
1643 | |
… | |
… | |
1394 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1660 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1395 | av_push (event, newSViv (eiv->klass)); |
1661 | av_push (event, newSViv (eiv->klass)); |
1396 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1662 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1397 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1663 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1398 | } |
1664 | } |
1399 | |
|
|
1400 | static const struct { |
|
|
1401 | int dtype; |
|
|
1402 | const char *name; |
|
|
1403 | IV idx; |
|
|
1404 | } *cprop, prop_table[] = { |
|
|
1405 | # define prop(type, name) { type, # name, (IV) CFAPI_ ## name }, |
|
|
1406 | prop (CFAPI_INT, MAP_PROP_FLAGS) |
|
|
1407 | prop (CFAPI_INT, MAP_PROP_DIFFICULTY) |
|
|
1408 | prop (CFAPI_STRING, MAP_PROP_PATH) |
|
|
1409 | prop (CFAPI_STRING, MAP_PROP_TMPNAME) |
|
|
1410 | prop (CFAPI_STRING, MAP_PROP_NAME) |
|
|
1411 | prop (CFAPI_INT, MAP_PROP_RESET_TIME) |
|
|
1412 | prop (CFAPI_INT, MAP_PROP_RESET_TIMEOUT) |
|
|
1413 | prop (CFAPI_INT, MAP_PROP_PLAYERS) |
|
|
1414 | prop (CFAPI_INT, MAP_PROP_DARKNESS) |
|
|
1415 | prop (CFAPI_INT, MAP_PROP_WIDTH) |
|
|
1416 | prop (CFAPI_INT, MAP_PROP_HEIGHT) |
|
|
1417 | prop (CFAPI_INT, MAP_PROP_ENTER_X) |
|
|
1418 | prop (CFAPI_INT, MAP_PROP_ENTER_Y) |
|
|
1419 | prop (CFAPI_INT, MAP_PROP_TEMPERATURE) |
|
|
1420 | prop (CFAPI_INT, MAP_PROP_PRESSURE) |
|
|
1421 | prop (CFAPI_INT, MAP_PROP_HUMIDITY) |
|
|
1422 | prop (CFAPI_INT, MAP_PROP_WINDSPEED) |
|
|
1423 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
|
|
1424 | prop (CFAPI_INT, MAP_PROP_SKY) |
|
|
1425 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
|
|
1426 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
|
|
1427 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
|
|
1428 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
|
|
1429 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
|
|
1430 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
|
|
1431 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
|
|
1432 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
|
|
1433 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
|
|
1434 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
|
|
1435 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
|
|
1436 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
|
|
1437 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
|
|
1438 | prop (CFAPI_STRING, OBJECT_PROP_NAME_PLURAL) |
|
|
1439 | prop (CFAPI_STRING, OBJECT_PROP_TITLE) |
|
|
1440 | prop (CFAPI_STRING, OBJECT_PROP_RACE) |
|
|
1441 | prop (CFAPI_STRING, OBJECT_PROP_SLAYING) |
|
|
1442 | prop (CFAPI_STRING, OBJECT_PROP_SKILL) |
|
|
1443 | prop (CFAPI_STRING, OBJECT_PROP_MESSAGE) |
|
|
1444 | prop (CFAPI_STRING, OBJECT_PROP_LORE) |
|
|
1445 | prop (CFAPI_INT, OBJECT_PROP_X) |
|
|
1446 | prop (CFAPI_INT, OBJECT_PROP_Y) |
|
|
1447 | prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED) |
|
|
1448 | prop (CFAPI_DOUBLE, OBJECT_PROP_SPEED_LEFT) |
|
|
1449 | prop (CFAPI_INT, OBJECT_PROP_NROF) |
|
|
1450 | prop (CFAPI_INT, OBJECT_PROP_DIRECTION) |
|
|
1451 | prop (CFAPI_INT, OBJECT_PROP_FACING) |
|
|
1452 | prop (CFAPI_INT, OBJECT_PROP_TYPE) |
|
|
1453 | prop (CFAPI_INT, OBJECT_PROP_SUBTYPE) |
|
|
1454 | prop (CFAPI_INT, OBJECT_PROP_CLIENT_TYPE) |
|
|
1455 | prop (CFAPI_INT, OBJECT_PROP_ATTACK_TYPE) |
|
|
1456 | prop (CFAPI_INT, OBJECT_PROP_PATH_ATTUNED) |
|
|
1457 | prop (CFAPI_INT, OBJECT_PROP_PATH_REPELLED) |
|
|
1458 | prop (CFAPI_INT, OBJECT_PROP_PATH_DENIED) |
|
|
1459 | prop (CFAPI_INT, OBJECT_PROP_MATERIAL) |
|
|
1460 | prop (CFAPI_STRING, OBJECT_PROP_MATERIAL_NAME) |
|
|
1461 | prop (CFAPI_INT, OBJECT_PROP_MAGIC) |
|
|
1462 | prop (CFAPI_INT, OBJECT_PROP_VALUE) |
|
|
1463 | prop (CFAPI_INT, OBJECT_PROP_LEVEL) |
|
|
1464 | prop (CFAPI_INT, OBJECT_PROP_LAST_HEAL) |
|
|
1465 | prop (CFAPI_INT, OBJECT_PROP_LAST_SP) |
|
|
1466 | prop (CFAPI_INT, OBJECT_PROP_LAST_GRACE) |
|
|
1467 | prop (CFAPI_INT, OBJECT_PROP_LAST_EAT) |
|
|
1468 | prop (CFAPI_INT, OBJECT_PROP_INVISIBLE_TIME) |
|
|
1469 | prop (CFAPI_INT, OBJECT_PROP_PICK_UP) |
|
|
1470 | prop (CFAPI_INT, OBJECT_PROP_ITEM_POWER) |
|
|
1471 | prop (CFAPI_INT, OBJECT_PROP_GEN_SP_ARMOUR) |
|
|
1472 | prop (CFAPI_INT, OBJECT_PROP_WEIGHT) |
|
|
1473 | prop (CFAPI_INT, OBJECT_PROP_WEIGHT_LIMIT) |
|
|
1474 | prop (CFAPI_INT, OBJECT_PROP_CARRYING) |
|
|
1475 | prop (CFAPI_INT, OBJECT_PROP_GLOW_RADIUS) |
|
|
1476 | prop (CFAPI_LONG, OBJECT_PROP_PERM_EXP) |
|
|
1477 | prop (CFAPI_POBJECT, OBJECT_PROP_CURRENT_WEAPON) |
|
|
1478 | prop (CFAPI_POBJECT, OBJECT_PROP_ENEMY) |
|
|
1479 | prop (CFAPI_POBJECT, OBJECT_PROP_ATTACKED_BY) |
|
|
1480 | prop (CFAPI_INT, OBJECT_PROP_RUN_AWAY) |
|
|
1481 | prop (CFAPI_POBJECT, OBJECT_PROP_CHOSEN_SKILL) |
|
|
1482 | prop (CFAPI_INT, OBJECT_PROP_HIDDEN) |
|
|
1483 | prop (CFAPI_INT, OBJECT_PROP_MOVE_STATUS) |
|
|
1484 | prop (CFAPI_INT, OBJECT_PROP_MOVE_TYPE) |
|
|
1485 | prop (CFAPI_POBJECT, OBJECT_PROP_SPELL_ITEM) |
|
|
1486 | prop (CFAPI_DOUBLE, OBJECT_PROP_EXP_MULTIPLIER) |
|
|
1487 | prop (CFAPI_PARCH, OBJECT_PROP_ARCHETYPE) |
|
|
1488 | prop (CFAPI_PARCH, OBJECT_PROP_OTHER_ARCH) |
|
|
1489 | prop (CFAPI_STRING, OBJECT_PROP_CUSTOM_NAME) |
|
|
1490 | prop (CFAPI_INT, OBJECT_PROP_ANIM_SPEED) |
|
|
1491 | prop (CFAPI_INT, OBJECT_PROP_FRIENDLY) |
|
|
1492 | prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) |
|
|
1493 | prop (CFAPI_INT, OBJECT_PROP_MAGICAL) |
|
|
1494 | prop (CFAPI_INT, OBJECT_PROP_LUCK) |
|
|
1495 | prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) |
|
|
1496 | prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) |
|
|
1497 | prop (CFAPI_INT, OBJECT_PROP_CHEATER) |
|
|
1498 | prop (CFAPI_INT, OBJECT_PROP_MERGEABLE) |
|
|
1499 | prop (CFAPI_INT, OBJECT_PROP_PICKABLE) |
|
|
1500 | prop (CFAPI_INT, OBJECT_PROP_STR) |
|
|
1501 | prop (CFAPI_INT, OBJECT_PROP_DEX) |
|
|
1502 | prop (CFAPI_INT, OBJECT_PROP_CON) |
|
|
1503 | prop (CFAPI_INT, OBJECT_PROP_WIS) |
|
|
1504 | prop (CFAPI_INT, OBJECT_PROP_INT) |
|
|
1505 | prop (CFAPI_INT, OBJECT_PROP_POW) |
|
|
1506 | prop (CFAPI_INT, OBJECT_PROP_CHA) |
|
|
1507 | prop (CFAPI_INT, OBJECT_PROP_WC) |
|
|
1508 | prop (CFAPI_INT, OBJECT_PROP_AC) |
|
|
1509 | prop (CFAPI_INT, OBJECT_PROP_HP) |
|
|
1510 | prop (CFAPI_INT, OBJECT_PROP_SP) |
|
|
1511 | prop (CFAPI_INT, OBJECT_PROP_GP) |
|
|
1512 | prop (CFAPI_INT, OBJECT_PROP_FP) |
|
|
1513 | prop (CFAPI_INT, OBJECT_PROP_MAXHP) |
|
|
1514 | prop (CFAPI_INT, OBJECT_PROP_MAXSP) |
|
|
1515 | prop (CFAPI_INT, OBJECT_PROP_MAXGP) |
|
|
1516 | prop (CFAPI_INT, OBJECT_PROP_DAM) |
|
|
1517 | prop (CFAPI_STRING, OBJECT_PROP_GOD) |
|
|
1518 | prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME) |
|
|
1519 | prop (CFAPI_INT, OBJECT_PROP_INVISIBLE) |
|
|
1520 | prop (CFAPI_INT, OBJECT_PROP_FACE) |
|
|
1521 | }; |
|
|
1522 | |
|
|
1523 | HV *prop_type = get_hv ("cf::PROP_TYPE", 1); |
|
|
1524 | HV *prop_idx = get_hv ("cf::PROP_IDX", 1); |
|
|
1525 | |
|
|
1526 | for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) |
|
|
1527 | { |
|
|
1528 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
|
|
1529 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
|
|
1530 | } |
|
|
1531 | |
|
|
1532 | //I_EVENT_API (PACKAGE); |
|
|
1533 | } |
1665 | } |
1534 | |
1666 | |
1535 | void _reload_1 () |
1667 | void _init_vars () |
1536 | CODE: |
1668 | CODE: |
1537 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1669 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1538 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1670 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1539 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1671 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1672 | cb_client = get_av ("cf::CB_CLIENT", 1); |
1540 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1673 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1541 | cb_map = get_av ("cf::CB_MAP" , 1); |
1674 | cb_map = get_av ("cf::CB_MAP" , 1); |
1542 | |
1675 | |
1543 | void _reload_2 () |
1676 | void _global_reattach () |
1544 | CODE: |
1677 | CODE: |
1545 | { |
1678 | { |
1546 | // reattach to all attachable objects in the game. |
1679 | // reattach to all attachable objects in the game. |
|
|
1680 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
|
|
1681 | reattach (*i); |
|
|
1682 | |
1547 | for (player *pl = first_player; pl; pl = pl->next) |
1683 | for (player *pl = first_player; pl; pl = pl->next) |
1548 | reattach (pl); |
1684 | reattach (pl); |
1549 | |
1685 | |
1550 | for (mapstruct *map = first_map; map; map = map->next) |
1686 | for (maptile *map = first_map; map; map = map->next) |
1551 | reattach (map); |
1687 | reattach (map); |
1552 | |
1688 | |
1553 | for (object *op = objects; op; op = op->next) |
1689 | for (object *op = object::first; op; op = op->next) |
1554 | reattach (op); |
1690 | reattach (op); |
1555 | } |
1691 | } |
1556 | |
1692 | |
1557 | NV floor (NV x) |
1693 | NV floor (NV x) |
1558 | |
1694 | |
… | |
… | |
1606 | case 5: RETVAL = settings.playerdir; break; |
1742 | case 5: RETVAL = settings.playerdir; break; |
1607 | case 6: RETVAL = settings.datadir ; break; |
1743 | case 6: RETVAL = settings.datadir ; break; |
1608 | } |
1744 | } |
1609 | OUTPUT: RETVAL |
1745 | OUTPUT: RETVAL |
1610 | |
1746 | |
1611 | int |
1747 | void _exit (int status = 0) |
|
|
1748 | |
1612 | cf_find_animation (char *text) |
1749 | int find_animation (char *text) |
1613 | PROTOTYPE: $ |
1750 | PROTOTYPE: $ |
1614 | |
1751 | |
1615 | int random_roll(int min, int max, object *op, int goodbad); |
1752 | int random_roll (int min, int max, object *op, int goodbad); |
1616 | |
1753 | |
1617 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1754 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1618 | |
|
|
1619 | int invoke (int event, ...) |
|
|
1620 | CODE: |
|
|
1621 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
|
|
1622 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1623 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
1624 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
|
|
1625 | OUTPUT: RETVAL |
|
|
1626 | |
1755 | |
1627 | int |
1756 | int |
1628 | exp_to_level (val64 exp) |
1757 | exp_to_level (val64 exp) |
1629 | CODE: |
1758 | CODE: |
1630 | { |
1759 | { |
… | |
… | |
1661 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1790 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1662 | else |
1791 | else |
1663 | XSRETURN_UNDEF; |
1792 | XSRETURN_UNDEF; |
1664 | OUTPUT: RETVAL |
1793 | OUTPUT: RETVAL |
1665 | |
1794 | |
|
|
1795 | MODULE = cf PACKAGE = cf::attachable |
|
|
1796 | |
1666 | int |
1797 | int |
1667 | _valid (SV *obj) |
1798 | valid (SV *obj) |
1668 | CODE: |
1799 | CODE: |
1669 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1800 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1670 | OUTPUT: |
1801 | OUTPUT: |
1671 | RETVAL |
1802 | RETVAL |
1672 | |
1803 | |
|
|
1804 | MODULE = cf PACKAGE = cf::global |
|
|
1805 | |
|
|
1806 | int invoke (SV *klass, int event, ...) |
|
|
1807 | CODE: |
|
|
1808 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
|
|
1809 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1810 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
1811 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
|
|
1812 | OUTPUT: RETVAL |
|
|
1813 | |
1673 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1814 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
|
|
1815 | |
|
|
1816 | INCLUDE: $PERL genacc object ../include/object.h | |
1674 | |
1817 | |
1675 | int invoke (object *op, int event, ...) |
1818 | int invoke (object *op, int event, ...) |
1676 | CODE: |
1819 | CODE: |
1677 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1820 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1678 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1821 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1679 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1822 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1680 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
1823 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
1681 | OUTPUT: RETVAL |
1824 | OUTPUT: RETVAL |
1682 | |
1825 | |
1683 | SV *registry (object *op) |
1826 | SV *registry (object *op) |
|
|
1827 | |
|
|
1828 | void mortals () |
1684 | CODE: |
1829 | PPCODE: |
1685 | RETVAL = registry_of (op); |
1830 | EXTEND (SP, object::mortals.size ()); |
|
|
1831 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
|
|
1832 | PUSHs (to_sv (*i)); |
|
|
1833 | |
|
|
1834 | object *first () |
|
|
1835 | CODE: |
|
|
1836 | RETVAL = object::first; |
|
|
1837 | OUTPUT: RETVAL |
|
|
1838 | |
|
|
1839 | # missing properties |
|
|
1840 | |
|
|
1841 | int flag (object *op, int flag, int value = 1) |
|
|
1842 | PROTOTYPE: $$;$ |
|
|
1843 | CODE: |
|
|
1844 | RETVAL = QUERY_FLAG (op, flag); |
|
|
1845 | if (items >= 3) |
|
|
1846 | if (value) |
|
|
1847 | SET_FLAG (op, flag); |
|
|
1848 | else |
|
|
1849 | CLEAR_FLAG (op, flag); |
1686 | OUTPUT: |
1850 | OUTPUT: RETVAL |
1687 | RETVAL |
|
|
1688 | |
1851 | |
1689 | object *head (object *op) |
1852 | object *head (object *op) |
1690 | PROTOTYPE: $ |
1853 | PROTOTYPE: $ |
1691 | ALIAS: |
|
|
1692 | more = 1 |
|
|
1693 | above = 2 |
|
|
1694 | below = 3 |
|
|
1695 | CODE: |
1854 | CODE: |
1696 | switch (ix) |
|
|
1697 | { |
|
|
1698 | case 0: RETVAL = op->head ? op->head : op; break; // DOH! |
1855 | RETVAL = op->head ? op->head : op; |
1699 | case 1: RETVAL = op->more; break; |
|
|
1700 | case 2: RETVAL = op->above; break; |
|
|
1701 | case 3: RETVAL = op->below; break; |
|
|
1702 | } |
|
|
1703 | OUTPUT: |
|
|
1704 | RETVAL |
1856 | OUTPUT: RETVAL |
1705 | |
1857 | |
1706 | SV * |
1858 | int is_head (object *op) |
1707 | get_property (object *obj, int type, int idx) |
1859 | PROTOTYPE: $ |
1708 | CODE: |
1860 | CODE: |
1709 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
|
|
1710 | OUTPUT: RETVAL |
|
|
1711 | |
|
|
1712 | SV * |
|
|
1713 | set_property (object *obj, int type, int idx, SV *newval) |
|
|
1714 | CODE: |
|
|
1715 | switch (type) |
|
|
1716 | { |
|
|
1717 | case CFAPI_INT: |
|
|
1718 | cf_object_set_int_property (obj, idx, SvIV (newval)); |
|
|
1719 | break; |
|
|
1720 | case CFAPI_LONG: |
|
|
1721 | cf_object_set_long_property (obj, idx, (long) SvVAL64 (newval)); |
|
|
1722 | break; |
|
|
1723 | case CFAPI_DOUBLE: |
|
|
1724 | { |
|
|
1725 | int unused_type; |
|
|
1726 | object_set_property (&unused_type, obj, idx, (double)SvNV (newval)); |
|
|
1727 | } |
|
|
1728 | break; |
|
|
1729 | case CFAPI_STRING: |
|
|
1730 | cf_object_set_string_property (obj, idx, SvOK (newval) ? SvPV_nolen (newval) : 0); |
|
|
1731 | break; |
|
|
1732 | case CFAPI_POBJECT: |
|
|
1733 | { |
|
|
1734 | int unused_type; |
|
|
1735 | object_set_property (&unused_type, obj, idx, (object *)SvPTR_ornull (newval, "cf::object")); |
|
|
1736 | } |
|
|
1737 | break; |
|
|
1738 | default: |
|
|
1739 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
|
|
1740 | } |
|
|
1741 | |
|
|
1742 | # missing properties |
|
|
1743 | |
|
|
1744 | void |
|
|
1745 | set_attacktype (object *obj, U32 attacktype) |
|
|
1746 | CODE: |
|
|
1747 | obj->attacktype = attacktype; |
|
|
1748 | |
|
|
1749 | U32 |
|
|
1750 | get_attacktype (object *obj) |
|
|
1751 | ALIAS: |
|
|
1752 | attacktype = 0 |
|
|
1753 | CODE: |
|
|
1754 | RETVAL = obj->attacktype; |
|
|
1755 | OUTPUT: RETVAL |
|
|
1756 | |
|
|
1757 | # missing in plug-in api, of course |
|
|
1758 | void |
|
|
1759 | set_food (object *obj, int food) |
|
|
1760 | CODE: |
|
|
1761 | obj->stats.food = food; |
|
|
1762 | |
|
|
1763 | int |
|
|
1764 | get_food (object *obj) |
|
|
1765 | ALIAS: |
|
|
1766 | food = 0 |
|
|
1767 | CODE: |
|
|
1768 | RETVAL = obj->stats.food; |
1861 | RETVAL = !op->head; |
1769 | OUTPUT: RETVAL |
1862 | OUTPUT: RETVAL |
1770 | |
1863 | |
1771 | void |
1864 | void |
1772 | inv (object *obj) |
1865 | inv (object *obj) |
1773 | PROTOTYPE: $ |
1866 | PROTOTYPE: $ |
1774 | PPCODE: |
1867 | PPCODE: |
1775 | { |
1868 | { |
1776 | object *o; |
1869 | object *o; |
1777 | for (o = obj->inv; o; o = o->below) |
1870 | for (o = obj->inv; o; o = o->below) |
1778 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1871 | XPUSHs (sv_2mortal (to_sv (o))); |
1779 | } |
1872 | } |
1780 | |
1873 | |
1781 | int cf_object_get_resistance (object *op, int rtype) |
1874 | void |
1782 | ALIAS: resistance = 0 |
1875 | set_animation (object *op, int idx) |
|
|
1876 | CODE: |
|
|
1877 | SET_ANIMATION (op, idx); |
1783 | |
1878 | |
1784 | int cf_object_get_flag (object *op, int flag) |
1879 | void |
1785 | ALIAS: flag = 0 |
1880 | object::drain_stat () |
1786 | |
1881 | |
1787 | void cf_object_set_flag (object *op, int flag, int value) |
1882 | void |
|
|
1883 | object::drain_specific_stat (int stat) |
|
|
1884 | |
|
|
1885 | void |
|
|
1886 | object::change_luck (int change) |
|
|
1887 | |
|
|
1888 | void |
|
|
1889 | object::add_statbonus () |
|
|
1890 | |
|
|
1891 | void |
|
|
1892 | object::remove_statbonus () |
|
|
1893 | |
|
|
1894 | object *find_best_object_match (object *op, const char *match) |
|
|
1895 | |
|
|
1896 | object *find_marked_object (object *op) |
|
|
1897 | |
|
|
1898 | int resistance (object *op, int rtype, int newval = 0) |
|
|
1899 | CODE: |
|
|
1900 | if (rtype < 0 || rtype >= NROFATTACKS) |
|
|
1901 | croak ("resistance out of bounds"); |
|
|
1902 | RETVAL = op->resist [rtype]; |
|
|
1903 | if (items >= 3) |
|
|
1904 | op->resist [rtype] = newval; |
|
|
1905 | OUTPUT: RETVAL |
|
|
1906 | |
|
|
1907 | void set_resistance (object *op, int rtype, int val) |
|
|
1908 | CODE: |
|
|
1909 | if (rtype < 0 || rtype >= NROFATTACKS) |
|
|
1910 | op->resist[rtype] = val; |
1788 | |
1911 | |
1789 | int need_identify (const object *obj); |
1912 | int need_identify (const object *obj); |
1790 | |
1913 | |
1791 | int apply_shop_mat (object *shop_mat, object *op); |
1914 | int apply_shop_mat (object *shop_mat, object *op); |
1792 | |
1915 | |
… | |
… | |
1794 | CODE: |
1917 | CODE: |
1795 | RETVAL = move_ob (op, dir, originator); |
1918 | RETVAL = move_ob (op, dir, originator); |
1796 | OUTPUT: |
1919 | OUTPUT: |
1797 | RETVAL |
1920 | RETVAL |
1798 | |
1921 | |
1799 | void cf_object_apply (object *op, object *author, int flags = 0) |
1922 | void apply (object *applier, object *applied, int flags = 0) |
|
|
1923 | CODE: |
|
|
1924 | manual_apply (applied, applier, flags); |
1800 | |
1925 | |
1801 | void cf_object_apply_below (object *op) |
1926 | void apply_below (object *op) |
|
|
1927 | CODE: |
|
|
1928 | player_apply_below (op); |
1802 | |
1929 | |
1803 | void cf_object_remove (object *op) |
1930 | void remove (object *op) |
|
|
1931 | CODE: |
|
|
1932 | op->remove (); |
1804 | |
1933 | |
1805 | void cf_object_free (object *op) |
1934 | void |
|
|
1935 | object::destroy (int recursive = 0) |
1806 | |
1936 | |
1807 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1937 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1808 | |
1938 | |
1809 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1939 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1810 | |
1940 | |
1811 | int cf_object_change_map (object *op, int x, int y, mapstruct *map) |
1941 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
1812 | |
1942 | |
1813 | object *cf_object_clone (object *op, int clonetype = 0) |
1943 | object *clone (object *op, int recursive = 0) |
|
|
1944 | CODE: |
|
|
1945 | if (recursive) |
|
|
1946 | RETVAL = object_create_clone (op); |
|
|
1947 | else |
|
|
1948 | { |
|
|
1949 | RETVAL = object::create (); |
|
|
1950 | op->copy_to (RETVAL); |
|
|
1951 | } |
|
|
1952 | OUTPUT: RETVAL |
1814 | |
1953 | |
1815 | int cf_object_pay_item (object *op, object *buyer) |
1954 | int pay_item (object *op, object *buyer) |
|
|
1955 | CODE: |
|
|
1956 | RETVAL = pay_for_item (op, buyer); |
|
|
1957 | OUTPUT: RETVAL |
1816 | |
1958 | |
1817 | int cf_object_pay_amount (object *op, uint64 amount) |
1959 | int pay_amount (object *op, uint64 amount) |
|
|
1960 | CODE: |
|
|
1961 | RETVAL = pay_for_amount (amount, op); |
|
|
1962 | OUTPUT: RETVAL |
1818 | |
1963 | |
1819 | void pay_player (object *op, uint64 amount) |
1964 | void pay_player (object *op, uint64 amount) |
1820 | |
1965 | |
1821 | val64 pay_player_arch (object *op, const char *arch, uint64 amount) |
1966 | val64 pay_player_arch (object *op, const char *arch, uint64 amount) |
1822 | |
1967 | |
1823 | int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) |
1968 | int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0) |
1824 | |
1969 | |
1825 | int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) |
1970 | void learn_spell (object *op, object *sp, int special_prayer = 0) |
|
|
1971 | CODE: |
|
|
1972 | do_learn_spell (op, sp, special_prayer); |
1826 | |
1973 | |
1827 | void cf_object_learn_spell (object *op, object *sp) |
|
|
1828 | |
|
|
1829 | void cf_object_forget_spell (object *op, object *sp) |
1974 | void forget_spell (object *op, object *sp) |
|
|
1975 | CODE: |
|
|
1976 | do_forget_spell (op, query_name (sp)); |
1830 | |
1977 | |
1831 | object *cf_object_check_for_spell (object *op, char *spellname) |
1978 | object *check_for_spell (object *op, char *spellname) |
|
|
1979 | CODE: |
|
|
1980 | RETVAL = check_spell_known (op, spellname); |
|
|
1981 | OUTPUT: RETVAL |
1832 | |
1982 | |
1833 | int cf_object_query_money (object *op) |
1983 | int query_money (object *op) |
1834 | ALIAS: money = 0 |
1984 | ALIAS: money = 0 |
1835 | |
1985 | |
1836 | int cf_object_query_cost (object *op, object *who, int flags) |
1986 | int query_cost (object *op, object *who, int flags) |
1837 | ALIAS: cost = 0 |
1987 | ALIAS: cost = 0 |
1838 | |
1988 | |
1839 | void cf_object_activate_rune (object *op , object *victim) |
1989 | void spring_trap (object *op, object *victim) |
1840 | |
1990 | |
1841 | int cf_object_check_trigger (object *op, object *cause) |
1991 | int check_trigger (object *op, object *cause) |
1842 | |
1992 | |
1843 | int cf_object_out_of_map (object *op, int x, int y) |
|
|
1844 | |
|
|
1845 | void cf_object_drop (object *op, object *author) |
1993 | void drop (object *who, object *op) |
1846 | |
1994 | |
1847 | void cf_object_take (object *op, object *author) |
1995 | void pick_up (object *who, object *op) |
1848 | |
1996 | |
1849 | object *cf_object_insert_object (object *op, object *container) |
1997 | object *cf_object_insert_object (object *op, object *container) |
1850 | |
1998 | |
1851 | const char *cf_object_get_msg (object *ob) |
|
|
1852 | ALIAS: msg = 0 |
|
|
1853 | |
|
|
1854 | object *cf_object_insert_in_ob (object *ob, object *where) |
1999 | object *cf_object_insert_in_ob (object *ob, object *where) |
1855 | |
2000 | |
1856 | int cf_object_teleport (object *op, mapstruct *map, int x, int y) |
2001 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1857 | |
2002 | |
1858 | void cf_object_update (object *op, int flags) |
2003 | void update_object (object *op, int action) |
1859 | |
|
|
1860 | void cf_object_pickup (object *op, object *what) |
|
|
1861 | |
2004 | |
1862 | object *cf_create_object_by_name (const char *name) |
2005 | object *cf_create_object_by_name (const char *name) |
1863 | |
2006 | |
1864 | void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) |
2007 | void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) |
1865 | |
2008 | |
… | |
… | |
1871 | |
2014 | |
1872 | void push_button (object *op); |
2015 | void push_button (object *op); |
1873 | |
2016 | |
1874 | void use_trigger (object *op); |
2017 | void use_trigger (object *op); |
1875 | |
2018 | |
1876 | void add_button_link (object *button, mapstruct *map, int connected); |
2019 | void add_button_link (object *button, maptile *map, int connected); |
1877 | |
2020 | |
1878 | void remove_button_link (object *op); |
2021 | void remove_button_link (object *op); |
1879 | |
2022 | |
1880 | void |
|
|
1881 | cf_object_set_resistance (object *op, int rtype, int val) |
|
|
1882 | CODE: |
|
|
1883 | if (rtype >= 0 && rtype < NROFATTACKS) |
|
|
1884 | op->resist[rtype] = val; |
|
|
1885 | |
|
|
1886 | |
2023 | |
1887 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2024 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1888 | |
|
|
1889 | void cf_fix_object (object *pl) |
|
|
1890 | ALIAS: fix = 0 |
|
|
1891 | |
2025 | |
1892 | object *cf_insert_ob_in_ob (object *ob, object *where) |
2026 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1893 | |
2027 | |
1894 | # no clean way to get an object from an archetype - stupid idiotic |
2028 | # no clean way to get an object from an archetype - stupid idiotic |
1895 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2029 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
… | |
… | |
1899 | CODE: |
2033 | CODE: |
1900 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
2034 | RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); |
1901 | OUTPUT: |
2035 | OUTPUT: |
1902 | RETVAL |
2036 | RETVAL |
1903 | |
2037 | |
1904 | object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) |
2038 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
1905 | PROTOTYPE: $$$$$$ |
2039 | PROTOTYPE: $$$$$$ |
1906 | CODE: |
2040 | CODE: |
1907 | { |
2041 | { |
1908 | int unused_type; |
2042 | int unused_type; |
1909 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
2043 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
… | |
… | |
1918 | |
2052 | |
1919 | player *contr (object *op) |
2053 | player *contr (object *op) |
1920 | CODE: |
2054 | CODE: |
1921 | RETVAL = op->contr; |
2055 | RETVAL = op->contr; |
1922 | OUTPUT: RETVAL |
2056 | OUTPUT: RETVAL |
|
|
2057 | |
|
|
2058 | void |
|
|
2059 | object::roll_stats () |
|
|
2060 | |
|
|
2061 | void |
|
|
2062 | object::update_stats () |
|
|
2063 | |
|
|
2064 | void |
|
|
2065 | object::swap_stats (int a, int b) |
1923 | |
2066 | |
1924 | const char *get_ob_key_value (object *op, const char *key) |
2067 | const char *get_ob_key_value (object *op, const char *key) |
1925 | |
2068 | |
1926 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
2069 | bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) |
1927 | |
2070 | |
… | |
… | |
1947 | bool on_same_map_as (object *ob, object *other) |
2090 | bool on_same_map_as (object *ob, object *other) |
1948 | CODE: |
2091 | CODE: |
1949 | RETVAL = on_same_map (ob, other); |
2092 | RETVAL = on_same_map (ob, other); |
1950 | OUTPUT: RETVAL |
2093 | OUTPUT: RETVAL |
1951 | |
2094 | |
1952 | char * |
2095 | const char * |
1953 | base_name (object *ob, int plural) |
2096 | base_name (object *op, int plural = op->nrof > 1) |
1954 | CODE: |
2097 | CODE: |
1955 | RETVAL = cf_query_base_name (ob, plural); |
2098 | RETVAL = query_base_name (op, plural); |
1956 | OUTPUT: RETVAL |
2099 | OUTPUT: RETVAL |
1957 | |
2100 | |
1958 | living * |
2101 | object *decrease_ob_nr (object *op, unsigned long i) |
1959 | stats (object *ob) |
|
|
1960 | CODE: |
|
|
1961 | RETVAL = &ob->stats; |
|
|
1962 | OUTPUT: RETVAL |
|
|
1963 | |
|
|
1964 | |
2102 | |
1965 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
2103 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1966 | |
2104 | |
1967 | player *player (object *op) |
2105 | player *player (object *op) |
1968 | CODE: |
2106 | CODE: |
… | |
… | |
1986 | |
2124 | |
1987 | void cf_player_set_party (object *op, partylist *party) |
2125 | void cf_player_set_party (object *op, partylist *party) |
1988 | |
2126 | |
1989 | void kill_player (object *op) |
2127 | void kill_player (object *op) |
1990 | |
2128 | |
|
|
2129 | void esrv_update_item (object *op, int what, object *item) |
|
|
2130 | C_ARGS: what, op, item |
|
|
2131 | |
|
|
2132 | void clear_los (object *op) |
|
|
2133 | |
|
|
2134 | int command_reset (object *op, char *params) |
|
|
2135 | |
|
|
2136 | int command_teleport (object *op, char *params) |
|
|
2137 | |
|
|
2138 | int command_summon (object *op, char *params) |
|
|
2139 | |
|
|
2140 | int command_arrest (object *op, char *params) |
|
|
2141 | |
|
|
2142 | int command_kick (object *op, char *params) |
|
|
2143 | |
|
|
2144 | int command_banish (object *op, char *params) |
|
|
2145 | |
|
|
2146 | |
1991 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2147 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
|
|
2148 | |
|
|
2149 | INCLUDE: $PERL genacc player ../include/player.h | |
1992 | |
2150 | |
1993 | int invoke (player *pl, int event, ...) |
2151 | int invoke (player *pl, int event, ...) |
1994 | CODE: |
2152 | CODE: |
1995 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2153 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
1996 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2154 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1997 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2155 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1998 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
2156 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
1999 | OUTPUT: RETVAL |
2157 | OUTPUT: RETVAL |
2000 | |
2158 | |
2001 | SV *registry (player *pl) |
2159 | SV *registry (player *pl) |
|
|
2160 | |
|
|
2161 | player * |
|
|
2162 | create () |
2002 | CODE: |
2163 | CODE: |
|
|
2164 | RETVAL = player::create (); |
|
|
2165 | OUTPUT: |
|
|
2166 | RETVAL |
|
|
2167 | |
|
|
2168 | player * |
|
|
2169 | load (const char *path) |
|
|
2170 | CODE: |
|
|
2171 | RETVAL = player::load (path); |
|
|
2172 | OUTPUT: |
|
|
2173 | RETVAL |
|
|
2174 | |
|
|
2175 | void |
|
|
2176 | player::save (bool final = false) |
|
|
2177 | |
|
|
2178 | void |
|
|
2179 | player::connect (client *ns) |
|
|
2180 | |
|
|
2181 | void |
|
|
2182 | save_stats (player *pl) |
|
|
2183 | CODE: |
|
|
2184 | pl->ob->stats.hp = pl->ob->stats.maxhp; |
|
|
2185 | pl->ob->stats.sp = pl->ob->stats.maxsp; |
|
|
2186 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
|
|
2187 | pl->orig_stats = pl->ob->stats; |
|
|
2188 | |
|
|
2189 | player *cf_player_find (char *name) |
|
|
2190 | PROTOTYPE: $ |
|
|
2191 | |
|
|
2192 | void cf_player_move (player *pl, int dir) |
|
|
2193 | |
|
|
2194 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
|
|
2195 | |
|
|
2196 | player *first () |
|
|
2197 | CODE: |
2003 | RETVAL = registry_of (pl); |
2198 | RETVAL = first_player; |
|
|
2199 | OUTPUT: RETVAL |
|
|
2200 | |
|
|
2201 | bool |
|
|
2202 | cell_visible (player *pl, int dx, int dy) |
|
|
2203 | CODE: |
|
|
2204 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
|
|
2205 | && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; |
2004 | OUTPUT: |
2206 | OUTPUT: |
2005 | RETVAL |
2207 | RETVAL |
2006 | |
2208 | |
2007 | player *cf_player_find (char *name) |
|
|
2008 | PROTOTYPE: $ |
|
|
2009 | |
|
|
2010 | void cf_player_move (player *pl, int dir) |
|
|
2011 | |
|
|
2012 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
|
|
2013 | |
|
|
2014 | # nonstandard |
|
|
2015 | object *ob (player *pl) |
|
|
2016 | CODE: |
|
|
2017 | RETVAL = pl->ob; |
|
|
2018 | OUTPUT: RETVAL |
|
|
2019 | |
|
|
2020 | player *first () |
|
|
2021 | CODE: |
|
|
2022 | RETVAL = first_player; |
|
|
2023 | OUTPUT: RETVAL |
|
|
2024 | |
|
|
2025 | player *next (player *pl) |
|
|
2026 | CODE: |
|
|
2027 | RETVAL = pl->next; |
|
|
2028 | OUTPUT: RETVAL |
|
|
2029 | |
|
|
2030 | bool |
|
|
2031 | cell_visible (player *pl, int dx, int dy) |
|
|
2032 | CODE: |
|
|
2033 | RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 |
|
|
2034 | && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; |
|
|
2035 | OUTPUT: |
|
|
2036 | RETVAL |
|
|
2037 | |
|
|
2038 | char * |
|
|
2039 | client (player *pl) |
|
|
2040 | CODE: |
|
|
2041 | RETVAL = pl->socket.client; |
|
|
2042 | OUTPUT: |
|
|
2043 | RETVAL |
|
|
2044 | |
|
|
2045 | char * |
|
|
2046 | host (player *pl) |
|
|
2047 | CODE: |
|
|
2048 | RETVAL = pl->socket.host; |
|
|
2049 | OUTPUT: |
|
|
2050 | RETVAL |
|
|
2051 | |
|
|
2052 | char * |
|
|
2053 | killer (player *pl, char *killer = 0) |
|
|
2054 | CODE: |
|
|
2055 | if (killer) |
|
|
2056 | snprintf (pl->killer, sizeof (pl->killer), "%s", killer); |
|
|
2057 | RETVAL = pl->killer; |
|
|
2058 | OUTPUT: |
|
|
2059 | RETVAL |
|
|
2060 | |
|
|
2061 | void |
|
|
2062 | buggy_mapscroll (player *pl, int value = 1) |
|
|
2063 | CODE: |
|
|
2064 | pl->socket.buggy_mapscroll = value; |
|
|
2065 | |
|
|
2066 | void |
2209 | void |
2067 | send (player *pl, SV *packet) |
2210 | send (player *pl, SV *packet) |
2068 | CODE: |
2211 | CODE: |
2069 | { |
2212 | { |
2070 | STRLEN len; |
2213 | STRLEN len; |
2071 | char *buf = SvPVbyte (packet, len); |
2214 | char *buf = SvPVbyte (packet, len); |
2072 | |
2215 | |
2073 | Write_String_To_Socket (&pl->socket, buf, len); |
2216 | if (pl->ns) |
|
|
2217 | pl->ns->send_packet (buf, len); |
2074 | } |
2218 | } |
2075 | |
2219 | |
2076 | int |
2220 | int |
2077 | listening (player *pl, int new_value = -1) |
2221 | listening (player *pl, int new_value = -1) |
2078 | CODE: |
2222 | CODE: |
… | |
… | |
2080 | if (new_value >= 0) |
2224 | if (new_value >= 0) |
2081 | pl->listening = new_value; |
2225 | pl->listening = new_value; |
2082 | OUTPUT: |
2226 | OUTPUT: |
2083 | RETVAL |
2227 | RETVAL |
2084 | |
2228 | |
2085 | void get_savebed (player *pl) |
2229 | void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) |
2086 | ALIAS: |
2230 | PROTOTYPE: $;$$$ |
2087 | savebed = 0 |
|
|
2088 | PPCODE: |
2231 | PPCODE: |
|
|
2232 | if (GIMME_V != G_VOID) |
|
|
2233 | { |
2089 | EXTEND (SP, 3); |
2234 | EXTEND (SP, 3); |
2090 | PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
2235 | PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
2091 | PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
2236 | PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
2092 | PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
2237 | PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
2093 | |
2238 | } |
2094 | void set_savebed (player *pl, char *map_path, int x, int y) |
2239 | if (map_path) sv_to (map_path, pl->savebed_map); |
2095 | CODE: |
2240 | if (x) sv_to (x, pl->bed_x); |
2096 | strcpy (pl->savebed_map, map_path); |
2241 | if (y) sv_to (y, pl->bed_y); |
2097 | pl->bed_x = x; |
|
|
2098 | pl->bed_y = y; |
|
|
2099 | |
2242 | |
2100 | void |
2243 | void |
2101 | list () |
2244 | list () |
2102 | PPCODE: |
2245 | PPCODE: |
2103 | { |
|
|
2104 | player *pl; |
|
|
2105 | for (pl = first_player; pl; pl = pl->next) |
2246 | for (player *pl = first_player; pl; pl = pl->next) |
2106 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
2247 | XPUSHs (sv_2mortal (to_sv (pl))); |
2107 | } |
|
|
2108 | |
2248 | |
2109 | bool |
2249 | bool |
2110 | peaceful (player *pl, bool new_setting = 0) |
2250 | peaceful (player *pl, bool new_setting = 0) |
2111 | PROTOTYPE: $;$ |
2251 | PROTOTYPE: $;$ |
2112 | CODE: |
2252 | CODE: |
… | |
… | |
2129 | OUTPUT: RETVAL |
2269 | OUTPUT: RETVAL |
2130 | |
2270 | |
2131 | |
2271 | |
2132 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2272 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2133 | |
2273 | |
2134 | mapstruct *first () |
2274 | maptile *first () |
2135 | PROTOTYPE: |
2275 | PROTOTYPE: |
2136 | CODE: |
2276 | CODE: |
2137 | RETVAL = first_map; |
2277 | RETVAL = first_map; |
2138 | OUTPUT: RETVAL |
2278 | OUTPUT: RETVAL |
2139 | |
2279 | |
2140 | mapstruct *next (mapstruct *map) |
|
|
2141 | PROTOTYPE: |
|
|
2142 | CODE: |
|
|
2143 | RETVAL = map->next; |
|
|
2144 | OUTPUT: RETVAL |
|
|
2145 | |
|
|
2146 | int invoke (mapstruct *map, int event, ...) |
2280 | int invoke (maptile *map, int event, ...) |
2147 | CODE: |
2281 | CODE: |
2148 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2282 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2149 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2283 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2150 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2284 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2151 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2285 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2152 | OUTPUT: RETVAL |
2286 | OUTPUT: RETVAL |
2153 | |
2287 | |
2154 | SV *registry (mapstruct *map) |
2288 | SV *registry (maptile *map) |
2155 | CODE: |
|
|
2156 | RETVAL = registry_of (map); |
|
|
2157 | OUTPUT: |
|
|
2158 | RETVAL |
|
|
2159 | |
2289 | |
2160 | SV * |
2290 | INCLUDE: $PERL genacc maptile ../include/map.h | |
2161 | get_property (mapstruct *obj, int type, int idx) |
|
|
2162 | CODE: |
|
|
2163 | RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx)); |
|
|
2164 | OUTPUT: RETVAL |
|
|
2165 | |
2291 | |
2166 | SV * |
|
|
2167 | set_property (mapstruct *obj, int type, int idx, SV *newval) |
|
|
2168 | CODE: |
|
|
2169 | switch (type) |
|
|
2170 | { |
|
|
2171 | case CFAPI_INT: |
|
|
2172 | cf_map_set_int_property (obj, idx, SvIV (newval)); |
|
|
2173 | break; |
|
|
2174 | default: |
|
|
2175 | croak ("unhandled type '%d' in set_property '%d'", type, idx); |
|
|
2176 | } |
|
|
2177 | |
|
|
2178 | mapstruct *new (int width, int height) |
2292 | maptile *new (int width, int height) |
2179 | PROTOTYPE: |
2293 | PROTOTYPE: |
2180 | CODE: |
2294 | CODE: |
2181 | { |
2295 | { |
2182 | RETVAL = get_empty_map (width, height); |
2296 | RETVAL = get_empty_map (width, height); |
2183 | } |
2297 | } |
2184 | OUTPUT: |
2298 | OUTPUT: |
2185 | RETVAL |
2299 | RETVAL |
2186 | |
2300 | |
2187 | void delete_map (mapstruct *map) |
2301 | void delete_map (maptile *map) |
2188 | |
2302 | |
2189 | void clean_tmp_map (mapstruct *map) |
2303 | void clean_tmp_map (maptile *map) |
2190 | |
2304 | |
2191 | void play_sound_map (mapstruct *map, int x, int y, int sound_num) |
2305 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2192 | |
2306 | |
|
|
2307 | int out_of_map (maptile *map, int x, int y) |
|
|
2308 | |
2193 | mapstruct *tile_map (mapstruct *map, unsigned int dir) |
2309 | maptile *tile_map (maptile *map, unsigned int dir) |
2194 | CODE: |
2310 | CODE: |
2195 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2311 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2196 | OUTPUT: |
2312 | OUTPUT: |
2197 | RETVAL |
2313 | RETVAL |
2198 | |
2314 | |
2199 | char *tile_path (mapstruct *map, unsigned int dir) |
2315 | char *tile_path (maptile *map, unsigned int dir) |
2200 | CODE: |
2316 | CODE: |
2201 | if (dir >= 4) |
2317 | if (dir >= 4) |
2202 | XSRETURN_UNDEF; |
2318 | XSRETURN_UNDEF; |
2203 | RETVAL = map->tile_path [dir]; |
2319 | RETVAL = map->tile_path [dir]; |
2204 | OUTPUT: |
2320 | OUTPUT: |
2205 | RETVAL |
2321 | RETVAL |
2206 | |
2322 | |
2207 | mapstruct *ready_map_name (char *name, int flags = 0) |
2323 | maptile *ready_map_name (char *name, int flags = 0) |
2208 | PROTOTYPE: $;$ |
2324 | PROTOTYPE: $;$ |
2209 | ALIAS: |
2325 | ALIAS: |
2210 | find = 0 |
2326 | find = 0 |
2211 | get_map = 1 |
2327 | get_map = 1 |
2212 | |
2328 | |
2213 | mapstruct *has_been_loaded (char *name) |
2329 | maptile *has_been_loaded (char *name) |
2214 | PROTOTYPE: $ |
2330 | PROTOTYPE: $ |
2215 | |
2331 | |
2216 | # whoever "designed" the plug-in api should have wasted |
|
|
2217 | # his/her time with staying away from the project - would have |
|
|
2218 | # saved others a lot of time, without doubt. |
|
|
2219 | void set_path (mapstruct *where, char *path) |
|
|
2220 | CODE: |
|
|
2221 | strcpy (where->path, path); |
|
|
2222 | |
|
|
2223 | int in_memory (mapstruct *map) |
2332 | int in_memory (maptile *map) |
2224 | CODE: |
2333 | CODE: |
2225 | RETVAL = map->in_memory; |
2334 | RETVAL = map->in_memory; |
2226 | OUTPUT: |
2335 | OUTPUT: |
2227 | RETVAL |
2336 | RETVAL |
2228 | |
2337 | |
2229 | bool unique (mapstruct *map) |
|
|
2230 | CODE: |
|
|
2231 | RETVAL = map->unique; |
|
|
2232 | OUTPUT: |
|
|
2233 | RETVAL |
|
|
2234 | |
|
|
2235 | void set_unique (mapstruct *map, bool unique) |
|
|
2236 | CODE: |
|
|
2237 | map->unique = unique; |
|
|
2238 | |
|
|
2239 | void |
2338 | void |
2240 | trigger (mapstruct *map, long connection, bool state = true) |
2339 | trigger (maptile *map, long connection, bool state = true) |
2241 | CODE: |
2340 | CODE: |
2242 | activate_connection (map, connection, state); |
2341 | activate_connection (map, connection, state); |
2243 | |
2342 | |
2244 | void |
2343 | void |
2245 | get_connection (mapstruct *map, long connection) |
2344 | get_connection (maptile *map, long connection) |
2246 | PPCODE: |
2345 | PPCODE: |
2247 | oblinkpt *obp = get_connection_links (map, connection); |
2346 | oblinkpt *obp = get_connection_links (map, connection); |
2248 | if (obp) |
2347 | if (obp) |
2249 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2348 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2250 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); |
2349 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); |
2251 | |
2350 | |
2252 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2351 | object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags) |
2253 | |
2352 | |
2254 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2353 | object *cf_map_insert_object (maptile *where, object* op, int x, int y) |
2255 | |
2354 | |
2256 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
2355 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
2257 | C_ARGS: str, map, nx, ny |
2356 | C_ARGS: str, map, nx, ny |
2258 | |
2357 | |
2259 | void |
2358 | void |
2260 | cf_map_normalise (mapstruct *map, int x, int y) |
2359 | cf_map_normalise (maptile *map, int x, int y) |
2261 | PPCODE: |
2360 | PPCODE: |
2262 | { |
2361 | { |
2263 | mapstruct *nmap = 0; |
2362 | maptile *nmap = 0; |
2264 | I16 nx = 0, ny = 0; |
2363 | I16 nx = 0, ny = 0; |
2265 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2364 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2266 | |
2365 | |
2267 | EXTEND (SP, 4); |
2366 | EXTEND (SP, 4); |
2268 | PUSHs (sv_2mortal (newSViv (flags))); |
2367 | PUSHs (sv_2mortal (newSViv (flags))); |
… | |
… | |
2274 | PUSHs (sv_2mortal (newSViv (ny))); |
2373 | PUSHs (sv_2mortal (newSViv (ny))); |
2275 | } |
2374 | } |
2276 | } |
2375 | } |
2277 | |
2376 | |
2278 | void |
2377 | void |
2279 | at (mapstruct *map, unsigned int x, unsigned int y) |
2378 | at (maptile *map, unsigned int x, unsigned int y) |
2280 | PROTOTYPE: $$$ |
2379 | PROTOTYPE: $$$ |
2281 | PPCODE: |
2380 | PPCODE: |
2282 | { |
2381 | { |
2283 | object *o; |
2382 | object *o; |
2284 | mapstruct *nmap = 0; |
2383 | maptile *nmap = 0; |
2285 | I16 nx, ny; |
2384 | I16 nx, ny; |
2286 | |
2385 | |
2287 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2386 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2288 | |
2387 | |
2289 | if (nmap) |
2388 | if (nmap) |
2290 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2389 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2291 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2390 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2292 | } |
2391 | } |
2293 | |
2392 | |
2294 | SV * |
2393 | SV * |
2295 | bot_at (mapstruct *obj, unsigned int x, unsigned int y) |
2394 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2296 | PROTOTYPE: $$$ |
2395 | PROTOTYPE: $$$ |
2297 | ALIAS: |
2396 | ALIAS: |
2298 | top_at = 1 |
2397 | top_at = 1 |
2299 | flags_at = 2 |
2398 | flags_at = 2 |
2300 | light_at = 3 |
2399 | light_at = 3 |
… | |
… | |
2317 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2416 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2318 | } |
2417 | } |
2319 | OUTPUT: |
2418 | OUTPUT: |
2320 | RETVAL |
2419 | RETVAL |
2321 | |
2420 | |
|
|
2421 | void fix_walls (maptile *map, int x, int y) |
|
|
2422 | |
|
|
2423 | void fix_walls_around (maptile *map, int x, int y) |
2322 | |
2424 | |
2323 | MODULE = cf PACKAGE = cf::arch |
2425 | MODULE = cf PACKAGE = cf::arch |
|
|
2426 | |
|
|
2427 | archetype *find (const char *name) |
|
|
2428 | CODE: |
|
|
2429 | RETVAL = archetype::find (name); |
|
|
2430 | OUTPUT: |
|
|
2431 | RETVAL |
2324 | |
2432 | |
2325 | archetype *first() |
2433 | archetype *first() |
2326 | PROTOTYPE: |
2434 | PROTOTYPE: |
2327 | CODE: |
2435 | CODE: |
2328 | RETVAL = first_archetype; |
2436 | RETVAL = first_archetype; |
2329 | OUTPUT: RETVAL |
2437 | OUTPUT: RETVAL |
2330 | |
2438 | |
2331 | archetype *next (archetype *arch) |
2439 | INCLUDE: $PERL genacc archetype ../include/object.h | |
2332 | CODE: |
|
|
2333 | RETVAL = arch->next; |
|
|
2334 | OUTPUT: RETVAL |
|
|
2335 | |
|
|
2336 | archetype *head (archetype *arch) |
|
|
2337 | CODE: |
|
|
2338 | RETVAL = arch->head; |
|
|
2339 | OUTPUT: RETVAL |
|
|
2340 | |
|
|
2341 | archetype *more (archetype *arch) |
|
|
2342 | CODE: |
|
|
2343 | RETVAL = arch->more; |
|
|
2344 | OUTPUT: RETVAL |
|
|
2345 | |
|
|
2346 | const char *name (archetype *arch) |
|
|
2347 | CODE: |
|
|
2348 | RETVAL = arch->name; |
|
|
2349 | OUTPUT: RETVAL |
|
|
2350 | |
|
|
2351 | object *clone (archetype *arch) |
|
|
2352 | CODE: |
|
|
2353 | RETVAL = &arch->clone; |
|
|
2354 | OUTPUT: RETVAL |
|
|
2355 | |
2440 | |
2356 | MODULE = cf PACKAGE = cf::party |
2441 | MODULE = cf PACKAGE = cf::party |
2357 | |
2442 | |
2358 | partylist *first () |
2443 | partylist *first () |
2359 | PROTOTYPE: |
2444 | PROTOTYPE: |
… | |
… | |
2409 | RETVAL = reg->msg; |
2494 | RETVAL = reg->msg; |
2410 | OUTPUT: RETVAL |
2495 | OUTPUT: RETVAL |
2411 | |
2496 | |
2412 | MODULE = cf PACKAGE = cf::living |
2497 | MODULE = cf PACKAGE = cf::living |
2413 | |
2498 | |
2414 | val64 |
2499 | INCLUDE: $PERL genacc living ../include/living.h | |
2415 | exp (living *liv, val64 new_val = 0) |
2500 | |
2416 | PROTOTYPE: $;$ |
2501 | MODULE = cf PACKAGE = cf::settings |
2417 | ALIAS: |
2502 | |
2418 | Str = 1 |
2503 | INCLUDE: $PERL genacc Settings ../include/global.h | |
2419 | Dex = 2 |
2504 | |
2420 | Con = 3 |
2505 | MODULE = cf PACKAGE = cf::client |
2421 | Wis = 4 |
2506 | |
2422 | Cha = 5 |
2507 | INCLUDE: $PERL genacc client ../include/client.h | |
2423 | Int = 6 |
2508 | |
2424 | Pow = 7 |
2509 | int invoke (client *ns, int event, ...) |
2425 | wc = 8 |
2510 | CODE: |
2426 | ac = 9 |
2511 | if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2427 | hp = 10 |
2512 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2428 | maxhp = 11 |
2513 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2429 | sp = 12 |
2514 | RETVAL = INVOKE_((event_type)event, ARG_CLIENT (ns), ARG_AV (av)); |
2430 | maxsp = 13 |
2515 | OUTPUT: RETVAL |
2431 | grace = 14 |
2516 | |
2432 | maxgrace = 15 |
2517 | SV *registry (client *ns) |
2433 | food = 16 |
2518 | |
2434 | dam = 17 |
2519 | void |
2435 | luck = 18 |
2520 | list () |
2436 | CODE: |
2521 | PPCODE: |
2437 | # define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break |
2522 | EXTEND (SP, clients.size ()); |
2438 | switch (ix) |
2523 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2439 | { |
2524 | PUSHs (sv_2mortal (to_sv (*i))); |
2440 | LIVING_ACC (exp , 0); |
2525 | |
2441 | LIVING_ACC (Str , 1); |
2526 | client * |
2442 | LIVING_ACC (Dex , 2); |
2527 | create (int fd, const char *peername) |
2443 | LIVING_ACC (Con , 3); |
2528 | CODE: |
2444 | LIVING_ACC (Wis , 4); |
2529 | RETVAL = client::create (fd, peername); |
2445 | LIVING_ACC (Cha , 5); |
|
|
2446 | LIVING_ACC (Int , 6); |
|
|
2447 | LIVING_ACC (Pow , 7); |
|
|
2448 | LIVING_ACC (wc , 8); |
|
|
2449 | LIVING_ACC (ac , 9); |
|
|
2450 | LIVING_ACC (hp , 10); |
|
|
2451 | LIVING_ACC (maxhp , 11); |
|
|
2452 | LIVING_ACC (sp , 12); |
|
|
2453 | LIVING_ACC (maxsp , 13); |
|
|
2454 | LIVING_ACC (grace , 14); |
|
|
2455 | LIVING_ACC (maxgrace, 15); |
|
|
2456 | LIVING_ACC (food , 16); |
|
|
2457 | LIVING_ACC (dam , 17); |
|
|
2458 | LIVING_ACC (luck , 18); |
|
|
2459 | } |
|
|
2460 | # undef LIVING_ACC |
|
|
2461 | OUTPUT: |
2530 | OUTPUT: |
2462 | RETVAL |
2531 | RETVAL |
2463 | |
2532 | |
|
|
2533 | void |
|
|
2534 | client::send_packet (SV *packet) |
|
|
2535 | CODE: |
|
|
2536 | { |
|
|
2537 | STRLEN len; |
|
|
2538 | char *buf = SvPVbyte (packet, len); |
|
|
2539 | |
|
|
2540 | THIS->send_packet (buf, len); |
|
|
2541 | } |
|
|
2542 | |
|
|
2543 | void |
|
|
2544 | client::destroy () |
|
|
2545 | |