1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2006,2007,2008,2009,2010,2012,2015 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
6 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
10 | * option) any later version. |
10 | * |
11 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
15 | * |
16 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
19 | * <http://www.gnu.org/licenses/>. |
19 | * |
20 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
22 | */ |
22 | |
23 | |
23 | #include "autoconf.h" |
24 | #include "autoconf.h" |
|
|
25 | |
|
|
26 | #define CFPERL 1 |
24 | |
27 | |
25 | #if HAVE_EXECINFO_H |
28 | #if HAVE_EXECINFO_H |
26 | # include <execinfo.h> |
29 | # include <execinfo.h> |
27 | #endif |
30 | #endif |
28 | |
31 | |
29 | #include <cstdarg> |
32 | #include <cstdarg> |
30 | #include <typeinfo> |
33 | #include <typeinfo> |
31 | |
34 | |
32 | #include "global.h" |
35 | #include "global.h" |
33 | #include "../random_maps/random_map.h" |
36 | #include "rmg.h" |
|
|
37 | #include "noise.h" |
34 | #include "evthread.h" |
38 | #include "evthread.h" |
35 | #include "sproto.h" |
39 | #include "sproto.h" |
36 | |
40 | |
37 | #include <unistd.h> |
41 | #include <unistd.h> |
38 | #if _POSIX_MEMLOCK |
42 | #if _POSIX_MEMLOCK |
… | |
… | |
66 | static int tick_inhibit; |
70 | static int tick_inhibit; |
67 | static int tick_pending; |
71 | static int tick_pending; |
68 | |
72 | |
69 | global gbl_ev; |
73 | global gbl_ev; |
70 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
74 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
71 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
75 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick; |
72 | static AV *av_reflect; |
76 | static AV *av_reflect; |
73 | |
77 | |
74 | bitset<NUM_EVENT_TYPES> ev_want_event; |
78 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_TYPES> ev_want_type; |
79 | bitset<NUM_TYPES> ev_want_type; |
76 | |
80 | |
… | |
… | |
84 | *stash_cf_client_wrap, |
88 | *stash_cf_client_wrap, |
85 | *stash_cf_arch_wrap, |
89 | *stash_cf_arch_wrap, |
86 | *stash_cf_party_wrap, |
90 | *stash_cf_party_wrap, |
87 | *stash_cf_region_wrap, |
91 | *stash_cf_region_wrap, |
88 | *stash_cf_living_wrap, |
92 | *stash_cf_living_wrap, |
|
|
93 | *stash_cf_layout_wrap, |
89 | *stash_ext_map_world; |
94 | *stash_ext_map_world; |
90 | |
95 | |
91 | static SV |
96 | static SV |
92 | *cv_cf_do_invoke, |
97 | *cv_cf_do_invoke, |
93 | *cv_cf__can_merge, |
98 | *cv_cf__can_merge, |
94 | *cv_cf_client_send_msg, |
99 | *cv_cf_client_send_msg, |
|
|
100 | *cv_cf_ix, |
95 | *cv_cf_tick, |
101 | *cv_cf_tick, |
96 | *cv_cf_match_match; |
102 | *cv_cf_match_match; |
97 | |
103 | |
98 | #ifndef newSVpv_utf8 |
104 | #ifndef newSVpv_utf8 |
99 | static SV * |
105 | static SV * |
… | |
… | |
122 | |
128 | |
123 | return sv; |
129 | return sv; |
124 | } |
130 | } |
125 | #endif |
131 | #endif |
126 | |
132 | |
127 | noinline utf8_string |
133 | ecb_noinline utf8_string |
128 | cfSvPVutf8_nolen (SV *sv) |
134 | cfSvPVutf8_nolen (SV *sv) |
129 | { |
135 | { |
130 | SvGETMAGIC (sv); |
136 | SvGETMAGIC (sv); |
131 | |
137 | |
132 | if (SvPOK (sv)) |
138 | if (SvPOK (sv)) |
… | |
… | |
251 | { |
257 | { |
252 | static int last_mortalcount; |
258 | static int last_mortalcount; |
253 | if (mortals.size () != last_mortalcount) |
259 | if (mortals.size () != last_mortalcount) |
254 | { |
260 | { |
255 | last_mortalcount = mortals.size (); |
261 | last_mortalcount = mortals.size (); |
256 | LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); |
262 | object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
|
|
263 | |
|
|
264 | LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
|
|
265 | (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
257 | |
266 | |
258 | if (0) |
267 | if (0) |
259 | { |
268 | { |
260 | for (int j = 0; j < mortals.size (); ++j)//D |
269 | for (int j = 0; j < mortals.size (); ++j)//D |
261 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
270 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
… | |
… | |
361 | |
370 | |
362 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
371 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
363 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
372 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
364 | } |
373 | } |
365 | |
374 | |
366 | static SV * noinline |
375 | ecb_noinline static SV * |
367 | newSVptr (void *ptr, HV *stash) |
376 | newSVptr (void *ptr, HV *stash) |
368 | { |
377 | { |
369 | return newSVptr (ptr, stash, newHV ()); |
378 | return newSVptr (ptr, stash, newHV ()); |
370 | } |
379 | } |
371 | |
380 | |
… | |
… | |
386 | return 0; |
395 | return 0; |
387 | } |
396 | } |
388 | |
397 | |
389 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
398 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
390 | |
399 | |
391 | static SV * noinline |
400 | ecb_noinline static SV * |
392 | newSVattachable (attachable *obj, HV *stash) |
401 | newSVattachable (attachable *obj, HV *stash) |
393 | { |
402 | { |
394 | if (!obj) |
403 | if (!obj) |
395 | return newSV (0); |
404 | return newSV (0); |
396 | |
405 | |
… | |
… | |
450 | croak ("object of type %s expected", klass); |
459 | croak ("object of type %s expected", klass); |
451 | |
460 | |
452 | return SvPTR_nc (sv); |
461 | return SvPTR_nc (sv); |
453 | } |
462 | } |
454 | |
463 | |
455 | static long noinline |
464 | ecb_noinline static long |
456 | SvPTR_ornull (SV *sv, const char *klass) |
465 | SvPTR_ornull (SV *sv, const char *klass) |
457 | { |
466 | { |
458 | if (expect_false (!SvOK (sv))) return 0; |
467 | if (expect_false (!SvOK (sv))) return 0; |
459 | |
468 | |
460 | return SvPTR (sv, klass); |
469 | return SvPTR (sv, klass); |
461 | } |
470 | } |
462 | |
471 | |
463 | static long noinline |
472 | ecb_noinline static long |
464 | SvPTR_ornull_client (SV *sv) |
473 | SvPTR_ornull_client (SV *sv) |
465 | { |
474 | { |
466 | if (expect_false (!SvOK (sv))) return 0; |
475 | if (expect_false (!SvOK (sv))) return 0; |
467 | |
476 | |
468 | if (!SvROK (sv) |
477 | if (!SvROK (sv) |
… | |
… | |
471 | croak ("object of type cf::client expected"); |
480 | croak ("object of type cf::client expected"); |
472 | |
481 | |
473 | return SvPTR_nc (sv); |
482 | return SvPTR_nc (sv); |
474 | } |
483 | } |
475 | |
484 | |
476 | static long noinline |
485 | ecb_noinline static long |
477 | SvPTR_ornull_object (SV *sv) |
486 | SvPTR_ornull_object (SV *sv) |
478 | { |
487 | { |
479 | if (expect_false (!SvOK (sv))) return 0; |
488 | if (expect_false (!SvOK (sv))) return 0; |
480 | |
489 | |
481 | if (!SvROK (sv) |
490 | if (!SvROK (sv) |
… | |
… | |
486 | croak ("object of type cf::object expected"); |
495 | croak ("object of type cf::object expected"); |
487 | |
496 | |
488 | return SvPTR_nc (sv); |
497 | return SvPTR_nc (sv); |
489 | } |
498 | } |
490 | |
499 | |
491 | static long noinline |
500 | ecb_noinline static long |
492 | SvPTR_ornull_maptile (SV *sv) |
501 | SvPTR_ornull_maptile (SV *sv) |
493 | { |
502 | { |
494 | if (expect_false (!SvOK (sv))) return 0; |
503 | if (expect_false (!SvOK (sv))) return 0; |
495 | |
504 | |
496 | if (!SvROK (sv) |
505 | if (!SvROK (sv) |
… | |
… | |
500 | croak ("object of type cf::map expected"); |
509 | croak ("object of type cf::map expected"); |
501 | |
510 | |
502 | return SvPTR_nc (sv); |
511 | return SvPTR_nc (sv); |
503 | } |
512 | } |
504 | |
513 | |
505 | static long noinline |
514 | ecb_noinline static long |
506 | SvPTR_ornull_player (SV *sv) |
515 | SvPTR_ornull_player (SV *sv) |
507 | { |
516 | { |
508 | if (expect_false (!SvOK (sv))) return 0; |
517 | if (expect_false (!SvOK (sv))) return 0; |
509 | |
518 | |
510 | if (!SvROK (sv) |
519 | if (!SvROK (sv) |
… | |
… | |
530 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
539 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
531 | static inline SV *to_sv (float v) { return newSVnv (v); } |
540 | static inline SV *to_sv (float v) { return newSVnv (v); } |
532 | static inline SV *to_sv (double v) { return newSVnv (v); } |
541 | static inline SV *to_sv (double v) { return newSVnv (v); } |
533 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
542 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
534 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
543 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
535 | // gcc dislikes noilnine on to_sv |
544 | // gcc dislikes noinline on to_sv |
536 | static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
545 | ecb_noinline static SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
537 | static inline SV *to_sv (object * v) { return to_sv_ni (v); } |
546 | static inline SV *to_sv (object * v) { return to_sv_ni (v); } |
538 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
547 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
539 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
548 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
540 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
549 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
541 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
550 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
542 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
551 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
543 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
552 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
|
|
553 | static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); } |
544 | |
554 | |
545 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
555 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
546 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
556 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
547 | |
557 | |
548 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
558 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
… | |
… | |
594 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
604 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
595 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
605 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
596 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
606 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
597 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
607 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
598 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
608 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
|
|
609 | static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); } |
599 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
610 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
600 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
611 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
601 | |
612 | |
602 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
613 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
603 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
614 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
… | |
… | |
616 | static inline void sv_to (SV *sv, std::string &v) |
627 | static inline void sv_to (SV *sv, std::string &v) |
617 | { |
628 | { |
618 | STRLEN len; |
629 | STRLEN len; |
619 | char *data = SvPVbyte (sv, len); |
630 | char *data = SvPVbyte (sv, len); |
620 | v.assign (data, len); |
631 | v.assign (data, len); |
|
|
632 | } |
|
|
633 | |
|
|
634 | static inline void sv_to (SV *sv, refcnt_buf &v) |
|
|
635 | { |
|
|
636 | STRLEN len; |
|
|
637 | char *data = SvPVbyte (sv, len); |
|
|
638 | refcnt_buf buf (data, len); |
|
|
639 | v = buf; |
621 | } |
640 | } |
622 | |
641 | |
623 | static inline void sv_to (SV *sv, UUID &v) |
642 | static inline void sv_to (SV *sv, UUID &v) |
624 | { |
643 | { |
625 | if (!v.parse (SvPV_nolen (sv))) |
644 | if (!v.parse (SvPV_nolen (sv))) |
… | |
… | |
710 | return sv; |
729 | return sv; |
711 | } |
730 | } |
712 | |
731 | |
713 | // typemap support, mostly to avoid excessive inlining |
732 | // typemap support, mostly to avoid excessive inlining |
714 | template<class type> |
733 | template<class type> |
715 | static void noinline |
734 | ecb_noinline static void |
716 | cf_obj_to (SV *arg, type &var) |
735 | cf_obj_to (SV *arg, type &var) |
717 | { |
736 | { |
718 | sv_to (arg, var); |
737 | sv_to (arg, var); |
719 | if (expect_false (!var)) |
738 | if (expect_false (!var)) |
720 | croak ("must not pass invalid/null cf_obj here"); |
739 | croak ("must not pass invalid/null cf_obj here"); |
721 | } |
740 | } |
722 | |
741 | |
723 | template<class object> |
742 | template<class object> |
724 | static void noinline |
743 | ecb_noinline static void |
725 | cf_obj_ornull_to (SV *arg, object *&var) |
744 | cf_obj_ornull_to (SV *arg, object *&var) |
726 | { |
745 | { |
727 | if (SvOK (arg)) |
746 | if (SvOK (arg)) |
728 | { |
747 | { |
729 | sv_to (arg, var); |
748 | sv_to (arg, var); |
… | |
… | |
821 | # undef def |
840 | # undef def |
822 | }; |
841 | }; |
823 | |
842 | |
824 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
843 | #define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
825 | |
844 | |
826 | static void noinline |
845 | ecb_noinline static void |
827 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
846 | gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
828 | { |
847 | { |
829 | // event must be in array |
848 | // event must be in array |
830 | if (event >= 0 && event <= AvFILLp (registry)) |
849 | if (event >= 0 && event <= AvFILLp (registry)) |
831 | { |
850 | { |
… | |
… | |
917 | { |
936 | { |
918 | attachable::gather_callbacks (callbacks, event); |
937 | attachable::gather_callbacks (callbacks, event); |
919 | ::gather_callbacks (callbacks, cb_map, event); |
938 | ::gather_callbacks (callbacks, cb_map, event); |
920 | } |
939 | } |
921 | |
940 | |
922 | static void noinline |
941 | ecb_noinline static void |
923 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
942 | _recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
924 | { |
943 | { |
925 | for (int event = 0; event <= AvFILLp (registry); ++event) |
944 | for (int event = 0; event <= AvFILLp (registry); ++event) |
926 | { |
945 | { |
927 | SV *cbs_ = AvARRAY (registry)[event]; |
946 | SV *cbs_ = AvARRAY (registry)[event]; |
… | |
… | |
1142 | CALL_ARG (originator); |
1161 | CALL_ARG (originator); |
1143 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1162 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1144 | CALL_END; |
1163 | CALL_END; |
1145 | } |
1164 | } |
1146 | |
1165 | |
|
|
1166 | void cfperl_ix (client *ns, int set, faceidx idx, int pri) |
|
|
1167 | { |
|
|
1168 | CALL_BEGIN (3); |
|
|
1169 | CALL_ARG (ns); |
|
|
1170 | CALL_ARG (set); |
|
|
1171 | CALL_ARG (idx); |
|
|
1172 | CALL_ARG (pri); |
|
|
1173 | CALL_CALL (cv_cf_ix, G_VOID); |
|
|
1174 | CALL_END; |
|
|
1175 | } |
|
|
1176 | |
1147 | player * |
1177 | player * |
1148 | player::find (const_utf8_string name) |
1178 | player::find (const_utf8_string name) |
1149 | { |
1179 | { |
1150 | CALL_BEGIN (1); |
1180 | CALL_BEGIN (1); |
1151 | CALL_ARG (name); |
1181 | CALL_ARG (name); |
… | |
… | |
1245 | CALL_ARG (y); |
1275 | CALL_ARG (y); |
1246 | CALL_CALL ("cf::object::player::goto", G_VOID); |
1276 | CALL_CALL ("cf::object::player::goto", G_VOID); |
1247 | CALL_END; |
1277 | CALL_END; |
1248 | } |
1278 | } |
1249 | |
1279 | |
1250 | const_utf8_string |
1280 | const_utf8_string |
1251 | object::ref () const |
1281 | object::ref () const |
1252 | { |
1282 | { |
1253 | if (type == PLAYER) |
1283 | if (type == PLAYER) |
1254 | return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); |
1284 | return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); |
1255 | else |
1285 | else |
… | |
… | |
1397 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1427 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1398 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1428 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1399 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1429 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1400 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1430 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1401 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1431 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
|
|
1432 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1402 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1433 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1403 | |
1434 | |
1404 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1435 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1405 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1436 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1437 | sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1406 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1438 | sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV); |
1407 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1439 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1408 | |
1440 | |
1409 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1441 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1410 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1442 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1411 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1443 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1412 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1444 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1419 | _connect_to_perl_2 () |
1451 | _connect_to_perl_2 () |
1420 | { |
1452 | { |
1421 | cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
1453 | cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
1422 | cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
1454 | cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
1423 | cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
1455 | cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
|
|
1456 | cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix); |
1424 | cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
1457 | cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
1425 | cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
1458 | cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
1426 | } |
1459 | } |
1427 | |
1460 | |
1428 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1461 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
… | |
… | |
1433 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1466 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1434 | |
1467 | |
1435 | _connect_to_perl_1 (); |
1468 | _connect_to_perl_1 (); |
1436 | |
1469 | |
1437 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1470 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1438 | |
|
|
1439 | //{ |
|
|
1440 | // require_pv ("Time::HiRes"); |
|
|
1441 | // |
|
|
1442 | // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
|
|
1443 | // if (!svp) croak ("Time::HiRes is required"); |
|
|
1444 | // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); |
|
|
1445 | // coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); |
|
|
1446 | //} |
|
|
1447 | |
1471 | |
1448 | static const struct { |
1472 | static const struct { |
1449 | const char *name; |
1473 | const char *name; |
1450 | IV iv; |
1474 | IV iv; |
1451 | } *civ, const_iv[] = { |
1475 | } *civ, const_iv[] = { |
… | |
… | |
1455 | # include "attackinc.h" |
1479 | # include "attackinc.h" |
1456 | # undef def |
1480 | # undef def |
1457 | # define def(uc, flags) const_iv (SK_ ## uc) |
1481 | # define def(uc, flags) const_iv (SK_ ## uc) |
1458 | # include "skillinc.h" |
1482 | # include "skillinc.h" |
1459 | # undef def |
1483 | # undef def |
1460 | |
1484 | # define def(name, use, nonuse) const_iv (body_ ## name) |
1461 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1485 | # include "slotinc.h" |
|
|
1486 | # undef def |
1462 | |
1487 | |
1463 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1488 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1464 | |
1489 | |
1465 | const_iv (MAX_TIME) |
1490 | const_iv (MAX_TIME) |
1466 | const_iv (MAXSOCKBUF) |
1491 | const_iv (MAXSOCKBUF) |
… | |
… | |
1480 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1505 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1481 | |
1506 | |
1482 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1507 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1483 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1508 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1484 | |
1509 | |
1485 | const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
|
|
1486 | const_iv (MAP_INACTIVE) |
|
|
1487 | |
|
|
1488 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1510 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1489 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1511 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1490 | |
1512 | |
1491 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1513 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1492 | |
1514 | |
1493 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1515 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1494 | }; |
1516 | }; |
1495 | |
1517 | |
1496 | for (civ = const_iv + array_length (const_iv); civ-- > const_iv; ) |
1518 | for (civ = const_iv + ecb_array_length (const_iv); civ-- > const_iv; ) |
1497 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1519 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1498 | |
1520 | |
1499 | static const struct { |
1521 | static const struct { |
1500 | const char *name; |
1522 | const char *name; |
1501 | int skip; |
1523 | int skip; |
… | |
… | |
1507 | # undef def |
1529 | # undef def |
1508 | }; |
1530 | }; |
1509 | |
1531 | |
1510 | AV *av = get_av ("cf::EVENT", 1); |
1532 | AV *av = get_av ("cf::EVENT", 1); |
1511 | |
1533 | |
1512 | for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; ) |
1534 | for (eiv = event_iv + ecb_array_length (event_iv); eiv-- > event_iv; ) |
1513 | { |
1535 | { |
1514 | AV *event = newAV (); |
1536 | AV *event = newAV (); |
1515 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1537 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1516 | av_push (event, newSViv (eiv->klass)); |
1538 | av_push (event, newSViv (eiv->klass)); |
1517 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1539 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
… | |
… | |
1524 | |
1546 | |
1525 | void _gv_clear (SV *gv) |
1547 | void _gv_clear (SV *gv) |
1526 | CODE: |
1548 | CODE: |
1527 | assert (SvTYPE (gv) == SVt_PVGV); |
1549 | assert (SvTYPE (gv) == SVt_PVGV); |
1528 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
1550 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
|
|
1551 | SvREFCNT_inc (gv); |
1529 | f (GvGP (gv)->gp_form); |
1552 | f (GvGP (gv)->gp_form); |
1530 | f (GvGP (gv)->gp_io); |
1553 | f (GvGP (gv)->gp_io); |
1531 | f (GvGP (gv)->gp_sv); |
1554 | f (GvGP (gv)->gp_sv); |
1532 | f (GvGP (gv)->gp_av); |
1555 | f (GvGP (gv)->gp_av); |
1533 | f (GvGP (gv)->gp_hv); |
1556 | f (GvGP (gv)->gp_hv); |
1534 | f (GvGP (gv)->gp_cv); |
1557 | f (GvGP (gv)->gp_cv); |
1535 | GvCVGEN (gv) = 0; |
1558 | GvCVGEN (gv) = 0; |
1536 | GvMULTI_off (gv); |
1559 | GvMULTI_off (gv); |
|
|
1560 | SvREFCNT_dec (gv); |
1537 | # undef f |
1561 | # undef f |
1538 | |
1562 | |
1539 | void _connect_to_perl_1 () |
1563 | void _connect_to_perl_1 () |
1540 | |
1564 | |
1541 | void _connect_to_perl_2 () |
1565 | void _connect_to_perl_2 () |
… | |
… | |
1552 | |
1576 | |
1553 | for_all_objects (op) |
1577 | for_all_objects (op) |
1554 | op->reattach (); |
1578 | op->reattach (); |
1555 | } |
1579 | } |
1556 | |
1580 | |
1557 | # support function for map-world.ext |
|
|
1558 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1559 | CODE: |
|
|
1560 | { |
|
|
1561 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1562 | croak ("_quantise called with invalid agruments"); |
|
|
1563 | |
|
|
1564 | plt_sv = SvRV (plt_sv); |
|
|
1565 | SV **plt = AvARRAY (plt_sv); |
|
|
1566 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1567 | |
|
|
1568 | STRLEN len; |
|
|
1569 | char *data = SvPVbyte (data_sv, len); |
|
|
1570 | char *dst = data; |
|
|
1571 | |
|
|
1572 | while (len >= 3) |
|
|
1573 | { |
|
|
1574 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1575 | { |
|
|
1576 | char *val = SvPVX (*val_sv); |
|
|
1577 | |
|
|
1578 | if (val [0] == data [0] |
|
|
1579 | && val [1] == data [1] |
|
|
1580 | && val [2] == data [2]) |
|
|
1581 | { |
|
|
1582 | *dst++ = val [3]; |
|
|
1583 | goto next; |
|
|
1584 | } |
|
|
1585 | } |
|
|
1586 | |
|
|
1587 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1588 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1589 | dst - SvPVX (data_sv), len); |
|
|
1590 | |
|
|
1591 | next: |
|
|
1592 | data += 3; |
|
|
1593 | len -= 3; |
|
|
1594 | } |
|
|
1595 | |
|
|
1596 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1597 | } |
|
|
1598 | |
|
|
1599 | void init_anim () |
1581 | void init_anim () |
1600 | |
1582 | |
1601 | void init_globals () |
1583 | void init_globals () |
1602 | |
1584 | |
1603 | void init_attackmess () |
1585 | void init_attackmess () |
1604 | |
1586 | |
1605 | void init_dynamic () |
1587 | void init_dynamic () |
1606 | |
1588 | |
1607 | void load_settings () |
1589 | void load_settings () |
1608 | |
1590 | |
1609 | void reload_exp_table () |
1591 | void _reload_exp_table () |
1610 | |
1592 | |
1611 | void reload_materials () |
1593 | void _reload_materials () |
1612 | |
1594 | |
1613 | void init_uuid () |
1595 | void init_uuid () |
1614 | CODE: |
1596 | CODE: |
1615 | UUID::init (); |
1597 | UUID::init (); |
1616 | |
1598 | |
… | |
… | |
1627 | coroapi::cede_to_tick (); |
1609 | coroapi::cede_to_tick (); |
1628 | |
1610 | |
1629 | NV till_tick () |
1611 | NV till_tick () |
1630 | CODE: |
1612 | CODE: |
1631 | RETVAL = SvNVX (sv_next_tick) - now (); |
1613 | RETVAL = SvNVX (sv_next_tick) - now (); |
1632 | OUTPUT: |
1614 | OUTPUT: RETVAL |
1633 | RETVAL |
|
|
1634 | |
1615 | |
1635 | int tick_inhibit () |
1616 | int tick_inhibit () |
1636 | CODE: |
1617 | CODE: |
1637 | RETVAL = tick_inhibit; |
1618 | RETVAL = tick_inhibit; |
1638 | OUTPUT: |
1619 | OUTPUT: RETVAL |
1639 | RETVAL |
|
|
1640 | |
1620 | |
1641 | void tick_inhibit_inc () |
1621 | void tick_inhibit_inc () |
1642 | CODE: |
1622 | CODE: |
1643 | ++tick_inhibit; |
1623 | ++tick_inhibit; |
1644 | |
1624 | |
… | |
… | |
1649 | { |
1629 | { |
1650 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1630 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1651 | coroapi::cede (); |
1631 | coroapi::cede (); |
1652 | } |
1632 | } |
1653 | |
1633 | |
1654 | void server_tick () |
1634 | void one_tick () |
1655 | CODE: |
1635 | CODE: |
1656 | { |
1636 | { |
1657 | ev_now_update (EV_DEFAULT); |
1637 | ev_now_update (EV_DEFAULT); |
1658 | NOW = ev_now (EV_DEFAULT); |
1638 | NOW = ev_now (EV_DEFAULT); |
1659 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1639 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1660 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1640 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1661 | runtime = SvNVX (sv_runtime); |
1641 | runtime = SvNVX (sv_runtime); |
1662 | |
1642 | |
|
|
1643 | one_tick (); |
|
|
1644 | |
1663 | server_tick (); |
1645 | ++server_tick; |
|
|
1646 | SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1664 | |
1647 | |
1665 | ev_now_update (EV_DEFAULT); |
1648 | ev_now_update (EV_DEFAULT); |
1666 | NOW = ev_now (EV_DEFAULT); |
1649 | NOW = ev_now (EV_DEFAULT); |
1667 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1650 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1651 | |
1668 | runtime += TICK; |
1652 | runtime += TICK; |
1669 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1653 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1670 | } |
1654 | } |
1671 | |
1655 | |
1672 | NV floor (NV x) |
1656 | NV floor (NV x) |
… | |
… | |
1676 | NV rndm (...) |
1660 | NV rndm (...) |
1677 | ALIAS: |
1661 | ALIAS: |
1678 | rmg_rndm = 1 |
1662 | rmg_rndm = 1 |
1679 | CODE: |
1663 | CODE: |
1680 | { |
1664 | { |
1681 | rand_gen &gen = ix ? rmg_rndm : rndm; |
1665 | rand_gen &gen = ix ? rmg_rndm : rndm; |
1682 | switch (items) |
1666 | switch (items) |
1683 | { |
1667 | { |
1684 | case 0: RETVAL = gen (); break; |
1668 | case 0: RETVAL = gen (); break; |
1685 | case 1: RETVAL = gen (SvUV (ST (0))); break; |
1669 | case 1: RETVAL = gen (SvUV (ST (0))); break; |
1686 | case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; |
1670 | case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; |
1687 | default: croak ("cf::rndm requires zero, one or two parameters."); break; |
1671 | default: croak ("cf::rndm requires zero, one or two parameters."); break; |
1688 | } |
1672 | } |
1689 | } |
1673 | } |
1690 | OUTPUT: |
1674 | OUTPUT: RETVAL |
1691 | RETVAL |
|
|
1692 | |
1675 | |
1693 | NV clamp (NV value, NV min_value, NV max_value) |
1676 | NV clamp (NV value, NV min_value, NV max_value) |
1694 | CODE: |
1677 | CODE: |
1695 | RETVAL = clamp (value, min_value, max_value); |
1678 | RETVAL = clamp (value, min_value, max_value); |
1696 | OUTPUT: |
1679 | OUTPUT: RETVAL |
1697 | RETVAL |
|
|
1698 | |
1680 | |
1699 | NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) |
1681 | NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) |
1700 | CODE: |
1682 | CODE: |
1701 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
1683 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
1702 | OUTPUT: |
1684 | OUTPUT: RETVAL |
1703 | RETVAL |
|
|
1704 | |
1685 | |
1705 | const char *ordinal (int i) |
1686 | const char *ordinal (int i) |
1706 | |
1687 | |
1707 | void weaken (...) |
1688 | void weaken (...) |
1708 | PROTOTYPE: @ |
1689 | PROTOTYPE: @ |
… | |
… | |
1771 | |
1752 | |
1772 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1753 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1773 | INIT: |
1754 | INIT: |
1774 | #if __GLIBC__ |
1755 | #if __GLIBC__ |
1775 | mallopt (M_TOP_PAD, 1024 * 1024); |
1756 | mallopt (M_TOP_PAD, 1024 * 1024); |
1776 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); |
1757 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024); |
1777 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
1758 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
|
|
1759 | if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10)) |
1778 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1760 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1779 | #endif |
1761 | #endif |
1780 | |
1762 | |
1781 | int munlockall () |
1763 | int munlockall () |
1782 | |
1764 | |
1783 | #endif |
1765 | #endif |
… | |
… | |
1806 | EXTEND (SP, 5*2); |
1788 | EXTEND (SP, 5*2); |
1807 | PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
1789 | PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
1808 | PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
1790 | PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
1809 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1791 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1810 | PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
1792 | PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
1811 | PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); |
|
|
1812 | } |
1793 | } |
1813 | |
|
|
1814 | int find_animation (utf8_string text) |
|
|
1815 | PROTOTYPE: $ |
|
|
1816 | |
1794 | |
1817 | int random_roll (int min, int max, object *op, int goodbad); |
1795 | int random_roll (int min, int max, object *op, int goodbad); |
1818 | |
1796 | |
1819 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1797 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1820 | |
1798 | |
1821 | int exp_to_level (val64 exp) |
1799 | int exp_to_level (val64 exp) |
1822 | |
1800 | |
1823 | val64 level_to_min_exp (int level) |
1801 | val64 level_to_min_exp (int level) |
1824 | |
1802 | |
|
|
1803 | const_utf8_string |
|
|
1804 | spellpathnames (int idx) |
|
|
1805 | CODE: |
|
|
1806 | RETVAL = spellpathnames [idx]; |
|
|
1807 | OUTPUT: RETVAL |
|
|
1808 | |
1825 | SV * |
1809 | SV * |
1826 | resistance_to_string (int atnr) |
1810 | attacktype_name (int atnr) |
1827 | CODE: |
1811 | CODE: |
1828 | if (atnr >= 0 && atnr < NROFATTACKS) |
1812 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1829 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1813 | ? newSVpv (attacktype_name [atnr], 0) |
1830 | else |
1814 | : &PL_sv_undef; |
1831 | XSRETURN_UNDEF; |
|
|
1832 | OUTPUT: RETVAL |
1815 | OUTPUT: RETVAL |
|
|
1816 | |
|
|
1817 | SV * |
|
|
1818 | attacktype_desc (int atnr) |
|
|
1819 | CODE: |
|
|
1820 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1821 | ? newSVpv (attacktype_desc [atnr], 0) |
|
|
1822 | : &PL_sv_undef; |
|
|
1823 | OUTPUT: RETVAL |
|
|
1824 | |
|
|
1825 | SV * |
|
|
1826 | resist_plus (int atnr) |
|
|
1827 | CODE: |
|
|
1828 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1829 | ? newSVpv (resist_plus [atnr], 0) |
|
|
1830 | : &PL_sv_undef; |
|
|
1831 | OUTPUT: RETVAL |
|
|
1832 | |
|
|
1833 | SV * |
|
|
1834 | change_resist_msg (int atnr) |
|
|
1835 | CODE: |
|
|
1836 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1837 | ? newSVpv (change_resist_msg [atnr], 0) |
|
|
1838 | : &PL_sv_undef; |
|
|
1839 | OUTPUT: RETVAL |
|
|
1840 | |
|
|
1841 | int |
|
|
1842 | skill_flags (int idx) |
|
|
1843 | CODE: |
|
|
1844 | if (idx < 0 || idx >= ecb_array_length (skill_flags)) |
|
|
1845 | croak ("skill_flags: index out of bounds"); |
|
|
1846 | RETVAL = skill_flags [idx]; |
|
|
1847 | OUTPUT: RETVAL |
1833 | |
1848 | |
1834 | UUID |
1849 | UUID |
1835 | uuid_cur () |
1850 | uuid_cur () |
1836 | CODE: |
1851 | CODE: |
1837 | RETVAL = UUID::cur; |
1852 | RETVAL = UUID::cur; |
1838 | OUTPUT: |
1853 | OUTPUT: RETVAL |
1839 | RETVAL |
|
|
1840 | |
1854 | |
1841 | UUID |
1855 | UUID |
1842 | uuid_gen () |
1856 | uuid_gen () |
1843 | CODE: |
1857 | CODE: |
1844 | RETVAL = UUID::gen (); |
1858 | RETVAL = UUID::gen (); |
1845 | OUTPUT: |
1859 | OUTPUT: RETVAL |
1846 | RETVAL |
|
|
1847 | |
1860 | |
1848 | val64 |
1861 | val64 |
1849 | uuid_seq (UUID uuid) |
1862 | uuid_seq (UUID uuid) |
1850 | CODE: |
1863 | CODE: |
1851 | RETVAL = uuid.seq; |
1864 | RETVAL = uuid.seq; |
1852 | OUTPUT: |
1865 | OUTPUT: RETVAL |
1853 | RETVAL |
|
|
1854 | |
1866 | |
1855 | UUID |
1867 | UUID |
1856 | uuid_str (val64 seq) |
1868 | uuid_str (val64 seq) |
1857 | CODE: |
1869 | CODE: |
1858 | RETVAL.seq = seq; |
1870 | RETVAL.seq = seq; |
1859 | OUTPUT: |
1871 | OUTPUT: RETVAL |
1860 | RETVAL |
|
|
1861 | |
1872 | |
1862 | void |
1873 | void |
1863 | coin_names () |
1874 | coin_names () |
1864 | PPCODE: |
1875 | PPCODE: |
1865 | EXTEND (SP, NUM_COINS); |
1876 | EXTEND (SP, NUM_COINS); |
… | |
… | |
1877 | load_resource_file_ (octet_string filename) |
1888 | load_resource_file_ (octet_string filename) |
1878 | |
1889 | |
1879 | void |
1890 | void |
1880 | fix_weight () |
1891 | fix_weight () |
1881 | |
1892 | |
|
|
1893 | utf8_string |
|
|
1894 | expand_cfpod (int hintmode, int gender, const_utf8_string cfpod) |
|
|
1895 | PPCODE: |
|
|
1896 | XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod))); |
|
|
1897 | |
1882 | MODULE = cf PACKAGE = cf::attachable |
1898 | MODULE = cf PACKAGE = cf::attachable |
1883 | |
1899 | |
1884 | int |
1900 | int |
1885 | valid (SV *obj) |
1901 | valid (SV *obj) |
1886 | CODE: |
1902 | CODE: |
1887 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1903 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1888 | OUTPUT: |
1904 | OUTPUT: RETVAL |
1889 | RETVAL |
|
|
1890 | |
1905 | |
1891 | bool should_invoke (attachable *obj, int event) |
1906 | bool should_invoke (attachable *obj, int event) |
1892 | CODE: |
1907 | CODE: |
1893 | RETVAL = obj->should_invoke ((event_type)event); |
1908 | RETVAL = obj->should_invoke ((event_type)event); |
1894 | OUTPUT: RETVAL |
1909 | OUTPUT: RETVAL |
… | |
… | |
1959 | int mortals_size () |
1974 | int mortals_size () |
1960 | CODE: |
1975 | CODE: |
1961 | RETVAL = attachable::mortals.size (); |
1976 | RETVAL = attachable::mortals.size (); |
1962 | OUTPUT: RETVAL |
1977 | OUTPUT: RETVAL |
1963 | |
1978 | |
1964 | const_utf8_string slot_use_name (U32 slot) |
1979 | const_utf8_string slot_name (U32 slot) |
1965 | ALIAS: |
1980 | ALIAS: |
|
|
1981 | slot_name = 0 |
|
|
1982 | slot_use_name = 1 |
1966 | slot_nonuse_name = 1 |
1983 | slot_nonuse_name = 2 |
1967 | CODE: |
1984 | CODE: |
1968 | { |
1985 | { |
1969 | if (slot >= NUM_BODY_LOCATIONS) |
1986 | if (slot >= NUM_BODY_LOCATIONS) |
1970 | croak ("body slot index out of range"); |
1987 | croak ("body slot index out of range"); |
1971 | |
1988 | |
1972 | switch (ix) |
1989 | switch (ix) |
1973 | { |
1990 | { |
|
|
1991 | case 0: RETVAL = body_locations[slot].name ; break; |
1974 | case 0: RETVAL = body_locations[slot].use_name; break; |
1992 | case 1: RETVAL = body_locations[slot].use_name ; break; |
1975 | case 1: RETVAL = body_locations[slot].nonuse_name; break; |
1993 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
1976 | } |
1994 | } |
1977 | } |
1995 | } |
1978 | OUTPUT: |
1996 | OUTPUT: RETVAL |
1979 | RETVAL |
|
|
1980 | |
1997 | |
1981 | # missing properties |
1998 | # missing properties |
1982 | |
1999 | |
1983 | object *head (object *op) |
2000 | object *head (object *op) |
1984 | PROTOTYPE: $ |
2001 | PROTOTYPE: $ |
… | |
… | |
1992 | PPCODE: |
2009 | PPCODE: |
1993 | { |
2010 | { |
1994 | for (object *o = obj->inv; o; o = o->below) |
2011 | for (object *o = obj->inv; o; o = o->below) |
1995 | XPUSHs (sv_2mortal (to_sv (o))); |
2012 | XPUSHs (sv_2mortal (to_sv (o))); |
1996 | } |
2013 | } |
1997 | |
|
|
1998 | void |
|
|
1999 | set_animation (object *op, int idx) |
|
|
2000 | CODE: |
|
|
2001 | SET_ANIMATION (op, idx); |
|
|
2002 | |
|
|
2003 | int |
|
|
2004 | num_animations (object *op) |
|
|
2005 | CODE: |
|
|
2006 | RETVAL = NUM_ANIMATIONS (op); |
|
|
2007 | OUTPUT: RETVAL |
|
|
2008 | |
2014 | |
2009 | int slot_info (object *op, UV slot, int value = 0) |
2015 | int slot_info (object *op, UV slot, int value = 0) |
2010 | ALIAS: |
2016 | ALIAS: |
2011 | slot_used = 1 |
2017 | slot_used = 1 |
2012 | CODE: |
2018 | CODE: |
… | |
… | |
2020 | if (ix) |
2026 | if (ix) |
2021 | op->slot[slot].used = value; |
2027 | op->slot[slot].used = value; |
2022 | else |
2028 | else |
2023 | op->slot[slot].info = value; |
2029 | op->slot[slot].info = value; |
2024 | } |
2030 | } |
2025 | OUTPUT: |
2031 | OUTPUT: RETVAL |
2026 | RETVAL |
|
|
2027 | |
2032 | |
2028 | object *find_best_object_match (object *op, utf8_string match) |
2033 | object *find_best_object_match (object *op, utf8_string match) |
2029 | |
2034 | |
2030 | int apply_shop_mat (object *shop_mat, object *op); |
2035 | int apply_shop_mat (object *shop_mat, object *op); |
2031 | |
2036 | |
2032 | int move (object *op, int dir, object *originator = op) |
2037 | int move (object *op, int dir, object *originator = op) |
2033 | CODE: |
2038 | CODE: |
2034 | RETVAL = op->move (dir, originator); |
2039 | RETVAL = op->move (dir, originator); |
2035 | OUTPUT: |
2040 | OUTPUT: RETVAL |
2036 | RETVAL |
|
|
2037 | |
2041 | |
2038 | void apply_below (object *op) |
2042 | void apply_below (object *op) |
2039 | CODE: |
2043 | CODE: |
2040 | player_apply_below (op); |
2044 | player_apply_below (op); |
2041 | |
2045 | |
… | |
… | |
2105 | int convert_item (object *item, object *converter) |
2109 | int convert_item (object *item, object *converter) |
2106 | |
2110 | |
2107 | void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); |
2111 | void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); |
2108 | |
2112 | |
2109 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2113 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2110 | |
|
|
2111 | # no clean way to get an object from an archetype - stupid idiotic |
|
|
2112 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
|
|
2113 | |
2114 | |
2114 | object *new (utf8_string archetype = 0) |
2115 | object *new (utf8_string archetype = 0) |
2115 | PROTOTYPE: ;$ |
2116 | PROTOTYPE: ;$ |
2116 | CODE: |
2117 | CODE: |
2117 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
2118 | RETVAL = archetype |
|
|
2119 | ? archetype::get (archetype) |
|
|
2120 | : object::create (); |
2118 | OUTPUT: |
2121 | OUTPUT: RETVAL |
2119 | RETVAL |
|
|
2120 | |
2122 | |
2121 | object *generate (utf8_string arch, object *creator) |
2123 | object *generate (utf8_string arch, object *creator) |
2122 | CODE: |
2124 | CODE: |
2123 | object *obj = get_archetype (arch); |
2125 | object *obj = archetype::get (arch); |
2124 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2126 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2125 | RETVAL = obj; |
2127 | RETVAL = obj; |
2126 | OUTPUT: |
2128 | OUTPUT: RETVAL |
2127 | RETVAL |
|
|
2128 | |
2129 | |
2129 | object *find_object (U32 tag) |
2130 | object *find_object (U32 tag) |
2130 | |
2131 | |
2131 | object *find_object_uuid (UUID i) |
2132 | object *find_object_uuid (UUID i) |
2132 | |
2133 | |
… | |
… | |
2138 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2139 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2139 | |
2140 | |
2140 | if (RETVAL->destroyed ()) |
2141 | if (RETVAL->destroyed ()) |
2141 | RETVAL = 0; |
2142 | RETVAL = 0; |
2142 | } |
2143 | } |
|
|
2144 | OUTPUT: RETVAL |
2143 | |
2145 | |
2144 | shstr |
2146 | shstr |
2145 | object::kv_get (shstr key) |
2147 | object::kv_get (shstr key) |
|
|
2148 | CODE: |
|
|
2149 | RETVAL = THIS->kv.get (key); |
|
|
2150 | OUTPUT: RETVAL |
2146 | |
2151 | |
2147 | void |
2152 | void |
2148 | object::kv_del (shstr key) |
2153 | object::kv_del (shstr key) |
|
|
2154 | CODE: |
|
|
2155 | THIS->kv.del (key); |
2149 | |
2156 | |
2150 | void |
2157 | void |
2151 | object::kv_set (shstr key, shstr value) |
2158 | object::kv_set (shstr key, shstr value) |
|
|
2159 | CODE: |
|
|
2160 | THIS->kv.set (key, value); |
2152 | |
2161 | |
2153 | object *get_nearest_player (object *ob) |
2162 | object *get_nearest_player (object *ob) |
2154 | ALIAS: nearest_player = 0 |
2163 | ALIAS: nearest_player = 0 |
2155 | PREINIT: |
2164 | PREINIT: |
2156 | extern object *get_nearest_player (object *); |
2165 | extern object *get_nearest_player (object *); |
… | |
… | |
2245 | #d# TODO: replace by blocked_los accessor, fix code using this |
2254 | #d# TODO: replace by blocked_los accessor, fix code using this |
2246 | bool |
2255 | bool |
2247 | cell_visible (player *pl, int dx, int dy) |
2256 | cell_visible (player *pl, int dx, int dy) |
2248 | CODE: |
2257 | CODE: |
2249 | RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; |
2258 | RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; |
2250 | OUTPUT: |
2259 | OUTPUT: RETVAL |
2251 | RETVAL |
|
|
2252 | |
2260 | |
2253 | void |
2261 | void |
2254 | send (player *pl, SV *packet) |
2262 | send (player *pl, SV *packet) |
2255 | CODE: |
2263 | CODE: |
2256 | { |
2264 | { |
… | |
… | |
2332 | outdoor_darkness (int darkness = 0) |
2340 | outdoor_darkness (int darkness = 0) |
2333 | CODE: |
2341 | CODE: |
2334 | RETVAL = maptile::outdoor_darkness; |
2342 | RETVAL = maptile::outdoor_darkness; |
2335 | if (items) |
2343 | if (items) |
2336 | maptile::outdoor_darkness = darkness; |
2344 | maptile::outdoor_darkness = darkness; |
2337 | OUTPUT: |
2345 | OUTPUT: RETVAL |
2338 | RETVAL |
|
|
2339 | |
2346 | |
2340 | void |
2347 | void |
2341 | maptile::instantiate () |
2348 | maptile::instantiate () |
2342 | |
2349 | |
2343 | maptile *new () |
2350 | maptile *new () |
2344 | PROTOTYPE: |
2351 | PROTOTYPE: |
2345 | CODE: |
2352 | CODE: |
2346 | RETVAL = new maptile; |
2353 | RETVAL = new maptile; |
2347 | OUTPUT: |
2354 | OUTPUT: RETVAL |
2348 | RETVAL |
|
|
2349 | |
2355 | |
2350 | void |
2356 | void |
2351 | maptile::players () |
2357 | maptile::players () |
2352 | PPCODE: |
2358 | PPCODE: |
2353 | if (GIMME_V == G_SCALAR) |
2359 | if (GIMME_V == G_SCALAR) |
… | |
… | |
2359 | if (pl->ob && pl->ob->map == THIS) |
2365 | if (pl->ob && pl->ob->map == THIS) |
2360 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2366 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2361 | } |
2367 | } |
2362 | |
2368 | |
2363 | void |
2369 | void |
|
|
2370 | maptile::gen_quadmap (int x, int y, int z) |
|
|
2371 | CODE: |
|
|
2372 | gen_quadmap (THIS, x * 50, y * 50, z); |
|
|
2373 | |
|
|
2374 | void |
2364 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2375 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2365 | CODE: |
2376 | CODE: |
2366 | { |
2377 | { |
2367 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2378 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2368 | croak ("maptile::add_underlay: palette must be arrayref"); |
2379 | croak ("maptile::add_underlay: palette must be arrayref"); |
2369 | |
2380 | |
2370 | palette = SvRV (palette); |
2381 | palette = SvRV (palette); |
2371 | |
2382 | |
2372 | STRLEN idxlen; |
2383 | STRLEN idxlen; |
2373 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2384 | const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen); |
2374 | |
2385 | |
2375 | for (int x = 0; x < THIS->width; ++x) |
2386 | for (int x = 0; x < THIS->width; ++x) |
2376 | for (int y = 0; y < THIS->height; ++y) |
2387 | for (int y = 0; y < THIS->height; ++y) |
2377 | { |
2388 | { |
2378 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
2389 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
… | |
… | |
2384 | |
2395 | |
2385 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2396 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2386 | { |
2397 | { |
2387 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2398 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2388 | { |
2399 | { |
2389 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
2400 | object *ob = archetype::get (cfSvPVutf8_nolen (*elem)); |
2390 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2401 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2391 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2402 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2392 | |
2403 | |
2393 | if (ob->randomitems && !ob->above) |
2404 | if (ob->randomitems && !ob->above) |
2394 | { |
2405 | { |
… | |
… | |
2398 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2409 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2399 | // TODO: if this is a pickable object, then the item |
2410 | // TODO: if this is a pickable object, then the item |
2400 | // will at a bit weird - saving inside the player |
2411 | // will at a bit weird - saving inside the player |
2401 | // will clear the flag, but when the player drops |
2412 | // will clear the flag, but when the player drops |
2402 | // it without logging out, it keeps the flag. |
2413 | // it without logging out, it keeps the flag. |
2403 | // nobody ahs reported this, but this can be rather |
2414 | // nobody has reported this, but this can be rather |
2404 | // annoying on persistent maps. |
2415 | // annoying on persistent maps. |
2405 | } |
2416 | } |
2406 | } |
2417 | } |
2407 | } |
2418 | } |
2408 | } |
2419 | } |
2409 | |
|
|
2410 | skip: ; |
2420 | skip: ; |
2411 | } |
2421 | } |
2412 | } |
2422 | } |
2413 | |
2423 | |
2414 | void |
2424 | void |
… | |
… | |
2419 | croak ("maptile::set_regiondata: palette must be arrayref"); |
2429 | croak ("maptile::set_regiondata: palette must be arrayref"); |
2420 | |
2430 | |
2421 | palette = SvRV (palette); |
2431 | palette = SvRV (palette); |
2422 | |
2432 | |
2423 | STRLEN idxlen; |
2433 | STRLEN idxlen; |
2424 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2434 | const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen); |
2425 | |
2435 | |
2426 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2436 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2427 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2437 | uint8 *regions = salloc<uint8_t> (THIS->size ()); |
2428 | |
2438 | |
2429 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2439 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2430 | regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2440 | regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2431 | |
2441 | |
2432 | for (int y = 0; y < THIS->height; ++y) |
2442 | for (int y = 0; y < THIS->height; ++y) |
… | |
… | |
2445 | for (int x = 0; x < THIS->width; ++x) |
2455 | for (int x = 0; x < THIS->width; ++x) |
2446 | for (int y = 0; y < THIS->height; ++y) |
2456 | for (int y = 0; y < THIS->height; ++y) |
2447 | { |
2457 | { |
2448 | region *rgn = THIS->region (x, y); |
2458 | region *rgn = THIS->region (x, y); |
2449 | |
2459 | |
2450 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2451 | if (object *op = THIS->at (x, y).top) |
2460 | if (object *op = THIS->at (x, y).top) |
2452 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2461 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2453 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2462 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2454 | } |
2463 | } |
2455 | |
2464 | |
… | |
… | |
2485 | if (!pos.move (dir).normalise ()) |
2494 | if (!pos.move (dir).normalise ()) |
2486 | XSRETURN_UNDEF; |
2495 | XSRETURN_UNDEF; |
2487 | |
2496 | |
2488 | RETVAL = &*pos; |
2497 | RETVAL = &*pos; |
2489 | } |
2498 | } |
2490 | OUTPUT: |
2499 | OUTPUT: RETVAL |
2491 | RETVAL |
|
|
2492 | |
2500 | |
2493 | void |
2501 | void |
2494 | at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2502 | at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2495 | PROTOTYPE: $$$;$ |
2503 | PROTOTYPE: $$$;$ |
2496 | PPCODE: |
2504 | PPCODE: |
… | |
… | |
2534 | } |
2542 | } |
2535 | OUTPUT: RETVAL |
2543 | OUTPUT: RETVAL |
2536 | |
2544 | |
2537 | # worst xs function of my life |
2545 | # worst xs function of my life |
2538 | bool |
2546 | bool |
2539 | _create_random_map (\ |
2547 | _create_random_map (maptile *self, SV *options) |
2540 | maptile *self,\ |
|
|
2541 | SV *options,\ |
|
|
2542 | val64 total_map_hp,\ |
|
|
2543 | region *region\ |
|
|
2544 | ) |
|
|
2545 | CODE: |
2548 | CODE: |
2546 | { |
2549 | { |
2547 | random_map_params rmp; |
2550 | random_map_params rmp ((HV *)SvRV (options)); |
2548 | |
|
|
2549 | rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options)); |
|
|
2550 | |
|
|
2551 | assign (rmp.wall_name , rmp.get_str ("wall_name")); |
|
|
2552 | assign (rmp.monsterstyle , rmp.get_str ("monsterstyle")); |
|
|
2553 | assign (rmp.layoutstyle , rmp.get_str ("layoutstyle")); |
|
|
2554 | assign (rmp.doorstyle , rmp.get_str ("doorstyle")); |
|
|
2555 | assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map")); |
|
|
2556 | |
|
|
2557 | rmp.origin_map = rmp.get_str ("origin_map"); |
|
|
2558 | rmp.origin_x = rmp.get_iv ("origin_x"); |
|
|
2559 | rmp.origin_y = rmp.get_iv ("origin_y"); |
|
|
2560 | rmp.final_map = rmp.get_str ("final_map"); |
|
|
2561 | rmp.this_map = rmp.get_str ("this_map"); |
|
|
2562 | rmp.xsize = rmp.get_iv ("xsize"); |
|
|
2563 | rmp.ysize = rmp.get_iv ("ysize"); |
|
|
2564 | rmp.expand2x = rmp.get_iv ("expand2x"); |
|
|
2565 | rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1"); |
|
|
2566 | rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2"); |
|
|
2567 | rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3"); |
|
|
2568 | rmp.symmetry = rmp.get_iv ("symmetry"); |
|
|
2569 | rmp.difficulty = rmp.get_iv ("difficulty"); |
|
|
2570 | rmp.difficulty_given = rmp.get_iv ("difficulty_given"); |
|
|
2571 | rmp.difficulty_increase = rmp.get_nv ("difficulty_increase"); |
|
|
2572 | rmp.dungeon_level = rmp.get_iv ("dungeon_level"); |
|
|
2573 | rmp.dungeon_depth = rmp.get_iv ("dungeon_depth"); |
|
|
2574 | rmp.orientation = rmp.get_iv ("orientation"); |
|
|
2575 | rmp.random_seed = rmp.get_uv ("random_seed"); |
|
|
2576 | rmp.total_map_hp = (uint64_t)total_map_hp; |
|
|
2577 | rmp.map_layout_style = rmp.get_iv ("map_layout_style"); |
|
|
2578 | rmp.symmetry_used = rmp.get_iv ("symmetry_used"); |
|
|
2579 | rmp.region = region; |
|
|
2580 | |
|
|
2581 | RETVAL = self->generate_random_map (&rmp); |
2551 | RETVAL = self->generate_random_map (&rmp); |
2582 | } |
2552 | } |
2583 | OUTPUT: |
2553 | OUTPUT: RETVAL |
2584 | RETVAL |
|
|
2585 | |
2554 | |
2586 | MODULE = cf PACKAGE = cf::mapspace |
2555 | MODULE = cf PACKAGE = cf::mapspace |
2587 | |
2556 | |
2588 | INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | |
2557 | INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | |
2589 | |
2558 | |
… | |
… | |
2596 | |
2565 | |
2597 | archetype *archetypes (U32 index) |
2566 | archetype *archetypes (U32 index) |
2598 | CODE: |
2567 | CODE: |
2599 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2568 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2600 | OUTPUT: RETVAL |
2569 | OUTPUT: RETVAL |
|
|
2570 | |
|
|
2571 | int skillvec_size () |
|
|
2572 | CODE: |
|
|
2573 | RETVAL = skillvec.size (); |
|
|
2574 | OUTPUT: RETVAL |
|
|
2575 | |
|
|
2576 | archetype *skillvec (U32 index) |
|
|
2577 | CODE: |
|
|
2578 | RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0; |
|
|
2579 | OUTPUT: RETVAL |
|
|
2580 | |
|
|
2581 | void |
|
|
2582 | find_by_type (int type) |
|
|
2583 | PPCODE: |
|
|
2584 | for_all_archetypes (arch) |
|
|
2585 | if (arch->type == type) |
|
|
2586 | XPUSHs (sv_2mortal (to_sv (arch))); |
2601 | |
2587 | |
2602 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2588 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2603 | |
2589 | |
2604 | MODULE = cf PACKAGE = cf::party |
2590 | MODULE = cf PACKAGE = cf::party |
2605 | |
2591 | |
… | |
… | |
2654 | list () |
2640 | list () |
2655 | PPCODE: |
2641 | PPCODE: |
2656 | EXTEND (SP, clients.size ()); |
2642 | EXTEND (SP, clients.size ()); |
2657 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2643 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2658 | PUSHs (sv_2mortal (to_sv (*i))); |
2644 | PUSHs (sv_2mortal (to_sv (*i))); |
|
|
2645 | |
|
|
2646 | STRLEN |
|
|
2647 | client::inbuf_append (SV *data) |
|
|
2648 | CODE: |
|
|
2649 | { |
|
|
2650 | STRLEN len; |
|
|
2651 | char *ptr = SvPVbyte (data, len); |
|
|
2652 | |
|
|
2653 | min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len); |
|
|
2654 | memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len); |
|
|
2655 | THIS->inbuf_len += len; |
|
|
2656 | |
|
|
2657 | THIS->inbuf_handle (); |
|
|
2658 | |
|
|
2659 | RETVAL = len; |
|
|
2660 | } |
|
|
2661 | OUTPUT: RETVAL |
2659 | |
2662 | |
2660 | void |
2663 | void |
2661 | client::send_packet (SV *packet) |
2664 | client::send_packet (SV *packet) |
2662 | CODE: |
2665 | CODE: |
2663 | { |
2666 | { |
… | |
… | |
2681 | if (RETVAL) |
2684 | if (RETVAL) |
2682 | { |
2685 | { |
2683 | THIS->send_face (RETVAL, pri); |
2686 | THIS->send_face (RETVAL, pri); |
2684 | THIS->flush_fx (); |
2687 | THIS->flush_fx (); |
2685 | } |
2688 | } |
2686 | OUTPUT: |
2689 | OUTPUT: RETVAL |
2687 | RETVAL |
|
|
2688 | |
2690 | |
2689 | int |
2691 | int |
2690 | client::fx_want (int idx, int value = -1) |
2692 | client::fx_want (int idx, int value = -1) |
2691 | CODE: |
2693 | CODE: |
2692 | if (0 < idx && idx < FT_NUM) |
2694 | if (0 < idx && idx < FT_NUM) |
… | |
… | |
2695 | if (items > 2) |
2697 | if (items > 2) |
2696 | THIS->fx_want [idx] = value; |
2698 | THIS->fx_want [idx] = value; |
2697 | } |
2699 | } |
2698 | else |
2700 | else |
2699 | RETVAL = 0; |
2701 | RETVAL = 0; |
2700 | OUTPUT: |
2702 | OUTPUT: RETVAL |
2701 | RETVAL |
|
|
2702 | |
2703 | |
2703 | MODULE = cf PACKAGE = cf::sound PREFIX = sound_ |
2704 | MODULE = cf PACKAGE = cf::sound PREFIX = sound_ |
2704 | |
2705 | |
2705 | faceidx sound_find (utf8_string name) |
2706 | faceidx sound_find (utf8_string name) |
2706 | |
2707 | |
… | |
… | |
2719 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2720 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2720 | |
2721 | |
2721 | faceidx alloc (utf8_string name) |
2722 | faceidx alloc (utf8_string name) |
2722 | CODE: |
2723 | CODE: |
2723 | { |
2724 | { |
2724 | do |
2725 | RETVAL = face_alloc (); |
2725 | { |
|
|
2726 | RETVAL = faces.size (); |
|
|
2727 | faces.resize (RETVAL + 1); |
|
|
2728 | } |
|
|
2729 | while (!RETVAL); // crude way to leave index 0 |
|
|
2730 | |
2726 | |
2731 | faces [RETVAL].name = name; |
2727 | faces [RETVAL].name = name; |
2732 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2728 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2733 | |
2729 | |
2734 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2730 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2735 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2731 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2736 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2732 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2737 | } |
2733 | } |
|
|
2734 | OUTPUT: RETVAL |
|
|
2735 | |
|
|
2736 | faceidx faces_size () |
|
|
2737 | CODE: |
|
|
2738 | RETVAL = faces.size (); |
2738 | OUTPUT: RETVAL |
2739 | OUTPUT: RETVAL |
2739 | |
2740 | |
2740 | void set_type (faceidx idx, int value) |
2741 | void set_type (faceidx idx, int value) |
2741 | ALIAS: |
2742 | ALIAS: |
2742 | set_type = 0 |
2743 | set_type = 0 |
… | |
… | |
2753 | case 2: f->magicmap = value; break; |
2754 | case 2: f->magicmap = value; break; |
2754 | case 3: f->smooth = value; break; |
2755 | case 3: f->smooth = value; break; |
2755 | case 4: f->smoothlevel = value; break; |
2756 | case 4: f->smoothlevel = value; break; |
2756 | } |
2757 | } |
2757 | |
2758 | |
2758 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2759 | void set_csum (faceidx idx, int faceset, SV *chksum) |
2759 | CODE: |
2760 | CODE: |
2760 | { |
2761 | { |
2761 | faceinfo *f = face_info (idx); assert (f); |
2762 | faceinfo *f = face_info (idx); assert (f); |
2762 | facedata *d = &(faceset ? f->data64 : f->data32); |
2763 | facedata *d = f->face + faceset; |
2763 | sv_to (data, d->data); |
|
|
2764 | STRLEN clen; |
2764 | STRLEN clen; |
2765 | char *cdata = SvPVbyte (chksum, clen); |
2765 | char *cdata = SvPVbyte (chksum, clen); |
2766 | clen = min (CHKSUM_MAXLEN, clen); |
|
|
2767 | |
2766 | |
|
|
2767 | assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN)); |
2768 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2768 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2769 | |
2769 | |
2770 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2770 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2771 | { |
2771 | { |
2772 | d->chksum_len = clen; |
2772 | d->chksum_len = clen; |
2773 | memcpy (d->chksum, cdata, clen); |
2773 | memcpy (d->chksum, cdata, clen); |
2774 | |
2774 | |
2775 | // invalidate existing client face info |
2775 | // invalidate existing client face info |
2776 | for_all_clients (ns) |
2776 | for_all_clients (ns) |
2777 | if (ns->faceset == faceset) |
2777 | ns->invalidate_face (idx); |
2778 | { |
|
|
2779 | ns->faces_sent [idx] = false; |
|
|
2780 | ns->force_newmap = true; |
|
|
2781 | } |
|
|
2782 | } |
2778 | } |
2783 | } |
2779 | } |
2784 | |
2780 | |
2785 | int get_data_size (faceidx idx, int faceset = 0) |
2781 | SV *mangle_csum (SV *chksum) |
2786 | CODE: |
2782 | CODE: |
2787 | facedata *d = face_data (idx, faceset); |
2783 | STRLEN len; |
2788 | if (!d) XSRETURN_UNDEF; |
2784 | char *data = SvPVbyte (chksum, len); |
2789 | RETVAL = d->data.size (); |
2785 | RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN)); |
2790 | OUTPUT: |
2786 | OUTPUT: RETVAL |
2791 | RETVAL |
|
|
2792 | |
2787 | |
2793 | SV *get_chksum (faceidx idx, int faceset = 0) |
2788 | SV *get_csum (faceidx idx, int faceset = 0) |
2794 | CODE: |
2789 | CODE: |
2795 | facedata *d = face_data (idx, faceset); |
2790 | facedata *d = face_data (idx, faceset); |
2796 | if (!d) XSRETURN_UNDEF; |
2791 | if (!d) XSRETURN_UNDEF; |
2797 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2792 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2798 | OUTPUT: |
2793 | OUTPUT: RETVAL |
2799 | RETVAL |
|
|
2800 | |
2794 | |
2801 | SV *get_data (faceidx idx, int faceset = 0) |
2795 | int get_type (faceidx idx) |
2802 | CODE: |
2796 | CODE: |
2803 | facedata *d = face_data (idx, faceset); |
2797 | faceinfo *f = face_info (idx); |
2804 | if (!d) XSRETURN_UNDEF; |
2798 | if (!f) XSRETURN_UNDEF; |
2805 | RETVAL = newSVpvn (d->data.data (), d->data.length ()); |
2799 | RETVAL = f->type; |
2806 | OUTPUT: |
2800 | OUTPUT: RETVAL |
2807 | RETVAL |
2801 | |
|
|
2802 | SV *get_name (faceidx idx) |
|
|
2803 | CODE: |
|
|
2804 | faceinfo *f = face_info (idx); |
|
|
2805 | if (!f) XSRETURN_UNDEF; |
|
|
2806 | RETVAL = to_sv (f->name); |
|
|
2807 | OUTPUT: RETVAL |
2808 | |
2808 | |
2809 | void invalidate (faceidx idx) |
2809 | void invalidate (faceidx idx) |
2810 | CODE: |
2810 | CODE: |
2811 | for_all_clients (ns) |
2811 | for_all_clients (ns) |
2812 | { |
2812 | ns->invalidate_face (idx); |
2813 | ns->faces_sent [idx] = false; |
|
|
2814 | ns->force_newmap = true; |
|
|
2815 | } |
|
|
2816 | |
2813 | |
2817 | void invalidate_all () |
2814 | void invalidate_all () |
2818 | CODE: |
2815 | CODE: |
2819 | for_all_clients (ns) |
2816 | for_all_clients (ns) |
2820 | { |
2817 | ns->invalidate_all_faces (); |
2821 | ns->faces_sent.reset (); |
|
|
2822 | ns->force_newmap = true; |
|
|
2823 | } |
|
|
2824 | |
2818 | |
2825 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2819 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2826 | |
2820 | |
2827 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2821 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2828 | |
2822 | |
… | |
… | |
2832 | OUTPUT: RETVAL |
2826 | OUTPUT: RETVAL |
2833 | |
2827 | |
2834 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2828 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2835 | CODE: |
2829 | CODE: |
2836 | { |
2830 | { |
2837 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2831 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2838 | croak ("frames must be an arrayref"); |
2832 | croak ("frames must be an arrayref"); |
2839 | |
2833 | |
2840 | AV *av = (AV *)SvRV (frames); |
2834 | AV *av = (AV *)SvRV (frames); |
2841 | |
2835 | |
2842 | animation *anim = &animation::find (name); |
2836 | animation *anim = &animation::find (name); |
2843 | if (anim->number) |
2837 | if (anim->number) |
2844 | { |
2838 | { |
2845 | anim->resize (av_len (av) + 1); |
2839 | anim->resize (av_len (av) + 1); |
2846 | anim->facings = facings; |
2840 | anim->facings = facings; |
2847 | } |
2841 | } |
… | |
… | |
2882 | bool |
2876 | bool |
2883 | errors_are_fatal (bool fatal) |
2877 | errors_are_fatal (bool fatal) |
2884 | CODE: |
2878 | CODE: |
2885 | RETVAL = object_thawer::errors_are_fatal; |
2879 | RETVAL = object_thawer::errors_are_fatal; |
2886 | object_thawer::errors_are_fatal = fatal; |
2880 | object_thawer::errors_are_fatal = fatal; |
2887 | OUTPUT: |
2881 | OUTPUT: RETVAL |
2888 | RETVAL |
|
|
2889 | |
2882 | |
2890 | SV * |
2883 | SV * |
2891 | new_from_file (char *klass, octet_string path) |
2884 | new_from_file (char *klass, octet_string path) |
2892 | CODE: |
2885 | CODE: |
2893 | object_thawer *f = new object_thawer (path); |
2886 | object_thawer *f = new object_thawer (path); |
… | |
… | |
2919 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2912 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2920 | |
2913 | |
2921 | self->skip (); |
2914 | self->skip (); |
2922 | } |
2915 | } |
2923 | |
2916 | |
|
|
2917 | MODULE = cf PACKAGE = cf::treasurelist |
|
|
2918 | |
|
|
2919 | # quick hack, because I didn't want to implement accessors for treasurelist. |
|
|
2920 | # this asks for even more autogen, actually. |
|
|
2921 | |
|
|
2922 | void |
|
|
2923 | expand (treasurelist *list) |
|
|
2924 | PPCODE: |
|
|
2925 | EXTEND (SP, 3); |
|
|
2926 | PUSHs (sv_2mortal (to_sv (list->name))); |
|
|
2927 | PUSHs (sv_2mortal (to_sv (list->total_chance))); |
|
|
2928 | AV *av = newAV (); |
|
|
2929 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
2930 | for (treasure *item = list->items; item; item = item->next) |
|
|
2931 | { |
|
|
2932 | AV *iav = newAV (); |
|
|
2933 | av_push (av, newRV_noinc ((SV *)iav)); |
|
|
2934 | |
|
|
2935 | av_extend (iav, 7); |
|
|
2936 | av_push (iav, to_sv (item->item)); |
|
|
2937 | av_push (iav, to_sv (item->name)); |
|
|
2938 | av_push (iav, to_sv (item->change_arch.name)); |
|
|
2939 | av_push (iav, to_sv (item->change_arch.title)); |
|
|
2940 | av_push (iav, to_sv (item->change_arch.slaying)); |
|
|
2941 | av_push (iav, to_sv (item->chance)); |
|
|
2942 | av_push (iav, to_sv (item->nrof)); |
|
|
2943 | av_push (iav, to_sv (item->magic)); |
|
|
2944 | } |
|
|
2945 | |
|
|
2946 | MODULE = cf PACKAGE = cf::layout |
|
|
2947 | |
|
|
2948 | INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
|
|
2949 | |