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.224 by root, Tue Jun 26 05:07:21 2007 UTC vs.
Revision 1.246 by root, Thu Aug 30 07:28:25 2007 UTC

3 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include "autoconf.h" 24#include "autoconf.h"
100 *stash_cf_arch_wrap, 99 *stash_cf_arch_wrap,
101 *stash_cf_party_wrap, 100 *stash_cf_party_wrap,
102 *stash_cf_region_wrap, 101 *stash_cf_region_wrap,
103 *stash_cf_living_wrap; 102 *stash_cf_living_wrap;
104 103
104static inline SV *
105newSVpv_utf8 (const char *s)
106{
107 SV *sv = newSVpv (s, 0);
108 SvUTF8_on (sv);
109 return sv;
110}
111
112static inline SV *
113newSVpvn_utf8 (const char *s, STRLEN l)
114{
115 SV *sv = newSVpvn (s, l);
116 SvUTF8_on (sv);
117 return sv;
118}
119
105// helper cast function, returns super class * or 0 120// helper cast function, returns super class * or 0
106template<class super> 121template<class super>
107static super * 122static super *
108is_a (attachable *at) 123is_a (attachable *at)
109{ 124{
247 delete obj; 262 delete obj;
248 } 263 }
249 } 264 }
250} 265}
251 266
267void
268attachable::set_key (const char *key, const char *value, bool is_utf8)
269{
270 if (!self)
271 self = newHV ();
272
273 if (value)
274 hv_store (self, key, strlen (key), is_utf8 ? newSVpv_utf8 (value) : newSVpv (value, 0), 0);
275 else
276 hv_delete (self, key, strlen (key), G_DISCARD);
277}
278
252attachable & 279attachable &
253attachable::operator =(const attachable &src) 280attachable::operator =(const attachable &src)
254{ 281{
255 //if (self || cb) 282 //if (self || cb)
256 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 283 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
331{ 358{
332 if (!obj) 359 if (!obj)
333 return &PL_sv_undef; 360 return &PL_sv_undef;
334 361
335 if (!obj->self) 362 if (!obj->self)
363 obj->self = newHV ();
364
365 if (!SvOBJECT (obj->self))
336 { 366 {
337 obj->self = newHV ();
338 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 367 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
339 368
340 // now bless the object _once_ 369 // now bless the object _once_
370 //TODO: create a class registry with c++ type<=>perl name<=>stash and use it here and elsewhere
341 return sv_bless (newRV_inc ((SV *)obj->self), stash); 371 return sv_bless (newRV_inc ((SV *)obj->self), stash);
342 } 372 }
343 else 373 else
344 { 374 {
345 SV *sv = newRV_inc ((SV *)obj->self); 375 SV *sv = newRV_inc ((SV *)obj->self);
380{ 410{
381 if (SvOK (sv)) 411 if (SvOK (sv))
382 return SvPTR (sv, klass); 412 return SvPTR (sv, klass);
383 else 413 else
384 return 0; 414 return 0;
385}
386
387static inline SV *
388newSVpv_utf8 (const char *s)
389{
390 SV *sv = newSVpv (s, 0);
391 SvUTF8_on (sv);
392 return sv;
393}
394
395static inline SV *
396newSVpvn_utf8 (const char *s, STRLEN l)
397{
398 SV *sv = newSVpvn (s, l);
399 SvUTF8_on (sv);
400 return sv;
401} 415}
402 416
403inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; } 417inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; }
404inline SV *to_sv (const char * v) { return newSVpv (v, 0); } 418inline SV *to_sv (const char * v) { return newSVpv (v, 0); }
405inline SV *to_sv (bool v) { return newSViv (v); } 419inline SV *to_sv (bool v) { return newSViv (v); }
418inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 432inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
419inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 433inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
420inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 434inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
421inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 435inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
422inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 436inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
437inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
423inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 438inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
424inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
425inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 439inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
426 440
427inline SV *to_sv (object & v) { return to_sv (&v); } 441inline SV *to_sv (object & v) { return to_sv (&v); }
428inline SV *to_sv (living & v) { return to_sv (&v); } 442inline SV *to_sv (living & v) { return to_sv (&v); }
429 443
455inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 469inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
456inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 470inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
457inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 471inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
458inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 472inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
459inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 473inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
474inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); }
460inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 475inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
461inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 476inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
462inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
463inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 477inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
464 478
465//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 479//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
466inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 480inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
467 481
950} 964}
951 965
952SV * 966SV *
953cfperl_result (int idx) 967cfperl_result (int idx)
954{ 968{
955 AV *av = get_av ("cfperl::invoke_results", 0); 969 AV *av = get_av ("cf::INVOKE_RESULTS", 0);
956 if (!av) 970 if (!av)
957 return &PL_sv_undef; 971 return &PL_sv_undef;
958 972
959 SV **sv = av_fetch (av, idx, 0); 973 SV **sv = av_fetch (av, idx, 0);
960 if (!sv) 974 if (!sv)
1007void 1021void
1008cfperl_send_msg (client *ns, int color, const char *type, const char *msg) 1022cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
1009{ 1023{
1010 CALL_BEGIN (4); 1024 CALL_BEGIN (4);
1011 CALL_ARG (ns); 1025 CALL_ARG (ns);
1012 CALL_ARG (color);
1013 CALL_ARG (type); 1026 CALL_ARG (type);
1014 CALL_ARG_SV (newSVpv_utf8 (msg)); 1027 CALL_ARG_SV (newSVpv_utf8 (msg));
1028 CALL_ARG (color);
1015 CALL_CALL ("cf::client::send_msg", G_VOID); 1029 CALL_CALL ("cf::client::send_msg", G_VOID);
1016 CALL_END; 1030 CALL_END;
1031}
1032
1033int
1034cfperl_can_merge (object *ob1, object *ob2)
1035{
1036 int can;
1037
1038 CALL_BEGIN (2);
1039 CALL_ARG (ob1);
1040 CALL_ARG (ob2);
1041 CALL_CALL ("cf::_can_merge", G_SCALAR);
1042 can = count && SvTRUE (TOPs);
1043 CALL_END;
1044
1045 return can;
1046}
1047
1048player *
1049player::find (const char *name)
1050{
1051 CALL_BEGIN (1);
1052 CALL_ARG (name);
1053 CALL_CALL ("cf::player::find", G_SCALAR);
1054
1055 player *retval;
1056
1057 if (count)
1058 sv_to (POPs, retval);
1059 else
1060 retval = 0;
1061
1062 CALL_END;
1063
1064 return retval;
1017} 1065}
1018 1066
1019maptile * 1067maptile *
1020maptile::find_sync (const char *path, maptile *origin) 1068maptile::find_sync (const char *path, maptile *origin)
1021{ 1069{
1035 1083
1036 return retval; 1084 return retval;
1037} 1085}
1038 1086
1039maptile * 1087maptile *
1040maptile::find_async (const char *path, maptile *origin) 1088maptile::find_async (const char *path, maptile *origin, bool load)
1041{ 1089{
1042 CALL_BEGIN (2); 1090 CALL_BEGIN (3);
1043 CALL_ARG (path); 1091 CALL_ARG (path);
1044 CALL_ARG (origin); 1092 CALL_ARG (origin);
1093 CALL_ARG (load);
1045 CALL_CALL ("cf::map::find_async", G_SCALAR); 1094 CALL_CALL ("cf::map::find_async", G_SCALAR);
1046 1095
1047 maptile *retval; 1096 maptile *retval;
1048 1097
1049 if (count) 1098 if (count)
1347 const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED) 1396 const_iv (FLAG_USE_ROD) const_iv (FLAG_USE_HORN) const_iv (FLAG_MAKE_INVIS) const_iv (FLAG_INV_LOCKED)
1348 const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON) 1397 const_iv (FLAG_IS_WOODED) const_iv (FLAG_IS_HILLY) const_iv (FLAG_READY_SKILL) const_iv (FLAG_READY_WEAPON)
1349 const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON) 1398 const_iv (FLAG_NO_SKILL_IDENT) const_iv (FLAG_BLIND) const_iv (FLAG_SEE_IN_DARK) const_iv (FLAG_IS_CAULDRON)
1350 const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_CLIENT_SENT) const_iv (FLAG_BERSERK) 1399 const_iv (FLAG_NO_STEAL) const_iv (FLAG_ONE_HIT) const_iv (FLAG_CLIENT_SENT) const_iv (FLAG_BERSERK)
1351 const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL) 1400 const_iv (FLAG_NEUTRAL) const_iv (FLAG_NO_ATTACK) const_iv (FLAG_NO_DAMAGE) const_iv (FLAG_OBJ_ORIGINAL)
1352 const_iv (FLAG_OBJ_SAVE_ON_OVL) const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER) 1401 const_iv (FLAG_ACTIVATE_ON_PUSH) const_iv (FLAG_ACTIVATE_ON_RELEASE) const_iv (FLAG_IS_WATER)
1353 const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) 1402 const_iv (FLAG_CONTENT_ON_GEN) const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE)
1354 const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE) 1403 const_iv (FLAG_DESTROY_ON_DEATH) const_iv (FLAG_NO_MAP_SAVE)
1355 1404
1356 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) 1405 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED)
1357 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) 1406 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN)
1358 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) 1407 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD)
1359 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) 1408 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE)
1409 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK)
1360 const_iv (NDI_ALL) 1410 const_iv (NDI_NOCREATE)
1361 1411
1362 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1412 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1363 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1413 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1364 1414
1365 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1415 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1492 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1542 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1493 1543
1494 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) 1544 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1495 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) 1545 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1496 const_iv (GT_MINIMAL) 1546 const_iv (GT_MINIMAL)
1547
1548 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND)
1549 const_iv (FT_RSRC) const_iv (FT_NUM)
1497 }; 1550 };
1498 1551
1499 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1552 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1500 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1553 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1501 1554
1535 1588
1536 for_all_objects (op) 1589 for_all_objects (op)
1537 op->reattach (); 1590 op->reattach ();
1538} 1591}
1539 1592
1540void _post_tick ()
1541 CODE:
1542 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1543
1544# support function for map-world.ext 1593# support function for map-world.ext
1545void _quantise (SV *data_sv, SV *plt_sv) 1594void _quantise (SV *data_sv, SV *plt_sv)
1546 CODE: 1595 CODE:
1547{ 1596{
1548 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) 1597 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1580 len -= 3; 1629 len -= 3;
1581 } 1630 }
1582 1631
1583 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1632 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1584} 1633}
1634
1635void _post_tick ()
1636 CODE:
1637 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1638
1639NV till_cede ()
1640 CODE:
1641 RETVAL = coroapi::next_cede - now ();
1642 OUTPUT:
1643 RETVAL
1644
1645NV till_tick ()
1646 CODE:
1647 RETVAL = SvNV (sv_next_tick) - now ();
1648 OUTPUT:
1649 RETVAL
1585 1650
1586NV floor (NV x) 1651NV floor (NV x)
1587 1652
1588NV ceil (NV x) 1653NV ceil (NV x)
1589 1654
1632octet_string path_combine (octet_string base, octet_string path) 1697octet_string path_combine (octet_string base, octet_string path)
1633 PROTOTYPE: $$ 1698 PROTOTYPE: $$
1634 1699
1635octet_string path_combine_and_normalize (octet_string base, octet_string path) 1700octet_string path_combine_and_normalize (octet_string base, octet_string path)
1636 PROTOTYPE: $$ 1701 PROTOTYPE: $$
1637
1638const_octet_string
1639get_maps_directory (octet_string path)
1640 PROTOTYPE: $
1641 ALIAS: maps_directory = 0
1642 CODE:
1643 RETVAL = create_pathname (path);
1644 OUTPUT: RETVAL
1645 1702
1646void 1703void
1647sub_generation_inc () 1704sub_generation_inc ()
1648 CODE: 1705 CODE:
1649 PL_sub_generation++; 1706 PL_sub_generation++;
1771#object *mortals (U32 index) 1828#object *mortals (U32 index)
1772# CODE: 1829# CODE:
1773# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; 1830# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0;
1774# OUTPUT: RETVAL 1831# OUTPUT: RETVAL
1775 1832
1776INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | 1833INCLUDE: $PERL $srcdir/genacc attachable ../include/util.h ../include/cfperl.h |
1777 1834
1778MODULE = cf PACKAGE = cf::global 1835MODULE = cf PACKAGE = cf::global
1779 1836
1780int invoke (SV *klass, int event, ...) 1837int invoke (SV *klass, int event, ...)
1781 CODE: 1838 CODE:
1995 2052
1996void add_button_link (object *button, maptile *map, int connected); 2053void add_button_link (object *button, maptile *map, int connected);
1997 2054
1998void remove_button_link (object *op); 2055void remove_button_link (object *op);
1999 2056
2057void handle_apply_yield (object *op);
2058
2000 2059
2001MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2060MODULE = cf PACKAGE = cf::object PREFIX = cf_
2002 2061
2003object *cf_insert_ob_in_ob (object *ob, object *where) 2062object *cf_insert_ob_in_ob (object *ob, object *where)
2004 2063
2010 CODE: 2069 CODE:
2011 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2070 RETVAL = archetype ? get_archetype (archetype) : object::create ();
2012 OUTPUT: 2071 OUTPUT:
2013 RETVAL 2072 RETVAL
2014 2073
2074object *find_object (U32 tag)
2075
2015# TODO: nuke 2076# TODO: nuke
2016object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2077object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2017 PROTOTYPE: $$$$$$ 2078 PROTOTYPE: $$$$$$
2018 CODE: 2079 CODE:
2019{ 2080{
2020 int unused_type; 2081 int unused_type;
2021 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 2082 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2022} 2083}
2023
2024player *contr (object *op)
2025 CODE:
2026 RETVAL = op->contr;
2027 OUTPUT: RETVAL
2028 2084
2029const_utf8_string get_ob_key_value (object *op, utf8_string key) 2085const_utf8_string get_ob_key_value (object *op, utf8_string key)
2030 2086
2031bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2087bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
2032 2088
2108 pl->orig_stats = pl->ob->stats; 2164 pl->orig_stats = pl->ob->stats;
2109 2165
2110void clear_los (player *pl) 2166void clear_los (player *pl)
2111 2167
2112void cf_player_move (player *pl, int dir) 2168void cf_player_move (player *pl, int dir)
2113
2114void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2115 2169
2116bool 2170bool
2117cell_visible (player *pl, int dx, int dy) 2171cell_visible (player *pl, int dx, int dy)
2118 CODE: 2172 CODE:
2119 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2173 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2258 palette = SvRV (palette); 2312 palette = SvRV (palette);
2259 2313
2260 STRLEN idxlen; 2314 STRLEN idxlen;
2261 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2315 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2262 2316
2263 region **regionmap = (region **)malloc ( 2317 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2264 (av_len ((AV *)palette) + 1) * sizeof (region *));
2265 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2318 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2266 2319
2267 for (int i = av_len ((AV *)palette) + 1; i--; ) 2320 for (int i = av_len ((AV *)palette) + 1; i--; )
2268 regionmap [i] = region::find ( 2321 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2269 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2270 2322
2271 for (int y = 0; y < THIS->height; ++y) 2323 for (int y = 0; y < THIS->height; ++y)
2272 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2324 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2273 2325
2274 sfree (THIS->regions, THIS->size ()); 2326 sfree (THIS->regions, THIS->size ());
2275 free (THIS->regionmap); 2327 delete [] THIS->regionmap;
2276 2328
2277 THIS->regions = regions; 2329 THIS->regions = regions;
2278 THIS->regionmap = regionmap; 2330 THIS->regionmap = regionmap;
2279} 2331}
2280 2332
2300 } 2352 }
2301 } 2353 }
2302 2354
2303 op->destroy (); 2355 op->destroy ();
2304} 2356}
2305
2306void play_sound_map (maptile *map, int x, int y, int sound_num)
2307 2357
2308int out_of_map (maptile *map, int x, int y) 2358int out_of_map (maptile *map, int x, int y)
2309 2359
2310void 2360void
2311trigger (maptile *map, long connection, bool state = true) 2361trigger (maptile *map, long connection, bool state = true)
2583 char *buf = SvPVbyte (packet, len); 2633 char *buf = SvPVbyte (packet, len);
2584 2634
2585 THIS->send_packet (buf, len); 2635 THIS->send_packet (buf, len);
2586} 2636}
2587 2637
2638faceidx
2639client::need_face (utf8_string name, int pri = 0)
2640 CODE:
2641 RETVAL = face_find (name, 0);
2642 if (RETVAL)
2643 {
2644 THIS->send_face (RETVAL, pri);
2645 THIS->flush_fx ();
2646 }
2647 OUTPUT:
2648 RETVAL
2649
2650int
2651client::fx_want (int idx, int value = -1)
2652 CODE:
2653 if (0 < idx && idx < FT_NUM)
2654 {
2655 RETVAL = THIS->fx_want [idx];
2656 if (items > 2)
2657 THIS->fx_want [idx] = value;
2658 }
2659 else
2660 RETVAL = 0;
2661 OUTPUT:
2662 RETVAL
2663
2664MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2665
2666faceidx sound_find (utf8_string name)
2667
2668void sound_set (utf8_string str, faceidx face)
2669
2670# dire hack
2671void old_sound_index (int idx, faceidx face)
2672 CODE:
2673 extern faceidx old_sound_index [SOUND_CAST_SPELL_0];
2674 old_sound_index [idx] = face;
2675
2588MODULE = cf PACKAGE = cf::face PREFIX = face_ 2676MODULE = cf PACKAGE = cf::face PREFIX = face_
2589 2677
2590#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | 2678#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2591 2679
2592faceidx face_find (utf8_string name, faceidx defidx = 0) 2680faceidx face_find (utf8_string name, faceidx defidx = 0)
2607 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2695 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2608 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2696 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2609} 2697}
2610 OUTPUT: RETVAL 2698 OUTPUT: RETVAL
2611 2699
2612void set (faceidx idx, int visibility, int magicmap) 2700void set_type (faceidx idx, int value)
2613 CODE: 2701 ALIAS:
2614 faceinfo *f = face_info (idx); 2702 set_type = 0
2615 assert (f); 2703 set_visibility = 1
2616 f->visibility = visibility; 2704 set_magicmap = 2
2617 f->magicmap = magicmap; 2705 set_smooth = 3
2618 2706 set_smoothlevel = 4
2619void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2620 CODE: 2707 CODE:
2621 faceinfo *f = face_info (idx); assert (f); 2708 faceinfo *f = face_info (idx); assert (f);
2622 f->smooth = smooth; 2709 switch (ix)
2623 f->smoothlevel = smoothlevel; 2710 {
2711 case 0: f->type = value; break;
2712 case 1: f->visibility = value; break;
2713 case 2: f->magicmap = value; break;
2714 case 3: f->smooth = value; break;
2715 case 4: f->smoothlevel = value; break;
2716 }
2624 2717
2625void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2718void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2626 CODE: 2719 CODE:
2627{ 2720{
2628 facedata *d = face_data (idx, faceset); 2721 faceinfo *f = face_info (idx); assert (f);
2629 assert (d); 2722 facedata *d = &(faceset ? f->data64 : f->data32);
2630 sv_to (data, d->data); 2723 sv_to (data, d->data);
2631 STRLEN clen; 2724 STRLEN clen;
2632 char *cdata = SvPVbyte (chksum, clen); 2725 char *cdata = SvPVbyte (chksum, clen);
2633 clen = min (CHKSUM_SIZE, clen); 2726 clen = min (CHKSUM_SIZE, clen);
2634 2727
2644 ns->force_newmap = true; 2737 ns->force_newmap = true;
2645 } 2738 }
2646 } 2739 }
2647} 2740}
2648 2741
2742int get_data_size (faceidx idx, int faceset = 0)
2743 CODE:
2744 facedata *d = face_data (idx, faceset); assert (d);
2745 RETVAL = d->data.size ();
2746 OUTPUT:
2747 RETVAL
2748
2749SV *get_chksum (faceidx idx, int faceset = 0)
2750 CODE:
2751 facedata *d = face_data (idx, faceset); assert (d);
2752 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2753 OUTPUT:
2754 RETVAL
2755
2649void invalidate (faceidx idx) 2756void invalidate (faceidx idx)
2650 CODE: 2757 CODE:
2651 for_all_clients (ns) 2758 for_all_clients (ns)
2652 { 2759 {
2653 ns->faces_sent [idx] = false; 2760 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines