rnd-20070424-1-src
[rocksndiamonds.git] / src / tools.c
index e7cd92d525a5b0ab66ec0ecd93c81d583affc5c3..66b11c62b4b89353b9682a1894b4f5e0c1bfb2dc 100644 (file)
@@ -205,16 +205,16 @@ void DrawMaskedBorder_Rect(int x, int y, int width, int height)
 
 void DrawMaskedBorder_FIELD()
 {
-  if (game_status >= GAME_MODE_TITLE &&
-      game_status <= GAME_MODE_PLAYING &&
-      border.draw_masked[game_status])
+  if (global.border_status >= GAME_MODE_TITLE &&
+      global.border_status <= GAME_MODE_PLAYING &&
+      border.draw_masked[global.border_status])
     DrawMaskedBorder_Rect(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
 }
 
 void DrawMaskedBorder_DOOR_1()
 {
   if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
-      (game_status != GAME_MODE_EDITOR ||
+      (global.border_status != GAME_MODE_EDITOR ||
        border.draw_masked[GFX_SPECIAL_ARG_EDITOR]))
     DrawMaskedBorder_Rect(DX, DY, DXSIZE, DYSIZE);
 }
@@ -222,7 +222,7 @@ void DrawMaskedBorder_DOOR_1()
 void DrawMaskedBorder_DOOR_2()
 {
   if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] &&
-      game_status != GAME_MODE_EDITOR)
+      global.border_status != GAME_MODE_EDITOR)
     DrawMaskedBorder_Rect(VX, VY, VXSIZE, VYSIZE);
 }
 
@@ -585,7 +585,10 @@ void FadeExt(int fade_mask, int fade_mode)
     fade_delay = fading.fade_delay;
     post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0);
 
-    draw_border_function = DrawMaskedBorder_FIELD;
+    if (border.draw_masked_when_fading)
+      draw_border_function = DrawMaskedBorder_FIELD;   /* update when fading */
+    else
+      DrawMaskedBorder_FIELD();                                /* draw once */
   }
   else         /* REDRAW_ALL */
   {
@@ -620,6 +623,31 @@ void FadeExt(int fade_mask, int fade_mode)
 
 void FadeIn(int fade_mask)
 {
+#if 0
+  global.border_status = game_status;
+#endif
+
+#if 0
+  global.fading_status = game_status;
+
+  if (global.fading_type == TYPE_ENTER_MENU)
+    fading = menu.enter_menu;
+  else if (global.fading_type == TYPE_LEAVE_MENU)
+    fading = menu.leave_menu;
+  else if (global.fading_type == TYPE_ENTER_SCREEN)
+    fading = menu.enter_screen[global.fading_status];
+  else if (global.fading_type == TYPE_LEAVE_SCREEN)
+    fading = menu.leave_screen[global.fading_status];
+
+  printf("::: FadeIn: %s [0x%08x] [%d]\n",
+        global.fading_type == TYPE_ENTER_MENU ? "enter_menu" :
+        global.fading_type == TYPE_LEAVE_MENU ? "leave_menu" :
+        global.fading_type == TYPE_ENTER_SCREEN ? "enter_screen" :
+        global.fading_type == TYPE_LEAVE_SCREEN ? "leave_screen" : "(?)",
+        global.fading_type,
+        global.fading_status);
+#endif
+
 #if 1
   // printf("::: now fading in...\n");
 
@@ -641,6 +669,25 @@ void FadeIn(int fade_mask)
 
 void FadeOut(int fade_mask)
 {
+#if 0
+  if (global.fading_type == TYPE_ENTER_MENU)
+    fading = menu.enter_menu;
+  else if (global.fading_type == TYPE_LEAVE_MENU)
+    fading = menu.leave_menu;
+  else if (global.fading_type == TYPE_ENTER_SCREEN)
+    fading = menu.enter_screen[global.fading_status];
+  else if (global.fading_type == TYPE_LEAVE_SCREEN)
+    fading = menu.leave_screen[global.fading_status];
+
+  printf("::: FadeOut: %s [0x%08x] [%d]\n",
+        global.fading_type == TYPE_ENTER_MENU ? "enter_menu" :
+        global.fading_type == TYPE_LEAVE_MENU ? "leave_menu" :
+        global.fading_type == TYPE_ENTER_SCREEN ? "enter_screen" :
+        global.fading_type == TYPE_LEAVE_SCREEN ? "leave_screen" : "(?)",
+        global.fading_type,
+        global.fading_status);
+#endif
+
 #if 1
   // printf("::: fading.fade_mode == %d\n", fading.fade_mode);
 
@@ -658,6 +705,10 @@ void FadeOut(int fade_mask)
   FadeExt(fade_mask, FADE_MODE_FADE_OUT);
 #endif
 #endif
+
+#if 1
+  global.border_status = game_status;
+#endif
 }
 
 void FadeCross(int fade_mask)
@@ -670,6 +721,32 @@ void FadeCrossSaveBackbuffer()
   BlitBitmap(backbuffer, bitmap_db_cross, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
 }
 
+#if 0
+void FadeSetEnterMenu()
+{
+  global.fading_type = TYPE_ENTER_MENU;
+}
+
+void FadeSetLeaveMenu()
+{
+  global.fading_type = TYPE_LEAVE_MENU;
+}
+
+void FadeSetEnterScreen()
+{
+  global.fading_type = TYPE_ENTER_SCREEN;
+}
+
+void FadeSetLeaveScreen()
+{
+  // global.fading_type = TYPE_LEAVE_SCREEN;
+
+  global.fading_type = (global.fading_type == TYPE_ENTER_SCREEN ?
+                       TYPE_LEAVE_SCREEN : TYPE_LEAVE_MENU);
+}
+
+#else
+
 static void FadeSetLeaveNext(struct TitleFadingInfo fading_leave, boolean set)
 {
   static struct TitleFadingInfo fading_leave_stored;
@@ -684,6 +761,10 @@ void FadeSetEnterMenu()
 {
   fading = menu.enter_menu;
 
+#if 0
+  printf("::: storing enter_menu\n");
+#endif
+
   FadeSetLeaveNext(fading, TRUE);      /* (keep same fade mode) */
 }
 
@@ -691,6 +772,10 @@ void FadeSetLeaveMenu()
 {
   fading = menu.leave_menu;
 
+#if 0
+  printf("::: storing leave_menu\n");
+#endif
+
   FadeSetLeaveNext(fading, TRUE);      /* (keep same fade mode) */
 }
 
@@ -698,14 +783,32 @@ void FadeSetEnterScreen()
 {
   fading = menu.enter_screen[game_status];
 
+#if 0
+  printf("::: storing leave_screen[%d]\n", game_status);
+#endif
+
+#if 0
+  printf("::: - %d, %d / %d, %d\n",
+        menu.enter_screen[game_status].fade_mode,
+        menu.enter_screen[game_status].fade_delay,
+        menu.leave_screen[game_status].fade_mode,
+        menu.leave_screen[game_status].fade_delay);
+#endif
+
   FadeSetLeaveNext(menu.leave_screen[game_status], TRUE);      /* store */
 }
 
 void FadeSetLeaveScreen()
 {
+#if 0
+  printf("::: recalling last stored value\n");
+#endif
+
   FadeSetLeaveNext(menu.leave_screen[game_status], FALSE);     /* recall */
 }
 
+#endif
+
 void FadeSetFromType(int type)
 {
   if (type & TYPE_ENTER_SCREEN)
@@ -3028,7 +3131,6 @@ boolean Request(char *text, unsigned int req_state)
     if (game_status == GAME_MODE_PLAYING && local_player->LevelSolved_GameEnd)
     {
       HandleGameActions();
-      BackToFront();
     }
     else
     {
@@ -3038,6 +3140,8 @@ boolean Request(char *text, unsigned int req_state)
        Delay(10);
     }
 
+    BackToFront();
+
 #else
 
     DoAnimation();
@@ -5972,6 +6076,67 @@ void ResetGfxAnimation_EM(int x, int y, int tile)
   GfxFrame[x][y] = 0;
 }
 
+void SetGfxAnimation_EM(int tile, int frame_em, int x, int y)
+{
+  int element         = object_mapping[tile].element_rnd;
+  int action          = object_mapping[tile].action;
+  int direction       = object_mapping[tile].direction;
+  boolean is_backside = object_mapping[tile].is_backside;
+  boolean action_removing = (action == ACTION_DIGGING ||
+                            action == ACTION_SNAPPING ||
+                            action == ACTION_COLLECTING);
+
+#if 0
+  printf("::: SET: %d, %d: '%s'\n", x, y, EL_NAME(element));
+#endif
+
+#if 1
+  if (action_removing)
+  {
+#if 0
+    printf("::: %d, %d: action_removing [%s]\n", x, y, EL_NAME(element));
+#endif
+
+    GfxFrame[x][y] = 7 - frame_em;
+  }
+  else if (action == ACTION_FALLING ||
+          action == ACTION_MOVING ||
+          action == ACTION_PUSHING ||
+          action == ACTION_EATING ||
+          action == ACTION_FILLING ||
+          action == ACTION_EMPTYING)
+  {
+    int move_dir =
+      (action == ACTION_FALLING ||
+       action == ACTION_FILLING ||
+       action == ACTION_EMPTYING ? MV_DOWN : direction);
+
+    if (is_backside)
+    {
+      GfxFrame[x][y]++;
+
+      if (move_dir == MV_LEFT)
+       GfxFrame[x - 1][y] = GfxFrame[x][y];
+      else if (move_dir == MV_RIGHT)
+       GfxFrame[x + 1][y] = GfxFrame[x][y];
+      else if (move_dir == MV_UP)
+       GfxFrame[x][y - 1] = GfxFrame[x][y];
+      else if (move_dir == MV_DOWN)
+       GfxFrame[x][y + 1] = GfxFrame[x][y];
+    }
+
+#if 0
+    printf("::: %d, %d: %s, %d, %d [%d]\n", x, y, EL_NAME(element), is_backside,
+          move_dir, GfxFrame[x][y]);
+#endif
+  }
+  else
+    GfxFrame[x][y]++;
+#else
+  GfxFrame[x][y] = 7 - frame_em;
+#endif
+}
+
 void getGraphicSourceObjectExt_EM(int tile, int frame_em,
                                  Bitmap **src_bitmap, int *src_x, int *src_y,
                                  int x, int y)
@@ -5993,10 +6158,28 @@ void getGraphicSourceObjectExt_EM(int tile, int frame_em,
   struct GraphicInfo *g = &graphic_info[graphic];
   int sync_frame;
 
+#if 0
+  printf("::: GET: %d, %d: '%s'\n", x, y, EL_NAME(element));
+#endif
+
+#if 0
+  if (GfxFrame[x][y] < 8)
+    printf("::: %d, %d: %d [%s]\n", x, y, GfxFrame[x][y], EL_NAME(element));
+#endif
+
+#if 1
+  if (graphic_info[graphic].anim_global_sync)
+    sync_frame = FrameCounter;
+  else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY))
+    sync_frame = GfxFrame[x][y];
+  else
+    sync_frame = 0;    /* steel border */
+#else
   if (graphic_info[graphic].anim_global_sync)
     sync_frame = FrameCounter;
   else
     sync_frame = 7 - frame_em;
+#endif
 
   SetRandomAnimationValue(x, y);