… | |
… | |
4 | |
4 | |
5 | /* |
5 | /* |
6 | * This code is placed under the GNU General Public Licence (GPL) |
6 | * This code is placed under the GNU General Public Licence (GPL) |
7 | * |
7 | * |
8 | * Copyright (C) 2001-2005 by Chachkoff Yann |
8 | * Copyright (C) 2001-2005 by Chachkoff Yann |
9 | * Copyright (C) 2006 by Marc Lehmann <cf@schmorp.de> |
9 | * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
10 | * |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
14 | * (at your option) any later version. |
… | |
… | |
29 | #include <plugin_common.h> |
29 | #include <plugin_common.h> |
30 | #include <sounds.h> |
30 | #include <sounds.h> |
31 | #include <cstdarg> |
31 | #include <cstdarg> |
32 | #include <sproto.h> |
32 | #include <sproto.h> |
33 | |
33 | |
|
|
34 | #include "loader.h" |
34 | #include "cfperl.h" |
35 | #include "cfperl.h" |
35 | #include "shstr.h" |
36 | #include "shstr.h" |
36 | |
37 | |
37 | #include <unistd.h> |
38 | #include <unistd.h> |
38 | #if _POSIX_MEMLOCK |
39 | #if _POSIX_MEMLOCK |
… | |
… | |
101 | |
102 | |
102 | unordered_vector<attachable *> attachable::mortals; |
103 | unordered_vector<attachable *> attachable::mortals; |
103 | |
104 | |
104 | attachable::~attachable () |
105 | attachable::~attachable () |
105 | { |
106 | { |
|
|
107 | flags |=0x3300;//D |
106 | assert (!self); |
108 | assert (!self); |
107 | assert (!cb); |
109 | assert (!cb); |
108 | } |
110 | } |
109 | |
111 | |
110 | int |
112 | int |
111 | attachable::refcnt_cnt () const |
113 | attachable::refcnt_cnt () const |
112 | { |
114 | { |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
115 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
|
|
116 | } |
|
|
117 | |
|
|
118 | void |
|
|
119 | attachable::sever_self () |
|
|
120 | { |
|
|
121 | if (HV *self = this->self) |
|
|
122 | { |
|
|
123 | // keep a refcount because sv_unmagic might call attachable_free, |
|
|
124 | // which might clear self, causing sv_unmagic to crash on a now |
|
|
125 | // invalid object. |
|
|
126 | SvREFCNT_inc (self); |
|
|
127 | hv_clear (self); |
|
|
128 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
129 | SvREFCNT_dec (self); |
|
|
130 | |
|
|
131 | // self *must* be null now because thats sv_unmagic's job. |
|
|
132 | assert (!this->self); |
|
|
133 | flags |= 0x80; // severed //D |
|
|
134 | } |
114 | } |
135 | } |
115 | |
136 | |
116 | void |
137 | void |
117 | attachable::optimise () |
138 | attachable::optimise () |
118 | { |
139 | { |
119 | if (self |
140 | if (self |
120 | && SvREFCNT (self) == 1 |
141 | && SvREFCNT (self) == 1 |
121 | && !HvTOTALKEYS (self)) |
142 | && !HvTOTALKEYS (self)) |
122 | { |
143 | flags |= 0x40,//D |
123 | SV *self = (SV *)this->self; |
144 | sever_self (); |
124 | |
|
|
125 | SvREFCNT_inc (self); |
|
|
126 | sv_unmagic (self, PERL_MAGIC_ext); |
|
|
127 | SvREFCNT_dec (self); |
|
|
128 | assert (!this->self); |
|
|
129 | } |
|
|
130 | } |
145 | } |
131 | |
146 | |
132 | // check wether the object really is dead |
147 | // check wether the object really is dead |
133 | void |
148 | void |
134 | attachable::do_check () |
149 | attachable::do_check () |
… | |
… | |
149 | SvREFCNT_dec (cb); |
164 | SvREFCNT_dec (cb); |
150 | cb = 0; |
165 | cb = 0; |
151 | } |
166 | } |
152 | |
167 | |
153 | if (self) |
168 | if (self) |
154 | { |
169 | sever_self (); |
155 | hv_clear (self); |
|
|
156 | |
170 | |
157 | SV *self = (SV *)this->self; |
171 | flags |= 0x20; //D |
158 | SvREFCNT_inc (self); |
|
|
159 | sv_unmagic (self, PERL_MAGIC_ext); |
|
|
160 | SvREFCNT_dec (self); |
|
|
161 | // self is now 0 |
|
|
162 | assert (!this->self);//D//TODO remove soon |
|
|
163 | } |
|
|
164 | |
|
|
165 | mortals.push_back (this); |
172 | mortals.push_back (this); |
166 | } |
173 | } |
167 | |
174 | |
168 | void |
175 | void |
169 | attachable::destroy () |
176 | attachable::destroy () |
… | |
… | |
264 | |
271 | |
265 | if (!obj->self) |
272 | if (!obj->self) |
266 | { |
273 | { |
267 | obj->self = newHV (); |
274 | obj->self = newHV (); |
268 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
275 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
|
|
276 | obj->flags |= (obj->flags & 0xc0) << 8; |
|
|
277 | obj->flags &= ~0xc0;//D |
|
|
278 | obj->flags |= 0x10;//D |
269 | |
279 | |
270 | // now bless the object _once_ |
280 | // now bless the object _once_ |
271 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
281 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
272 | } |
282 | } |
273 | else |
283 | else |
… | |
… | |
345 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
355 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
346 | |
356 | |
347 | inline SV *to_sv (UUID v) |
357 | inline SV *to_sv (UUID v) |
348 | { |
358 | { |
349 | char buf[128]; |
359 | char buf[128]; |
350 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
360 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
351 | return newSVpv (buf, 0); |
361 | return newSVpv (buf, 0); |
352 | } |
362 | } |
353 | |
363 | |
354 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
364 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
355 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
365 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
… | |
… | |
602 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
612 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
603 | { |
613 | { |
604 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
614 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
605 | exit (EXIT_FAILURE); |
615 | exit (EXIT_FAILURE); |
606 | } |
616 | } |
|
|
617 | |
|
|
618 | { |
|
|
619 | dSP; |
|
|
620 | |
|
|
621 | PUSHMARK (SP); |
|
|
622 | PUTBACK; |
|
|
623 | call_pv ("cf::init", G_DISCARD | G_VOID); |
|
|
624 | } |
607 | } |
625 | } |
608 | |
626 | |
609 | void cfperl_main () |
627 | void cfperl_main () |
610 | { |
628 | { |
611 | dSP; |
629 | dSP; |
… | |
… | |
829 | void |
847 | void |
830 | cfperl_emergency_save () |
848 | cfperl_emergency_save () |
831 | { |
849 | { |
832 | CALL_BEGIN (0); |
850 | CALL_BEGIN (0); |
833 | CALL_CALL ("cf::emergency_save", G_VOID); |
851 | CALL_CALL ("cf::emergency_save", G_VOID); |
|
|
852 | CALL_END; |
|
|
853 | } |
|
|
854 | |
|
|
855 | void |
|
|
856 | cfperl_cleanup (int make_core) |
|
|
857 | { |
|
|
858 | CALL_BEGIN (1); |
|
|
859 | CALL_ARG (make_core); |
|
|
860 | CALL_CALL ("cf::post_cleanup", G_VOID); |
834 | CALL_END; |
861 | CALL_END; |
835 | } |
862 | } |
836 | |
863 | |
837 | maptile * |
864 | maptile * |
838 | maptile::find_sync (const char *path, maptile *origin) |
865 | maptile::find_sync (const char *path, maptile *origin) |
… | |
… | |
1559 | { |
1586 | { |
1560 | // reattach to all attachable objects in the game. |
1587 | // reattach to all attachable objects in the game. |
1561 | for_all_clients (ns) |
1588 | for_all_clients (ns) |
1562 | ns->reattach (); |
1589 | ns->reattach (); |
1563 | |
1590 | |
1564 | for_all_players (pl) |
|
|
1565 | pl->reattach (); |
|
|
1566 | |
|
|
1567 | //TODO |
|
|
1568 | //for (map_container::iterator i = maps.begin (); i != maps.end (); ++i) |
|
|
1569 | // i->second->reattach (); |
|
|
1570 | |
|
|
1571 | for_all_objects (op) |
1591 | for_all_objects (op) |
1572 | op->reattach (); |
1592 | op->reattach (); |
1573 | } |
1593 | } |
1574 | |
1594 | |
1575 | NV floor (NV x) |
1595 | NV floor (NV x) |
… | |
… | |
1647 | |
1667 | |
1648 | void cleanup (const char *cause, bool make_core = false) |
1668 | void cleanup (const char *cause, bool make_core = false) |
1649 | |
1669 | |
1650 | void emergency_save () |
1670 | void emergency_save () |
1651 | |
1671 | |
|
|
1672 | void _exit (int status = EXIT_SUCCESS) |
|
|
1673 | |
1652 | UV sv_2watcher (SV *w) |
1674 | UV sv_2watcher (SV *w) |
1653 | CODE: |
1675 | CODE: |
1654 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1676 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1655 | OUTPUT: |
1677 | OUTPUT: |
1656 | RETVAL |
1678 | RETVAL |
1657 | |
|
|
1658 | void _exit (int status = 0) |
|
|
1659 | |
1679 | |
1660 | #if _POSIX_MEMLOCK |
1680 | #if _POSIX_MEMLOCK |
1661 | |
1681 | |
1662 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1682 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1663 | |
1683 | |
… | |
… | |
1709 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1729 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1710 | else |
1730 | else |
1711 | XSRETURN_UNDEF; |
1731 | XSRETURN_UNDEF; |
1712 | OUTPUT: RETVAL |
1732 | OUTPUT: RETVAL |
1713 | |
1733 | |
|
|
1734 | bool |
|
|
1735 | load_resource_file (const char *filename) |
|
|
1736 | |
1714 | MODULE = cf PACKAGE = cf::attachable |
1737 | MODULE = cf PACKAGE = cf::attachable |
1715 | |
1738 | |
1716 | int |
1739 | int |
1717 | valid (SV *obj) |
1740 | valid (SV *obj) |
1718 | CODE: |
1741 | CODE: |
1719 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1742 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1720 | OUTPUT: |
1743 | OUTPUT: |
1721 | RETVAL |
1744 | RETVAL |
|
|
1745 | |
|
|
1746 | void |
|
|
1747 | debug_trace (attachable *obj, bool on = true) |
|
|
1748 | CODE: |
|
|
1749 | obj->flags &= ~attachable::F_DEBUG_TRACE; |
|
|
1750 | if (on) |
|
|
1751 | obj->flags |= attachable::F_DEBUG_TRACE; |
1722 | |
1752 | |
1723 | int mortals_size () |
1753 | int mortals_size () |
1724 | CODE: |
1754 | CODE: |
1725 | RETVAL = attachable::mortals.size (); |
1755 | RETVAL = attachable::mortals.size (); |
1726 | OUTPUT: RETVAL |
1756 | OUTPUT: RETVAL |
… | |
… | |
1728 | #object *mortals (U32 index) |
1758 | #object *mortals (U32 index) |
1729 | # CODE: |
1759 | # CODE: |
1730 | # RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; |
1760 | # RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; |
1731 | # OUTPUT: RETVAL |
1761 | # OUTPUT: RETVAL |
1732 | |
1762 | |
1733 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1763 | INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | |
1734 | |
1764 | |
1735 | MODULE = cf PACKAGE = cf::global |
1765 | MODULE = cf PACKAGE = cf::global |
1736 | |
1766 | |
1737 | int invoke (SV *klass, int event, ...) |
1767 | int invoke (SV *klass, int event, ...) |
1738 | CODE: |
1768 | CODE: |
… | |
… | |
1742 | RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); |
1772 | RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); |
1743 | OUTPUT: RETVAL |
1773 | OUTPUT: RETVAL |
1744 | |
1774 | |
1745 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1775 | MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1746 | |
1776 | |
1747 | INCLUDE: $PERL genacc object ../include/object.h | |
1777 | INCLUDE: $PERL $srcdir/genacc object ../include/object.h | |
1748 | |
1778 | |
1749 | int invoke (object *op, int event, ...) |
1779 | int invoke (object *op, int event, ...) |
1750 | CODE: |
1780 | CODE: |
1751 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1781 | if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1752 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1782 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
1803 | void |
1833 | void |
1804 | set_animation (object *op, int idx) |
1834 | set_animation (object *op, int idx) |
1805 | CODE: |
1835 | CODE: |
1806 | SET_ANIMATION (op, idx); |
1836 | SET_ANIMATION (op, idx); |
1807 | |
1837 | |
|
|
1838 | int |
|
|
1839 | num_animations (object *op) |
|
|
1840 | CODE: |
|
|
1841 | RETVAL = NUM_ANIMATIONS (op); |
|
|
1842 | OUTPUT: RETVAL |
|
|
1843 | |
1808 | object *find_best_object_match (object *op, const char *match) |
1844 | object *find_best_object_match (object *op, const char *match) |
1809 | |
1845 | |
1810 | object *find_marked_object (object *op) |
1846 | object *find_marked_object (object *op) |
1811 | |
1847 | |
1812 | int need_identify (object *obj); |
1848 | int need_identify (object *obj); |
1813 | |
1849 | |
1814 | int apply_shop_mat (object *shop_mat, object *op); |
1850 | int apply_shop_mat (object *shop_mat, object *op); |
|
|
1851 | |
|
|
1852 | int move_player (object *op, int dir) |
|
|
1853 | CODE: |
|
|
1854 | RETVAL = move_player (op, dir); |
|
|
1855 | OUTPUT: |
|
|
1856 | RETVAL |
1815 | |
1857 | |
1816 | int move (object *op, int dir, object *originator = op) |
1858 | int move (object *op, int dir, object *originator = op) |
1817 | CODE: |
1859 | CODE: |
1818 | RETVAL = move_ob (op, dir, originator); |
1860 | RETVAL = move_ob (op, dir, originator); |
1819 | OUTPUT: |
1861 | OUTPUT: |
… | |
… | |
1824 | manual_apply (applied, applier, flags); |
1866 | manual_apply (applied, applier, flags); |
1825 | |
1867 | |
1826 | void apply_below (object *op) |
1868 | void apply_below (object *op) |
1827 | CODE: |
1869 | CODE: |
1828 | player_apply_below (op); |
1870 | player_apply_below (op); |
|
|
1871 | |
|
|
1872 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
1829 | |
1873 | |
1830 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1874 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1831 | |
1875 | |
1832 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1876 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1833 | |
1877 | |
… | |
… | |
2018 | |
2062 | |
2019 | int command_summon (object *op, char *params) |
2063 | int command_summon (object *op, char *params) |
2020 | |
2064 | |
2021 | int command_arrest (object *op, char *params) |
2065 | int command_arrest (object *op, char *params) |
2022 | |
2066 | |
2023 | int command_kick (object *op, char *params) |
|
|
2024 | |
|
|
2025 | int command_banish (object *op, char *params) |
|
|
2026 | |
|
|
2027 | |
2067 | |
2028 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2068 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2029 | |
2069 | |
2030 | INCLUDE: $PERL genacc player ../include/player.h | |
2070 | INCLUDE: $PERL $srcdir/genacc player ../include/player.h | |
2031 | |
2071 | |
2032 | int invoke (player *pl, int event, ...) |
2072 | int invoke (player *pl, int event, ...) |
2033 | CODE: |
2073 | CODE: |
2034 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2074 | if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2035 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2075 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
… | |
… | |
2048 | pl->orig_stats = pl->ob->stats; |
2088 | pl->orig_stats = pl->ob->stats; |
2049 | |
2089 | |
2050 | void cf_player_move (player *pl, int dir) |
2090 | void cf_player_move (player *pl, int dir) |
2051 | |
2091 | |
2052 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2092 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2053 | |
|
|
2054 | player *first () |
|
|
2055 | CODE: |
|
|
2056 | RETVAL = first_player; |
|
|
2057 | OUTPUT: RETVAL |
|
|
2058 | |
2093 | |
2059 | bool |
2094 | bool |
2060 | cell_visible (player *pl, int dx, int dy) |
2095 | cell_visible (player *pl, int dx, int dy) |
2061 | CODE: |
2096 | CODE: |
2062 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2097 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
… | |
… | |
2115 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2150 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2116 | OUTPUT: RETVAL |
2151 | OUTPUT: RETVAL |
2117 | |
2152 | |
2118 | SV *registry (maptile *map) |
2153 | SV *registry (maptile *map) |
2119 | |
2154 | |
2120 | INCLUDE: $PERL genacc maptile ../include/map.h | |
2155 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2121 | |
2156 | |
2122 | void |
2157 | void |
2123 | maptile::instantiate () |
2158 | maptile::instantiate () |
2124 | |
2159 | |
2125 | maptile *new () |
2160 | maptile *new () |
… | |
… | |
2139 | EXTEND (SP, THIS->players); |
2174 | EXTEND (SP, THIS->players); |
2140 | for_all_players (pl) |
2175 | for_all_players (pl) |
2141 | if (pl->ob && pl->ob->map == THIS) |
2176 | if (pl->ob && pl->ob->map == THIS) |
2142 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2177 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2143 | } |
2178 | } |
|
|
2179 | |
|
|
2180 | void |
|
|
2181 | maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
|
|
2182 | CODE: |
|
|
2183 | { |
|
|
2184 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
|
|
2185 | croak ("maptile::add_underlay: palette must be arrayref"); |
|
|
2186 | |
|
|
2187 | palette = SvRV (palette); |
|
|
2188 | |
|
|
2189 | STRLEN idxlen; |
|
|
2190 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
|
|
2191 | |
|
|
2192 | for (int x = 0; x < THIS->width; ++x) |
|
|
2193 | for (int y = 0; y < THIS->height; ++y) |
|
|
2194 | { |
|
|
2195 | for (object *op = THIS->at (x, y).bot; op; op = op->above) |
|
|
2196 | if (op->flag [FLAG_IS_FLOOR]) |
|
|
2197 | goto skip_space; |
|
|
2198 | |
|
|
2199 | { |
|
|
2200 | int offs = offset + y * stride + x; |
|
|
2201 | if (IN_RANGE_EXC (offs, 0, idxlen)) |
|
|
2202 | { |
|
|
2203 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
|
|
2204 | { |
|
|
2205 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
|
|
2206 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2207 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
|
|
2208 | } |
|
|
2209 | } |
|
|
2210 | } |
|
|
2211 | |
|
|
2212 | skip_space: ; |
|
|
2213 | } |
|
|
2214 | } |
|
|
2215 | |
|
|
2216 | void |
|
|
2217 | maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) |
|
|
2218 | CODE: |
|
|
2219 | { |
|
|
2220 | if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
|
|
2221 | croak ("maptile::set_regiondata: palette must be arrayref"); |
|
|
2222 | |
|
|
2223 | palette = SvRV (palette); |
|
|
2224 | |
|
|
2225 | STRLEN idxlen; |
|
|
2226 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
|
|
2227 | |
|
|
2228 | region **regionmap = (region **)malloc ( |
|
|
2229 | (av_len ((AV *)palette) + 1) * sizeof (region *)); |
|
|
2230 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
|
|
2231 | |
|
|
2232 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
|
|
2233 | regionmap [i] = region::find ( |
|
|
2234 | SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
|
|
2235 | |
|
|
2236 | for (int y = 0; y < THIS->height; ++y) |
|
|
2237 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
|
|
2238 | |
|
|
2239 | sfree (THIS->regions, THIS->size ()); |
|
|
2240 | free (THIS->regionmap); |
|
|
2241 | |
|
|
2242 | THIS->regions = regions; |
|
|
2243 | THIS->regionmap = regionmap; |
|
|
2244 | } |
2144 | |
2245 | |
2145 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2246 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2146 | |
2247 | |
2147 | int out_of_map (maptile *map, int x, int y) |
2248 | int out_of_map (maptile *map, int x, int y) |
2148 | |
2249 | |
… | |
… | |
2229 | OUTPUT: RETVAL |
2330 | OUTPUT: RETVAL |
2230 | |
2331 | |
2231 | void fix_walls (maptile *map, int x, int y) |
2332 | void fix_walls (maptile *map, int x, int y) |
2232 | |
2333 | |
2233 | void fix_walls_around (maptile *map, int x, int y) |
2334 | void fix_walls_around (maptile *map, int x, int y) |
2234 | |
|
|
2235 | const char * |
|
|
2236 | region_name (maptile *m) |
|
|
2237 | CODE: |
|
|
2238 | RETVAL = get_name_of_region_for_map (m); |
|
|
2239 | OUTPUT: RETVAL |
|
|
2240 | |
2335 | |
2241 | # worst xs function of my life |
2336 | # worst xs function of my life |
2242 | bool |
2337 | bool |
2243 | _create_random_map (\ |
2338 | _create_random_map (\ |
2244 | maptile *self,\ |
2339 | maptile *self,\ |
… | |
… | |
2338 | PROTOTYPE: |
2433 | PROTOTYPE: |
2339 | CODE: |
2434 | CODE: |
2340 | RETVAL = first_archetype; |
2435 | RETVAL = first_archetype; |
2341 | OUTPUT: RETVAL |
2436 | OUTPUT: RETVAL |
2342 | |
2437 | |
2343 | INCLUDE: $PERL genacc archetype ../include/object.h | |
2438 | INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | |
2344 | |
2439 | |
2345 | MODULE = cf PACKAGE = cf::party |
2440 | MODULE = cf PACKAGE = cf::party |
2346 | |
2441 | |
2347 | partylist *first () |
2442 | partylist *first () |
2348 | PROTOTYPE: |
2443 | PROTOTYPE: |
2349 | CODE: |
2444 | CODE: |
2350 | RETVAL = get_firstparty (); |
2445 | RETVAL = get_firstparty (); |
2351 | OUTPUT: RETVAL |
2446 | OUTPUT: RETVAL |
2352 | |
2447 | |
2353 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2448 | INCLUDE: $PERL $srcdir/genacc partylist ../include/player.h | |
2354 | |
2449 | |
2355 | MODULE = cf PACKAGE = cf::region |
2450 | MODULE = cf PACKAGE = cf::region |
2356 | |
2451 | |
2357 | region *first () |
2452 | void |
2358 | PROTOTYPE: |
2453 | list () |
2359 | CODE: |
2454 | PPCODE: |
2360 | RETVAL = first_region; |
2455 | for_all_regions (rgn) |
2361 | OUTPUT: RETVAL |
2456 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2362 | |
2457 | |
2363 | region *find (char *name) |
2458 | region *find (char *name) |
2364 | PROTOTYPE: $ |
2459 | PROTOTYPE: $ |
2365 | CODE: |
2460 | CODE: |
2366 | RETVAL = get_region_by_name (name); |
2461 | RETVAL = region::find (name); |
2367 | OUTPUT: RETVAL |
2462 | OUTPUT: RETVAL |
2368 | |
2463 | |
|
|
2464 | region *find_fuzzy (char *name) |
|
|
2465 | PROTOTYPE: $ |
|
|
2466 | CODE: |
|
|
2467 | RETVAL = region::find_fuzzy (name); |
|
|
2468 | OUTPUT: RETVAL |
|
|
2469 | |
2369 | INCLUDE: $PERL genacc region ../include/map.h | |
2470 | INCLUDE: $PERL $srcdir/genacc region ../include/map.h | |
2370 | |
2471 | |
2371 | MODULE = cf PACKAGE = cf::living |
2472 | MODULE = cf PACKAGE = cf::living |
2372 | |
2473 | |
2373 | INCLUDE: $PERL genacc living ../include/living.h | |
2474 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2374 | |
2475 | |
2375 | MODULE = cf PACKAGE = cf::settings |
2476 | MODULE = cf PACKAGE = cf::settings |
2376 | |
2477 | |
2377 | INCLUDE: $PERL genacc Settings ../include/global.h | |
2478 | INCLUDE: $PERL $srcdir/genacc Settings ../include/global.h | |
2378 | |
2479 | |
2379 | MODULE = cf PACKAGE = cf::client |
2480 | MODULE = cf PACKAGE = cf::client |
2380 | |
2481 | |
2381 | INCLUDE: $PERL genacc client ../include/client.h | |
2482 | INCLUDE: $PERL $srcdir/genacc client ../include/client.h | |
2382 | |
2483 | |
2383 | int invoke (client *ns, int event, ...) |
2484 | int invoke (client *ns, int event, ...) |
2384 | CODE: |
2485 | CODE: |
2385 | if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2486 | if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2386 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2487 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |