--- deliantra/server/common/map.C 2007/02/16 19:43:40 1.88 +++ deliantra/server/common/map.C 2007/03/11 02:12:44 1.93 @@ -356,10 +356,8 @@ return; for (mapspace *ms = spaces + size (); ms-- > spaces; ) - for (object *tmp = ms->bot; tmp; ) + for (object *tmp = ms->bot; tmp; tmp = tmp->above) { - object *above = tmp->above; - /* already multipart - don't do anything more */ if (!tmp->head && !tmp->more) { @@ -391,8 +389,6 @@ insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); } } - - tmp = above; } } @@ -410,7 +406,7 @@ switch (f.kw) { case KW_arch: - if (object *op = object::read (f)) + if (object *op = object::read (f, this)) { if (op->inv) sum_weight (op); @@ -1081,7 +1077,7 @@ { object *tmp, *last = 0; uint8 flags = P_UPTODATE, light = 0, anywhere = 0; - facetile *top, *floor, *middle; + faceidx top, floor, middle; object *top_obj, *floor_obj, *middle_obj; MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; @@ -1140,7 +1136,7 @@ * visibilities, we still want the one nearer to the * top */ - else if (middle == blank_face || (tmp->face->visibility > middle->visibility && !anywhere)) + else if (middle == blank_face || (::faces [tmp->face].visibility > ::faces [middle].visibility && !anywhere)) { middle = tmp->face; middle_obj = tmp; @@ -1675,4 +1671,29 @@ return ::region::default_region (); } +/* picks a random object from a style map. + * Redone by MSW so it should be faster and not use static + * variables to generate tables. + */ +object * +maptile::pick_random_object () const +{ + /* while returning a null object will result in a crash, that + * is actually preferable to an infinite loop. That is because + * most servers will automatically restart in case of crash. + * Change the logic on getting the random space - shouldn't make + * any difference, but this seems clearer to me. + */ + for (int i = 1000; --i;) + { + object *pick = at (rndm (width), rndm (height)).bot; + + // do not prefer big monsters just because they are big. + if (pick && pick->head_ () == pick) + return pick->head_ (); + } + + // instead of crashing in the unlikely(?) case, try to return *something* + return get_archetype ("blocked"); +}