… | |
… | |
22 | */ |
22 | */ |
23 | |
23 | |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <random_map.h> |
26 | #include <random_map.h> |
27 | #ifndef WIN32 /* ---win32 exclude headers */ |
|
|
28 | # include <dirent.h> |
27 | #include <dirent.h> |
29 | # include <sys/stat.h> |
28 | #include <sys/stat.h> |
30 | # include <unistd.h> |
29 | #include <unistd.h> |
31 | # include "../include/autoconf.h" |
30 | #include "../include/autoconf.h" |
32 | #endif /* win32 */ |
|
|
33 | |
31 | |
34 | |
32 | |
35 | static int |
33 | static int |
36 | pointer_strcmp (const void *p1, const void *p2) |
34 | pointer_strcmp (const void *p1, const void *p2) |
37 | { |
35 | { |
… | |
… | |
83 | if (entries == entry_size) |
81 | if (entries == entry_size) |
84 | { |
82 | { |
85 | entry_size += 10; |
83 | entry_size += 10; |
86 | rn = (char **) realloc (rn, sizeof (char *) * entry_size); |
84 | rn = (char **) realloc (rn, sizeof (char *) * entry_size); |
87 | } |
85 | } |
88 | rn[entries] = strdup_local (d->d_name); |
86 | rn[entries] = strdup (d->d_name); |
89 | entries++; |
87 | entries++; |
90 | |
88 | |
91 | } |
89 | } |
92 | (void) closedir (dp); |
90 | (void) closedir (dp); |
93 | |
91 | |
… | |
… | |
108 | * 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. |
109 | * Otherwise, it tries to match the difficulty given with a style |
107 | * Otherwise, it tries to match the difficulty given with a style |
110 | * file, named style_name_# where # is an integer |
108 | * file, named style_name_# where # is an integer |
111 | */ |
109 | */ |
112 | |
110 | |
113 | /* remove extern, so visible to command_style_map_info function */ |
|
|
114 | maptile *styles = NULL; |
|
|
115 | |
|
|
116 | |
|
|
117 | maptile * |
111 | maptile * |
118 | load_style_map (char *style_name) |
112 | load_style_map (char *style_name) |
119 | { |
113 | { |
120 | maptile *style_map; |
114 | maptile *style_map = maptile::find_map (style_name, 0); |
121 | |
115 | style_map->load (); |
122 | /* Given a file. See if its in memory */ |
|
|
123 | for (style_map = styles; style_map != NULL; style_map = style_map->next) |
|
|
124 | { |
|
|
125 | if (!strcmp (style_name, style_map->path)) |
|
|
126 | return style_map; |
|
|
127 | } |
|
|
128 | style_map = load_original_map (style_name, MAP_STYLE); |
|
|
129 | /* Remove it from global list, put it on our local list */ |
|
|
130 | if (style_map) |
|
|
131 | { |
|
|
132 | maptile *tmp; |
|
|
133 | |
|
|
134 | if (style_map == first_map) |
|
|
135 | first_map = style_map->next; |
|
|
136 | else |
|
|
137 | { |
|
|
138 | for (tmp = first_map; tmp && tmp->next != style_map; tmp = tmp->next); |
|
|
139 | if (tmp) |
|
|
140 | tmp->next = style_map->next; |
|
|
141 | } |
|
|
142 | style_map->next = styles; |
|
|
143 | styles = style_map; |
|
|
144 | } |
|
|
145 | return style_map; |
116 | return style_map; |
146 | } |
117 | } |
147 | |
118 | |
148 | maptile * |
119 | maptile * |
149 | find_style (const char *dirname, const char *stylename, int difficulty) |
120 | find_style (const char *dirname, const char *stylename, int difficulty) |
… | |
… | |
247 | } |
218 | } |
248 | return style_map; |
219 | return style_map; |
249 | |
220 | |
250 | } |
221 | } |
251 | |
222 | |
252 | |
|
|
253 | /* picks a random object from a style map. |
223 | /* picks a random object from a style map. |
254 | * 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 |
255 | * variables to generate tables. |
225 | * variables to generate tables. |
256 | */ |
226 | */ |
257 | object * |
227 | object * |
… | |
… | |
267 | * any difference, but this seems clearer to me. |
237 | * any difference, but this seems clearer to me. |
268 | */ |
238 | */ |
269 | do |
239 | do |
270 | { |
240 | { |
271 | limit++; |
241 | limit++; |
272 | x = RANDOM () % MAP_WIDTH (style); |
242 | x = RANDOM () % style->width; |
273 | y = RANDOM () % MAP_HEIGHT (style); |
243 | y = RANDOM () % style->height; |
274 | new_obj = get_map_ob (style, x, y); |
244 | new_obj = GET_MAP_OB (style, x, y); |
275 | } |
245 | } |
276 | while (new_obj == NULL && limit < 1000); |
246 | while (new_obj == NULL && limit < 1000); |
|
|
247 | |
277 | if (new_obj->head) |
248 | if (new_obj->head) |
278 | return new_obj->head; |
249 | return new_obj->head; |
279 | else |
250 | else |
280 | return new_obj; |
251 | return new_obj; |
281 | } |
252 | } |
282 | |
253 | |
283 | |
|
|
284 | void |
|
|
285 | free_style_maps (void) |
|
|
286 | { |
|
|
287 | maptile *next; |
|
|
288 | int style_maps = 0; |
|
|
289 | |
|
|
290 | /* delete_map will try to free it from the linked list, |
|
|
291 | * but won't find it, so we need to do it ourselves |
|
|
292 | */ |
|
|
293 | while (styles) |
|
|
294 | { |
|
|
295 | next = styles->next; |
|
|
296 | delete_map (styles); |
|
|
297 | styles = next; |
|
|
298 | style_maps++; |
|
|
299 | } |
|
|
300 | LOG (llevDebug, "free_style_maps: Freed %d maps\n", style_maps); |
|
|
301 | } |
|
|