ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.70 by elmex, Mon Dec 4 15:15:34 2006 UTC vs.
Revision 1.76 by root, Wed Dec 13 02:55:51 2006 UTC

43extern sint64 *levels; // the experience table 43extern sint64 *levels; // the experience table
44 44
45typedef object object_ornull; 45typedef object object_ornull;
46typedef maptile maptile_ornull; 46typedef maptile maptile_ornull;
47 47
48#if IVSIZE >= 8
49 typedef IV val64;
50# define newSVval64 newSViv
51# define SvVAL64 SvIV
52#else
48typedef 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
52static f_plug_api gethook = cfapi_get_hooks; 58static f_plug_api gethook = cfapi_get_hooks;
53static f_plug_api object_set_property = cfapi_object_set_property; 59static f_plug_api object_set_property = cfapi_object_set_property;
54static f_plug_api object_insert = cfapi_object_insert; 60static f_plug_api object_insert = cfapi_object_insert;
55 61
148inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 154inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
149 155
150inline SV *to_sv (UUID v) 156inline 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
157inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 163inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
158inline 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 164inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
159inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 165inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
160inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 166inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
161inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 167inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
162inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 168inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
163inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } 169inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); }
187inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 193inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
188 194
189inline void sv_to (SV *sv, UUID &v) 195inline 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
200static SV * 203static SV *
201newSVdt_va (va_list &ap, data_type type) 204newSVdt_va (va_list &ap, data_type type)
202{ 205{
768static CommArray_s rtn_cmd; 771static CommArray_s rtn_cmd;
769 772
770static int 773static int
771runPluginCommand (object *obj, char *params) 774runPluginCommand (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
803extern "C" void *cfperl_getPluginProperty (int *type, ...) 779extern "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
1085int 1042int
1086cfperl_result_INT (int idx) 1043cfperl_result_INT (int idx)
1087{ 1044{
1088 return SvIV (cfperl_result (idx)); 1045 return SvIV (cfperl_result (idx));
1046}
1047
1048double
1049cfperl_result_DOUBLE (int idx)
1050{
1051 return SvNV (cfperl_result (idx));
1089} 1052}
1090 1053
1091MODULE = cf PACKAGE = cf PREFIX = cf_ 1054MODULE = cf PACKAGE = cf PREFIX = cf_
1092 1055
1093BOOT: 1056BOOT:
1617 //I_EVENT_API (PACKAGE); 1580 //I_EVENT_API (PACKAGE);
1618} 1581}
1619 1582
1620void _init_vars () 1583void _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
1628void _global_reattach () 1591void _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
1696void _exit (int status = 0) 1659void _exit (int status = 0)
1697 1660
1698int cf_find_animation (char *text) 1661int find_animation (char *text)
1699 PROTOTYPE: $ 1662 PROTOTYPE: $
1700 1663
1701int random_roll(int min, int max, object *op, int goodbad); 1664int random_roll (int min, int max, object *op, int goodbad);
1702 1665
1703const char *cost_string_from_value(uint64 cost, int approx = 0) 1666const char *cost_string_from_value(uint64 cost, int approx = 0)
1704 1667
1705int invoke (int event, ...) 1668int invoke (int event, ...)
1706 CODE: 1669 CODE:
1822 1785
1823object *find_best_object_match (object *op, const char *match) 1786object *find_best_object_match (object *op, const char *match)
1824 1787
1825object *find_marked_object (object *op) 1788object *find_marked_object (object *op)
1826 1789
1827int cf_object_get_resistance (object *op, int rtype) 1790int 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
1799void set_resistance (object *op, int rtype, int val)
1800 CODE:
1801 if (rtype < 0 || rtype >= NROFATTACKS)
1802 op->resist[rtype] = val;
1829 1803
1830int need_identify (const object *obj); 1804int need_identify (const object *obj);
1831 1805
1832int apply_shop_mat (object *shop_mat, object *op); 1806int 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
1840void cf_object_apply (object *op, object *author, int flags = 0) 1814void apply (object *applier, object *applied, int flags = 0)
1815 CODE:
1816 manual_apply (applied, applier, flags);
1841 1817
1842void cf_object_apply_below (object *op) 1818void apply_below (object *op)
1819 CODE:
1820 player_apply_below (op);
1843 1821
1844void cf_object_remove (object *op) 1822void remove (object *op)
1823 CODE:
1824 op->remove ();
1845 1825
1846void cf_object_free (object *op) 1826void destroy (object *op, int recursive = 0)
1827 CODE:
1828 op->destroy (recursive);
1847 1829
1848object *cf_object_present_archname_inside (object *op, char *whatstr) 1830object *cf_object_present_archname_inside (object *op, char *whatstr)
1849 1831
1850int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1832int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1851 1833
1852int cf_object_change_map (object *op, int x, int y, maptile *map) 1834int cf_object_change_map (object *op, int x, int y, maptile *map)
1853 1835
1854object *cf_object_clone (object *op, int clonetype = 0) 1836object *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
1856int cf_object_pay_item (object *op, object *buyer) 1847int pay_item (object *op, object *buyer)
1848 CODE:
1849 RETVAL = pay_for_item (op, buyer);
1850 OUTPUT: RETVAL
1857 1851
1858int cf_object_pay_amount (object *op, uint64 amount) 1852int pay_amount (object *op, uint64 amount)
1853 CODE:
1854 RETVAL = pay_for_amount (amount, op);
1855 OUTPUT: RETVAL
1859 1856
1860void pay_player (object *op, uint64 amount) 1857void pay_player (object *op, uint64 amount)
1861 1858
1862val64 pay_player_arch (object *op, const char *arch, uint64 amount) 1859val64 pay_player_arch (object *op, const char *arch, uint64 amount)
1863 1860
1864int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) 1861int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0)
1865 1862
1866int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) 1863void learn_spell (object *op, object *sp, int special_prayer = 0)
1864 CODE:
1865 do_learn_spell (op, sp, special_prayer);
1867 1866
1868void cf_object_learn_spell (object *op, object *sp)
1869
1870void cf_object_forget_spell (object *op, object *sp) 1867void forget_spell (object *op, object *sp)
1868 CODE:
1869 do_forget_spell (op, query_name (sp));
1871 1870
1872object *cf_object_check_for_spell (object *op, char *spellname) 1871object *check_for_spell (object *op, char *spellname)
1872 CODE:
1873 RETVAL = check_spell_known (op, spellname);
1874 OUTPUT: RETVAL
1873 1875
1874int cf_object_query_money (object *op) 1876int query_money (object *op)
1875 ALIAS: money = 0 1877 ALIAS: money = 0
1876 1878
1877int cf_object_query_cost (object *op, object *who, int flags) 1879int query_cost (object *op, object *who, int flags)
1878 ALIAS: cost = 0 1880 ALIAS: cost = 0
1879 1881
1880void cf_object_activate_rune (object *op , object *victim) 1882void spring_trap (object *op, object *victim)
1881 1883
1882int cf_object_check_trigger (object *op, object *cause) 1884int check_trigger (object *op, object *cause)
1883 1885
1884int cf_object_out_of_map (object *op, int x, int y)
1885
1886void cf_object_drop (object *op, object *author) 1886void drop (object *who, object *op)
1887 1887
1888void cf_object_take (object *op, object *author) 1888void pick_up (object *who, object *op)
1889 1889
1890object *cf_object_insert_object (object *op, object *container) 1890object *cf_object_insert_object (object *op, object *container)
1891 1891
1892object *cf_object_insert_in_ob (object *ob, object *where) 1892object *cf_object_insert_in_ob (object *ob, object *where)
1893 1893
1894int cf_object_teleport (object *op, maptile *map, int x, int y) 1894int cf_object_teleport (object *op, maptile *map, int x, int y)
1895 1895
1896void cf_object_update (object *op, int flags) 1896void update (object *op, int action)
1897 1897 CODE:
1898void cf_object_pickup (object *op, object *what) 1898 update_object (op, action);
1899 1899
1900object *cf_create_object_by_name (const char *name) 1900object *cf_create_object_by_name (const char *name)
1901 1901
1902void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1902void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1903 1903
1912void use_trigger (object *op); 1912void use_trigger (object *op);
1913 1913
1914void add_button_link (object *button, maptile *map, int connected); 1914void add_button_link (object *button, maptile *map, int connected);
1915 1915
1916void remove_button_link (object *op); 1916void remove_button_link (object *op);
1917
1918void
1919cf_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
1925MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1919MODULE = cf PACKAGE = cf::object PREFIX = cf_
1926 1920
1927void cf_fix_object (object *pl) 1921void cf_fix_object (object *pl)
2201 2195
2202void clean_tmp_map (maptile *map) 2196void clean_tmp_map (maptile *map)
2203 2197
2204void play_sound_map (maptile *map, int x, int y, int sound_num) 2198void play_sound_map (maptile *map, int x, int y, int sound_num)
2205 2199
2200int out_of_map (maptile *map, int x, int y)
2201
2206maptile *tile_map (maptile *map, unsigned int dir) 2202maptile *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
2394MODULE = cf PACKAGE = cf::living 2390MODULE = cf PACKAGE = cf::living
2395 2391
2396INCLUDE: $PERL genacc living ../include/living.h | 2392INCLUDE: $PERL genacc living ../include/living.h |
2397 2393
2394MODULE = cf PACKAGE = cf::settings
2395
2396INCLUDE: $PERL genacc Settings ../include/global.h |
2397

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines