changed "http" to "https" in URLs
[rocksndiamonds.git] / src / libgame / setup.c
index 300e815d919e6f20e40ecd1f9c6bb99659ed2f77..5beaafd23eb643145386fbf9094bbf5ce913cba3 100644 (file)
@@ -4,7 +4,7 @@
 // (c) 1995-2014 by Artsoft Entertainment
 //                         Holger Schemel
 //                 info@artsoft.org
-//                 http://www.artsoft.org/
+//                 https://www.artsoft.org/
 // ----------------------------------------------------------------------------
 // setup.c
 // ============================================================================
@@ -99,6 +99,7 @@ static int token_comment_position = TOKEN_COMMENT_POSITION_DEFAULT;
 
 static SetupFileHash *artworkinfo_cache_old = NULL;
 static SetupFileHash *artworkinfo_cache_new = NULL;
+static SetupFileHash *optional_tokens_hash = NULL;
 static boolean use_artworkinfo_cache = TRUE;
 
 
@@ -1302,21 +1303,59 @@ static boolean adjustTreeGraphicsForEMC(TreeInfo *node)
 
   while (node)
   {
-    if (node->graphics_set_ecs && !setup.prefer_aga_graphics &&
-       !strEqual(node->graphics_set, node->graphics_set_ecs))
+    boolean want_ecs = (setup.prefer_aga_graphics == FALSE);
+    boolean want_aga = (setup.prefer_aga_graphics == TRUE);
+    boolean has_only_ecs = (!node->graphics_set && !node->graphics_set_aga);
+    boolean has_only_aga = (!node->graphics_set && !node->graphics_set_ecs);
+    char *graphics_set = NULL;
+
+    if (node->graphics_set_ecs && (want_ecs || has_only_ecs))
+      graphics_set = node->graphics_set_ecs;
+
+    if (node->graphics_set_aga && (want_aga || has_only_aga))
+      graphics_set = node->graphics_set_aga;
+
+    if (graphics_set && !strEqual(node->graphics_set, graphics_set))
     {
-      setString(&node->graphics_set, node->graphics_set_ecs);
+      setString(&node->graphics_set, graphics_set);
       settings_changed = TRUE;
     }
-    else if (node->graphics_set_aga && setup.prefer_aga_graphics &&
-            !strEqual(node->graphics_set, node->graphics_set_aga))
+
+    if (node->node_group != NULL)
+      settings_changed |= adjustTreeGraphicsForEMC(node->node_group);
+
+    node = node->next;
+  }
+
+  return settings_changed;
+}
+
+static boolean adjustTreeSoundsForEMC(TreeInfo *node)
+{
+  boolean settings_changed = FALSE;
+
+  while (node)
+  {
+    boolean want_default = (setup.prefer_lowpass_sounds == FALSE);
+    boolean want_lowpass = (setup.prefer_lowpass_sounds == TRUE);
+    boolean has_only_default = (!node->sounds_set && !node->sounds_set_lowpass);
+    boolean has_only_lowpass = (!node->sounds_set && !node->sounds_set_default);
+    char *sounds_set = NULL;
+
+    if (node->sounds_set_default && (want_default || has_only_default))
+      sounds_set = node->sounds_set_default;
+
+    if (node->sounds_set_lowpass && (want_lowpass || has_only_lowpass))
+      sounds_set = node->sounds_set_lowpass;
+
+    if (sounds_set && !strEqual(node->sounds_set, sounds_set))
     {
-      setString(&node->graphics_set, node->graphics_set_aga);
+      setString(&node->sounds_set, sounds_set);
       settings_changed = TRUE;
     }
 
     if (node->node_group != NULL)
-      settings_changed |= adjustTreeGraphicsForEMC(node->node_group);
+      settings_changed |= adjustTreeSoundsForEMC(node->node_group);
 
     node = node->next;
   }
@@ -2314,16 +2353,18 @@ SetupFileHash *loadSetupFileHash(char *filename)
 #define LEVELINFO_TOKEN_GRAPHICS_SET_ECS       17
 #define LEVELINFO_TOKEN_GRAPHICS_SET_AGA       18
 #define LEVELINFO_TOKEN_GRAPHICS_SET           19
-#define LEVELINFO_TOKEN_SOUNDS_SET             20
-#define LEVELINFO_TOKEN_MUSIC_SET              21
-#define LEVELINFO_TOKEN_FILENAME               22
-#define LEVELINFO_TOKEN_FILETYPE               23
-#define LEVELINFO_TOKEN_SPECIAL_FLAGS          24
-#define LEVELINFO_TOKEN_HANDICAP               25
-#define LEVELINFO_TOKEN_SKIP_LEVELS            26
-#define LEVELINFO_TOKEN_USE_EMC_TILES          27
-
-#define NUM_LEVELINFO_TOKENS                   28
+#define LEVELINFO_TOKEN_SOUNDS_SET_DEFAULT     20
+#define LEVELINFO_TOKEN_SOUNDS_SET_LOWPASS     21
+#define LEVELINFO_TOKEN_SOUNDS_SET             22
+#define LEVELINFO_TOKEN_MUSIC_SET              23
+#define LEVELINFO_TOKEN_FILENAME               24
+#define LEVELINFO_TOKEN_FILETYPE               25
+#define LEVELINFO_TOKEN_SPECIAL_FLAGS          26
+#define LEVELINFO_TOKEN_HANDICAP               27
+#define LEVELINFO_TOKEN_SKIP_LEVELS            28
+#define LEVELINFO_TOKEN_USE_EMC_TILES          29
+
+#define NUM_LEVELINFO_TOKENS                   30
 
 static LevelDirTree ldi;
 
@@ -2350,6 +2391,8 @@ static struct TokenInfo levelinfo_tokens[] =
   { 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_default,"sounds_set.default"    },
+  { TYPE_STRING,       &ldi.sounds_set_lowpass,"sounds_set.lowpass"    },
   { TYPE_STRING,       &ldi.sounds_set,        "sounds_set"            },
   { TYPE_STRING,       &ldi.music_set,         "music_set"             },
   { TYPE_STRING,       &ldi.level_filename,    "filename"              },
@@ -2381,6 +2424,15 @@ static struct TokenInfo artworkinfo_tokens[] =
   { -1,                        NULL,                   NULL                    },
 };
 
+static char *optional_tokens[] =
+{
+  "program_title",
+  "program_copyright",
+  "program_company",
+
+  NULL
+};
+
 static void setTreeInfoToDefaults(TreeInfo *ti, int type)
 {
   ti->type = type;
@@ -2430,6 +2482,8 @@ static void setTreeInfoToDefaults(TreeInfo *ti, int type)
     ti->graphics_set_ecs = NULL;
     ti->graphics_set_aga = NULL;
     ti->graphics_set = NULL;
+    ti->sounds_set_default = NULL;
+    ti->sounds_set_lowpass = NULL;
     ti->sounds_set = NULL;
     ti->music_set = NULL;
     ti->graphics_path = getStringCopy(UNDEFINED_FILENAME);
@@ -2509,6 +2563,8 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ti, TreeInfo *parent)
     ti->graphics_set_ecs = getStringCopy(parent->graphics_set_ecs);
     ti->graphics_set_aga = getStringCopy(parent->graphics_set_aga);
     ti->graphics_set = getStringCopy(parent->graphics_set);
+    ti->sounds_set_default = getStringCopy(parent->sounds_set_default);
+    ti->sounds_set_lowpass = getStringCopy(parent->sounds_set_lowpass);
     ti->sounds_set = getStringCopy(parent->sounds_set);
     ti->music_set = getStringCopy(parent->music_set);
     ti->graphics_path = getStringCopy(UNDEFINED_FILENAME);
@@ -2569,6 +2625,8 @@ static TreeInfo *getTreeInfoCopy(TreeInfo *ti)
   ti_copy->graphics_set_ecs    = getStringCopy(ti->graphics_set_ecs);
   ti_copy->graphics_set_aga    = getStringCopy(ti->graphics_set_aga);
   ti_copy->graphics_set                = getStringCopy(ti->graphics_set);
+  ti_copy->sounds_set_default  = getStringCopy(ti->sounds_set_default);
+  ti_copy->sounds_set_lowpass  = getStringCopy(ti->sounds_set_lowpass);
   ti_copy->sounds_set          = getStringCopy(ti->sounds_set);
   ti_copy->music_set           = getStringCopy(ti->music_set);
   ti_copy->graphics_path       = getStringCopy(ti->graphics_path);
@@ -2638,6 +2696,8 @@ void freeTreeInfo(TreeInfo *ti)
     checked_free(ti->graphics_set_ecs);
     checked_free(ti->graphics_set_aga);
     checked_free(ti->graphics_set);
+    checked_free(ti->sounds_set_default);
+    checked_free(ti->sounds_set_lowpass);
     checked_free(ti->sounds_set);
     checked_free(ti->music_set);
 
@@ -2907,6 +2967,16 @@ static TreeInfo *getArtworkInfoCacheEntry(LevelDirTree *level_node, int type)
   if (!use_artworkinfo_cache)
     return NULL;
 
+  if (optional_tokens_hash == NULL)
+  {
+    int i;
+
+    // create hash from list of optional tokens (for quick access)
+    optional_tokens_hash = newSetupFileHash();
+    for (i = 0; optional_tokens[i] != NULL; i++)
+      setHashEntry(optional_tokens_hash, optional_tokens[i], "");
+  }
+
   if (cached)
   {
     int i;
@@ -2918,16 +2988,28 @@ static TreeInfo *getArtworkInfoCacheEntry(LevelDirTree *level_node, int type)
     ldi = *artwork_info;
     for (i = 0; artworkinfo_tokens[i].type != -1; i++)
     {
-      char *token = getCacheToken(token_prefix, artworkinfo_tokens[i].text);
+      char *token_suffix = artworkinfo_tokens[i].text;
+      char *token = getCacheToken(token_prefix, token_suffix);
       char *value = getHashEntry(artworkinfo_cache_old, token);
+      boolean optional =
+       (getHashEntry(optional_tokens_hash, token_suffix) != NULL);
+
+      setSetupInfo(artworkinfo_tokens, i, value);
+
+      // check if cache entry for this item is mandatory, but missing
+      if (value == NULL && !optional)
+      {
+       Error(ERR_WARN, "missing cache entry '%s'", token);
 
-      // if defined, use value from cache, else keep default value
-      if (value != NULL)
-       setSetupInfo(artworkinfo_tokens, i, value);
+       cached = FALSE;
+      }
     }
 
     *artwork_info = ldi;
+  }
 
+  if (cached)
+  {
     char *filename_levelinfo = getPath2(getLevelDirFromTreeInfo(level_node),
                                        LEVELINFO_FILENAME);
     char *filename_artworkinfo = getPath2(getSetupArtworkDir(artwork_info),
@@ -3430,6 +3512,16 @@ boolean AdjustGraphicsForEMC(void)
   return settings_changed;
 }
 
+boolean AdjustSoundsForEMC(void)
+{
+  boolean settings_changed = FALSE;
+
+  settings_changed |= adjustTreeSoundsForEMC(leveldir_first_all);
+  settings_changed |= adjustTreeSoundsForEMC(leveldir_first);
+
+  return settings_changed;
+}
+
 void LoadLevelInfo(void)
 {
   InitUserLevelDirectory(getLoginName());
@@ -3449,6 +3541,7 @@ void LoadLevelInfo(void)
   cloneTree(&leveldir_first, leveldir_first_all, TRUE);
 
   AdjustGraphicsForEMC();
+  AdjustSoundsForEMC();
 
   // before sorting, the first entries will be from the user directory
   leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);