42 #include "../include/autoconf.h"
54 const char *s1 = *(
const char *
const *)p1;
55 const char *s2 = *(
const char *
const *)p2;
57 return(strcmp(s1, s2));
83 int load_dir(
const char *dir,
char ***namelist,
int skip_dirs) {
86 int entries = 0, entry_size = 0;
94 while ((d =
readdir(dp)) != NULL) {
103 if (entries == entry_size) {
105 rn = realloc(rn,
sizeof(
char *)*entry_size);
135 for (style_map = styles; style_map != NULL; style_map = style_map->
next) {
136 if (!strcmp(style_name, style_map->
path))
178 char style_file_path[256];
179 char style_file_full_path[256];
181 struct stat file_stat;
182 int i, only_subdirs = 0;
185 if (stylename && strlen(stylename) > 0)
186 snprintf(style_file_path,
sizeof(style_file_path),
"%s/%s", dirname, stylename);
188 snprintf(style_file_path,
sizeof(style_file_path),
"%s", dirname);
192 if (stat(style_file_full_path, &file_stat) == 0
193 && !
S_ISDIR(file_stat.st_mode)) {
196 if (style_map == NULL) {
199 char style_dir_full_path[256];
207 n =
load_dir(style_dir_full_path, &namelist, 1);
209 n =
load_dir(style_dir_full_path, &namelist, 0);
221 if (difficulty == -1) {
225 strncat(style_file_path,
"/",
sizeof(style_file_path));
226 strncat(style_file_path, namelist[RANDOM()%n],
sizeof(style_file_path));
230 int min_dist = 32000, min_index = -1;
232 for (i = 0; i < n; i++) {
234 char *mfile_name = strrchr(namelist[i],
'_')+1;
236 if ((mfile_name-1) == NULL) {
240 style_map =
find_style(style_file_path, namelist[RANDOM()%n], difficulty);
241 for (q = 0; q < n; q++)
246 dist = abs(difficulty-atoi(mfile_name));
247 if (dist < min_dist) {
255 strncat(style_file_path,
"/",
sizeof(style_file_path));
256 strncat(style_file_path, namelist[min_index],
sizeof(style_file_path));
259 for (i = 0; i < n; i++)
290 }
while (new_obj == NULL && limit < 1000);
292 return new_obj->
head;
313 LOG(
llevDebug,
"free_style_maps: Freed %d maps\n", style_maps);
DIR * opendir(const char *)
mapstruct * load_original_map(const char *filename, int flags)
static int pointer_strcmp(const void *p1, const void *p2)
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
int load_dir(const char *dir, char ***namelist, int skip_dirs)
char d_name[_MAX_FNAME+1]
char * strdup_local(const char *str)
object * pick_random_object(mapstruct *style)
mapstruct * load_style_map(char *style_name)
int snprintf(char *dest, int max, const char *format,...)
struct dirent * readdir(DIR *)
void delete_map(mapstruct *m)
#define GET_MAP_OB(M, X, Y)
void LOG(LogLevel logLevel, const char *format,...)
EXTERN mapstruct * first_map
void free_style_maps(void)