rnd-20041114-1-src
[rocksndiamonds.git] / src / init.c
index 0e69d6621f79242720e0a9d991e8f07dff14dab3..18eab0224ee040bd2f25189700dfea9eea29b5c2 100644 (file)
@@ -239,6 +239,11 @@ void InitGadgets()
   gadgets_initialized = TRUE;
 }
 
+inline void InitElementSmallImagesScaledUp(int graphic)
+{
+  CreateImageWithSmallImages(graphic, graphic_info[graphic].scale_up_factor);
+}
+
 void InitElementSmallImages()
 {
   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
@@ -247,17 +252,32 @@ void InitElementSmallImages()
 
   /* initialize normal images from static configuration */
   for (i = 0; element_to_graphic[i].element > -1; i++)
-    CreateImageWithSmallImages(element_to_graphic[i].graphic);
+    InitElementSmallImagesScaledUp(element_to_graphic[i].graphic);
 
   /* initialize special images from static configuration */
   for (i = 0; element_to_special_graphic[i].element > -1; i++)
-    CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
+    InitElementSmallImagesScaledUp(element_to_special_graphic[i].graphic);
 
   /* initialize images from dynamic configuration */
   for (i = 0; i < num_property_mappings; i++)
     if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
-      CreateImageWithSmallImages(property_mapping[i].artwork_index);
+      InitElementSmallImagesScaledUp(property_mapping[i].artwork_index);
+
+#if 1
+  /* !!! FIX THIS (CHANGE TO USING NORMAL ELEMENT GRAPHIC DEFINITIONS) !!! */
+  for (i = IMG_EMC_OBJECT; i <= IMG_EMC_SPRITE; i++)
+    InitElementSmallImagesScaledUp(i);
+#endif
+}
+
+#if 1
+/* !!! FIX THIS (CHANGE TO USING NORMAL ELEMENT GRAPHIC DEFINITIONS) !!! */
+void SetBitmaps_EM(Bitmap **em_bitmap)
+{
+  em_bitmap[0] = graphic_info[IMG_EMC_OBJECT].bitmap;
+  em_bitmap[1] = graphic_info[IMG_EMC_SPRITE].bitmap;
 }
+#endif
 
 static int getFontBitmapID(int font_nr)
 {
@@ -846,6 +866,7 @@ static void set_graphic_parameters(int graphic, char **parameter_raw)
   graphic_info[graphic].crumbled_like = -1;    /* do not use clone element */
   graphic_info[graphic].diggable_like = -1;    /* do not use clone element */
   graphic_info[graphic].border_size = TILEX / 8;  /* "CRUMBLED" border size */
+  graphic_info[graphic].scale_up_factor = 1;   /* default: no scaling up */
   graphic_info[graphic].anim_delay_fixed = 0;
   graphic_info[graphic].anim_delay_random = 0;
   graphic_info[graphic].post_delay_fixed = 0;
@@ -869,10 +890,21 @@ static void set_graphic_parameters(int graphic, char **parameter_raw)
   if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
     graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
 
+  /* optional zoom factor for scaling up the image to a larger size */
+  if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE)
+    graphic_info[graphic].scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR];
+  if (graphic_info[graphic].scale_up_factor < 1)
+    graphic_info[graphic].scale_up_factor = 1;         /* no scaling */
+
   if (src_bitmap)
   {
-    anim_frames_per_row = src_bitmap->width  / graphic_info[graphic].width;
-    anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
+    /* bitmap is not scaled at this stage, so calculate final size */
+    int scale_up_factor = graphic_info[graphic].scale_up_factor;
+    int src_bitmap_width  = src_bitmap->width  * scale_up_factor;
+    int src_bitmap_height = src_bitmap->height * scale_up_factor;
+
+    anim_frames_per_row = src_bitmap_width  / graphic_info[graphic].width;
+    anim_frames_per_col = src_bitmap_height / graphic_info[graphic].height;
   }
 
   /* correct x or y offset dependent of vertical or horizontal frame order */
@@ -1017,6 +1049,7 @@ static void InitGraphicInfo()
     Bitmap *src_bitmap;
     int src_x, src_y;
     int first_frame, last_frame;
+    int scale_up_factor, src_bitmap_width, src_bitmap_height;
 
 #if 0
     printf("::: image: '%s' [%d]\n", image->token, i);
@@ -1035,11 +1068,16 @@ static void InitGraphicInfo()
     if (graphic_info[i].bitmap == NULL)
       continue;                /* skip check for optional images that are undefined */
 
+    /* bitmap is not scaled at this stage, so calculate final size */
+    scale_up_factor = graphic_info[i].scale_up_factor;
+    src_bitmap_width  = graphic_info[i].bitmap->width  * scale_up_factor;
+    src_bitmap_height = graphic_info[i].bitmap->height * scale_up_factor;
+
     first_frame = 0;
     getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
     if (src_x < 0 || src_y < 0 ||
-       src_x + TILEX > src_bitmap->width ||
-       src_y + TILEY > src_bitmap->height)
+       src_x + TILEX > src_bitmap_width ||
+       src_y + TILEY > src_bitmap_height)
     {
       Error(ERR_RETURN_LINE, "-");
       Error(ERR_RETURN, "warning: error found in config file:");
@@ -1054,6 +1092,10 @@ static void InitGraphicInfo()
            src_x, src_y);
       Error(ERR_RETURN, "custom graphic rejected for this element/action");
 
+#if 0
+      Error(ERR_RETURN, "scale_up_factor == %d", scale_up_factor);
+#endif
+
       if (i == fallback_graphic)
        Error(ERR_EXIT, "fatal error: no fallback graphic available");
 
@@ -1067,8 +1109,8 @@ static void InitGraphicInfo()
     last_frame = graphic_info[i].anim_frames - 1;
     getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
     if (src_x < 0 || src_y < 0 ||
-       src_x + TILEX > src_bitmap->width ||
-       src_y + TILEY > src_bitmap->height)
+       src_x + TILEX > src_bitmap_width ||
+       src_y + TILEY > src_bitmap_height)
     {
       Error(ERR_RETURN_LINE, "-");
       Error(ERR_RETURN, "warning: error found in config file:");
@@ -1218,6 +1260,13 @@ static void InitElementSoundInfo()
        default_action_sound = element_info[i].sound[ACTION_DEFAULT];
 #endif
 
+#if 1
+      /* !!! needed because EL_EMPTY_SPACE treated as IS_SP_ELEMENT !!! */
+      /* !!! make this better !!! */
+      if (i == EL_EMPTY_SPACE)
+       default_action_sound = element_info[EL_DEFAULT].sound[act];
+#endif
+
       /* no sound for this specific action -- use default action sound */
       if (element_info[i].sound[act] == -1)
        element_info[i].sound[act] = default_action_sound;
@@ -1272,6 +1321,12 @@ static void set_sound_parameters(int sound, char **parameter_raw)
   /* explicit loop mode setting in configuration overrides default value */
   if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
     sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
+
+  /* sound volume to change the original volume when loading the sound file */
+  sound_info[sound].volume = parameter[SND_ARG_VOLUME];
+
+  /* sound priority to give certain sounds a higher or lower priority */
+  sound_info[sound].volume = parameter[SND_ARG_VOLUME];
 }
 
 static void InitSoundInfo()
@@ -1552,7 +1607,7 @@ static void ReinitializeGraphics()
   InitElementGraphicInfo();            /* element game graphic mapping */
   InitElementSpecialGraphicInfo();     /* element special graphic mapping */
 
-  InitElementSmallImages();            /* create editor and preview images */
+  InitElementSmallImages();            /* scale images to all needed sizes */
   InitFontGraphicInfo();               /* initialize text drawing functions */
 
   SetMainBackgroundImage(IMG_BACKGROUND);
@@ -1740,6 +1795,7 @@ void InitElementPropertiesStatic()
     EL_TRAP,
     EL_INVISIBLE_SAND,
     EL_INVISIBLE_SAND_ACTIVE,
+    EL_EMC_GRASS,
 
     /* !!! currently not diggable, but handled by 'ep_dont_run_into' !!! */
     /* (if amoeba can grow into anything diggable, maybe keep these out) */
@@ -1747,6 +1803,7 @@ void InitElementPropertiesStatic()
     EL_LANDMINE,
     EL_TRAP_ACTIVE,
     EL_SP_BUGGY_BASE_ACTIVE,
+    EL_EMC_PLANT,
 #endif
     -1
   };
@@ -1767,6 +1824,10 @@ void InitElementPropertiesStatic()
     EL_EM_KEY_2,
     EL_EM_KEY_3,
     EL_EM_KEY_4,
+    EL_EM_KEY_5,
+    EL_EM_KEY_6,
+    EL_EM_KEY_7,
+    EL_EM_KEY_8,
     EL_DYNAMITE,
     EL_DYNABOMB_INCREASE_NUMBER,
     EL_DYNABOMB_INCREASE_SIZE,
@@ -1784,6 +1845,8 @@ void InitElementPropertiesStatic()
     EL_ENVELOPE_3,
     EL_ENVELOPE_4,
     EL_SPEED_PILL,
+    EL_EMC_LENSES,
+    EL_EMC_MAGNIFIER,
     -1
   };
 
@@ -1812,6 +1875,7 @@ void InitElementPropertiesStatic()
     EL_LANDMINE,
     EL_TRAP_ACTIVE,
     EL_SP_BUGGY_BASE_ACTIVE,
+    EL_EMC_PLANT,
 #endif
     -1
   };
@@ -1977,6 +2041,10 @@ void InitElementPropertiesStatic()
     EL_STEELWALL_SLIPPERY,
     EL_PEARL,
     EL_CRYSTAL,
+    EL_EMC_WALL_SLIPPERY_1,
+    EL_EMC_WALL_SLIPPERY_2,
+    EL_EMC_WALL_SLIPPERY_3,
+    EL_EMC_WALL_SLIPPERY_4,
     -1
   };
 
@@ -2005,6 +2073,7 @@ void InitElementPropertiesStatic()
     EL_SP_ELECTRON,
     EL_BALLOON,
     EL_SPRING,
+    EL_EMC_ANDROID,
     -1
   };
 
@@ -2185,10 +2254,18 @@ void InitElementPropertiesStatic()
     EL_EM_GATE_2,
     EL_EM_GATE_3,
     EL_EM_GATE_4,
+    EL_EM_GATE_5,
+    EL_EM_GATE_6,
+    EL_EM_GATE_7,
+    EL_EM_GATE_8,
     EL_EM_GATE_1_GRAY,
     EL_EM_GATE_2_GRAY,
     EL_EM_GATE_3_GRAY,
     EL_EM_GATE_4_GRAY,
+    EL_EM_GATE_5_GRAY,
+    EL_EM_GATE_6_GRAY,
+    EL_EM_GATE_7_GRAY,
+    EL_EM_GATE_8_GRAY,
     EL_SWITCHGATE_OPEN,
     EL_TIMEGATE_OPEN,
     -1
@@ -2249,6 +2326,7 @@ void InitElementPropertiesStatic()
     EL_SATELLITE,
     EL_SP_DISK_YELLOW,
     EL_BALLOON,
+    EL_EMC_ANDROID,
     -1
   };
 
@@ -2277,10 +2355,18 @@ void InitElementPropertiesStatic()
     EL_EM_GATE_2,
     EL_EM_GATE_3,
     EL_EM_GATE_4,
+    EL_EM_GATE_5,
+    EL_EM_GATE_6,
+    EL_EM_GATE_7,
+    EL_EM_GATE_8,
     EL_EM_GATE_1_GRAY,
     EL_EM_GATE_2_GRAY,
     EL_EM_GATE_3_GRAY,
     EL_EM_GATE_4_GRAY,
+    EL_EM_GATE_5_GRAY,
+    EL_EM_GATE_6_GRAY,
+    EL_EM_GATE_7_GRAY,
+    EL_EM_GATE_8_GRAY,
     EL_SWITCHGATE_OPEN,
     EL_TIMEGATE_OPEN,
 
@@ -2374,6 +2460,7 @@ void InitElementPropertiesStatic()
     EL_SP_GRAVITY_OFF_PORT_RIGHT,
     EL_SP_GRAVITY_OFF_PORT_UP,
     EL_SP_GRAVITY_OFF_PORT_DOWN,
+    EL_EMC_GRASS,
     -1
   };
 
@@ -2430,6 +2517,7 @@ void InitElementPropertiesStatic()
     EL_BALLOON_SWITCH_ANY,
     EL_LAMP,
     EL_TIME_ORB_FULL,
+    EL_EMC_MAGIC_BALL_SWITCH,
     -1
   };
 
@@ -2940,10 +3028,18 @@ void InitElementPropertiesStatic()
     EL_EM_GATE_2,
     EL_EM_GATE_3,
     EL_EM_GATE_4,
+    EL_EM_GATE_5,
+    EL_EM_GATE_6,
+    EL_EM_GATE_7,
+    EL_EM_GATE_8,
     EL_EM_GATE_1_GRAY,
     EL_EM_GATE_2_GRAY,
     EL_EM_GATE_3_GRAY,
     EL_EM_GATE_4_GRAY,
+    EL_EM_GATE_5_GRAY,
+    EL_EM_GATE_6_GRAY,
+    EL_EM_GATE_7_GRAY,
+    EL_EM_GATE_8_GRAY,
     -1
   };
 
@@ -3025,6 +3121,10 @@ void InitElementPropertiesStatic()
     EL_EM_KEY_2,
     EL_EM_KEY_3,
     EL_EM_KEY_4,
+    EL_EM_KEY_5,
+    EL_EM_KEY_6,
+    EL_EM_KEY_7,
+    EL_EM_KEY_8,
     EL_GATE_1,
     EL_GATE_2,
     EL_GATE_3,
@@ -3037,10 +3137,18 @@ void InitElementPropertiesStatic()
     EL_EM_GATE_2,
     EL_EM_GATE_3,
     EL_EM_GATE_4,
+    EL_EM_GATE_5,
+    EL_EM_GATE_6,
+    EL_EM_GATE_7,
+    EL_EM_GATE_8,
     EL_EM_GATE_1_GRAY,
     EL_EM_GATE_2_GRAY,
     EL_EM_GATE_3_GRAY,
     EL_EM_GATE_4_GRAY,
+    EL_EM_GATE_5_GRAY,
+    EL_EM_GATE_6_GRAY,
+    EL_EM_GATE_7_GRAY,
+    EL_EM_GATE_8_GRAY,
     EL_DYNAMITE,
     EL_INVISIBLE_STEELWALL,
     EL_INVISIBLE_WALL,
@@ -3142,6 +3250,10 @@ void InitElementPropertiesStatic()
     EL_EMC_STEELWALL_2,
     EL_EMC_STEELWALL_3,
     EL_EMC_STEELWALL_4,
+    EL_EMC_WALL_SLIPPERY_1,
+    EL_EMC_WALL_SLIPPERY_2,
+    EL_EMC_WALL_SLIPPERY_3,
+    EL_EMC_WALL_SLIPPERY_4,
     EL_EMC_WALL_1,
     EL_EMC_WALL_2,
     EL_EMC_WALL_3,
@@ -3150,6 +3262,14 @@ void InitElementPropertiesStatic()
     EL_EMC_WALL_6,
     EL_EMC_WALL_7,
     EL_EMC_WALL_8,
+    EL_EMC_WALL_9,
+    EL_EMC_WALL_10,
+    EL_EMC_WALL_11,
+    EL_EMC_WALL_12,
+    EL_EMC_WALL_13,
+    EL_EMC_WALL_14,
+    EL_EMC_WALL_15,
+    EL_EMC_WALL_16,
     -1
   };
 
@@ -3665,6 +3785,10 @@ static void InitGlobal()
 
   for (i = 0; i < MAX_NUM_ELEMENTS + 1; i++)
   {
+    /* check if element_name_info entry defined for each element in "main.h" */
+    if (i < MAX_NUM_ELEMENTS && element_name_info[i].token_name == NULL)
+      Error(ERR_EXIT, "undefined 'element_name_info' entry for element %d", i);
+
     element_info[i].token_name = element_name_info[i].token_name;
     element_info[i].class_name = element_name_info[i].class_name;
     element_info[i].editor_description=element_name_info[i].editor_description;
@@ -4434,6 +4558,10 @@ void OpenAll()
 
   game_status = GAME_MODE_MAIN;
 
+#if 1
+  em_open_all();
+#endif
+
   DrawMainMenu();
 
   InitNetworkServer();
@@ -4446,6 +4574,10 @@ void CloseAllAndExit(int exit_value)
   FreeAllMusic();
   CloseAudio();                /* called after freeing sounds (needed for SDL) */
 
+#if 1
+  em_close_all();
+#endif
+
   FreeAllImages();
   FreeTileClipmasks();