rnd-20060407-2-src
[rocksndiamonds.git] / src / libgame / setup.c
index 3ff575d19d7d2a10e9230384e386899e95bce5b7..a004bc82fda34659823eb1b50811b43d578098a4 100644 (file)
@@ -917,7 +917,7 @@ TreeInfo *getTreeInfoFromIdentifier(TreeInfo *node, char *identifier)
     }
     else if (!node->parent_link)
     {
-      if (strcmp(identifier, node->identifier) == 0)
+      if (strEqual(identifier, node->identifier))
        return node;
     }
 
@@ -964,6 +964,34 @@ void cloneTree(TreeInfo **ti_new, TreeInfo *ti, boolean skip_empty_sets)
   *ti_new = ti_cloned;
 }
 
+static boolean adjustTreeGraphicsForEMC(TreeInfo *node)
+{
+  boolean settings_changed = FALSE;
+
+  while (node)
+  {
+    if (node->graphics_set_ecs && !setup.prefer_aga_graphics &&
+       !strEqual(node->graphics_set, node->graphics_set_ecs))
+    {
+      setString(&node->graphics_set, node->graphics_set_ecs);
+      settings_changed = TRUE;
+    }
+    else if (node->graphics_set_aga && setup.prefer_aga_graphics &&
+            !strEqual(node->graphics_set, node->graphics_set_aga))
+    {
+      setString(&node->graphics_set, node->graphics_set_aga);
+      settings_changed = TRUE;
+    }
+
+    if (node->node_group != NULL)
+      settings_changed |= adjustTreeGraphicsForEMC(node->node_group);
+
+    node = node->next;
+  }
+
+  return settings_changed;
+}
+
 void dumpTreeInfo(TreeInfo *node, int depth)
 {
   int i;
@@ -1100,7 +1128,7 @@ char *getCommonDataDir(void)
     char *dir = checked_malloc(MAX_PATH + 1);
 
     if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, dir))
-       && strcmp(dir, "") != 0)        /* empty for Windows 95/98 */
+       && !strEqual(dir, ""))          /* empty for Windows 95/98 */
       common_data_dir = getPath2(dir, program.userdata_directory);
     else
       common_data_dir = options.rw_base_directory;
@@ -1281,7 +1309,7 @@ char *getListEntry(SetupFileList *list, char *token)
   if (list == NULL)
     return NULL;
 
-  if (strcmp(list->token, token) == 0)
+  if (strEqual(list->token, token))
     return list->value;
   else
     return getListEntry(list->next, token);
@@ -1292,7 +1320,7 @@ SetupFileList *setListEntry(SetupFileList *list, char *token, char *value)
   if (list == NULL)
     return NULL;
 
-  if (strcmp(list->token, token) == 0)
+  if (strEqual(list->token, token))
   {
     checked_free(list->value);
 
@@ -1374,7 +1402,7 @@ static unsigned int get_hash_from_key(void *key)
 
 static int keys_are_equal(void *key1, void *key2)
 {
-  return (strcmp((char *)key1, (char *)key2) == 0);
+  return (strEqual((char *)key1, (char *)key2));
 }
 
 SetupFileHash *newSetupFileHash()
@@ -1605,57 +1633,61 @@ void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash,
 /* setup file stuff                                                          */
 /* ========================================================================= */
 
-#define TOKEN_STR_LAST_LEVEL_SERIES    "last_level_series"
-#define TOKEN_STR_LAST_PLAYED_LEVEL    "last_played_level"
-#define TOKEN_STR_HANDICAP_LEVEL       "handicap_level"
+#define TOKEN_STR_LAST_LEVEL_SERIES            "last_level_series"
+#define TOKEN_STR_LAST_PLAYED_LEVEL            "last_played_level"
+#define TOKEN_STR_HANDICAP_LEVEL               "handicap_level"
 
 /* level directory info */
-#define LEVELINFO_TOKEN_IDENTIFIER     0
-#define LEVELINFO_TOKEN_NAME           1
-#define LEVELINFO_TOKEN_NAME_SORTING   2
-#define LEVELINFO_TOKEN_AUTHOR         3
-#define LEVELINFO_TOKEN_IMPORTED_FROM  4
-#define LEVELINFO_TOKEN_IMPORTED_BY    5
-#define LEVELINFO_TOKEN_LEVELS         6
-#define LEVELINFO_TOKEN_FIRST_LEVEL    7
-#define LEVELINFO_TOKEN_SORT_PRIORITY  8
-#define LEVELINFO_TOKEN_LATEST_ENGINE  9
-#define LEVELINFO_TOKEN_LEVEL_GROUP    10
-#define LEVELINFO_TOKEN_READONLY       11
-#define LEVELINFO_TOKEN_GRAPHICS_SET   12
-#define LEVELINFO_TOKEN_SOUNDS_SET     13
-#define LEVELINFO_TOKEN_MUSIC_SET      14
-#define LEVELINFO_TOKEN_FILENAME       15
-#define LEVELINFO_TOKEN_FILETYPE       16
-#define LEVELINFO_TOKEN_HANDICAP       17
-#define LEVELINFO_TOKEN_SKIP_LEVELS    18
-
-#define NUM_LEVELINFO_TOKENS           19
+#define LEVELINFO_TOKEN_IDENTIFIER             0
+#define LEVELINFO_TOKEN_NAME                   1
+#define LEVELINFO_TOKEN_NAME_SORTING           2
+#define LEVELINFO_TOKEN_AUTHOR                 3
+#define LEVELINFO_TOKEN_IMPORTED_FROM          4
+#define LEVELINFO_TOKEN_IMPORTED_BY            5
+#define LEVELINFO_TOKEN_LEVELS                 6
+#define LEVELINFO_TOKEN_FIRST_LEVEL            7
+#define LEVELINFO_TOKEN_SORT_PRIORITY          8
+#define LEVELINFO_TOKEN_LATEST_ENGINE          9
+#define LEVELINFO_TOKEN_LEVEL_GROUP            10
+#define LEVELINFO_TOKEN_READONLY               11
+#define LEVELINFO_TOKEN_GRAPHICS_SET_ECS       12
+#define LEVELINFO_TOKEN_GRAPHICS_SET_AGA       13
+#define LEVELINFO_TOKEN_GRAPHICS_SET           14
+#define LEVELINFO_TOKEN_SOUNDS_SET             15
+#define LEVELINFO_TOKEN_MUSIC_SET              16
+#define LEVELINFO_TOKEN_FILENAME               17
+#define LEVELINFO_TOKEN_FILETYPE               18
+#define LEVELINFO_TOKEN_HANDICAP               19
+#define LEVELINFO_TOKEN_SKIP_LEVELS            20
+
+#define NUM_LEVELINFO_TOKENS                   21
 
 static LevelDirTree ldi;
 
 static struct TokenInfo levelinfo_tokens[] =
 {
   /* level directory info */
-  { TYPE_STRING,       &ldi.identifier,        "identifier"    },
-  { TYPE_STRING,       &ldi.name,              "name"          },
-  { TYPE_STRING,       &ldi.name_sorting,      "name_sorting"  },
-  { TYPE_STRING,       &ldi.author,            "author"        },
-  { TYPE_STRING,       &ldi.imported_from,     "imported_from" },
-  { TYPE_STRING,       &ldi.imported_by,       "imported_by"   },
-  { TYPE_INTEGER,      &ldi.levels,            "levels"        },
-  { TYPE_INTEGER,      &ldi.first_level,       "first_level"   },
-  { TYPE_INTEGER,      &ldi.sort_priority,     "sort_priority" },
-  { TYPE_BOOLEAN,      &ldi.latest_engine,     "latest_engine" },
-  { TYPE_BOOLEAN,      &ldi.level_group,       "level_group"   },
-  { TYPE_BOOLEAN,      &ldi.readonly,          "readonly"      },
-  { TYPE_STRING,       &ldi.graphics_set,      "graphics_set"  },
-  { TYPE_STRING,       &ldi.sounds_set,        "sounds_set"    },
-  { TYPE_STRING,       &ldi.music_set,         "music_set"     },
-  { TYPE_STRING,       &ldi.level_filename,    "filename"      },
-  { TYPE_STRING,       &ldi.level_filetype,    "filetype"      },
-  { TYPE_BOOLEAN,      &ldi.handicap,          "handicap"      },
-  { TYPE_BOOLEAN,      &ldi.skip_levels,       "skip_levels"   }
+  { TYPE_STRING,       &ldi.identifier,        "identifier"            },
+  { TYPE_STRING,       &ldi.name,              "name"                  },
+  { TYPE_STRING,       &ldi.name_sorting,      "name_sorting"          },
+  { TYPE_STRING,       &ldi.author,            "author"                },
+  { TYPE_STRING,       &ldi.imported_from,     "imported_from"         },
+  { TYPE_STRING,       &ldi.imported_by,       "imported_by"           },
+  { TYPE_INTEGER,      &ldi.levels,            "levels"                },
+  { TYPE_INTEGER,      &ldi.first_level,       "first_level"           },
+  { TYPE_INTEGER,      &ldi.sort_priority,     "sort_priority"         },
+  { TYPE_BOOLEAN,      &ldi.latest_engine,     "latest_engine"         },
+  { TYPE_BOOLEAN,      &ldi.level_group,       "level_group"           },
+  { TYPE_BOOLEAN,      &ldi.readonly,          "readonly"              },
+  { TYPE_STRING,       &ldi.graphics_set_ecs,  "graphics_set.ecs"      },
+  { TYPE_STRING,       &ldi.graphics_set_aga,  "graphics_set.aga"      },
+  { TYPE_STRING,       &ldi.graphics_set,      "graphics_set"          },
+  { TYPE_STRING,       &ldi.sounds_set,        "sounds_set"            },
+  { TYPE_STRING,       &ldi.music_set,         "music_set"             },
+  { TYPE_STRING,       &ldi.level_filename,    "filename"              },
+  { TYPE_STRING,       &ldi.level_filetype,    "filetype"              },
+  { TYPE_BOOLEAN,      &ldi.handicap,          "handicap"              },
+  { TYPE_BOOLEAN,      &ldi.skip_levels,       "skip_levels"           }
 };
 
 static void setTreeInfoToDefaults(TreeInfo *ldi, int type)
@@ -1696,6 +1728,8 @@ static void setTreeInfoToDefaults(TreeInfo *ldi, int type)
     ldi->imported_from = NULL;
     ldi->imported_by = NULL;
 
+    ldi->graphics_set_ecs = NULL;
+    ldi->graphics_set_aga = NULL;
     ldi->graphics_set = NULL;
     ldi->sounds_set = NULL;
     ldi->music_set = NULL;
@@ -1761,6 +1795,8 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ldi, TreeInfo *parent)
     ldi->imported_from = getStringCopy(parent->imported_from);
     ldi->imported_by = getStringCopy(parent->imported_by);
 
+    ldi->graphics_set_ecs = NULL;
+    ldi->graphics_set_aga = NULL;
     ldi->graphics_set = NULL;
     ldi->sounds_set = NULL;
     ldi->music_set = NULL;
@@ -1800,6 +1836,8 @@ static void freeTreeInfo(TreeInfo *ldi)
     checked_free(ldi->imported_from);
     checked_free(ldi->imported_by);
 
+    checked_free(ldi->graphics_set_ecs);
+    checked_free(ldi->graphics_set_aga);
     checked_free(ldi->graphics_set);
     checked_free(ldi->sounds_set);
     checked_free(ldi->music_set);
@@ -1972,7 +2010,7 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first,
                 getHashEntry(setup_file_hash, levelinfo_tokens[i].text));
   *leveldir_new = ldi;
 
-  if (strcmp(leveldir_new->name, ANONYMOUS_NAME) == 0)
+  if (strEqual(leveldir_new->name, ANONYMOUS_NAME))
     setString(&leveldir_new->name, leveldir_new->subdir);
 
   DrawInitText(leveldir_new->name, 150, FC_YELLOW);
@@ -2003,14 +2041,14 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first,
     leveldir_new->first_level + leveldir_new->levels - 1;
 
   leveldir_new->in_user_dir =
-    (strcmp(leveldir_new->basepath, options.level_directory) != 0);
+    (!strEqual(leveldir_new->basepath, options.level_directory));
 
   /* adjust some settings if user's private level directory was detected */
   if (leveldir_new->sort_priority == LEVELCLASS_UNDEFINED &&
       leveldir_new->in_user_dir &&
-      (strcmp(leveldir_new->subdir, getLoginName()) == 0 ||
-       strcmp(leveldir_new->name,   getLoginName()) == 0 ||
-       strcmp(leveldir_new->author, getRealName())  == 0))
+      (strEqual(leveldir_new->subdir, getLoginName()) ||
+       strEqual(leveldir_new->name,   getLoginName()) ||
+       strEqual(leveldir_new->author, getRealName())))
   {
     leveldir_new->sort_priority = LEVELCLASS_PRIVATE_START;
     leveldir_new->readonly = FALSE;
@@ -2084,8 +2122,8 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first,
     char *directory_path = getPath2(level_directory, directory_name);
 
     /* skip entries for current and parent directory */
-    if (strcmp(directory_name, ".")  == 0 ||
-       strcmp(directory_name, "..") == 0)
+    if (strEqual(directory_name, ".") ||
+       strEqual(directory_name, ".."))
     {
       free(directory_path);
       continue;
@@ -2101,9 +2139,9 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first,
 
     free(directory_path);
 
-    if (strcmp(directory_name, GRAPHICS_DIRECTORY) == 0 ||
-       strcmp(directory_name, SOUNDS_DIRECTORY) == 0 ||
-       strcmp(directory_name, MUSIC_DIRECTORY) == 0)
+    if (strEqual(directory_name, GRAPHICS_DIRECTORY) ||
+       strEqual(directory_name, SOUNDS_DIRECTORY) ||
+       strEqual(directory_name, MUSIC_DIRECTORY))
       continue;
 
     valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent,
@@ -2126,6 +2164,16 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first,
          level_directory);
 }
 
+boolean AdjustGraphicsForEMC()
+{
+  boolean settings_changed = FALSE;
+
+  settings_changed |= adjustTreeGraphicsForEMC(leveldir_first_all);
+  settings_changed |= adjustTreeGraphicsForEMC(leveldir_first);
+
+  return settings_changed;
+}
+
 void LoadLevelInfo()
 {
   InitUserLevelDirectory(getLoginName());
@@ -2144,6 +2192,8 @@ void LoadLevelInfo()
   cloneTree(&leveldir_first, leveldir_first_all, TRUE);
 #endif
 
+  AdjustGraphicsForEMC();
+
   /* before sorting, the first entries will be from the user directory */
   leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
 
@@ -2195,7 +2245,7 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
 
     if (!valid_file_found)
     {
-      if (strcmp(directory_name, ".") != 0)
+      if (!strEqual(directory_name, "."))
        Error(ERR_WARN, "ignoring artwork directory '%s'", directory_path);
 
       free(directory_path);
@@ -2227,7 +2277,7 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
                   getHashEntry(setup_file_hash, levelinfo_tokens[i].text));
     *artwork_new = ldi;
 
-    if (strcmp(artwork_new->name, ANONYMOUS_NAME) == 0)
+    if (strEqual(artwork_new->name, ANONYMOUS_NAME))
       setString(&artwork_new->name, artwork_new->subdir);
 
 #if 0
@@ -2253,7 +2303,7 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
   }
 
   artwork_new->in_user_dir =
-    (strcmp(artwork_new->basepath, OPTIONS_ARTWORK_DIRECTORY(type)) != 0);
+    (!strEqual(artwork_new->basepath, OPTIONS_ARTWORK_DIRECTORY(type)));
 
   /* (may use ".sort_priority" from "setup_file_hash" above) */
   artwork_new->color = ARTWORKCOLOR(artwork_new);
@@ -2262,7 +2312,7 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
 
   if (setup_file_hash == NULL) /* (after determining ".user_defined") */
   {
-    if (strcmp(artwork_new->subdir, ".") == 0)
+    if (strEqual(artwork_new->subdir, "."))
     {
       if (artwork_new->user_defined)
       {
@@ -2312,8 +2362,10 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first,
 
   if ((dir = opendir(base_directory)) == NULL)
   {
+    /* display error if directory is main "options.graphics_directory" etc. */
     if (base_directory == OPTIONS_ARTWORK_DIRECTORY(type))
       Error(ERR_WARN, "cannot read directory '%s'", base_directory);
+
     return;
   }
 
@@ -2323,15 +2375,15 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first,
     char *directory_name = dir_entry->d_name;
     char *directory_path = getPath2(base_directory, directory_name);
 
-    /* skip entries for current and parent directory */
-    if (strcmp(directory_name, ".")  == 0 ||
-       strcmp(directory_name, "..") == 0)
+    /* skip directory entries for current and parent directory */
+    if (strEqual(directory_name, ".") ||
+       strEqual(directory_name, ".."))
     {
       free(directory_path);
       continue;
     }
 
-    /* find out if directory entry is itself a directory */
+    /* skip directory entries which are not a directory or are not accessible */
     if (stat(directory_path, &file_status) != 0 ||     /* cannot stat file */
        (file_status.st_mode & S_IFMT) != S_IFDIR)      /* not a directory */
     {
@@ -2342,7 +2394,7 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first,
     free(directory_path);
 
     /* check if this directory contains artwork with or without config file */
-    valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent,
+    valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first, node_parent,
                                                        base_directory,
                                                        directory_name, type);
   }
@@ -2350,7 +2402,7 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first,
   closedir(dir);
 
   /* check if this directory directly contains artwork itself */
-  valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent,
+  valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first, node_parent,
                                                      base_directory, ".",
                                                      type);
   if (!valid_entry_found)
@@ -2461,12 +2513,12 @@ void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
 
   while (level_node)
   {
-    char *path = getPath2(getLevelDirFromTreeInfo(level_node),
-                         ARTWORK_DIRECTORY((*artwork_node)->type));
-
+    /* check all tree entries for artwork, but skip parent link entries */
     if (!level_node->parent_link)
     {
       TreeInfo *topnode_last = *artwork_node;
+      char *path = getPath2(getLevelDirFromTreeInfo(level_node),
+                           ARTWORK_DIRECTORY((*artwork_node)->type));
 
       LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path,
                                    (*artwork_node)->type);
@@ -2484,9 +2536,9 @@ void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
        (*artwork_node)->sort_priority = level_node->sort_priority;
        (*artwork_node)->color = LEVELCOLOR((*artwork_node));
       }
-    }
 
-    free(path);
+      free(path);
+    }
 
     if (level_node->node_group != NULL)
       LoadArtworkInfoFromLevelInfo(artwork_node, level_node->node_group);
@@ -2505,7 +2557,7 @@ void LoadLevelArtworkInfo()
 
   /* needed for reloading level artwork not known at ealier stage */
 
-  if (strcmp(artwork.gfx_current_identifier, setup.graphics_set) != 0)
+  if (!strEqual(artwork.gfx_current_identifier, setup.graphics_set))
   {
     artwork.gfx_current =
       getTreeInfoFromIdentifier(artwork.gfx_first, setup.graphics_set);
@@ -2516,7 +2568,7 @@ void LoadLevelArtworkInfo()
       artwork.gfx_current = getFirstValidTreeInfoEntry(artwork.gfx_first);
   }
 
-  if (strcmp(artwork.snd_current_identifier, setup.sounds_set) != 0)
+  if (!strEqual(artwork.snd_current_identifier, setup.sounds_set))
   {
     artwork.snd_current =
       getTreeInfoFromIdentifier(artwork.snd_first, setup.sounds_set);
@@ -2527,7 +2579,7 @@ void LoadLevelArtworkInfo()
       artwork.snd_current = getFirstValidTreeInfoEntry(artwork.snd_first);
   }
 
-  if (strcmp(artwork.mus_current_identifier, setup.music_set) != 0)
+  if (!strEqual(artwork.mus_current_identifier, setup.music_set))
   {
     artwork.mus_current =
       getTreeInfoFromIdentifier(artwork.mus_first, setup.music_set);
@@ -2625,6 +2677,10 @@ char *getSetupValue(int type, void *value)
       strcpy(value_string, (*(boolean *)value ? "yes" : "no"));
       break;
 
+    case TYPE_ECS_AGA:
+      strcpy(value_string, (*(boolean *)value ? "AGA" : "ECS"));
+      break;
+
     case TYPE_KEY:
       strcpy(value_string, getKeyNameFromKey(*(Key *)value));
       break;
@@ -2674,8 +2730,8 @@ char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr)
     char *keyname = getKeyNameFromKey(key);
 
     /* add comment, if useful */
-    if (strcmp(keyname, "(undefined)") != 0 &&
-       strcmp(keyname, "(unknown)") != 0)
+    if (!strEqual(keyname, "(undefined)") &&
+       !strEqual(keyname, "(unknown)"))
     {
       /* add at least one whitespace */
       strcat(line, " ");
@@ -2777,7 +2833,7 @@ static void checkSeriesInfo()
   {
     if (strlen(dir_entry->d_name) > 4 &&
        dir_entry->d_name[3] == '.' &&
-       strcmp(&dir_entry->d_name[4], LEVELFILE_EXTENSION) == 0)
+       strEqual(&dir_entry->d_name[4], LEVELFILE_EXTENSION))
     {
       char levelnum_str[4];
       int levelnum_value;