… | |
… | |
195 | return (min); |
195 | return (min); |
196 | |
196 | |
197 | return (RANDOM () % diff + min); |
197 | return (RANDOM () % diff + min); |
198 | } |
198 | } |
199 | |
199 | |
200 | /* decay and destroy persihable items in a map */ |
200 | /* decay and destroy perishable items in a map */ |
201 | |
|
|
202 | void |
201 | void |
203 | decay_objects (maptile *m) |
202 | maptile::decay_objects () |
204 | { |
203 | { |
205 | int x, y, destroy; |
204 | int x, y, destroy; |
206 | object *op, *otmp; |
205 | object *op, *otmp; |
207 | |
206 | |
208 | if (m->unique) |
207 | for (x = 0; x < width; x++) |
209 | return; |
208 | for (y = 0; y < height; y++) |
210 | |
|
|
211 | for (x = 0; x < MAP_WIDTH (m); x++) |
|
|
212 | for (y = 0; y < MAP_HEIGHT (m); y++) |
|
|
213 | for (op = GET_MAP_OB (m, x, y); op; op = otmp) |
209 | for (op = at (x, y).bot; op; op = otmp) |
214 | { |
210 | { |
215 | destroy = 0; |
211 | destroy = 0; |
216 | otmp = op->above; |
212 | otmp = op->above; |
|
|
213 | |
217 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
214 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
218 | break; |
215 | break; |
|
|
216 | |
219 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) |
217 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) |
220 | || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) |
218 | || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) |
221 | || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) |
219 | || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) |
222 | || QUERY_FLAG (op, FLAG_UNIQUE) |
220 | || QUERY_FLAG (op, FLAG_UNIQUE) |
223 | || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) |
221 | || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) |
… | |
… | |
247 | else |
245 | else |
248 | { |
246 | { |
249 | if (op->material & M_PAPER || op->material & M_LEATHER || |
247 | if (op->material & M_PAPER || op->material & M_LEATHER || |
250 | op->material & M_WOOD || op->material & M_ORGANIC || op->material & M_CLOTH || op->material & M_LIQUID) |
248 | op->material & M_WOOD || op->material & M_ORGANIC || op->material & M_CLOTH || op->material & M_LIQUID) |
251 | destroy = 1; |
249 | destroy = 1; |
|
|
250 | |
252 | if (op->material & M_IRON && rndm (1, 5) == 1) |
251 | if (op->material & M_IRON && rndm (1, 5) == 1) |
253 | destroy = 1; |
252 | destroy = 1; |
|
|
253 | |
254 | if (op->material & M_GLASS && rndm (1, 2) == 1) |
254 | if (op->material & M_GLASS && rndm (1, 2) == 1) |
255 | destroy = 1; |
255 | destroy = 1; |
|
|
256 | |
256 | if ((op->material & M_STONE || op->material & M_ADAMANT) && rndm (1, 10) == 1) |
257 | if ((op->material & M_STONE || op->material & M_ADAMANT) && rndm (1, 10) == 1) |
257 | destroy = 1; |
258 | destroy = 1; |
|
|
259 | |
258 | if ((op->material & M_SOFT_METAL || op->material & M_BONE) && rndm (1, 3) == 1) |
260 | if ((op->material & M_SOFT_METAL || op->material & M_BONE) && rndm (1, 3) == 1) |
259 | destroy = 1; |
261 | destroy = 1; |
|
|
262 | |
260 | if (op->material & M_ICE && MAP_TEMP (m) > 32) |
263 | if (op->material & M_ICE && temp > 32) |
261 | destroy = 1; |
264 | destroy = 1; |
262 | } |
265 | } |
|
|
266 | |
263 | /* adjust overall chance below */ |
267 | /* adjust overall chance below */ |
264 | if (destroy && rndm (0, 1)) |
268 | if (destroy && rndm (0, 1)) |
265 | op->destroy (); |
269 | op->destroy (); |
266 | } |
270 | } |
267 | } |
271 | } |
… | |
… | |
544 | return; |
548 | return; |
545 | } |
549 | } |
546 | |
550 | |
547 | ///////////////////////////////////////////////////////////////////////////// |
551 | ///////////////////////////////////////////////////////////////////////////// |
548 | |
552 | |
549 | #if 0 |
|
|
550 | refcounted *refcounted::rc_first; |
|
|
551 | |
|
|
552 | refcounted::refcounted () |
|
|
553 | { |
|
|
554 | refcnt = 0; |
|
|
555 | rc_next = rc_first; |
|
|
556 | rc_first = this; |
|
|
557 | } |
|
|
558 | #endif |
|
|
559 | |
|
|
560 | refcounted::~refcounted () |
|
|
561 | { |
|
|
562 | #if 0 |
|
|
563 | assert (!rc_next); |
|
|
564 | assert (!refcnt); |
|
|
565 | #endif |
|
|
566 | } |
|
|
567 | |
|
|
568 | void *salloc_ (int n) throw (std::bad_alloc) |
553 | void *salloc_ (int n) throw (std::bad_alloc) |
569 | { |
554 | { |
570 | void *ptr = g_slice_alloc (n); |
555 | void *ptr = g_slice_alloc (n); |
571 | |
556 | |
572 | if (!ptr) |
557 | if (!ptr) |
… | |
… | |
617 | |
602 | |
618 | gettimeofday (&tv, 0); |
603 | gettimeofday (&tv, 0); |
619 | return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); |
604 | return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); |
620 | } |
605 | } |
621 | |
606 | |
|
|
607 | int |
|
|
608 | similar_direction (int a, int b) |
|
|
609 | { |
|
|
610 | if (!a || !b) |
|
|
611 | return 0; |
|
|
612 | |
|
|
613 | int diff = (b - a) & 7; |
|
|
614 | return diff <= 1 || diff >= 7; |
|
|
615 | } |
|
|
616 | |