added separate time counter for tape time frames
[rocksndiamonds.git] / src / files.c
index c484aceed3b0499363ebea86578bacf4ea235258..34d9f6d0b92f2e00810e63c5b799c9a5f566ebbc 100644 (file)
@@ -1771,10 +1771,12 @@ static void setLevelInfoToDefaults_Level(struct LevelInfo *level)
   setConfigToDefaultsFromConfigList(chunk_config_INFO);
   *level = li;         // copy temporary buffer back to level data
 
+  setLevelInfoToDefaults_BD();
   setLevelInfoToDefaults_EM();
   setLevelInfoToDefaults_SP();
   setLevelInfoToDefaults_MM();
 
+  level->native_bd_level = &native_bd_level;
   level->native_em_level = &native_em_level;
   level->native_sp_level = &native_sp_level;
   level->native_mm_level = &native_mm_level;
@@ -1903,8 +1905,7 @@ static void setLevelInfoToDefaults_Elements(struct LevelInfo *level)
     setElementChangeInfoToDefaults(ei->change);
 
     if (IS_CUSTOM_ELEMENT(element) ||
-       IS_GROUP_ELEMENT(element) ||
-       IS_INTERNAL_ELEMENT(element))
+       IS_GROUP_ELEMENT(element))
     {
       setElementDescriptionToDefault(ei);
 
@@ -2890,7 +2891,7 @@ static int LoadLevel_CUS3(File *file, int chunk_size, struct LevelInfo *level)
     ei->change->delay_random = getFile16BitBE(file);
     ei->change->delay_frames = getFile16BitBE(file);
 
-    ei->change->initial_trigger_element= getMappedElement(getFile16BitBE(file));
+    ei->change->initial_trigger_element = getMappedElement(getFile16BitBE(file));
 
     ei->change->explode = getFile8Bit(file);
     ei->change->use_target_content = getFile8Bit(file);
@@ -3649,6 +3650,27 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
 }
 
 
+// ----------------------------------------------------------------------------
+// functions for loading BD level
+// ----------------------------------------------------------------------------
+
+static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level)
+{
+  struct LevelInfo_BD *level_bd = level->native_bd_level;
+
+  level_bd->width  = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH);
+  level_bd->height = MIN(level->fieldy, MAX_PLAYFIELD_HEIGHT);
+}
+
+static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level)
+{
+  struct LevelInfo_BD *level_bd = level->native_bd_level;
+
+  level->fieldx = MIN(level_bd->width,  MAX_LEV_FIELDX);
+  level->fieldy = MIN(level_bd->height, MAX_LEV_FIELDY);
+}
+
+
 // ----------------------------------------------------------------------------
 // functions for loading EM level
 // ----------------------------------------------------------------------------
@@ -6322,7 +6344,9 @@ static void LoadLevelFromFileInfo_MM(struct LevelInfo *level,
 
 void CopyNativeLevel_RND_to_Native(struct LevelInfo *level)
 {
-  if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
+  if (level->game_engine_type == GAME_ENGINE_TYPE_BD)
+    CopyNativeLevel_RND_to_BD(level);
+  else if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
     CopyNativeLevel_RND_to_EM(level);
   else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
     CopyNativeLevel_RND_to_SP(level);
@@ -6332,7 +6356,9 @@ void CopyNativeLevel_RND_to_Native(struct LevelInfo *level)
 
 void CopyNativeLevel_Native_to_RND(struct LevelInfo *level)
 {
-  if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
+  if (level->game_engine_type == GAME_ENGINE_TYPE_BD)
+    CopyNativeLevel_BD_to_RND(level);
+  else if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
     CopyNativeLevel_EM_to_RND(level);
   else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
     CopyNativeLevel_SP_to_RND(level);
@@ -8134,7 +8160,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
       byte action = tape->pos[i].action[0];
       int k, num_moves = 0;
 
-      for (k = 0; k<4; k++)
+      for (k = 0; k < 4; k++)
       {
        if (action & joy_dir[k])
        {
@@ -9490,6 +9516,10 @@ static struct TokenInfo global_setup_tokens[] =
     TYPE_SWITCH,
     &setup.toons,                              "toons"
   },
+  {
+    TYPE_SWITCH,
+    &setup.global_animations,                  "global_animations"
+  },
   {
     TYPE_SWITCH,
     &setup.scroll_delay,                       "scroll_delay"
@@ -10409,6 +10439,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->sound_music = TRUE;
   si->sound_simple = TRUE;
   si->toons = TRUE;
+  si->global_animations = TRUE;
   si->scroll_delay = TRUE;
   si->forced_scroll_delay = FALSE;
   si->scroll_delay_value = STD_SCROLL_DELAY;
@@ -10585,7 +10616,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   for (i = 0; i < MAX_PLAYERS; i++)
   {
     si->input[i].use_joystick = FALSE;
-    si->input[i].joy.device_name=getStringCopy(getDeviceNameFromJoystickNr(i));
+    si->input[i].joy.device_name = getStringCopy(getDeviceNameFromJoystickNr(i));
     si->input[i].joy.xleft   = JOYSTICK_XLEFT;
     si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
     si->input[i].joy.xright  = JOYSTICK_XRIGHT;
@@ -11527,8 +11558,9 @@ static boolean string_has_parameter(char *s, char *s_contained)
     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);
+    if (next_char == ',' || next_char == '\0' ||
+       next_char == ' ' || next_char == '\t')
+      return TRUE;
   }
 
   // check if string contains another parameter string after a comma
@@ -11546,6 +11578,85 @@ static boolean string_has_parameter(char *s, char *s_contained)
   return string_has_parameter(substring, s_contained);
 }
 
+static int get_anim_parameter_value_ce(char *s)
+{
+  char *s_ptr = s;
+  char *pattern_1 = "ce_change:custom_";
+  char *pattern_2 = ".page_";
+  int pattern_1_len = strlen(pattern_1);
+  char *matching_char = strstr(s_ptr, pattern_1);
+  int result = ANIM_EVENT_NONE;
+
+  if (matching_char == NULL)
+    return ANIM_EVENT_NONE;
+
+  result = ANIM_EVENT_CE_CHANGE;
+
+  s_ptr = matching_char + pattern_1_len;
+
+  // check for custom element number ("custom_X", "custom_XX" or "custom_XXX")
+  if (*s_ptr >= '0' && *s_ptr <= '9')
+  {
+    int gic_ce_nr = (*s_ptr++ - '0');
+
+    if (*s_ptr >= '0' && *s_ptr <= '9')
+    {
+      gic_ce_nr = 10 * gic_ce_nr + (*s_ptr++ - '0');
+
+      if (*s_ptr >= '0' && *s_ptr <= '9')
+       gic_ce_nr = 10 * gic_ce_nr + (*s_ptr++ - '0');
+    }
+
+    if (gic_ce_nr < 1 || gic_ce_nr > NUM_CUSTOM_ELEMENTS)
+      return ANIM_EVENT_NONE;
+
+    // custom element stored as 0 to 255
+    gic_ce_nr--;
+
+    result |= gic_ce_nr << ANIM_EVENT_CE_BIT;
+  }
+  else
+  {
+    // invalid custom element number specified
+
+    return ANIM_EVENT_NONE;
+  }
+
+  // check for change page number ("page_X" or "page_XX") (optional)
+  if (strPrefix(s_ptr, pattern_2))
+  {
+    s_ptr += strlen(pattern_2);
+
+    if (*s_ptr >= '0' && *s_ptr <= '9')
+    {
+      int gic_page_nr = (*s_ptr++ - '0');
+
+      if (*s_ptr >= '0' && *s_ptr <= '9')
+       gic_page_nr = 10 * gic_page_nr + (*s_ptr++ - '0');
+
+      if (gic_page_nr < 1 || gic_page_nr > MAX_CHANGE_PAGES)
+       return ANIM_EVENT_NONE;
+
+      // change page stored as 1 to 32 (0 means "all change pages")
+
+      result |= gic_page_nr << ANIM_EVENT_PAGE_BIT;
+    }
+    else
+    {
+      // invalid animation part number specified
+
+      return ANIM_EVENT_NONE;
+    }
+  }
+
+  // discard result if next character is neither delimiter nor whitespace
+  if (!(*s_ptr == ',' || *s_ptr == '\0' ||
+       *s_ptr == ' ' || *s_ptr == '\t'))
+    return ANIM_EVENT_NONE;
+
+  return result;
+}
+
 static int get_anim_parameter_value(char *s)
 {
   int event_value[] =
@@ -11571,6 +11682,11 @@ static int get_anim_parameter_value(char *s)
   int result = ANIM_EVENT_NONE;
   int i;
 
+  result = get_anim_parameter_value_ce(s);
+
+  if (result != ANIM_EVENT_NONE)
+    return result;
+
   for (i = 0; i < ARRAY_SIZE(event_value); i++)
   {
     matching_char = strstr(s_ptr, pattern_1[i]);
@@ -11740,6 +11856,8 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
              strEqual(value, "lower")  ? POS_LOWER :
              strEqual(value, "bottom") ? POS_BOTTOM :
              strEqual(value, "any")    ? POS_ANY :
+             strEqual(value, "ce")     ? POS_CE :
+             strEqual(value, "ce_trigger") ? POS_CE_TRIGGER :
              strEqual(value, "last")   ? POS_LAST : POS_UNDEFINED);
   }
   else if (strEqual(suffix, ".align"))
@@ -11773,6 +11891,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
              string_has_parameter(value, "centered")   ? ANIM_CENTERED :
              string_has_parameter(value, "all")        ? ANIM_ALL :
              string_has_parameter(value, "tiled")      ? ANIM_TILED :
+             string_has_parameter(value, "level_nr")   ? ANIM_LEVEL_NR :
              ANIM_DEFAULT);
 
     if (string_has_parameter(value, "once"))
@@ -11829,11 +11948,16 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
 
     if (string_has_parameter(value, "multiple_actions"))
       result |= STYLE_MULTIPLE_ACTIONS;
+
+    if (string_has_parameter(value, "consume_ce_event"))
+      result |= STYLE_CONSUME_CE_EVENT;
   }
   else if (strEqual(suffix, ".fade_mode"))
   {
     result = (string_has_parameter(value, "none")      ? FADE_MODE_NONE :
              string_has_parameter(value, "fade")       ? FADE_MODE_FADE :
+             string_has_parameter(value, "fade_in")    ? FADE_MODE_FADE_IN :
+             string_has_parameter(value, "fade_out")   ? FADE_MODE_FADE_OUT :
              string_has_parameter(value, "crossfade")  ? FADE_MODE_CROSSFADE :
              string_has_parameter(value, "melt")       ? FADE_MODE_MELT :
              string_has_parameter(value, "curtain")    ? FADE_MODE_CURTAIN :
@@ -12345,9 +12469,9 @@ static void InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics(void)
   }
 }
 
-static void InitMenuDesignSettings_PreviewPlayers_FromHash(SetupFileHash *hash)
+static void InitMenuDesignSettings_PreviewPlayers_Ext(SetupFileHash *hash,
+                                                      boolean initialize)
 {
-
   // special case: check if network and preview player positions are redefined,
   // to compare this later against the main menu level preview being redefined
   struct TokenIntPtrInfo menu_config_players[] =
@@ -12361,12 +12485,27 @@ static void InitMenuDesignSettings_PreviewPlayers_FromHash(SetupFileHash *hash)
   };
   int i;
 
-  for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
-    *menu_config_players[i].value = FALSE;
+  if (initialize)
+  {
+    for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
+      *menu_config_players[i].value = FALSE;
+  }
+  else
+  {
+    for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
+      if (getHashEntry(hash, menu_config_players[i].token) != NULL)
+        *menu_config_players[i].value = TRUE;
+  }
+}
 
-  for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
-    if (getHashEntry(hash, menu_config_players[i].token) != NULL)
-      *menu_config_players[i].value = TRUE;
+static void InitMenuDesignSettings_PreviewPlayers(void)
+{
+  InitMenuDesignSettings_PreviewPlayers_Ext(NULL, TRUE);
+}
+
+static void InitMenuDesignSettings_PreviewPlayers_FromHash(SetupFileHash *hash)
+{
+  InitMenuDesignSettings_PreviewPlayers_Ext(hash, FALSE);
 }
 
 static void LoadMenuDesignSettingsFromFilename(char *filename)
@@ -12710,12 +12849,12 @@ static void LoadMenuDesignSettingsFromFilename(char *filename)
     }
   }
 
-  // special case: check if network and preview player positions are redefined
-  InitMenuDesignSettings_PreviewPlayers_FromHash(setup_file_hash);
-
   // read (and overwrite with) values that may be specified in config file
   InitMenuDesignSettings_FromHash(setup_file_hash, TRUE);
 
+  // special case: check if network and preview player positions are redefined
+  InitMenuDesignSettings_PreviewPlayers_FromHash(setup_file_hash);
+
   freeSetupFileHash(setup_file_hash);
 }
 
@@ -12725,6 +12864,7 @@ void LoadMenuDesignSettings(void)
 
   InitMenuDesignSettings_Static();
   InitMenuDesignSettings_SpecialPreProcessing();
+  InitMenuDesignSettings_PreviewPlayers();
 
   if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_GRAPHICS))
   {
@@ -12748,6 +12888,65 @@ void LoadMenuDesignSettings_AfterGraphics(void)
   InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics();
 }
 
+void InitSoundSettings_FromHash(SetupFileHash *setup_file_hash,
+                               boolean ignore_defaults)
+{
+  int i;
+
+  for (i = 0; sound_config_vars[i].token != NULL; i++)
+  {
+    char *value = getHashEntry(setup_file_hash, sound_config_vars[i].token);
+
+    // (ignore definitions set to "[DEFAULT]" which are already initialized)
+    if (ignore_defaults && strEqual(value, ARG_DEFAULT))
+      continue;
+
+    if (value != NULL)
+      *sound_config_vars[i].value =
+       get_token_parameter_value(sound_config_vars[i].token, value);
+  }
+}
+
+void InitSoundSettings_Static(void)
+{
+  // always start with reliable default values from static default config
+  InitSoundSettings_FromHash(sound_config_hash, FALSE);
+}
+
+static void LoadSoundSettingsFromFilename(char *filename)
+{
+  SetupFileHash *setup_file_hash;
+
+  if ((setup_file_hash = loadSetupFileHash(filename)) == NULL)
+    return;
+
+  // read (and overwrite with) values that may be specified in config file
+  InitSoundSettings_FromHash(setup_file_hash, TRUE);
+
+  freeSetupFileHash(setup_file_hash);
+}
+
+void LoadSoundSettings(void)
+{
+  char *filename_base = UNDEFINED_FILENAME, *filename_local;
+
+  InitSoundSettings_Static();
+
+  if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_SOUNDS))
+  {
+    // first look for special settings configured in level series config
+    filename_base = getCustomArtworkLevelConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+    if (fileExists(filename_base))
+      LoadSoundSettingsFromFilename(filename_base);
+  }
+
+  filename_local = getCustomArtworkConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+  if (filename_local != NULL && !strEqual(filename_base, filename_local))
+    LoadSoundSettingsFromFilename(filename_local);
+}
+
 void LoadUserDefinedEditorElementList(int **elements, int *num_elements)
 {
   char *filename = getEditorSetupFilename();