… | |
… | |
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 | |
… | |
… | |
60 | #define SvVAL64 SvNV |
50 | #define SvVAL64 SvNV |
61 | |
51 | |
62 | static f_plug_api gethook = cfapi_get_hooks; |
52 | static f_plug_api gethook = cfapi_get_hooks; |
63 | static f_plug_api object_set_property = cfapi_object_set_property; |
53 | static f_plug_api object_set_property = cfapi_object_set_property; |
64 | static f_plug_api object_insert = cfapi_object_insert; |
54 | static f_plug_api object_insert = cfapi_object_insert; |
65 | |
|
|
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 | |
55 | |
84 | static HV *obj_cache; |
56 | static HV *obj_cache; |
85 | static PerlInterpreter *perl; |
57 | static PerlInterpreter *perl; |
86 | |
58 | |
87 | static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; |
59 | static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; |
… | |
… | |
188 | return SvPTR (sv, klass); |
160 | return SvPTR (sv, klass); |
189 | else |
161 | else |
190 | return 0; |
162 | return 0; |
191 | } |
163 | } |
192 | |
164 | |
|
|
165 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } |
|
|
166 | inline SV *to_sv (const char * v) { return newSVpv (v, 0); } |
|
|
167 | inline SV *to_sv (bool v) { return newSViv (v); } |
|
|
168 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
|
|
169 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
|
|
170 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
|
|
171 | inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
|
|
172 | inline SV *to_sv ( signed int v) { return newSViv (v); } |
|
|
173 | inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
|
|
174 | inline SV *to_sv ( signed long v) { return newSViv (v); } |
|
|
175 | inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
|
|
176 | inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
|
|
177 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
|
|
178 | inline SV *to_sv (float v) { return newSVnv (v); } |
|
|
179 | inline SV *to_sv (double v) { return newSVnv (v); } |
|
|
180 | inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } |
|
|
181 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } |
|
|
182 | inline SV *to_sv (mapstruct * v) { return newSVattachable (v, "cf::map::wrap"); } |
|
|
183 | inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } |
|
|
184 | inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } |
|
|
185 | inline SV *to_sv (region * v) { return newSVptr (v, "cf::region::wrap"); } |
|
|
186 | inline SV *to_sv (living * v) { return newSVptr (v, "cf::living::wrap"); } |
|
|
187 | |
|
|
188 | inline SV *to_sv (object & v) { return to_sv (&v); } |
|
|
189 | inline SV *to_sv (living & v) { return to_sv (&v); } |
|
|
190 | |
|
|
191 | //TODO: |
|
|
192 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
|
|
193 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
194 | |
|
|
195 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
|
|
196 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed |
|
|
197 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
|
|
198 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
|
|
199 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
|
|
200 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
|
|
201 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
|
|
202 | inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
|
|
203 | inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
|
|
204 | inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
|
|
205 | inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
|
|
206 | inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
|
|
207 | inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
|
|
208 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
|
|
209 | inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
|
|
210 | inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); } |
|
|
211 | inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); } |
|
|
212 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); } |
|
|
213 | inline void sv_to (SV *sv, mapstruct * &v) { v = (mapstruct *)SvPTR_ornull (sv, "cf::map"); } |
|
|
214 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
|
|
215 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
|
|
216 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
|
|
217 | |
|
|
218 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
|
|
219 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO |
|
|
220 | |
|
|
221 | template<class T> |
|
|
222 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
|
|
223 | |
|
|
224 | template<int N> |
|
|
225 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
|
|
226 | |
193 | static SV * |
227 | static SV * |
194 | newSVdt_va (va_list &ap, data_type type) |
228 | newSVdt_va (va_list &ap, data_type type) |
195 | { |
229 | { |
196 | SV *sv; |
230 | SV *sv; |
197 | |
231 | |
… | |
… | |
223 | sv = str ? newSVpv (str, len) : &PL_sv_undef; |
257 | sv = str ? newSVpv (str, len) : &PL_sv_undef; |
224 | } |
258 | } |
225 | break; |
259 | break; |
226 | |
260 | |
227 | case DT_OBJECT: |
261 | case DT_OBJECT: |
228 | { |
262 | 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; |
263 | break; |
233 | |
264 | |
234 | case DT_MAP: |
265 | case DT_MAP: |
235 | // va_arg (object *) when void * is passed is an XSI extension |
266 | // va_arg (object *) when void * is passed is an XSI extension |
236 | sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
267 | sv = to_sv (va_arg (ap, mapstruct *)); |
237 | break; |
268 | break; |
238 | |
269 | |
239 | case DT_PLAYER: |
270 | case DT_PLAYER: |
240 | sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap"); |
271 | sv = to_sv (va_arg (ap, player *)); |
241 | break; |
272 | break; |
242 | |
273 | |
243 | case DT_ARCH: |
274 | case DT_ARCH: |
244 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
275 | sv = to_sv (va_arg (ap, archetype *)); |
245 | break; |
276 | break; |
246 | |
277 | |
247 | case DT_PARTY: |
278 | case DT_PARTY: |
248 | sv = newSVptr (va_arg (ap, partylist *), "cf::party::wrap"); |
279 | sv = to_sv (va_arg (ap, partylist *)); |
249 | break; |
280 | break; |
250 | |
281 | |
251 | case DT_REGION: |
282 | case DT_REGION: |
252 | sv = newSVptr (va_arg (ap, region *), "cf::region::wrap"); |
283 | sv = to_sv (va_arg (ap, region *)); |
253 | break; |
284 | break; |
254 | |
285 | |
255 | default: |
286 | default: |
256 | assert (("unhandled type in newSVdt_va", 0)); |
287 | assert (("unhandled type in newSVdt_va", 0)); |
257 | } |
288 | } |
… | |
… | |
336 | { |
367 | { |
337 | SvREFCNT_dec (cb); |
368 | SvREFCNT_dec (cb); |
338 | cb = 0; |
369 | cb = 0; |
339 | } |
370 | } |
340 | |
371 | |
341 | if (attach) |
|
|
342 | { |
|
|
343 | free_string (attach); |
|
|
344 | attach = 0; |
372 | attach = 0; |
345 | } |
|
|
346 | } |
373 | } |
347 | |
374 | |
348 | void attachable_base::optimise () |
375 | void attachable_base::optimise () |
349 | { |
376 | { |
350 | if (!self) |
377 | if (!self) |
… | |
… | |
369 | PUSHMARK (SP); |
396 | PUSHMARK (SP); |
370 | EXTEND (SP, 2); |
397 | EXTEND (SP, 2); |
371 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
398 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
372 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
399 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
373 | |
400 | |
374 | free_string (attach); |
|
|
375 | attach = 0; |
401 | attach = 0; |
376 | |
402 | |
377 | PUTBACK; |
403 | PUTBACK; |
378 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
404 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
379 | FREETMPS; |
405 | FREETMPS; |
… | |
… | |
414 | void reattach (attachable<subclass> *obj) |
440 | void reattach (attachable<subclass> *obj) |
415 | { |
441 | { |
416 | obj->optimise (); |
442 | obj->optimise (); |
417 | |
443 | |
418 | if (obj->self) |
444 | if (obj->self) |
419 | reattach (subclass::get_dt (), (subclass *)obj); |
445 | reattach ((data_type) cftype<subclass>::dt, (subclass *)obj); |
420 | } |
446 | } |
421 | |
447 | |
|
|
448 | #include "kw_hash.h" |
|
|
449 | |
422 | object_freezer::object_freezer (const char *filename) |
450 | object_freezer::object_freezer () |
|
|
451 | : dynbuf (128 * 1024, 64 * 1024) |
423 | { |
452 | { |
424 | this->filename = (SV *)newSVpv (filename, 0); |
|
|
425 | |
|
|
426 | char filename2 [4096]; |
|
|
427 | snprintf (filename2, 4096, "%s~", filename); |
|
|
428 | |
|
|
429 | av = newAV (); |
453 | 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 | } |
454 | } |
434 | |
455 | |
435 | object_freezer::~object_freezer () |
456 | object_freezer::~object_freezer () |
|
|
457 | { |
|
|
458 | SvREFCNT_dec (av); |
|
|
459 | } |
|
|
460 | |
|
|
461 | void object_freezer::put (attachable_base *ext) |
|
|
462 | { |
|
|
463 | ext->optimise (); |
|
|
464 | |
|
|
465 | if (ext->self) |
|
|
466 | { |
|
|
467 | int idx = AvFILLp ((AV *)av) + 1; |
|
|
468 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
|
|
469 | |
|
|
470 | add ((void *)"oid ", 4); |
|
|
471 | add ((sint32)idx); |
|
|
472 | add ('\n'); |
|
|
473 | } |
|
|
474 | } |
|
|
475 | |
|
|
476 | bool object_freezer::save (const char *filename) |
436 | { |
477 | { |
437 | dSP; |
478 | dSP; |
438 | ENTER; |
479 | ENTER; |
439 | SAVETMPS; |
480 | SAVETMPS; |
440 | PUSHMARK (SP); |
481 | PUSHMARK (SP); |
|
|
482 | EXTEND (SP, 3); |
441 | XPUSHs (sv_2mortal ((SV *)filename)); |
483 | PUSHs (sv_2mortal (newSVpv (filename, 0))); |
442 | XPUSHs (sv_2mortal (newRV_noinc (text))); |
484 | PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); |
443 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
485 | PUSHs (sv_2mortal (newRV_inc ((SV *)av))); |
444 | PUTBACK; |
486 | PUTBACK; |
445 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
487 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
446 | FREETMPS; |
488 | FREETMPS; |
447 | LEAVE; |
489 | LEAVE; |
448 | } |
490 | } |
449 | |
491 | |
450 | void object_freezer::put (attachable_base *ext) |
|
|
451 | { |
|
|
452 | ext->optimise (); |
|
|
453 | |
|
|
454 | if (ext->self) |
|
|
455 | { |
|
|
456 | int idx = AvFILLp ((AV *)av) + 1; |
|
|
457 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
|
|
458 | |
|
|
459 | sv_catpvf (text, "oid %d\n", idx); |
|
|
460 | } |
|
|
461 | } |
|
|
462 | |
|
|
463 | int fprintf (object_freezer &freezer, const char *format, ...) |
492 | int fprintf (object_freezer &freezer, const char *format, ...) |
464 | { |
493 | { |
465 | va_list ap; |
494 | va_list ap; |
466 | |
495 | |
467 | va_start (ap, format); |
496 | va_start (ap, format); |
468 | sv_vcatpvfn (freezer.text, format, strlen (format), &ap, 0, 0, 0); |
497 | |
|
|
498 | int len = vsnprintf ((char *)freezer.force (1024), 1024, format, ap); |
|
|
499 | |
|
|
500 | if (len >= 0) |
|
|
501 | freezer.alloc (len); |
|
|
502 | |
469 | va_end (ap); |
503 | va_end (ap); |
470 | } |
504 | } |
471 | |
505 | |
472 | int fputs (const char *s, object_freezer &freezer) |
506 | int fputs (const char *s, object_freezer &freezer) |
473 | { |
507 | { |
474 | sv_catpvn (freezer.text, s, strlen (s)); |
508 | freezer.add (s); |
475 | } |
509 | } |
476 | |
510 | |
477 | object_thawer::object_thawer (const char *filename) |
511 | object_thawer::object_thawer (const char *filename) |
478 | { |
512 | { |
|
|
513 | static const char eof[] = "\n\n\n\0\0\0"; |
|
|
514 | |
479 | av = 0; |
515 | av = 0; |
480 | fp = 0; |
516 | text = 0; |
|
|
517 | line = 0; |
481 | |
518 | |
482 | if (!filename) |
519 | 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 | { |
520 | { |
494 | dSP; |
521 | dSP; |
495 | ENTER; |
522 | ENTER; |
496 | SAVETMPS; |
523 | SAVETMPS; |
497 | PUSHMARK (SP); |
524 | PUSHMARK (SP); |
498 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
525 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
499 | PUTBACK; |
526 | PUTBACK; |
500 | |
527 | |
501 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
528 | if (2 == call_pv ("cf::object_thawer_load", G_ARRAY | G_EVAL)) |
502 | { |
529 | { |
503 | SPAGAIN; |
530 | SPAGAIN; |
|
|
531 | |
|
|
532 | // second value - perl objects |
|
|
533 | { |
504 | SV *sv = POPs; |
534 | SV *sv = POPs; |
505 | if (SvROK (sv)) |
535 | if (SvROK (sv)) |
506 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
536 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
|
|
537 | } |
|
|
538 | |
|
|
539 | // first value - text part, pad with 3 zeroes |
|
|
540 | { |
|
|
541 | SV *sv = POPs; |
|
|
542 | STRLEN len; |
|
|
543 | char *sv_ = SvPVbyte (sv, len); |
|
|
544 | text = newSV (len + sizeof (eof)); |
|
|
545 | SvCUR_set (text, len); |
|
|
546 | memcpy (SvPVX (text), sv_, len); |
|
|
547 | memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure |
|
|
548 | |
|
|
549 | line = SvPVX (text); |
|
|
550 | } |
507 | } |
551 | } |
508 | |
552 | |
|
|
553 | PUTBACK; |
509 | FREETMPS; |
554 | FREETMPS; |
510 | LEAVE; |
555 | LEAVE; |
511 | } |
556 | } |
512 | } |
557 | } |
513 | |
558 | |
… | |
… | |
533 | reattach (type, obj); |
578 | reattach (type, obj); |
534 | } |
579 | } |
535 | |
580 | |
536 | object_thawer::~object_thawer () |
581 | object_thawer::~object_thawer () |
537 | { |
582 | { |
538 | if (fp) fclose (fp); |
583 | if (text) SvREFCNT_dec (text); |
539 | if (av) SvREFCNT_dec ((AV *)av); |
584 | if (av) SvREFCNT_dec (av); |
|
|
585 | } |
|
|
586 | |
|
|
587 | char *fgets (char *s, int n, object_thawer &thawer) |
|
|
588 | { |
|
|
589 | char *p = thawer.line; |
|
|
590 | char *q = s; |
|
|
591 | |
|
|
592 | if (!p) |
|
|
593 | return 0; |
|
|
594 | |
|
|
595 | while (--n) |
|
|
596 | { |
|
|
597 | if (!*p) |
|
|
598 | break; |
|
|
599 | |
|
|
600 | *q++ = *p; |
|
|
601 | |
|
|
602 | if (*p++ == '\n') |
|
|
603 | break; |
|
|
604 | } |
|
|
605 | |
|
|
606 | *q = 0; |
|
|
607 | thawer.line = p; |
|
|
608 | |
|
|
609 | return s == q ? 0 : s; |
|
|
610 | } |
|
|
611 | |
|
|
612 | keyword object_thawer::get_kv () |
|
|
613 | { |
|
|
614 | if (!line) |
|
|
615 | return KW_EOF; |
|
|
616 | |
|
|
617 | for (;;) |
|
|
618 | { |
|
|
619 | char *p = line; |
|
|
620 | |
|
|
621 | if (!*p) |
|
|
622 | return KW_EOF; |
|
|
623 | |
|
|
624 | // parse keyword |
|
|
625 | while (*p > ' ') |
|
|
626 | p++; |
|
|
627 | |
|
|
628 | int klen = p - line; |
|
|
629 | |
|
|
630 | if (*p++ != '\n') |
|
|
631 | { |
|
|
632 | // parse value |
|
|
633 | while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 |
|
|
634 | ++p; |
|
|
635 | |
|
|
636 | last_value = p; |
|
|
637 | |
|
|
638 | while (*p != '\n') |
|
|
639 | p++; |
|
|
640 | |
|
|
641 | *p++ = 0; |
|
|
642 | } |
|
|
643 | else |
|
|
644 | last_value = 0; |
|
|
645 | |
|
|
646 | line [klen] = 0; |
|
|
647 | keyword_idx *kw = kw_lex::match (line, klen); |
|
|
648 | |
|
|
649 | //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D |
|
|
650 | |
|
|
651 | if (kw) |
|
|
652 | { |
|
|
653 | line = p; |
|
|
654 | return kw->index; |
|
|
655 | } |
|
|
656 | else if (!*line || *line == '#') |
|
|
657 | { |
|
|
658 | // empty/comment line |
|
|
659 | line = p; |
|
|
660 | } |
|
|
661 | else |
|
|
662 | return KW_ERROR; |
|
|
663 | } |
|
|
664 | } |
|
|
665 | |
|
|
666 | void object_thawer::get (shstr &sh) const |
|
|
667 | { |
|
|
668 | if (last_value) |
|
|
669 | sh = last_value; |
|
|
670 | else |
|
|
671 | { |
|
|
672 | sh = "<value missing>"; |
|
|
673 | LOG (llevError, "keyword requires value: <%s>\n", line);//TODO: add filename |
|
|
674 | } |
|
|
675 | } |
|
|
676 | |
|
|
677 | void object_thawer::get_ml (keyword kend, shstr &sh) |
|
|
678 | { |
|
|
679 | char kw[128]; |
|
|
680 | |
|
|
681 | int klen = keyword_len [kend]; |
|
|
682 | |
|
|
683 | kw [0] = '\n'; |
|
|
684 | memcpy (kw + 1, keyword_str [kend], klen); |
|
|
685 | kw [klen + 1] = '\n'; |
|
|
686 | kw [klen + 2] = 0; |
|
|
687 | |
|
|
688 | // first test for completely empty msg... "endXXX\n" |
|
|
689 | if (!strncmp (line, kw + 1, klen + 1)) |
|
|
690 | { |
|
|
691 | sh = 0; |
|
|
692 | |
|
|
693 | line += klen + 1; |
|
|
694 | |
|
|
695 | return; |
|
|
696 | } |
|
|
697 | else |
|
|
698 | { |
|
|
699 | // multi-line strings are delimited by "\nendXXX\n" or "endXXX\n" (NULL) |
|
|
700 | |
|
|
701 | char *end = strstr (line, kw); |
|
|
702 | |
|
|
703 | if (!end) |
|
|
704 | { |
|
|
705 | sh = 0; |
|
|
706 | return; |
|
|
707 | } |
|
|
708 | |
|
|
709 | *end = 0; |
|
|
710 | sh = line; |
|
|
711 | |
|
|
712 | line = end + keyword_len [kend] + 1; |
|
|
713 | |
|
|
714 | while (*line++ != '\n') |
|
|
715 | ; |
|
|
716 | } |
|
|
717 | } |
|
|
718 | |
|
|
719 | sint32 object_thawer::get_sint32 () const |
|
|
720 | { |
|
|
721 | char *p = last_value; |
|
|
722 | |
|
|
723 | if (!p) |
|
|
724 | return 0; |
|
|
725 | |
|
|
726 | sint32 val = 0; |
|
|
727 | bool negate; |
|
|
728 | |
|
|
729 | if (*p == '-') |
|
|
730 | { |
|
|
731 | negate = true; |
|
|
732 | ++p; |
|
|
733 | } |
|
|
734 | else |
|
|
735 | negate = false; |
|
|
736 | |
|
|
737 | do |
|
|
738 | { |
|
|
739 | val *= 10; |
|
|
740 | val += *p++ - '0'; |
|
|
741 | } |
|
|
742 | while (*p); |
|
|
743 | |
|
|
744 | return negate ? -val : val; |
|
|
745 | } |
|
|
746 | |
|
|
747 | sint64 object_thawer::get_sint64 () const |
|
|
748 | { |
|
|
749 | return last_value ? atoll (last_value) : 0; |
|
|
750 | } |
|
|
751 | |
|
|
752 | double object_thawer::get_double () const |
|
|
753 | { |
|
|
754 | return last_value ? atof (last_value) : 0; |
540 | } |
755 | } |
541 | |
756 | |
542 | ///////////////////////////////////////////////////////////////////////////// |
757 | ///////////////////////////////////////////////////////////////////////////// |
543 | |
758 | |
544 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
759 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
… | |
… | |
654 | char *argv[] = { |
869 | char *argv[] = { |
655 | "", |
870 | "", |
656 | "-e" |
871 | "-e" |
657 | "cf->bootstrap;" |
872 | "cf->bootstrap;" |
658 | "unshift @INC, cf::datadir ();" |
873 | "unshift @INC, cf::datadir ();" |
|
|
874 | "require cf;" |
659 | }; |
875 | }; |
660 | |
876 | |
661 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
877 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
662 | { |
878 | { |
663 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
879 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
664 | exit (EXIT_FAILURE); |
880 | exit (EXIT_FAILURE); |
665 | } |
881 | } |
666 | |
882 | |
667 | obj_cache = newHV (); |
883 | obj_cache = newHV (); |
668 | } |
|
|
669 | |
|
|
670 | void cfperl_boot () |
|
|
671 | { |
|
|
672 | perl_booted = true; |
|
|
673 | |
|
|
674 | eval_pv ("require cf", 1); |
|
|
675 | } |
884 | } |
676 | |
885 | |
677 | void cfperl_main () |
886 | void cfperl_main () |
678 | { |
887 | { |
679 | dSP; |
888 | dSP; |
… | |
… | |
1052 | const_iv (AT_BLIND) |
1261 | const_iv (AT_BLIND) |
1053 | const_iv (AT_INTERNAL) |
1262 | const_iv (AT_INTERNAL) |
1054 | const_iv (AT_LIFE_STEALING) |
1263 | const_iv (AT_LIFE_STEALING) |
1055 | const_iv (AT_DISEASE) |
1264 | const_iv (AT_DISEASE) |
1056 | |
1265 | |
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) |
1266 | const_iv (WEAP_HIT) |
1068 | const_iv (WEAP_SLASH) |
1267 | const_iv (WEAP_SLASH) |
1069 | const_iv (WEAP_PIERCE) |
1268 | const_iv (WEAP_PIERCE) |
1070 | const_iv (WEAP_CLEAVE) |
1269 | const_iv (WEAP_CLEAVE) |
1071 | const_iv (WEAP_SLICE) |
1270 | const_iv (WEAP_SLICE) |
… | |
… | |
1192 | const_iv (NDI_MAX_COLOR) |
1391 | const_iv (NDI_MAX_COLOR) |
1193 | const_iv (NDI_COLOR_MASK) |
1392 | const_iv (NDI_COLOR_MASK) |
1194 | const_iv (NDI_UNIQUE) |
1393 | const_iv (NDI_UNIQUE) |
1195 | const_iv (NDI_ALL) |
1394 | const_iv (NDI_ALL) |
1196 | |
1395 | |
|
|
1396 | const_iv (UPD_LOCATION) |
|
|
1397 | const_iv (UPD_FLAGS) |
|
|
1398 | const_iv (UPD_WEIGHT) |
|
|
1399 | const_iv (UPD_FACE) |
|
|
1400 | const_iv (UPD_NAME) |
|
|
1401 | const_iv (UPD_ANIM) |
|
|
1402 | const_iv (UPD_ANIMSPEED) |
|
|
1403 | const_iv (UPD_NROF) |
|
|
1404 | |
|
|
1405 | const_iv (UPD_SP_MANA) |
|
|
1406 | const_iv (UPD_SP_GRACE) |
|
|
1407 | const_iv (UPD_SP_DAMAGE) |
|
|
1408 | |
1197 | const_iv (F_APPLIED) |
1409 | const_iv (F_APPLIED) |
1198 | const_iv (F_LOCATION) |
1410 | const_iv (F_LOCATION) |
1199 | const_iv (F_UNPAID) |
1411 | const_iv (F_UNPAID) |
1200 | const_iv (F_MAGIC) |
1412 | const_iv (F_MAGIC) |
1201 | const_iv (F_CURSED) |
1413 | const_iv (F_CURSED) |
… | |
… | |
1255 | |
1467 | |
1256 | const_iv (SK_EXP_ADD_SKILL) |
1468 | const_iv (SK_EXP_ADD_SKILL) |
1257 | const_iv (SK_EXP_TOTAL) |
1469 | const_iv (SK_EXP_TOTAL) |
1258 | const_iv (SK_EXP_NONE) |
1470 | const_iv (SK_EXP_NONE) |
1259 | const_iv (SK_SUBTRACT_SKILL_EXP) |
1471 | const_iv (SK_SUBTRACT_SKILL_EXP) |
|
|
1472 | const_iv (SK_EXP_SKILL_ONLY) |
1260 | |
1473 | |
1261 | const_iv (SK_LOCKPICKING) |
1474 | const_iv (SK_LOCKPICKING) |
1262 | const_iv (SK_HIDING) |
1475 | const_iv (SK_HIDING) |
1263 | const_iv (SK_SMITHERY) |
1476 | const_iv (SK_SMITHERY) |
1264 | const_iv (SK_BOWYER) |
1477 | const_iv (SK_BOWYER) |
… | |
… | |
1395 | av_push (event, newSViv (eiv->klass)); |
1608 | av_push (event, newSViv (eiv->klass)); |
1396 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1609 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1397 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1610 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1398 | } |
1611 | } |
1399 | |
1612 | |
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); |
1613 | //I_EVENT_API (PACKAGE); |
1533 | } |
1614 | } |
1534 | |
1615 | |
1535 | void _reload_1 () |
1616 | void _init_vars () |
1536 | CODE: |
1617 | CODE: |
1537 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1618 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1538 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1619 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1539 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1620 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1540 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1621 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1541 | cb_map = get_av ("cf::CB_MAP" , 1); |
1622 | cb_map = get_av ("cf::CB_MAP" , 1); |
1542 | |
1623 | |
1543 | void _reload_2 () |
1624 | void _global_reattach () |
1544 | CODE: |
1625 | CODE: |
1545 | { |
1626 | { |
1546 | // reattach to all attachable objects in the game. |
1627 | // reattach to all attachable objects in the game. |
1547 | for (player *pl = first_player; pl; pl = pl->next) |
1628 | for (player *pl = first_player; pl; pl = pl->next) |
1548 | reattach (pl); |
1629 | reattach (pl); |
1549 | |
1630 | |
1550 | for (mapstruct *map = first_map; map; map = map->next) |
1631 | for (mapstruct *map = first_map; map; map = map->next) |
1551 | reattach (map); |
1632 | reattach (map); |
1552 | |
1633 | |
1553 | for (object *op = objects; op; op = op->next) |
1634 | for (object *op = object::first; op; op = op->next) |
1554 | reattach (op); |
1635 | reattach (op); |
1555 | } |
1636 | } |
1556 | |
1637 | |
1557 | NV floor (NV x) |
1638 | NV floor (NV x) |
1558 | |
1639 | |
… | |
… | |
1606 | case 5: RETVAL = settings.playerdir; break; |
1687 | case 5: RETVAL = settings.playerdir; break; |
1607 | case 6: RETVAL = settings.datadir ; break; |
1688 | case 6: RETVAL = settings.datadir ; break; |
1608 | } |
1689 | } |
1609 | OUTPUT: RETVAL |
1690 | OUTPUT: RETVAL |
1610 | |
1691 | |
1611 | int |
1692 | void _exit (int status = 0) |
|
|
1693 | |
1612 | cf_find_animation (char *text) |
1694 | int cf_find_animation (char *text) |
1613 | PROTOTYPE: $ |
1695 | PROTOTYPE: $ |
1614 | |
1696 | |
1615 | int random_roll(int min, int max, object *op, int goodbad); |
1697 | int random_roll(int min, int max, object *op, int goodbad); |
1616 | |
1698 | |
1617 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1699 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
… | |
… | |
1684 | CODE: |
1766 | CODE: |
1685 | RETVAL = registry_of (op); |
1767 | RETVAL = registry_of (op); |
1686 | OUTPUT: |
1768 | OUTPUT: |
1687 | RETVAL |
1769 | RETVAL |
1688 | |
1770 | |
|
|
1771 | void mortals () |
|
|
1772 | PPCODE: |
|
|
1773 | EXTEND (SP, object::mortals.size ()); |
|
|
1774 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
|
|
1775 | PUSHs (to_sv (*i)); |
|
|
1776 | |
|
|
1777 | object *first () |
|
|
1778 | CODE: |
|
|
1779 | RETVAL = object::first; |
|
|
1780 | OUTPUT: RETVAL |
|
|
1781 | |
|
|
1782 | INCLUDE: $PERL genacc object ../include/object.h | |
|
|
1783 | |
|
|
1784 | # missing properties |
|
|
1785 | |
|
|
1786 | int flag (object *op, int flag, int value = 1) |
|
|
1787 | PROTOTYPE: $$;$ |
|
|
1788 | CODE: |
|
|
1789 | RETVAL = QUERY_FLAG (op, flag); |
|
|
1790 | if (items >= 3) |
|
|
1791 | if (value) |
|
|
1792 | SET_FLAG (op, flag); |
|
|
1793 | else |
|
|
1794 | CLEAR_FLAG (op, flag); |
|
|
1795 | OUTPUT: RETVAL |
|
|
1796 | |
1689 | object *head (object *op) |
1797 | object *head (object *op) |
1690 | PROTOTYPE: $ |
1798 | PROTOTYPE: $ |
1691 | ALIAS: |
|
|
1692 | more = 1 |
|
|
1693 | above = 2 |
|
|
1694 | below = 3 |
|
|
1695 | CODE: |
1799 | CODE: |
1696 | switch (ix) |
|
|
1697 | { |
|
|
1698 | case 0: RETVAL = op->head ? op->head : op; break; // DOH! |
1800 | 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 |
1801 | OUTPUT: RETVAL |
1705 | |
1802 | |
1706 | SV * |
1803 | int is_head (object *op) |
1707 | get_property (object *obj, int type, int idx) |
1804 | PROTOTYPE: $ |
1708 | CODE: |
1805 | 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; |
1806 | RETVAL = !op->head; |
1769 | OUTPUT: RETVAL |
1807 | OUTPUT: RETVAL |
1770 | |
1808 | |
1771 | void |
1809 | void |
1772 | inv (object *obj) |
1810 | inv (object *obj) |
1773 | PROTOTYPE: $ |
1811 | PROTOTYPE: $ |
1774 | PPCODE: |
1812 | PPCODE: |
… | |
… | |
1776 | object *o; |
1814 | object *o; |
1777 | for (o = obj->inv; o; o = o->below) |
1815 | for (o = obj->inv; o; o = o->below) |
1778 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1816 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
1779 | } |
1817 | } |
1780 | |
1818 | |
|
|
1819 | object *find_best_object_match (object *op, const char *match) |
|
|
1820 | |
|
|
1821 | object *find_marked_object (object *op) |
|
|
1822 | |
1781 | int cf_object_get_resistance (object *op, int rtype) |
1823 | int cf_object_get_resistance (object *op, int rtype) |
1782 | ALIAS: resistance = 0 |
1824 | ALIAS: resistance = 0 |
1783 | |
|
|
1784 | int cf_object_get_flag (object *op, int flag) |
|
|
1785 | ALIAS: flag = 0 |
|
|
1786 | |
|
|
1787 | void cf_object_set_flag (object *op, int flag, int value) |
|
|
1788 | |
1825 | |
1789 | int need_identify (const object *obj); |
1826 | int need_identify (const object *obj); |
1790 | |
1827 | |
1791 | int apply_shop_mat (object *shop_mat, object *op); |
1828 | int apply_shop_mat (object *shop_mat, object *op); |
1792 | |
1829 | |
… | |
… | |
1845 | void cf_object_drop (object *op, object *author) |
1882 | void cf_object_drop (object *op, object *author) |
1846 | |
1883 | |
1847 | void cf_object_take (object *op, object *author) |
1884 | void cf_object_take (object *op, object *author) |
1848 | |
1885 | |
1849 | object *cf_object_insert_object (object *op, object *container) |
1886 | object *cf_object_insert_object (object *op, object *container) |
1850 | |
|
|
1851 | const char *cf_object_get_msg (object *ob) |
|
|
1852 | ALIAS: msg = 0 |
|
|
1853 | |
1887 | |
1854 | object *cf_object_insert_in_ob (object *ob, object *where) |
1888 | object *cf_object_insert_in_ob (object *ob, object *where) |
1855 | |
1889 | |
1856 | int cf_object_teleport (object *op, mapstruct *map, int x, int y) |
1890 | int cf_object_teleport (object *op, mapstruct *map, int x, int y) |
1857 | |
1891 | |
… | |
… | |
1947 | bool on_same_map_as (object *ob, object *other) |
1981 | bool on_same_map_as (object *ob, object *other) |
1948 | CODE: |
1982 | CODE: |
1949 | RETVAL = on_same_map (ob, other); |
1983 | RETVAL = on_same_map (ob, other); |
1950 | OUTPUT: RETVAL |
1984 | OUTPUT: RETVAL |
1951 | |
1985 | |
1952 | char * |
1986 | const char * |
1953 | base_name (object *ob, int plural) |
1987 | base_name (object *op, int plural = op->nrof > 1) |
1954 | CODE: |
1988 | CODE: |
1955 | RETVAL = cf_query_base_name (ob, plural); |
1989 | RETVAL = query_base_name (op, plural); |
1956 | OUTPUT: RETVAL |
1990 | OUTPUT: RETVAL |
1957 | |
|
|
1958 | living * |
|
|
1959 | stats (object *ob) |
|
|
1960 | CODE: |
|
|
1961 | RETVAL = &ob->stats; |
|
|
1962 | OUTPUT: RETVAL |
|
|
1963 | |
|
|
1964 | |
1991 | |
1965 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1992 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1966 | |
1993 | |
1967 | player *player (object *op) |
1994 | player *player (object *op) |
1968 | CODE: |
1995 | CODE: |
… | |
… | |
1985 | ALIAS: party = 0 |
2012 | ALIAS: party = 0 |
1986 | |
2013 | |
1987 | void cf_player_set_party (object *op, partylist *party) |
2014 | void cf_player_set_party (object *op, partylist *party) |
1988 | |
2015 | |
1989 | void kill_player (object *op) |
2016 | void kill_player (object *op) |
|
|
2017 | |
|
|
2018 | void esrv_update_item (object *op, int what, object *item) |
|
|
2019 | C_ARGS: what, op, item |
1990 | |
2020 | |
1991 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2021 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1992 | |
2022 | |
1993 | int invoke (player *pl, int event, ...) |
2023 | int invoke (player *pl, int event, ...) |
1994 | CODE: |
2024 | CODE: |
… | |
… | |
2080 | if (new_value >= 0) |
2110 | if (new_value >= 0) |
2081 | pl->listening = new_value; |
2111 | pl->listening = new_value; |
2082 | OUTPUT: |
2112 | OUTPUT: |
2083 | RETVAL |
2113 | RETVAL |
2084 | |
2114 | |
2085 | void get_savebed (player *pl) |
2115 | void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) |
2086 | ALIAS: |
2116 | PROTOTYPE: $;$$$ |
2087 | savebed = 0 |
|
|
2088 | PPCODE: |
2117 | PPCODE: |
|
|
2118 | if (GIMME_V != G_VOID) |
|
|
2119 | { |
2089 | EXTEND (SP, 3); |
2120 | EXTEND (SP, 3); |
2090 | PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
2121 | PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
2091 | PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
2122 | PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
2092 | PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
2123 | PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
2093 | |
2124 | } |
2094 | void set_savebed (player *pl, char *map_path, int x, int y) |
2125 | if (map_path) sv_to (map_path, pl->savebed_map); |
2095 | CODE: |
2126 | if (x) sv_to (x, pl->bed_x); |
2096 | strcpy (pl->savebed_map, map_path); |
2127 | if (y) sv_to (y, pl->bed_y); |
2097 | pl->bed_x = x; |
|
|
2098 | pl->bed_y = y; |
|
|
2099 | |
2128 | |
2100 | void |
2129 | void |
2101 | list () |
2130 | list () |
2102 | PPCODE: |
2131 | PPCODE: |
2103 | { |
2132 | { |
… | |
… | |
2135 | PROTOTYPE: |
2164 | PROTOTYPE: |
2136 | CODE: |
2165 | CODE: |
2137 | RETVAL = first_map; |
2166 | RETVAL = first_map; |
2138 | OUTPUT: RETVAL |
2167 | OUTPUT: RETVAL |
2139 | |
2168 | |
2140 | mapstruct *next (mapstruct *map) |
|
|
2141 | PROTOTYPE: |
|
|
2142 | CODE: |
|
|
2143 | RETVAL = map->next; |
|
|
2144 | OUTPUT: RETVAL |
|
|
2145 | |
|
|
2146 | int invoke (mapstruct *map, int event, ...) |
2169 | int invoke (mapstruct *map, int event, ...) |
2147 | CODE: |
2170 | CODE: |
2148 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2171 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2149 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2172 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2150 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2173 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
… | |
… | |
2155 | CODE: |
2178 | CODE: |
2156 | RETVAL = registry_of (map); |
2179 | RETVAL = registry_of (map); |
2157 | OUTPUT: |
2180 | OUTPUT: |
2158 | RETVAL |
2181 | RETVAL |
2159 | |
2182 | |
2160 | SV * |
2183 | INCLUDE: $PERL genacc mapstruct ../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 | |
|
|
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 | |
2184 | |
2178 | mapstruct *new (int width, int height) |
2185 | mapstruct *new (int width, int height) |
2179 | PROTOTYPE: |
2186 | PROTOTYPE: |
2180 | CODE: |
2187 | CODE: |
2181 | { |
2188 | { |
… | |
… | |
2211 | get_map = 1 |
2218 | get_map = 1 |
2212 | |
2219 | |
2213 | mapstruct *has_been_loaded (char *name) |
2220 | mapstruct *has_been_loaded (char *name) |
2214 | PROTOTYPE: $ |
2221 | PROTOTYPE: $ |
2215 | |
2222 | |
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) |
2223 | int in_memory (mapstruct *map) |
2224 | CODE: |
2224 | CODE: |
2225 | RETVAL = map->in_memory; |
2225 | RETVAL = map->in_memory; |
2226 | OUTPUT: |
2226 | OUTPUT: |
2227 | RETVAL |
2227 | RETVAL |
2228 | |
|
|
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 | |
2228 | |
2239 | void |
2229 | void |
2240 | trigger (mapstruct *map, long connection, bool state = true) |
2230 | trigger (mapstruct *map, long connection, bool state = true) |
2241 | CODE: |
2231 | CODE: |
2242 | activate_connection (map, connection, state); |
2232 | activate_connection (map, connection, state); |
… | |
… | |
2320 | RETVAL |
2310 | RETVAL |
2321 | |
2311 | |
2322 | |
2312 | |
2323 | MODULE = cf PACKAGE = cf::arch |
2313 | MODULE = cf PACKAGE = cf::arch |
2324 | |
2314 | |
|
|
2315 | archetype *find (const char *name) |
|
|
2316 | CODE: |
|
|
2317 | RETVAL = find_archetype (name); |
|
|
2318 | OUTPUT: |
|
|
2319 | RETVAL |
|
|
2320 | |
2325 | archetype *first() |
2321 | archetype *first() |
2326 | PROTOTYPE: |
2322 | PROTOTYPE: |
2327 | CODE: |
2323 | CODE: |
2328 | RETVAL = first_archetype; |
2324 | RETVAL = first_archetype; |
2329 | OUTPUT: RETVAL |
2325 | OUTPUT: RETVAL |
2330 | |
2326 | |
2331 | archetype *next (archetype *arch) |
2327 | 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 | |
2328 | |
2356 | MODULE = cf PACKAGE = cf::party |
2329 | MODULE = cf PACKAGE = cf::party |
2357 | |
2330 | |
2358 | partylist *first () |
2331 | partylist *first () |
2359 | PROTOTYPE: |
2332 | PROTOTYPE: |
… | |
… | |
2409 | RETVAL = reg->msg; |
2382 | RETVAL = reg->msg; |
2410 | OUTPUT: RETVAL |
2383 | OUTPUT: RETVAL |
2411 | |
2384 | |
2412 | MODULE = cf PACKAGE = cf::living |
2385 | MODULE = cf PACKAGE = cf::living |
2413 | |
2386 | |
2414 | val64 |
2387 | INCLUDE: $PERL genacc living ../include/living.h | |
2415 | exp (living *liv, val64 new_val = 0) |
|
|
2416 | PROTOTYPE: $;$ |
|
|
2417 | ALIAS: |
|
|
2418 | Str = 1 |
|
|
2419 | Dex = 2 |
|
|
2420 | Con = 3 |
|
|
2421 | Wis = 4 |
|
|
2422 | Cha = 5 |
|
|
2423 | Int = 6 |
|
|
2424 | Pow = 7 |
|
|
2425 | wc = 8 |
|
|
2426 | ac = 9 |
|
|
2427 | hp = 10 |
|
|
2428 | maxhp = 11 |
|
|
2429 | sp = 12 |
|
|
2430 | maxsp = 13 |
|
|
2431 | grace = 14 |
|
|
2432 | maxgrace = 15 |
|
|
2433 | food = 16 |
|
|
2434 | dam = 17 |
|
|
2435 | luck = 18 |
|
|
2436 | CODE: |
|
|
2437 | # define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = (sint64)new_val; break |
|
|
2438 | switch (ix) |
|
|
2439 | { |
|
|
2440 | LIVING_ACC (exp , 0); |
|
|
2441 | LIVING_ACC (Str , 1); |
|
|
2442 | LIVING_ACC (Dex , 2); |
|
|
2443 | LIVING_ACC (Con , 3); |
|
|
2444 | LIVING_ACC (Wis , 4); |
|
|
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: |
|
|
2462 | RETVAL |
|
|
2463 | |
2388 | |