… | |
… | |
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) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) || QUERY_FLAG (op, FLAG_UNPAID) || IS_LIVE (op)) |
220 | || QUERY_FLAG (op, FLAG_UNIQUE) |
|
|
221 | || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) |
|
|
222 | || QUERY_FLAG (op, FLAG_UNPAID) |
|
|
223 | || op->is_alive ()) |
223 | continue; |
224 | continue; |
|
|
225 | |
224 | /* otherwise, we decay and destroy */ |
226 | /* otherwise, we decay and destroy */ |
225 | if (IS_WEAPON (op)) |
227 | if (op->is_weapon ()) |
226 | { |
228 | { |
227 | op->stats.dam--; |
229 | op->stats.dam--; |
228 | if (op->stats.dam < 0) |
230 | if (op->stats.dam < 0) |
229 | destroy = 1; |
231 | destroy = 1; |
230 | } |
232 | } |
231 | else if (IS_ARMOR (op)) |
233 | else if (op->is_armor ()) |
232 | { |
234 | { |
233 | op->stats.ac--; |
235 | op->stats.ac--; |
234 | if (op->stats.ac < 0) |
236 | if (op->stats.ac < 0) |
235 | destroy = 1; |
237 | destroy = 1; |
236 | } |
238 | } |
… | |
… | |
243 | else |
245 | else |
244 | { |
246 | { |
245 | if (op->material & M_PAPER || op->material & M_LEATHER || |
247 | if (op->material & M_PAPER || op->material & M_LEATHER || |
246 | 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) |
247 | destroy = 1; |
249 | destroy = 1; |
|
|
250 | |
248 | if (op->material & M_IRON && rndm (1, 5) == 1) |
251 | if (op->material & M_IRON && rndm (1, 5) == 1) |
249 | destroy = 1; |
252 | destroy = 1; |
|
|
253 | |
250 | if (op->material & M_GLASS && rndm (1, 2) == 1) |
254 | if (op->material & M_GLASS && rndm (1, 2) == 1) |
251 | destroy = 1; |
255 | destroy = 1; |
|
|
256 | |
252 | 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) |
253 | destroy = 1; |
258 | destroy = 1; |
|
|
259 | |
254 | 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) |
255 | destroy = 1; |
261 | destroy = 1; |
|
|
262 | |
256 | if (op->material & M_ICE && MAP_TEMP (m) > 32) |
263 | if (op->material & M_ICE && temp > 32) |
257 | destroy = 1; |
264 | destroy = 1; |
258 | } |
265 | } |
|
|
266 | |
259 | /* adjust overall chance below */ |
267 | /* adjust overall chance below */ |
260 | if (destroy && rndm (0, 1)) |
268 | if (destroy && rndm (0, 1)) |
261 | op->destroy (); |
269 | op->destroy (); |
262 | } |
270 | } |
263 | } |
271 | } |
… | |
… | |
295 | return; |
303 | return; |
296 | |
304 | |
297 | if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) |
305 | if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) |
298 | return; |
306 | return; |
299 | |
307 | |
300 | if (!IS_ARMOR (op)) |
308 | if (!op->is_armor ()) |
301 | return; |
309 | return; |
302 | |
310 | |
303 | mt = name_to_material (op->materialname); |
311 | mt = name_to_material (op->materialname); |
304 | if (!mt) |
312 | if (!mt) |
305 | { |
313 | { |
… | |
… | |
351 | { |
359 | { |
352 | if (op->material & mt->material && rndm (1, 100) <= mt->chance && |
360 | if (op->material & mt->material && rndm (1, 100) <= mt->chance && |
353 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
361 | difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) |
354 | { |
362 | { |
355 | lmt = mt; |
363 | lmt = mt; |
356 | if (!(IS_WEAPON (op) || IS_ARMOR (op))) |
364 | if (!(op->is_weapon () || op->is_armor ())) |
357 | break; |
365 | break; |
358 | } |
366 | } |
359 | } |
367 | } |
360 | #endif |
368 | #endif |
361 | } |
369 | } |
… | |
… | |
369 | #ifndef NEW_MATERIAL_CODE |
377 | #ifndef NEW_MATERIAL_CODE |
370 | op->materialname = lmt->name; |
378 | op->materialname = lmt->name; |
371 | return; |
379 | return; |
372 | #else |
380 | #else |
373 | |
381 | |
374 | if (op->stats.dam && IS_WEAPON (op)) |
382 | if (op->stats.dam && op->is_weapon ()) |
375 | { |
383 | { |
376 | op->stats.dam += lmt->damage; |
384 | op->stats.dam += lmt->damage; |
377 | if (op->stats.dam < 1) |
385 | if (op->stats.dam < 1) |
378 | op->stats.dam = 1; |
386 | op->stats.dam = 1; |
379 | } |
387 | } |
380 | if (op->stats.sp && op->type == BOW) |
388 | if (op->stats.sp && op->type == BOW) |
381 | op->stats.sp += lmt->sp; |
389 | op->stats.sp += lmt->sp; |
382 | if (op->stats.wc && IS_WEAPON (op)) |
390 | if (op->stats.wc && op->is_weapon ()) |
383 | op->stats.wc += lmt->wc; |
391 | op->stats.wc += lmt->wc; |
384 | if (IS_ARMOR (op)) |
392 | if (op->is_armor ()) |
385 | { |
393 | { |
386 | if (op->stats.ac) |
394 | if (op->stats.ac) |
387 | op->stats.ac += lmt->ac; |
395 | op->stats.ac += lmt->ac; |
388 | for (j = 0; j < NROFATTACKS; j++) |
396 | for (j = 0; j < NROFATTACKS; j++) |
389 | if (op->resist[j] != 0) |
397 | if (op->resist[j] != 0) |
… | |
… | |
395 | op->resist[j] = -100; |
403 | op->resist[j] = -100; |
396 | } |
404 | } |
397 | } |
405 | } |
398 | op->materialname = add_string (lmt->name); |
406 | op->materialname = add_string (lmt->name); |
399 | /* dont make it unstackable if it doesn't need to be */ |
407 | /* dont make it unstackable if it doesn't need to be */ |
400 | if (IS_WEAPON (op) || IS_ARMOR (op)) |
408 | if (op->is_weapon () || op->is_armor ()) |
401 | { |
409 | { |
402 | op->weight = (op->weight * lmt->weight) / 100; |
410 | op->weight = (op->weight * lmt->weight) / 100; |
403 | op->value = (op->value * lmt->value) / 100; |
411 | op->value = (op->value * lmt->value) / 100; |
404 | } |
412 | } |
405 | #endif |
413 | #endif |
… | |
… | |
540 | return; |
548 | return; |
541 | } |
549 | } |
542 | |
550 | |
543 | ///////////////////////////////////////////////////////////////////////////// |
551 | ///////////////////////////////////////////////////////////////////////////// |
544 | |
552 | |
545 | #if 0 |
|
|
546 | refcounted *refcounted::rc_first; |
|
|
547 | |
|
|
548 | refcounted::refcounted () |
|
|
549 | { |
|
|
550 | refcnt = 0; |
|
|
551 | rc_next = rc_first; |
|
|
552 | rc_first = this; |
|
|
553 | } |
|
|
554 | |
|
|
555 | refcounted::~refcounted () |
|
|
556 | { |
|
|
557 | assert (!rc_next); |
|
|
558 | assert (!refcnt); |
|
|
559 | } |
|
|
560 | #endif |
|
|
561 | |
|
|
562 | void *salloc (int size) throw (std::bad_alloc) |
553 | void *salloc_ (int n) throw (std::bad_alloc) |
563 | { |
554 | { |
564 | void *ptr = g_slice_alloc (size); |
555 | void *ptr = g_slice_alloc (n); |
565 | |
556 | |
566 | if (!ptr) |
557 | if (!ptr) |
567 | throw std::bad_alloc (); |
558 | throw std::bad_alloc (); |
568 | |
559 | |
569 | return ptr; |
560 | return ptr; |
570 | } |
561 | } |
571 | |
562 | |
572 | void *salloc (int size, void *src) throw (std::bad_alloc) |
563 | void *salloc_ (int n, void *src) throw (std::bad_alloc) |
573 | { |
564 | { |
574 | void *ptr = salloc (size); |
565 | void *ptr = salloc_ (n); |
575 | |
566 | |
576 | if (src) |
567 | if (src) |
577 | memcpy (ptr, src, size); |
568 | memcpy (ptr, src, n); |
578 | else |
569 | else |
579 | memset (ptr, 0, size); |
570 | memset (ptr, 0, n); |
580 | |
571 | |
581 | return ptr; |
572 | return ptr; |
582 | } |
573 | } |
583 | |
574 | |
584 | void assign (char *dst, const char *src, int maxlen) |
575 | void assign (char *dst, const char *src, int maxlen) |
… | |
… | |
611 | |
602 | |
612 | gettimeofday (&tv, 0); |
603 | gettimeofday (&tv, 0); |
613 | 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); |
614 | } |
605 | } |
615 | |
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 | |