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.337 by root, Thu Nov 12 01:11:52 2009 UTC vs.
Revision 1.356 by root, Sat Apr 3 02:27:24 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
6 * 5 *
7 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
8 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version. 9 * option) any later version.
29 28
30#include <cstdarg> 29#include <cstdarg>
31#include <typeinfo> 30#include <typeinfo>
32 31
33#include "global.h" 32#include "global.h"
34#include "loader.h"
35#include "../random_maps/random_map.h" 33#include "../random_maps/random_map.h"
36#include "evthread.h" 34#include "evthread.h"
37#include "sproto.h" 35#include "sproto.h"
38 36
39#include <unistd.h> 37#include <unistd.h>
97 *cv_cf_client_send_msg, 95 *cv_cf_client_send_msg,
98 *cv_cf_tick, 96 *cv_cf_tick,
99 *cv_cf_match_match; 97 *cv_cf_match_match;
100 98
101#ifndef newSVpv_utf8 99#ifndef newSVpv_utf8
102static inline SV * 100static SV *
103newSVpv_utf8 (const char *s) 101newSVpv_utf8 (const char *s)
104{ 102{
105 if (!s) 103 if (!s)
106 return newSV (0); 104 return newSV (0);
107 105
110 return sv; 108 return sv;
111} 109}
112#endif 110#endif
113 111
114#ifndef newSVpvn_utf8 112#ifndef newSVpvn_utf8
115static inline SV * 113static SV *
116newSVpvn_utf8 (const char *s, STRLEN l, int utf8) 114newSVpvn_utf8 (const char *s, STRLEN l, int utf8)
117{ 115{
118 if (!s) 116 if (!s)
119 return newSV (0); 117 return newSV (0);
120 118
124 SvUTF8_on (sv); 122 SvUTF8_on (sv);
125 123
126 return sv; 124 return sv;
127} 125}
128#endif 126#endif
127
128static noinline utf8_string
129cfSvPVutf8_nolen (SV *sv)
130{
131 SvGETMAGIC (sv);
132
133 if (SvPOK (sv))
134 {
135 if (!SvUTF8 (sv))
136 sv_utf8_upgrade_nomg (sv);
137
138 return SvPVX (sv);
139 }
140
141 return SvPV_nolen (sv);
142}
129 143
130// helper cast function, returns super class * or 0 144// helper cast function, returns super class * or 0
131template<class super> 145template<class super>
132static super * 146static super *
133is_a (attachable *at) 147is_a (attachable *at)
402 hv_clear ((HV *)sv); 416 hv_clear ((HV *)sv);
403 sv_unmagic (sv, PERL_MAGIC_ext); 417 sv_unmagic (sv, PERL_MAGIC_ext);
404} 418}
405#endif 419#endif
406 420
407static long SvPTR_nc (SV *sv) 421static long
422SvPTR_nc (SV *sv)
408{ 423{
409 sv = SvRV (sv); 424 sv = SvRV (sv);
410 425
411 // very important shortcut 426 // very important shortcut
412 if (expect_true (SvMAGIC (sv)->mg_type == PERL_MAGIC_ext)) 427 if (expect_true (SvMAGIC (sv) && SvMAGIC (sv)->mg_type == PERL_MAGIC_ext))
413 return (long)SvMAGIC (sv)->mg_ptr; 428 return (long)SvMAGIC (sv)->mg_ptr;
414 429
415 if (MAGIC *mg = mg_find (sv, PERL_MAGIC_ext)) 430 if (MAGIC *mg = mg_find (sv, PERL_MAGIC_ext))
416 return (long)mg->mg_ptr; 431 return (long)mg->mg_ptr;
417 432
470 485
471 if (!SvROK (sv) 486 if (!SvROK (sv)
472 || (SvSTASH (SvRV (sv)) != stash_cf_player_wrap 487 || (SvSTASH (SvRV (sv)) != stash_cf_player_wrap
473 && !sv_derived_from (sv, "cf::player"))) 488 && !sv_derived_from (sv, "cf::player")))
474 croak ("object of type cf::player expected"); 489 croak ("object of type cf::player expected");
475
476 if (SvSTASH (SvRV (sv)) != stash_cf_player_wrap)
477 printf ("unexpected stash %s:%s\n", HvNAME(SvSTASH(SvRV(sv))));//D
478
479 490
480 return SvPTR_nc (sv); 491 return SvPTR_nc (sv);
481} 492}
482 493
483static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } 494static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); }
532 SV *sv = to_sv (static_cast<dynbuf *> (v)); 543 SV *sv = to_sv (static_cast<dynbuf *> (v));
533 SvUTF8_on (sv); 544 SvUTF8_on (sv);
534 return sv; 545 return sv;
535} 546}
536 547
537static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } 548static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? cfSvPVutf8_nolen (sv) : 0; }
538static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 549static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
539static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 550static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
540static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 551static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
541static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 552static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
542static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 553static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
1067 CALL_CALL ("ext::books::make_book", G_VOID); 1078 CALL_CALL ("ext::books::make_book", G_VOID);
1068 CALL_END; 1079 CALL_END;
1069} 1080}
1070 1081
1071void 1082void
1072cfperl_send_msg (client *ns, int color, const char *type, const char *msg) 1083cfperl_send_msg (client *ns, int color, const_utf8_string type, const_utf8_string msg)
1073{ 1084{
1074 CALL_BEGIN (4); 1085 CALL_BEGIN (4);
1075 CALL_ARG (ns); 1086 CALL_ARG (ns);
1076 CALL_ARG (type); 1087 CALL_ARG (type);
1077 CALL_ARG_SV (newSVpv_utf8 (msg)); 1088 CALL_ARG_SV (newSVpv_utf8 (msg));
1106 CALL_CALL ("cf::mapscript::activate", G_VOID); 1117 CALL_CALL ("cf::mapscript::activate", G_VOID);
1107 CALL_END; 1118 CALL_END;
1108} 1119}
1109 1120
1110player * 1121player *
1111player::find (const char *name) 1122player::find (const_utf8_string name)
1112{ 1123{
1113 CALL_BEGIN (1); 1124 CALL_BEGIN (1);
1114 CALL_ARG (name); 1125 CALL_ARG (name);
1115 CALL_CALL ("cf::player::find", G_SCALAR); 1126 CALL_CALL ("cf::player::find", G_SCALAR);
1116 1127
1121 1132
1122 return retval; 1133 return retval;
1123} 1134}
1124 1135
1125maptile * 1136maptile *
1126find_style (const char *dirname, const char *stylename, int difficulty) 1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty)
1127{ 1138{
1128 CALL_BEGIN (3); 1139 CALL_BEGIN (3);
1129 CALL_ARG (dirname); 1140 CALL_ARG (dirname);
1130 CALL_ARG (stylename); 1141 CALL_ARG (stylename);
1131 CALL_ARG (difficulty); 1142 CALL_ARG (difficulty);
1138 1149
1139 return retval; 1150 return retval;
1140} 1151}
1141 1152
1142maptile * 1153maptile *
1143maptile::find_sync (const char *path, maptile *origin) 1154maptile::find_sync (const_utf8_string path, maptile *origin)
1144{ 1155{
1145 CALL_BEGIN (2); 1156 CALL_BEGIN (2);
1146 CALL_ARG (path); 1157 CALL_ARG (path);
1147 CALL_ARG (origin); 1158 CALL_ARG (origin);
1148 CALL_CALL ("cf::map::find_sync", G_SCALAR); 1159 CALL_CALL ("cf::map::find_sync", G_SCALAR);
1154 1165
1155 return retval; 1166 return retval;
1156} 1167}
1157 1168
1158maptile * 1169maptile *
1159maptile::find_async (const char *path, maptile *origin, bool load) 1170maptile::find_async (const_utf8_string path, maptile *origin, bool load)
1160{ 1171{
1161 CALL_BEGIN (3); 1172 CALL_BEGIN (3);
1162 CALL_ARG (path); 1173 CALL_ARG (path);
1163 CALL_ARG (origin); 1174 CALL_ARG (origin);
1164 CALL_ARG (load); 1175 CALL_ARG (load);
1193 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1204 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
1194 CALL_END; 1205 CALL_END;
1195} 1206}
1196 1207
1197void 1208void
1198object::player_goto (const char *path, int x, int y) 1209object::player_goto (const_utf8_string path, int x, int y)
1199{ 1210{
1200 if (type != PLAYER) 1211 if (type != PLAYER)
1201 return; 1212 return;
1202 1213
1203 CALL_BEGIN (4); 1214 CALL_BEGIN (4);
1207 CALL_ARG (y); 1218 CALL_ARG (y);
1208 CALL_CALL ("cf::object::player::goto", G_VOID); 1219 CALL_CALL ("cf::object::player::goto", G_VOID);
1209 CALL_END; 1220 CALL_END;
1210} 1221}
1211 1222
1212const char * 1223const_utf8_string
1213object::ref () const 1224object::ref () const
1214{ 1225{
1215 if (type == PLAYER) 1226 if (type == PLAYER)
1216 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1227 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1217 else 1228 else
1218 return 0; 1229 return 0;
1219} 1230}
1220 1231
1221object * 1232object *
1222object::deref (const char *ref) 1233object::deref (const_utf8_string ref)
1223{ 1234{
1224 object *retval = 0; 1235 object *retval = 0;
1225 1236
1226 if (ref) 1237 if (ref)
1227 { 1238 {
1237 1248
1238 return retval; 1249 return retval;
1239} 1250}
1240 1251
1241void 1252void
1242log_backtrace (const char *msg) 1253log_backtrace (const_utf8_string msg)
1243{ 1254{
1244#if HAVE_BACKTRACE 1255#if HAVE_BACKTRACE
1245 void *addr [20]; 1256 void *addr [20];
1246 int size = backtrace (addr, 20); 1257 int size = backtrace (addr, 20);
1247 1258
1253 CALL_END; 1264 CALL_END;
1254#endif 1265#endif
1255} 1266}
1256 1267
1257bool 1268bool
1258is_match_expr (const char *expr) 1269is_match_expr (const_utf8_string expr)
1259{ 1270{
1260 return !strncmp (expr, "match ", sizeof ("match ") - 1); 1271 return !strncmp (expr, "match ", sizeof ("match ") - 1);
1261} 1272}
1262 1273
1263bool 1274bool
1264match (const char *expr, object *ob, object *self, object *source, object *originator) 1275match (const_utf8_string expr, object *ob, object *self, object *source, object *originator)
1265{ 1276{
1266 if (!strncmp (expr, "match ", sizeof ("match ") - 1)) 1277 if (!strncmp (expr, "match ", sizeof ("match ") - 1))
1267 expr += sizeof ("match ") - 1; 1278 expr += sizeof ("match ") - 1;
1268 1279
1269 CALL_BEGIN (5); 1280 CALL_BEGIN (5);
1280 1291
1281 return matched; 1292 return matched;
1282} 1293}
1283 1294
1284object * 1295object *
1285match_one (const char *expr, object *ob, object *self, object *source, object *originator) 1296match_one (const_utf8_string expr, object *ob, object *self, object *source, object *originator)
1286{ 1297{
1287 if (!strncmp (expr, "match ", sizeof ("match ") - 1)) 1298 if (!strncmp (expr, "match ", sizeof ("match ") - 1))
1288 expr += sizeof ("match ") - 1; 1299 expr += sizeof ("match ") - 1;
1289 1300
1290 CALL_BEGIN (5); 1301 CALL_BEGIN (5);
1444 const_iv (MOOD_FLOOR) const_iv (EXIT) const_iv (ENCOUNTER) const_iv (SHOP_FLOOR) 1455 const_iv (MOOD_FLOOR) const_iv (EXIT) const_iv (ENCOUNTER) const_iv (SHOP_FLOOR)
1445 const_iv (SHOP_MAT) const_iv (RING) const_iv (FLOOR) const_iv (FLESH) 1456 const_iv (SHOP_MAT) const_iv (RING) const_iv (FLOOR) const_iv (FLESH)
1446 const_iv (INORGANIC) const_iv (SKILL_TOOL) const_iv (LIGHTER) const_iv (BUILDABLE_WALL) 1457 const_iv (INORGANIC) const_iv (SKILL_TOOL) const_iv (LIGHTER) const_iv (BUILDABLE_WALL)
1447 const_iv (MISC_OBJECT) const_iv (LAMP) const_iv (DUPLICATOR) const_iv (SPELLBOOK) 1458 const_iv (MISC_OBJECT) const_iv (LAMP) const_iv (DUPLICATOR) const_iv (SPELLBOOK)
1448 const_iv (CLOAK) const_iv (SPINNER) const_iv (GATE) const_iv (BUTTON) 1459 const_iv (CLOAK) const_iv (SPINNER) const_iv (GATE) const_iv (BUTTON)
1449 const_iv (T_HANDLE) const_iv (HOLE) const_iv (TRAPDOOR) const_iv (SIGN) 1460 const_iv (T_HANDLE) const_iv (HOLE) const_iv (TRAPDOOR) const_iv (SIGN)
1450 const_iv (BOOTS) const_iv (GLOVES) const_iv (SPELL) const_iv (SPELL_EFFECT) 1461 const_iv (BOOTS) const_iv (GLOVES) const_iv (SPELL) const_iv (SPELL_EFFECT)
1451 const_iv (CONVERTER) const_iv (BRACERS) const_iv (POISONING) const_iv (SAVEBED) 1462 const_iv (CONVERTER) const_iv (BRACERS) const_iv (POISONING) const_iv (SAVEBED)
1452 const_iv (WAND) const_iv (SCROLL) const_iv (DIRECTOR) const_iv (GIRDLE) 1463 const_iv (WAND) const_iv (SCROLL) const_iv (DIRECTOR) const_iv (GIRDLE)
1453 const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON) 1464 const_iv (FORCE) const_iv (POTION_EFFECT) const_iv (EVENT_CONNECTOR) const_iv (CLOSE_CON)
1454 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) 1465 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL)
1455 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) 1466 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE)
1456 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) 1467 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE)
1457 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) 1468 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER)
1458 const_iv (MAPSCRIPT) const_iv (SAFE_GROUND) 1469 const_iv (MAPSCRIPT) const_iv (SAFE_GROUND) const_iv (VEIN)
1459 1470
1460 const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES) 1471 const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES)
1461 1472
1462 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) 1473 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE)
1463 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) 1474 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM)
1509 const_iv (NDI_NOCREATE) const_iv (NDI_CLEAR) const_iv (NDI_VERBATIM) 1520 const_iv (NDI_NOCREATE) const_iv (NDI_CLEAR) const_iv (NDI_VERBATIM)
1510 1521
1511 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1522 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1512 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1523 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1513 1524
1514 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1525 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_LEVEL)
1515 1526
1516 const_iv (SP_RAISE_DEAD) 1527 const_iv (SP_RAISE_DEAD)
1517 const_iv (SP_RUNE) 1528 const_iv (SP_RUNE)
1518 const_iv (SP_MAKE_MARK) 1529 const_iv (SP_MAKE_MARK)
1519 const_iv (SP_BOLT) 1530 const_iv (SP_BOLT)
1597 const_iv (SK_WOODSMAN) const_iv (SK_INSCRIPTION) const_iv (SK_ONE_HANDED_WEAPON) const_iv (SK_MISSILE_WEAPON) 1608 const_iv (SK_WOODSMAN) const_iv (SK_INSCRIPTION) const_iv (SK_ONE_HANDED_WEAPON) const_iv (SK_MISSILE_WEAPON)
1598 const_iv (SK_THROWING) const_iv (SK_USE_MAGIC_ITEM) const_iv (SK_DISARM_TRAPS) const_iv (SK_SET_TRAP) 1609 const_iv (SK_THROWING) const_iv (SK_USE_MAGIC_ITEM) const_iv (SK_DISARM_TRAPS) const_iv (SK_SET_TRAP)
1599 const_iv (SK_THAUMATURGY) const_iv (SK_PRAYING) const_iv (SK_CLAWING) const_iv (SK_LEVITATION) 1610 const_iv (SK_THAUMATURGY) const_iv (SK_PRAYING) const_iv (SK_CLAWING) const_iv (SK_LEVITATION)
1600 const_iv (SK_SUMMONING) const_iv (SK_PYROMANCY) const_iv (SK_EVOCATION) const_iv (SK_SORCERY) 1611 const_iv (SK_SUMMONING) const_iv (SK_PYROMANCY) const_iv (SK_EVOCATION) const_iv (SK_SORCERY)
1601 const_iv (SK_TWO_HANDED_WEAPON) const_iv (SK_SPARK_TOUCH) const_iv (SK_SHIVER) const_iv (SK_ACID_SPLASH) 1612 const_iv (SK_TWO_HANDED_WEAPON) const_iv (SK_SPARK_TOUCH) const_iv (SK_SHIVER) const_iv (SK_ACID_SPLASH)
1602 const_iv (SK_POISON_NAIL) 1613 const_iv (SK_POISON_NAIL) const_iv (SK_MINING) const_iv (SK_FISHING)
1603 1614
1604 const_iv (SOUND_NEW_PLAYER) const_iv (SOUND_FIRE_ARROW) const_iv (SOUND_LEARN_SPELL) const_iv (SOUND_FUMBLE_SPELL) 1615 const_iv (SOUND_NEW_PLAYER) const_iv (SOUND_FIRE_ARROW) const_iv (SOUND_LEARN_SPELL) const_iv (SOUND_FUMBLE_SPELL)
1605 const_iv (SOUND_WAND_POOF) const_iv (SOUND_OPEN_DOOR) const_iv (SOUND_PUSH_PLAYER) const_iv (SOUND_PLAYER_HITS1) 1616 const_iv (SOUND_WAND_POOF) const_iv (SOUND_OPEN_DOOR) const_iv (SOUND_PUSH_PLAYER) const_iv (SOUND_PLAYER_HITS1)
1606 const_iv (SOUND_PLAYER_HITS2) const_iv (SOUND_PLAYER_HITS3) const_iv (SOUND_PLAYER_HITS4) const_iv (SOUND_PLAYER_IS_HIT1) 1617 const_iv (SOUND_PLAYER_HITS2) const_iv (SOUND_PLAYER_HITS3) const_iv (SOUND_PLAYER_HITS4) const_iv (SOUND_PLAYER_IS_HIT1)
1607 const_iv (SOUND_PLAYER_IS_HIT2) const_iv (SOUND_PLAYER_IS_HIT3) const_iv (SOUND_PLAYER_KILLS) const_iv (SOUND_PET_IS_KILLED) 1618 const_iv (SOUND_PLAYER_IS_HIT2) const_iv (SOUND_PLAYER_IS_HIT3) const_iv (SOUND_PLAYER_KILLS) const_iv (SOUND_PET_IS_KILLED)
1811 } 1822 }
1812 1823
1813void server_tick () 1824void server_tick ()
1814 CODE: 1825 CODE:
1815{ 1826{
1827 ev_now_update (EV_DEFAULT);
1816 NOW = ev_now (EV_DEFAULT); 1828 NOW = ev_now (EV_DEFAULT);
1817 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1829 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1818 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1830 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1819 runtime = SvNVX (sv_runtime); 1831 runtime = SvNVX (sv_runtime);
1820 1832
1821 server_tick (); 1833 server_tick ();
1822 1834
1823 NOW = ev_time (); 1835 ev_now_update (EV_DEFAULT);
1836 NOW = ev_now (EV_DEFAULT);
1824 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1837 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1825 runtime += TICK; 1838 runtime += TICK;
1826 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1839 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1827} 1840}
1828 1841
2133int mortals_size () 2146int mortals_size ()
2134 CODE: 2147 CODE:
2135 RETVAL = attachable::mortals.size (); 2148 RETVAL = attachable::mortals.size ();
2136 OUTPUT: RETVAL 2149 OUTPUT: RETVAL
2137 2150
2138const char *slot_use_name (U32 slot) 2151const_utf8_string slot_use_name (U32 slot)
2139 ALIAS: 2152 ALIAS:
2140 slot_nonuse_name = 1 2153 slot_nonuse_name = 1
2141 CODE: 2154 CODE:
2142{ 2155{
2143 if (slot >= NUM_BODY_LOCATIONS) 2156 if (slot >= NUM_BODY_LOCATIONS)
2207 2220
2208int apply_shop_mat (object *shop_mat, object *op); 2221int apply_shop_mat (object *shop_mat, object *op);
2209 2222
2210int move (object *op, int dir, object *originator = op) 2223int move (object *op, int dir, object *originator = op)
2211 CODE: 2224 CODE:
2212 RETVAL = move_ob (op, dir, originator); 2225 RETVAL = op->move (dir, originator);
2213 OUTPUT: 2226 OUTPUT:
2214 RETVAL 2227 RETVAL
2215 2228
2216void apply (object *applier, object *applied, int flags = 0)
2217 CODE:
2218 manual_apply (applied, applier, flags);
2219
2220void apply_below (object *op) 2229void apply_below (object *op)
2221 CODE: 2230 CODE:
2222 player_apply_below (op); 2231 player_apply_below (op);
2223 2232
2224int cast_heal (object *op, object *caster, object *spell, int dir = 0) 2233int cast_heal (object *op, object *caster, object *spell, int dir = 0)
2284 2293
2285void handle_apply_yield (object *op) 2294void handle_apply_yield (object *op)
2286 2295
2287int convert_item (object *item, object *converter) 2296int convert_item (object *item, object *converter)
2288 2297
2298void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2289 2299
2290MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2300MODULE = cf PACKAGE = cf::object PREFIX = cf_
2291 2301
2292# no clean way to get an object from an archetype - stupid idiotic 2302# no clean way to get an object from an archetype - stupid idiotic
2293# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2303# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2297 CODE: 2307 CODE:
2298 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2308 RETVAL = archetype ? get_archetype (archetype) : object::create ();
2299 OUTPUT: 2309 OUTPUT:
2300 RETVAL 2310 RETVAL
2301 2311
2312object *generate (utf8_string arch, object *creator)
2313 CODE:
2314 object *obj = get_archetype (arch);
2315 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2316 RETVAL = obj;
2317 OUTPUT:
2318 RETVAL
2319
2302object *find_object (U32 tag) 2320object *find_object (U32 tag)
2321
2322object *find_object_uuid (UUID i)
2303 2323
2304# TODO: nuke 2324# TODO: nuke
2305object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2325object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2306 PROTOTYPE: $$$$$$ 2326 PROTOTYPE: $$$$$$
2307 CODE: 2327 CODE:
2368 CODE: 2388 CODE:
2369 RETVAL = op->contr; 2389 RETVAL = op->contr;
2370 OUTPUT: RETVAL 2390 OUTPUT: RETVAL
2371 2391
2372bool move_player (object *op, int dir) 2392bool move_player (object *op, int dir)
2373
2374void check_score (object *op)
2375 2393
2376void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2394void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2377 CODE: 2395 CODE:
2378 new_draw_info (flags, 0, op, txt); 2396 new_draw_info (flags, 0, op, txt);
2379 2397
2550 for (int x = 0; x < THIS->width; ++x) 2568 for (int x = 0; x < THIS->width; ++x)
2551 for (int y = 0; y < THIS->height; ++y) 2569 for (int y = 0; y < THIS->height; ++y)
2552 { 2570 {
2553 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2571 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2554 if (op->flag [FLAG_IS_FLOOR]) 2572 if (op->flag [FLAG_IS_FLOOR])
2555 goto skip_space; 2573 goto skip;
2556 2574
2557 { 2575 {
2558 int offs = offset + y * stride + x; 2576 int offs = offset + y * stride + x;
2577
2559 if (IN_RANGE_EXC (offs, 0, idxlen)) 2578 if (IN_RANGE_EXC (offs, 0, idxlen))
2560 { 2579 {
2561 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2580 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2562 { 2581 {
2563 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2582 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2564 ob->flag [FLAG_NO_MAP_SAVE] = true; 2583 ob->flag [FLAG_NO_MAP_SAVE] = true;
2565 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2584 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2566 2585
2567 if (ob->randomitems) 2586 if (ob->randomitems && !ob->above)
2568 { 2587 {
2569 if (!ob->above)
2570 {
2571 ob->create_treasure (ob->randomitems); 2588 ob->create_treasure (ob->randomitems);
2572 2589
2573 for (object *op = ob->above; op; op = op->above) 2590 for (object *op = ob->above; op; op = op->above)
2574 op->flag [FLAG_NO_MAP_SAVE] = true; 2591 op->flag [FLAG_NO_MAP_SAVE] = true;
2575 } 2592 // TODO: if this is a pickable object, then the item
2576 2593 // will at a bit weird - saving inside the player
2577 ob->randomitems = 0; 2594 // will clear the flag, but when the player drops
2595 // it without logging out, it keeps the flag.
2596 // nobody ahs reported this, but this can be rather
2597 // annoying on persistent maps.
2578 } 2598 }
2579 } 2599 }
2580 } 2600 }
2581 } 2601 }
2582 2602
2583 skip_space: ; 2603 skip: ;
2584 } 2604 }
2585} 2605}
2586 2606
2587void 2607void
2588maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) 2608maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2598 2618
2599 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2619 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2600 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2620 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2601 2621
2602 for (int i = av_len ((AV *)palette) + 1; i--; ) 2622 for (int i = av_len ((AV *)palette) + 1; i--; )
2603 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2623 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2604 2624
2605 for (int y = 0; y < THIS->height; ++y) 2625 for (int y = 0; y < THIS->height; ++y)
2606 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2626 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2607 2627
2608 sfree (THIS->regions, THIS->size ()); 2628 sfree (THIS->regions, THIS->size ());
2741 utf8_string monsterstyle,\ 2761 utf8_string monsterstyle,\
2742 utf8_string treasurestyle,\ 2762 utf8_string treasurestyle,\
2743 utf8_string layoutstyle,\ 2763 utf8_string layoutstyle,\
2744 utf8_string doorstyle,\ 2764 utf8_string doorstyle,\
2745 utf8_string decorstyle,\ 2765 utf8_string decorstyle,\
2766 utf8_string miningstyle,\
2746 utf8_string origin_map,\ 2767 utf8_string origin_map,\
2747 utf8_string final_map,\ 2768 utf8_string final_map,\
2748 utf8_string exitstyle,\ 2769 utf8_string exitstyle,\
2749 utf8_string this_map,\ 2770 utf8_string this_map,\
2750 utf8_string exit_on_final_map,\ 2771 utf8_string exit_on_final_map,\
2782 assign (rmp.monsterstyle , monsterstyle); 2803 assign (rmp.monsterstyle , monsterstyle);
2783 assign (rmp.treasurestyle , treasurestyle); 2804 assign (rmp.treasurestyle , treasurestyle);
2784 assign (rmp.layoutstyle , layoutstyle); 2805 assign (rmp.layoutstyle , layoutstyle);
2785 assign (rmp.doorstyle , doorstyle); 2806 assign (rmp.doorstyle , doorstyle);
2786 assign (rmp.decorstyle , decorstyle); 2807 assign (rmp.decorstyle , decorstyle);
2808 assign (rmp.miningstyle , miningstyle);
2787 assign (rmp.exitstyle , exitstyle); 2809 assign (rmp.exitstyle , exitstyle);
2788 assign (rmp.exit_on_final_map, exit_on_final_map); 2810 assign (rmp.exit_on_final_map, exit_on_final_map);
2789 2811
2790 rmp.origin_map = origin_map; 2812 rmp.origin_map = origin_map;
2791 rmp.final_map = final_map; 2813 rmp.final_map = final_map;
2833archetype *archetypes (U32 index) 2855archetype *archetypes (U32 index)
2834 CODE: 2856 CODE:
2835 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2857 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2836 OUTPUT: RETVAL 2858 OUTPUT: RETVAL
2837 2859
2838object *instantiate (archetype *arch)
2839 CODE:
2840 RETVAL = arch_to_object (arch);
2841 OUTPUT:
2842 RETVAL
2843
2844INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2860INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2845 2861
2846MODULE = cf PACKAGE = cf::party 2862MODULE = cf PACKAGE = cf::party
2847 2863
2848partylist *first () 2864partylist *first ()
3008 faceinfo *f = face_info (idx); assert (f); 3024 faceinfo *f = face_info (idx); assert (f);
3009 facedata *d = &(faceset ? f->data64 : f->data32); 3025 facedata *d = &(faceset ? f->data64 : f->data32);
3010 sv_to (data, d->data); 3026 sv_to (data, d->data);
3011 STRLEN clen; 3027 STRLEN clen;
3012 char *cdata = SvPVbyte (chksum, clen); 3028 char *cdata = SvPVbyte (chksum, clen);
3013 clen = min (CHKSUM_SIZE, clen); 3029 clen = min (CHKSUM_MAXLEN, clen);
3014 3030
3031 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
3032
3015 if (memcmp (d->chksum, cdata, clen)) 3033 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
3016 { 3034 {
3035 d->chksum_len = clen;
3017 memcpy (d->chksum, cdata, clen); 3036 memcpy (d->chksum, cdata, clen);
3018 3037
3019 // invalidate existing client face info 3038 // invalidate existing client face info
3020 for_all_clients (ns) 3039 for_all_clients (ns)
3021 if (ns->faceset == faceset) 3040 if (ns->faceset == faceset)
3036 3055
3037SV *get_chksum (faceidx idx, int faceset = 0) 3056SV *get_chksum (faceidx idx, int faceset = 0)
3038 CODE: 3057 CODE:
3039 facedata *d = face_data (idx, faceset); 3058 facedata *d = face_data (idx, faceset);
3040 if (!d) XSRETURN_UNDEF; 3059 if (!d) XSRETURN_UNDEF;
3041 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); 3060 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
3042 OUTPUT: 3061 OUTPUT:
3043 RETVAL 3062 RETVAL
3044 3063
3045SV *get_data (faceidx idx, int faceset = 0) 3064SV *get_data (faceidx idx, int faceset = 0)
3046 CODE: 3065 CODE:
3091 } 3110 }
3092 else 3111 else
3093 anim = &animation::create (name, av_len (av) + 1, facings); 3112 anim = &animation::create (name, av_len (av) + 1, facings);
3094 3113
3095 for (int i = 0; i < anim->num_animations; ++i) 3114 for (int i = 0; i < anim->num_animations; ++i)
3096 anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1))); 3115 anim->faces [i] = face_find (cfSvPVutf8_nolen (*av_fetch (av, i, 1)));
3097} 3116}
3098 OUTPUT: RETVAL 3117 OUTPUT: RETVAL
3099 3118
3100void invalidate_all () 3119void invalidate_all ()
3101 CODE: 3120 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines