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 (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2006,2007,2008,2009,2010,2012,2015 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * 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 |
7 | * 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 |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
10 | * |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | * |
15 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
16 | * 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 |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
19 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
21 | */ |
22 | |
22 | |
23 | #include "autoconf.h" |
23 | #include "autoconf.h" |
24 | |
24 | |
… | |
… | |
28 | |
28 | |
29 | #include <cstdarg> |
29 | #include <cstdarg> |
30 | #include <typeinfo> |
30 | #include <typeinfo> |
31 | |
31 | |
32 | #include "global.h" |
32 | #include "global.h" |
33 | #include "../random_maps/random_map.h" |
33 | #include "rmg.h" |
|
|
34 | #include "noise.h" |
34 | #include "evthread.h" |
35 | #include "evthread.h" |
35 | #include "sproto.h" |
36 | #include "sproto.h" |
36 | |
37 | |
37 | #include <unistd.h> |
38 | #include <unistd.h> |
38 | #if _POSIX_MEMLOCK |
39 | #if _POSIX_MEMLOCK |
… | |
… | |
52 | #include <XSUB.h> |
53 | #include <XSUB.h> |
53 | |
54 | |
54 | #include "CoroAPI.h" |
55 | #include "CoroAPI.h" |
55 | #include "perlxsi.c" |
56 | #include "perlxsi.c" |
56 | |
57 | |
57 | extern sint64 *levels; // the experience table |
|
|
58 | |
|
|
59 | typedef object_thawer &object_thawer_ref; |
58 | typedef object_thawer &object_thawer_ref; |
60 | typedef object_freezer &object_freezer_ref; |
59 | typedef object_freezer &object_freezer_ref; |
61 | |
60 | |
62 | typedef std::string std__string; |
61 | typedef std::string std__string; |
63 | |
62 | |
… | |
… | |
68 | static int tick_inhibit; |
67 | static int tick_inhibit; |
69 | static int tick_pending; |
68 | static int tick_pending; |
70 | |
69 | |
71 | global gbl_ev; |
70 | global gbl_ev; |
72 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
71 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
73 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
72 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick; |
74 | static AV *av_reflect; |
73 | static AV *av_reflect; |
75 | |
74 | |
76 | bitset<NUM_EVENT_TYPES> ev_want_event; |
75 | bitset<NUM_EVENT_TYPES> ev_want_event; |
77 | bitset<NUM_TYPES> ev_want_type; |
76 | bitset<NUM_TYPES> ev_want_type; |
78 | |
77 | |
… | |
… | |
85 | *stash_cf_mapspace_wrap, |
84 | *stash_cf_mapspace_wrap, |
86 | *stash_cf_client_wrap, |
85 | *stash_cf_client_wrap, |
87 | *stash_cf_arch_wrap, |
86 | *stash_cf_arch_wrap, |
88 | *stash_cf_party_wrap, |
87 | *stash_cf_party_wrap, |
89 | *stash_cf_region_wrap, |
88 | *stash_cf_region_wrap, |
90 | *stash_cf_living_wrap; |
89 | *stash_cf_living_wrap, |
|
|
90 | *stash_cf_layout_wrap, |
|
|
91 | *stash_ext_map_world; |
91 | |
92 | |
92 | static SV |
93 | static SV |
93 | *cv_cf_do_invoke, |
94 | *cv_cf_do_invoke, |
94 | *cv_cf__can_merge, |
95 | *cv_cf__can_merge, |
95 | *cv_cf_client_send_msg, |
96 | *cv_cf_client_send_msg, |
|
|
97 | *cv_cf_ix, |
96 | *cv_cf_tick, |
98 | *cv_cf_tick, |
97 | *cv_cf_match_match; |
99 | *cv_cf_match_match; |
98 | |
100 | |
99 | #ifndef newSVpv_utf8 |
101 | #ifndef newSVpv_utf8 |
100 | static SV * |
102 | static SV * |
… | |
… | |
123 | |
125 | |
124 | return sv; |
126 | return sv; |
125 | } |
127 | } |
126 | #endif |
128 | #endif |
127 | |
129 | |
128 | static noinline utf8_string |
130 | noinline utf8_string |
129 | cfSvPVutf8_nolen (SV *sv) |
131 | cfSvPVutf8_nolen (SV *sv) |
130 | { |
132 | { |
131 | SvGETMAGIC (sv); |
133 | SvGETMAGIC (sv); |
132 | |
134 | |
133 | if (SvPOK (sv)) |
135 | if (SvPOK (sv)) |
… | |
… | |
252 | { |
254 | { |
253 | static int last_mortalcount; |
255 | static int last_mortalcount; |
254 | if (mortals.size () != last_mortalcount) |
256 | if (mortals.size () != last_mortalcount) |
255 | { |
257 | { |
256 | last_mortalcount = mortals.size (); |
258 | last_mortalcount = mortals.size (); |
257 | LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); |
259 | object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
|
|
260 | |
|
|
261 | LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
|
|
262 | (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
258 | |
263 | |
259 | if (0) |
264 | if (0) |
260 | { |
265 | { |
261 | for (int j = 0; j < mortals.size (); ++j)//D |
266 | for (int j = 0; j < mortals.size (); ++j)//D |
262 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
267 | fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
… | |
… | |
353 | #endif |
358 | #endif |
354 | |
359 | |
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
360 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
356 | |
361 | |
357 | static SV * |
362 | static SV * |
358 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
363 | newSVptr (void *ptr, HV *stash, HV *hv) |
359 | { |
364 | { |
360 | SV *sv; |
|
|
361 | |
|
|
362 | if (!ptr) |
365 | if (!ptr) |
363 | return newSV (0); |
366 | return newSV (0); |
364 | |
367 | |
365 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
368 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
366 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
369 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
|
|
370 | } |
|
|
371 | |
|
|
372 | static SV * noinline |
|
|
373 | newSVptr (void *ptr, HV *stash) |
|
|
374 | { |
|
|
375 | return newSVptr (ptr, stash, newHV ()); |
367 | } |
376 | } |
368 | |
377 | |
369 | static int |
378 | static int |
370 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
379 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
371 | { |
380 | { |
… | |
… | |
383 | return 0; |
392 | return 0; |
384 | } |
393 | } |
385 | |
394 | |
386 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
395 | MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
387 | |
396 | |
388 | static SV * |
397 | static SV * noinline |
389 | newSVattachable (attachable *obj, HV *stash) |
398 | newSVattachable (attachable *obj, HV *stash) |
390 | { |
399 | { |
391 | if (!obj) |
400 | if (!obj) |
392 | return newSV (0); |
401 | return newSV (0); |
393 | |
402 | |
… | |
… | |
479 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
488 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
480 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
489 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
481 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
490 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
482 | && !sv_derived_from (sv, "cf::object"))) |
491 | && !sv_derived_from (sv, "cf::object"))) |
483 | croak ("object of type cf::object expected"); |
492 | croak ("object of type cf::object expected"); |
|
|
493 | |
|
|
494 | return SvPTR_nc (sv); |
|
|
495 | } |
|
|
496 | |
|
|
497 | static long noinline |
|
|
498 | SvPTR_ornull_maptile (SV *sv) |
|
|
499 | { |
|
|
500 | if (expect_false (!SvOK (sv))) return 0; |
|
|
501 | |
|
|
502 | if (!SvROK (sv) |
|
|
503 | || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap |
|
|
504 | && SvSTASH (SvRV (sv)) != stash_ext_map_world |
|
|
505 | && !sv_derived_from (sv, "cf::map"))) |
|
|
506 | croak ("object of type cf::map expected"); |
484 | |
507 | |
485 | return SvPTR_nc (sv); |
508 | return SvPTR_nc (sv); |
486 | } |
509 | } |
487 | |
510 | |
488 | static long noinline |
511 | static long noinline |
… | |
… | |
513 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
536 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
514 | static inline SV *to_sv (float v) { return newSVnv (v); } |
537 | static inline SV *to_sv (float v) { return newSVnv (v); } |
515 | static inline SV *to_sv (double v) { return newSVnv (v); } |
538 | static inline SV *to_sv (double v) { return newSVnv (v); } |
516 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
539 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
517 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
540 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
|
|
541 | // gcc dislikes noilnine on to_sv |
518 | static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
542 | static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
|
|
543 | static inline SV *to_sv (object * v) { return to_sv_ni (v); } |
519 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
544 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
520 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
545 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
521 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
546 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
522 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
547 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
523 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
548 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
524 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
549 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
|
|
550 | static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); } |
525 | |
551 | |
526 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
552 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
527 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
553 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
528 | |
554 | |
529 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
555 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
… | |
… | |
565 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
591 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
566 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
592 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
567 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
593 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
568 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
594 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
569 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
595 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
570 | static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } |
596 | static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } |
571 | static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } |
597 | static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } |
572 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
598 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
|
|
599 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); } |
573 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
600 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
574 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); } |
|
|
575 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
601 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
576 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
602 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
577 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
603 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
578 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
604 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
579 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
605 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
|
|
606 | static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); } |
580 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
607 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
581 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
608 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
582 | |
609 | |
583 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
610 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
584 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
611 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
… | |
… | |
597 | static inline void sv_to (SV *sv, std::string &v) |
624 | static inline void sv_to (SV *sv, std::string &v) |
598 | { |
625 | { |
599 | STRLEN len; |
626 | STRLEN len; |
600 | char *data = SvPVbyte (sv, len); |
627 | char *data = SvPVbyte (sv, len); |
601 | v.assign (data, len); |
628 | v.assign (data, len); |
|
|
629 | } |
|
|
630 | |
|
|
631 | static inline void sv_to (SV *sv, refcnt_buf &v) |
|
|
632 | { |
|
|
633 | STRLEN len; |
|
|
634 | char *data = SvPVbyte (sv, len); |
|
|
635 | refcnt_buf buf (data, len); |
|
|
636 | v = buf; |
602 | } |
637 | } |
603 | |
638 | |
604 | static inline void sv_to (SV *sv, UUID &v) |
639 | static inline void sv_to (SV *sv, UUID &v) |
605 | { |
640 | { |
606 | if (!v.parse (SvPV_nolen (sv))) |
641 | if (!v.parse (SvPV_nolen (sv))) |
… | |
… | |
695 | template<class type> |
730 | template<class type> |
696 | static void noinline |
731 | static void noinline |
697 | cf_obj_to (SV *arg, type &var) |
732 | cf_obj_to (SV *arg, type &var) |
698 | { |
733 | { |
699 | sv_to (arg, var); |
734 | sv_to (arg, var); |
700 | if (!var) |
735 | if (expect_false (!var)) |
701 | croak ("must not pass invalid/null cf_obj here"); |
736 | croak ("must not pass invalid/null cf_obj here"); |
702 | } |
737 | } |
703 | |
738 | |
704 | template<class object> |
739 | template<class object> |
705 | static void noinline |
740 | static void noinline |
706 | cf_obj_ornull_to (SV *arg, object *&var) |
741 | cf_obj_ornull_to (SV *arg, object *&var) |
707 | { |
742 | { |
708 | if (SvOK (arg)) |
743 | if (SvOK (arg)) |
709 | { |
744 | { |
710 | sv_to (arg, var); |
745 | sv_to (arg, var); |
711 | if (!var) |
746 | if (expect_false (!var)) |
712 | croak ("unable to convert perl object to C++ object"); |
747 | croak ("unable to convert perl object to C++ object"); |
713 | } |
748 | } |
714 | else |
749 | else |
715 | var = 0; |
750 | var = 0; |
716 | } |
751 | } |
… | |
… | |
751 | exit (EXIT_FAILURE); |
786 | exit (EXIT_FAILURE); |
752 | } |
787 | } |
753 | |
788 | |
754 | eval_pv ( |
789 | eval_pv ( |
755 | "#line 1 'cfperl init'\n" |
790 | "#line 1 'cfperl init'\n" |
756 | "use EV ();\n" |
791 | "use EV ();\n" // required by bootstrap |
757 | "use Coro ();\n" |
792 | "use Coro ();\n" // required by bootstrap |
758 | "cf->bootstrap;\n" |
793 | "cf->bootstrap;\n" // required for cf::datadir |
759 | "unshift @INC, cf::datadir ();\n" |
794 | "unshift @INC, cf::datadir ();\n" // required for 'require' :) |
760 | "require cf;\n", |
795 | "require cf;\n", |
761 | 0 |
796 | 0 |
762 | ); |
797 | ); |
763 | |
798 | |
764 | if (SvTRUE (ERRSV)) |
799 | if (SvTRUE (ERRSV)) |
… | |
… | |
1123 | CALL_ARG (originator); |
1158 | CALL_ARG (originator); |
1124 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1159 | CALL_CALL ("cf::mapscript::activate", G_VOID); |
1125 | CALL_END; |
1160 | CALL_END; |
1126 | } |
1161 | } |
1127 | |
1162 | |
|
|
1163 | void cfperl_ix (client *ns, int set, faceidx idx, int pri) |
|
|
1164 | { |
|
|
1165 | CALL_BEGIN (3); |
|
|
1166 | CALL_ARG (ns); |
|
|
1167 | CALL_ARG (set); |
|
|
1168 | CALL_ARG (idx); |
|
|
1169 | CALL_ARG (pri); |
|
|
1170 | CALL_CALL (cv_cf_ix, G_VOID); |
|
|
1171 | CALL_END; |
|
|
1172 | } |
|
|
1173 | |
1128 | player * |
1174 | player * |
1129 | player::find (const_utf8_string name) |
1175 | player::find (const_utf8_string name) |
1130 | { |
1176 | { |
1131 | CALL_BEGIN (1); |
1177 | CALL_BEGIN (1); |
1132 | CALL_ARG (name); |
1178 | CALL_ARG (name); |
… | |
… | |
1226 | CALL_ARG (y); |
1272 | CALL_ARG (y); |
1227 | CALL_CALL ("cf::object::player::goto", G_VOID); |
1273 | CALL_CALL ("cf::object::player::goto", G_VOID); |
1228 | CALL_END; |
1274 | CALL_END; |
1229 | } |
1275 | } |
1230 | |
1276 | |
1231 | const_utf8_string |
1277 | const_utf8_string |
1232 | object::ref () const |
1278 | object::ref () const |
1233 | { |
1279 | { |
1234 | if (type == PLAYER) |
1280 | if (type == PLAYER) |
1235 | return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); |
1281 | return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); |
1236 | else |
1282 | else |
… | |
… | |
1378 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1424 | stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1379 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1425 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1380 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1426 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1381 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1427 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1382 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1428 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
|
|
1429 | stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
|
|
1430 | stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1383 | |
1431 | |
1384 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1432 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1385 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1433 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1434 | sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1386 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1435 | sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV); |
1387 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1436 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1388 | |
1437 | |
1389 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1438 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1390 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1439 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1391 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1440 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1392 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1441 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1399 | _connect_to_perl_2 () |
1448 | _connect_to_perl_2 () |
1400 | { |
1449 | { |
1401 | cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
1450 | cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
1402 | cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
1451 | cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
1403 | cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
1452 | cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
|
|
1453 | cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix); |
1404 | cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
1454 | cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
1405 | cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
1455 | cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
1406 | } |
1456 | } |
1407 | |
1457 | |
1408 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1458 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
… | |
… | |
1413 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1463 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1414 | |
1464 | |
1415 | _connect_to_perl_1 (); |
1465 | _connect_to_perl_1 (); |
1416 | |
1466 | |
1417 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1467 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1418 | |
|
|
1419 | //{ |
|
|
1420 | // require_pv ("Time::HiRes"); |
|
|
1421 | // |
|
|
1422 | // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
|
|
1423 | // if (!svp) croak ("Time::HiRes is required"); |
|
|
1424 | // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); |
|
|
1425 | // coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); |
|
|
1426 | //} |
|
|
1427 | |
1468 | |
1428 | static const struct { |
1469 | static const struct { |
1429 | const char *name; |
1470 | const char *name; |
1430 | IV iv; |
1471 | IV iv; |
1431 | } *civ, const_iv[] = { |
1472 | } *civ, const_iv[] = { |
… | |
… | |
1435 | # include "attackinc.h" |
1476 | # include "attackinc.h" |
1436 | # undef def |
1477 | # undef def |
1437 | # define def(uc, flags) const_iv (SK_ ## uc) |
1478 | # define def(uc, flags) const_iv (SK_ ## uc) |
1438 | # include "skillinc.h" |
1479 | # include "skillinc.h" |
1439 | # undef def |
1480 | # undef def |
1440 | |
1481 | # define def(name, use, nonuse) const_iv (body_ ## name) |
1441 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
1482 | # include "slotinc.h" |
1442 | const_iv (logBacktrace) |
1483 | # undef def |
1443 | |
|
|
1444 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
|
|
1445 | |
1484 | |
1446 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1485 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1447 | |
1486 | |
1448 | const_iv (MAX_TIME) |
1487 | const_iv (MAX_TIME) |
1449 | const_iv (MAXSOCKBUF) |
1488 | const_iv (MAXSOCKBUF) |
… | |
… | |
1463 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1502 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1464 | |
1503 | |
1465 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1504 | const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1466 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1505 | const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1467 | |
1506 | |
1468 | const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
|
|
1469 | const_iv (MAP_INACTIVE) |
|
|
1470 | |
|
|
1471 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1507 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1472 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1508 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1473 | |
1509 | |
1474 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1510 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1475 | |
1511 | |
1476 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1512 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1477 | }; |
1513 | }; |
1478 | |
1514 | |
1479 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1515 | for (civ = const_iv + array_length (const_iv); civ-- > const_iv; ) |
1480 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1516 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1481 | |
1517 | |
1482 | static const struct { |
1518 | static const struct { |
1483 | const char *name; |
1519 | const char *name; |
1484 | int skip; |
1520 | int skip; |
… | |
… | |
1490 | # undef def |
1526 | # undef def |
1491 | }; |
1527 | }; |
1492 | |
1528 | |
1493 | AV *av = get_av ("cf::EVENT", 1); |
1529 | AV *av = get_av ("cf::EVENT", 1); |
1494 | |
1530 | |
1495 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1531 | for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; ) |
1496 | { |
1532 | { |
1497 | AV *event = newAV (); |
1533 | AV *event = newAV (); |
1498 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1534 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1499 | av_push (event, newSViv (eiv->klass)); |
1535 | av_push (event, newSViv (eiv->klass)); |
1500 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1536 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
… | |
… | |
1507 | |
1543 | |
1508 | void _gv_clear (SV *gv) |
1544 | void _gv_clear (SV *gv) |
1509 | CODE: |
1545 | CODE: |
1510 | assert (SvTYPE (gv) == SVt_PVGV); |
1546 | assert (SvTYPE (gv) == SVt_PVGV); |
1511 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
1547 | # define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
|
|
1548 | SvREFCNT_inc (gv); |
1512 | f (GvGP (gv)->gp_form); |
1549 | f (GvGP (gv)->gp_form); |
1513 | f (GvGP (gv)->gp_io); |
1550 | f (GvGP (gv)->gp_io); |
1514 | f (GvGP (gv)->gp_sv); |
1551 | f (GvGP (gv)->gp_sv); |
1515 | f (GvGP (gv)->gp_av); |
1552 | f (GvGP (gv)->gp_av); |
1516 | f (GvGP (gv)->gp_hv); |
1553 | f (GvGP (gv)->gp_hv); |
1517 | f (GvGP (gv)->gp_cv); |
1554 | f (GvGP (gv)->gp_cv); |
1518 | GvCVGEN (gv) = 0; |
1555 | GvCVGEN (gv) = 0; |
1519 | GvMULTI_off (gv); |
1556 | GvMULTI_off (gv); |
|
|
1557 | SvREFCNT_dec (gv); |
1520 | # undef f |
1558 | # undef f |
1521 | |
1559 | |
1522 | void _connect_to_perl_1 () |
1560 | void _connect_to_perl_1 () |
1523 | |
1561 | |
1524 | void _connect_to_perl_2 () |
1562 | void _connect_to_perl_2 () |
… | |
… | |
1535 | |
1573 | |
1536 | for_all_objects (op) |
1574 | for_all_objects (op) |
1537 | op->reattach (); |
1575 | op->reattach (); |
1538 | } |
1576 | } |
1539 | |
1577 | |
1540 | # support function for map-world.ext |
|
|
1541 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1542 | CODE: |
|
|
1543 | { |
|
|
1544 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1545 | croak ("_quantise called with invalid agruments"); |
|
|
1546 | |
|
|
1547 | plt_sv = SvRV (plt_sv); |
|
|
1548 | SV **plt = AvARRAY (plt_sv); |
|
|
1549 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1550 | |
|
|
1551 | STRLEN len; |
|
|
1552 | char *data = SvPVbyte (data_sv, len); |
|
|
1553 | char *dst = data; |
|
|
1554 | |
|
|
1555 | while (len >= 3) |
|
|
1556 | { |
|
|
1557 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1558 | { |
|
|
1559 | char *val = SvPVX (*val_sv); |
|
|
1560 | |
|
|
1561 | if (val [0] == data [0] |
|
|
1562 | && val [1] == data [1] |
|
|
1563 | && val [2] == data [2]) |
|
|
1564 | { |
|
|
1565 | *dst++ = val [3]; |
|
|
1566 | goto next; |
|
|
1567 | } |
|
|
1568 | } |
|
|
1569 | |
|
|
1570 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1571 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1572 | dst - SvPVX (data_sv), len); |
|
|
1573 | |
|
|
1574 | next: |
|
|
1575 | data += 3; |
|
|
1576 | len -= 3; |
|
|
1577 | } |
|
|
1578 | |
|
|
1579 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1580 | } |
|
|
1581 | |
|
|
1582 | void init_anim () |
1578 | void init_anim () |
1583 | |
1579 | |
1584 | void init_globals () |
1580 | void init_globals () |
1585 | |
1581 | |
1586 | void init_experience () |
|
|
1587 | |
|
|
1588 | void init_attackmess () |
1582 | void init_attackmess () |
1589 | |
1583 | |
1590 | void init_dynamic () |
1584 | void init_dynamic () |
1591 | |
1585 | |
1592 | void load_settings () |
1586 | void load_settings () |
1593 | |
1587 | |
|
|
1588 | void _reload_exp_table () |
|
|
1589 | |
1594 | void load_materials () |
1590 | void _reload_materials () |
1595 | |
1591 | |
1596 | void init_uuid () |
1592 | void init_uuid () |
1597 | CODE: |
1593 | CODE: |
1598 | UUID::init (); |
1594 | UUID::init (); |
1599 | |
1595 | |
… | |
… | |
1610 | coroapi::cede_to_tick (); |
1606 | coroapi::cede_to_tick (); |
1611 | |
1607 | |
1612 | NV till_tick () |
1608 | NV till_tick () |
1613 | CODE: |
1609 | CODE: |
1614 | RETVAL = SvNVX (sv_next_tick) - now (); |
1610 | RETVAL = SvNVX (sv_next_tick) - now (); |
1615 | OUTPUT: |
1611 | OUTPUT: RETVAL |
1616 | RETVAL |
|
|
1617 | |
1612 | |
1618 | int tick_inhibit () |
1613 | int tick_inhibit () |
1619 | CODE: |
1614 | CODE: |
1620 | RETVAL = tick_inhibit; |
1615 | RETVAL = tick_inhibit; |
1621 | OUTPUT: |
1616 | OUTPUT: RETVAL |
1622 | RETVAL |
|
|
1623 | |
1617 | |
1624 | void tick_inhibit_inc () |
1618 | void tick_inhibit_inc () |
1625 | CODE: |
1619 | CODE: |
1626 | ++tick_inhibit; |
1620 | ++tick_inhibit; |
1627 | |
1621 | |
… | |
… | |
1632 | { |
1626 | { |
1633 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1627 | ev_async_send (EV_DEFAULT, &tick_watcher); |
1634 | coroapi::cede (); |
1628 | coroapi::cede (); |
1635 | } |
1629 | } |
1636 | |
1630 | |
1637 | void server_tick () |
1631 | void one_tick () |
1638 | CODE: |
1632 | CODE: |
1639 | { |
1633 | { |
1640 | ev_now_update (EV_DEFAULT); |
1634 | ev_now_update (EV_DEFAULT); |
1641 | NOW = ev_now (EV_DEFAULT); |
1635 | NOW = ev_now (EV_DEFAULT); |
1642 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1636 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1643 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1637 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1644 | runtime = SvNVX (sv_runtime); |
1638 | runtime = SvNVX (sv_runtime); |
1645 | |
1639 | |
|
|
1640 | one_tick (); |
|
|
1641 | |
1646 | server_tick (); |
1642 | ++server_tick; |
|
|
1643 | SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1647 | |
1644 | |
1648 | ev_now_update (EV_DEFAULT); |
1645 | ev_now_update (EV_DEFAULT); |
1649 | NOW = ev_now (EV_DEFAULT); |
1646 | NOW = ev_now (EV_DEFAULT); |
1650 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1647 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1648 | |
1651 | runtime += TICK; |
1649 | runtime += TICK; |
1652 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1650 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1653 | } |
1651 | } |
1654 | |
1652 | |
1655 | NV floor (NV x) |
1653 | NV floor (NV x) |
… | |
… | |
1659 | NV rndm (...) |
1657 | NV rndm (...) |
1660 | ALIAS: |
1658 | ALIAS: |
1661 | rmg_rndm = 1 |
1659 | rmg_rndm = 1 |
1662 | CODE: |
1660 | CODE: |
1663 | { |
1661 | { |
1664 | rand_gen &gen = ix ? rmg_rndm : rndm; |
1662 | rand_gen &gen = ix ? rmg_rndm : rndm; |
1665 | switch (items) |
1663 | switch (items) |
1666 | { |
1664 | { |
1667 | case 0: RETVAL = gen (); break; |
1665 | case 0: RETVAL = gen (); break; |
1668 | case 1: RETVAL = gen (SvUV (ST (0))); break; |
1666 | case 1: RETVAL = gen (SvUV (ST (0))); break; |
1669 | case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; |
1667 | case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; |
1670 | default: croak ("cf::rndm requires zero, one or two parameters."); break; |
1668 | default: croak ("cf::rndm requires zero, one or two parameters."); break; |
1671 | } |
1669 | } |
1672 | } |
1670 | } |
1673 | OUTPUT: |
1671 | OUTPUT: RETVAL |
1674 | RETVAL |
|
|
1675 | |
1672 | |
1676 | NV clamp (NV value, NV min_value, NV max_value) |
1673 | NV clamp (NV value, NV min_value, NV max_value) |
1677 | CODE: |
1674 | CODE: |
1678 | RETVAL = clamp (value, min_value, max_value); |
1675 | RETVAL = clamp (value, min_value, max_value); |
1679 | OUTPUT: |
1676 | OUTPUT: RETVAL |
1680 | RETVAL |
|
|
1681 | |
1677 | |
1682 | NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) |
1678 | NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) |
1683 | CODE: |
1679 | CODE: |
1684 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
1680 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
1685 | OUTPUT: |
1681 | OUTPUT: RETVAL |
1686 | RETVAL |
|
|
1687 | |
1682 | |
1688 | const char *ordinal (int i) |
1683 | const char *ordinal (int i) |
1689 | |
1684 | |
1690 | void weaken (...) |
1685 | void weaken (...) |
1691 | PROTOTYPE: @ |
1686 | PROTOTYPE: @ |
… | |
… | |
1754 | |
1749 | |
1755 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1750 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1756 | INIT: |
1751 | INIT: |
1757 | #if __GLIBC__ |
1752 | #if __GLIBC__ |
1758 | mallopt (M_TOP_PAD, 1024 * 1024); |
1753 | mallopt (M_TOP_PAD, 1024 * 1024); |
1759 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); |
1754 | mallopt (M_MMAP_THRESHOLD, 1024 * 1024); |
1760 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
1755 | mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
|
|
1756 | if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10)) |
1761 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1757 | mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1762 | #endif |
1758 | #endif |
1763 | |
1759 | |
1764 | int munlockall () |
1760 | int munlockall () |
1765 | |
1761 | |
1766 | #endif |
1762 | #endif |
… | |
… | |
1789 | EXTEND (SP, 5*2); |
1785 | EXTEND (SP, 5*2); |
1790 | PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
1786 | PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
1791 | PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
1787 | PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
1792 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1788 | PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1793 | PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
1789 | PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
1794 | PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); |
|
|
1795 | } |
1790 | } |
1796 | |
|
|
1797 | int find_animation (utf8_string text) |
|
|
1798 | PROTOTYPE: $ |
|
|
1799 | |
1791 | |
1800 | int random_roll (int min, int max, object *op, int goodbad); |
1792 | int random_roll (int min, int max, object *op, int goodbad); |
1801 | |
1793 | |
1802 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1794 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1803 | |
1795 | |
|
|
1796 | int exp_to_level (val64 exp) |
|
|
1797 | |
|
|
1798 | val64 level_to_min_exp (int level) |
|
|
1799 | |
|
|
1800 | const_utf8_string |
|
|
1801 | spellpathnames (int idx) |
|
|
1802 | CODE: |
|
|
1803 | RETVAL = spellpathnames [idx]; |
|
|
1804 | OUTPUT: RETVAL |
|
|
1805 | |
|
|
1806 | SV * |
|
|
1807 | attacktype_name (int atnr) |
|
|
1808 | CODE: |
|
|
1809 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1810 | ? newSVpv (attacktype_name [atnr], 0) |
|
|
1811 | : &PL_sv_undef; |
|
|
1812 | OUTPUT: RETVAL |
|
|
1813 | |
|
|
1814 | SV * |
|
|
1815 | attacktype_desc (int atnr) |
|
|
1816 | CODE: |
|
|
1817 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1818 | ? newSVpv (attacktype_desc [atnr], 0) |
|
|
1819 | : &PL_sv_undef; |
|
|
1820 | OUTPUT: RETVAL |
|
|
1821 | |
|
|
1822 | SV * |
|
|
1823 | resist_plus (int atnr) |
|
|
1824 | CODE: |
|
|
1825 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1826 | ? newSVpv (resist_plus [atnr], 0) |
|
|
1827 | : &PL_sv_undef; |
|
|
1828 | OUTPUT: RETVAL |
|
|
1829 | |
|
|
1830 | SV * |
|
|
1831 | change_resist_msg (int atnr) |
|
|
1832 | CODE: |
|
|
1833 | RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
|
|
1834 | ? newSVpv (change_resist_msg [atnr], 0) |
|
|
1835 | : &PL_sv_undef; |
|
|
1836 | OUTPUT: RETVAL |
|
|
1837 | |
1804 | int |
1838 | int |
1805 | exp_to_level (val64 exp) |
1839 | skill_flags (int idx) |
1806 | CODE: |
1840 | CODE: |
1807 | { |
1841 | if (idx < 0 || idx >= array_length (skill_flags)) |
1808 | int i = 0; |
1842 | croak ("skill_flags: index out of bounds"); |
1809 | |
1843 | RETVAL = skill_flags [idx]; |
1810 | RETVAL = settings.max_level; |
|
|
1811 | |
|
|
1812 | for (i = 1; i <= settings.max_level; i++) |
|
|
1813 | { |
|
|
1814 | if (levels[i] > exp) |
|
|
1815 | { |
|
|
1816 | RETVAL = i - 1; |
|
|
1817 | break; |
|
|
1818 | } |
|
|
1819 | } |
|
|
1820 | } |
|
|
1821 | OUTPUT: RETVAL |
|
|
1822 | |
|
|
1823 | val64 |
|
|
1824 | level_to_min_exp (int level) |
|
|
1825 | CODE: |
|
|
1826 | if (level > settings.max_level) |
|
|
1827 | RETVAL = levels[settings.max_level]; |
|
|
1828 | else if (level < 1) |
|
|
1829 | RETVAL = 0; |
|
|
1830 | else |
|
|
1831 | RETVAL = levels[level]; |
|
|
1832 | OUTPUT: RETVAL |
1844 | OUTPUT: RETVAL |
1833 | |
|
|
1834 | SV * |
|
|
1835 | resistance_to_string (int atnr) |
|
|
1836 | CODE: |
|
|
1837 | if (atnr >= 0 && atnr < NROFATTACKS) |
|
|
1838 | RETVAL = newSVpv (resist_plus[atnr], 0); |
|
|
1839 | else |
|
|
1840 | XSRETURN_UNDEF; |
|
|
1841 | OUTPUT: RETVAL |
|
|
1842 | |
1845 | |
1843 | UUID |
1846 | UUID |
1844 | uuid_cur () |
1847 | uuid_cur () |
1845 | CODE: |
1848 | CODE: |
1846 | RETVAL = UUID::cur; |
1849 | RETVAL = UUID::cur; |
1847 | OUTPUT: |
1850 | OUTPUT: RETVAL |
1848 | RETVAL |
|
|
1849 | |
1851 | |
1850 | UUID |
1852 | UUID |
1851 | uuid_gen () |
1853 | uuid_gen () |
1852 | CODE: |
1854 | CODE: |
1853 | RETVAL = UUID::gen (); |
1855 | RETVAL = UUID::gen (); |
1854 | OUTPUT: |
1856 | OUTPUT: RETVAL |
1855 | RETVAL |
|
|
1856 | |
1857 | |
1857 | val64 |
1858 | val64 |
1858 | uuid_seq (UUID uuid) |
1859 | uuid_seq (UUID uuid) |
1859 | CODE: |
1860 | CODE: |
1860 | RETVAL = uuid.seq; |
1861 | RETVAL = uuid.seq; |
1861 | OUTPUT: |
1862 | OUTPUT: RETVAL |
1862 | RETVAL |
|
|
1863 | |
1863 | |
1864 | UUID |
1864 | UUID |
1865 | uuid_str (val64 seq) |
1865 | uuid_str (val64 seq) |
1866 | CODE: |
1866 | CODE: |
1867 | RETVAL.seq = seq; |
1867 | RETVAL.seq = seq; |
1868 | OUTPUT: |
1868 | OUTPUT: RETVAL |
1869 | RETVAL |
|
|
1870 | |
1869 | |
1871 | void |
1870 | void |
1872 | coin_names () |
1871 | coin_names () |
1873 | PPCODE: |
1872 | PPCODE: |
1874 | EXTEND (SP, NUM_COINS); |
1873 | EXTEND (SP, NUM_COINS); |
… | |
… | |
1886 | load_resource_file_ (octet_string filename) |
1885 | load_resource_file_ (octet_string filename) |
1887 | |
1886 | |
1888 | void |
1887 | void |
1889 | fix_weight () |
1888 | fix_weight () |
1890 | |
1889 | |
|
|
1890 | utf8_string |
|
|
1891 | expand_cfpod (int hintmode, int gender, const_utf8_string cfpod) |
|
|
1892 | PPCODE: |
|
|
1893 | XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod))); |
|
|
1894 | |
1891 | MODULE = cf PACKAGE = cf::attachable |
1895 | MODULE = cf PACKAGE = cf::attachable |
1892 | |
1896 | |
1893 | int |
1897 | int |
1894 | valid (SV *obj) |
1898 | valid (SV *obj) |
1895 | CODE: |
1899 | CODE: |
1896 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1900 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1897 | OUTPUT: |
1901 | OUTPUT: RETVAL |
1898 | RETVAL |
1902 | |
|
|
1903 | bool should_invoke (attachable *obj, int event) |
|
|
1904 | CODE: |
|
|
1905 | RETVAL = obj->should_invoke ((event_type)event); |
|
|
1906 | OUTPUT: RETVAL |
1899 | |
1907 | |
1900 | void |
1908 | void |
1901 | debug_trace (attachable *obj, bool on = true) |
1909 | debug_trace (attachable *obj, bool on = true) |
1902 | CODE: |
1910 | CODE: |
1903 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1911 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
… | |
… | |
1963 | int mortals_size () |
1971 | int mortals_size () |
1964 | CODE: |
1972 | CODE: |
1965 | RETVAL = attachable::mortals.size (); |
1973 | RETVAL = attachable::mortals.size (); |
1966 | OUTPUT: RETVAL |
1974 | OUTPUT: RETVAL |
1967 | |
1975 | |
1968 | const_utf8_string slot_use_name (U32 slot) |
1976 | const_utf8_string slot_name (U32 slot) |
1969 | ALIAS: |
1977 | ALIAS: |
|
|
1978 | slot_name = 0 |
|
|
1979 | slot_use_name = 1 |
1970 | slot_nonuse_name = 1 |
1980 | slot_nonuse_name = 2 |
1971 | CODE: |
1981 | CODE: |
1972 | { |
1982 | { |
1973 | if (slot >= NUM_BODY_LOCATIONS) |
1983 | if (slot >= NUM_BODY_LOCATIONS) |
1974 | croak ("body slot index out of range"); |
1984 | croak ("body slot index out of range"); |
1975 | |
1985 | |
1976 | switch (ix) |
1986 | switch (ix) |
1977 | { |
1987 | { |
|
|
1988 | case 0: RETVAL = body_locations[slot].name ; break; |
1978 | case 0: RETVAL = body_locations[slot].use_name; break; |
1989 | case 1: RETVAL = body_locations[slot].use_name ; break; |
1979 | case 1: RETVAL = body_locations[slot].nonuse_name; break; |
1990 | case 2: RETVAL = body_locations[slot].nonuse_name; break; |
1980 | } |
1991 | } |
1981 | } |
1992 | } |
1982 | OUTPUT: |
1993 | OUTPUT: RETVAL |
1983 | RETVAL |
|
|
1984 | |
1994 | |
1985 | # missing properties |
1995 | # missing properties |
1986 | |
1996 | |
1987 | object *head (object *op) |
1997 | object *head (object *op) |
1988 | PROTOTYPE: $ |
1998 | PROTOTYPE: $ |
… | |
… | |
2024 | if (ix) |
2034 | if (ix) |
2025 | op->slot[slot].used = value; |
2035 | op->slot[slot].used = value; |
2026 | else |
2036 | else |
2027 | op->slot[slot].info = value; |
2037 | op->slot[slot].info = value; |
2028 | } |
2038 | } |
2029 | OUTPUT: |
2039 | OUTPUT: RETVAL |
2030 | RETVAL |
|
|
2031 | |
2040 | |
2032 | object *find_best_object_match (object *op, utf8_string match) |
2041 | object *find_best_object_match (object *op, utf8_string match) |
2033 | |
2042 | |
2034 | object *find_marked_object (object *op) |
|
|
2035 | |
|
|
2036 | int need_identify (object *obj); |
|
|
2037 | |
|
|
2038 | int apply_shop_mat (object *shop_mat, object *op); |
2043 | int apply_shop_mat (object *shop_mat, object *op); |
2039 | |
2044 | |
2040 | int move (object *op, int dir, object *originator = op) |
2045 | int move (object *op, int dir, object *originator = op) |
2041 | CODE: |
2046 | CODE: |
2042 | RETVAL = op->move (dir, originator); |
2047 | RETVAL = op->move (dir, originator); |
2043 | OUTPUT: |
2048 | OUTPUT: RETVAL |
2044 | RETVAL |
|
|
2045 | |
2049 | |
2046 | void apply_below (object *op) |
2050 | void apply_below (object *op) |
2047 | CODE: |
2051 | CODE: |
2048 | player_apply_below (op); |
2052 | player_apply_below (op); |
2049 | |
2053 | |
… | |
… | |
2094 | |
2098 | |
2095 | void pick_up (object *who, object *op) |
2099 | void pick_up (object *who, object *op) |
2096 | |
2100 | |
2097 | void update_object (object *op, int action) |
2101 | void update_object (object *op, int action) |
2098 | |
2102 | |
2099 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
2103 | void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0) |
2100 | |
2104 | |
2101 | void player_lvl_adj (object *who, object *skill = 0) |
2105 | void player_lvl_adj (object *who, object *skill = 0) |
2102 | |
2106 | |
2103 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2107 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2104 | |
2108 | |
… | |
… | |
2113 | int convert_item (object *item, object *converter) |
2117 | int convert_item (object *item, object *converter) |
2114 | |
2118 | |
2115 | void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); |
2119 | void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); |
2116 | |
2120 | |
2117 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2121 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2118 | |
|
|
2119 | # no clean way to get an object from an archetype - stupid idiotic |
|
|
2120 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
|
|
2121 | |
2122 | |
2122 | object *new (utf8_string archetype = 0) |
2123 | object *new (utf8_string archetype = 0) |
2123 | PROTOTYPE: ;$ |
2124 | PROTOTYPE: ;$ |
2124 | CODE: |
2125 | CODE: |
2125 | RETVAL = archetype ? get_archetype (archetype) : object::create (); |
2126 | RETVAL = archetype |
|
|
2127 | ? archetype::get (archetype) |
|
|
2128 | : object::create (); |
2126 | OUTPUT: |
2129 | OUTPUT: RETVAL |
2127 | RETVAL |
|
|
2128 | |
2130 | |
2129 | object *generate (utf8_string arch, object *creator) |
2131 | object *generate (utf8_string arch, object *creator) |
2130 | CODE: |
2132 | CODE: |
2131 | object *obj = get_archetype (arch); |
2133 | object *obj = archetype::get (arch); |
2132 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2134 | fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2133 | RETVAL = obj; |
2135 | RETVAL = obj; |
2134 | OUTPUT: |
2136 | OUTPUT: RETVAL |
2135 | RETVAL |
|
|
2136 | |
2137 | |
2137 | object *find_object (U32 tag) |
2138 | object *find_object (U32 tag) |
2138 | |
2139 | |
2139 | object *find_object_uuid (UUID i) |
2140 | object *find_object_uuid (UUID i) |
2140 | |
2141 | |
… | |
… | |
2146 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2147 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2147 | |
2148 | |
2148 | if (RETVAL->destroyed ()) |
2149 | if (RETVAL->destroyed ()) |
2149 | RETVAL = 0; |
2150 | RETVAL = 0; |
2150 | } |
2151 | } |
|
|
2152 | OUTPUT: RETVAL |
2151 | |
2153 | |
2152 | shstr |
2154 | shstr |
2153 | object::kv_get (shstr key) |
2155 | object::kv_get (shstr key) |
|
|
2156 | CODE: |
|
|
2157 | RETVAL = THIS->kv.get (key); |
|
|
2158 | OUTPUT: RETVAL |
2154 | |
2159 | |
2155 | void |
2160 | void |
2156 | object::kv_del (shstr key) |
2161 | object::kv_del (shstr key) |
|
|
2162 | CODE: |
|
|
2163 | THIS->kv.del (key); |
2157 | |
2164 | |
2158 | void |
2165 | void |
2159 | object::kv_set (shstr key, shstr value) |
2166 | object::kv_set (shstr key, shstr value) |
|
|
2167 | CODE: |
|
|
2168 | THIS->kv.set (key, value); |
2160 | |
2169 | |
2161 | object *get_nearest_player (object *ob) |
2170 | object *get_nearest_player (object *ob) |
2162 | ALIAS: nearest_player = 0 |
2171 | ALIAS: nearest_player = 0 |
2163 | PREINIT: |
2172 | PREINIT: |
2164 | extern object *get_nearest_player (object *); |
2173 | extern object *get_nearest_player (object *); |
… | |
… | |
2253 | #d# TODO: replace by blocked_los accessor, fix code using this |
2262 | #d# TODO: replace by blocked_los accessor, fix code using this |
2254 | bool |
2263 | bool |
2255 | cell_visible (player *pl, int dx, int dy) |
2264 | cell_visible (player *pl, int dx, int dy) |
2256 | CODE: |
2265 | CODE: |
2257 | RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; |
2266 | RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; |
2258 | OUTPUT: |
2267 | OUTPUT: RETVAL |
2259 | RETVAL |
|
|
2260 | |
2268 | |
2261 | void |
2269 | void |
2262 | send (player *pl, SV *packet) |
2270 | send (player *pl, SV *packet) |
2263 | CODE: |
2271 | CODE: |
2264 | { |
2272 | { |
… | |
… | |
2340 | outdoor_darkness (int darkness = 0) |
2348 | outdoor_darkness (int darkness = 0) |
2341 | CODE: |
2349 | CODE: |
2342 | RETVAL = maptile::outdoor_darkness; |
2350 | RETVAL = maptile::outdoor_darkness; |
2343 | if (items) |
2351 | if (items) |
2344 | maptile::outdoor_darkness = darkness; |
2352 | maptile::outdoor_darkness = darkness; |
2345 | OUTPUT: |
2353 | OUTPUT: RETVAL |
2346 | RETVAL |
|
|
2347 | |
2354 | |
2348 | void |
2355 | void |
2349 | maptile::instantiate () |
2356 | maptile::instantiate () |
2350 | |
2357 | |
2351 | maptile *new () |
2358 | maptile *new () |
2352 | PROTOTYPE: |
2359 | PROTOTYPE: |
2353 | CODE: |
2360 | CODE: |
2354 | RETVAL = new maptile; |
2361 | RETVAL = new maptile; |
2355 | OUTPUT: |
2362 | OUTPUT: RETVAL |
2356 | RETVAL |
|
|
2357 | |
2363 | |
2358 | void |
2364 | void |
2359 | maptile::players () |
2365 | maptile::players () |
2360 | PPCODE: |
2366 | PPCODE: |
2361 | if (GIMME_V == G_SCALAR) |
2367 | if (GIMME_V == G_SCALAR) |
… | |
… | |
2367 | if (pl->ob && pl->ob->map == THIS) |
2373 | if (pl->ob && pl->ob->map == THIS) |
2368 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2374 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2369 | } |
2375 | } |
2370 | |
2376 | |
2371 | void |
2377 | void |
|
|
2378 | maptile::gen_quadmap (int x, int y, int z) |
|
|
2379 | CODE: |
|
|
2380 | gen_quadmap (THIS, x * 50, y * 50, z); |
|
|
2381 | |
|
|
2382 | void |
2372 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2383 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2373 | CODE: |
2384 | CODE: |
2374 | { |
2385 | { |
2375 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2386 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2376 | croak ("maptile::add_underlay: palette must be arrayref"); |
2387 | croak ("maptile::add_underlay: palette must be arrayref"); |
2377 | |
2388 | |
2378 | palette = SvRV (palette); |
2389 | palette = SvRV (palette); |
2379 | |
2390 | |
2380 | STRLEN idxlen; |
2391 | STRLEN idxlen; |
2381 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2392 | const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen); |
2382 | |
2393 | |
2383 | for (int x = 0; x < THIS->width; ++x) |
2394 | for (int x = 0; x < THIS->width; ++x) |
2384 | for (int y = 0; y < THIS->height; ++y) |
2395 | for (int y = 0; y < THIS->height; ++y) |
2385 | { |
2396 | { |
2386 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
2397 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
… | |
… | |
2392 | |
2403 | |
2393 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2404 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
2394 | { |
2405 | { |
2395 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2406 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2396 | { |
2407 | { |
2397 | object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); |
2408 | object *ob = archetype::get (cfSvPVutf8_nolen (*elem)); |
2398 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2409 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2399 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2410 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2400 | |
2411 | |
2401 | if (ob->randomitems && !ob->above) |
2412 | if (ob->randomitems && !ob->above) |
2402 | { |
2413 | { |
… | |
… | |
2406 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2417 | op->flag [FLAG_NO_MAP_SAVE] = true; |
2407 | // TODO: if this is a pickable object, then the item |
2418 | // TODO: if this is a pickable object, then the item |
2408 | // will at a bit weird - saving inside the player |
2419 | // will at a bit weird - saving inside the player |
2409 | // will clear the flag, but when the player drops |
2420 | // will clear the flag, but when the player drops |
2410 | // it without logging out, it keeps the flag. |
2421 | // it without logging out, it keeps the flag. |
2411 | // nobody ahs reported this, but this can be rather |
2422 | // nobody has reported this, but this can be rather |
2412 | // annoying on persistent maps. |
2423 | // annoying on persistent maps. |
2413 | } |
2424 | } |
2414 | } |
2425 | } |
2415 | } |
2426 | } |
2416 | } |
2427 | } |
2417 | |
|
|
2418 | skip: ; |
2428 | skip: ; |
2419 | } |
2429 | } |
2420 | } |
2430 | } |
2421 | |
2431 | |
2422 | void |
2432 | void |
… | |
… | |
2427 | croak ("maptile::set_regiondata: palette must be arrayref"); |
2437 | croak ("maptile::set_regiondata: palette must be arrayref"); |
2428 | |
2438 | |
2429 | palette = SvRV (palette); |
2439 | palette = SvRV (palette); |
2430 | |
2440 | |
2431 | STRLEN idxlen; |
2441 | STRLEN idxlen; |
2432 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2442 | const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen); |
2433 | |
2443 | |
2434 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2444 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2435 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2445 | uint8 *regions = salloc<uint8_t> (THIS->size ()); |
2436 | |
2446 | |
2437 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2447 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2438 | regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2448 | regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2439 | |
2449 | |
2440 | for (int y = 0; y < THIS->height; ++y) |
2450 | for (int y = 0; y < THIS->height; ++y) |
… | |
… | |
2453 | for (int x = 0; x < THIS->width; ++x) |
2463 | for (int x = 0; x < THIS->width; ++x) |
2454 | for (int y = 0; y < THIS->height; ++y) |
2464 | for (int y = 0; y < THIS->height; ++y) |
2455 | { |
2465 | { |
2456 | region *rgn = THIS->region (x, y); |
2466 | region *rgn = THIS->region (x, y); |
2457 | |
2467 | |
2458 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2459 | if (object *op = THIS->at (x, y).top) |
2468 | if (object *op = THIS->at (x, y).top) |
2460 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2469 | if (rgn->treasure && rndm () < rgn->treasure_density) |
2461 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2470 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2462 | } |
2471 | } |
2463 | |
2472 | |
… | |
… | |
2469 | if (oblinkpt *obp = map->find_link (connection)) |
2478 | if (oblinkpt *obp = map->find_link (connection)) |
2470 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2479 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2471 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2480 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2472 | |
2481 | |
2473 | void |
2482 | void |
2474 | get_map_flags (maptile *map, int x, int y) |
2483 | xy_normalise (maptile *map, int x, int y, int dir = 0) |
2475 | PPCODE: |
2484 | PPCODE: |
2476 | { |
2485 | { |
2477 | maptile *nmap = 0; |
2486 | mapxy pos (map, x, y); |
2478 | I16 nx = 0, ny = 0; |
2487 | if (!pos.move (dir).normalise ()) |
|
|
2488 | XSRETURN_EMPTY; |
2479 | |
2489 | |
2480 | PUTBACK; |
|
|
2481 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2482 | SPAGAIN; |
|
|
2483 | |
|
|
2484 | EXTEND (SP, 4); |
2490 | EXTEND (SP, 3); |
2485 | PUSHs (sv_2mortal (newSViv (flags))); |
|
|
2486 | |
|
|
2487 | if (GIMME_V == G_ARRAY) |
|
|
2488 | { |
|
|
2489 | PUSHs (sv_2mortal (to_sv (nmap))); |
2491 | PUSHs (sv_2mortal (to_sv (pos.m))); |
2490 | PUSHs (sv_2mortal (newSViv (nx))); |
2492 | PUSHs (sv_2mortal (to_sv (pos.x))); |
2491 | PUSHs (sv_2mortal (newSViv (ny))); |
2493 | PUSHs (sv_2mortal (to_sv (pos.y))); |
2492 | } |
|
|
2493 | } |
2494 | } |
2494 | |
2495 | |
2495 | mapspace * |
2496 | mapspace * |
2496 | ms (maptile *map, unsigned int x, unsigned int y) |
2497 | ms (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2497 | PROTOTYPE: $$$ |
2498 | PROTOTYPE: $$$;$ |
2498 | CODE: |
2499 | CODE: |
2499 | { |
2500 | { |
2500 | maptile *nmap = 0; |
2501 | mapxy pos (map, x, y); |
2501 | I16 nx, ny; |
2502 | if (!pos.move (dir).normalise ()) |
2502 | |
|
|
2503 | PUTBACK; |
|
|
2504 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2505 | SPAGAIN; |
|
|
2506 | |
|
|
2507 | if (!nmap) |
|
|
2508 | XSRETURN_UNDEF; |
2503 | XSRETURN_UNDEF; |
2509 | |
2504 | |
2510 | RETVAL = &nmap->at (nx, ny); |
|
|
2511 | } |
|
|
2512 | OUTPUT: |
|
|
2513 | RETVAL |
2505 | RETVAL = &*pos; |
|
|
2506 | } |
|
|
2507 | OUTPUT: RETVAL |
2514 | |
2508 | |
2515 | void |
2509 | void |
2516 | at (maptile *map, unsigned int x, unsigned int y) |
2510 | at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2517 | PROTOTYPE: $$$ |
2511 | PROTOTYPE: $$$;$ |
2518 | PPCODE: |
2512 | PPCODE: |
2519 | { |
2513 | mapxy pos (map, x, y); |
2520 | maptile *nmap = 0; |
2514 | if (pos.move (dir).normalise ()) |
2521 | I16 nx, ny; |
|
|
2522 | |
|
|
2523 | PUTBACK; |
|
|
2524 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
|
|
2525 | SPAGAIN; |
|
|
2526 | |
|
|
2527 | if (nmap) |
|
|
2528 | for (object *o = nmap->at (nx, ny).bot; o; o = o->above) |
2515 | for (object *o = pos->bot; o; o = o->above) |
2529 | XPUSHs (sv_2mortal (to_sv (o))); |
2516 | XPUSHs (sv_2mortal (to_sv (o))); |
2530 | } |
|
|
2531 | |
2517 | |
2532 | SV * |
2518 | SV * |
2533 | bot_at (maptile *map, unsigned int x, unsigned int y) |
2519 | bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2534 | PROTOTYPE: $$$ |
2520 | PROTOTYPE: $$$;$ |
2535 | ALIAS: |
2521 | ALIAS: |
2536 | top_at = 1 |
2522 | top_at = 1 |
2537 | flags_at = 2 |
2523 | flags_at = 2 |
2538 | light_at = 3 |
2524 | light_at = 3 |
2539 | move_block_at = 4 |
2525 | move_block_at = 4 |
2540 | move_slow_at = 5 |
2526 | move_slow_at = 5 |
2541 | move_on_at = 6 |
2527 | move_on_at = 6 |
2542 | move_off_at = 7 |
2528 | move_off_at = 7 |
2543 | CODE: |
2529 | CODE: |
2544 | { |
2530 | { |
2545 | sint16 nx = x; |
2531 | mapxy pos (map, x, y); |
2546 | sint16 ny = y; |
2532 | if (!pos.move (dir).normalise ()) |
2547 | |
|
|
2548 | if (!xy_normalise (map, nx, ny)) |
|
|
2549 | XSRETURN_UNDEF; |
2533 | XSRETURN_UNDEF; |
2550 | |
2534 | |
2551 | mapspace &ms = map->at (nx, ny); |
2535 | mapspace &ms = *pos; |
2552 | |
2536 | |
2553 | ms.update (); |
2537 | ms.update (); |
2554 | |
2538 | |
2555 | switch (ix) |
2539 | switch (ix) |
2556 | { |
2540 | { |
… | |
… | |
2566 | } |
2550 | } |
2567 | OUTPUT: RETVAL |
2551 | OUTPUT: RETVAL |
2568 | |
2552 | |
2569 | # worst xs function of my life |
2553 | # worst xs function of my life |
2570 | bool |
2554 | bool |
2571 | _create_random_map (\ |
2555 | _create_random_map (maptile *self, SV *options) |
2572 | maptile *self,\ |
|
|
2573 | utf8_string wallstyle,\ |
|
|
2574 | utf8_string wall_name,\ |
|
|
2575 | utf8_string floorstyle,\ |
|
|
2576 | utf8_string monsterstyle,\ |
|
|
2577 | utf8_string treasurestyle,\ |
|
|
2578 | utf8_string layoutstyle,\ |
|
|
2579 | utf8_string doorstyle,\ |
|
|
2580 | utf8_string decorstyle,\ |
|
|
2581 | utf8_string miningstyle,\ |
|
|
2582 | utf8_string origin_map,\ |
|
|
2583 | utf8_string final_map,\ |
|
|
2584 | utf8_string exitstyle,\ |
|
|
2585 | utf8_string this_map,\ |
|
|
2586 | utf8_string exit_on_final_map,\ |
|
|
2587 | int xsize,\ |
|
|
2588 | int ysize,\ |
|
|
2589 | int expand2x,\ |
|
|
2590 | int layoutoptions1,\ |
|
|
2591 | int layoutoptions2,\ |
|
|
2592 | int layoutoptions3,\ |
|
|
2593 | int symmetry,\ |
|
|
2594 | int difficulty,\ |
|
|
2595 | int difficulty_given,\ |
|
|
2596 | float difficulty_increase,\ |
|
|
2597 | int dungeon_level,\ |
|
|
2598 | int dungeon_depth,\ |
|
|
2599 | int decoroptions,\ |
|
|
2600 | int orientation,\ |
|
|
2601 | int origin_y,\ |
|
|
2602 | int origin_x,\ |
|
|
2603 | U32 random_seed,\ |
|
|
2604 | val64 total_map_hp,\ |
|
|
2605 | int map_layout_style,\ |
|
|
2606 | int treasureoptions,\ |
|
|
2607 | int symmetry_used,\ |
|
|
2608 | region *region,\ |
|
|
2609 | utf8_string custom\ |
|
|
2610 | ) |
|
|
2611 | CODE: |
2556 | CODE: |
2612 | { |
2557 | { |
2613 | random_map_params rmp; |
2558 | random_map_params rmp ((HV *)SvRV (options)); |
2614 | |
|
|
2615 | assign (rmp.wallstyle , wallstyle); |
|
|
2616 | assign (rmp.wall_name , wall_name); |
|
|
2617 | assign (rmp.floorstyle , floorstyle); |
|
|
2618 | assign (rmp.monsterstyle , monsterstyle); |
|
|
2619 | assign (rmp.treasurestyle , treasurestyle); |
|
|
2620 | assign (rmp.layoutstyle , layoutstyle); |
|
|
2621 | assign (rmp.doorstyle , doorstyle); |
|
|
2622 | assign (rmp.decorstyle , decorstyle); |
|
|
2623 | assign (rmp.miningstyle , miningstyle); |
|
|
2624 | assign (rmp.exitstyle , exitstyle); |
|
|
2625 | assign (rmp.exit_on_final_map, exit_on_final_map); |
|
|
2626 | |
|
|
2627 | rmp.origin_map = origin_map; |
|
|
2628 | rmp.final_map = final_map; |
|
|
2629 | rmp.this_map = this_map; |
|
|
2630 | rmp.xsize = xsize; |
|
|
2631 | rmp.ysize = ysize; |
|
|
2632 | rmp.expand2x = expand2x; |
|
|
2633 | rmp.layoutoptions1 = layoutoptions1; |
|
|
2634 | rmp.layoutoptions2 = layoutoptions2; |
|
|
2635 | rmp.layoutoptions3 = layoutoptions3; |
|
|
2636 | rmp.symmetry = symmetry; |
|
|
2637 | rmp.difficulty = difficulty; |
|
|
2638 | rmp.difficulty_given = difficulty_given; |
|
|
2639 | rmp.difficulty_increase = difficulty_increase; |
|
|
2640 | rmp.dungeon_level = dungeon_level; |
|
|
2641 | rmp.dungeon_depth = dungeon_depth; |
|
|
2642 | rmp.decoroptions = decoroptions; |
|
|
2643 | rmp.orientation = orientation; |
|
|
2644 | rmp.origin_y = origin_y; |
|
|
2645 | rmp.origin_x = origin_x; |
|
|
2646 | rmp.random_seed = random_seed; |
|
|
2647 | rmp.total_map_hp = (uint64_t) total_map_hp; |
|
|
2648 | rmp.map_layout_style = map_layout_style; |
|
|
2649 | rmp.treasureoptions = treasureoptions; |
|
|
2650 | rmp.symmetry_used = symmetry_used; |
|
|
2651 | rmp.region = region; |
|
|
2652 | rmp.custom = custom; |
|
|
2653 | |
|
|
2654 | RETVAL = self->generate_random_map (&rmp); |
2559 | RETVAL = self->generate_random_map (&rmp); |
2655 | } |
2560 | } |
2656 | OUTPUT: |
2561 | OUTPUT: RETVAL |
2657 | RETVAL |
|
|
2658 | |
2562 | |
2659 | MODULE = cf PACKAGE = cf::mapspace |
2563 | MODULE = cf PACKAGE = cf::mapspace |
2660 | |
2564 | |
2661 | INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | |
2565 | INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | |
2662 | |
2566 | |
… | |
… | |
2669 | |
2573 | |
2670 | archetype *archetypes (U32 index) |
2574 | archetype *archetypes (U32 index) |
2671 | CODE: |
2575 | CODE: |
2672 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2576 | RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2673 | OUTPUT: RETVAL |
2577 | OUTPUT: RETVAL |
|
|
2578 | |
|
|
2579 | int skillvec_size () |
|
|
2580 | CODE: |
|
|
2581 | RETVAL = skillvec.size (); |
|
|
2582 | OUTPUT: RETVAL |
|
|
2583 | |
|
|
2584 | archetype *skillvec (U32 index) |
|
|
2585 | CODE: |
|
|
2586 | RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0; |
|
|
2587 | OUTPUT: RETVAL |
|
|
2588 | |
|
|
2589 | void |
|
|
2590 | find_by_type (int type) |
|
|
2591 | PPCODE: |
|
|
2592 | for_all_archetypes (arch) |
|
|
2593 | if (arch->type == type) |
|
|
2594 | XPUSHs (sv_2mortal (to_sv (arch))); |
2674 | |
2595 | |
2675 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2596 | INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2676 | |
2597 | |
2677 | MODULE = cf PACKAGE = cf::party |
2598 | MODULE = cf PACKAGE = cf::party |
2678 | |
2599 | |
… | |
… | |
2690 | list () |
2611 | list () |
2691 | PPCODE: |
2612 | PPCODE: |
2692 | for_all_regions (rgn) |
2613 | for_all_regions (rgn) |
2693 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2614 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2694 | |
2615 | |
2695 | region *find (utf8_string name) |
|
|
2696 | PROTOTYPE: $ |
|
|
2697 | CODE: |
|
|
2698 | RETVAL = region::find (name); |
|
|
2699 | OUTPUT: RETVAL |
|
|
2700 | |
|
|
2701 | int specificity (region *rgn) |
2616 | int specificity (region *rgn) |
2702 | CODE: |
2617 | CODE: |
2703 | RETVAL = 0; |
2618 | RETVAL = 0; |
2704 | while (rgn = rgn->parent) |
2619 | while (rgn = rgn->parent) |
2705 | RETVAL++; |
2620 | RETVAL++; |
… | |
… | |
2733 | list () |
2648 | list () |
2734 | PPCODE: |
2649 | PPCODE: |
2735 | EXTEND (SP, clients.size ()); |
2650 | EXTEND (SP, clients.size ()); |
2736 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2651 | for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2737 | PUSHs (sv_2mortal (to_sv (*i))); |
2652 | PUSHs (sv_2mortal (to_sv (*i))); |
|
|
2653 | |
|
|
2654 | STRLEN |
|
|
2655 | client::inbuf_append (SV *data) |
|
|
2656 | CODE: |
|
|
2657 | { |
|
|
2658 | STRLEN len; |
|
|
2659 | char *ptr = SvPVbyte (data, len); |
|
|
2660 | |
|
|
2661 | min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len); |
|
|
2662 | memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len); |
|
|
2663 | THIS->inbuf_len += len; |
|
|
2664 | |
|
|
2665 | THIS->inbuf_handle (); |
|
|
2666 | |
|
|
2667 | RETVAL = len; |
|
|
2668 | } |
|
|
2669 | OUTPUT: RETVAL |
2738 | |
2670 | |
2739 | void |
2671 | void |
2740 | client::send_packet (SV *packet) |
2672 | client::send_packet (SV *packet) |
2741 | CODE: |
2673 | CODE: |
2742 | { |
2674 | { |
… | |
… | |
2760 | if (RETVAL) |
2692 | if (RETVAL) |
2761 | { |
2693 | { |
2762 | THIS->send_face (RETVAL, pri); |
2694 | THIS->send_face (RETVAL, pri); |
2763 | THIS->flush_fx (); |
2695 | THIS->flush_fx (); |
2764 | } |
2696 | } |
2765 | OUTPUT: |
2697 | OUTPUT: RETVAL |
2766 | RETVAL |
|
|
2767 | |
2698 | |
2768 | int |
2699 | int |
2769 | client::fx_want (int idx, int value = -1) |
2700 | client::fx_want (int idx, int value = -1) |
2770 | CODE: |
2701 | CODE: |
2771 | if (0 < idx && idx < FT_NUM) |
2702 | if (0 < idx && idx < FT_NUM) |
… | |
… | |
2774 | if (items > 2) |
2705 | if (items > 2) |
2775 | THIS->fx_want [idx] = value; |
2706 | THIS->fx_want [idx] = value; |
2776 | } |
2707 | } |
2777 | else |
2708 | else |
2778 | RETVAL = 0; |
2709 | RETVAL = 0; |
2779 | OUTPUT: |
2710 | OUTPUT: RETVAL |
2780 | RETVAL |
|
|
2781 | |
2711 | |
2782 | MODULE = cf PACKAGE = cf::sound PREFIX = sound_ |
2712 | MODULE = cf PACKAGE = cf::sound PREFIX = sound_ |
2783 | |
2713 | |
2784 | faceidx sound_find (utf8_string name) |
2714 | faceidx sound_find (utf8_string name) |
2785 | |
2715 | |
… | |
… | |
2798 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2728 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2799 | |
2729 | |
2800 | faceidx alloc (utf8_string name) |
2730 | faceidx alloc (utf8_string name) |
2801 | CODE: |
2731 | CODE: |
2802 | { |
2732 | { |
2803 | do |
2733 | RETVAL = face_alloc (); |
2804 | { |
|
|
2805 | RETVAL = faces.size (); |
|
|
2806 | faces.resize (RETVAL + 1); |
|
|
2807 | } |
|
|
2808 | while (!RETVAL); // crude way to leave index 0 |
|
|
2809 | |
2734 | |
2810 | faces [RETVAL].name = name; |
2735 | faces [RETVAL].name = name; |
2811 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2736 | facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2812 | |
2737 | |
2813 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2738 | if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2814 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2739 | if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2815 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2740 | if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2816 | } |
2741 | } |
|
|
2742 | OUTPUT: RETVAL |
|
|
2743 | |
|
|
2744 | faceidx faces_size () |
|
|
2745 | CODE: |
|
|
2746 | RETVAL = faces.size (); |
2817 | OUTPUT: RETVAL |
2747 | OUTPUT: RETVAL |
2818 | |
2748 | |
2819 | void set_type (faceidx idx, int value) |
2749 | void set_type (faceidx idx, int value) |
2820 | ALIAS: |
2750 | ALIAS: |
2821 | set_type = 0 |
2751 | set_type = 0 |
… | |
… | |
2832 | case 2: f->magicmap = value; break; |
2762 | case 2: f->magicmap = value; break; |
2833 | case 3: f->smooth = value; break; |
2763 | case 3: f->smooth = value; break; |
2834 | case 4: f->smoothlevel = value; break; |
2764 | case 4: f->smoothlevel = value; break; |
2835 | } |
2765 | } |
2836 | |
2766 | |
2837 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2767 | void set_csum (faceidx idx, int faceset, SV *chksum) |
2838 | CODE: |
2768 | CODE: |
2839 | { |
2769 | { |
2840 | faceinfo *f = face_info (idx); assert (f); |
2770 | faceinfo *f = face_info (idx); assert (f); |
2841 | facedata *d = &(faceset ? f->data64 : f->data32); |
2771 | facedata *d = f->face + faceset; |
2842 | sv_to (data, d->data); |
|
|
2843 | STRLEN clen; |
2772 | STRLEN clen; |
2844 | char *cdata = SvPVbyte (chksum, clen); |
2773 | char *cdata = SvPVbyte (chksum, clen); |
2845 | clen = min (CHKSUM_MAXLEN, clen); |
|
|
2846 | |
2774 | |
|
|
2775 | assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN)); |
2847 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2776 | assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2848 | |
2777 | |
2849 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2778 | if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2850 | { |
2779 | { |
2851 | d->chksum_len = clen; |
2780 | d->chksum_len = clen; |
2852 | memcpy (d->chksum, cdata, clen); |
2781 | memcpy (d->chksum, cdata, clen); |
2853 | |
2782 | |
2854 | // invalidate existing client face info |
2783 | // invalidate existing client face info |
2855 | for_all_clients (ns) |
2784 | for_all_clients (ns) |
2856 | if (ns->faceset == faceset) |
2785 | ns->invalidate_face (idx); |
2857 | { |
|
|
2858 | ns->faces_sent [idx] = false; |
|
|
2859 | ns->force_newmap = true; |
|
|
2860 | } |
|
|
2861 | } |
2786 | } |
2862 | } |
2787 | } |
2863 | |
2788 | |
2864 | int get_data_size (faceidx idx, int faceset = 0) |
2789 | SV *mangle_csum (SV *chksum) |
2865 | CODE: |
2790 | CODE: |
2866 | facedata *d = face_data (idx, faceset); |
2791 | STRLEN len; |
2867 | if (!d) XSRETURN_UNDEF; |
2792 | char *data = SvPVbyte (chksum, len); |
2868 | RETVAL = d->data.size (); |
2793 | RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN)); |
2869 | OUTPUT: |
2794 | OUTPUT: RETVAL |
2870 | RETVAL |
|
|
2871 | |
2795 | |
2872 | SV *get_chksum (faceidx idx, int faceset = 0) |
2796 | SV *get_csum (faceidx idx, int faceset = 0) |
2873 | CODE: |
2797 | CODE: |
2874 | facedata *d = face_data (idx, faceset); |
2798 | facedata *d = face_data (idx, faceset); |
2875 | if (!d) XSRETURN_UNDEF; |
2799 | if (!d) XSRETURN_UNDEF; |
2876 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2800 | RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2877 | OUTPUT: |
2801 | OUTPUT: RETVAL |
2878 | RETVAL |
|
|
2879 | |
2802 | |
2880 | SV *get_data (faceidx idx, int faceset = 0) |
2803 | int get_type (faceidx idx) |
2881 | CODE: |
2804 | CODE: |
2882 | facedata *d = face_data (idx, faceset); |
2805 | faceinfo *f = face_info (idx); |
2883 | if (!d) XSRETURN_UNDEF; |
2806 | if (!f) XSRETURN_UNDEF; |
2884 | RETVAL = newSVpvn (d->data.data (), d->data.length ()); |
2807 | RETVAL = f->type; |
2885 | OUTPUT: |
2808 | OUTPUT: RETVAL |
2886 | RETVAL |
2809 | |
|
|
2810 | SV *get_name (faceidx idx) |
|
|
2811 | CODE: |
|
|
2812 | faceinfo *f = face_info (idx); |
|
|
2813 | if (!f) XSRETURN_UNDEF; |
|
|
2814 | RETVAL = to_sv (f->name); |
|
|
2815 | OUTPUT: RETVAL |
2887 | |
2816 | |
2888 | void invalidate (faceidx idx) |
2817 | void invalidate (faceidx idx) |
2889 | CODE: |
2818 | CODE: |
2890 | for_all_clients (ns) |
2819 | for_all_clients (ns) |
2891 | { |
2820 | ns->invalidate_face (idx); |
2892 | ns->faces_sent [idx] = false; |
|
|
2893 | ns->force_newmap = true; |
|
|
2894 | } |
|
|
2895 | |
2821 | |
2896 | void invalidate_all () |
2822 | void invalidate_all () |
2897 | CODE: |
2823 | CODE: |
2898 | for_all_clients (ns) |
2824 | for_all_clients (ns) |
2899 | { |
2825 | ns->invalidate_all_faces (); |
2900 | ns->faces_sent.reset (); |
|
|
2901 | ns->force_newmap = true; |
|
|
2902 | } |
|
|
2903 | |
2826 | |
2904 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2827 | MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2905 | |
2828 | |
2906 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2829 | #INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2907 | |
2830 | |
… | |
… | |
2911 | OUTPUT: RETVAL |
2834 | OUTPUT: RETVAL |
2912 | |
2835 | |
2913 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2836 | animidx set (utf8_string name, SV *frames, int facings = 1) |
2914 | CODE: |
2837 | CODE: |
2915 | { |
2838 | { |
2916 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2839 | if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2917 | croak ("frames must be an arrayref"); |
2840 | croak ("frames must be an arrayref"); |
2918 | |
2841 | |
2919 | AV *av = (AV *)SvRV (frames); |
2842 | AV *av = (AV *)SvRV (frames); |
2920 | |
2843 | |
2921 | animation *anim = &animation::find (name); |
2844 | animation *anim = &animation::find (name); |
2922 | if (anim->number) |
2845 | if (anim->number) |
2923 | { |
2846 | { |
2924 | anim->resize (av_len (av) + 1); |
2847 | anim->resize (av_len (av) + 1); |
2925 | anim->facings = facings; |
2848 | anim->facings = facings; |
2926 | } |
2849 | } |
… | |
… | |
2954 | sv_to (sv, self); |
2877 | sv_to (sv, self); |
2955 | delete self; |
2878 | delete self; |
2956 | |
2879 | |
2957 | MODULE = cf PACKAGE = cf::object::thawer |
2880 | MODULE = cf PACKAGE = cf::object::thawer |
2958 | |
2881 | |
2959 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | |
2882 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h | |
|
|
2883 | |
|
|
2884 | bool |
|
|
2885 | errors_are_fatal (bool fatal) |
|
|
2886 | CODE: |
|
|
2887 | RETVAL = object_thawer::errors_are_fatal; |
|
|
2888 | object_thawer::errors_are_fatal = fatal; |
|
|
2889 | OUTPUT: RETVAL |
2960 | |
2890 | |
2961 | SV * |
2891 | SV * |
2962 | new_from_file (char *klass, octet_string path) |
2892 | new_from_file (char *klass, octet_string path) |
2963 | CODE: |
2893 | CODE: |
2964 | object_thawer *f = new object_thawer (path); |
2894 | object_thawer *f = new object_thawer (path); |
… | |
… | |
2990 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2920 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2991 | |
2921 | |
2992 | self->skip (); |
2922 | self->skip (); |
2993 | } |
2923 | } |
2994 | |
2924 | |
|
|
2925 | MODULE = cf PACKAGE = cf::treasurelist |
|
|
2926 | |
|
|
2927 | # quick hack, because I didn't want to implement accessors for treasurelist. |
|
|
2928 | # this asks for even more autogen, actually. |
|
|
2929 | |
|
|
2930 | void |
|
|
2931 | expand (treasurelist *list) |
|
|
2932 | PPCODE: |
|
|
2933 | EXTEND (SP, 3); |
|
|
2934 | PUSHs (sv_2mortal (to_sv (list->name))); |
|
|
2935 | PUSHs (sv_2mortal (to_sv (list->total_chance))); |
|
|
2936 | AV *av = newAV (); |
|
|
2937 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
2938 | for (treasure *item = list->items; item; item = item->next) |
|
|
2939 | { |
|
|
2940 | AV *iav = newAV (); |
|
|
2941 | av_push (av, newRV_noinc ((SV *)iav)); |
|
|
2942 | |
|
|
2943 | av_extend (iav, 7); |
|
|
2944 | av_push (iav, to_sv (item->item)); |
|
|
2945 | av_push (iav, to_sv (item->name)); |
|
|
2946 | av_push (iav, to_sv (item->change_arch.name)); |
|
|
2947 | av_push (iav, to_sv (item->change_arch.title)); |
|
|
2948 | av_push (iav, to_sv (item->change_arch.slaying)); |
|
|
2949 | av_push (iav, to_sv (item->chance)); |
|
|
2950 | av_push (iav, to_sv (item->nrof)); |
|
|
2951 | av_push (iav, to_sv (item->magic)); |
|
|
2952 | } |
|
|
2953 | |
|
|
2954 | MODULE = cf PACKAGE = cf::layout |
|
|
2955 | |
|
|
2956 | INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
|
|
2957 | |