--- deliantra/server/common/utils.C 2006/12/18 03:00:02 1.26 +++ deliantra/server/common/utils.C 2007/01/01 12:28:46 1.34 @@ -197,25 +197,22 @@ return (RANDOM () % diff + min); } -/* decay and destroy persihable items in a map */ - +/* decay and destroy perishable items in a map */ void -decay_objects (maptile *m) +maptile::decay_objects () { - int x, y, destroy; - object *op, *otmp; + for (int x = 0; x < width; x++) + for (int y = 0; y < height; y++) + for (object *above = 0, *op = at (x, y).bot; op; op = above) + { + bool destroy = 0; - if (m->unique) - return; + above = op->above; - for (x = 0; x < MAP_WIDTH (m); x++) - for (y = 0; y < MAP_HEIGHT (m); y++) - for (op = get_map_ob (m, x, y); op; op = otmp) - { - destroy = 0; - otmp = op->above; + // do not decay anything above unique floor tiles (yet :) if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) break; + if (QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) @@ -223,10 +220,8 @@ || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) || QUERY_FLAG (op, FLAG_UNPAID) || op->is_alive ()) - continue; - - /* otherwise, we decay and destroy */ - if (op->is_weapon ()) + ; // do not decay + else if (op->is_weapon ()) { op->stats.dam--; if (op->stats.dam < 0) @@ -246,20 +241,22 @@ } else { - if (op->material & M_PAPER || op->material & M_LEATHER || - op->material & M_WOOD || op->material & M_ORGANIC || op->material & M_CLOTH || op->material & M_LIQUID) - destroy = 1; - if (op->material & M_IRON && rndm (1, 5) == 1) - destroy = 1; - if (op->material & M_GLASS && rndm (1, 2) == 1) - destroy = 1; - if ((op->material & M_STONE || op->material & M_ADAMANT) && rndm (1, 10) == 1) - destroy = 1; - if ((op->material & M_SOFT_METAL || op->material & M_BONE) && rndm (1, 3) == 1) - destroy = 1; - if (op->material & M_ICE && MAP_TEMP (m) > 32) + int mat = op->material; + + if (mat & M_PAPER + || mat & M_LEATHER + || mat & M_WOOD + || mat & M_ORGANIC + || mat & M_CLOTH + || mat & M_LIQUID + || (mat & M_IRON && rndm (1, 5) == 1) + || (mat & M_GLASS && rndm (1, 2) == 1) + || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1) + || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1) + || (mat & M_ICE && temp > 32)) destroy = 1; } + /* adjust overall chance below */ if (destroy && rndm (0, 1)) op->destroy (); @@ -546,23 +543,6 @@ ///////////////////////////////////////////////////////////////////////////// -#if 0 -refcounted *refcounted::rc_first; - -refcounted::refcounted () -{ - refcnt = 0; - rc_next = rc_first; - rc_first = this; -} - -refcounted::~refcounted () -{ - assert (!rc_next); - assert (!refcnt); -} -#endif - void *salloc_ (int n) throw (std::bad_alloc) { void *ptr = g_slice_alloc (n); @@ -617,3 +597,13 @@ return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); } +int +similar_direction (int a, int b) +{ + if (!a || !b) + return 0; + + int diff = (b - a) & 7; + return diff <= 1 || diff >= 7; +} +