… | |
… | |
60 | int entries = 0, entry_size = 0; |
60 | int entries = 0, entry_size = 0; |
61 | char name[NAME_MAX + 1], **rn = NULL; |
61 | char name[NAME_MAX + 1], **rn = NULL; |
62 | struct stat sb; |
62 | struct stat sb; |
63 | |
63 | |
64 | dp = opendir (dir); |
64 | dp = opendir (dir); |
65 | if (dp == NULL) |
65 | if (!dp) |
66 | return -1; |
66 | return -1; |
67 | |
67 | |
68 | while ((d = readdir (dp)) != NULL) |
68 | while ((d = readdir (dp))) |
69 | { |
69 | { |
70 | sprintf (name, "%s/%s", dir, d->d_name); |
70 | sprintf (name, "%s/%s", dir, d->d_name); |
71 | if (skip_dirs) |
71 | if (skip_dirs) |
72 | { |
72 | { |
73 | stat (name, &sb); |
73 | stat (name, &sb); |
74 | if (S_ISDIR (sb.st_mode)) |
74 | if (S_ISDIR (sb.st_mode)) |
75 | { |
|
|
76 | continue; |
75 | continue; |
77 | } |
|
|
78 | } |
76 | } |
79 | |
77 | |
80 | if (entries == entry_size) |
78 | if (entries == entry_size) |
81 | { |
79 | { |
82 | entry_size += 10; |
80 | entry_size += 10; |
… | |
… | |
108 | sprintf (style_file_path, "%s/%s", dirname, stylename); |
106 | sprintf (style_file_path, "%s/%s", dirname, stylename); |
109 | else /* otherwise, just use the dirname. We'll pick a random stylefile. */ |
107 | else /* otherwise, just use the dirname. We'll pick a random stylefile. */ |
110 | sprintf (style_file_path, "%s", dirname); |
108 | sprintf (style_file_path, "%s", dirname); |
111 | |
109 | |
112 | /* is what we were given a directory, or a file? */ |
110 | /* is what we were given a directory, or a file? */ |
113 | sprintf (style_file_full_path, "%s/maps%s", settings.datadir, style_file_path); |
111 | sprintf (style_file_full_path, "%s/maps%s.map", settings.datadir, style_file_path); |
114 | |
112 | |
115 | if (stat (style_file_full_path, &file_stat) == 0 && !S_ISDIR (file_stat.st_mode)) |
113 | if (stat (style_file_full_path, &file_stat) == 0 && !S_ISDIR (file_stat.st_mode)) |
116 | style_map = maptile::find_sync (style_file_path); |
114 | style_map = maptile::find_sync (style_file_path); |
117 | |
115 | |
118 | if (!style_map) /* maybe we were given a directory! */ |
116 | if (!style_map) /* maybe we were given a directory! */ |
… | |
… | |
148 | if (only_subdirs) |
146 | if (only_subdirs) |
149 | style_map = 0; |
147 | style_map = 0; |
150 | else |
148 | else |
151 | { |
149 | { |
152 | strcat (style_file_path, "/"); |
150 | strcat (style_file_path, "/"); |
153 | strcat (style_file_path, namelist[RANDOM () % n]); |
151 | strcat (style_file_path, namelist[rndm (n)]); |
154 | style_map = maptile::find_sync (style_file_path); |
152 | style_map = maptile::find_sync (style_file_path); |
155 | } |
153 | } |
156 | } |
154 | } |
157 | else |
155 | else |
158 | { /* find the map closest in difficulty */ |
156 | { /* find the map closest in difficulty */ |
… | |
… | |
166 | if ((mfile_name - 1) == NULL) |
164 | if ((mfile_name - 1) == NULL) |
167 | { /* since there isn't a sequence, */ |
165 | { /* since there isn't a sequence, */ |
168 | int q; |
166 | int q; |
169 | |
167 | |
170 | /*pick one at random to recurse */ |
168 | /*pick one at random to recurse */ |
171 | style_map = find_style (style_file_path, namelist[RANDOM () % n], difficulty); |
169 | style_map = find_style (style_file_path, namelist[rndm (n)], difficulty); |
172 | for (q = 0; q < n; q++) |
170 | for (q = 0; q < n; q++) |
173 | free (namelist[q]); |
171 | free (namelist[q]); |
174 | free (namelist); |
172 | free (namelist); |
175 | return style_map; |
173 | return style_map; |
176 | } |
174 | } |
… | |
… | |
221 | * Change the logic on getting the random space - shouldn't make |
219 | * Change the logic on getting the random space - shouldn't make |
222 | * any difference, but this seems clearer to me. |
220 | * any difference, but this seems clearer to me. |
223 | */ |
221 | */ |
224 | for (int i = 1000; --i;) |
222 | for (int i = 1000; --i;) |
225 | { |
223 | { |
226 | object *new_obj = style->at (RANDOM () % style->width, RANDOM () % style->height).bot; |
224 | object *new_obj = style->at (rndm (style->width), rndm (style->height)).bot; |
227 | |
225 | |
228 | if (new_obj) |
226 | if (new_obj) |
229 | return new_obj->head_ (); |
227 | return new_obj->head_ (); |
230 | } |
228 | } |
231 | |
229 | |