rnd-20030304-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index 3e3f5b7164983b24de30c8e0c7f5eb411be6628d..b6ec4fda6353c2494c1c15f0eeca311ea6733887 100644 (file)
@@ -537,6 +537,11 @@ void GetOptions(char *argv[])
   options.verbose = FALSE;
   options.debug = FALSE;
 
+#if !defined(PLATFORM_UNIX)
+  if (*options_left == NULL)   /* no options given -- enable verbose mode */
+    options.verbose = TRUE;
+#endif
+
   while (*options_left)
   {
     char option_str[MAX_OPTION_LEN];
@@ -1507,12 +1512,78 @@ boolean FileIsArtworkType(char *basename, int type)
 /* functions for loading artwork configuration information                   */
 /* ------------------------------------------------------------------------- */
 
-int get_parameter_value(int type, char *value)
+/* This function checks if a string <s> of the format "string1, string2, ..."
+   exactly contains a string <s_contained>. */
+
+static boolean string_has_parameter(char *s, char *s_contained)
+{
+  char *substring;
+
+  if (s == NULL || s_contained == NULL)
+    return FALSE;
+
+  if (strlen(s_contained) > strlen(s))
+    return FALSE;
+
+  if (strncmp(s, s_contained, strlen(s_contained)) == 0)
+  {
+    char next_char = s[strlen(s_contained)];
+
+    /* check if next character is delimiter or whitespace */
+    return (next_char == ',' || next_char == '\0' ||
+           next_char == ' ' || next_char == '\t' ? TRUE : FALSE);
+  }
+
+  /* check if string contains another parameter string after a comma */
+  substring = strchr(s, ',');
+  if (substring == NULL)       /* string does not contain a comma */
+    return FALSE;
+
+  /* advance string pointer to next character after the comma */
+  substring++;
+
+  /* skip potential whitespaces after the comma */
+  while (*substring == ' ' || *substring == '\t')
+    substring++;
+
+  return string_has_parameter(substring, s_contained);
+}
+
+int get_parameter_value(char *token, char *value_raw, int type)
 {
-  return (strcmp(value, ARG_UNDEFINED) == 0 ? ARG_UNDEFINED_VALUE :
-         type == TYPE_INTEGER ? get_integer_from_string(value) :
-         type == TYPE_BOOLEAN ? get_boolean_from_string(value) :
-         ARG_UNDEFINED_VALUE);
+  char *value = getStringToLower(value_raw);
+  int result = 0;      /* probably a save default value */
+
+  if (strcmp(token, ".direction") == 0)
+  {
+    result = (strcmp(value, "left")  == 0 ? MV_LEFT :
+             strcmp(value, "right") == 0 ? MV_RIGHT :
+             strcmp(value, "up")    == 0 ? MV_UP :
+             strcmp(value, "down")  == 0 ? MV_DOWN : MV_NO_MOVING);
+  }
+  else if (strcmp(token, ".anim_mode") == 0)
+  {
+    result = (string_has_parameter(value, "loop")      ? ANIM_LOOP :
+             string_has_parameter(value, "linear")    ? ANIM_LINEAR :
+             string_has_parameter(value, "pingpong")  ? ANIM_PINGPONG :
+             string_has_parameter(value, "pingpong2") ? ANIM_PINGPONG2 :
+             string_has_parameter(value, "random")    ? ANIM_RANDOM :
+             ANIM_LOOP);
+
+    if (string_has_parameter(value, "reverse"))
+      result |= ANIM_REVERSE;
+  }
+  else         /* generic parameter of type integer or boolean */
+  {
+    result = (strcmp(value, ARG_UNDEFINED) == 0 ? ARG_UNDEFINED_VALUE :
+             type == TYPE_INTEGER ? get_integer_from_string(value) :
+             type == TYPE_BOOLEAN ? get_boolean_from_string(value) :
+             ARG_UNDEFINED_VALUE);
+  }
+
+  free(value);
+
+  return result;
 }
 
 static void FreeCustomArtworkList(struct ArtworkListInfo *,
@@ -1579,6 +1650,11 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list,
       }
     }
 
+    /* the following tokens are no file definitions, but other config tokens */
+    if (strcmp(config_list[i].token, "global.num_toons") == 0 ||
+       strcmp(config_list[i].token, "menu.main.hide_static_text") == 0)
+      is_file_entry = FALSE;
+
     if (is_file_entry)
     {
       if (i > 0)
@@ -1745,12 +1821,14 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info)
   char **ext1_suffixes = artwork_info->ext1_suffixes;
   char **ext2_suffixes = artwork_info->ext2_suffixes;
   char **ext3_suffixes = artwork_info->ext3_suffixes;
+  char **ignore_tokens = artwork_info->ignore_tokens;
   int num_file_list_entries = artwork_info->num_file_list_entries;
   int num_suffix_list_entries = artwork_info->num_suffix_list_entries;
   int num_base_prefixes = artwork_info->num_base_prefixes;
   int num_ext1_suffixes = artwork_info->num_ext1_suffixes;
   int num_ext2_suffixes = artwork_info->num_ext2_suffixes;
   int num_ext3_suffixes = artwork_info->num_ext3_suffixes;
+  int num_ignore_tokens = artwork_info->num_ignore_tokens;
   char *filename = getCustomArtworkConfigFilename(artwork_info->type);
   struct SetupFileList *setup_file_list;
   struct SetupFileList *extra_file_list = NULL;
@@ -1809,9 +1887,9 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info)
   for (i=0; i<num_file_list_entries; i++)
     read_token_parameters(setup_file_list, suffix_list, &file_list[i]);
 
-  /* set all known tokens to "known" keyword */
-  setTokenValue(setup_file_list, "name", known_token_value);
-  setTokenValue(setup_file_list, "sort_priority", known_token_value);
+  /* set all tokens that can be ignored here to "known" keyword */
+  for (i=0; i < num_ignore_tokens; i++)
+    setTokenValue(setup_file_list, ignore_tokens[i], known_token_value);
 
   /* copy all unknown config file tokens to extra config list */
   for (list = setup_file_list; list != NULL; list = list->next)