… | |
… | |
21 | * You should have received a copy of the GNU General Public License |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | */ |
24 | */ |
25 | |
25 | |
26 | #include <EXTERN.h> |
|
|
27 | #include <perl.h> |
|
|
28 | #include <XSUB.h> |
|
|
29 | |
|
|
30 | #undef save_long // clashes with libproto.h |
|
|
31 | |
|
|
32 | #define PLUGIN_NAME "perl" |
26 | #define PLUGIN_NAME "perl" |
33 | #define PLUGIN_VERSION "cfperl 0.5" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
34 | |
|
|
35 | #ifndef __CEXTRACT__ |
|
|
36 | #include <plugin.h> |
|
|
37 | #endif |
|
|
38 | |
|
|
39 | #undef MODULEAPI |
|
|
40 | #ifdef WIN32 |
|
|
41 | #else |
|
|
42 | #define MODULEAPI |
|
|
43 | #endif |
|
|
44 | |
28 | |
45 | #include <plugin_common.h> |
29 | #include <plugin_common.h> |
46 | #include <sounds.h> |
30 | #include <sounds.h> |
47 | #include <cstdarg> |
31 | #include <cstdarg> |
48 | #include <sproto.h> |
32 | #include <sproto.h> |
49 | |
33 | |
50 | #include "cfperl.h" |
34 | #include "cfperl.h" |
51 | #include "shstr.h" |
35 | #include "shstr.h" |
52 | |
36 | |
|
|
37 | #include <EXTERN.h> |
|
|
38 | #include <perl.h> |
|
|
39 | #include <XSUB.h> |
|
|
40 | |
53 | #include "perlxsi.c" |
41 | #include "perlxsi.c" |
54 | |
42 | |
55 | extern sint64 *levels; // the experience table |
43 | extern sint64 *levels; // the experience table |
56 | |
44 | |
57 | typedef object object_ornull; |
45 | typedef object object_ornull; |
… | |
… | |
59 | |
47 | |
60 | typedef double val64; |
48 | typedef double val64; |
61 | #define newSVval64 newSVnv |
49 | #define newSVval64 newSVnv |
62 | #define SvVAL64 SvNV |
50 | #define SvVAL64 SvNV |
63 | |
51 | |
64 | static f_plug_api gethook; |
52 | static f_plug_api gethook = cfapi_get_hooks; |
65 | static f_plug_api systemDirectory; |
53 | static f_plug_api object_set_property = cfapi_object_set_property; |
66 | static f_plug_api object_set_property; |
54 | static f_plug_api object_insert = cfapi_object_insert; |
67 | static f_plug_api map_get_map; |
|
|
68 | static f_plug_api object_insert; |
|
|
69 | |
55 | |
70 | /* this is a stupid way to do things, and awkward to use for plug-in authors */ |
56 | /* this is a stupid way to do things, and awkward to use for plug-in authors */ |
71 | typedef struct |
57 | typedef struct |
72 | { |
58 | { |
73 | object* who; |
59 | object* who; |
… | |
… | |
108 | |
94 | |
109 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
95 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
110 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
96 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
111 | } |
97 | } |
112 | |
98 | |
113 | template<class extendable> |
99 | template<class attachable> |
114 | SV * |
100 | SV * |
115 | newSVextendable (extendable *obj, const char *klass) |
101 | newSVattachable (attachable *obj, const char *klass) |
116 | { |
102 | { |
117 | if (!obj) |
103 | if (!obj) |
118 | return &PL_sv_undef; |
104 | return &PL_sv_undef; |
119 | |
105 | |
120 | if (!obj->self) |
106 | if (!obj->self) |
121 | obj->self = newSVptr (obj, klass); |
107 | obj->self = newSVptr (obj, klass); |
122 | |
108 | |
123 | return newSVsv (static_cast<SV *>(obj->self)); |
109 | return newSVsv (obj->self); |
124 | } |
110 | } |
125 | |
111 | |
126 | static void |
112 | static void |
127 | SVptr_cache_set (void *ptr, SV *sv) |
113 | SVptr_cache_set (void *ptr, SV *sv) |
128 | { |
114 | { |
… | |
… | |
227 | break; |
213 | break; |
228 | |
214 | |
229 | case DT_OBJECT: |
215 | case DT_OBJECT: |
230 | { |
216 | { |
231 | object *obj = va_arg (ap, object *); |
217 | object *obj = va_arg (ap, object *); |
232 | sv = newSVextendable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
218 | sv = newSVattachable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); |
233 | } |
219 | } |
234 | break; |
220 | break; |
235 | |
221 | |
236 | case DT_MAP: |
222 | case DT_MAP: |
237 | // va_arg (object *) when void * is passed is an XSI extension |
223 | // va_arg (object *) when void * is passed is an XSI extension |
238 | sv = newSVextendable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
224 | sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap"); |
239 | break; |
225 | break; |
240 | |
226 | |
241 | case DT_PLAYER: |
227 | case DT_PLAYER: |
242 | sv = newSVextendable (va_arg (ap, player *), "cf::player::wrap"); |
228 | sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap"); |
243 | break; |
229 | break; |
244 | |
230 | |
245 | case DT_ARCH: |
231 | case DT_ARCH: |
246 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
232 | sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); |
247 | break; |
233 | break; |
… | |
… | |
304 | } |
290 | } |
305 | |
291 | |
306 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
292 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
307 | |
293 | |
308 | SV * |
294 | SV * |
309 | registry_of (extendable_base *ext) |
295 | registry_of (attachable_base *ext) |
310 | { |
296 | { |
311 | if (!ext->cb) |
297 | if (!ext->cb) |
312 | ext->cb = newAV (); |
298 | ext->cb = newAV (); |
313 | |
299 | |
314 | return newRV_inc ((SV *)ext->cb); |
300 | return newRV_inc ((SV *)ext->cb); |
315 | } |
301 | } |
316 | |
302 | |
317 | void extendable_base::clear () |
303 | void attachable_base::clear () |
318 | { |
304 | { |
319 | //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D |
305 | if (self) |
|
|
306 | { |
|
|
307 | if (cb) |
|
|
308 | if (SvROK (*av_fetch (cb, EVENT_OBJECT_DESTROY, 1))) |
|
|
309 | INVOKE_OBJECT (DESTROY, static_cast<object *>(this)); |
|
|
310 | else if (SvROK (*av_fetch (cb, EVENT_MAP_DESTROY, 1))) |
|
|
311 | INVOKE_MAP (DESTROY, static_cast<mapstruct *>(this)); |
320 | |
312 | |
|
|
313 | // disconnect Perl from C, to avoid crashes |
|
|
314 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
|
|
315 | |
|
|
316 | // clear the perl hash, might or might not be a good idea |
|
|
317 | hv_clear ((HV *)SvRV ((SV *)self)); |
|
|
318 | |
321 | if (self) SvREFCNT_dec (self); |
319 | SvREFCNT_dec (self); |
|
|
320 | self = 0; |
|
|
321 | } |
|
|
322 | |
|
|
323 | if (cb) |
|
|
324 | { |
322 | if (cb) SvREFCNT_dec (cb); |
325 | SvREFCNT_dec (cb); |
|
|
326 | cb = 0; |
|
|
327 | } |
323 | |
328 | |
324 | if (attach) free_string (attach); |
|
|
325 | |
|
|
326 | self = 0; |
|
|
327 | cb = 0; |
|
|
328 | attach = 0; |
329 | attach = 0; |
329 | } |
330 | } |
330 | |
331 | |
331 | void extendable_base::optimise () |
332 | void attachable_base::optimise () |
332 | { |
333 | { |
333 | if (!self) |
334 | if (!self) |
334 | return; |
335 | return; |
335 | |
336 | |
336 | HV *hv = (HV *)SvRV ((SV *)self); |
337 | HV *hv = (HV *)SvRV ((SV *)self); |
… | |
… | |
342 | SvREFCNT_dec ((SV *)self); |
343 | SvREFCNT_dec ((SV *)self); |
343 | self = 0; |
344 | self = 0; |
344 | } |
345 | } |
345 | } |
346 | } |
346 | |
347 | |
347 | void |
348 | void attachable_base::instantiate (data_type type, void *obj) |
348 | object::instantiate_ () |
|
|
349 | { |
349 | { |
350 | dSP; |
350 | dSP; |
351 | ENTER; |
351 | ENTER; |
352 | SAVETMPS; |
352 | SAVETMPS; |
353 | PUSHMARK (SP); |
353 | PUSHMARK (SP); |
354 | EXTEND (SP, 2); |
354 | EXTEND (SP, 2); |
355 | PUSHs (sv_2mortal (newSVdt (DT_OBJECT, static_cast<object *>(this)))); |
355 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
356 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
356 | PUSHs (sv_2mortal (newSVpv (attach, 0))); |
|
|
357 | |
|
|
358 | attach = 0; |
|
|
359 | |
357 | PUTBACK; |
360 | PUTBACK; |
358 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
361 | call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); |
359 | FREETMPS; |
362 | FREETMPS; |
360 | LEAVE; |
363 | LEAVE; |
|
|
364 | |
|
|
365 | switch (type) |
|
|
366 | { |
|
|
367 | case DT_OBJECT: INVOKE_OBJECT (INSTANTIATE, obj); break; |
|
|
368 | case DT_MAP: INVOKE_MAP (INSTANTIATE, obj); break; |
|
|
369 | } |
361 | } |
370 | } |
362 | |
371 | |
363 | ///////////////////////////////////////////////////////////////////////////// |
372 | ///////////////////////////////////////////////////////////////////////////// |
364 | |
373 | |
365 | object_freezer::object_freezer (const char *filename) |
|
|
366 | : filename (filename) |
|
|
367 | { |
|
|
368 | av = (AV *)newAV (); |
|
|
369 | idx = 0; |
|
|
370 | av_extend ((AV *)av, 1024); |
|
|
371 | } |
|
|
372 | |
|
|
373 | object_freezer::~object_freezer () |
|
|
374 | { |
|
|
375 | dSP; |
|
|
376 | ENTER; |
|
|
377 | SAVETMPS; |
|
|
378 | PUSHMARK (SP); |
|
|
379 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
|
|
380 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
381 | PUTBACK; |
|
|
382 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
|
|
383 | FREETMPS; |
|
|
384 | LEAVE; |
|
|
385 | } |
|
|
386 | |
|
|
387 | void object_freezer::put (extendable_base *ext) |
|
|
388 | { |
|
|
389 | ext->optimise (); |
|
|
390 | |
|
|
391 | if (ext->self) |
|
|
392 | av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); |
|
|
393 | |
|
|
394 | ++idx; |
|
|
395 | } |
|
|
396 | |
|
|
397 | object_thawer::object_thawer (const char *filename) |
|
|
398 | { |
|
|
399 | av = 0; |
|
|
400 | idx = 0; |
|
|
401 | |
|
|
402 | if (!filename) |
|
|
403 | return; |
|
|
404 | |
|
|
405 | dSP; |
|
|
406 | ENTER; |
|
|
407 | SAVETMPS; |
|
|
408 | PUSHMARK (SP); |
|
|
409 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
|
|
410 | PUTBACK; |
|
|
411 | |
|
|
412 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
|
|
413 | { |
|
|
414 | SPAGAIN; |
|
|
415 | SV *sv = POPs; |
|
|
416 | if (SvROK (sv)) |
|
|
417 | av = SvREFCNT_inc (SvRV (sv)); |
|
|
418 | } |
|
|
419 | |
|
|
420 | FREETMPS; |
|
|
421 | LEAVE; |
|
|
422 | } |
|
|
423 | |
|
|
424 | void reattach (data_type type, void *obj) |
374 | void reattach (data_type type, void *obj) |
425 | { |
375 | { |
|
|
376 | //TODO only do this when the object has _attachment's |
|
|
377 | |
426 | dSP; |
378 | dSP; |
427 | ENTER; |
379 | ENTER; |
428 | SAVETMPS; |
380 | SAVETMPS; |
429 | PUSHMARK (SP); |
381 | PUSHMARK (SP); |
430 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
382 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
… | |
… | |
440 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
392 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
441 | } |
393 | } |
442 | } |
394 | } |
443 | |
395 | |
444 | template<class subclass> |
396 | template<class subclass> |
445 | void reattach (extendable<subclass> *obj) |
397 | void reattach (attachable<subclass> *obj) |
446 | { |
398 | { |
447 | obj->optimise (); |
399 | obj->optimise (); |
448 | |
400 | |
449 | if (obj->self) |
401 | if (obj->self) |
450 | reattach (subclass::get_dt (), (subclass *)obj); |
402 | reattach ((data_type) cftype<subclass>::dt, (subclass *)obj); |
451 | } |
403 | } |
452 | |
404 | |
|
|
405 | #include "kw_hash.h" |
|
|
406 | |
|
|
407 | object_freezer::object_freezer () |
|
|
408 | : dynbuf (128 * 1024, 64 * 1024) |
|
|
409 | { |
|
|
410 | av = newAV (); |
|
|
411 | } |
|
|
412 | |
|
|
413 | object_freezer::~object_freezer () |
|
|
414 | { |
|
|
415 | SvREFCNT_dec (av); |
|
|
416 | } |
|
|
417 | |
|
|
418 | void object_freezer::put (attachable_base *ext) |
|
|
419 | { |
|
|
420 | ext->optimise (); |
|
|
421 | |
|
|
422 | if (ext->self) |
|
|
423 | { |
|
|
424 | int idx = AvFILLp ((AV *)av) + 1; |
|
|
425 | av_store (av, idx, SvREFCNT_inc (ext->self)); |
|
|
426 | |
|
|
427 | add ((void *)"oid ", 4); |
|
|
428 | add ((sint32)idx); |
|
|
429 | add ('\n'); |
|
|
430 | } |
|
|
431 | } |
|
|
432 | |
|
|
433 | bool object_freezer::save (const char *filename) |
|
|
434 | { |
|
|
435 | dSP; |
|
|
436 | ENTER; |
|
|
437 | SAVETMPS; |
|
|
438 | PUSHMARK (SP); |
|
|
439 | EXTEND (SP, 3); |
|
|
440 | PUSHs (sv_2mortal (newSVpv (filename, 0))); |
|
|
441 | PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); |
|
|
442 | PUSHs (sv_2mortal (newRV_inc ((SV *)av))); |
|
|
443 | PUTBACK; |
|
|
444 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
|
|
445 | FREETMPS; |
|
|
446 | LEAVE; |
|
|
447 | } |
|
|
448 | |
|
|
449 | int fprintf (object_freezer &freezer, const char *format, ...) |
|
|
450 | { |
|
|
451 | va_list ap; |
|
|
452 | |
|
|
453 | va_start (ap, format); |
|
|
454 | |
|
|
455 | int len = vsnprintf ((char *)freezer.force (1024), 1024, format, ap); |
|
|
456 | |
|
|
457 | if (len >= 0) |
|
|
458 | freezer.alloc (len); |
|
|
459 | |
|
|
460 | va_end (ap); |
|
|
461 | } |
|
|
462 | |
|
|
463 | int fputs (const char *s, object_freezer &freezer) |
|
|
464 | { |
|
|
465 | freezer.add (s); |
|
|
466 | } |
|
|
467 | |
|
|
468 | object_thawer::object_thawer (const char *filename) |
|
|
469 | { |
|
|
470 | static const char eof[] = "\n\n\n\0\0\0"; |
|
|
471 | |
|
|
472 | av = 0; |
|
|
473 | text = 0; |
|
|
474 | line = 0; |
|
|
475 | |
|
|
476 | if (filename) |
|
|
477 | { |
|
|
478 | dSP; |
|
|
479 | ENTER; |
|
|
480 | SAVETMPS; |
|
|
481 | PUSHMARK (SP); |
|
|
482 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
|
|
483 | PUTBACK; |
|
|
484 | |
|
|
485 | if (2 == call_pv ("cf::object_thawer_load", G_ARRAY | G_EVAL)) |
|
|
486 | { |
|
|
487 | SPAGAIN; |
|
|
488 | |
|
|
489 | // second value - perl objects |
|
|
490 | { |
|
|
491 | SV *sv = POPs; |
|
|
492 | if (SvROK (sv)) |
|
|
493 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
|
|
494 | } |
|
|
495 | |
|
|
496 | // first value - text part, pad with 3 zeroes |
|
|
497 | { |
|
|
498 | SV *sv = POPs; |
|
|
499 | STRLEN len; |
|
|
500 | char *sv_ = SvPVbyte (sv, len); |
|
|
501 | text = newSV (len + sizeof (eof)); |
|
|
502 | SvCUR_set (text, len); |
|
|
503 | memcpy (SvPVX (text), sv_, len); |
|
|
504 | memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure |
|
|
505 | |
|
|
506 | line = SvPVX (text); |
|
|
507 | } |
|
|
508 | } |
|
|
509 | |
|
|
510 | PUTBACK; |
|
|
511 | FREETMPS; |
|
|
512 | LEAVE; |
|
|
513 | } |
|
|
514 | } |
|
|
515 | |
453 | void object_thawer::get (data_type type, void *obj, extendable_base *ext) |
516 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
454 | { |
517 | { |
455 | if (!av) |
518 | if (!av || oid < 0) // this is actually an error of sorts |
456 | return; |
519 | return; |
457 | |
520 | |
458 | // we have to "re-instantiate"/reattach to an object, so nuke ext->attach |
521 | // we have to "re-instantiate"/reattach to an object, so nuke ext->attach |
459 | ext->clear (); |
522 | ext->clear (); |
460 | |
523 | |
461 | SV **svp = av_fetch ((AV *)av, idx, 0); |
524 | SV **svp = av_fetch ((AV *)av, oid, 0); |
462 | |
525 | |
463 | ++idx; |
|
|
464 | |
|
|
465 | if (!svp) |
|
|
466 | return; |
|
|
467 | |
|
|
468 | if (SvROK (*svp)) |
526 | if (!svp || !SvROK (*svp)) |
469 | { |
527 | { |
470 | ext->self = SvREFCNT_inc (*svp); |
528 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
471 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
529 | return; |
472 | |
|
|
473 | reattach (type, obj); |
|
|
474 | } |
530 | } |
|
|
531 | |
|
|
532 | ext->self = *svp; *svp = &PL_sv_undef; |
|
|
533 | sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
|
|
534 | |
|
|
535 | reattach (type, obj); |
475 | } |
536 | } |
476 | |
537 | |
477 | object_thawer::~object_thawer () |
538 | object_thawer::~object_thawer () |
478 | { |
539 | { |
|
|
540 | if (text) SvREFCNT_dec (text); |
|
|
541 | if (av) SvREFCNT_dec (av); |
|
|
542 | } |
|
|
543 | |
|
|
544 | char *fgets (char *s, int n, object_thawer &thawer) |
|
|
545 | { |
|
|
546 | char *p = thawer.line; |
|
|
547 | char *q = s; |
|
|
548 | |
479 | if (av) |
549 | if (!p) |
480 | SvREFCNT_dec ((SV *)av); |
550 | return 0; |
|
|
551 | |
|
|
552 | while (--n) |
|
|
553 | { |
|
|
554 | if (!*p) |
|
|
555 | break; |
|
|
556 | |
|
|
557 | *q++ = *p; |
|
|
558 | |
|
|
559 | if (*p++ == '\n') |
|
|
560 | break; |
|
|
561 | } |
|
|
562 | |
|
|
563 | *q = 0; |
|
|
564 | thawer.line = p; |
|
|
565 | |
|
|
566 | return s == q ? 0 : s; |
|
|
567 | } |
|
|
568 | |
|
|
569 | keyword object_thawer::get_kv () |
|
|
570 | { |
|
|
571 | if (!line) |
|
|
572 | return KW_EOF; |
|
|
573 | |
|
|
574 | for (;;) |
|
|
575 | { |
|
|
576 | char *p = line; |
|
|
577 | |
|
|
578 | if (!*p) |
|
|
579 | return KW_EOF; |
|
|
580 | |
|
|
581 | // parse keyword |
|
|
582 | while (*p > ' ') |
|
|
583 | p++; |
|
|
584 | |
|
|
585 | int klen = p - line; |
|
|
586 | |
|
|
587 | if (*p++ != '\n') |
|
|
588 | { |
|
|
589 | // parse value |
|
|
590 | while (*p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 |
|
|
591 | ++p; |
|
|
592 | |
|
|
593 | last_value = p; |
|
|
594 | |
|
|
595 | while (*p != '\n') |
|
|
596 | p++; |
|
|
597 | |
|
|
598 | *p++ = 0; |
|
|
599 | } |
|
|
600 | else |
|
|
601 | last_value = 0; |
|
|
602 | |
|
|
603 | line [klen] = 0; |
|
|
604 | keyword_idx *kw = kw_lex::match (line, klen); |
|
|
605 | |
|
|
606 | //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D |
|
|
607 | |
|
|
608 | if (kw) |
|
|
609 | { |
|
|
610 | line = p; |
|
|
611 | return kw->index; |
|
|
612 | } |
|
|
613 | else if (!*line || *line == '#') |
|
|
614 | { |
|
|
615 | // empty/comment line |
|
|
616 | line = p; |
|
|
617 | } |
|
|
618 | else |
|
|
619 | return KW_ERROR; |
|
|
620 | } |
|
|
621 | } |
|
|
622 | |
|
|
623 | void object_thawer::get (shstr &sh) const |
|
|
624 | { |
|
|
625 | if (last_value) |
|
|
626 | sh = last_value; |
|
|
627 | else |
|
|
628 | { |
|
|
629 | sh = "<value missing>"; |
|
|
630 | LOG (llevError, "keyword requires value: <%s>\n", line);//TODO: add filename |
|
|
631 | } |
|
|
632 | } |
|
|
633 | |
|
|
634 | void object_thawer::get_ml (keyword kend, shstr &sh) |
|
|
635 | { |
|
|
636 | char kw[128]; |
|
|
637 | |
|
|
638 | // multi-line strings are delimited by "\nendXXX\n" |
|
|
639 | kw [0] = '\n'; |
|
|
640 | strcpy (kw + 1, keyword_str [kend]); |
|
|
641 | |
|
|
642 | char *end = strstr (line, kw); |
|
|
643 | |
|
|
644 | if (!end) |
|
|
645 | { |
|
|
646 | sh = 0; |
|
|
647 | return; |
|
|
648 | } |
|
|
649 | |
|
|
650 | *end = 0; |
|
|
651 | sh = line; |
|
|
652 | |
|
|
653 | line = end + keyword_len [kend] + 1; |
|
|
654 | |
|
|
655 | while (*line++ != '\n') |
|
|
656 | ; |
|
|
657 | } |
|
|
658 | |
|
|
659 | sint32 object_thawer::get_sint32 () const |
|
|
660 | { |
|
|
661 | char *p = last_value; |
|
|
662 | |
|
|
663 | if (!p) |
|
|
664 | return 0; |
|
|
665 | |
|
|
666 | sint32 val = 0; |
|
|
667 | bool negate; |
|
|
668 | |
|
|
669 | if (*p == '-') |
|
|
670 | { |
|
|
671 | negate = true; |
|
|
672 | ++p; |
|
|
673 | } |
|
|
674 | else |
|
|
675 | negate = false; |
|
|
676 | |
|
|
677 | do |
|
|
678 | { |
|
|
679 | val *= 10; |
|
|
680 | val += *p++ - '0'; |
|
|
681 | } |
|
|
682 | while (*p); |
|
|
683 | |
|
|
684 | return negate ? -val : val; |
|
|
685 | } |
|
|
686 | |
|
|
687 | sint64 object_thawer::get_sint64 () const |
|
|
688 | { |
|
|
689 | return last_value ? atoll (last_value) : 0; |
|
|
690 | } |
|
|
691 | |
|
|
692 | double object_thawer::get_double () const |
|
|
693 | { |
|
|
694 | return last_value ? atof (last_value) : 0; |
481 | } |
695 | } |
482 | |
696 | |
483 | ///////////////////////////////////////////////////////////////////////////// |
697 | ///////////////////////////////////////////////////////////////////////////// |
484 | |
698 | |
485 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
699 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
486 | { |
700 | { |
487 | gethook = gethooksptr; |
|
|
488 | printf (PLUGIN_VERSION " init\n"); |
|
|
489 | |
|
|
490 | return 0; |
701 | return 0; |
491 | } |
702 | } |
492 | |
703 | |
493 | static CommArray_s rtn_cmd; |
704 | static CommArray_s rtn_cmd; |
494 | |
705 | |
… | |
… | |
574 | extern "C" int cfperl_postInitPlugin () |
785 | extern "C" int cfperl_postInitPlugin () |
575 | { |
786 | { |
576 | int hooktype = 1; |
787 | int hooktype = 1; |
577 | int rtype = 0; |
788 | int rtype = 0; |
578 | |
789 | |
579 | printf (PLUGIN_VERSION " post init\n"); |
|
|
580 | |
|
|
581 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
|
|
582 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
|
|
583 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
|
|
584 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
|
|
585 | |
|
|
586 | cf_init_plugin (gethook); |
790 | cf_init_plugin (gethook); |
587 | |
791 | |
588 | return 0; |
792 | return 0; |
589 | } |
793 | } |
590 | |
794 | |
… | |
… | |
594 | } |
798 | } |
595 | |
799 | |
596 | void |
800 | void |
597 | cfperl_init () |
801 | cfperl_init () |
598 | { |
802 | { |
|
|
803 | PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); |
|
|
804 | perl = perl_alloc (); |
|
|
805 | perl_construct (perl); |
|
|
806 | |
|
|
807 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
808 | |
599 | char *argv[] = { |
809 | char *argv[] = { |
600 | "", |
810 | "", |
601 | "-e" |
811 | "-e" |
602 | "BEGIN {" |
|
|
603 | " cf->bootstrap;" |
812 | "cf->bootstrap;" |
604 | " unshift @INC, cf::datadir ();" |
813 | "unshift @INC, cf::datadir ();" |
605 | "}" |
|
|
606 | "" |
|
|
607 | "use cf;" |
814 | "require cf;" |
608 | }; |
815 | }; |
609 | |
|
|
610 | perl = perl_alloc (); |
|
|
611 | perl_construct (perl); |
|
|
612 | |
|
|
613 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
614 | |
816 | |
615 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
817 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
616 | { |
818 | { |
617 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
819 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
618 | |
|
|
619 | exit (EXIT_FAILURE); |
820 | exit (EXIT_FAILURE); |
620 | //perl_destruct (perl); |
|
|
621 | //perl_free (perl); |
|
|
622 | //perl = 0; |
|
|
623 | //return; |
|
|
624 | } |
821 | } |
625 | |
822 | |
626 | obj_cache = newHV (); |
823 | obj_cache = newHV (); |
627 | } |
824 | } |
628 | |
825 | |
… | |
… | |
638 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
835 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
639 | # define def(type,name) KLASS_ ## type, |
836 | # define def(type,name) KLASS_ ## type, |
640 | # include "eventinc.h" |
837 | # include "eventinc.h" |
641 | # undef def |
838 | # undef def |
642 | }; |
839 | }; |
|
|
840 | |
|
|
841 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
643 | |
842 | |
644 | static void |
843 | static void |
645 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
844 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
646 | { |
845 | { |
647 | // event must be in array |
846 | // event must be in array |
… | |
… | |
690 | // 2a. per-type callback |
889 | // 2a. per-type callback |
691 | // 4. global callbacks |
890 | // 4. global callbacks |
692 | |
891 | |
693 | gather_callbacks (callbacks, cb_global, event); |
892 | gather_callbacks (callbacks, cb_global, event); |
694 | |
893 | |
695 | switch (klass_of [event]) |
894 | switch (KLASS_OF (event)) |
696 | { |
895 | { |
697 | case KLASS_GLOBAL: |
896 | case KLASS_GLOBAL: |
698 | break; |
897 | break; |
699 | |
898 | |
700 | case KLASS_OBJECT: |
899 | case KLASS_OBJECT: |
701 | dt = (data_type) va_arg (ap, int); |
900 | dt = (data_type) va_arg (ap, int); |
702 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
901 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
703 | op = va_arg (ap, object *); |
902 | op = va_arg (ap, object *); |
704 | |
903 | |
705 | if (op->cb) |
904 | if (op->cb) |
706 | gather_callbacks (callbacks, (AV *)op->cb, event); |
905 | gather_callbacks (callbacks, op->cb, event); |
707 | |
906 | |
708 | if (op->type) |
907 | if (op->type) |
709 | { |
908 | { |
710 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
909 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
711 | { |
910 | { |
… | |
… | |
732 | dt = (data_type) va_arg (ap, int); |
931 | dt = (data_type) va_arg (ap, int); |
733 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
932 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
734 | pl = va_arg (ap, player *); |
933 | pl = va_arg (ap, player *); |
735 | |
934 | |
736 | if (pl->cb) |
935 | if (pl->cb) |
737 | gather_callbacks (callbacks, (AV *)pl->cb, event); |
936 | gather_callbacks (callbacks, pl->cb, event); |
738 | |
937 | |
739 | gather_callbacks (callbacks, cb_player, event); |
938 | gather_callbacks (callbacks, cb_player, event); |
740 | break; |
939 | break; |
741 | |
940 | |
742 | case KLASS_MAP: |
941 | case KLASS_MAP: |
743 | dt = (data_type) va_arg (ap, int); |
942 | dt = (data_type) va_arg (ap, int); |
744 | assert (("first argument must be of type object", dt == DT_MAP)); |
943 | assert (("first argument must be of type object", dt == DT_MAP)); |
745 | map = va_arg (ap, mapstruct *); |
944 | map = va_arg (ap, mapstruct *); |
746 | |
945 | |
747 | if (map->cb) |
946 | if (map->cb) |
748 | gather_callbacks (callbacks, (AV *)map->cb, event); |
947 | gather_callbacks (callbacks, map->cb, event); |
749 | |
948 | |
750 | gather_callbacks (callbacks, cb_map, event); |
949 | gather_callbacks (callbacks, cb_map, event); |
751 | break; |
950 | break; |
752 | |
951 | |
753 | default: |
952 | default: |
… | |
… | |
766 | EXTEND (SP, 3); |
965 | EXTEND (SP, 3); |
767 | |
966 | |
768 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
967 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
769 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
968 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
770 | |
969 | |
771 | switch (klass_of [event]) |
970 | switch (KLASS_OF (event)) |
772 | { |
971 | { |
773 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
972 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
774 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
973 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
775 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
974 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
776 | } |
975 | } |
… | |
… | |
1205 | |
1404 | |
1206 | const_iv (SK_EXP_ADD_SKILL) |
1405 | const_iv (SK_EXP_ADD_SKILL) |
1207 | const_iv (SK_EXP_TOTAL) |
1406 | const_iv (SK_EXP_TOTAL) |
1208 | const_iv (SK_EXP_NONE) |
1407 | const_iv (SK_EXP_NONE) |
1209 | const_iv (SK_SUBTRACT_SKILL_EXP) |
1408 | const_iv (SK_SUBTRACT_SKILL_EXP) |
|
|
1409 | const_iv (SK_EXP_SKILL_ONLY) |
1210 | |
1410 | |
1211 | const_iv (SK_LOCKPICKING) |
1411 | const_iv (SK_LOCKPICKING) |
1212 | const_iv (SK_HIDING) |
1412 | const_iv (SK_HIDING) |
1213 | const_iv (SK_SMITHERY) |
1413 | const_iv (SK_SMITHERY) |
1214 | const_iv (SK_BOWYER) |
1414 | const_iv (SK_BOWYER) |
… | |
… | |
1373 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1573 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1374 | prop (CFAPI_INT, MAP_PROP_SKY) |
1574 | prop (CFAPI_INT, MAP_PROP_SKY) |
1375 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1575 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1376 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1576 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1377 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1577 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1378 | prop (CFAPI_PMAP, MAP_PROP_NEXT) |
|
|
1379 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1578 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1380 | prop (CFAPI_POBJECT, OBJECT_PROP_OB_ABOVE) |
|
|
1381 | prop (CFAPI_POBJECT, OBJECT_PROP_OB_BELOW) |
|
|
1382 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1579 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1383 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1580 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1384 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1581 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1385 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
1582 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
1386 | prop (CFAPI_POBJECT, OBJECT_PROP_HEAD) |
|
|
1387 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
1583 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
1388 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
1584 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
1389 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
1585 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
1390 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
1586 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
1391 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
1587 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
… | |
… | |
1523 | PROTOTYPE: $$ |
1719 | PROTOTYPE: $$ |
1524 | |
1720 | |
1525 | char *path_combine_and_normalize (char *base, char *path) |
1721 | char *path_combine_and_normalize (char *base, char *path) |
1526 | PROTOTYPE: $$ |
1722 | PROTOTYPE: $$ |
1527 | |
1723 | |
1528 | char * |
1724 | const char * |
1529 | cf_get_maps_directory (char *path) |
1725 | get_maps_directory (char *path) |
1530 | PROTOTYPE: $ |
1726 | PROTOTYPE: $ |
1531 | ALIAS: maps_directory = 0 |
1727 | ALIAS: maps_directory = 0 |
|
|
1728 | CODE: |
|
|
1729 | RETVAL = create_pathname (path); |
|
|
1730 | OUTPUT: RETVAL |
1532 | |
1731 | |
1533 | void |
1732 | void |
1534 | sub_generation_inc () |
1733 | sub_generation_inc () |
1535 | CODE: |
1734 | CODE: |
1536 | PL_sub_generation++; |
1735 | PL_sub_generation++; |
… | |
… | |
1545 | confdir = 3 |
1744 | confdir = 3 |
1546 | localdir = 4 |
1745 | localdir = 4 |
1547 | playerdir = 5 |
1746 | playerdir = 5 |
1548 | datadir = 6 |
1747 | datadir = 6 |
1549 | CODE: |
1748 | CODE: |
1550 | { |
1749 | switch (ix) |
1551 | int unused_type; |
1750 | { |
1552 | RETVAL = (char *)systemDirectory (&unused_type, ix); |
1751 | case 0: RETVAL = settings.mapdir ; break; |
1553 | } |
1752 | case 1: RETVAL = settings.uniquedir; break; |
|
|
1753 | case 2: RETVAL = settings.tmpdir ; break; |
|
|
1754 | case 3: RETVAL = settings.confdir ; break; |
|
|
1755 | case 4: RETVAL = settings.localdir ; break; |
|
|
1756 | case 5: RETVAL = settings.playerdir; break; |
|
|
1757 | case 6: RETVAL = settings.datadir ; break; |
|
|
1758 | } |
1554 | OUTPUT: RETVAL |
1759 | OUTPUT: RETVAL |
1555 | |
1760 | |
1556 | int |
1761 | int |
1557 | cf_find_animation (char *text) |
1762 | cf_find_animation (char *text) |
1558 | PROTOTYPE: $ |
1763 | PROTOTYPE: $ |
1559 | |
1764 | |
1560 | int random_roll(int min, int max, object *op, int goodbad); |
1765 | int random_roll(int min, int max, object *op, int goodbad); |
1561 | |
1766 | |
1562 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1767 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1563 | |
1768 | |
1564 | int invoke (int event, SV *arg1, ...) |
1769 | int invoke (int event, ...) |
1565 | CODE: |
1770 | CODE: |
1566 | { |
1771 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1567 | // parse first arg and call invoke_object etc as seen fit |
1772 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1568 | //TODO |
1773 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1569 | //cfperl_invoke (event, |
1774 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
1570 | } |
1775 | OUTPUT: RETVAL |
1571 | |
1776 | |
1572 | int |
1777 | int |
1573 | exp_to_level (val64 exp) |
1778 | exp_to_level (val64 exp) |
1574 | CODE: |
1779 | CODE: |
1575 | { |
1780 | { |
… | |
… | |
1606 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1811 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1607 | else |
1812 | else |
1608 | XSRETURN_UNDEF; |
1813 | XSRETURN_UNDEF; |
1609 | OUTPUT: RETVAL |
1814 | OUTPUT: RETVAL |
1610 | |
1815 | |
|
|
1816 | int |
|
|
1817 | _valid (SV *obj) |
|
|
1818 | CODE: |
|
|
1819 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
|
|
1820 | OUTPUT: |
|
|
1821 | RETVAL |
|
|
1822 | |
1611 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1823 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
|
|
1824 | |
|
|
1825 | int invoke (object *op, int event, ...) |
|
|
1826 | CODE: |
|
|
1827 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
|
|
1828 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1829 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
1830 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
|
|
1831 | OUTPUT: RETVAL |
|
|
1832 | |
|
|
1833 | SV *registry (object *op) |
|
|
1834 | CODE: |
|
|
1835 | RETVAL = registry_of (op); |
|
|
1836 | OUTPUT: |
|
|
1837 | RETVAL |
|
|
1838 | |
|
|
1839 | object *head (object *op) |
|
|
1840 | PROTOTYPE: $ |
|
|
1841 | ALIAS: |
|
|
1842 | more = 1 |
|
|
1843 | above = 2 |
|
|
1844 | below = 3 |
|
|
1845 | CODE: |
|
|
1846 | switch (ix) |
|
|
1847 | { |
|
|
1848 | case 0: RETVAL = op->head ? op->head : op; break; // DOH! |
|
|
1849 | case 1: RETVAL = op->more; break; |
|
|
1850 | case 2: RETVAL = op->above; break; |
|
|
1851 | case 3: RETVAL = op->below; break; |
|
|
1852 | } |
|
|
1853 | OUTPUT: |
|
|
1854 | RETVAL |
1612 | |
1855 | |
1613 | SV * |
1856 | SV * |
1614 | get_property (object *obj, int type, int idx) |
1857 | get_property (object *obj, int type, int idx) |
1615 | CODE: |
1858 | CODE: |
1616 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
1859 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
… | |
… | |
1695 | |
1938 | |
1696 | int need_identify (const object *obj); |
1939 | int need_identify (const object *obj); |
1697 | |
1940 | |
1698 | int apply_shop_mat (object *shop_mat, object *op); |
1941 | int apply_shop_mat (object *shop_mat, object *op); |
1699 | |
1942 | |
1700 | void cf_object_move (object *op, int dir, object *originator = op) |
1943 | int move (object *op, int dir, object *originator = op) |
|
|
1944 | CODE: |
|
|
1945 | RETVAL = move_ob (op, dir, originator); |
|
|
1946 | OUTPUT: |
|
|
1947 | RETVAL |
1701 | |
1948 | |
1702 | void cf_object_apply (object *op, object *author, int flags = 0) |
1949 | void cf_object_apply (object *op, object *author, int flags = 0) |
1703 | |
1950 | |
1704 | void cf_object_apply_below (object *op) |
1951 | void cf_object_apply_below (object *op) |
1705 | |
1952 | |
… | |
… | |
1746 | int cf_object_out_of_map (object *op, int x, int y) |
1993 | int cf_object_out_of_map (object *op, int x, int y) |
1747 | |
1994 | |
1748 | void cf_object_drop (object *op, object *author) |
1995 | void cf_object_drop (object *op, object *author) |
1749 | |
1996 | |
1750 | void cf_object_take (object *op, object *author) |
1997 | void cf_object_take (object *op, object *author) |
1751 | |
|
|
1752 | void cf_object_say (object *op, char *msg) |
|
|
1753 | |
|
|
1754 | void cf_object_speak (object *op, char *msg) |
|
|
1755 | |
1998 | |
1756 | object *cf_object_insert_object (object *op, object *container) |
1999 | object *cf_object_insert_object (object *op, object *container) |
1757 | |
2000 | |
1758 | const char *cf_object_get_msg (object *ob) |
2001 | const char *cf_object_get_msg (object *ob) |
1759 | ALIAS: msg = 0 |
2002 | ALIAS: msg = 0 |
… | |
… | |
1813 | CODE: |
2056 | CODE: |
1814 | { |
2057 | { |
1815 | int unused_type; |
2058 | int unused_type; |
1816 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
2059 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1817 | } |
2060 | } |
1818 | |
|
|
1819 | SV *registry (object *op) |
|
|
1820 | CODE: |
|
|
1821 | RETVAL = registry_of (op); |
|
|
1822 | OUTPUT: |
|
|
1823 | RETVAL |
|
|
1824 | |
2061 | |
1825 | # syntatic sugar for easier use in event callbacks. |
2062 | # syntatic sugar for easier use in event callbacks. |
1826 | const char *options (object *op) |
2063 | const char *options (object *op) |
1827 | CODE: |
2064 | CODE: |
1828 | RETVAL = op->name; |
2065 | RETVAL = op->name; |
… | |
… | |
1901 | |
2138 | |
1902 | void kill_player (object *op) |
2139 | void kill_player (object *op) |
1903 | |
2140 | |
1904 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2141 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1905 | |
2142 | |
|
|
2143 | int invoke (player *pl, int event, ...) |
|
|
2144 | CODE: |
|
|
2145 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
|
|
2146 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
2147 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
2148 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
|
|
2149 | OUTPUT: RETVAL |
|
|
2150 | |
1906 | SV *registry (player *pl) |
2151 | SV *registry (player *pl) |
1907 | CODE: |
2152 | CODE: |
1908 | RETVAL = registry_of (pl); |
2153 | RETVAL = registry_of (pl); |
1909 | OUTPUT: |
2154 | OUTPUT: |
1910 | RETVAL |
2155 | RETVAL |
… | |
… | |
2034 | OUTPUT: RETVAL |
2279 | OUTPUT: RETVAL |
2035 | |
2280 | |
2036 | |
2281 | |
2037 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2282 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2038 | |
2283 | |
|
|
2284 | mapstruct *first () |
|
|
2285 | PROTOTYPE: |
|
|
2286 | CODE: |
|
|
2287 | RETVAL = first_map; |
|
|
2288 | OUTPUT: RETVAL |
|
|
2289 | |
|
|
2290 | mapstruct *next (mapstruct *map) |
|
|
2291 | PROTOTYPE: |
|
|
2292 | CODE: |
|
|
2293 | RETVAL = map->next; |
|
|
2294 | OUTPUT: RETVAL |
|
|
2295 | |
|
|
2296 | int invoke (mapstruct *map, int event, ...) |
|
|
2297 | CODE: |
|
|
2298 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
|
|
2299 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
2300 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
2301 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
|
|
2302 | OUTPUT: RETVAL |
|
|
2303 | |
2039 | SV *registry (mapstruct *map) |
2304 | SV *registry (mapstruct *map) |
2040 | CODE: |
2305 | CODE: |
2041 | RETVAL = registry_of (map); |
2306 | RETVAL = registry_of (map); |
2042 | OUTPUT: |
2307 | OUTPUT: |
2043 | RETVAL |
2308 | RETVAL |
… | |
… | |
2062 | |
2327 | |
2063 | mapstruct *new (int width, int height) |
2328 | mapstruct *new (int width, int height) |
2064 | PROTOTYPE: |
2329 | PROTOTYPE: |
2065 | CODE: |
2330 | CODE: |
2066 | { |
2331 | { |
2067 | int unused_type; |
2332 | RETVAL = get_empty_map (width, height); |
2068 | RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); |
|
|
2069 | } |
2333 | } |
2070 | OUTPUT: |
2334 | OUTPUT: |
2071 | RETVAL |
2335 | RETVAL |
2072 | |
2336 | |
2073 | void delete_map (mapstruct *map) |
2337 | void delete_map (mapstruct *map) |
… | |
… | |
2088 | XSRETURN_UNDEF; |
2352 | XSRETURN_UNDEF; |
2089 | RETVAL = map->tile_path [dir]; |
2353 | RETVAL = map->tile_path [dir]; |
2090 | OUTPUT: |
2354 | OUTPUT: |
2091 | RETVAL |
2355 | RETVAL |
2092 | |
2356 | |
2093 | mapstruct *cf_map_get_map (char *name) |
2357 | mapstruct *ready_map_name (char *name, int flags = 0) |
2094 | PROTOTYPE: $ |
2358 | PROTOTYPE: $;$ |
2095 | ALIAS: map = 0 |
2359 | ALIAS: |
|
|
2360 | find = 0 |
|
|
2361 | get_map = 1 |
2096 | |
2362 | |
2097 | mapstruct *has_been_loaded (char *name) |
2363 | mapstruct *has_been_loaded (char *name) |
2098 | PROTOTYPE: $ |
2364 | PROTOTYPE: $ |
2099 | |
|
|
2100 | mapstruct *cf_map_get_first () |
|
|
2101 | PROTOTYPE: |
|
|
2102 | ALIAS: first = 0 |
|
|
2103 | |
2365 | |
2104 | # whoever "designed" the plug-in api should have wasted |
2366 | # whoever "designed" the plug-in api should have wasted |
2105 | # his/her time with staying away from the project - would have |
2367 | # his/her time with staying away from the project - would have |
2106 | # saved others a lot of time, without doubt. |
2368 | # saved others a lot of time, without doubt. |
2107 | void set_path (mapstruct *where, char *path) |
2369 | void set_path (mapstruct *where, char *path) |
… | |
… | |
2122 | |
2384 | |
2123 | void set_unique (mapstruct *map, bool unique) |
2385 | void set_unique (mapstruct *map, bool unique) |
2124 | CODE: |
2386 | CODE: |
2125 | map->unique = unique; |
2387 | map->unique = unique; |
2126 | |
2388 | |
|
|
2389 | void |
|
|
2390 | trigger (mapstruct *map, long connection, bool state = true) |
|
|
2391 | CODE: |
|
|
2392 | activate_connection (map, connection, state); |
|
|
2393 | |
|
|
2394 | void |
|
|
2395 | get_connection (mapstruct *map, long connection) |
|
|
2396 | PPCODE: |
|
|
2397 | oblinkpt *obp = get_connection_links (map, connection); |
|
|
2398 | if (obp) |
|
|
2399 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
|
|
2400 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); |
|
|
2401 | |
2127 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2402 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2128 | |
2403 | |
2129 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2404 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2130 | |
2405 | |
2131 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
2406 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
… | |
… | |
2135 | cf_map_normalise (mapstruct *map, int x, int y) |
2410 | cf_map_normalise (mapstruct *map, int x, int y) |
2136 | PPCODE: |
2411 | PPCODE: |
2137 | { |
2412 | { |
2138 | mapstruct *nmap = 0; |
2413 | mapstruct *nmap = 0; |
2139 | I16 nx = 0, ny = 0; |
2414 | I16 nx = 0, ny = 0; |
2140 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2415 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2141 | |
2416 | |
2142 | EXTEND (SP, 4); |
2417 | EXTEND (SP, 4); |
2143 | PUSHs (sv_2mortal (newSViv (flags))); |
2418 | PUSHs (sv_2mortal (newSViv (flags))); |
2144 | |
2419 | |
2145 | if (GIMME_V == G_ARRAY) |
2420 | if (GIMME_V == G_ARRAY) |
… | |
… | |
2157 | { |
2432 | { |
2158 | object *o; |
2433 | object *o; |
2159 | mapstruct *nmap = 0; |
2434 | mapstruct *nmap = 0; |
2160 | I16 nx, ny; |
2435 | I16 nx, ny; |
2161 | |
2436 | |
2162 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2437 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2163 | |
2438 | |
2164 | if (nmap) |
2439 | if (nmap) |
2165 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2440 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2166 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2441 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2167 | } |
2442 | } |
… | |
… | |
2192 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2467 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2193 | } |
2468 | } |
2194 | OUTPUT: |
2469 | OUTPUT: |
2195 | RETVAL |
2470 | RETVAL |
2196 | |
2471 | |
2197 | # "deserialise" perl map data into the map # TODO# compatibility cruft, remove |
|
|
2198 | void |
|
|
2199 | _set_obs (mapstruct *map, SV *sv) |
|
|
2200 | CODE: |
|
|
2201 | { |
|
|
2202 | object *o; |
|
|
2203 | AV *av; |
|
|
2204 | int x, y; |
|
|
2205 | AV *obs = (AV *)SvRV (sv); |
|
|
2206 | |
2472 | |
2207 | for (y = 0; y < MAP_HEIGHT (map); y++) |
2473 | MODULE = cf PACKAGE = cf::arch |
2208 | for (x = 0; x < MAP_WIDTH (map); x++) |
|
|
2209 | { |
|
|
2210 | sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1); |
|
|
2211 | |
2474 | |
2212 | if (!SvROK (sv)) |
2475 | archetype *find (const char *name) |
2213 | continue; |
2476 | CODE: |
|
|
2477 | RETVAL = find_archetype (name); |
|
|
2478 | OUTPUT: |
|
|
2479 | RETVAL |
2214 | |
2480 | |
2215 | av = (AV *)SvRV (sv); |
2481 | archetype *first() |
2216 | |
|
|
2217 | for (o = GET_MAP_OB (map, x, y); o; o = o->above) |
|
|
2218 | { |
|
|
2219 | sv = av_shift (av); |
|
|
2220 | |
|
|
2221 | if (SvROK (sv)) |
|
|
2222 | { |
|
|
2223 | sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0); |
|
|
2224 | SVptr_cache_set (o, sv); |
|
|
2225 | } |
|
|
2226 | } |
|
|
2227 | } |
|
|
2228 | } |
|
|
2229 | |
|
|
2230 | |
|
|
2231 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
|
|
2232 | |
|
|
2233 | archetype *cf_archetype_get_first() |
|
|
2234 | PROTOTYPE: |
2482 | PROTOTYPE: |
2235 | ALIAS: first = 0 |
2483 | CODE: |
|
|
2484 | RETVAL = first_archetype; |
|
|
2485 | OUTPUT: RETVAL |
2236 | |
2486 | |
2237 | archetype *cf_archetype_get_next (archetype *arch) |
2487 | archetype *next (archetype *arch) |
2238 | ALIAS: next = 0 |
2488 | CODE: |
|
|
2489 | RETVAL = arch->next; |
|
|
2490 | OUTPUT: RETVAL |
2239 | |
2491 | |
2240 | archetype *cf_archetype_get_head (archetype *arch) |
2492 | archetype *head (archetype *arch) |
2241 | ALIAS: head = 0 |
2493 | CODE: |
|
|
2494 | RETVAL = arch->head; |
|
|
2495 | OUTPUT: RETVAL |
2242 | |
2496 | |
2243 | archetype *cf_archetype_get_more (archetype *arch) |
2497 | archetype *more (archetype *arch) |
2244 | ALIAS: more = 0 |
2498 | CODE: |
|
|
2499 | RETVAL = arch->more; |
|
|
2500 | OUTPUT: RETVAL |
2245 | |
2501 | |
2246 | const char *cf_archetype_get_name (archetype *arch) |
2502 | const char *name (archetype *arch) |
2247 | ALIAS: name = 0 |
2503 | CODE: |
|
|
2504 | RETVAL = arch->name; |
|
|
2505 | OUTPUT: RETVAL |
2248 | |
2506 | |
2249 | object *cf_archetype_get_clone (archetype *arch) |
2507 | object *clone (archetype *arch) |
2250 | ALIAS: clone = 0 |
2508 | CODE: |
|
|
2509 | RETVAL = &arch->clone; |
|
|
2510 | OUTPUT: RETVAL |
2251 | |
2511 | |
2252 | MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ |
2512 | MODULE = cf PACKAGE = cf::party |
2253 | |
2513 | |
2254 | partylist *cf_party_get_first () |
2514 | partylist *first () |
2255 | PROTOTYPE: |
2515 | PROTOTYPE: |
2256 | ALIAS: first = 0 |
2516 | CODE: |
|
|
2517 | RETVAL = get_firstparty (); |
|
|
2518 | OUTPUT: RETVAL |
2257 | |
2519 | |
2258 | partylist *cf_party_get_next (partylist *party) |
2520 | partylist *next (partylist *party) |
2259 | ALIAS: next = 0 |
2521 | CODE: |
|
|
2522 | RETVAL = party->next; |
|
|
2523 | OUTPUT: RETVAL |
2260 | |
2524 | |
2261 | const char *cf_party_get_name (partylist *party) |
2525 | const char *name (partylist *party) |
|
|
2526 | CODE: |
|
|
2527 | RETVAL = party->partyname; |
|
|
2528 | OUTPUT: RETVAL |
2262 | |
2529 | |
2263 | const char *cf_party_get_password (partylist *party) |
2530 | const char *password (partylist *party) |
2264 | ALIAS: password = 0 |
2531 | CODE: |
|
|
2532 | RETVAL = party->passwd; |
|
|
2533 | OUTPUT: RETVAL |
2265 | |
2534 | |
2266 | player *cf_party_get_first_player (partylist *party) |
2535 | MODULE = cf PACKAGE = cf::region |
2267 | ALIAS: first_player = 0 |
|
|
2268 | |
2536 | |
2269 | player *cf_party_get_next_player (partylist *party, player *op) |
2537 | region *first () |
2270 | ALIAS: next_player = 0 |
|
|
2271 | |
|
|
2272 | |
|
|
2273 | MODULE = cf PACKAGE = cf::region PREFIX = cf_region_ |
|
|
2274 | |
|
|
2275 | region *cf_region_get_first () |
|
|
2276 | PROTOTYPE: |
2538 | PROTOTYPE: |
2277 | ALIAS: first = 0 |
2539 | CODE: |
|
|
2540 | RETVAL = first_region; |
|
|
2541 | OUTPUT: RETVAL |
2278 | |
2542 | |
|
|
2543 | region *next (region *reg) |
|
|
2544 | CODE: |
|
|
2545 | RETVAL = reg->next; |
|
|
2546 | OUTPUT: RETVAL |
|
|
2547 | |
|
|
2548 | const char *name (region *reg) |
|
|
2549 | CODE: |
|
|
2550 | RETVAL = reg->name; |
|
|
2551 | OUTPUT: RETVAL |
|
|
2552 | |
|
|
2553 | region *parent (region *reg) |
|
|
2554 | CODE: |
|
|
2555 | RETVAL = reg->parent; |
|
|
2556 | OUTPUT: RETVAL |
|
|
2557 | |
2279 | const char *cf_region_get_name (region *reg) |
2558 | const char *longname (region *reg) |
2280 | ALIAS: name = 0 |
2559 | CODE: |
|
|
2560 | RETVAL = reg->longname; |
|
|
2561 | OUTPUT: RETVAL |
2281 | |
2562 | |
2282 | region *cf_region_get_next (region *reg) |
2563 | const char *msg (region *reg) |
2283 | ALIAS: next = 0 |
2564 | CODE: |
|
|
2565 | RETVAL = reg->msg; |
|
|
2566 | OUTPUT: RETVAL |
2284 | |
2567 | |
2285 | region *cf_region_get_parent (region *reg) |
2568 | MODULE = cf PACKAGE = cf::living |
2286 | ALIAS: parent = 0 |
|
|
2287 | |
|
|
2288 | const char *cf_region_get_longname (region *reg) |
|
|
2289 | ALIAS: longname = 0 |
|
|
2290 | |
|
|
2291 | const char *cf_region_get_message (region *reg) |
|
|
2292 | ALIAS: message = 0 |
|
|
2293 | |
|
|
2294 | |
|
|
2295 | MODULE = cf PACKAGE = cf::living PREFIX = cf_living_ |
|
|
2296 | |
2569 | |
2297 | val64 |
2570 | val64 |
2298 | exp (living *liv, val64 new_val = 0) |
2571 | exp (living *liv, val64 new_val = 0) |
2299 | PROTOTYPE: $;$ |
2572 | PROTOTYPE: $;$ |
2300 | ALIAS: |
2573 | ALIAS: |