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.85 by root, Sat Dec 16 03:08:26 2006 UTC vs.
Revision 1.108 by elmex, Mon Dec 25 11:16:48 2006 UTC

19 * GNU General Public License for more details. 19 * GNU General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24*/ 24 */
25 25
26#define PLUGIN_NAME "perl" 26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 27#define PLUGIN_VERSION "cfperl 0.5"
28 28
29#include <plugin_common.h> 29#include <plugin_common.h>
36 36
37#include <EXTERN.h> 37#include <EXTERN.h>
38#include <perl.h> 38#include <perl.h>
39#include <XSUB.h> 39#include <XSUB.h>
40 40
41#include "CoroAPI.h"
41#include "perlxsi.c" 42#include "perlxsi.c"
42 43
43extern sint64 *levels; // the experience table 44extern sint64 *levels; // the experience table
44 45
45typedef object object_ornull; 46typedef object object_ornull;
59static f_plug_api object_set_property = cfapi_object_set_property; 60static f_plug_api object_set_property = cfapi_object_set_property;
60static f_plug_api object_insert = cfapi_object_insert; 61static f_plug_api object_insert = cfapi_object_insert;
61 62
62static PerlInterpreter *perl; 63static PerlInterpreter *perl;
63 64
64static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 65static AV *cb_global, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
65 66
66////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 67//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 68
68static SV * 69static SV *
69newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) 70newSVptr (void *ptr, const char *klass, HV *hv = newHV ())
192inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 193inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
193 194
194template<int N> 195template<int N>
195inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 196inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
196 197
198inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
199inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
200inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
201inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
202inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
203
197inline void sv_to (SV *sv, UUID &v) 204inline void sv_to (SV *sv, UUID &v)
198{ 205{
199 unsigned int version; 206 unsigned int version;
200 207
201 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) 208 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version)
202 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 209 croak ("unparsable uuid: %s", SvPV_nolen (sv));
203} 210}
211
212inline void sv_to (SV *sv, object::flags_t::reference v) { v = boolSV (sv); }
204 213
205static SV * 214static SV *
206newSVdt_va (va_list &ap, data_type type) 215newSVdt_va (va_list &ap, data_type type)
207{ 216{
208 SV *sv; 217 SV *sv;
243 case DT_MAP: 252 case DT_MAP:
244 // va_arg (object *) when void * is passed is an XSI extension 253 // va_arg (object *) when void * is passed is an XSI extension
245 sv = to_sv (va_arg (ap, maptile *)); 254 sv = to_sv (va_arg (ap, maptile *));
246 break; 255 break;
247 256
248 case DT_SOCKET: 257 case DT_CLIENT:
249 sv = to_sv (va_arg (ap, client *)); 258 sv = to_sv (va_arg (ap, client *));
250 break; 259 break;
251 260
252 case DT_PLAYER: 261 case DT_PLAYER:
253 sv = to_sv (va_arg (ap, player *)); 262 sv = to_sv (va_arg (ap, player *));
361 370
362 HV *hv = (HV *)SvRV ((SV *)self); 371 HV *hv = (HV *)SvRV ((SV *)self);
363 372
364 if (SvREFCNT ((SV *)self) == 1 373 if (SvREFCNT ((SV *)self) == 1
365 && SvREFCNT ((SV *)hv) == 1 374 && SvREFCNT ((SV *)hv) == 1
366 && !HvKEYS (hv)) 375 && !HvTOTALKEYS (hv))
367 { 376 {
368 SvREFCNT_dec ((SV *)self); 377 SvREFCNT_dec ((SV *)self);
369 self = 0; 378 self = 0;
370 } 379 }
371} 380}
412 421
413 switch (type) 422 switch (type)
414 { 423 {
415 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; 424 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break;
416 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; 425 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break;
426 case DT_CLIENT: INVOKE_CLIENT (REATTACH, obj); break;
417 case DT_MAP: INVOKE_MAP (REATTACH, obj); break; 427 case DT_MAP: INVOKE_MAP (REATTACH, obj); break;
418 } 428 }
419} 429}
420 430
421template<class subclass> 431template<class subclass>
834 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 844 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
835 845
836 char *argv[] = { 846 char *argv[] = {
837 "", 847 "",
838 "-e" 848 "-e"
839 "use Event;" // required for bootstrap 849 "use Event; use Coro;" // required for bootstrap
840 "cf->bootstrap;" // required for datadir :*> 850 "cf->bootstrap;" // required for datadir :*>
841 "unshift @INC, cf::datadir ();" 851 "unshift @INC, cf::datadir ();"
842 "require cf;" 852 "require cf;"
843 }; 853 };
844 854
845 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 855 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
906 AV *callbacks = 0; 916 AV *callbacks = 0;
907 917
908 object *op; 918 object *op;
909 player *pl; 919 player *pl;
910 maptile *map; 920 maptile *map;
921 client *ns;
911 922
912 // callback call ordering is: 923 // callback call ordering is:
913 // 1. per-object callback 924 // 1. per-object callback
914 // 2. per-class object 925 // 2. per-class object
915 // 3. per-type callback 926 // 3. per-type callback
973 gather_callbacks (callbacks, map->cb, event); 984 gather_callbacks (callbacks, map->cb, event);
974 985
975 gather_callbacks (callbacks, cb_map, event); 986 gather_callbacks (callbacks, cb_map, event);
976 break; 987 break;
977 988
989 case KLASS_CLIENT:
990 dt = (data_type) va_arg (ap, int);
991 assert (("first argument must be of type client", dt == DT_CLIENT));
992 ns = va_arg (ap, client *);
993
994 if (ns->cb)
995 gather_callbacks (callbacks, ns->cb, event);
996
997 gather_callbacks (callbacks, cb_client, event);
998 break;
999
978 default: 1000 default:
979 assert (("unsupported event klass in cfperl_invoke", 0)); 1001 assert (("unsupported event klass in cfperl_invoke", 0));
980 } 1002 }
981 1003
982 // short-circuit processing if no callbacks found/defined 1004 // short-circuit processing if no callbacks found/defined
995 1017
996 switch (KLASS_OF (event)) 1018 switch (KLASS_OF (event))
997 { 1019 {
998 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; 1020 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break;
999 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; 1021 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break;
1022 case KLASS_CLIENT: PUSHs (sv_2mortal (newSVdt (DT_CLIENT, ns))); break;
1000 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; 1023 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break;
1001 } 1024 }
1002 1025
1003 for (;;) 1026 for (;;)
1004 { 1027 {
1124{ 1147{
1125 HV *stash = gv_stashpv ("cf", 1); 1148 HV *stash = gv_stashpv ("cf", 1);
1126 1149
1127 I_EVENT_API (PACKAGE); 1150 I_EVENT_API (PACKAGE);
1128 watcher_base::GEventAPI = GEventAPI; 1151 watcher_base::GEventAPI = GEventAPI;
1152 I_CORO_API (PACKAGE);
1129 1153
1130 newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1154 newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1131 1155
1132 static const struct { 1156 static const struct {
1133 const char *name; 1157 const char *name;
1147 const_iv (POTION) 1171 const_iv (POTION)
1148 const_iv (FOOD) 1172 const_iv (FOOD)
1149 const_iv (POISON) 1173 const_iv (POISON)
1150 const_iv (BOOK) 1174 const_iv (BOOK)
1151 const_iv (CLOCK) 1175 const_iv (CLOCK)
1152 const_iv (LIGHTNING)
1153 const_iv (ARROW) 1176 const_iv (ARROW)
1154 const_iv (BOW) 1177 const_iv (BOW)
1155 const_iv (WEAPON) 1178 const_iv (WEAPON)
1156 const_iv (ARMOUR) 1179 const_iv (ARMOUR)
1157 const_iv (PEDESTAL) 1180 const_iv (PEDESTAL)
1177 const_iv (AMULET) 1200 const_iv (AMULET)
1178 const_iv (PLAYERMOVER) 1201 const_iv (PLAYERMOVER)
1179 const_iv (TELEPORTER) 1202 const_iv (TELEPORTER)
1180 const_iv (CREATOR) 1203 const_iv (CREATOR)
1181 const_iv (SKILL) 1204 const_iv (SKILL)
1182 const_iv (EXPERIENCE)
1183 const_iv (EARTHWALL) 1205 const_iv (EARTHWALL)
1184 const_iv (GOLEM) 1206 const_iv (GOLEM)
1185 const_iv (THROWN_OBJ) 1207 const_iv (THROWN_OBJ)
1186 const_iv (BLINDNESS) 1208 const_iv (BLINDNESS)
1187 const_iv (GOD) 1209 const_iv (GOD)
1207 const_iv (FLOOR) 1229 const_iv (FLOOR)
1208 const_iv (FLESH) 1230 const_iv (FLESH)
1209 const_iv (INORGANIC) 1231 const_iv (INORGANIC)
1210 const_iv (SKILL_TOOL) 1232 const_iv (SKILL_TOOL)
1211 const_iv (LIGHTER) 1233 const_iv (LIGHTER)
1212 const_iv (TRAP_PART)
1213 const_iv (WALL) 1234 const_iv (BUILDABLE_WALL)
1214 const_iv (LIGHT_SOURCE)
1215 const_iv (MISC_OBJECT) 1235 const_iv (MISC_OBJECT)
1216 const_iv (MONSTER)
1217 const_iv (SPAWN_GENERATOR)
1218 const_iv (LAMP) 1236 const_iv (LAMP)
1219 const_iv (DUPLICATOR) 1237 const_iv (DUPLICATOR)
1220 const_iv (TOOL)
1221 const_iv (SPELLBOOK) 1238 const_iv (SPELLBOOK)
1222 const_iv (BUILDFAC)
1223 const_iv (CLOAK) 1239 const_iv (CLOAK)
1224 const_iv (SPINNER) 1240 const_iv (SPINNER)
1225 const_iv (GATE) 1241 const_iv (GATE)
1226 const_iv (BUTTON) 1242 const_iv (BUTTON)
1227 const_iv (CF_HANDLE) 1243 const_iv (CF_HANDLE)
1234 const_iv (SPELL_EFFECT) 1250 const_iv (SPELL_EFFECT)
1235 const_iv (CONVERTER) 1251 const_iv (CONVERTER)
1236 const_iv (BRACERS) 1252 const_iv (BRACERS)
1237 const_iv (POISONING) 1253 const_iv (POISONING)
1238 const_iv (SAVEBED) 1254 const_iv (SAVEBED)
1239 const_iv (POISONCLOUD)
1240 const_iv (FIREHOLES)
1241 const_iv (WAND) 1255 const_iv (WAND)
1242 const_iv (SCROLL) 1256 const_iv (SCROLL)
1243 const_iv (DIRECTOR) 1257 const_iv (DIRECTOR)
1244 const_iv (GIRDLE) 1258 const_iv (GIRDLE)
1245 const_iv (FORCE) 1259 const_iv (FORCE)
1260 const_iv (DISEASE) 1274 const_iv (DISEASE)
1261 const_iv (SYMPTOM) 1275 const_iv (SYMPTOM)
1262 const_iv (BUILDER) 1276 const_iv (BUILDER)
1263 const_iv (MATERIAL) 1277 const_iv (MATERIAL)
1264 const_iv (ITEM_TRANSFORMER) 1278 const_iv (ITEM_TRANSFORMER)
1265 const_iv (QUEST)
1266 1279
1267 const_iv (NUM_SUBTYPES) 1280 const_iv (NUM_SUBTYPES)
1268 1281
1269 const_iv (ST_BD_BUILD) 1282 const_iv (ST_BD_BUILD)
1270 const_iv (ST_BD_REMOVE) 1283 const_iv (ST_BD_REMOVE)
1323 const_iv (FLAG_MONSTER) 1336 const_iv (FLAG_MONSTER)
1324 const_iv (FLAG_FRIENDLY) 1337 const_iv (FLAG_FRIENDLY)
1325 const_iv (FLAG_GENERATOR) 1338 const_iv (FLAG_GENERATOR)
1326 const_iv (FLAG_IS_THROWN) 1339 const_iv (FLAG_IS_THROWN)
1327 const_iv (FLAG_AUTO_APPLY) 1340 const_iv (FLAG_AUTO_APPLY)
1328 const_iv (FLAG_TREASURE)
1329 const_iv (FLAG_PLAYER_SOLD) 1341 const_iv (FLAG_PLAYER_SOLD)
1330 const_iv (FLAG_SEE_INVISIBLE) 1342 const_iv (FLAG_SEE_INVISIBLE)
1331 const_iv (FLAG_CAN_ROLL) 1343 const_iv (FLAG_CAN_ROLL)
1332 const_iv (FLAG_OVERLAY_FLOOR) 1344 const_iv (FLAG_OVERLAY_FLOOR)
1333 const_iv (FLAG_IS_TURNABLE) 1345 const_iv (FLAG_IS_TURNABLE)
1408 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1420 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1409 const_iv (FLAG_IS_WATER) 1421 const_iv (FLAG_IS_WATER)
1410 const_iv (FLAG_CONTENT_ON_GEN) 1422 const_iv (FLAG_CONTENT_ON_GEN)
1411 const_iv (FLAG_IS_A_TEMPLATE) 1423 const_iv (FLAG_IS_A_TEMPLATE)
1412 const_iv (FLAG_IS_BUILDABLE) 1424 const_iv (FLAG_IS_BUILDABLE)
1413 const_iv (FLAG_AFK)
1414 1425
1415 const_iv (NDI_BLACK) 1426 const_iv (NDI_BLACK)
1416 const_iv (NDI_WHITE) 1427 const_iv (NDI_WHITE)
1417 const_iv (NDI_NAVY) 1428 const_iv (NDI_NAVY)
1418 const_iv (NDI_RED) 1429 const_iv (NDI_RED)
1456 const_iv (F_BUY) 1467 const_iv (F_BUY)
1457 const_iv (F_SHOP) 1468 const_iv (F_SHOP)
1458 const_iv (F_SELL) 1469 const_iv (F_SELL)
1459 1470
1460 const_iv (P_BLOCKSVIEW) 1471 const_iv (P_BLOCKSVIEW)
1472 const_iv (P_PLAYER)
1461 const_iv (P_NO_MAGIC) 1473 const_iv (P_NO_MAGIC)
1462 const_iv (P_IS_ALIVE) 1474 const_iv (P_IS_ALIVE)
1463 const_iv (P_NO_CLERIC) 1475 const_iv (P_NO_CLERIC)
1464 const_iv (P_NEED_UPDATE) 1476 const_iv (P_NEED_UPDATE)
1465 const_iv (P_NO_ERROR)
1466 const_iv (P_OUT_OF_MAP) 1477 const_iv (P_OUT_OF_MAP)
1467 const_iv (P_NEW_MAP) 1478 const_iv (P_NEW_MAP)
1468 1479
1469 const_iv (UP_OBJ_INSERT) 1480 const_iv (UP_OBJ_INSERT)
1470 const_iv (UP_OBJ_REMOVE) 1481 const_iv (UP_OBJ_REMOVE)
1616 const_iv (MAP_LOADING) 1627 const_iv (MAP_LOADING)
1617 const_iv (MAP_SAVING) 1628 const_iv (MAP_SAVING)
1618 1629
1619 const_iv (KLASS_GLOBAL) 1630 const_iv (KLASS_GLOBAL)
1620 const_iv (KLASS_OBJECT) 1631 const_iv (KLASS_OBJECT)
1632 const_iv (KLASS_CLIENT)
1621 const_iv (KLASS_PLAYER) 1633 const_iv (KLASS_PLAYER)
1622 const_iv (KLASS_MAP) 1634 const_iv (KLASS_MAP)
1635
1636 const_iv (CS_QUERY_YESNO)
1637 const_iv (CS_QUERY_SINGLECHAR)
1638 const_iv (CS_QUERY_HIDEINPUT)
1639
1640 const_iv (ST_DEAD)
1641 const_iv (ST_SETUP)
1642 const_iv (ST_PLAYING)
1643 const_iv (ST_CUSTOM)
1644
1645 const_iv (ST_CHANGE_CLASS)
1646 const_iv (ST_CONFIRM_QUIT)
1647 const_iv (ST_GET_PARTY_PASSWORD)
1623 }; 1648 };
1624 1649
1625 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1650 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1626 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1651 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1627 1652
1651void _init_vars () 1676void _init_vars ()
1652 CODE: 1677 CODE:
1653 cb_global = get_av ("cf::CB_GLOBAL", 1); 1678 cb_global = get_av ("cf::CB_GLOBAL", 1);
1654 cb_object = get_av ("cf::CB_OBJECT", 1); 1679 cb_object = get_av ("cf::CB_OBJECT", 1);
1655 cb_player = get_av ("cf::CB_PLAYER", 1); 1680 cb_player = get_av ("cf::CB_PLAYER", 1);
1681 cb_client = get_av ("cf::CB_CLIENT", 1);
1656 cb_type = get_av ("cf::CB_TYPE" , 1); 1682 cb_type = get_av ("cf::CB_TYPE" , 1);
1657 cb_map = get_av ("cf::CB_MAP" , 1); 1683 cb_map = get_av ("cf::CB_MAP" , 1);
1658 1684
1659void _global_reattach () 1685void _global_reattach ()
1660 CODE: 1686 CODE:
1661{ 1687{
1662 // reattach to all attachable objects in the game. 1688 // reattach to all attachable objects in the game.
1689 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
1690 reattach (*i);
1691
1663 for (player *pl = first_player; pl; pl = pl->next) 1692 for (player *pl = first_player; pl; pl = pl->next)
1664 reattach (pl); 1693 reattach (pl);
1665 1694
1666 for (maptile *map = first_map; map; map = map->next) 1695 for (maptile *map = first_map; map; map = map->next)
1667 reattach (map); 1696 reattach (map);
1668 1697
1669 for (object *op = object::first; op; op = op->next) 1698 for (object *op = object::first; op; op = op->next)
1670 reattach (op); 1699 reattach (op);
1671} 1700}
1672
1673bool
1674add_client (int fd, const char *peername)
1675 1701
1676NV floor (NV x) 1702NV floor (NV x)
1677 1703
1678NV ceil (NV x) 1704NV ceil (NV x)
1679 1705
1734 1760
1735int random_roll (int min, int max, object *op, int goodbad); 1761int random_roll (int min, int max, object *op, int goodbad);
1736 1762
1737const char *cost_string_from_value(uint64 cost, int approx = 0) 1763const char *cost_string_from_value(uint64 cost, int approx = 0)
1738 1764
1739int invoke (int event, ...)
1740 CODE:
1741 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1742 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1743 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1744 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1745 OUTPUT: RETVAL
1746
1747int 1765int
1748exp_to_level (val64 exp) 1766exp_to_level (val64 exp)
1749 CODE: 1767 CODE:
1750{ 1768{
1751 int i = 0; 1769 int i = 0;
1781 RETVAL = newSVpv (resist_plus[atnr], 0); 1799 RETVAL = newSVpv (resist_plus[atnr], 0);
1782 else 1800 else
1783 XSRETURN_UNDEF; 1801 XSRETURN_UNDEF;
1784 OUTPUT: RETVAL 1802 OUTPUT: RETVAL
1785 1803
1804MODULE = cf PACKAGE = cf::attachable
1805
1786int 1806int
1787_valid (SV *obj) 1807valid (SV *obj)
1788 CODE: 1808 CODE:
1789 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1809 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1790 OUTPUT: 1810 OUTPUT:
1791 RETVAL 1811 RETVAL
1812
1813MODULE = cf PACKAGE = cf::global
1814
1815int invoke (SV *klass, int event, ...)
1816 CODE:
1817 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1818 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1819 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1820 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1821 OUTPUT: RETVAL
1792 1822
1793MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1823MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1794 1824
1795INCLUDE: $PERL genacc object ../include/object.h | 1825INCLUDE: $PERL genacc object ../include/object.h |
1796 1826
1815 RETVAL = object::first; 1845 RETVAL = object::first;
1816 OUTPUT: RETVAL 1846 OUTPUT: RETVAL
1817 1847
1818# missing properties 1848# missing properties
1819 1849
1820int flag (object *op, int flag, int value = 1)
1821 PROTOTYPE: $$;$
1822 CODE:
1823 RETVAL = QUERY_FLAG (op, flag);
1824 if (items >= 3)
1825 if (value)
1826 SET_FLAG (op, flag);
1827 else
1828 CLEAR_FLAG (op, flag);
1829 OUTPUT: RETVAL
1830
1831object *head (object *op) 1850object *head (object *op)
1832 PROTOTYPE: $ 1851 PROTOTYPE: $
1833 CODE: 1852 CODE:
1834 RETVAL = op->head ? op->head : op; 1853 RETVAL = op->head ? op->head : op;
1835 OUTPUT: RETVAL 1854 OUTPUT: RETVAL
1845 PROTOTYPE: $ 1864 PROTOTYPE: $
1846 PPCODE: 1865 PPCODE:
1847{ 1866{
1848 object *o; 1867 object *o;
1849 for (o = obj->inv; o; o = o->below) 1868 for (o = obj->inv; o; o = o->below)
1850 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1869 XPUSHs (sv_2mortal (to_sv (o)));
1851} 1870}
1871
1872void
1873set_animation (object *op, int idx)
1874 CODE:
1875 SET_ANIMATION (op, idx);
1876
1877void
1878object::drain_stat ()
1879
1880void
1881object::drain_specific_stat (int stat)
1882
1883void
1884object::change_luck (int change)
1885
1886void
1887object::add_statbonus ()
1888
1889void
1890object::remove_statbonus ()
1852 1891
1853object *find_best_object_match (object *op, const char *match) 1892object *find_best_object_match (object *op, const char *match)
1854 1893
1855object *find_marked_object (object *op) 1894object *find_marked_object (object *op)
1856
1857int resistance (object *op, int rtype, int newval = 0)
1858 CODE:
1859 if (rtype < 0 || rtype >= NROFATTACKS)
1860 croak ("resistance out of bounds");
1861 RETVAL = op->resist [rtype];
1862 if (items >= 3)
1863 op->resist [rtype] = newval;
1864 OUTPUT: RETVAL
1865
1866void set_resistance (object *op, int rtype, int val)
1867 CODE:
1868 if (rtype < 0 || rtype >= NROFATTACKS)
1869 op->resist[rtype] = val;
1870 1895
1871int need_identify (const object *obj); 1896int need_identify (const object *obj);
1872 1897
1873int apply_shop_mat (object *shop_mat, object *op); 1898int apply_shop_mat (object *shop_mat, object *op);
1874 1899
1888 1913
1889void remove (object *op) 1914void remove (object *op)
1890 CODE: 1915 CODE:
1891 op->remove (); 1916 op->remove ();
1892 1917
1893void destroy (object *op, int recursive = 0) 1918void
1894 CODE: 1919object::destroy (int recursive = 0)
1895 op->destroy (recursive);
1896 1920
1897object *cf_object_present_archname_inside (object *op, char *whatstr) 1921object *cf_object_present_archname_inside (object *op, char *whatstr)
1898 1922
1899int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1923int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1900 1924
1941 OUTPUT: RETVAL 1965 OUTPUT: RETVAL
1942 1966
1943int query_money (object *op) 1967int query_money (object *op)
1944 ALIAS: money = 0 1968 ALIAS: money = 0
1945 1969
1946int query_cost (object *op, object *who, int flags) 1970val64 query_cost (object *op, object *who, int flags)
1947 ALIAS: cost = 0 1971 ALIAS: cost = 0
1948 1972
1949void spring_trap (object *op, object *victim) 1973void spring_trap (object *op, object *victim)
1950 1974
1951int check_trigger (object *op, object *cause) 1975int check_trigger (object *op, object *cause)
1958 1982
1959object *cf_object_insert_in_ob (object *ob, object *where) 1983object *cf_object_insert_in_ob (object *ob, object *where)
1960 1984
1961int cf_object_teleport (object *op, maptile *map, int x, int y) 1985int cf_object_teleport (object *op, maptile *map, int x, int y)
1962 1986
1963void update (object *op, int action) 1987void update_object (object *op, int action)
1964 CODE:
1965 update_object (op, action);
1966 1988
1967object *cf_create_object_by_name (const char *name) 1989object *cf_create_object_by_name (const char *name)
1968 1990
1969void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1991void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1970 1992
1982 2004
1983void remove_button_link (object *op); 2005void remove_button_link (object *op);
1984 2006
1985 2007
1986MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2008MODULE = cf PACKAGE = cf::object PREFIX = cf_
1987
1988void cf_fix_object (object *pl)
1989 ALIAS: fix = 0
1990 2009
1991object *cf_insert_ob_in_ob (object *ob, object *where) 2010object *cf_insert_ob_in_ob (object *ob, object *where)
1992 2011
1993# no clean way to get an object from an archetype - stupid idiotic 2012# no clean way to get an object from an archetype - stupid idiotic
1994# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2013# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2017 2036
2018player *contr (object *op) 2037player *contr (object *op)
2019 CODE: 2038 CODE:
2020 RETVAL = op->contr; 2039 RETVAL = op->contr;
2021 OUTPUT: RETVAL 2040 OUTPUT: RETVAL
2041
2042void
2043object::roll_stats ()
2044
2045void
2046object::update_stats ()
2047
2048void
2049object::swap_stats (int a, int b)
2022 2050
2023const char *get_ob_key_value (object *op, const char *key) 2051const char *get_ob_key_value (object *op, const char *key)
2024 2052
2025bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 2053bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
2026 2054
2052base_name (object *op, int plural = op->nrof > 1) 2080base_name (object *op, int plural = op->nrof > 1)
2053 CODE: 2081 CODE:
2054 RETVAL = query_base_name (op, plural); 2082 RETVAL = query_base_name (op, plural);
2055 OUTPUT: RETVAL 2083 OUTPUT: RETVAL
2056 2084
2085object *decrease_ob_nr (object *op, unsigned long i)
2086
2057MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 2087MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
2058 2088
2059player *player (object *op) 2089player *player (object *op)
2060 CODE: 2090 CODE:
2061 RETVAL = op->contr; 2091 RETVAL = op->contr;
2062 OUTPUT: RETVAL 2092 OUTPUT: RETVAL
2093
2094void check_score (object *op)
2063 2095
2064void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2096void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2065 2097
2066object *cf_player_send_inventory (object *op) 2098object *cf_player_send_inventory (object *op)
2067 2099
2110 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); 2142 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av));
2111 OUTPUT: RETVAL 2143 OUTPUT: RETVAL
2112 2144
2113SV *registry (player *pl) 2145SV *registry (player *pl)
2114 2146
2147player *
2148create ()
2149 CODE:
2150 RETVAL = player::create ();
2151 OUTPUT:
2152 RETVAL
2153
2154player *
2155load (const char *path)
2156 CODE:
2157 RETVAL = player::load (path);
2158 OUTPUT:
2159 RETVAL
2160
2161void
2162player::save (bool final = false)
2163
2164void
2165player::connect (client *ns)
2166
2167void
2168save_stats (player *pl)
2169 CODE:
2170 pl->ob->stats.hp = pl->ob->stats.maxhp;
2171 pl->ob->stats.sp = pl->ob->stats.maxsp;
2172 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2173 pl->orig_stats = pl->ob->stats;
2174
2115player *cf_player_find (char *name) 2175player *cf_player_find (char *name)
2116 PROTOTYPE: $ 2176 PROTOTYPE: $
2117 2177
2118void cf_player_move (player *pl, int dir) 2178void cf_player_move (player *pl, int dir)
2119 2179
2122player *first () 2182player *first ()
2123 CODE: 2183 CODE:
2124 RETVAL = first_player; 2184 RETVAL = first_player;
2125 OUTPUT: RETVAL 2185 OUTPUT: RETVAL
2126 2186
2127player *next (player *pl)
2128 CODE:
2129 RETVAL = pl->next;
2130 OUTPUT: RETVAL
2131
2132bool 2187bool
2133cell_visible (player *pl, int dx, int dy) 2188cell_visible (player *pl, int dx, int dy)
2134 CODE: 2189 CODE:
2135 RETVAL = FABS (dx) <= pl->socket->mapx / 2 && FABS (dy) <= pl->socket->mapy / 2 2190 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2136 && !pl->blocked_los [dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]; 2191 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2137 OUTPUT: 2192 OUTPUT:
2138 RETVAL 2193 RETVAL
2139 2194
2140void 2195void
2141send (player *pl, SV *packet) 2196send (player *pl, SV *packet)
2142 CODE: 2197 CODE:
2143{ 2198{
2144 STRLEN len; 2199 STRLEN len;
2145 char *buf = SvPVbyte (packet, len); 2200 char *buf = SvPVbyte (packet, len);
2146 2201
2202 if (pl->ns)
2147 pl->socket->send_packet (buf, len); 2203 pl->ns->send_packet (buf, len);
2148} 2204}
2149 2205
2150int 2206int
2151listening (player *pl, int new_value = -1) 2207listening (player *pl, int new_value = -1)
2152 CODE: 2208 CODE:
2171 if (y) sv_to (y, pl->bed_y); 2227 if (y) sv_to (y, pl->bed_y);
2172 2228
2173void 2229void
2174list () 2230list ()
2175 PPCODE: 2231 PPCODE:
2176{
2177 player *pl;
2178 for (pl = first_player; pl; pl = pl->next) 2232 for (player *pl = first_player; pl; pl = pl->next)
2179 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 2233 XPUSHs (sv_2mortal (to_sv (pl)));
2180}
2181 2234
2182bool 2235bool
2183peaceful (player *pl, bool new_setting = 0) 2236peaceful (player *pl, bool new_setting = 0)
2184 PROTOTYPE: $;$ 2237 PROTOTYPE: $;$
2185 CODE: 2238 CODE:
2439 2492
2440INCLUDE: $PERL genacc client ../include/client.h | 2493INCLUDE: $PERL genacc client ../include/client.h |
2441 2494
2442int invoke (client *ns, int event, ...) 2495int invoke (client *ns, int event, ...)
2443 CODE: 2496 CODE:
2444 if (KLASS_OF (event) != KLASS_SOCKET) croak ("event class must be SOCKET"); 2497 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2445 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2498 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2446 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 2499 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2447 RETVAL = INVOKE_((event_type)event, ARG_SOCKET (ns), ARG_AV (av)); 2500 RETVAL = INVOKE_((event_type)event, ARG_CLIENT (ns), ARG_AV (av));
2448 OUTPUT: RETVAL 2501 OUTPUT: RETVAL
2449 2502
2450SV *registry (client *ns) 2503SV *registry (client *ns)
2451 2504
2505void
2506list ()
2507 PPCODE:
2508 EXTEND (SP, clients.size ());
2509 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2510 PUSHs (sv_2mortal (to_sv (*i)));
2511
2512client *
2513create (int fd, const char *peername)
2514 CODE:
2515 RETVAL = client::create (fd, peername);
2516 OUTPUT:
2517 RETVAL
2518
2519void
2520client::send_packet (SV *packet)
2521 CODE:
2522{
2523 STRLEN len;
2524 char *buf = SvPVbyte (packet, len);
2525
2526 THIS->send_packet (buf, len);
2527}
2528
2529void
2530client::destroy ()
2531

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines