… | |
… | |
201 | style_map->load_sync (); |
201 | style_map->load_sync (); |
202 | style_map->deactivate (); |
202 | style_map->deactivate (); |
203 | } |
203 | } |
204 | |
204 | |
205 | return style_map; |
205 | return style_map; |
206 | |
|
|
207 | } |
206 | } |
208 | |
|
|
209 | /* picks a random object from a style map. |
|
|
210 | * Redone by MSW so it should be faster and not use static |
|
|
211 | * variables to generate tables. |
|
|
212 | */ |
|
|
213 | object * |
|
|
214 | pick_random_object (maptile *style) |
|
|
215 | { |
|
|
216 | /* while returning a null object will result in a crash, that |
|
|
217 | * is actually preferable to an infinite loop. That is because |
|
|
218 | * most servers will automatically restart in case of crash. |
|
|
219 | * Change the logic on getting the random space - shouldn't make |
|
|
220 | * any difference, but this seems clearer to me. |
|
|
221 | */ |
|
|
222 | for (int i = 1000; --i;) |
|
|
223 | { |
|
|
224 | object *new_obj = style->at (rndm (style->width), rndm (style->height)).bot; |
|
|
225 | |
|
|
226 | if (new_obj) |
|
|
227 | return new_obj->head_ (); |
|
|
228 | } |
|
|
229 | |
|
|
230 | // instead of crashing in the unlikely case, try to return *something* |
|
|
231 | return get_archetype ("blocked"); |
|
|
232 | } |
|
|