… | |
… | |
106 | * isn't, and difficult is -1, it returns a random style map. |
106 | * isn't, and difficult is -1, it returns a random style map. |
107 | * Otherwise, it tries to match the difficulty given with a style |
107 | * Otherwise, it tries to match the difficulty given with a style |
108 | * file, named style_name_# where # is an integer |
108 | * file, named style_name_# where # is an integer |
109 | */ |
109 | */ |
110 | |
110 | |
111 | /* remove extern, so visible to command_style_map_info function */ |
|
|
112 | maptile *styles = NULL; |
|
|
113 | |
|
|
114 | |
|
|
115 | maptile * |
111 | maptile * |
116 | load_style_map (char *style_name) |
112 | load_style_map (char *style_name) |
117 | { |
113 | { |
118 | maptile *style_map; |
114 | maptile *style_map = maptile::find_map (style_name, 0); |
119 | |
|
|
120 | /* Given a file. See if its in memory */ |
|
|
121 | for (style_map = styles; style_map; style_map = style_map->next) |
|
|
122 | if (!strcmp (style_name, style_map->path)) |
|
|
123 | return style_map; |
|
|
124 | |
|
|
125 | style_map = load_original_map (style_name, MAP_STYLE); |
|
|
126 | |
|
|
127 | /* Remove it from global list, put it on our local list */ |
|
|
128 | if (style_map) |
|
|
129 | { |
|
|
130 | style_map->unlink (); |
115 | style_map->load (); |
131 | |
|
|
132 | style_map->next = styles; |
|
|
133 | styles = style_map; |
|
|
134 | } |
|
|
135 | |
|
|
136 | return style_map; |
116 | return style_map; |
137 | } |
117 | } |
138 | |
118 | |
139 | maptile * |
119 | maptile * |
140 | find_style (const char *dirname, const char *stylename, int difficulty) |
120 | find_style (const char *dirname, const char *stylename, int difficulty) |
… | |
… | |
238 | } |
218 | } |
239 | return style_map; |
219 | return style_map; |
240 | |
220 | |
241 | } |
221 | } |
242 | |
222 | |
243 | |
|
|
244 | /* picks a random object from a style map. |
223 | /* picks a random object from a style map. |
245 | * Redone by MSW so it should be faster and not use static |
224 | * Redone by MSW so it should be faster and not use static |
246 | * variables to generate tables. |
225 | * variables to generate tables. |
247 | */ |
226 | */ |
248 | object * |
227 | object * |
… | |
… | |
263 | x = RANDOM () % style->width; |
242 | x = RANDOM () % style->width; |
264 | y = RANDOM () % style->height; |
243 | y = RANDOM () % style->height; |
265 | new_obj = GET_MAP_OB (style, x, y); |
244 | new_obj = GET_MAP_OB (style, x, y); |
266 | } |
245 | } |
267 | while (new_obj == NULL && limit < 1000); |
246 | while (new_obj == NULL && limit < 1000); |
|
|
247 | |
268 | if (new_obj->head) |
248 | if (new_obj->head) |
269 | return new_obj->head; |
249 | return new_obj->head; |
270 | else |
250 | else |
271 | return new_obj; |
251 | return new_obj; |
272 | } |
252 | } |
273 | |
253 | |
274 | |
|
|
275 | void |
|
|
276 | free_style_maps (void) |
|
|
277 | { |
|
|
278 | maptile *next; |
|
|
279 | int style_maps = 0; |
|
|
280 | |
|
|
281 | /* delete_map will try to free it from the linked list, |
|
|
282 | * but won't find it, so we need to do it ourselves |
|
|
283 | */ |
|
|
284 | while (styles) |
|
|
285 | { |
|
|
286 | next = styles->next; |
|
|
287 | delete_map (styles); |
|
|
288 | styles = next; |
|
|
289 | style_maps++; |
|
|
290 | } |
|
|
291 | LOG (llevDebug, "free_style_maps: Freed %d maps\n", style_maps); |
|
|
292 | } |
|
|