… | |
… | |
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 | { |
|
|
399 | obj->optimise (); |
|
|
400 | |
447 | if (obj->self) |
401 | if (obj->self) |
448 | reattach (subclass::get_dt (), (subclass *)obj); |
402 | reattach ((data_type) cftype<subclass>::dt, (subclass *)obj); |
449 | } |
403 | } |
450 | |
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 | |
451 | 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) |
452 | { |
517 | { |
453 | if (!av) |
518 | if (!av || oid < 0) // this is actually an error of sorts |
454 | return; |
519 | return; |
455 | |
520 | |
456 | // 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 |
457 | ext->clear (); |
522 | ext->clear (); |
458 | |
523 | |
459 | SV **svp = av_fetch ((AV *)av, idx, 0); |
524 | SV **svp = av_fetch ((AV *)av, oid, 0); |
460 | |
525 | |
461 | ++idx; |
526 | if (!svp || !SvROK (*svp)) |
462 | |
527 | { |
463 | if (!svp) |
528 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
464 | return; |
529 | return; |
465 | |
|
|
466 | if (SvROK (*svp)) |
|
|
467 | { |
530 | } |
468 | ext->self = SvREFCNT_inc (*svp); |
531 | |
|
|
532 | ext->self = *svp; *svp = &PL_sv_undef; |
469 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
533 | sv_magic (SvRV (ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
470 | |
534 | |
471 | reattach (type, obj); |
535 | reattach (type, obj); |
472 | } |
|
|
473 | } |
536 | } |
474 | |
537 | |
475 | object_thawer::~object_thawer () |
538 | object_thawer::~object_thawer () |
476 | { |
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 | |
477 | if (av) |
549 | if (!p) |
478 | 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 | int klen = keyword_len [kend]; |
|
|
639 | |
|
|
640 | kw [0] = '\n'; |
|
|
641 | memcpy (kw + 1, keyword_str [kend], klen); |
|
|
642 | kw [klen + 1] = '\n'; |
|
|
643 | kw [klen + 2] = 0; |
|
|
644 | |
|
|
645 | // first test for completely empty msg... "endXXX\n" |
|
|
646 | if (!strncmp (line, kw + 1, klen + 1)) |
|
|
647 | { |
|
|
648 | sh = 0; |
|
|
649 | |
|
|
650 | line += klen + 1; |
|
|
651 | |
|
|
652 | return; |
|
|
653 | } |
|
|
654 | else |
|
|
655 | { |
|
|
656 | // multi-line strings are delimited by "\nendXXX\n" or "endXXX\n" (NULL) |
|
|
657 | |
|
|
658 | char *end = strstr (line, kw); |
|
|
659 | |
|
|
660 | if (!end) |
|
|
661 | { |
|
|
662 | sh = 0; |
|
|
663 | return; |
|
|
664 | } |
|
|
665 | |
|
|
666 | *end = 0; |
|
|
667 | sh = line; |
|
|
668 | |
|
|
669 | line = end + keyword_len [kend] + 1; |
|
|
670 | |
|
|
671 | while (*line++ != '\n') |
|
|
672 | ; |
|
|
673 | } |
|
|
674 | } |
|
|
675 | |
|
|
676 | sint32 object_thawer::get_sint32 () const |
|
|
677 | { |
|
|
678 | char *p = last_value; |
|
|
679 | |
|
|
680 | if (!p) |
|
|
681 | return 0; |
|
|
682 | |
|
|
683 | sint32 val = 0; |
|
|
684 | bool negate; |
|
|
685 | |
|
|
686 | if (*p == '-') |
|
|
687 | { |
|
|
688 | negate = true; |
|
|
689 | ++p; |
|
|
690 | } |
|
|
691 | else |
|
|
692 | negate = false; |
|
|
693 | |
|
|
694 | do |
|
|
695 | { |
|
|
696 | val *= 10; |
|
|
697 | val += *p++ - '0'; |
|
|
698 | } |
|
|
699 | while (*p); |
|
|
700 | |
|
|
701 | return negate ? -val : val; |
|
|
702 | } |
|
|
703 | |
|
|
704 | sint64 object_thawer::get_sint64 () const |
|
|
705 | { |
|
|
706 | return last_value ? atoll (last_value) : 0; |
|
|
707 | } |
|
|
708 | |
|
|
709 | double object_thawer::get_double () const |
|
|
710 | { |
|
|
711 | return last_value ? atof (last_value) : 0; |
479 | } |
712 | } |
480 | |
713 | |
481 | ///////////////////////////////////////////////////////////////////////////// |
714 | ///////////////////////////////////////////////////////////////////////////// |
482 | |
715 | |
483 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
716 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
484 | { |
717 | { |
485 | gethook = gethooksptr; |
|
|
486 | printf (PLUGIN_VERSION " init\n"); |
|
|
487 | |
|
|
488 | return 0; |
718 | return 0; |
489 | } |
719 | } |
490 | |
720 | |
491 | static CommArray_s rtn_cmd; |
721 | static CommArray_s rtn_cmd; |
492 | |
722 | |
… | |
… | |
572 | extern "C" int cfperl_postInitPlugin () |
802 | extern "C" int cfperl_postInitPlugin () |
573 | { |
803 | { |
574 | int hooktype = 1; |
804 | int hooktype = 1; |
575 | int rtype = 0; |
805 | int rtype = 0; |
576 | |
806 | |
577 | printf (PLUGIN_VERSION " post init\n"); |
|
|
578 | |
|
|
579 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
|
|
580 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
|
|
581 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
|
|
582 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
|
|
583 | |
|
|
584 | cf_init_plugin (gethook); |
807 | cf_init_plugin (gethook); |
585 | |
808 | |
586 | return 0; |
809 | return 0; |
587 | } |
810 | } |
588 | |
811 | |
… | |
… | |
592 | } |
815 | } |
593 | |
816 | |
594 | void |
817 | void |
595 | cfperl_init () |
818 | cfperl_init () |
596 | { |
819 | { |
|
|
820 | PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); |
|
|
821 | perl = perl_alloc (); |
|
|
822 | perl_construct (perl); |
|
|
823 | |
|
|
824 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
825 | |
597 | char *argv[] = { |
826 | char *argv[] = { |
598 | "", |
827 | "", |
599 | "-e" |
828 | "-e" |
600 | "BEGIN {" |
|
|
601 | " cf->bootstrap;" |
829 | "cf->bootstrap;" |
602 | " unshift @INC, cf::datadir ();" |
830 | "unshift @INC, cf::datadir ();" |
603 | "}" |
|
|
604 | "" |
|
|
605 | "use cf;" |
831 | "require cf;" |
606 | }; |
832 | }; |
607 | |
833 | |
608 | perl = perl_alloc (); |
|
|
609 | perl_construct (perl); |
|
|
610 | |
|
|
611 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
612 | |
|
|
613 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
834 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
614 | { |
835 | { |
615 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
836 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
616 | |
|
|
617 | exit (EXIT_FAILURE); |
837 | exit (EXIT_FAILURE); |
618 | //perl_destruct (perl); |
|
|
619 | //perl_free (perl); |
|
|
620 | //perl = 0; |
|
|
621 | //return; |
|
|
622 | } |
838 | } |
623 | |
839 | |
624 | obj_cache = newHV (); |
840 | obj_cache = newHV (); |
625 | } |
841 | } |
626 | |
842 | |
… | |
… | |
636 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
852 | static event_klass klass_of[NUM_EVENT_TYPES] = { |
637 | # define def(type,name) KLASS_ ## type, |
853 | # define def(type,name) KLASS_ ## type, |
638 | # include "eventinc.h" |
854 | # include "eventinc.h" |
639 | # undef def |
855 | # undef def |
640 | }; |
856 | }; |
|
|
857 | |
|
|
858 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
641 | |
859 | |
642 | static void |
860 | static void |
643 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
861 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
644 | { |
862 | { |
645 | // event must be in array |
863 | // event must be in array |
… | |
… | |
688 | // 2a. per-type callback |
906 | // 2a. per-type callback |
689 | // 4. global callbacks |
907 | // 4. global callbacks |
690 | |
908 | |
691 | gather_callbacks (callbacks, cb_global, event); |
909 | gather_callbacks (callbacks, cb_global, event); |
692 | |
910 | |
693 | switch (klass_of [event]) |
911 | switch (KLASS_OF (event)) |
694 | { |
912 | { |
695 | case KLASS_GLOBAL: |
913 | case KLASS_GLOBAL: |
696 | break; |
914 | break; |
697 | |
915 | |
698 | case KLASS_OBJECT: |
916 | case KLASS_OBJECT: |
699 | dt = (data_type) va_arg (ap, int); |
917 | dt = (data_type) va_arg (ap, int); |
700 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
918 | assert (("first argument must be of type object", dt == DT_OBJECT)); |
701 | op = va_arg (ap, object *); |
919 | op = va_arg (ap, object *); |
702 | |
920 | |
703 | if (op->cb) |
921 | if (op->cb) |
704 | gather_callbacks (callbacks, (AV *)op->cb, event); |
922 | gather_callbacks (callbacks, op->cb, event); |
705 | |
923 | |
706 | if (op->type) |
924 | if (op->type) |
707 | { |
925 | { |
708 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
926 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
709 | { |
927 | { |
… | |
… | |
730 | dt = (data_type) va_arg (ap, int); |
948 | dt = (data_type) va_arg (ap, int); |
731 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
949 | assert (("first argument must be of type player", dt == DT_PLAYER)); |
732 | pl = va_arg (ap, player *); |
950 | pl = va_arg (ap, player *); |
733 | |
951 | |
734 | if (pl->cb) |
952 | if (pl->cb) |
735 | gather_callbacks (callbacks, (AV *)pl->cb, event); |
953 | gather_callbacks (callbacks, pl->cb, event); |
736 | |
954 | |
737 | gather_callbacks (callbacks, cb_player, event); |
955 | gather_callbacks (callbacks, cb_player, event); |
738 | break; |
956 | break; |
739 | |
957 | |
740 | case KLASS_MAP: |
958 | case KLASS_MAP: |
741 | dt = (data_type) va_arg (ap, int); |
959 | dt = (data_type) va_arg (ap, int); |
742 | assert (("first argument must be of type object", dt == DT_MAP)); |
960 | assert (("first argument must be of type object", dt == DT_MAP)); |
743 | map = va_arg (ap, mapstruct *); |
961 | map = va_arg (ap, mapstruct *); |
744 | |
962 | |
745 | if (map->cb) |
963 | if (map->cb) |
746 | gather_callbacks (callbacks, (AV *)map->cb, event); |
964 | gather_callbacks (callbacks, map->cb, event); |
747 | |
965 | |
748 | gather_callbacks (callbacks, cb_map, event); |
966 | gather_callbacks (callbacks, cb_map, event); |
749 | break; |
967 | break; |
750 | |
968 | |
751 | default: |
969 | default: |
… | |
… | |
764 | EXTEND (SP, 3); |
982 | EXTEND (SP, 3); |
765 | |
983 | |
766 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
984 | PUSHs (sv_2mortal (newSViv (event))); // only used for debugging nowadays |
767 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
985 | PUSHs (sv_2mortal (newRV_noinc ((SV *)callbacks))); |
768 | |
986 | |
769 | switch (klass_of [event]) |
987 | switch (KLASS_OF (event)) |
770 | { |
988 | { |
771 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
989 | case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; |
772 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
990 | case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; |
773 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
991 | case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; |
774 | } |
992 | } |
… | |
… | |
1203 | |
1421 | |
1204 | const_iv (SK_EXP_ADD_SKILL) |
1422 | const_iv (SK_EXP_ADD_SKILL) |
1205 | const_iv (SK_EXP_TOTAL) |
1423 | const_iv (SK_EXP_TOTAL) |
1206 | const_iv (SK_EXP_NONE) |
1424 | const_iv (SK_EXP_NONE) |
1207 | const_iv (SK_SUBTRACT_SKILL_EXP) |
1425 | const_iv (SK_SUBTRACT_SKILL_EXP) |
|
|
1426 | const_iv (SK_EXP_SKILL_ONLY) |
1208 | |
1427 | |
1209 | const_iv (SK_LOCKPICKING) |
1428 | const_iv (SK_LOCKPICKING) |
1210 | const_iv (SK_HIDING) |
1429 | const_iv (SK_HIDING) |
1211 | const_iv (SK_SMITHERY) |
1430 | const_iv (SK_SMITHERY) |
1212 | const_iv (SK_BOWYER) |
1431 | const_iv (SK_BOWYER) |
… | |
… | |
1371 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1590 | prop (CFAPI_INT, MAP_PROP_WINDDIR) |
1372 | prop (CFAPI_INT, MAP_PROP_SKY) |
1591 | prop (CFAPI_INT, MAP_PROP_SKY) |
1373 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1592 | prop (CFAPI_INT, MAP_PROP_WPARTX) |
1374 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1593 | prop (CFAPI_INT, MAP_PROP_WPARTY) |
1375 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1594 | prop (CFAPI_STRING, MAP_PROP_MESSAGE) |
1376 | prop (CFAPI_PMAP, MAP_PROP_NEXT) |
|
|
1377 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1595 | prop (CFAPI_PREGION, MAP_PROP_REGION) |
1378 | prop (CFAPI_POBJECT, OBJECT_PROP_OB_ABOVE) |
|
|
1379 | prop (CFAPI_POBJECT, OBJECT_PROP_OB_BELOW) |
|
|
1380 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1596 | prop (CFAPI_POBJECT, OBJECT_PROP_NEXT_ACTIVE_OB) |
1381 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1597 | prop (CFAPI_POBJECT, OBJECT_PROP_PREV_ACTIVE_OB) |
1382 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1598 | prop (CFAPI_POBJECT, OBJECT_PROP_INVENTORY) |
1383 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
1599 | prop (CFAPI_POBJECT, OBJECT_PROP_ENVIRONMENT) |
1384 | prop (CFAPI_POBJECT, OBJECT_PROP_HEAD) |
|
|
1385 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
1600 | prop (CFAPI_POBJECT, OBJECT_PROP_CONTAINER) |
1386 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
1601 | prop (CFAPI_PMAP, OBJECT_PROP_MAP) |
1387 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
1602 | prop (CFAPI_INT, OBJECT_PROP_COUNT) |
1388 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
1603 | prop (CFAPI_INT, OBJECT_PROP_REFCOUNT) |
1389 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
1604 | prop (CFAPI_STRING, OBJECT_PROP_NAME) |
… | |
… | |
1521 | PROTOTYPE: $$ |
1736 | PROTOTYPE: $$ |
1522 | |
1737 | |
1523 | char *path_combine_and_normalize (char *base, char *path) |
1738 | char *path_combine_and_normalize (char *base, char *path) |
1524 | PROTOTYPE: $$ |
1739 | PROTOTYPE: $$ |
1525 | |
1740 | |
1526 | char * |
1741 | const char * |
1527 | cf_get_maps_directory (char *path) |
1742 | get_maps_directory (char *path) |
1528 | PROTOTYPE: $ |
1743 | PROTOTYPE: $ |
1529 | ALIAS: maps_directory = 0 |
1744 | ALIAS: maps_directory = 0 |
|
|
1745 | CODE: |
|
|
1746 | RETVAL = create_pathname (path); |
|
|
1747 | OUTPUT: RETVAL |
1530 | |
1748 | |
1531 | void |
1749 | void |
1532 | sub_generation_inc () |
1750 | sub_generation_inc () |
1533 | CODE: |
1751 | CODE: |
1534 | PL_sub_generation++; |
1752 | PL_sub_generation++; |
… | |
… | |
1543 | confdir = 3 |
1761 | confdir = 3 |
1544 | localdir = 4 |
1762 | localdir = 4 |
1545 | playerdir = 5 |
1763 | playerdir = 5 |
1546 | datadir = 6 |
1764 | datadir = 6 |
1547 | CODE: |
1765 | CODE: |
1548 | { |
1766 | switch (ix) |
1549 | int unused_type; |
1767 | { |
1550 | RETVAL = (char *)systemDirectory (&unused_type, ix); |
1768 | case 0: RETVAL = settings.mapdir ; break; |
1551 | } |
1769 | case 1: RETVAL = settings.uniquedir; break; |
|
|
1770 | case 2: RETVAL = settings.tmpdir ; break; |
|
|
1771 | case 3: RETVAL = settings.confdir ; break; |
|
|
1772 | case 4: RETVAL = settings.localdir ; break; |
|
|
1773 | case 5: RETVAL = settings.playerdir; break; |
|
|
1774 | case 6: RETVAL = settings.datadir ; break; |
|
|
1775 | } |
1552 | OUTPUT: RETVAL |
1776 | OUTPUT: RETVAL |
1553 | |
1777 | |
1554 | int |
1778 | int |
1555 | cf_find_animation (char *text) |
1779 | cf_find_animation (char *text) |
1556 | PROTOTYPE: $ |
1780 | PROTOTYPE: $ |
1557 | |
1781 | |
1558 | int random_roll(int min, int max, object *op, int goodbad); |
1782 | int random_roll(int min, int max, object *op, int goodbad); |
1559 | |
1783 | |
1560 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1784 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1561 | |
1785 | |
1562 | int invoke (int event, SV *arg1, ...) |
1786 | int invoke (int event, ...) |
1563 | CODE: |
1787 | CODE: |
1564 | { |
1788 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1565 | // parse first arg and call invoke_object etc as seen fit |
1789 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1566 | //TODO |
1790 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1567 | //cfperl_invoke (event, |
1791 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
1568 | } |
1792 | OUTPUT: RETVAL |
1569 | |
1793 | |
1570 | int |
1794 | int |
1571 | exp_to_level (val64 exp) |
1795 | exp_to_level (val64 exp) |
1572 | CODE: |
1796 | CODE: |
1573 | { |
1797 | { |
… | |
… | |
1604 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1828 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1605 | else |
1829 | else |
1606 | XSRETURN_UNDEF; |
1830 | XSRETURN_UNDEF; |
1607 | OUTPUT: RETVAL |
1831 | OUTPUT: RETVAL |
1608 | |
1832 | |
|
|
1833 | int |
|
|
1834 | _valid (SV *obj) |
|
|
1835 | CODE: |
|
|
1836 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
|
|
1837 | OUTPUT: |
|
|
1838 | RETVAL |
|
|
1839 | |
1609 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1840 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
|
|
1841 | |
|
|
1842 | int invoke (object *op, int event, ...) |
|
|
1843 | CODE: |
|
|
1844 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
|
|
1845 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1846 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
1847 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
|
|
1848 | OUTPUT: RETVAL |
|
|
1849 | |
|
|
1850 | SV *registry (object *op) |
|
|
1851 | CODE: |
|
|
1852 | RETVAL = registry_of (op); |
|
|
1853 | OUTPUT: |
|
|
1854 | RETVAL |
|
|
1855 | |
|
|
1856 | object *head (object *op) |
|
|
1857 | PROTOTYPE: $ |
|
|
1858 | ALIAS: |
|
|
1859 | more = 1 |
|
|
1860 | above = 2 |
|
|
1861 | below = 3 |
|
|
1862 | CODE: |
|
|
1863 | switch (ix) |
|
|
1864 | { |
|
|
1865 | case 0: RETVAL = op->head ? op->head : op; break; // DOH! |
|
|
1866 | case 1: RETVAL = op->more; break; |
|
|
1867 | case 2: RETVAL = op->above; break; |
|
|
1868 | case 3: RETVAL = op->below; break; |
|
|
1869 | } |
|
|
1870 | OUTPUT: |
|
|
1871 | RETVAL |
1610 | |
1872 | |
1611 | SV * |
1873 | SV * |
1612 | get_property (object *obj, int type, int idx) |
1874 | get_property (object *obj, int type, int idx) |
1613 | CODE: |
1875 | CODE: |
1614 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
1876 | RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); |
… | |
… | |
1693 | |
1955 | |
1694 | int need_identify (const object *obj); |
1956 | int need_identify (const object *obj); |
1695 | |
1957 | |
1696 | int apply_shop_mat (object *shop_mat, object *op); |
1958 | int apply_shop_mat (object *shop_mat, object *op); |
1697 | |
1959 | |
1698 | void cf_object_move (object *op, int dir, object *originator = op) |
1960 | int move (object *op, int dir, object *originator = op) |
|
|
1961 | CODE: |
|
|
1962 | RETVAL = move_ob (op, dir, originator); |
|
|
1963 | OUTPUT: |
|
|
1964 | RETVAL |
1699 | |
1965 | |
1700 | void cf_object_apply (object *op, object *author, int flags = 0) |
1966 | void cf_object_apply (object *op, object *author, int flags = 0) |
1701 | |
1967 | |
1702 | void cf_object_apply_below (object *op) |
1968 | void cf_object_apply_below (object *op) |
1703 | |
1969 | |
… | |
… | |
1744 | int cf_object_out_of_map (object *op, int x, int y) |
2010 | int cf_object_out_of_map (object *op, int x, int y) |
1745 | |
2011 | |
1746 | void cf_object_drop (object *op, object *author) |
2012 | void cf_object_drop (object *op, object *author) |
1747 | |
2013 | |
1748 | void cf_object_take (object *op, object *author) |
2014 | void cf_object_take (object *op, object *author) |
1749 | |
|
|
1750 | void cf_object_say (object *op, char *msg) |
|
|
1751 | |
|
|
1752 | void cf_object_speak (object *op, char *msg) |
|
|
1753 | |
2015 | |
1754 | object *cf_object_insert_object (object *op, object *container) |
2016 | object *cf_object_insert_object (object *op, object *container) |
1755 | |
2017 | |
1756 | const char *cf_object_get_msg (object *ob) |
2018 | const char *cf_object_get_msg (object *ob) |
1757 | ALIAS: msg = 0 |
2019 | ALIAS: msg = 0 |
… | |
… | |
1811 | CODE: |
2073 | CODE: |
1812 | { |
2074 | { |
1813 | int unused_type; |
2075 | int unused_type; |
1814 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
2076 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
1815 | } |
2077 | } |
1816 | |
|
|
1817 | SV *registry (object *op) |
|
|
1818 | CODE: |
|
|
1819 | RETVAL = registry_of (op); |
|
|
1820 | OUTPUT: |
|
|
1821 | RETVAL |
|
|
1822 | |
2078 | |
1823 | # syntatic sugar for easier use in event callbacks. |
2079 | # syntatic sugar for easier use in event callbacks. |
1824 | const char *options (object *op) |
2080 | const char *options (object *op) |
1825 | CODE: |
2081 | CODE: |
1826 | RETVAL = op->name; |
2082 | RETVAL = op->name; |
… | |
… | |
1899 | |
2155 | |
1900 | void kill_player (object *op) |
2156 | void kill_player (object *op) |
1901 | |
2157 | |
1902 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2158 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1903 | |
2159 | |
|
|
2160 | int invoke (player *pl, int event, ...) |
|
|
2161 | CODE: |
|
|
2162 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
|
|
2163 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
2164 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
2165 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
|
|
2166 | OUTPUT: RETVAL |
|
|
2167 | |
1904 | SV *registry (player *pl) |
2168 | SV *registry (player *pl) |
1905 | CODE: |
2169 | CODE: |
1906 | RETVAL = registry_of (pl); |
2170 | RETVAL = registry_of (pl); |
1907 | OUTPUT: |
2171 | OUTPUT: |
1908 | RETVAL |
2172 | RETVAL |
… | |
… | |
2032 | OUTPUT: RETVAL |
2296 | OUTPUT: RETVAL |
2033 | |
2297 | |
2034 | |
2298 | |
2035 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2299 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2036 | |
2300 | |
|
|
2301 | mapstruct *first () |
|
|
2302 | PROTOTYPE: |
|
|
2303 | CODE: |
|
|
2304 | RETVAL = first_map; |
|
|
2305 | OUTPUT: RETVAL |
|
|
2306 | |
|
|
2307 | mapstruct *next (mapstruct *map) |
|
|
2308 | PROTOTYPE: |
|
|
2309 | CODE: |
|
|
2310 | RETVAL = map->next; |
|
|
2311 | OUTPUT: RETVAL |
|
|
2312 | |
|
|
2313 | int invoke (mapstruct *map, int event, ...) |
|
|
2314 | CODE: |
|
|
2315 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
|
|
2316 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
2317 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
|
|
2318 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
|
|
2319 | OUTPUT: RETVAL |
|
|
2320 | |
2037 | SV *registry (mapstruct *map) |
2321 | SV *registry (mapstruct *map) |
2038 | CODE: |
2322 | CODE: |
2039 | RETVAL = registry_of (map); |
2323 | RETVAL = registry_of (map); |
2040 | OUTPUT: |
2324 | OUTPUT: |
2041 | RETVAL |
2325 | RETVAL |
… | |
… | |
2060 | |
2344 | |
2061 | mapstruct *new (int width, int height) |
2345 | mapstruct *new (int width, int height) |
2062 | PROTOTYPE: |
2346 | PROTOTYPE: |
2063 | CODE: |
2347 | CODE: |
2064 | { |
2348 | { |
2065 | int unused_type; |
2349 | RETVAL = get_empty_map (width, height); |
2066 | RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); |
|
|
2067 | } |
2350 | } |
2068 | OUTPUT: |
2351 | OUTPUT: |
2069 | RETVAL |
2352 | RETVAL |
2070 | |
2353 | |
2071 | void delete_map (mapstruct *map) |
2354 | void delete_map (mapstruct *map) |
… | |
… | |
2086 | XSRETURN_UNDEF; |
2369 | XSRETURN_UNDEF; |
2087 | RETVAL = map->tile_path [dir]; |
2370 | RETVAL = map->tile_path [dir]; |
2088 | OUTPUT: |
2371 | OUTPUT: |
2089 | RETVAL |
2372 | RETVAL |
2090 | |
2373 | |
2091 | mapstruct *cf_map_get_map (char *name) |
2374 | mapstruct *ready_map_name (char *name, int flags = 0) |
2092 | PROTOTYPE: $ |
2375 | PROTOTYPE: $;$ |
2093 | ALIAS: map = 0 |
2376 | ALIAS: |
|
|
2377 | find = 0 |
|
|
2378 | get_map = 1 |
2094 | |
2379 | |
2095 | mapstruct *has_been_loaded (char *name) |
2380 | mapstruct *has_been_loaded (char *name) |
2096 | PROTOTYPE: $ |
2381 | PROTOTYPE: $ |
2097 | |
|
|
2098 | mapstruct *cf_map_get_first () |
|
|
2099 | PROTOTYPE: |
|
|
2100 | ALIAS: first = 0 |
|
|
2101 | |
2382 | |
2102 | # whoever "designed" the plug-in api should have wasted |
2383 | # whoever "designed" the plug-in api should have wasted |
2103 | # his/her time with staying away from the project - would have |
2384 | # his/her time with staying away from the project - would have |
2104 | # saved others a lot of time, without doubt. |
2385 | # saved others a lot of time, without doubt. |
2105 | void set_path (mapstruct *where, char *path) |
2386 | void set_path (mapstruct *where, char *path) |
… | |
… | |
2120 | |
2401 | |
2121 | void set_unique (mapstruct *map, bool unique) |
2402 | void set_unique (mapstruct *map, bool unique) |
2122 | CODE: |
2403 | CODE: |
2123 | map->unique = unique; |
2404 | map->unique = unique; |
2124 | |
2405 | |
|
|
2406 | void |
|
|
2407 | trigger (mapstruct *map, long connection, bool state = true) |
|
|
2408 | CODE: |
|
|
2409 | activate_connection (map, connection, state); |
|
|
2410 | |
|
|
2411 | void |
|
|
2412 | get_connection (mapstruct *map, long connection) |
|
|
2413 | PPCODE: |
|
|
2414 | oblinkpt *obp = get_connection_links (map, connection); |
|
|
2415 | if (obp) |
|
|
2416 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
|
|
2417 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, ol->ob))); |
|
|
2418 | |
2125 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2419 | object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) |
2126 | |
2420 | |
2127 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2421 | object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) |
2128 | |
2422 | |
2129 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
2423 | object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) |
… | |
… | |
2133 | cf_map_normalise (mapstruct *map, int x, int y) |
2427 | cf_map_normalise (mapstruct *map, int x, int y) |
2134 | PPCODE: |
2428 | PPCODE: |
2135 | { |
2429 | { |
2136 | mapstruct *nmap = 0; |
2430 | mapstruct *nmap = 0; |
2137 | I16 nx = 0, ny = 0; |
2431 | I16 nx = 0, ny = 0; |
2138 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2432 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2139 | |
2433 | |
2140 | EXTEND (SP, 4); |
2434 | EXTEND (SP, 4); |
2141 | PUSHs (sv_2mortal (newSViv (flags))); |
2435 | PUSHs (sv_2mortal (newSViv (flags))); |
2142 | |
2436 | |
2143 | if (GIMME_V == G_ARRAY) |
2437 | if (GIMME_V == G_ARRAY) |
… | |
… | |
2155 | { |
2449 | { |
2156 | object *o; |
2450 | object *o; |
2157 | mapstruct *nmap = 0; |
2451 | mapstruct *nmap = 0; |
2158 | I16 nx, ny; |
2452 | I16 nx, ny; |
2159 | |
2453 | |
2160 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2454 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2161 | |
2455 | |
2162 | if (nmap) |
2456 | if (nmap) |
2163 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2457 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2164 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2458 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2165 | } |
2459 | } |
… | |
… | |
2190 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2484 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2191 | } |
2485 | } |
2192 | OUTPUT: |
2486 | OUTPUT: |
2193 | RETVAL |
2487 | RETVAL |
2194 | |
2488 | |
2195 | # "deserialise" perl map data into the map # TODO# compatibility cruft, remove |
|
|
2196 | void |
|
|
2197 | _set_obs (mapstruct *map, SV *sv) |
|
|
2198 | CODE: |
|
|
2199 | { |
|
|
2200 | object *o; |
|
|
2201 | AV *av; |
|
|
2202 | int x, y; |
|
|
2203 | AV *obs = (AV *)SvRV (sv); |
|
|
2204 | |
2489 | |
2205 | for (y = 0; y < MAP_HEIGHT (map); y++) |
2490 | MODULE = cf PACKAGE = cf::arch |
2206 | for (x = 0; x < MAP_WIDTH (map); x++) |
|
|
2207 | { |
|
|
2208 | sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1); |
|
|
2209 | |
2491 | |
2210 | if (!SvROK (sv)) |
2492 | archetype *find (const char *name) |
2211 | continue; |
2493 | CODE: |
|
|
2494 | RETVAL = find_archetype (name); |
|
|
2495 | OUTPUT: |
|
|
2496 | RETVAL |
2212 | |
2497 | |
2213 | av = (AV *)SvRV (sv); |
2498 | archetype *first() |
2214 | |
|
|
2215 | for (o = GET_MAP_OB (map, x, y); o; o = o->above) |
|
|
2216 | { |
|
|
2217 | sv = av_shift (av); |
|
|
2218 | |
|
|
2219 | if (SvROK (sv)) |
|
|
2220 | { |
|
|
2221 | sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0); |
|
|
2222 | SVptr_cache_set (o, sv); |
|
|
2223 | } |
|
|
2224 | } |
|
|
2225 | } |
|
|
2226 | } |
|
|
2227 | |
|
|
2228 | |
|
|
2229 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
|
|
2230 | |
|
|
2231 | archetype *cf_archetype_get_first() |
|
|
2232 | PROTOTYPE: |
2499 | PROTOTYPE: |
2233 | ALIAS: first = 0 |
2500 | CODE: |
|
|
2501 | RETVAL = first_archetype; |
|
|
2502 | OUTPUT: RETVAL |
2234 | |
2503 | |
2235 | archetype *cf_archetype_get_next (archetype *arch) |
2504 | archetype *next (archetype *arch) |
2236 | ALIAS: next = 0 |
2505 | CODE: |
|
|
2506 | RETVAL = arch->next; |
|
|
2507 | OUTPUT: RETVAL |
2237 | |
2508 | |
2238 | archetype *cf_archetype_get_head (archetype *arch) |
2509 | archetype *head (archetype *arch) |
2239 | ALIAS: head = 0 |
2510 | CODE: |
|
|
2511 | RETVAL = arch->head; |
|
|
2512 | OUTPUT: RETVAL |
2240 | |
2513 | |
2241 | archetype *cf_archetype_get_more (archetype *arch) |
2514 | archetype *more (archetype *arch) |
2242 | ALIAS: more = 0 |
2515 | CODE: |
|
|
2516 | RETVAL = arch->more; |
|
|
2517 | OUTPUT: RETVAL |
2243 | |
2518 | |
2244 | const char *cf_archetype_get_name (archetype *arch) |
2519 | const char *name (archetype *arch) |
2245 | ALIAS: name = 0 |
2520 | CODE: |
|
|
2521 | RETVAL = arch->name; |
|
|
2522 | OUTPUT: RETVAL |
2246 | |
2523 | |
2247 | object *cf_archetype_get_clone (archetype *arch) |
2524 | object *clone (archetype *arch) |
2248 | ALIAS: clone = 0 |
2525 | CODE: |
|
|
2526 | RETVAL = &arch->clone; |
|
|
2527 | OUTPUT: RETVAL |
2249 | |
2528 | |
2250 | MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ |
2529 | MODULE = cf PACKAGE = cf::party |
2251 | |
2530 | |
2252 | partylist *cf_party_get_first () |
2531 | partylist *first () |
2253 | PROTOTYPE: |
2532 | PROTOTYPE: |
2254 | ALIAS: first = 0 |
2533 | CODE: |
|
|
2534 | RETVAL = get_firstparty (); |
|
|
2535 | OUTPUT: RETVAL |
2255 | |
2536 | |
2256 | partylist *cf_party_get_next (partylist *party) |
2537 | partylist *next (partylist *party) |
2257 | ALIAS: next = 0 |
2538 | CODE: |
|
|
2539 | RETVAL = party->next; |
|
|
2540 | OUTPUT: RETVAL |
2258 | |
2541 | |
2259 | const char *cf_party_get_name (partylist *party) |
2542 | const char *name (partylist *party) |
|
|
2543 | CODE: |
|
|
2544 | RETVAL = party->partyname; |
|
|
2545 | OUTPUT: RETVAL |
2260 | |
2546 | |
2261 | const char *cf_party_get_password (partylist *party) |
2547 | const char *password (partylist *party) |
2262 | ALIAS: password = 0 |
2548 | CODE: |
|
|
2549 | RETVAL = party->passwd; |
|
|
2550 | OUTPUT: RETVAL |
2263 | |
2551 | |
2264 | player *cf_party_get_first_player (partylist *party) |
2552 | MODULE = cf PACKAGE = cf::region |
2265 | ALIAS: first_player = 0 |
|
|
2266 | |
2553 | |
2267 | player *cf_party_get_next_player (partylist *party, player *op) |
2554 | region *first () |
2268 | ALIAS: next_player = 0 |
|
|
2269 | |
|
|
2270 | |
|
|
2271 | MODULE = cf PACKAGE = cf::region PREFIX = cf_region_ |
|
|
2272 | |
|
|
2273 | region *cf_region_get_first () |
|
|
2274 | PROTOTYPE: |
2555 | PROTOTYPE: |
2275 | ALIAS: first = 0 |
2556 | CODE: |
|
|
2557 | RETVAL = first_region; |
|
|
2558 | OUTPUT: RETVAL |
2276 | |
2559 | |
|
|
2560 | region *next (region *reg) |
|
|
2561 | CODE: |
|
|
2562 | RETVAL = reg->next; |
|
|
2563 | OUTPUT: RETVAL |
|
|
2564 | |
|
|
2565 | const char *name (region *reg) |
|
|
2566 | CODE: |
|
|
2567 | RETVAL = reg->name; |
|
|
2568 | OUTPUT: RETVAL |
|
|
2569 | |
|
|
2570 | region *parent (region *reg) |
|
|
2571 | CODE: |
|
|
2572 | RETVAL = reg->parent; |
|
|
2573 | OUTPUT: RETVAL |
|
|
2574 | |
2277 | const char *cf_region_get_name (region *reg) |
2575 | const char *longname (region *reg) |
2278 | ALIAS: name = 0 |
2576 | CODE: |
|
|
2577 | RETVAL = reg->longname; |
|
|
2578 | OUTPUT: RETVAL |
2279 | |
2579 | |
2280 | region *cf_region_get_next (region *reg) |
2580 | const char *msg (region *reg) |
2281 | ALIAS: next = 0 |
2581 | CODE: |
|
|
2582 | RETVAL = reg->msg; |
|
|
2583 | OUTPUT: RETVAL |
2282 | |
2584 | |
2283 | region *cf_region_get_parent (region *reg) |
2585 | MODULE = cf PACKAGE = cf::living |
2284 | ALIAS: parent = 0 |
|
|
2285 | |
|
|
2286 | const char *cf_region_get_longname (region *reg) |
|
|
2287 | ALIAS: longname = 0 |
|
|
2288 | |
|
|
2289 | const char *cf_region_get_message (region *reg) |
|
|
2290 | ALIAS: message = 0 |
|
|
2291 | |
|
|
2292 | |
|
|
2293 | MODULE = cf PACKAGE = cf::living PREFIX = cf_living_ |
|
|
2294 | |
2586 | |
2295 | val64 |
2587 | val64 |
2296 | exp (living *liv, val64 new_val = 0) |
2588 | exp (living *liv, val64 new_val = 0) |
2297 | PROTOTYPE: $;$ |
2589 | PROTOTYPE: $;$ |
2298 | ALIAS: |
2590 | ALIAS: |