… | |
… | |
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; |
… | |
… | |
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 | { |
… | |
… | |
314 | return newRV_inc ((SV *)ext->cb); |
300 | return newRV_inc ((SV *)ext->cb); |
315 | } |
301 | } |
316 | |
302 | |
317 | void attachable_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 attachable_base::optimise () |
332 | void attachable_base::optimise () |
332 | { |
333 | { |
333 | if (!self) |
334 | if (!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; |
361 | |
364 | |
362 | INVOKE_OBJECT (INSTANTIATE, this); |
365 | switch (type) |
|
|
366 | { |
|
|
367 | case DT_OBJECT: INVOKE_OBJECT (INSTANTIATE, obj); break; |
|
|
368 | case DT_MAP: INVOKE_MAP (INSTANTIATE, obj); break; |
|
|
369 | } |
363 | } |
370 | } |
364 | |
371 | |
365 | ///////////////////////////////////////////////////////////////////////////// |
372 | ///////////////////////////////////////////////////////////////////////////// |
366 | |
373 | |
367 | void reattach (data_type type, void *obj) |
374 | void reattach (data_type type, void *obj) |
368 | { |
375 | { |
|
|
376 | //TODO only do this when the object has _attachment's |
|
|
377 | |
369 | dSP; |
378 | dSP; |
370 | ENTER; |
379 | ENTER; |
371 | SAVETMPS; |
380 | SAVETMPS; |
372 | PUSHMARK (SP); |
381 | PUSHMARK (SP); |
373 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
382 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
… | |
… | |
388 | void reattach (attachable<subclass> *obj) |
397 | void reattach (attachable<subclass> *obj) |
389 | { |
398 | { |
390 | obj->optimise (); |
399 | obj->optimise (); |
391 | |
400 | |
392 | if (obj->self) |
401 | if (obj->self) |
393 | reattach (subclass::get_dt (), (subclass *)obj); |
402 | reattach ((data_type) cftype<subclass>::dt, (subclass *)obj); |
394 | } |
403 | } |
395 | |
404 | |
|
|
405 | #include "kw_hash.h" |
|
|
406 | |
396 | object_freezer::object_freezer (const char *filename) |
407 | object_freezer::object_freezer () |
397 | : filename (filename) |
408 | : dynbuf (128 * 1024, 64 * 1024) |
398 | { |
409 | { |
399 | av = (AV *)newAV (); |
410 | av = newAV (); |
400 | } |
411 | } |
401 | |
412 | |
402 | object_freezer::~object_freezer () |
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) |
403 | { |
434 | { |
404 | dSP; |
435 | dSP; |
405 | ENTER; |
436 | ENTER; |
406 | SAVETMPS; |
437 | SAVETMPS; |
407 | PUSHMARK (SP); |
438 | PUSHMARK (SP); |
|
|
439 | EXTEND (SP, 3); |
408 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
440 | PUSHs (sv_2mortal (newSVpv (filename, 0))); |
|
|
441 | PUSHs (sv_2mortal (newRV_noinc (newSVpvn ((char *)linearise (), size ())))); |
409 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
442 | PUSHs (sv_2mortal (newRV_inc ((SV *)av))); |
410 | PUTBACK; |
443 | PUTBACK; |
411 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
444 | call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); |
412 | FREETMPS; |
445 | FREETMPS; |
413 | LEAVE; |
446 | LEAVE; |
414 | } |
447 | } |
415 | |
448 | |
416 | void object_freezer::put (FILE *fp, attachable_base *ext) |
449 | int fprintf (object_freezer &freezer, const char *format, ...) |
417 | { |
450 | { |
418 | ext->optimise (); |
451 | va_list ap; |
419 | |
452 | |
420 | if (ext->self) |
453 | va_start (ap, format); |
421 | { |
454 | |
422 | int idx = AvFILLp ((AV *)av) + 1; |
455 | int len = vsnprintf ((char *)freezer.force (1024), 1024, format, ap); |
423 | av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); |
456 | |
424 | fprintf (fp, "oid %d\n", idx); |
457 | if (len >= 0) |
425 | } |
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); |
426 | } |
466 | } |
427 | |
467 | |
428 | object_thawer::object_thawer (const char *filename) |
468 | object_thawer::object_thawer (const char *filename) |
429 | { |
469 | { |
|
|
470 | static const char eof[] = "\n\n\n\0\0\0"; |
|
|
471 | |
430 | av = 0; |
472 | av = 0; |
|
|
473 | text = 0; |
|
|
474 | line = 0; |
431 | |
475 | |
432 | if (!filename) |
476 | if (filename) |
433 | return; |
477 | { |
434 | |
|
|
435 | dSP; |
478 | dSP; |
436 | ENTER; |
479 | ENTER; |
437 | SAVETMPS; |
480 | SAVETMPS; |
438 | PUSHMARK (SP); |
481 | PUSHMARK (SP); |
439 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
482 | XPUSHs (sv_2mortal (newSVpv (filename, 0))); |
440 | PUTBACK; |
483 | PUTBACK; |
441 | |
484 | |
442 | if (0 < call_pv ("cf::object_thawer_load", G_SCALAR | G_EVAL)) |
485 | if (2 == call_pv ("cf::object_thawer_load", G_ARRAY | G_EVAL)) |
443 | { |
486 | { |
444 | SPAGAIN; |
487 | SPAGAIN; |
|
|
488 | |
|
|
489 | // second value - perl objects |
|
|
490 | { |
445 | SV *sv = POPs; |
491 | SV *sv = POPs; |
446 | if (SvROK (sv)) |
492 | if (SvROK (sv)) |
447 | av = SvREFCNT_inc (SvRV (sv)); |
493 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
448 | } |
494 | } |
449 | |
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; |
450 | FREETMPS; |
511 | FREETMPS; |
451 | LEAVE; |
512 | LEAVE; |
|
|
513 | } |
452 | } |
514 | } |
453 | |
515 | |
454 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
516 | void object_thawer::get (data_type type, void *obj, attachable_base *ext, int oid) |
455 | { |
517 | { |
456 | if (!av || oid < 0) // this is actually an error of sorts |
518 | if (!av || oid < 0) // this is actually an error of sorts |
… | |
… | |
466 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
528 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
467 | return; |
529 | return; |
468 | } |
530 | } |
469 | |
531 | |
470 | ext->self = *svp; *svp = &PL_sv_undef; |
532 | ext->self = *svp; *svp = &PL_sv_undef; |
471 | 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); |
472 | |
534 | |
473 | reattach (type, obj); |
535 | reattach (type, obj); |
474 | } |
536 | } |
475 | |
537 | |
476 | object_thawer::~object_thawer () |
538 | object_thawer::~object_thawer () |
477 | { |
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 | |
478 | if (av) |
549 | if (!p) |
479 | 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 (*(unsigned char *)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; |
480 | } |
712 | } |
481 | |
713 | |
482 | ///////////////////////////////////////////////////////////////////////////// |
714 | ///////////////////////////////////////////////////////////////////////////// |
483 | |
715 | |
484 | 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) |
485 | { |
717 | { |
486 | gethook = gethooksptr; |
|
|
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 | systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); |
|
|
578 | object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); |
|
|
579 | map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); |
|
|
580 | object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); |
|
|
581 | |
|
|
582 | cf_init_plugin (gethook); |
807 | cf_init_plugin (gethook); |
583 | |
808 | |
584 | return 0; |
809 | return 0; |
585 | } |
810 | } |
586 | |
811 | |
… | |
… | |
590 | } |
815 | } |
591 | |
816 | |
592 | void |
817 | void |
593 | cfperl_init () |
818 | cfperl_init () |
594 | { |
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 | |
595 | char *argv[] = { |
826 | char *argv[] = { |
596 | "", |
827 | "", |
597 | "-e" |
828 | "-e" |
598 | "BEGIN {" |
|
|
599 | " cf->bootstrap;" |
829 | "cf->bootstrap;" |
600 | " unshift @INC, cf::datadir ();" |
830 | "unshift @INC, cf::datadir ();" |
601 | "}" |
|
|
602 | "" |
|
|
603 | "use cf;" |
831 | "require cf;" |
604 | }; |
832 | }; |
605 | |
833 | |
606 | perl = perl_alloc (); |
|
|
607 | perl_construct (perl); |
|
|
608 | |
|
|
609 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
|
|
610 | |
|
|
611 | 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)) |
612 | { |
835 | { |
613 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
836 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
614 | |
|
|
615 | exit (EXIT_FAILURE); |
837 | exit (EXIT_FAILURE); |
616 | //perl_destruct (perl); |
|
|
617 | //perl_free (perl); |
|
|
618 | //perl = 0; |
|
|
619 | //return; |
|
|
620 | } |
838 | } |
621 | |
839 | |
622 | obj_cache = newHV (); |
840 | obj_cache = newHV (); |
623 | } |
841 | } |
624 | |
842 | |
… | |
… | |
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: |
… | |
… | |
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: $ |
… | |
… | |
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, ...) |
1786 | int invoke (int event, ...) |
1563 | CODE: |
1787 | CODE: |
1564 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1788 | if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1565 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 1; i < items; i++) av_push (av, ST (i)); |
1789 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1790 | for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1566 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
1791 | RETVAL = INVOKE_((event_type)event, ARG_AV (av)); |
1567 | OUTPUT: RETVAL |
1792 | OUTPUT: RETVAL |
1568 | |
1793 | |
1569 | int |
1794 | int |
1570 | exp_to_level (val64 exp) |
1795 | exp_to_level (val64 exp) |
… | |
… | |
1603 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1828 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1604 | else |
1829 | else |
1605 | XSRETURN_UNDEF; |
1830 | XSRETURN_UNDEF; |
1606 | OUTPUT: RETVAL |
1831 | OUTPUT: RETVAL |
1607 | |
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 | |
1608 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1840 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1609 | |
1841 | |
1610 | int invoke (object *op, int event, ...) |
1842 | int invoke (object *op, int event, ...) |
1611 | CODE: |
1843 | CODE: |
1612 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1844 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1613 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); |
1845 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
1846 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1614 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
1847 | RETVAL = INVOKE_((event_type)event, ARG_OBJECT (op), ARG_AV (av)); |
1615 | OUTPUT: RETVAL |
1848 | OUTPUT: RETVAL |
1616 | |
1849 | |
1617 | SV *registry (object *op) |
1850 | SV *registry (object *op) |
1618 | CODE: |
1851 | CODE: |
1619 | RETVAL = registry_of (op); |
1852 | RETVAL = registry_of (op); |
1620 | OUTPUT: |
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: |
1621 | RETVAL |
1871 | RETVAL |
1622 | |
1872 | |
1623 | SV * |
1873 | SV * |
1624 | get_property (object *obj, int type, int idx) |
1874 | get_property (object *obj, int type, int idx) |
1625 | CODE: |
1875 | CODE: |
… | |
… | |
1705 | |
1955 | |
1706 | int need_identify (const object *obj); |
1956 | int need_identify (const object *obj); |
1707 | |
1957 | |
1708 | int apply_shop_mat (object *shop_mat, object *op); |
1958 | int apply_shop_mat (object *shop_mat, object *op); |
1709 | |
1959 | |
1710 | 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 |
1711 | |
1965 | |
1712 | void cf_object_apply (object *op, object *author, int flags = 0) |
1966 | void cf_object_apply (object *op, object *author, int flags = 0) |
1713 | |
1967 | |
1714 | void cf_object_apply_below (object *op) |
1968 | void cf_object_apply_below (object *op) |
1715 | |
1969 | |
… | |
… | |
1756 | 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) |
1757 | |
2011 | |
1758 | void cf_object_drop (object *op, object *author) |
2012 | void cf_object_drop (object *op, object *author) |
1759 | |
2013 | |
1760 | void cf_object_take (object *op, object *author) |
2014 | void cf_object_take (object *op, object *author) |
1761 | |
|
|
1762 | void cf_object_say (object *op, char *msg) |
|
|
1763 | |
|
|
1764 | void cf_object_speak (object *op, char *msg) |
|
|
1765 | |
2015 | |
1766 | object *cf_object_insert_object (object *op, object *container) |
2016 | object *cf_object_insert_object (object *op, object *container) |
1767 | |
2017 | |
1768 | const char *cf_object_get_msg (object *ob) |
2018 | const char *cf_object_get_msg (object *ob) |
1769 | ALIAS: msg = 0 |
2019 | ALIAS: msg = 0 |
… | |
… | |
1908 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2158 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
1909 | |
2159 | |
1910 | int invoke (player *pl, int event, ...) |
2160 | int invoke (player *pl, int event, ...) |
1911 | CODE: |
2161 | CODE: |
1912 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2162 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
1913 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); |
2163 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
2164 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1914 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
2165 | RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); |
1915 | OUTPUT: RETVAL |
2166 | OUTPUT: RETVAL |
1916 | |
2167 | |
1917 | SV *registry (player *pl) |
2168 | SV *registry (player *pl) |
1918 | CODE: |
2169 | CODE: |
… | |
… | |
2045 | OUTPUT: RETVAL |
2296 | OUTPUT: RETVAL |
2046 | |
2297 | |
2047 | |
2298 | |
2048 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2299 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2049 | |
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 | |
2050 | int invoke (mapstruct *map, int event, ...) |
2313 | int invoke (mapstruct *map, int event, ...) |
2051 | CODE: |
2314 | CODE: |
2052 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2315 | if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2053 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); for (int i = 2; i < items; i++) av_push (av, ST (i)); |
2316 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
2317 | for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2054 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2318 | RETVAL = INVOKE_((event_type)event, ARG_MAP (map), ARG_AV (av)); |
2055 | OUTPUT: |
2319 | OUTPUT: RETVAL |
2056 | RETVAL |
|
|
2057 | |
2320 | |
2058 | SV *registry (mapstruct *map) |
2321 | SV *registry (mapstruct *map) |
2059 | CODE: |
2322 | CODE: |
2060 | RETVAL = registry_of (map); |
2323 | RETVAL = registry_of (map); |
2061 | OUTPUT: |
2324 | OUTPUT: |
… | |
… | |
2081 | |
2344 | |
2082 | mapstruct *new (int width, int height) |
2345 | mapstruct *new (int width, int height) |
2083 | PROTOTYPE: |
2346 | PROTOTYPE: |
2084 | CODE: |
2347 | CODE: |
2085 | { |
2348 | { |
2086 | int unused_type; |
2349 | RETVAL = get_empty_map (width, height); |
2087 | RETVAL = (mapstruct*) map_get_map (&unused_type, 0, width, height); |
|
|
2088 | } |
2350 | } |
2089 | OUTPUT: |
2351 | OUTPUT: |
2090 | RETVAL |
2352 | RETVAL |
2091 | |
2353 | |
2092 | void delete_map (mapstruct *map) |
2354 | void delete_map (mapstruct *map) |
… | |
… | |
2107 | XSRETURN_UNDEF; |
2369 | XSRETURN_UNDEF; |
2108 | RETVAL = map->tile_path [dir]; |
2370 | RETVAL = map->tile_path [dir]; |
2109 | OUTPUT: |
2371 | OUTPUT: |
2110 | RETVAL |
2372 | RETVAL |
2111 | |
2373 | |
2112 | mapstruct *cf_map_get_map (char *name) |
2374 | mapstruct *ready_map_name (char *name, int flags = 0) |
2113 | PROTOTYPE: $ |
2375 | PROTOTYPE: $;$ |
2114 | ALIAS: map = 0 |
2376 | ALIAS: |
|
|
2377 | find = 0 |
|
|
2378 | get_map = 1 |
2115 | |
2379 | |
2116 | mapstruct *has_been_loaded (char *name) |
2380 | mapstruct *has_been_loaded (char *name) |
2117 | PROTOTYPE: $ |
2381 | PROTOTYPE: $ |
2118 | |
|
|
2119 | mapstruct *cf_map_get_first () |
|
|
2120 | PROTOTYPE: |
|
|
2121 | ALIAS: first = 0 |
|
|
2122 | |
2382 | |
2123 | # whoever "designed" the plug-in api should have wasted |
2383 | # whoever "designed" the plug-in api should have wasted |
2124 | # his/her time with staying away from the project - would have |
2384 | # his/her time with staying away from the project - would have |
2125 | # saved others a lot of time, without doubt. |
2385 | # saved others a lot of time, without doubt. |
2126 | void set_path (mapstruct *where, char *path) |
2386 | void set_path (mapstruct *where, char *path) |
… | |
… | |
2141 | |
2401 | |
2142 | void set_unique (mapstruct *map, bool unique) |
2402 | void set_unique (mapstruct *map, bool unique) |
2143 | CODE: |
2403 | CODE: |
2144 | map->unique = unique; |
2404 | map->unique = unique; |
2145 | |
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 | |
2146 | 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) |
2147 | |
2420 | |
2148 | 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) |
2149 | |
2422 | |
2150 | 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) |
… | |
… | |
2154 | cf_map_normalise (mapstruct *map, int x, int y) |
2427 | cf_map_normalise (mapstruct *map, int x, int y) |
2155 | PPCODE: |
2428 | PPCODE: |
2156 | { |
2429 | { |
2157 | mapstruct *nmap = 0; |
2430 | mapstruct *nmap = 0; |
2158 | I16 nx = 0, ny = 0; |
2431 | I16 nx = 0, ny = 0; |
2159 | int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2432 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2160 | |
2433 | |
2161 | EXTEND (SP, 4); |
2434 | EXTEND (SP, 4); |
2162 | PUSHs (sv_2mortal (newSViv (flags))); |
2435 | PUSHs (sv_2mortal (newSViv (flags))); |
2163 | |
2436 | |
2164 | if (GIMME_V == G_ARRAY) |
2437 | if (GIMME_V == G_ARRAY) |
… | |
… | |
2176 | { |
2449 | { |
2177 | object *o; |
2450 | object *o; |
2178 | mapstruct *nmap = 0; |
2451 | mapstruct *nmap = 0; |
2179 | I16 nx, ny; |
2452 | I16 nx, ny; |
2180 | |
2453 | |
2181 | cf_map_get_flags (map, &nmap, x, y, &nx, &ny); |
2454 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2182 | |
2455 | |
2183 | if (nmap) |
2456 | if (nmap) |
2184 | 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) |
2185 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2458 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2186 | } |
2459 | } |
… | |
… | |
2211 | 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; |
2212 | } |
2485 | } |
2213 | OUTPUT: |
2486 | OUTPUT: |
2214 | RETVAL |
2487 | RETVAL |
2215 | |
2488 | |
2216 | # "deserialise" perl map data into the map # TODO# compatibility cruft, remove |
|
|
2217 | void |
|
|
2218 | _set_obs (mapstruct *map, SV *sv) |
|
|
2219 | CODE: |
|
|
2220 | { |
|
|
2221 | object *o; |
|
|
2222 | AV *av; |
|
|
2223 | int x, y; |
|
|
2224 | AV *obs = (AV *)SvRV (sv); |
|
|
2225 | |
2489 | |
2226 | for (y = 0; y < MAP_HEIGHT (map); y++) |
2490 | MODULE = cf PACKAGE = cf::arch |
2227 | for (x = 0; x < MAP_WIDTH (map); x++) |
|
|
2228 | { |
|
|
2229 | sv = *av_fetch (obs, x + y * MAP_HEIGHT (map), 1); |
|
|
2230 | |
2491 | |
2231 | if (!SvROK (sv)) |
2492 | archetype *find (const char *name) |
2232 | continue; |
2493 | CODE: |
|
|
2494 | RETVAL = find_archetype (name); |
|
|
2495 | OUTPUT: |
|
|
2496 | RETVAL |
2233 | |
2497 | |
2234 | av = (AV *)SvRV (sv); |
2498 | archetype *first() |
2235 | |
|
|
2236 | for (o = GET_MAP_OB (map, x, y); o; o = o->above) |
|
|
2237 | { |
|
|
2238 | sv = av_shift (av); |
|
|
2239 | |
|
|
2240 | if (SvROK (sv)) |
|
|
2241 | { |
|
|
2242 | sv_magic ((SV *)SvRV (sv), 0, PERL_MAGIC_ext, (char *)o, 0); |
|
|
2243 | SVptr_cache_set (o, sv); |
|
|
2244 | } |
|
|
2245 | } |
|
|
2246 | } |
|
|
2247 | } |
|
|
2248 | |
|
|
2249 | |
|
|
2250 | MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ |
|
|
2251 | |
|
|
2252 | archetype *cf_archetype_get_first() |
|
|
2253 | PROTOTYPE: |
2499 | PROTOTYPE: |
2254 | ALIAS: first = 0 |
2500 | CODE: |
|
|
2501 | RETVAL = first_archetype; |
|
|
2502 | OUTPUT: RETVAL |
2255 | |
2503 | |
2256 | archetype *cf_archetype_get_next (archetype *arch) |
2504 | archetype *next (archetype *arch) |
2257 | ALIAS: next = 0 |
2505 | CODE: |
|
|
2506 | RETVAL = arch->next; |
|
|
2507 | OUTPUT: RETVAL |
2258 | |
2508 | |
2259 | archetype *cf_archetype_get_head (archetype *arch) |
2509 | archetype *head (archetype *arch) |
2260 | ALIAS: head = 0 |
2510 | CODE: |
|
|
2511 | RETVAL = arch->head; |
|
|
2512 | OUTPUT: RETVAL |
2261 | |
2513 | |
2262 | archetype *cf_archetype_get_more (archetype *arch) |
2514 | archetype *more (archetype *arch) |
2263 | ALIAS: more = 0 |
2515 | CODE: |
|
|
2516 | RETVAL = arch->more; |
|
|
2517 | OUTPUT: RETVAL |
2264 | |
2518 | |
2265 | const char *cf_archetype_get_name (archetype *arch) |
2519 | const char *name (archetype *arch) |
2266 | ALIAS: name = 0 |
2520 | CODE: |
|
|
2521 | RETVAL = arch->name; |
|
|
2522 | OUTPUT: RETVAL |
2267 | |
2523 | |
2268 | object *cf_archetype_get_clone (archetype *arch) |
2524 | object *clone (archetype *arch) |
2269 | ALIAS: clone = 0 |
2525 | CODE: |
|
|
2526 | RETVAL = &arch->clone; |
|
|
2527 | OUTPUT: RETVAL |
2270 | |
2528 | |
2271 | MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ |
2529 | MODULE = cf PACKAGE = cf::party |
2272 | |
2530 | |
2273 | partylist *cf_party_get_first () |
2531 | partylist *first () |
2274 | PROTOTYPE: |
2532 | PROTOTYPE: |
2275 | ALIAS: first = 0 |
2533 | CODE: |
|
|
2534 | RETVAL = get_firstparty (); |
|
|
2535 | OUTPUT: RETVAL |
2276 | |
2536 | |
2277 | partylist *cf_party_get_next (partylist *party) |
2537 | partylist *next (partylist *party) |
2278 | ALIAS: next = 0 |
2538 | CODE: |
|
|
2539 | RETVAL = party->next; |
|
|
2540 | OUTPUT: RETVAL |
2279 | |
2541 | |
2280 | const char *cf_party_get_name (partylist *party) |
2542 | const char *name (partylist *party) |
|
|
2543 | CODE: |
|
|
2544 | RETVAL = party->partyname; |
|
|
2545 | OUTPUT: RETVAL |
2281 | |
2546 | |
2282 | const char *cf_party_get_password (partylist *party) |
2547 | const char *password (partylist *party) |
2283 | ALIAS: password = 0 |
2548 | CODE: |
|
|
2549 | RETVAL = party->passwd; |
|
|
2550 | OUTPUT: RETVAL |
2284 | |
2551 | |
2285 | player *cf_party_get_first_player (partylist *party) |
2552 | MODULE = cf PACKAGE = cf::region |
2286 | ALIAS: first_player = 0 |
|
|
2287 | |
2553 | |
2288 | player *cf_party_get_next_player (partylist *party, player *op) |
2554 | region *first () |
2289 | ALIAS: next_player = 0 |
|
|
2290 | |
|
|
2291 | |
|
|
2292 | MODULE = cf PACKAGE = cf::region PREFIX = cf_region_ |
|
|
2293 | |
|
|
2294 | region *cf_region_get_first () |
|
|
2295 | PROTOTYPE: |
2555 | PROTOTYPE: |
2296 | ALIAS: first = 0 |
2556 | CODE: |
|
|
2557 | RETVAL = first_region; |
|
|
2558 | OUTPUT: RETVAL |
2297 | |
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 | |
2298 | const char *cf_region_get_name (region *reg) |
2575 | const char *longname (region *reg) |
2299 | ALIAS: name = 0 |
2576 | CODE: |
|
|
2577 | RETVAL = reg->longname; |
|
|
2578 | OUTPUT: RETVAL |
2300 | |
2579 | |
2301 | region *cf_region_get_next (region *reg) |
2580 | const char *msg (region *reg) |
2302 | ALIAS: next = 0 |
2581 | CODE: |
|
|
2582 | RETVAL = reg->msg; |
|
|
2583 | OUTPUT: RETVAL |
2303 | |
2584 | |
2304 | region *cf_region_get_parent (region *reg) |
2585 | MODULE = cf PACKAGE = cf::living |
2305 | ALIAS: parent = 0 |
|
|
2306 | |
|
|
2307 | const char *cf_region_get_longname (region *reg) |
|
|
2308 | ALIAS: longname = 0 |
|
|
2309 | |
|
|
2310 | const char *cf_region_get_message (region *reg) |
|
|
2311 | ALIAS: message = 0 |
|
|
2312 | |
|
|
2313 | |
|
|
2314 | MODULE = cf PACKAGE = cf::living PREFIX = cf_living_ |
|
|
2315 | |
2586 | |
2316 | val64 |
2587 | val64 |
2317 | exp (living *liv, val64 new_val = 0) |
2588 | exp (living *liv, val64 new_val = 0) |
2318 | PROTOTYPE: $;$ |
2589 | PROTOTYPE: $;$ |
2319 | ALIAS: |
2590 | ALIAS: |