rnd-20070113-1-src
[rocksndiamonds.git] / src / init.c
index b0d66991e22a29c6ba28a0a53e7ec26b1a6d27b2..f081d19a6d0b685b24d0e82abe2c013624ef1256 100644 (file)
@@ -104,6 +104,8 @@ void InitGadgets()
   CreateToolButtons();
   CreateScreenGadgets();
 
+  InitGadgetsSoundCallback(PlaySoundActivating, PlaySoundSelecting);
+
   gadgets_initialized = TRUE;
 }
 
@@ -165,7 +167,7 @@ static int getFontBitmapID(int font_nr)
 {
   int special = -1;
 
-  if (game_status >= GAME_MODE_MAIN && game_status <= GAME_MODE_PSEUDO_PREVIEW)
+  if (game_status >= GAME_MODE_TITLE && game_status <= GAME_MODE_PSEUDO_PREVIEW)
     special = game_status;
   else if (game_status == GAME_MODE_PSEUDO_TYPENAME)
     special = GFX_SPECIAL_ARG_MAIN;
@@ -949,13 +951,13 @@ static void set_graphic_parameters(int graphic)
 
   graphic_info[graphic].bitmap = src_bitmap;
 
-  /* start with reliable default values */
+  /* always start with reliable default values */
   graphic_info[graphic].src_image_width = 0;
   graphic_info[graphic].src_image_height = 0;
   graphic_info[graphic].src_x = 0;
   graphic_info[graphic].src_y = 0;
-  graphic_info[graphic].width = TILEX;
-  graphic_info[graphic].height = TILEY;
+  graphic_info[graphic].width  = TILEX;        /* default for element graphics */
+  graphic_info[graphic].height = TILEY;        /* default for element graphics */
   graphic_info[graphic].offset_x = 0;  /* one or both of these values ... */
   graphic_info[graphic].offset_y = 0;  /* ... will be corrected later */
   graphic_info[graphic].offset2_x = 0; /* one or both of these values ... */
@@ -970,6 +972,26 @@ static void set_graphic_parameters(int graphic)
   graphic_info[graphic].anim_delay_random = 0;
   graphic_info[graphic].post_delay_fixed = 0;
   graphic_info[graphic].post_delay_random = 0;
+  graphic_info[graphic].fade_delay = -1;
+  graphic_info[graphic].post_delay = -1;
+  graphic_info[graphic].auto_delay = -1;
+
+#if 1
+  /* 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 */
+#endif
+
+#if 1
+  if (graphic_info[graphic].use_image_size)
+  {
+    /* set new default bitmap size (with scaling, but without small images) */
+    graphic_info[graphic].width  = get_scaled_graphic_width(graphic);
+    graphic_info[graphic].height = get_scaled_graphic_height(graphic);
+  }
+#endif
 
   /* optional x and y tile position of animation frame sequence */
   if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
@@ -989,11 +1011,13 @@ static void set_graphic_parameters(int graphic)
   if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
     graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
 
+#if 0
   /* 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 */
+#endif
 
   if (src_bitmap)
   {
@@ -1135,6 +1159,14 @@ static void set_graphic_parameters(int graphic)
   /* optional graphic for cloning all graphics settings */
   if (parameter[GFX_ARG_CLONE_FROM] != ARG_UNDEFINED_VALUE)
     graphic_info[graphic].clone_from = parameter[GFX_ARG_CLONE_FROM];
+
+  /* optional settings for drawing title screens */
+  if (parameter[GFX_ARG_FADE_DELAY] != ARG_UNDEFINED_VALUE)
+    graphic_info[graphic].fade_delay = parameter[GFX_ARG_FADE_DELAY];
+  if (parameter[GFX_ARG_POST_DELAY] != ARG_UNDEFINED_VALUE)
+    graphic_info[graphic].post_delay = parameter[GFX_ARG_POST_DELAY];
+  if (parameter[GFX_ARG_AUTO_DELAY] != ARG_UNDEFINED_VALUE)
+    graphic_info[graphic].auto_delay = parameter[GFX_ARG_AUTO_DELAY];
 }
 
 static void set_cloned_graphic_parameters(int graphic)
@@ -1190,10 +1222,61 @@ static void InitGraphicInfo()
   GC copy_clipmask_gc = None;
 #endif
 
+  /* use image size as default values for width and height for these images */
+  static int full_size_graphics[] =
+  {
+    IMG_GLOBAL_BORDER,
+    IMG_GLOBAL_DOOR,
+
+    IMG_BACKGROUND_ENVELOPE_1,
+    IMG_BACKGROUND_ENVELOPE_2,
+    IMG_BACKGROUND_ENVELOPE_3,
+    IMG_BACKGROUND_ENVELOPE_4,
+
+    IMG_BACKGROUND,
+    IMG_BACKGROUND_TITLE,
+    IMG_BACKGROUND_MESSAGE,
+    IMG_BACKGROUND_MAIN,
+    IMG_BACKGROUND_LEVELS,
+    IMG_BACKGROUND_SCORES,
+    IMG_BACKGROUND_EDITOR,
+    IMG_BACKGROUND_INFO,
+    IMG_BACKGROUND_INFO_ELEMENTS,
+    IMG_BACKGROUND_INFO_MUSIC,
+    IMG_BACKGROUND_INFO_CREDITS,
+    IMG_BACKGROUND_INFO_PROGRAM,
+    IMG_BACKGROUND_INFO_LEVELSET,
+    IMG_BACKGROUND_SETUP,
+    IMG_BACKGROUND_DOOR,
+
+    IMG_TITLESCREEN_INITIAL_1,
+    IMG_TITLESCREEN_INITIAL_2,
+    IMG_TITLESCREEN_INITIAL_3,
+    IMG_TITLESCREEN_INITIAL_4,
+    IMG_TITLESCREEN_INITIAL_5,
+    IMG_TITLESCREEN_1,
+    IMG_TITLESCREEN_2,
+    IMG_TITLESCREEN_3,
+    IMG_TITLESCREEN_4,
+    IMG_TITLESCREEN_5,
+
+    -1
+  };
+
   checked_free(graphic_info);
 
   graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
 
+#if 1
+  /* initialize "use_image_size" flag with default value */
+  for (i = 0; i < num_images; i++)
+    graphic_info[i].use_image_size = FALSE;
+
+  /* initialize "use_image_size" flag from static configuration above */
+  for (i = 0; full_size_graphics[i] != -1; i++)
+    graphic_info[full_size_graphics[i]].use_image_size = TRUE;
+#endif
+
 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
   if (clipmasks_initialized)
   {
@@ -1223,6 +1306,7 @@ static void InitGraphicInfo()
   {
     Bitmap *src_bitmap;
     int src_x, src_y;
+    int width, height;
     int first_frame, last_frame;
     int src_bitmap_width, src_bitmap_height;
 
@@ -1231,6 +1315,10 @@ static void InitGraphicInfo()
     if (graphic_info[i].bitmap == NULL)
       continue;                /* skip check for optional images that are undefined */
 
+    /* get image size (this can differ from the standard element tile size!) */
+    width  = graphic_info[i].width;
+    height = graphic_info[i].height;
+
     /* get final bitmap size (with scaling, but without small images) */
     src_bitmap_width  = graphic_info[i].src_image_width;
     src_bitmap_height = graphic_info[i].src_image_height;
@@ -1240,9 +1328,15 @@ static void InitGraphicInfo()
     first_frame = 0;
     getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
 
+#if 1
+    /* this avoids calculating wrong start position for out-of-bounds frame */
+    src_x = graphic_info[i].src_x;
+    src_y = graphic_info[i].src_y;
+#endif
+
     if (src_x < 0 || src_y < 0 ||
-       src_x + TILEX > src_bitmap_width ||
-       src_y + TILEY > src_bitmap_height)
+       src_x + width  > src_bitmap_width ||
+       src_y + height > src_bitmap_height)
     {
       Error(ERR_RETURN_LINE, "-");
       Error(ERR_RETURN, "warning: error found in config file:");
@@ -1269,8 +1363,8 @@ static void InitGraphicInfo()
     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 + width  > src_bitmap_width ||
+       src_y + height > src_bitmap_height)
     {
       Error(ERR_RETURN_LINE, "-");
       Error(ERR_RETURN, "warning: error found in config file:");
@@ -2082,13 +2176,20 @@ void InitElementPropertiesStatic()
     EL_SIGN_STOP,
     EL_SIGN_WHEELCHAIR,
     EL_SIGN_PARKING,
-    EL_SIGN_ONEWAY,
+    EL_SIGN_NO_ENTRY,
+    EL_SIGN_UNUSED_1,
+    EL_SIGN_GIVE_WAY,
+    EL_SIGN_ENTRY_FORBIDDEN,
+    EL_SIGN_EMERGENCY_EXIT,
+    EL_SIGN_YIN_YANG,
+    EL_SIGN_UNUSED_2,
+    EL_SIGN_SPERMS,
+    EL_SIGN_BULLET,
     EL_SIGN_HEART,
-    EL_SIGN_TRIANGLE,
-    EL_SIGN_ROUND,
-    EL_SIGN_EXIT,
-    EL_SIGN_YINYANG,
-    EL_SIGN_OTHER,
+    EL_SIGN_CROSS,
+    EL_SIGN_FRANKIE,
+    EL_STEEL_EXIT_CLOSED,
+    EL_STEEL_EXIT_OPEN,
     EL_STEELWALL_SLIPPERY,
     EL_EMC_STEELWALL_1,
     EL_EMC_STEELWALL_2,
@@ -3101,13 +3202,20 @@ void InitElementPropertiesStatic()
     EL_SIGN_STOP,
     EL_SIGN_WHEELCHAIR,
     EL_SIGN_PARKING,
-    EL_SIGN_ONEWAY,
+    EL_SIGN_NO_ENTRY,
+    EL_SIGN_UNUSED_1,
+    EL_SIGN_GIVE_WAY,
+    EL_SIGN_ENTRY_FORBIDDEN,
+    EL_SIGN_EMERGENCY_EXIT,
+    EL_SIGN_YIN_YANG,
+    EL_SIGN_UNUSED_2,
+    EL_SIGN_SPERMS,
+    EL_SIGN_BULLET,
     EL_SIGN_HEART,
-    EL_SIGN_TRIANGLE,
-    EL_SIGN_ROUND,
-    EL_SIGN_EXIT,
-    EL_SIGN_YINYANG,
-    EL_SIGN_OTHER,
+    EL_SIGN_CROSS,
+    EL_SIGN_FRANKIE,
+    EL_STEEL_EXIT_CLOSED,
+    EL_STEEL_EXIT_OPEN,
     EL_STEELWALL_SLIPPERY,
     EL_EMC_STEELWALL_1,
     EL_EMC_STEELWALL_2,
@@ -3519,13 +3627,18 @@ void InitElementPropertiesStatic()
     EL_SIGN_STOP,
     EL_SIGN_WHEELCHAIR,
     EL_SIGN_PARKING,
-    EL_SIGN_ONEWAY,
+    EL_SIGN_NO_ENTRY,
+    EL_SIGN_UNUSED_1,
+    EL_SIGN_GIVE_WAY,
+    EL_SIGN_ENTRY_FORBIDDEN,
+    EL_SIGN_EMERGENCY_EXIT,
+    EL_SIGN_YIN_YANG,
+    EL_SIGN_UNUSED_2,
+    EL_SIGN_SPERMS,
+    EL_SIGN_BULLET,
     EL_SIGN_HEART,
-    EL_SIGN_TRIANGLE,
-    EL_SIGN_ROUND,
-    EL_SIGN_EXIT,
-    EL_SIGN_YINYANG,
-    EL_SIGN_OTHER,
+    EL_SIGN_CROSS,
+    EL_SIGN_FRANKIE,
     EL_STEELWALL_SLIPPERY,
     EL_EMC_STEELWALL_1,
     EL_EMC_STEELWALL_2,
@@ -3581,6 +3694,7 @@ void InitElementPropertiesStatic()
     EL_INTERNAL_CASCADE_DC_ACTIVE,
     EL_INTERNAL_CASCADE_DX_ACTIVE,
     EL_INTERNAL_CASCADE_CHARS_ACTIVE,
+    EL_INTERNAL_CASCADE_STEELCHARS_ACTIVE,
     EL_INTERNAL_CASCADE_CE_ACTIVE,
     EL_INTERNAL_CASCADE_GE_ACTIVE,
     EL_INTERNAL_CASCADE_REF_ACTIVE,
@@ -3601,6 +3715,7 @@ void InitElementPropertiesStatic()
     EL_INTERNAL_CASCADE_DC,
     EL_INTERNAL_CASCADE_DX,
     EL_INTERNAL_CASCADE_CHARS,
+    EL_INTERNAL_CASCADE_STEELCHARS,
     EL_INTERNAL_CASCADE_CE,
     EL_INTERNAL_CASCADE_GE,
     EL_INTERNAL_CASCADE_REF,
@@ -3771,7 +3886,14 @@ void InitElementPropertiesEngine(int engine_version)
   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
   {
     /* ---------- INACTIVE ------------------------------------------------- */
-    SET_PROPERTY(i, EP_INACTIVE, (i >= EL_CHAR_START && i <= EL_CHAR_END));
+    SET_PROPERTY(i, EP_INACTIVE, ((i >= EL_CHAR_START &&
+                                  i <= EL_CHAR_END) ||
+                                 (i >= EL_STEELCHAR_START &&
+                                  i <= EL_STEELCHAR_END)));
+
+    /* ---------- INDESTRUCTIBLE -------------------------------------------- */
+    if (i >= EL_STEELCHAR_START && i <= EL_STEELCHAR_END)
+      SET_PROPERTY(i, EP_INDESTRUCTIBLE, TRUE);
 
     /* ---------- WALKABLE, PASSABLE, ACCESSIBLE --------------------------- */
     SET_PROPERTY(i, EP_WALKABLE, (IS_WALKABLE_OVER(i) ||
@@ -3825,7 +3947,6 @@ void InitElementPropertiesEngine(int engine_version)
                                             !IS_COLLECTIBLE(i)));
 
     /* ---------- DRAGONFIRE_PROOF ----------------------------------------- */
-
     if (IS_HISTORIC_SOLID(i) || i == EL_EXPLOSION)
       SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, TRUE);
     else
@@ -4005,6 +4126,10 @@ static void InitGlobal()
     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;
+
+#if 0
+    printf("%04d: %s\n", i, element_name_info[i].token_name);
+#endif
   }
 
   global.autoplay_leveldir = NULL;
@@ -4481,11 +4606,15 @@ void InitGfx()
 
   font_height = getFontHeight(FC_RED);
 
+#if 1
+  DrawInitText(getWindowTitleString(), 20, FC_YELLOW);
+#else
   DrawInitText(getProgramInitString(), 20, FC_YELLOW);
+#endif
   DrawInitText(PROGRAM_COPYRIGHT_STRING, 50, FC_RED);
   DrawInitText(PROGRAM_WEBSITE_STRING, WIN_YSIZE - 20 - font_height, FC_RED);
 
-  DrawInitText("Loading graphics:", 120, FC_GREEN);
+  DrawInitText("Loading graphics", 120, FC_GREEN);
 }
 
 void RedrawBackground()
@@ -4500,7 +4629,6 @@ void InitGfxBackground()
 {
   int x, y;
 
-  drawto = backbuffer;
   fieldbuffer = bitmap_db_field;
   SetDrawtoField(DRAW_BACKBUFFER);
 
@@ -4815,8 +4943,7 @@ void OpenAll()
   InitJoysticks();
 
   InitVideoDisplay();
-  InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
-                 setup.fullscreen);
+  InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
 
   InitEventFilter(FilterMouseMotionEvents);
 
@@ -4825,8 +4952,11 @@ void OpenAll()
 
   InitGfx();
 
+  // debug_print_timestamp(0, "INIT");
   InitLevelInfo();
+  // debug_print_timestamp(0, "TIME InitLevelInfo:        ");
   InitLevelArtworkInfo();
+  // debug_print_timestamp(0, "TIME InitLevelArtworkInfo: ");
 
   InitImages();                        /* needs to know current level directory */
   InitSound(NULL);             /* needs to know current level directory */