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.190 by root, Tue Apr 17 18:24:31 2007 UTC vs.
Revision 1.208 by root, Sat May 12 13:27:38 2007 UTC

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#include "autoconf.h"
27
26#define PLUGIN_NAME "perl" 28#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 29#define PLUGIN_VERSION "cfperl 0.5"
28 30
29#define CEDES_PER_TICK 5 31#define CEDES_PER_TICK 5
32
33#if HAVE_EXECINFO_H
34# include <execinfo.h>
35#endif
30 36
31#include <plugin_common.h> 37#include <plugin_common.h>
32#include <sounds.h> 38#include <sounds.h>
33#include <cstdarg> 39#include <cstdarg>
34#include <sproto.h> 40#include <sproto.h>
56 62
57typedef char *octet_string; 63typedef char *octet_string;
58typedef char *utf8_string; 64typedef char *utf8_string;
59typedef const char *const_octet_string; 65typedef const char *const_octet_string;
60typedef const char *const_utf8_string; 66typedef const char *const_utf8_string;
67
68typedef std::string std__string;
61 69
62#if IVSIZE >= 8 70#if IVSIZE >= 8
63 typedef IV val64; 71 typedef IV val64;
64# define newSVval64 newSViv 72# define newSVval64 newSViv
65# define SvVAL64 SvIV 73# define SvVAL64 SvIV
109 117
110unordered_vector<attachable *> attachable::mortals; 118unordered_vector<attachable *> attachable::mortals;
111 119
112attachable::~attachable () 120attachable::~attachable ()
113{ 121{
114 flags |=0x3300;//D
115 assert (!self); 122 assert (!self);
116 assert (!cb); 123 assert (!cb);
117} 124}
118 125
119int 126int
135 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 142 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
136 SvREFCNT_dec (self); 143 SvREFCNT_dec (self);
137 144
138 // self *must* be null now because thats sv_unmagic's job. 145 // self *must* be null now because thats sv_unmagic's job.
139 assert (!this->self); 146 assert (!this->self);
140 flags |= 0x80; // severed //D
141 } 147 }
142} 148}
143 149
144void 150void
145attachable::optimise () 151attachable::optimise ()
146{ 152{
147 if (self 153 if (self
148 && SvREFCNT (self) == 1 154 && SvREFCNT (self) == 1
149 && !HvTOTALKEYS (self)) 155 && !HvTOTALKEYS (self))
150 flags |= 0x40,//D
151 sever_self (); 156 sever_self ();
152} 157}
153 158
154// check wether the object really is dead 159// check wether the object really is dead
155void 160void
170 { 175 {
171 SvREFCNT_dec (cb); 176 SvREFCNT_dec (cb);
172 cb = 0; 177 cb = 0;
173 } 178 }
174 179
175 if (self)
176 sever_self ();
177
178 flags |= 0x20; //D
179 mortals.push_back (this); 180 mortals.push_back (this);
180} 181}
181 182
182void 183void
183attachable::destroy () 184attachable::destroy ()
185 if (destroyed ()) 186 if (destroyed ())
186 return; 187 return;
187 188
188 flags |= F_DESTROYED; 189 flags |= F_DESTROYED;
189 do_destroy (); 190 do_destroy ();
191 sever_self ();
190} 192}
191 193
192void 194void
193attachable::check_mortals () 195attachable::check_mortals ()
194{ 196{
199 if (i >= mortals.size ()) 201 if (i >= mortals.size ())
200 { 202 {
201 i = 0; 203 i = 0;
202 204
203 if (mortals.size () > 1000) 205 if (mortals.size () > 1000)
204 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 206 LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
205 207
206 break; 208 break;
207 } 209 }
208 210
209 attachable *obj = mortals [i]; 211 attachable *obj = mortals [i];
210 212
211 obj->refcnt_chk (); // unborrow from perl, if necessary 213#if 0
212 214 if (obj->self)//D make this an assert later
213 //if (obj->refcnt > 0 || obj->self)
214 if (obj->refcnt || obj->self)
215 { 215 {
216//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D 216 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
217 obj->sever_self ();
218 }
219#endif
220
221 if (obj->refcnt)
222 {
217 ++i; // further delay freeing 223 ++i; // further delay freeing
218 224
219 if (!(i & 0x3ff)) 225 if (!(i & 0x3ff))
220 break; 226 break;
221 } 227 }
222 else 228 else
223 { 229 {
224 mortals.erase (i); 230 mortals.erase (i);
231 obj->sever_self ();
225 delete obj; 232 delete obj;
226 } 233 }
227 } 234 }
228} 235}
229 236
278 285
279 if (!obj->self) 286 if (!obj->self)
280 { 287 {
281 obj->self = newHV (); 288 obj->self = newHV ();
282 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 289 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
283 obj->flags |= (obj->flags & 0xc0) << 8;
284 obj->flags &= ~0xc0;//D
285 obj->flags |= 0x10;//D
286 290
287 // now bless the object _once_ 291 // now bless the object _once_
288 return sv_bless (newRV_inc ((SV *)obj->self), stash); 292 return sv_bless (newRV_inc ((SV *)obj->self), stash);
289 } 293 }
290 else 294 else
356inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 360inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
357 361
358inline SV *to_sv (object & v) { return to_sv (&v); } 362inline SV *to_sv (object & v) { return to_sv (&v); }
359inline SV *to_sv (living & v) { return to_sv (&v); } 363inline SV *to_sv (living & v) { return to_sv (&v); }
360 364
361//inline SV *to_sv (faceinfo * v) { return to_sv (v->name); }
362inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
363inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } 365inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
366inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); }
364 367
365inline SV *to_sv (UUID v) 368inline SV *to_sv (UUID v)
366{ 369{
367 char buf[128]; 370 char buf[128];
368 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); 371 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
401inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 404inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
402 405
403template<int N> 406template<int N>
404inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 407inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
405 408
406inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
407inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 409inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
408inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 410inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
409inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 411inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
410inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 412inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
411 413
614 perl_construct (perl); 616 perl_construct (perl);
615 617
616 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 618 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
617 619
618 const char *argv[] = { 620 const char *argv[] = {
619 "", 621 settings.argv [0],
620 "-e" 622 "-e"
621 "use Event; use Coro;" // required for bootstrap 623 "use Event; use Coro;" // required for bootstrap
622 "cf->bootstrap;" // required for datadir :*> 624 "cf->bootstrap;" // required for datadir :*>
623 "unshift @INC, cf::datadir ();" 625 "unshift @INC, cf::datadir ();"
624 "require cf;" 626 "require cf;"
946 CALL_ARG (exit); 948 CALL_ARG (exit);
947 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 949 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
948 CALL_END; 950 CALL_END;
949} 951}
950 952
953void
954log_backtrace (const char *msg)
955{
956#if HAVE_BACKTRACE
957 void *addr [20];
958 int size = backtrace (addr, 20);
959
960 CALL_BEGIN (size);
961 CALL_ARG (msg);
962 for (int i = 0; i < size; ++i)
963 CALL_ARG ((IV)addr [i]);
964 CALL_CALL ("cf::_log_backtrace", G_VOID);
965 CALL_END;
966#endif
967}
968
951///////////////////////////////////////////////////////////////////////////// 969/////////////////////////////////////////////////////////////////////////////
952 970
953struct EventAPI *watcher_base::GEventAPI; 971struct EventAPI *watcher_base::GEventAPI;
954struct CoroAPI *coroapi::GCoroAPI; 972struct CoroAPI *coroapi::GCoroAPI;
955 973
1109 const char *name; 1127 const char *name;
1110 IV iv; 1128 IV iv;
1111 } *civ, const_iv[] = { 1129 } *civ, const_iv[] = {
1112# define const_iv(name) { # name, (IV)name }, 1130# define const_iv(name) { # name, (IV)name },
1113 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1131 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1132 const_iv (logBacktrace)
1114 1133
1115 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1134 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1116 1135
1117 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1136 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1118 1137
1119 const_iv (MAX_TIME) 1138 const_iv (MAX_TIME)
1139
1140 const_iv (NUM_BODY_LOCATIONS)
1141 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1142 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1143 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1144 const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand)
1145 const_iv (body_wrist) const_iv (body_waist)
1120 1146
1121 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) 1147 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE)
1122 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) 1148 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK)
1123 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) 1149 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON)
1124 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) 1150 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR)
1265 1291
1266 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1292 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1267 1293
1268 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1294 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1269 1295
1270 const_iv (ST_CHANGE_CLASS)
1271
1272 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1296 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1273 1297
1274 // random map generator 1298 // random map generator
1275 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) 1299 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL)
1276 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) 1300 const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL)
1279 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) 1303 const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE)
1280 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) 1304 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS)
1281 1305
1282 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1306 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1283 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1307 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1308
1309 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1310 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1311 const_iv (GT_MINIMAL)
1284 }; 1312 };
1285 1313
1286 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1314 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1287 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1315 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1288 1316
1324 1352
1325void _post_tick () 1353void _post_tick ()
1326 CODE: 1354 CODE:
1327 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); 1355 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1328 1356
1357# support function for map-world.ext
1358void _quantise (SV *data_sv, SV *plt_sv)
1359 CODE:
1360{
1361 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1362 croak ("_quantise called with invalid agruments");
1363
1364 plt_sv = SvRV (plt_sv);
1365 SV **plt = AvARRAY (plt_sv);
1366 int plt_count = AvFILL (plt_sv) + 1;
1367
1368 STRLEN len;
1369 char *data = SvPVbyte (data_sv, len);
1370 char *dst = data;
1371
1372 while (len >= 3)
1373 {
1374 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1375 {
1376 char *val = SvPVX (*val_sv);
1377
1378 if (val [0] == data [0]
1379 && val [1] == data [1]
1380 && val [2] == data [2])
1381 {
1382 *dst++ = val [3];
1383 goto next;
1384 }
1385 }
1386
1387 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1388 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1389 dst - SvPVX (data_sv), len);
1390
1391 next:
1392 data += 3;
1393 len -= 3;
1394 }
1395
1396 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1397}
1398
1329NV floor (NV x) 1399NV floor (NV x)
1330 1400
1331NV ceil (NV x) 1401NV ceil (NV x)
1332 1402
1333NV rndm (...) 1403NV rndm (...)
1340 default: croak ("cf::rndm requires none, one or two parameters."); break; 1410 default: croak ("cf::rndm requires none, one or two parameters."); break;
1341 } 1411 }
1342 OUTPUT: 1412 OUTPUT:
1343 RETVAL 1413 RETVAL
1344 1414
1415NV clamp (NV value, NV min_value, NV max_value)
1416 CODE:
1417 RETVAL = clamp (value, min_value, max_value);
1418 OUTPUT:
1419 RETVAL
1420
1421NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1422 CODE:
1423 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1424 OUTPUT:
1425 RETVAL
1426
1427void cede_to_tick ()
1428 CODE:
1429 coroapi::cede_to_tick ();
1430
1345void server_tick () 1431void server_tick ()
1346 CODE: 1432 CODE:
1347 runtime = SvNVx (sv_runtime); 1433 runtime = SvNVx (sv_runtime);
1348 server_tick (); 1434 server_tick ();
1349 1435
1350void 1436void
1437log_backtrace (utf8_string msg)
1438
1439void
1351LOG (int level, utf8_string msg) 1440LOG (int flags, utf8_string msg)
1352 PROTOTYPE: $$ 1441 PROTOTYPE: $$
1353 C_ARGS: (LogLevel)level, "%s", msg 1442 C_ARGS: flags, "%s", msg
1354 1443
1355octet_string path_combine (octet_string base, octet_string path) 1444octet_string path_combine (octet_string base, octet_string path)
1356 PROTOTYPE: $$ 1445 PROTOTYPE: $$
1357 1446
1358octet_string path_combine_and_normalize (octet_string base, octet_string path) 1447octet_string path_combine_and_normalize (octet_string base, octet_string path)
1395 } 1484 }
1396 OUTPUT: RETVAL 1485 OUTPUT: RETVAL
1397 1486
1398void abort () 1487void abort ()
1399 1488
1489void reset_signals ()
1490
1400void fork_abort (octet_string cause = "cf::fork_abort") 1491void fork_abort (octet_string cause = "cf::fork_abort")
1401 1492
1402void cleanup (octet_string cause, bool make_core = false) 1493void cleanup (octet_string cause, bool make_core = false)
1403 1494
1404void emergency_save () 1495void emergency_save ()
1466 OUTPUT: RETVAL 1557 OUTPUT: RETVAL
1467 1558
1468bool 1559bool
1469load_resource_file (octet_string filename) 1560load_resource_file (octet_string filename)
1470 1561
1471bool
1472load_archetype_file (octet_string filename)
1473
1474MODULE = cf PACKAGE = cf::attachable 1562MODULE = cf PACKAGE = cf::attachable
1475 1563
1476int 1564int
1477valid (SV *obj) 1565valid (SV *obj)
1478 CODE: 1566 CODE:
1541object *actives (U32 index) 1629object *actives (U32 index)
1542 CODE: 1630 CODE:
1543 RETVAL = index < actives.size () ? actives [index] : 0; 1631 RETVAL = index < actives.size () ? actives [index] : 0;
1544 OUTPUT: RETVAL 1632 OUTPUT: RETVAL
1545 1633
1634const char *slot_save_name (U32 slot)
1635 ALIAS:
1636 slot_use_name = 1
1637 slot_nonuse_name = 2
1638 CODE:
1639{
1640 if (slot >= NUM_BODY_LOCATIONS)
1641 croak ("body slot index out of range");
1642
1643 switch (ix)
1644 {
1645 case 0: RETVAL = body_locations[slot].save_name; break;
1646 case 1: RETVAL = body_locations[slot].use_name; break;
1647 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1648 }
1649}
1650 OUTPUT:
1651 RETVAL
1652
1546# missing properties 1653# missing properties
1547 1654
1548object *head (object *op) 1655object *head (object *op)
1549 PROTOTYPE: $ 1656 PROTOTYPE: $
1550 CODE: 1657 CODE:
1575int 1682int
1576num_animations (object *op) 1683num_animations (object *op)
1577 CODE: 1684 CODE:
1578 RETVAL = NUM_ANIMATIONS (op); 1685 RETVAL = NUM_ANIMATIONS (op);
1579 OUTPUT: RETVAL 1686 OUTPUT: RETVAL
1687
1688int slot_info (object *op, UV slot, int value = 0)
1689 ALIAS:
1690 slot_used = 1
1691 CODE:
1692{
1693 if (slot >= NUM_BODY_LOCATIONS)
1694 croak ("body slot index out of range");
1695
1696 RETVAL = ix ? op->slot[slot].used : op->slot[slot].info;
1697
1698 if (items > 2)
1699 if (ix)
1700 op->slot[slot].used = value;
1701 else
1702 op->slot[slot].info = value;
1703}
1704 OUTPUT:
1705 RETVAL
1580 1706
1581object *find_best_object_match (object *op, utf8_string match) 1707object *find_best_object_match (object *op, utf8_string match)
1582 1708
1583object *find_marked_object (object *op) 1709object *find_marked_object (object *op)
1584 1710
1933 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2059 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1934 { 2060 {
1935 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2061 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1936 ob->flag [FLAG_NO_MAP_SAVE] = true; 2062 ob->flag [FLAG_NO_MAP_SAVE] = true;
1937 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2063 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2064
2065 if (ob->randomitems)
2066 {
2067 if (!ob->above)
2068 {
2069 ob->create_treasure (ob->randomitems);
2070
2071 for (object *op = ob->above; op; op = op->above)
2072 op->flag [FLAG_NO_MAP_SAVE] = true;
2073 }
2074
2075 ob->randomitems = 0;
2076 }
1938 } 2077 }
1939 } 2078 }
1940 } 2079 }
1941 2080
1942 skip_space: ; 2081 skip_space: ;
1969 sfree (THIS->regions, THIS->size ()); 2108 sfree (THIS->regions, THIS->size ());
1970 free (THIS->regionmap); 2109 free (THIS->regionmap);
1971 2110
1972 THIS->regions = regions; 2111 THIS->regions = regions;
1973 THIS->regionmap = regionmap; 2112 THIS->regionmap = regionmap;
2113}
2114
2115void
2116maptile::create_region_treasure ()
2117 CODE:
2118{
2119 object *op = object::create ();
2120 op->type = FLOOR;
2121 op->map = THIS;
2122
2123 for (int x = 0; x < THIS->width; ++x)
2124 for (int y = 0; y < THIS->height; ++y)
2125 {
2126 region *rgn = THIS->region (x, y);
2127
2128 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2129 if (rgn->treasure && rndm () < rgn->treasure_density)
2130 {
2131 op->x = x;
2132 op->y = y;
2133 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2134 }
2135 }
2136
2137 op->destroy ();
1974} 2138}
1975 2139
1976void play_sound_map (maptile *map, int x, int y, int sound_num) 2140void play_sound_map (maptile *map, int x, int y, int sound_num)
1977 2141
1978int out_of_map (maptile *map, int x, int y) 2142int out_of_map (maptile *map, int x, int y)
2202 RETVAL = 0; 2366 RETVAL = 0;
2203 while (rgn = rgn->parent) 2367 while (rgn = rgn->parent)
2204 RETVAL++; 2368 RETVAL++;
2205 OUTPUT: RETVAL 2369 OUTPUT: RETVAL
2206 2370
2207INCLUDE: $PERL $srcdir/genacc region ../include/map.h | 2371INCLUDE: $PERL $srcdir/genacc region ../include/region.h |
2208 2372
2209MODULE = cf PACKAGE = cf::living 2373MODULE = cf PACKAGE = cf::living
2210 2374
2211INCLUDE: $PERL $srcdir/genacc living ../include/living.h | 2375INCLUDE: $PERL $srcdir/genacc living ../include/living.h |
2212 2376

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines