… | |
… | |
52 | #include <XSUB.h> |
52 | #include <XSUB.h> |
53 | |
53 | |
54 | #include "CoroAPI.h" |
54 | #include "CoroAPI.h" |
55 | #include "perlxsi.c" |
55 | #include "perlxsi.c" |
56 | |
56 | |
57 | extern sint64 *levels; // the experience table |
|
|
58 | |
|
|
59 | typedef object_thawer &object_thawer_ref; |
57 | typedef object_thawer &object_thawer_ref; |
60 | typedef object_freezer &object_freezer_ref; |
58 | typedef object_freezer &object_freezer_ref; |
61 | |
59 | |
62 | typedef std::string std__string; |
60 | typedef std::string std__string; |
63 | |
61 | |
… | |
… | |
479 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
477 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
480 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
478 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
481 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
479 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
482 | && !sv_derived_from (sv, "cf::object"))) |
480 | && !sv_derived_from (sv, "cf::object"))) |
483 | croak ("object of type cf::object expected"); |
481 | croak ("object of type cf::object expected"); |
|
|
482 | |
|
|
483 | return SvPTR_nc (sv); |
|
|
484 | } |
|
|
485 | |
|
|
486 | static long noinline |
|
|
487 | SvPTR_ornull_maptile (SV *sv) |
|
|
488 | { |
|
|
489 | if (expect_false (!SvOK (sv))) return 0; |
|
|
490 | |
|
|
491 | if (!SvROK (sv) |
|
|
492 | || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap |
|
|
493 | && !sv_derived_from (sv, "cf::map"))) |
|
|
494 | croak ("object of type cf::map expected"); |
484 | |
495 | |
485 | return SvPTR_nc (sv); |
496 | return SvPTR_nc (sv); |
486 | } |
497 | } |
487 | |
498 | |
488 | static long noinline |
499 | static long noinline |
… | |
… | |
565 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
576 | 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); } |
577 | 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); } |
578 | 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); } |
579 | 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); } |
580 | 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); } |
581 | 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); } |
582 | 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); } |
583 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
|
|
584 | 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"); } |
585 | 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"); } |
586 | 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"); } |
587 | 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"); } |
588 | 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"); } |
589 | 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"); } |
590 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
… | |
… | |
695 | template<class type> |
706 | template<class type> |
696 | static void noinline |
707 | static void noinline |
697 | cf_obj_to (SV *arg, type &var) |
708 | cf_obj_to (SV *arg, type &var) |
698 | { |
709 | { |
699 | sv_to (arg, var); |
710 | sv_to (arg, var); |
700 | if (!var) |
711 | if (expect_false (!var)) |
701 | croak ("must not pass invalid/null cf_obj here"); |
712 | croak ("must not pass invalid/null cf_obj here"); |
702 | } |
713 | } |
703 | |
714 | |
704 | template<class object> |
715 | template<class object> |
705 | static void noinline |
716 | static void noinline |
706 | cf_obj_ornull_to (SV *arg, object *&var) |
717 | cf_obj_ornull_to (SV *arg, object *&var) |
707 | { |
718 | { |
708 | if (SvOK (arg)) |
719 | if (SvOK (arg)) |
709 | { |
720 | { |
710 | sv_to (arg, var); |
721 | sv_to (arg, var); |
711 | if (!var) |
722 | if (expect_false (!var)) |
712 | croak ("unable to convert perl object to C++ object"); |
723 | croak ("unable to convert perl object to C++ object"); |
713 | } |
724 | } |
714 | else |
725 | else |
715 | var = 0; |
726 | var = 0; |
716 | } |
727 | } |
… | |
… | |
1799 | |
1810 | |
1800 | int random_roll (int min, int max, object *op, int goodbad); |
1811 | int random_roll (int min, int max, object *op, int goodbad); |
1801 | |
1812 | |
1802 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1813 | const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1803 | |
1814 | |
1804 | int |
|
|
1805 | exp_to_level (val64 exp) |
1815 | int exp_to_level (val64 exp) |
1806 | CODE: |
|
|
1807 | { |
|
|
1808 | int i = 0; |
|
|
1809 | |
1816 | |
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) |
1817 | val64 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 |
|
|
1833 | |
1818 | |
1834 | SV * |
1819 | SV * |
1835 | resistance_to_string (int atnr) |
1820 | resistance_to_string (int atnr) |
1836 | CODE: |
1821 | CODE: |
1837 | if (atnr >= 0 && atnr < NROFATTACKS) |
1822 | if (atnr >= 0 && atnr < NROFATTACKS) |
… | |
… | |
2028 | } |
2013 | } |
2029 | OUTPUT: |
2014 | OUTPUT: |
2030 | RETVAL |
2015 | RETVAL |
2031 | |
2016 | |
2032 | object *find_best_object_match (object *op, utf8_string match) |
2017 | object *find_best_object_match (object *op, utf8_string match) |
2033 | |
|
|
2034 | object *find_marked_object (object *op) |
|
|
2035 | |
|
|
2036 | int need_identify (object *obj); |
|
|
2037 | |
2018 | |
2038 | int apply_shop_mat (object *shop_mat, object *op); |
2019 | int apply_shop_mat (object *shop_mat, object *op); |
2039 | |
2020 | |
2040 | int move (object *op, int dir, object *originator = op) |
2021 | int move (object *op, int dir, object *originator = op) |
2041 | CODE: |
2022 | CODE: |
… | |
… | |
2954 | sv_to (sv, self); |
2935 | sv_to (sv, self); |
2955 | delete self; |
2936 | delete self; |
2956 | |
2937 | |
2957 | MODULE = cf PACKAGE = cf::object::thawer |
2938 | MODULE = cf PACKAGE = cf::object::thawer |
2958 | |
2939 | |
2959 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | |
2940 | INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h | |
|
|
2941 | |
|
|
2942 | bool |
|
|
2943 | errors_are_fatal (bool fatal) |
|
|
2944 | CODE: |
|
|
2945 | RETVAL = object_thawer::errors_are_fatal; |
|
|
2946 | object_thawer::errors_are_fatal = fatal; |
|
|
2947 | OUTPUT: |
|
|
2948 | RETVAL |
2960 | |
2949 | |
2961 | SV * |
2950 | SV * |
2962 | new_from_file (char *klass, octet_string path) |
2951 | new_from_file (char *klass, octet_string path) |
2963 | CODE: |
2952 | CODE: |
2964 | object_thawer *f = new object_thawer (path); |
2953 | object_thawer *f = new object_thawer (path); |