… | |
… | |
43 | extern sint64 *levels; // the experience table |
43 | extern sint64 *levels; // the experience table |
44 | |
44 | |
45 | typedef object object_ornull; |
45 | typedef object object_ornull; |
46 | typedef maptile maptile_ornull; |
46 | typedef maptile maptile_ornull; |
47 | |
47 | |
|
|
48 | #if IVSIZE >= 8 |
|
|
49 | typedef IV val64; |
|
|
50 | # define newSVval64 newSViv |
|
|
51 | # define SvVAL64 SvIV |
|
|
52 | #else |
48 | typedef double val64; |
53 | typedef double val64; |
49 | #define newSVval64 newSVnv |
54 | # define newSVval64 newSVnv |
50 | #define SvVAL64 SvNV |
55 | # define SvVAL64 SvNV |
|
|
56 | #endif |
51 | |
57 | |
52 | static f_plug_api gethook = cfapi_get_hooks; |
58 | static f_plug_api gethook = cfapi_get_hooks; |
53 | static f_plug_api object_set_property = cfapi_object_set_property; |
59 | static f_plug_api object_set_property = cfapi_object_set_property; |
54 | static f_plug_api object_insert = cfapi_object_insert; |
60 | static f_plug_api object_insert = cfapi_object_insert; |
55 | |
61 | |
… | |
… | |
148 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
154 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
149 | |
155 | |
150 | inline SV *to_sv (UUID v) |
156 | inline SV *to_sv (UUID v) |
151 | { |
157 | { |
152 | char buf[128]; |
158 | char buf[128]; |
153 | snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq); |
159 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
154 | return newSVpv (buf, 0); |
160 | return newSVpv (buf, 0); |
155 | } |
161 | } |
156 | |
162 | |
157 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
163 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
158 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed |
164 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
159 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
165 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
160 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
166 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
161 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
167 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
162 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
168 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
163 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
169 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
… | |
… | |
187 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
193 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
188 | |
194 | |
189 | inline void sv_to (SV *sv, UUID &v) |
195 | inline void sv_to (SV *sv, UUID &v) |
190 | { |
196 | { |
191 | unsigned int version; |
197 | unsigned int version; |
192 | unsigned long long seq; |
|
|
193 | |
198 | |
194 | if (2 != sscanf (SvPV_nolen (sv), "<%d.%llx>", &version, &seq) || 1 != version) |
199 | if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) |
195 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
200 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
196 | |
|
|
197 | v.seq = seq; |
|
|
198 | } |
201 | } |
199 | |
202 | |
200 | static SV * |
203 | static SV * |
201 | newSVdt_va (va_list &ap, data_type type) |
204 | newSVdt_va (va_list &ap, data_type type) |
202 | { |
205 | { |
… | |
… | |
768 | static CommArray_s rtn_cmd; |
771 | static CommArray_s rtn_cmd; |
769 | |
772 | |
770 | static int |
773 | static int |
771 | runPluginCommand (object *obj, char *params) |
774 | runPluginCommand (object *obj, char *params) |
772 | { |
775 | { |
773 | dSP; |
776 | return -1; |
774 | |
|
|
775 | ENTER; |
|
|
776 | SAVETMPS; |
|
|
777 | |
|
|
778 | PUSHMARK (SP); |
|
|
779 | |
|
|
780 | EXTEND (SP, 3); |
|
|
781 | PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0))); |
|
|
782 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj))); |
|
|
783 | |
|
|
784 | if (params) |
|
|
785 | PUSHs (sv_2mortal (newSVpv (params, 0))); |
|
|
786 | |
|
|
787 | PUTBACK; |
|
|
788 | int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL); |
|
|
789 | SPAGAIN; |
|
|
790 | |
|
|
791 | if (SvTRUE (ERRSV)) |
|
|
792 | LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV)); |
|
|
793 | |
|
|
794 | int returnvalue = count > 0 ? POPi : -1; |
|
|
795 | |
|
|
796 | PUTBACK; |
|
|
797 | FREETMPS; |
|
|
798 | LEAVE; |
|
|
799 | |
|
|
800 | return returnvalue; |
|
|
801 | } |
777 | } |
802 | |
778 | |
803 | extern "C" void *cfperl_getPluginProperty (int *type, ...) |
779 | extern "C" void *cfperl_getPluginProperty (int *type, ...) |
804 | { |
780 | { |
805 | va_list args; |
781 | va_list args; |
… | |
… | |
808 | va_start (args, type); |
784 | va_start (args, type); |
809 | propname = va_arg (args, char *); |
785 | propname = va_arg (args, char *); |
810 | //printf ("Property name: %s\n", propname); |
786 | //printf ("Property name: %s\n", propname); |
811 | |
787 | |
812 | if (!strcmp (propname, "command?")) |
788 | if (!strcmp (propname, "command?")) |
813 | { |
|
|
814 | if (!perl) |
|
|
815 | return NULL; |
789 | return NULL; |
816 | |
790 | else if (!strcmp (propname, "Identification")) |
817 | const char *cmdname = va_arg (args, const char *); |
791 | { |
818 | HV *hv = get_hv ("cf::COMMAND", 1); |
|
|
819 | SV **svp = hv_fetch (hv, cmdname, strlen (cmdname) + 1, 0); |
|
|
820 | |
|
|
821 | va_end (args); |
792 | va_end (args); |
822 | |
793 | return (void *)PLUGIN_NAME; |
823 | if (svp) |
|
|
824 | { |
|
|
825 | // this is totaly broken, should stash it into %COMMAND |
|
|
826 | rtn_cmd.name = cmdname; |
|
|
827 | rtn_cmd.time = SvNV (*svp); |
|
|
828 | rtn_cmd.func = runPluginCommand; |
|
|
829 | |
|
|
830 | return &rtn_cmd; |
|
|
831 | } |
|
|
832 | } |
794 | } |
833 | else if (!strcmp (propname, "Identification")) |
795 | else if (!strcmp (propname, "FullName")) |
834 | { |
796 | { |
835 | va_end (args); |
797 | va_end (args); |
836 | return (void*) PLUGIN_NAME; |
|
|
837 | } |
|
|
838 | else if (!strcmp (propname, "FullName")) |
|
|
839 | { |
|
|
840 | va_end (args); |
|
|
841 | return (void*) PLUGIN_VERSION; |
798 | return (void *)PLUGIN_VERSION; |
842 | } |
799 | } |
843 | else |
800 | else |
844 | va_end (args); |
801 | va_end (args); |
845 | |
802 | |
846 | return NULL; |
803 | return NULL; |
… | |
… | |
944 | object *op; |
901 | object *op; |
945 | player *pl; |
902 | player *pl; |
946 | maptile *map; |
903 | maptile *map; |
947 | |
904 | |
948 | // callback call ordering is: |
905 | // callback call ordering is: |
949 | // 1. per-object callback (NYI) |
906 | // 1. per-object callback |
950 | // 2. per-class object |
907 | // 2. per-class object |
951 | // 2a. per-type callback |
908 | // 3. per-type callback |
952 | // 4. global callbacks |
909 | // 4. global callbacks |
953 | |
910 | |
954 | gather_callbacks (callbacks, cb_global, event); |
911 | gather_callbacks (callbacks, cb_global, event); |
955 | |
912 | |
956 | switch (KLASS_OF (event)) |
913 | switch (KLASS_OF (event)) |
… | |
… | |
1084 | |
1041 | |
1085 | int |
1042 | int |
1086 | cfperl_result_INT (int idx) |
1043 | cfperl_result_INT (int idx) |
1087 | { |
1044 | { |
1088 | return SvIV (cfperl_result (idx)); |
1045 | return SvIV (cfperl_result (idx)); |
|
|
1046 | } |
|
|
1047 | |
|
|
1048 | double |
|
|
1049 | cfperl_result_DOUBLE (int idx) |
|
|
1050 | { |
|
|
1051 | return SvNV (cfperl_result (idx)); |
1089 | } |
1052 | } |
1090 | |
1053 | |
1091 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1054 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1092 | |
1055 | |
1093 | BOOT: |
1056 | BOOT: |
… | |
… | |
1617 | //I_EVENT_API (PACKAGE); |
1580 | //I_EVENT_API (PACKAGE); |
1618 | } |
1581 | } |
1619 | |
1582 | |
1620 | void _init_vars () |
1583 | void _init_vars () |
1621 | CODE: |
1584 | CODE: |
1622 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1585 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1623 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1586 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1624 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1587 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1625 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1588 | cb_type = get_av ("cf::CB_TYPE" , 1); |
1626 | cb_map = get_av ("cf::CB_MAP" , 1); |
1589 | cb_map = get_av ("cf::CB_MAP" , 1); |
1627 | |
1590 | |
1628 | void _global_reattach () |
1591 | void _global_reattach () |
1629 | CODE: |
1592 | CODE: |
1630 | { |
1593 | { |
1631 | // reattach to all attachable objects in the game. |
1594 | // reattach to all attachable objects in the game. |
… | |
… | |
1693 | } |
1656 | } |
1694 | OUTPUT: RETVAL |
1657 | OUTPUT: RETVAL |
1695 | |
1658 | |
1696 | void _exit (int status = 0) |
1659 | void _exit (int status = 0) |
1697 | |
1660 | |
1698 | int cf_find_animation (char *text) |
1661 | int find_animation (char *text) |
1699 | PROTOTYPE: $ |
1662 | PROTOTYPE: $ |
1700 | |
1663 | |
1701 | int random_roll(int min, int max, object *op, int goodbad); |
1664 | int random_roll (int min, int max, object *op, int goodbad); |
1702 | |
1665 | |
1703 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1666 | const char *cost_string_from_value(uint64 cost, int approx = 0) |
1704 | |
1667 | |
1705 | int invoke (int event, ...) |
1668 | int invoke (int event, ...) |
1706 | CODE: |
1669 | CODE: |
… | |
… | |
1822 | |
1785 | |
1823 | object *find_best_object_match (object *op, const char *match) |
1786 | object *find_best_object_match (object *op, const char *match) |
1824 | |
1787 | |
1825 | object *find_marked_object (object *op) |
1788 | object *find_marked_object (object *op) |
1826 | |
1789 | |
1827 | int cf_object_get_resistance (object *op, int rtype) |
1790 | int resistance (object *op, int rtype, int newval = 0) |
1828 | ALIAS: resistance = 0 |
1791 | CODE: |
|
|
1792 | if (rtype < 0 || rtype >= NROFATTACKS) |
|
|
1793 | croak ("resistance out of bounds"); |
|
|
1794 | RETVAL = op->resist [rtype]; |
|
|
1795 | if (items >= 3) |
|
|
1796 | op->resist [rtype] = newval; |
|
|
1797 | OUTPUT: RETVAL |
|
|
1798 | |
|
|
1799 | void set_resistance (object *op, int rtype, int val) |
|
|
1800 | CODE: |
|
|
1801 | if (rtype < 0 || rtype >= NROFATTACKS) |
|
|
1802 | op->resist[rtype] = val; |
1829 | |
1803 | |
1830 | int need_identify (const object *obj); |
1804 | int need_identify (const object *obj); |
1831 | |
1805 | |
1832 | int apply_shop_mat (object *shop_mat, object *op); |
1806 | int apply_shop_mat (object *shop_mat, object *op); |
1833 | |
1807 | |
… | |
… | |
1835 | CODE: |
1809 | CODE: |
1836 | RETVAL = move_ob (op, dir, originator); |
1810 | RETVAL = move_ob (op, dir, originator); |
1837 | OUTPUT: |
1811 | OUTPUT: |
1838 | RETVAL |
1812 | RETVAL |
1839 | |
1813 | |
1840 | void cf_object_apply (object *op, object *author, int flags = 0) |
1814 | void apply (object *applier, object *applied, int flags = 0) |
|
|
1815 | CODE: |
|
|
1816 | manual_apply (applied, applier, flags); |
1841 | |
1817 | |
1842 | void cf_object_apply_below (object *op) |
1818 | void apply_below (object *op) |
|
|
1819 | CODE: |
|
|
1820 | player_apply_below (op); |
1843 | |
1821 | |
1844 | void cf_object_remove (object *op) |
1822 | void remove (object *op) |
|
|
1823 | CODE: |
|
|
1824 | op->remove (); |
1845 | |
1825 | |
1846 | void cf_object_free (object *op) |
1826 | void destroy (object *op, int recursive = 0) |
|
|
1827 | CODE: |
|
|
1828 | op->destroy (recursive); |
1847 | |
1829 | |
1848 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1830 | object *cf_object_present_archname_inside (object *op, char *whatstr) |
1849 | |
1831 | |
1850 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1832 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
1851 | |
1833 | |
1852 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
1834 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
1853 | |
1835 | |
1854 | object *cf_object_clone (object *op, int clonetype = 0) |
1836 | object *clone (object *op, int recursive = 0) |
|
|
1837 | CODE: |
|
|
1838 | if (recursive) |
|
|
1839 | RETVAL = object_create_clone (op); |
|
|
1840 | else |
|
|
1841 | { |
|
|
1842 | RETVAL = object::create (); |
|
|
1843 | op->copy_to (RETVAL); |
|
|
1844 | } |
|
|
1845 | OUTPUT: RETVAL |
1855 | |
1846 | |
1856 | int cf_object_pay_item (object *op, object *buyer) |
1847 | int pay_item (object *op, object *buyer) |
|
|
1848 | CODE: |
|
|
1849 | RETVAL = pay_for_item (op, buyer); |
|
|
1850 | OUTPUT: RETVAL |
1857 | |
1851 | |
1858 | int cf_object_pay_amount (object *op, uint64 amount) |
1852 | int pay_amount (object *op, uint64 amount) |
|
|
1853 | CODE: |
|
|
1854 | RETVAL = pay_for_amount (amount, op); |
|
|
1855 | OUTPUT: RETVAL |
1859 | |
1856 | |
1860 | void pay_player (object *op, uint64 amount) |
1857 | void pay_player (object *op, uint64 amount) |
1861 | |
1858 | |
1862 | val64 pay_player_arch (object *op, const char *arch, uint64 amount) |
1859 | val64 pay_player_arch (object *op, const char *arch, uint64 amount) |
1863 | |
1860 | |
1864 | int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) |
1861 | int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0) |
1865 | |
1862 | |
1866 | int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) |
1863 | void learn_spell (object *op, object *sp, int special_prayer = 0) |
|
|
1864 | CODE: |
|
|
1865 | do_learn_spell (op, sp, special_prayer); |
1867 | |
1866 | |
1868 | void cf_object_learn_spell (object *op, object *sp) |
|
|
1869 | |
|
|
1870 | void cf_object_forget_spell (object *op, object *sp) |
1867 | void forget_spell (object *op, object *sp) |
|
|
1868 | CODE: |
|
|
1869 | do_forget_spell (op, query_name (sp)); |
1871 | |
1870 | |
1872 | object *cf_object_check_for_spell (object *op, char *spellname) |
1871 | object *check_for_spell (object *op, char *spellname) |
|
|
1872 | CODE: |
|
|
1873 | RETVAL = check_spell_known (op, spellname); |
|
|
1874 | OUTPUT: RETVAL |
1873 | |
1875 | |
1874 | int cf_object_query_money (object *op) |
1876 | int query_money (object *op) |
1875 | ALIAS: money = 0 |
1877 | ALIAS: money = 0 |
1876 | |
1878 | |
1877 | int cf_object_query_cost (object *op, object *who, int flags) |
1879 | int query_cost (object *op, object *who, int flags) |
1878 | ALIAS: cost = 0 |
1880 | ALIAS: cost = 0 |
1879 | |
1881 | |
1880 | void cf_object_activate_rune (object *op , object *victim) |
1882 | void spring_trap (object *op, object *victim) |
1881 | |
1883 | |
1882 | int cf_object_check_trigger (object *op, object *cause) |
1884 | int check_trigger (object *op, object *cause) |
1883 | |
1885 | |
1884 | int cf_object_out_of_map (object *op, int x, int y) |
|
|
1885 | |
|
|
1886 | void cf_object_drop (object *op, object *author) |
1886 | void drop (object *who, object *op) |
1887 | |
1887 | |
1888 | void cf_object_take (object *op, object *author) |
1888 | void pick_up (object *who, object *op) |
1889 | |
1889 | |
1890 | object *cf_object_insert_object (object *op, object *container) |
1890 | object *cf_object_insert_object (object *op, object *container) |
1891 | |
1891 | |
1892 | object *cf_object_insert_in_ob (object *ob, object *where) |
1892 | object *cf_object_insert_in_ob (object *ob, object *where) |
1893 | |
1893 | |
1894 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1894 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1895 | |
1895 | |
1896 | void cf_object_update (object *op, int flags) |
1896 | void update (object *op, int action) |
1897 | |
1897 | CODE: |
1898 | void cf_object_pickup (object *op, object *what) |
1898 | update_object (op, action); |
1899 | |
1899 | |
1900 | object *cf_create_object_by_name (const char *name) |
1900 | object *cf_create_object_by_name (const char *name) |
1901 | |
1901 | |
1902 | void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) |
1902 | void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) |
1903 | |
1903 | |
… | |
… | |
1912 | void use_trigger (object *op); |
1912 | void use_trigger (object *op); |
1913 | |
1913 | |
1914 | void add_button_link (object *button, maptile *map, int connected); |
1914 | void add_button_link (object *button, maptile *map, int connected); |
1915 | |
1915 | |
1916 | void remove_button_link (object *op); |
1916 | void remove_button_link (object *op); |
1917 | |
|
|
1918 | void |
|
|
1919 | cf_object_set_resistance (object *op, int rtype, int val) |
|
|
1920 | CODE: |
|
|
1921 | if (rtype >= 0 && rtype < NROFATTACKS) |
|
|
1922 | op->resist[rtype] = val; |
|
|
1923 | |
1917 | |
1924 | |
1918 | |
1925 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1919 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1926 | |
1920 | |
1927 | void cf_fix_object (object *pl) |
1921 | void cf_fix_object (object *pl) |
… | |
… | |
2201 | |
2195 | |
2202 | void clean_tmp_map (maptile *map) |
2196 | void clean_tmp_map (maptile *map) |
2203 | |
2197 | |
2204 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2198 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2205 | |
2199 | |
|
|
2200 | int out_of_map (maptile *map, int x, int y) |
|
|
2201 | |
2206 | maptile *tile_map (maptile *map, unsigned int dir) |
2202 | maptile *tile_map (maptile *map, unsigned int dir) |
2207 | CODE: |
2203 | CODE: |
2208 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2204 | RETVAL = dir < 4 ? map->tile_map [dir] : 0; |
2209 | OUTPUT: |
2205 | OUTPUT: |
2210 | RETVAL |
2206 | RETVAL |
… | |
… | |
2393 | |
2389 | |
2394 | MODULE = cf PACKAGE = cf::living |
2390 | MODULE = cf PACKAGE = cf::living |
2395 | |
2391 | |
2396 | INCLUDE: $PERL genacc living ../include/living.h | |
2392 | INCLUDE: $PERL genacc living ../include/living.h | |
2397 | |
2393 | |
|
|
2394 | MODULE = cf PACKAGE = cf::settings |
|
|
2395 | |
|
|
2396 | INCLUDE: $PERL genacc Settings ../include/global.h | |
|
|
2397 | |