renamed function
[rocksndiamonds.git] / src / init.c
index 39f5c347156d682106bfe79d0f6da337eaea99b5..b0ed61da0998f84cb9ba1e7a6032fd0b3e71dfda 100644 (file)
@@ -157,10 +157,6 @@ inline void InitElementSmallImagesScaledUp(int graphic)
 
   // create small and game tile sized bitmaps (and scale up, if needed)
   CreateImageWithSmallImages(graphic, g->scale_up_factor, g->tile_size);
-
-  // default (standard sized) bitmap may have changed now -- update it
-  if (g->bitmaps)
-    g->bitmap = g->bitmaps[IMG_BITMAP_STANDARD];
 }
 
 void InitElementSmallImages()
@@ -214,6 +210,17 @@ void InitScaledImages()
     ScaleImage(i, graphic_info[i].scale_up_factor);
 }
 
+void InitBitmapPointers()
+{
+  int num_images = getImageListSize();
+  int i;
+
+  // standard size bitmap may have changed -- update default bitmap pointer
+  for (i = 0; i < num_images; i++)
+    if (graphic_info[i].bitmaps)
+      graphic_info[i].bitmap = graphic_info[i].bitmaps[IMG_BITMAP_STANDARD];
+}
+
 #if 1
 /* !!! FIX THIS (CHANGE TO USING NORMAL ELEMENT GRAPHIC DEFINITIONS) !!! */
 void SetBitmaps_EM(Bitmap **em_bitmap)
@@ -953,13 +960,36 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type)
   {
     char *value = getHashEntry(element_token_hash, value_raw);
 
+    if (value == NULL)
+    {
+      Error(ERR_INFO_LINE, "-");
+      Error(ERR_INFO, "warning: error found in config file:");
+      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
+      Error(ERR_INFO, "error: invalid element token '%s'", value_raw);
+      Error(ERR_INFO, "custom graphic rejected for this element/action");
+      Error(ERR_INFO, "fallback done to undefined element for this graphic");
+      Error(ERR_INFO_LINE, "-");
+    }
+
     return (value != NULL ? atoi(value) : EL_UNDEFINED);
   }
   else if (type == TYPE_GRAPHIC)
   {
     char *value = getHashEntry(graphic_token_hash, value_raw);
+    int fallback_graphic = IMG_CHAR_EXCLAM;
 
-    return (value != NULL ? atoi(value) : IMG_UNDEFINED);
+    if (value == NULL)
+    {
+      Error(ERR_INFO_LINE, "-");
+      Error(ERR_INFO, "warning: error found in config file:");
+      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
+      Error(ERR_INFO, "error: invalid graphic token '%s'", value_raw);
+      Error(ERR_INFO, "custom graphic rejected for this element/action");
+      Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
+      Error(ERR_INFO_LINE, "-");
+    }
+
+    return (value != NULL ? atoi(value) : fallback_graphic);
   }
 
   return -1;
@@ -1895,6 +1925,8 @@ static void ReinitializeGraphics()
   print_timestamp_time("InitElementSmallImages");
   InitScaledImages();                  /* scale all other images, if needed */
   print_timestamp_time("InitScaledImages");
+  InitBitmapPointers();                        /* set standard size bitmap pointers */
+  print_timestamp_time("InitBitmapPointers");
   InitFontGraphicInfo();               /* initialize text drawing functions */
   print_timestamp_time("InitFontGraphicInfo");
 
@@ -4446,6 +4478,33 @@ static void InitGlobal()
                 font_info[i].token_name,
                 int2str(i, 0));
 
+  /* set default filenames for all cloned graphics in static configuration */
+  for (i = 0; image_config[i].token != NULL; i++)
+  {
+    if (strEqual(image_config[i].value, UNDEFINED_FILENAME))
+    {
+      char *token = image_config[i].token;
+      char *token_clone_from = getStringCat2(token, ".clone_from");
+      char *token_cloned = getHashEntry(image_config_hash, token_clone_from);
+
+      if (token_cloned != NULL)
+      {
+       char *value_cloned = getHashEntry(image_config_hash, token_cloned);
+
+       if (value_cloned != NULL)
+       {
+         /* set default filename in static configuration */
+         image_config[i].value = value_cloned;
+
+         /* set default filename in image config hash */
+         setHashEntry(image_config_hash, token, value_cloned);
+       }
+      }
+
+      free(token_clone_from);
+    }
+  }
+
   /* always start with reliable default values (all elements) */
   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
     ActiveElement[i] = i;
@@ -4675,6 +4734,12 @@ void Execute_Command(char *command)
       Error(ERR_EXIT, "image target directory '%s' not found or not writable",
            global.create_images_dir);
   }
+  else if (strPrefix(command, "create CE image "))
+  {
+    CreateCustomElementImages(&command[16]);
+
+    exit(0);
+  }
 
 #if DEBUG
 #if defined(TARGET_SDL2)
@@ -4955,6 +5020,9 @@ void InitGfxBuffers()
   InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
   InitGfxClipRegion(FALSE, -1, -1, -1, -1);
 
+  /* required if door size definitions have changed */
+  InitGraphicCompatibilityInfo_Doors();
+
   InitGfxBuffers_EM();
   InitGfxBuffers_SP();
 }
@@ -5007,6 +5075,7 @@ void InitGfx()
 
   InitGfxBuffers();
   InitGfxCustomArtworkInfo();
+  InitGfxOtherSettings();
 
   bitmap_font_initial = LoadCustomImage(filename_font_initial);
 
@@ -5090,7 +5159,7 @@ void InitGfx()
   init_last = init;
 }
 
-void RedrawBackground()
+void RedrawGlobalBorder()
 {
   BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
             0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
@@ -5507,7 +5576,7 @@ void ReloadCustomArtwork(int force_reload)
 
   FadeOut(REDRAW_ALL);
 
-  RedrawBackground();
+  RedrawGlobalBorder();
 
   /* force redraw of (open or closed) door graphics */
   SetDoorState(DOOR_OPEN_ALL);
@@ -5604,6 +5673,10 @@ void OpenAll()
 
   print_timestamp_time("[init global stuff]");
 
+  InitSetup();
+
+  print_timestamp_time("[init setup/config stuff (1)]");
+
   if (options.execute_command)
     Execute_Command(options.execute_command);
 
@@ -5618,10 +5691,6 @@ void OpenAll()
     exit(0);                   /* never reached, server loops forever */
   }
 
-  InitSetup();
-
-  print_timestamp_time("[init setup/config stuff (1)]");
-
   InitGameInfo();
   print_timestamp_time("[init setup/config stuff (2)]");
   InitPlayerInfo();