--- deliantra/server/common/map.C 2007/02/16 22:21:46 1.90 +++ deliantra/server/common/map.C 2007/02/17 23:32:11 1.91 @@ -1671,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->head_ () == pick) + return pick->head_ (); + } + + // instead of crashing in the unlikely(?) case, try to return *something* + return get_archetype ("blocked"); +}