rnd-20030730-1-src
[rocksndiamonds.git] / src / init.c
index dfd97f5ef2df5dca82cb92c99c2de7ae27158fd4..b4ce8d8917ea41515eba64d48d05e5f17048ca1b 100644 (file)
@@ -645,7 +645,7 @@ static void set_graphic_parameters(int graphic, char **parameter_raw)
     anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
   }
 
-  /* correct x or y offset dependant of vertical or horizontal frame order */
+  /* correct x or y offset dependent of vertical or horizontal frame order */
   if (parameter[GFX_ARG_VERTICAL])     /* frames are ordered vertically */
   {
     graphic_info[graphic].offset_y =
@@ -754,6 +754,16 @@ static void InitGraphicInfo()
     int src_x, src_y;
     int first_frame, last_frame;
 
+#if 0
+    printf("::: image: '%s'\n", image->token);
+#endif
+
+#if 0
+    printf("::: image # %d: '%s' ['%s']\n",
+          i, image->token,
+          getTokenFromImageID(i));
+#endif
+
     set_graphic_parameters(i, image->parameter);
 
     /* now check if no animation frames are outside of the loaded image */
@@ -966,8 +976,10 @@ static void set_sound_parameters(int sound, char **parameter_raw)
 
 static void InitSoundInfo()
 {
+#if 0
   struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
   int num_property_mappings = getSoundListPropertyMappingSize();
+#endif
   int *sound_effect_properties;
   int num_sounds = getSoundListSize();
   int i, j;
@@ -991,6 +1003,10 @@ static void InitSoundInfo()
     sound_effect_properties[i] = ACTION_OTHER;
     sound_info[i].loop = FALSE;
 
+#if 0
+    printf("::: sound %d: '%s'\n", i, sound->token);
+#endif
+
     /* determine all loop sounds and identify certain sound classes */
 
     for (j=0; element_action_info[j].suffix; j++)
@@ -1002,12 +1018,17 @@ static void InitSoundInfo()
                 element_action_info[j].suffix) == 0)
       {
        sound_effect_properties[i] = element_action_info[j].value;
+       sound_info[i].loop = element_action_info[j].is_loop_sound;
 
-       if (element_action_info[j].is_loop_sound)
-         sound_info[i].loop = TRUE;
+       break;
       }
     }
 
+#if 0
+    if (strcmp(sound->token, "custom_42") == 0)
+      printf("::: '%s' -> %d\n", sound->token, sound_info[i].loop);
+#endif
+
     /* associate elements and some selected sound actions */
 
     for (j=0; j<MAX_NUM_ELEMENTS; j++)
@@ -1033,6 +1054,8 @@ static void InitSoundInfo()
 
   free(sound_effect_properties);
 
+#if 0
+  /* !!! now handled in InitElementSoundInfo() !!! */
   /* initialize element/sound mapping from dynamic configuration */
   for (i=0; i < num_property_mappings; i++)
   {
@@ -1043,8 +1066,12 @@ static void InitSoundInfo()
     if (action < 0)
       action = ACTION_DEFAULT;
 
+    printf("::: %d: %d, %d, %d ['%s']\n",
+          i, element, action, sound, element_info[element].token_name);
+
     element_info[element].sound[action] = sound;
   }
+#endif
 
 #if 0
   /* TEST ONLY */
@@ -1526,6 +1553,9 @@ void InitElementPropertiesStatic()
     EL_GATE_2_GRAY,
     EL_GATE_3_GRAY,
     EL_GATE_4_GRAY,
+    EL_PENGUIN,
+    EL_PIG,
+    EL_DRAGON,
     -1
   };
 
@@ -2518,7 +2548,7 @@ void InitElementPropertiesEngine(int engine_version)
   InitElementPropertiesStatic();
 #endif
 
-  /* set all special, combined or engine dependant element properties */
+  /* set all special, combined or engine dependent element properties */
   for (i=0; i < MAX_NUM_ELEMENTS; i++)
   {
 #if 0
@@ -2617,7 +2647,7 @@ void InitElementPropertiesEngine(int engine_version)
     /* ---------- CAN_EXPLODE ---------------------------------------------- */
     SET_PROPERTY(i, EP_CAN_EXPLODE, (CAN_EXPLODE_BY_FIRE(i) ||
                                     CAN_EXPLODE_SMASHED(i) ||
-                                    CAN_EXPLODE_BY_FIRE(i)));
+                                    CAN_EXPLODE_IMPACT(i)));
   }
 
 #if 0
@@ -2746,7 +2776,7 @@ void Execute_Command(char *command)
     if (access(filename, F_OK) != 0)
       Error(ERR_EXIT, "cannot open file '%s'", filename);
 
-    LoadLevelFromFilename(filename);
+    LoadLevelFromFilename(&level, filename);
     DumpLevel(&level);
 
     exit(0);
@@ -3030,6 +3060,18 @@ void InitLevelArtworkInfo()
 
 static void InitImages()
 {
+#if 1
+  setLevelArtworkDir(artwork.gfx_first);
+#endif
+
+#if 0
+  printf("::: InitImages ['%s', '%s'] ['%s', '%s']\n",
+        artwork.gfx_current_identifier,
+        artwork.gfx_current->identifier,
+        leveldir_current->graphics_set,
+        leveldir_current->graphics_path);
+#endif
+
   ReloadCustomImages();
 
   LoadCustomElementDescriptions();
@@ -3040,12 +3082,16 @@ static void InitImages()
 
 static void InitSound()
 {
+  setLevelArtworkDir(artwork.snd_first);
+
   InitReloadCustomSounds(artwork.snd_current->identifier);
   ReinitializeSounds();
 }
 
 static void InitMusic()
 {
+  setLevelArtworkDir(artwork.mus_first);
+
   InitReloadCustomMusic(artwork.mus_current->identifier);
   ReinitializeMusic();
 }
@@ -3079,14 +3125,28 @@ void ReloadCustomArtwork()
   static boolean last_override_level_graphics = FALSE;
   static boolean last_override_level_sounds = FALSE;
   static boolean last_override_level_music = FALSE;
+  static boolean last_own_level_graphics_set = FALSE;
+  static boolean last_own_level_sounds_set = FALSE;
+  static boolean last_own_level_music_set = FALSE;
+  boolean level_graphics_set_changed = FALSE;
+  boolean level_sounds_set_changed = FALSE;
+  boolean level_music_set_changed = FALSE;
   /* identifier for new artwork; default: artwork configured in setup */
+#if 0
   char *gfx_new_identifier = artwork.gfx_current->identifier;
   char *snd_new_identifier = artwork.snd_current->identifier;
   char *mus_new_identifier = artwork.mus_current->identifier;
+#else
+  char *gfx_new_identifier = artwork.gfx_current_identifier;
+  char *snd_new_identifier = artwork.snd_current_identifier;
+  char *mus_new_identifier = artwork.mus_current_identifier;
+#endif
   boolean redraw_screen = FALSE;
 
+#if 0
   if (leveldir_current_identifier == NULL)
     leveldir_current_identifier = leveldir_current->identifier;
+#endif
 
 #if 0
   printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
@@ -3110,27 +3170,72 @@ void ReloadCustomArtwork()
 
   /* when a new level series was selected, check if there was a change
      in custom artwork stored in level series directory */
-  if (leveldir_current_identifier != leveldir_current->identifier)
+  if (1 || leveldir_current_identifier != leveldir_current->identifier)
   {
+#if 0
     char *identifier_old = leveldir_current_identifier;
+#endif
     char *identifier_new = leveldir_current->identifier;
 
-    if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
-       getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
+#if 0
+    printf("::: 1: ['%s'] '%s', '%s' [%lx, %lx]\n",
+          gfx_new_identifier, identifier_old, identifier_new,
+          getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old),
+          getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new));
+#endif
+
+#if 0
+    if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new) == NULL)
+      gfx_new_identifier = GRAPHICS_SUBDIR;
+    else if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
+            getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
+      gfx_new_identifier = identifier_new;
+#else
+    if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
       gfx_new_identifier = identifier_new;
-    if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
-       getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
+    else
+      gfx_new_identifier = setup.graphics_set;
+#endif
+
+#if 0
+    if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_new) == NULL)
+      snd_new_identifier = SOUNDS_SUBDIR;
+    else if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
+            getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
       snd_new_identifier = identifier_new;
-    if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
-       getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
+#else
+    if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
+      snd_new_identifier = identifier_new;
+    else
+      snd_new_identifier = setup.sounds_set;
+#endif
+
+#if 0
+    if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) == NULL)
+      mus_new_identifier = MUSIC_SUBDIR;
+    else if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
+            getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
       mus_new_identifier = identifier_new;
+#else
+    if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
+      mus_new_identifier = identifier_new;
+    else
+      mus_new_identifier = setup.music_set;
+#endif
+
+#if 0
+    printf("::: 2: ['%s'] '%s', '%s'\n",
+          gfx_new_identifier, identifier_old, identifier_new);
+#endif
 
+#if 0
     leveldir_current_identifier = leveldir_current->identifier;
+#endif
   }
 
   /* custom level artwork configured in level series configuration file
      always overrides custom level artwork stored in level series directory
-     and (level independant) custom artwork configured in setup menue */
+     and (level independent) custom artwork configured in setup menu */
   if (leveldir_current->graphics_set != NULL)
     gfx_new_identifier = leveldir_current->graphics_set;
   if (leveldir_current->sounds_set != NULL)
@@ -3138,33 +3243,99 @@ void ReloadCustomArtwork()
   if (leveldir_current->music_set != NULL)
     mus_new_identifier = leveldir_current->music_set;
 
+  if (leveldir_current_identifier != leveldir_current->identifier)
+  {
+    if (last_own_level_graphics_set || leveldir_current->graphics_set != NULL)
+      level_graphics_set_changed = TRUE;
+
+    if (last_own_level_sounds_set || leveldir_current->sounds_set != NULL)
+      level_sounds_set_changed = TRUE;
+
+    if (last_own_level_music_set || leveldir_current->music_set != NULL)
+      level_music_set_changed = TRUE;
+
+    last_own_level_graphics_set = (leveldir_current->graphics_set != NULL);
+    last_own_level_sounds_set = (leveldir_current->sounds_set != NULL);
+    last_own_level_music_set = (leveldir_current->music_set != NULL);
+  }
+
+#if 1
+  leveldir_current_identifier = leveldir_current->identifier;
+#endif
+
+  if (setup.override_level_graphics)
+    gfx_new_identifier = artwork.gfx_current->identifier;
+  if (setup.override_level_sounds)
+    snd_new_identifier = artwork.snd_current->identifier;
+  if (setup.override_level_music)
+    mus_new_identifier = artwork.mus_current->identifier;
+
+
+#if 0
+  printf("CHECKING OLD/NEW GFX:\n  OLD: '%s'\n  NEW: '%s' ['%s', '%s'] [%d]\n",
+        artwork.gfx_current_identifier, gfx_new_identifier,
+        artwork.gfx_current->identifier, leveldir_current->graphics_set,
+        level_graphics_set_changed);
+#endif
+
   if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
-      last_override_level_graphics != setup.override_level_graphics)
+      last_override_level_graphics != setup.override_level_graphics ||
+      level_graphics_set_changed)
   {
 #if 0
-    printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
+    printf("RELOADING GRAPHICS '%s' -> '%s' ['%s']\n",
           artwork.gfx_current_identifier,
-          artwork.gfx_current->identifier,
-          gfx_new_identifier);
+          gfx_new_identifier,
+          artwork.gfx_current->identifier);
 #endif
 
+#if 0
+    artwork.gfx_current =
+      getTreeInfoFromIdentifier(artwork.gfx_first, gfx_new_identifier);
+#endif
+#if 0
+    artwork.gfx_current_identifier = gfx_new_identifier;
+#endif
+
+#if 0
     setLevelArtworkDir(artwork.gfx_first);
+#endif
 
     ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
 
     InitImages();
 
+#if 0
+    printf("::: %d\n", menu.list_size[GAME_MODE_LEVELS]);
+#endif
+
     FreeTileClipmasks();
     InitTileClipmasks();
+#if 0
+    artwork.gfx_current =
+      getTreeInfoFromIdentifier(artwork.gfx_first, gfx_new_identifier);
+#endif
+#if 0
+    printf("::: '%s', %lx\n", gfx_new_identifier, artwork.gfx_current);
+#endif
 
+#if 0
     artwork.gfx_current_identifier = artwork.gfx_current->identifier;
+#endif
+    artwork.gfx_current_identifier = gfx_new_identifier;
     last_override_level_graphics = setup.override_level_graphics;
 
+#if 0
+    printf("DONE RELOADING GFX: '%s' ['%s']\n",
+          artwork.gfx_current_identifier, artwork.gfx_current->identifier);
+#endif
+
     redraw_screen = TRUE;
   }
 
   if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
-      last_override_level_sounds != setup.override_level_sounds)
+      last_override_level_sounds != setup.override_level_sounds ||
+      level_sounds_set_changed)
   {
 #if 0
     printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
@@ -3176,25 +3347,40 @@ void ReloadCustomArtwork()
     /* set artwork path to send it to the sound server process */
     setLevelArtworkDir(artwork.snd_first);
 
+    ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
     InitReloadCustomSounds(snd_new_identifier);
     ReinitializeSounds();
 
+#if 0
+    artwork.snd_current =
+      getTreeInfoFromIdentifier(artwork.snd_first, setup.sounds_set);
     artwork.snd_current_identifier = artwork.snd_current->identifier;
+#endif
+    artwork.snd_current_identifier = snd_new_identifier;
     last_override_level_sounds = setup.override_level_sounds;
 
     redraw_screen = TRUE;
   }
 
   if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
-      last_override_level_music != setup.override_level_music)
+      last_override_level_music != setup.override_level_music ||
+      level_music_set_changed)
   {
     /* set artwork path to send it to the sound server process */
     setLevelArtworkDir(artwork.mus_first);
 
+    ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
     InitReloadCustomMusic(mus_new_identifier);
     ReinitializeMusic();
 
+#if 0
+    artwork.mus_current =
+      getTreeInfoFromIdentifier(artwork.mus_first, setup.music_set);
     artwork.mus_current_identifier = artwork.mus_current->identifier;
+#endif
+    artwork.mus_current_identifier = mus_new_identifier;
     last_override_level_music = setup.override_level_music;
 
     redraw_screen = TRUE;
@@ -3295,7 +3481,7 @@ void CloseAllAndExit(int exit_value)
   FreeTileClipmasks();
 
   CloseVideoDisplay();
-  ClosePlatformDependantStuff();
+  ClosePlatformDependentStuff();
 
   exit(exit_value);
 }