rnd-20071020-1-src
[rocksndiamonds.git] / src / init.c
index c41af9fb25ba1cdb4aeec37f96f9eea2226db704..6ef48aee97da2ced884db8f8a24a540967fe1740 100644 (file)
@@ -201,24 +201,41 @@ void DrawInitAnim()
   y = WIN_YSIZE / 2 - TILESIZE / 2;
 #endif
 
+  graphic_info = &anim_initial;                /* graphic == 0 => anim_initial */
+
 #if 0
   {
     static boolean done = FALSE;
 
-    if (!done)
-      printf("::: %d, %d, %d, %d => %d, %d\n",
+    // if (!done)
+      printf("::: %d, %d, %d, %d => %d, %d [%d, %d] [%d, %d]\n",
             init.busy.x, init.busy.y,
             init.busy.align, init.busy.valign,
-            x, y);
+            x, y,
+            graphic_info[graphic].width,
+            graphic_info[graphic].height,
+            sync_frame, anim_initial.anim_delay);
 
     done = TRUE;
   }
 #endif
 
-  graphic_info = &anim_initial;                /* graphic == 0 => anim_initial */
-
   if (sync_frame % anim_initial.anim_delay == 0)
+  {
+#if 1
+    Bitmap *src_bitmap;
+    int src_x, src_y;
+    int width = graphic_info[graphic].width;
+    int height = graphic_info[graphic].height;
+    int frame = getGraphicAnimationFrame(graphic, sync_frame);
+
+    getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
+    BlitBitmap(src_bitmap, window, src_x, src_y, width, height, x, y);
+#else
+    /* !!! this can only draw TILEX/TILEY size animations !!! */
     DrawGraphicAnimationExt(window, x, y, graphic, sync_frame, NO_MASKING);
+#endif
+  }
 
   graphic_info = graphic_info_last;
 
@@ -1237,9 +1254,10 @@ static int get_scaled_graphic_height(int graphic)
   return original_height * scale_up_factor;
 }
 
-static void set_graphic_parameters_ext(int graphic, struct GraphicInfo *g,
-                                      int *parameter, Bitmap *src_bitmap)
+static void set_graphic_parameters_ext(int graphic, int *parameter,
+                                      Bitmap *src_bitmap)
 {
+  struct GraphicInfo *g = &graphic_info[graphic];
   int anim_frames_per_row = 1, anim_frames_per_col = 1;
   int anim_frames_per_line = 1;
 
@@ -1323,6 +1341,13 @@ static void set_graphic_parameters_ext(int graphic, struct GraphicInfo *g,
     int src_image_width  = get_scaled_graphic_width(graphic);
     int src_image_height = get_scaled_graphic_height(graphic);
 
+    if (src_image_width == 0 || src_image_height == 0)
+    {
+      /* only happens when loaded outside artwork system (like "global.busy") */
+      src_image_width  = src_bitmap->width;
+      src_image_height = src_bitmap->height;
+    }
+
     anim_frames_per_row = src_image_width  / g->width;
     anim_frames_per_col = src_image_height / g->height;
 
@@ -1485,8 +1510,7 @@ static void set_graphic_parameters(int graphic)
                                               image_config_suffix[i].token,
                                               image_config_suffix[i].type);
 
-  set_graphic_parameters_ext(graphic, &graphic_info[graphic],
-                            parameter, src_bitmap);
+  set_graphic_parameters_ext(graphic, parameter, src_bitmap);
 
 #else
 
@@ -5360,11 +5384,13 @@ static void InitArtworkConfig()
 static void InitMixer()
 {
   OpenAudio();
+
   StartMixer();
 }
 
 void InitGfx()
 {
+  struct GraphicInfo *graphic_info_last = graphic_info;
   char *filename_font_initial = NULL;
   char *filename_anim_initial = NULL;
   Bitmap *bitmap_font_initial = NULL;
@@ -5413,6 +5439,7 @@ void InitGfx()
   bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
   bitmap_db_panel = CreateBitmap(DXSIZE, DYSIZE, DEFAULT_DEPTH);
   bitmap_db_door  = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
+  bitmap_db_toons = CreateBitmap(FULL_SXSIZE, FULL_SYSIZE, DEFAULT_DEPTH);
 
   /* initialize screen properties */
   InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
@@ -5421,6 +5448,7 @@ void InitGfx()
   InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
   InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
   InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
+  InitGfxCustomArtworkInfo();
 
   bitmap_font_initial = LoadCustomImage(filename_font_initial);
 
@@ -5496,13 +5524,38 @@ void InitGfx()
     }
   }
 
-  set_graphic_parameters_ext(0, &anim_initial, parameter, NULL);
+#if defined(CREATE_SPECIAL_EDITION_RND_JUE)
+  filename_anim_initial = "loading.pcx";
+
+  parameter[GFX_ARG_X] = 0;
+  parameter[GFX_ARG_Y] = 0;
+  parameter[GFX_ARG_WIDTH] = 128;
+  parameter[GFX_ARG_HEIGHT] = 40;
+  parameter[GFX_ARG_FRAMES] = 32;
+  parameter[GFX_ARG_DELAY] = 4;
+  parameter[GFX_ARG_FRAMES_PER_LINE] = ARG_UNDEFINED_VALUE;
+#endif
 
   if (filename_anim_initial == NULL)   /* should not happen */
     Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_GLOBAL_BUSY);
 
   anim_initial.bitmap = LoadCustomImage(filename_anim_initial);
 
+  graphic_info = &anim_initial;                /* graphic == 0 => anim_initial */
+
+  set_graphic_parameters_ext(0, parameter, anim_initial.bitmap);
+
+#if 0
+  printf("::: INIT_GFX: anim_frames_per_line == %d [%d / %d] [%d, %d]\n",
+        graphic_info[0].anim_frames_per_line,
+        get_scaled_graphic_width(0),
+        graphic_info[0].width,
+        getOriginalImageWidthFromImageID(0),
+        graphic_info[0].scale_up_factor);
+#endif
+
+  graphic_info = graphic_info_last;
+
   init.busy.width  = anim_initial.width;
   init.busy.height = anim_initial.height;
 
@@ -5549,7 +5602,7 @@ static void InitLevelInfo()
   LoadLevelSetup_SeriesInfo();                 /* last played level info */
 }
 
-void InitLevelArtworkInfo()
+static void InitLevelArtworkInfo()
 {
   LoadLevelArtworkInfo();
 }
@@ -5558,8 +5611,30 @@ static void InitImages()
 {
   print_timestamp_init("InitImages");
 
+#if 0
+  printf("::: leveldir_current->identifier == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
+  printf("::: leveldir_current->graphics_path == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
+  printf("::: leveldir_current->graphics_set == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
+  printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS));
+#endif
+
   setLevelArtworkDir(artwork.gfx_first);
 
+#if 0
+  printf("::: leveldir_current->identifier == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
+  printf("::: leveldir_current->graphics_path == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
+  printf("::: leveldir_current->graphics_set == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
+  printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS));
+#endif
+
 #if 0
   printf("::: InitImages for '%s' ['%s', '%s'] ['%s', '%s']\n",
         leveldir_current->identifier,
@@ -5655,6 +5730,124 @@ void InitNetworkServer()
 #endif
 }
 
+static boolean CheckArtworkConfigForCustomElements(char *filename)
+{
+  SetupFileHash *setup_file_hash;
+  boolean redefined_ce_found = FALSE;
+
+  /* !!! CACHE THIS BY USING HASH 'filename' => 'true/false' !!! */
+
+  if ((setup_file_hash = loadSetupFileHash(filename)) != NULL)
+  {
+    BEGIN_HASH_ITERATION(setup_file_hash, itr)
+    {
+      char *token = HASH_ITERATION_TOKEN(itr);
+
+      if (strPrefix(token, "custom_"))
+      {
+       redefined_ce_found = TRUE;
+
+       break;
+      }
+    }
+    END_HASH_ITERATION(setup_file_hash, itr)
+
+    freeSetupFileHash(setup_file_hash);
+  }
+
+  return redefined_ce_found;
+}
+
+static boolean CheckArtworkTypeForRedefinedCustomElements(int type)
+{
+  char *filename_base, *filename_local;
+  boolean redefined_ce_found = FALSE;
+
+  setLevelArtworkDir(ARTWORK_FIRST_NODE(artwork, type));
+
+#if 0
+  printf("::: leveldir_current->identifier == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
+  printf("::: leveldir_current->graphics_path == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
+  printf("::: leveldir_current->graphics_set == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
+  printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n",
+        leveldir_current == NULL ? "[NULL]" :
+        LEVELDIR_ARTWORK_SET(leveldir_current, type));
+#endif
+
+  /* first look for special artwork configured in level series config */
+  filename_base = getCustomArtworkLevelConfigFilename(type);
+
+#if 0
+  printf("::: filename_base == '%s'\n", filename_base);
+#endif
+
+  if (fileExists(filename_base))
+    redefined_ce_found |= CheckArtworkConfigForCustomElements(filename_base);
+
+  filename_local = getCustomArtworkConfigFilename(type);
+
+#if 0
+  printf("::: filename_local == '%s'\n", filename_local);
+#endif
+
+  if (filename_local != NULL && !strEqual(filename_base, filename_local))
+    redefined_ce_found |= CheckArtworkConfigForCustomElements(filename_local);
+
+#if 0
+  printf("::: redefined_ce_found == %d\n", redefined_ce_found);
+#endif
+
+  return redefined_ce_found;
+}
+
+static void InitOverrideArtwork()
+{
+  boolean redefined_ce_found = FALSE;
+
+  /* to check if this level set redefines any CEs, do not use overriding */
+  gfx.override_level_graphics = FALSE;
+  gfx.override_level_sounds   = FALSE;
+  gfx.override_level_music    = FALSE;
+
+  /* now check if this level set has definitions for custom elements */
+  if (setup.override_level_graphics == AUTO ||
+      setup.override_level_sounds   == AUTO ||
+      setup.override_level_music    == AUTO)
+    redefined_ce_found =
+      (CheckArtworkTypeForRedefinedCustomElements(ARTWORK_TYPE_GRAPHICS) |
+       CheckArtworkTypeForRedefinedCustomElements(ARTWORK_TYPE_SOUNDS) |
+       CheckArtworkTypeForRedefinedCustomElements(ARTWORK_TYPE_MUSIC));
+
+#if 0
+  printf("::: redefined_ce_found == %d\n", redefined_ce_found);
+#endif
+
+  if (redefined_ce_found)
+  {
+    /* this level set has CE definitions: change "AUTO" to "FALSE" */
+    gfx.override_level_graphics = (setup.override_level_graphics == TRUE);
+    gfx.override_level_sounds   = (setup.override_level_sounds   == TRUE);
+    gfx.override_level_music    = (setup.override_level_music    == TRUE);
+  }
+  else
+  {
+    /* this level set has no CE definitions: change "AUTO" to "TRUE" */
+    gfx.override_level_graphics = (setup.override_level_graphics != FALSE);
+    gfx.override_level_sounds   = (setup.override_level_sounds   != FALSE);
+    gfx.override_level_music    = (setup.override_level_music    != FALSE);
+  }
+
+#if 0
+  printf("::: => %d, %d, %d\n",
+        gfx.override_level_graphics,
+        gfx.override_level_sounds,
+        gfx.override_level_music);
+#endif
+}
+
 static char *getNewArtworkIdentifier(int type)
 {
   static char *leveldir_current_identifier[3] = { NULL, NULL, NULL };
@@ -5662,7 +5855,11 @@ static char *getNewArtworkIdentifier(int type)
   static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE };
   static boolean initialized[3] = { FALSE, FALSE, FALSE };
   TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type);
+#if 1
+  boolean setup_override_artwork = GFX_OVERRIDE_ARTWORK(type);
+#else
   boolean setup_override_artwork = SETUP_OVERRIDE_ARTWORK(setup, type);
+#endif
   char *setup_artwork_set = SETUP_ARTWORK_SET(setup, type);
   char *leveldir_identifier = leveldir_current->identifier;
 #if 1
@@ -5779,6 +5976,8 @@ void ReloadCustomArtwork(int force_reload)
   boolean force_reload_mus = (force_reload & (1 << ARTWORK_TYPE_MUSIC));
   boolean reload_needed;
 
+  InitOverrideArtwork();
+
   force_reload_gfx |= AdjustGraphicsForEMC();
 
   gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS);
@@ -5951,6 +6150,9 @@ void OpenAll()
   InitLevelArtworkInfo();
   print_timestamp_time("InitLevelArtworkInfo");
 
+  InitOverrideArtwork();       /* needs to know current level directory */
+  print_timestamp_time("InitOverrideArtwork");
+
   InitImages();                        /* needs to know current level directory */
   print_timestamp_time("InitImages");