rnd-20070420-2-src
[rocksndiamonds.git] / src / init.c
index 57c03bd0ab3060a5160435c13259012377558537..148f927d5bcfc697775bd63352b3677a6e05735e 100644 (file)
@@ -32,6 +32,7 @@
 #include "conf_fnt.c"  /* include auto-generated data structure definitions */
 #include "conf_g2s.c"  /* include auto-generated data structure definitions */
 #include "conf_g2m.c"  /* include auto-generated data structure definitions */
+#include "conf_act.c"  /* include auto-generated data structure definitions */
 
 
 #define CONFIG_TOKEN_FONT_INITIAL              "font.initial"
@@ -167,12 +168,15 @@ static int getFontBitmapID(int font_nr)
 {
   int special = -1;
 
-  if (game_status >= GAME_MODE_TITLE && game_status <= GAME_MODE_PSEUDO_PREVIEW)
+  if (game_status >= GAME_MODE_TITLE_INITIAL &&
+      game_status <= GAME_MODE_PSEUDO_PREVIEW)
     special = game_status;
   else if (game_status == GAME_MODE_PSEUDO_TYPENAME)
     special = GFX_SPECIAL_ARG_MAIN;
+#if 0
   else if (game_status == GAME_MODE_PLAYING)
     special = GFX_SPECIAL_ARG_DOOR;
+#endif
 
   if (special != -1)
     return font_info[font_nr].special_bitmap_id[special];
@@ -180,6 +184,19 @@ static int getFontBitmapID(int font_nr)
     return font_nr;
 }
 
+static int getFontFromToken(char *token)
+{
+  int i;
+
+  /* !!! OPTIMIZE THIS BY USING HASH !!! */
+  for (i = 0; i < NUM_FONTS; i++)
+    if (strEqual(token, font_info[i].token_name))
+      return i;
+
+  /* if font not found, use reliable default value */
+  return FONT_INITIAL_1;
+}
+
 void InitFontGraphicInfo()
 {
   static struct FontBitmapInfo *font_bitmap_info = NULL;
@@ -190,7 +207,8 @@ void InitFontGraphicInfo()
 
   if (graphic_info == NULL)            /* still at startup phase */
   {
-    InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
+    InitFontInfo(font_initial, NUM_INITIAL_FONTS,
+                getFontBitmapID, getFontFromToken);
 
     return;
   }
@@ -232,7 +250,7 @@ void InitFontGraphicInfo()
     int graphic      = font_to_graphic[i].graphic;
     int base_graphic = font2baseimg(font_nr);
 
-    if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
+    if (IS_SPECIAL_GFX_ARG(special))
     {
       boolean base_redefined =
        getImageListEntryFromImageID(base_graphic)->redefined;
@@ -240,16 +258,6 @@ void InitFontGraphicInfo()
        getImageListEntryFromImageID(graphic)->redefined;
       boolean special_cloned = (graphic_info[graphic].clone_from != -1);
 
-#if 0
-      printf("::: %d, %d, %d / %d, %d, %d\n",
-            font_nr, special, graphic,
-            base_redefined, special_redefined, special_cloned);
-#endif
-
-#if 0
-      // special_cloned = 0;
-#endif
-
       /* if the base font ("font.title_1", for example) has been redefined,
         but not the special font ("font.title_1.LEVELS", for example), do not
         use an existing (in this case considered obsolete) special font
@@ -275,7 +283,7 @@ void InitFontGraphicInfo()
     if (font_nr < 0)
       continue;
 
-    if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
+    if (IS_SPECIAL_GFX_ARG(special))
     {
       font_info[font_nr].special_graphic[special] = graphic;
       font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
@@ -283,34 +291,18 @@ void InitFontGraphicInfo()
     }
   }
 
-#if 0
-  printf("-0- T3.P: %d, %d\n",
-        font_info[FONT_TEXT_3].special_graphic[GFX_SPECIAL_ARG_PREVIEW],
-        font_info[FONT_TEXT_3].special_bitmap_id[GFX_SPECIAL_ARG_PREVIEW]);
-
-  printf("-0- T4.M: %d, %d\n",
-        font_info[FONT_TEXT_4].special_graphic[GFX_SPECIAL_ARG_MAIN],
-        font_info[FONT_TEXT_4].special_bitmap_id[GFX_SPECIAL_ARG_MAIN]);
-#endif
-
-#if 1
-  /* correct special font/graphic mapping for cloned fonts
-     (per definition only needed for static configuration) */
+  /* correct special font/graphic mapping for cloned fonts for downwards
+     compatibility of PREVIEW fonts -- this is only needed for implicit
+     redefinition of special font by redefined base font, and only if other
+     fonts are cloned from this special font (like in the "Zelda" level set) */
   for (i = 0; font_to_graphic[i].font_nr > -1; i++)
   {
-    int font_nr      = font_to_graphic[i].font_nr;
-    int special      = font_to_graphic[i].special;
-    int graphic      = font_to_graphic[i].graphic;
-#if 0
-    int base_graphic = font2baseimg(font_nr);
-#endif
+    int font_nr = font_to_graphic[i].font_nr;
+    int special = font_to_graphic[i].special;
+    int graphic = font_to_graphic[i].graphic;
 
-    if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
+    if (IS_SPECIAL_GFX_ARG(special))
     {
-#if 0
-      boolean base_redefined =
-       getImageListEntryFromImageID(base_graphic)->redefined;
-#endif
       boolean special_redefined =
        getImageListEntryFromImageID(graphic)->redefined;
       boolean special_cloned = (graphic_info[graphic].clone_from != -1);
@@ -319,50 +311,24 @@ void InitFontGraphicInfo()
       {
        int j;
 
-#if 0
-       printf(":2: %d, %d, %d / %d, %d, %d\n",
-              font_nr, special, graphic,
-              base_redefined, special_redefined, special_cloned);
-#endif
-
        for (j = 0; font_to_graphic[j].font_nr > -1; j++)
        {
-         int font_nr2      = font_to_graphic[j].font_nr;
-         int special2      = font_to_graphic[j].special;
-         int graphic2      = font_to_graphic[j].graphic;
-#if 0
-         int base_graphic2 = font2baseimg(font_nr2);
-#endif
+         int font_nr2 = font_to_graphic[j].font_nr;
+         int special2 = font_to_graphic[j].special;
+         int graphic2 = font_to_graphic[j].graphic;
 
-         if (graphic2 == graphic_info[graphic].clone_from)
+         if (IS_SPECIAL_GFX_ARG(special2) &&
+             graphic2 == graphic_info[graphic].clone_from)
          {
-#if 0
-           printf(":2.1: %d, %d, %d, %d\n",
-                  font_nr2, special2, graphic2, base_graphic2);
-#endif
-
-#if 1
            font_info[font_nr].special_graphic[special] =
              font_info[font_nr2].special_graphic[special2];
            font_info[font_nr].special_bitmap_id[special] =
              font_info[font_nr2].special_bitmap_id[special2];
-#else
-#if 1
-           font_info[font_nr].special_graphic[special] = graphic2;
-           font_info[font_nr].special_bitmap_id[special] =
-             font_info[font_nr2].special_bitmap_id[special2];
-#else
-           font_info[font_nr].special_graphic[special] = graphic2;
-           font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
-           num_font_bitmaps++;
-#endif
-#endif
          }
        }
       }
     }
   }
-#endif
 
   /* reset non-redefined ".active" font graphics if normal font is redefined */
   /* (this different treatment is needed because normal and active fonts are
@@ -412,24 +378,6 @@ void InitFontGraphicInfo()
     }
   }
 
-#if 0
-  printf("-1- T4.M: %d, %d\n",
-        font_info[FONT_TEXT_4].special_graphic[GFX_SPECIAL_ARG_MAIN],
-        font_info[FONT_TEXT_4].special_bitmap_id[GFX_SPECIAL_ARG_MAIN]);
-
-  font_info[FONT_TEXT_4].special_graphic[GFX_SPECIAL_ARG_MAIN] =
-    IMG_FONT_TEXT_3;
-  font_info[FONT_TEXT_4].special_bitmap_id[GFX_SPECIAL_ARG_MAIN] =
-    FONT_TEXT_3;
-
-#if 0
-  font_info[FONT_TEXT_4].special_graphic[GFX_SPECIAL_ARG_MAIN] =
-    IMG_FONT_TEXT_3_PREVIEW;
-  font_info[FONT_TEXT_4].special_bitmap_id[GFX_SPECIAL_ARG_MAIN] =
-    FONT_TEXT_3;
-#endif
-#endif
-
   /* ---------- initialize font bitmap array ---------- */
 
   if (font_bitmap_info != NULL)
@@ -479,17 +427,8 @@ void InitFontGraphicInfo()
     }
   }
 
-  InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
-
-#if 0
-  printf("-X- T3.P: %d, %d\n",
-        font_info[FONT_TEXT_3].special_graphic[GFX_SPECIAL_ARG_PREVIEW],
-        font_info[FONT_TEXT_3].special_bitmap_id[GFX_SPECIAL_ARG_PREVIEW]);
-
-  printf("-4- T4.M: %d, %d\n",
-        font_info[FONT_TEXT_4].special_graphic[GFX_SPECIAL_ARG_MAIN],
-        font_info[FONT_TEXT_4].special_bitmap_id[GFX_SPECIAL_ARG_MAIN]);
-#endif
+  InitFontInfo(font_bitmap_info, num_font_bitmaps,
+              getFontBitmapID, getFontFromToken);
 }
 
 void InitElementGraphicInfo()
@@ -575,6 +514,16 @@ void InitElementGraphicInfo()
     int graphic   = property_mapping[i].artwork_index;
     boolean crumbled = FALSE;
 
+#if 0
+    if ((element == EL_EM_DYNAMITE ||
+        element == EL_EM_DYNAMITE_ACTIVE) &&
+       action == ACTION_ACTIVE &&
+       (special == GFX_SPECIAL_ARG_EDITOR ||
+        special == GFX_SPECIAL_ARG_PANEL))
+      printf("::: DYNAMIC: %d, %d, %d -> %d\n",
+            element, action, special, graphic);
+#endif
+
     if (special == GFX_SPECIAL_ARG_CRUMBLED)
     {
       special = -1;
@@ -968,6 +917,15 @@ void InitElementSpecialGraphicInfo()
     boolean special_redefined =
       getImageListEntryFromImageID(graphic)->redefined;
 
+#if 0
+    if ((element == EL_EM_DYNAMITE ||
+        element == EL_EM_DYNAMITE_ACTIVE) &&
+       (special == GFX_SPECIAL_ARG_EDITOR ||
+        special == GFX_SPECIAL_ARG_PANEL))
+      printf("::: SPECIAL STATIC: %d, %d -> %d\n",
+            element, special, graphic);
+#endif
+
     /* if the base graphic ("emerald", for example) has been redefined,
        but not the special graphic ("emerald.EDITOR", for example), do not
        use an existing (in this case considered obsolete) special graphic
@@ -981,14 +939,58 @@ void InitElementSpecialGraphicInfo()
   /* initialize special element/graphic mapping from dynamic configuration */
   for (i = 0; i < num_property_mappings; i++)
   {
-    int element = property_mapping[i].base_index;
-    int special = property_mapping[i].ext3_index;
-    int graphic = property_mapping[i].artwork_index;
+    int element   = property_mapping[i].base_index;
+    int action    = property_mapping[i].ext1_index;
+    int direction = property_mapping[i].ext2_index;
+    int special   = property_mapping[i].ext3_index;
+    int graphic   = property_mapping[i].artwork_index;
+
+#if 0
+    if ((element == EL_EM_DYNAMITE ||
+        element == EL_EM_DYNAMITE_ACTIVE ||
+        element == EL_CONVEYOR_BELT_1_MIDDLE ||
+        element == EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE) &&
+       (special == GFX_SPECIAL_ARG_EDITOR ||
+        special == GFX_SPECIAL_ARG_PANEL))
+      printf("::: SPECIAL DYNAMIC: %d, %d -> %d [%d]\n",
+            element, special, graphic, property_mapping[i].ext1_index);
+#endif
+
+#if 0
+    if (element == EL_CONVEYOR_BELT_1_MIDDLE &&
+       action == ACTION_ACTIVE)
+    {
+      element = EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE;
+      action = -1;
+    }
+#endif
+
+#if 0
+    if (element == EL_MAGIC_WALL &&
+       action == ACTION_ACTIVE)
+    {
+      element = EL_MAGIC_WALL_ACTIVE;
+      action = -1;
+    }
+#endif
+
+#if 1
+    /* for action ".active", replace element with active element, if exists */
+    if (action == ACTION_ACTIVE && element != ELEMENT_ACTIVE(element))
+    {
+      element = ELEMENT_ACTIVE(element);
+      action = -1;
+    }
+#endif
 
     if (element >= MAX_NUM_ELEMENTS)
       continue;
 
-    if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
+    /* do not change special graphic if action or direction was specified */
+    if (action != -1 || direction != -1)
+      continue;
+
+    if (IS_SPECIAL_GFX_ARG(special))
       element_info[element].special_graphic[special] = graphic;
   }
 
@@ -1094,10 +1096,12 @@ 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_mode = FADE_MODE_DEFAULT;
   graphic_info[graphic].fade_delay = -1;
   graphic_info[graphic].post_delay = -1;
   graphic_info[graphic].auto_delay = -1;
   graphic_info[graphic].align = ALIGN_CENTER;  /* default for title screens */
+  graphic_info[graphic].valign = VALIGN_MIDDLE;        /* default for title screens */
   graphic_info[graphic].sort_priority = 0;     /* default for title screens */
 
 #if 1
@@ -1284,7 +1288,9 @@ static void set_graphic_parameters(int graphic)
   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 */
+  /* optional settings for drawing title screens and title messages */
+  if (parameter[GFX_ARG_FADE_MODE] != ARG_UNDEFINED_VALUE)
+    graphic_info[graphic].fade_mode = parameter[GFX_ARG_FADE_MODE];
   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)
@@ -1293,6 +1299,8 @@ static void set_graphic_parameters(int graphic)
     graphic_info[graphic].auto_delay = parameter[GFX_ARG_AUTO_DELAY];
   if (parameter[GFX_ARG_ALIGN] != ARG_UNDEFINED_VALUE)
     graphic_info[graphic].align = parameter[GFX_ARG_ALIGN];
+  if (parameter[GFX_ARG_VALIGN] != ARG_UNDEFINED_VALUE)
+    graphic_info[graphic].valign = parameter[GFX_ARG_VALIGN];
   if (parameter[GFX_ARG_SORT_PRIORITY] != ARG_UNDEFINED_VALUE)
     graphic_info[graphic].sort_priority = parameter[GFX_ARG_SORT_PRIORITY];
 }
@@ -1362,8 +1370,8 @@ static void InitGraphicInfo()
     IMG_BACKGROUND_ENVELOPE_4,
 
     IMG_BACKGROUND,
+    IMG_BACKGROUND_TITLE_INITIAL,
     IMG_BACKGROUND_TITLE,
-    IMG_BACKGROUND_MESSAGE,
     IMG_BACKGROUND_MAIN,
     IMG_BACKGROUND_LEVELS,
     IMG_BACKGROUND_SCORES,
@@ -1712,7 +1720,7 @@ static void set_sound_parameters(int sound, char **parameter_raw)
   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];
+  sound_info[sound].priority = parameter[SND_ARG_PRIORITY];
 }
 
 static void InitSoundInfo()
@@ -4400,19 +4408,64 @@ 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;
+    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
   }
 
+  /* always start with reliable default values (all elements) */
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+    ActiveElement[i] = i;
+
+  /* now add all entries that have an active state (active elements) */
+  for (i = 0; element_with_active_state[i].element != -1; i++)
+  {
+    int element = element_with_active_state[i].element;
+    int element_active = element_with_active_state[i].element_active;
+
+    ActiveElement[element] = element_active;
+  }
+
+  /* always start with reliable default values (all buttons) */
+  for (i = 0; i < NUM_IMAGE_FILES; i++)
+    ActiveButton[i] = i;
+
+  /* now add all entries that have an active state (active buttons) */
+  for (i = 0; button_with_active_state[i].button != -1; i++)
+  {
+    int button = button_with_active_state[i].button;
+    int button_active = button_with_active_state[i].button_active;
+
+    ActiveButton[button] = button_active;
+  }
+
+  /* always start with reliable default values (all fonts) */
+  for (i = 0; i < NUM_FONTS; i++)
+    ActiveFont[i] = i;
+
+  /* now add all entries that have an active state (active fonts) */
+  for (i = 0; font_with_active_state[i].font_nr != -1; i++)
+  {
+    int font = font_with_active_state[i].font_nr;
+    int font_active = font_with_active_state[i].font_nr_active;
+
+    ActiveFont[font] = font_active;
+  }
+
   global.autoplay_leveldir = NULL;
   global.convert_leveldir = NULL;
 
   global.frames_per_second = 0;
   global.fps_slowdown = FALSE;
   global.fps_slowdown_factor = 1;
+
+  global.border_status = GAME_MODE_MAIN;
+#if 0
+  global.fading_status = GAME_MODE_MAIN;
+  global.fading_type = TYPE_ENTER_MENU;
+#endif
 }
 
 void Execute_Command(char *command)
@@ -4907,10 +4960,14 @@ void InitGfxBackground()
   fieldbuffer = bitmap_db_field;
   SetDrawtoField(DRAW_BACKBUFFER);
 
+#if 1
+  ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
+#else
   RedrawBackground();
 
   ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
   ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
+#endif
 
   for (x = 0; x < MAX_BUF_XSIZE; x++)
     for (y = 0; y < MAX_BUF_YSIZE; y++)
@@ -5170,6 +5227,18 @@ void ReloadCustomArtwork(int force_reload)
     /* force redraw of (open or closed) door graphics */
     SetDoorState(DOOR_OPEN_ALL);
     CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
+
+#if 1
+#if 1
+    FadeSetEnterScreen();
+    // FadeSkipNextFadeOut();
+    // FadeSetDisabled();
+#else
+    FadeSkipNext();
+#endif
+#else
+    fading = fading_none;
+#endif
   }
 }
 
@@ -5256,6 +5325,15 @@ void OpenAll()
 
   game_status = GAME_MODE_MAIN;
 
+#if 1
+  FadeSetEnterScreen();
+  if (!(fading.fade_mode & FADE_TYPE_TRANSFORM))
+    FadeSkipNextFadeOut();
+  // FadeSetDisabled();
+#else
+  fading = fading_none;
+#endif
+
   DrawMainMenu();
 
   InitNetworkServer();