rnd-20100623-1-src
[rocksndiamonds.git] / src / tools.c
index c26996b6720fef0ee85581256e04de8eb3322ad7..326af5f9d8ea37dd725ecb623cb8f9ff9a44f886 100644 (file)
@@ -251,6 +251,11 @@ void DrawMaskedBorder(int redraw_mask)
       effectiveGameStatus() == GAME_MODE_TITLE)
     return;
 
+  /* never draw masked screen borders when displaying request outside door */
+  if (effectiveGameStatus() == GAME_MODE_PSEUDO_DOOR &&
+      global.use_envelope_request)
+    return;
+
   if (redraw_mask & REDRAW_ALL)
     DrawMaskedBorder_ALL();
   else
@@ -332,7 +337,7 @@ void BackToFront()
 
   SyncDisplay();
 
-  /* prevent drawing masked border to backbuffer when using playfield buffer */
+  /* never draw masked border to backbuffer when using playfield buffer */
   if (game_status != GAME_MODE_PLAYING ||
       redraw_mask & REDRAW_FROM_BACKBUFFER ||
       buffer == backbuffer)
@@ -795,8 +800,22 @@ void SetDoorBackgroundImage(int graphic)
 
 void SetPanelBackground()
 {
+#if 1
+  struct GraphicInfo *gfx = &graphic_info[IMG_BACKGROUND_PANEL];
+
+#if 1
+  BlitBitmapTiled(gfx->bitmap, bitmap_db_panel, gfx->src_x, gfx->src_y,
+                 gfx->width, gfx->height, 0, 0, DXSIZE, DYSIZE);
+#else
+  /* (ClearRectangle() only needed if panel bitmap is smaller than panel) */
+  ClearRectangle(bitmap_db_panel, DX, DY, DXSIZE, DYSIZE);
+  BlitBitmap(gfx->bitmap, bitmap_db_panel, gfx->src_x, gfx->src_y,
+            MIN(gfx->width, DXSIZE), MIN(gfx->height, DYSIZE), 0, 0);
+#endif
+#else
   BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, bitmap_db_panel,
              DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, 0, 0);
+#endif
 
   SetDoorBackgroundBitmap(bitmap_db_panel);
 }
@@ -2417,7 +2436,7 @@ void ShowEnvelopeDoor(char *text, int action)
   game.envelope_active = FALSE;
 
 #if 1
-  game_status = last_game_status;      /* restore current game status */
+  // game_status = last_game_status;   /* restore current game status */
 
   if (action == ACTION_CLOSING)
   {
@@ -2445,6 +2464,9 @@ void ShowEnvelopeDoor(char *text, int action)
 
   BackToFront();
 
+  /* (important: after "BackToFront()", but before "SetDrawtoField()") */
+  game_status = last_game_status;      /* restore current game status */
+
   if (game_status == GAME_MODE_PLAYING &&
       level.game_engine_type == GAME_ENGINE_TYPE_RND)
     SetDrawtoField(DRAW_BUFFERED);
@@ -3378,13 +3400,14 @@ boolean Request(char *text, unsigned int req_state)
   int last_game_status = game_status;  /* save current game status */
   int max_request_line_len = MAX_REQUEST_LINE_FONT1_LEN;
   int font_nr = FONT_TEXT_2;
-  boolean use_envelope_request = TRUE  * 0;
 #if 0
   int max_word_len = 0;
 #endif
   char *text_ptr;
   int i;
 
+  global.use_envelope_request = TRUE  * 1;
+
 #if 1
   if (maxWordLengthInString(text) > MAX_REQUEST_LINE_FONT1_LEN)
   {
@@ -3440,13 +3463,21 @@ boolean Request(char *text, unsigned int req_state)
 
   UnmapAllGadgets();
 
-#if 1
-  if (old_door_state & DOOR_OPEN_1 && !use_envelope_request)
+  /* draw released gadget before proceeding */
+  // BackToFront();
+
+#if 0
+  if (old_door_state & DOOR_OPEN_1 && !global.use_envelope_request)
 #else
   if (old_door_state & DOOR_OPEN_1)
 #endif
   {
+#if 1
+    if (!global.use_envelope_request)
+      CloseDoor(DOOR_CLOSE_1);
+#else
     CloseDoor(DOOR_CLOSE_1);
+#endif
 
     /* save old door content */
     BlitBitmap(bitmap_db_door, bitmap_db_door,
@@ -3502,7 +3533,7 @@ boolean Request(char *text, unsigned int req_state)
   game_status = last_game_status;      /* restore current game status */
 
 #if 1
-  if (use_envelope_request)
+  if (global.use_envelope_request)
   {
     /* !!! TMP !!! */
     FreeToolButtons();
@@ -3533,7 +3564,7 @@ boolean Request(char *text, unsigned int req_state)
             DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
 
 #if 1
-  if (use_envelope_request)
+  if (global.use_envelope_request)
   {
     ShowEnvelopeDoor(text, ACTION_OPENING);
 
@@ -3557,7 +3588,7 @@ boolean Request(char *text, unsigned int req_state)
 #endif
 
 #if 1
-  if (!use_envelope_request)
+  if (!global.use_envelope_request)
     OpenDoor(DOOR_OPEN_1);
 #else
   OpenDoor(DOOR_OPEN_1);
@@ -3579,7 +3610,7 @@ boolean Request(char *text, unsigned int req_state)
   }
 
 #if 1
-  if (game_status != GAME_MODE_MAIN && !use_envelope_request)
+  if (game_status != GAME_MODE_MAIN && !global.use_envelope_request)
     InitAnimation();
 #else
   if (game_status != GAME_MODE_MAIN)
@@ -3721,8 +3752,16 @@ boolean Request(char *text, unsigned int req_state)
        Delay(10);
     }
 
+#if 1
+    game_status = GAME_MODE_PSEUDO_DOOR;
+#endif
+
     BackToFront();
 
+#if 1
+    game_status = last_game_status;    /* restore current game status */
+#endif
+
 #else
 
     DoAnimation();
@@ -3744,12 +3783,12 @@ boolean Request(char *text, unsigned int req_state)
   UnmapToolButtons();
 
 #if 1
-  if (use_envelope_request)
+  if (global.use_envelope_request)
     ShowEnvelopeDoor(text, ACTION_CLOSING);
 #endif
 
 #if 1
-  if (!(req_state & REQ_STAY_OPEN) && !use_envelope_request)
+  if (!(req_state & REQ_STAY_OPEN) && !global.use_envelope_request)
 #else
   if (!(req_state & REQ_STAY_OPEN))
 #endif
@@ -8333,7 +8372,8 @@ void InitGraphicInfo_EM(void)
 }
 
 void CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame,
-                           boolean any_player_moving)
+                           boolean any_player_moving,
+                           boolean player_is_dropping)
 {
   int i;
 
@@ -8345,17 +8385,31 @@ void CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame,
       if (action[i] != JOY_NO_ACTION)
        active_players = TRUE;
 
-    if (frame == 0)
+    // if (frame == 0)
+    if (frame == 0 && !player_is_dropping)
       TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
   }
 }
 
-void CheckSingleStepMode_SP(boolean murphy_is_moving)
+void CheckSingleStepMode_SP(boolean murphy_is_waiting,
+                           boolean murphy_is_dropping)
 {
+#if 0
+  printf("::: waiting: %d, dropping: %d\n",
+        murphy_is_waiting, murphy_is_dropping);
+#endif
+
   if (tape.single_step && tape.recording && !tape.pausing)
   {
-    if (!murphy_is_moving)
+    // if (murphy_is_waiting || murphy_is_dropping)
+    if (murphy_is_waiting)
+    {
+#if 0
+      printf("::: murphy is waiting -> pause mode\n");
+#endif
+
       TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
+    }
   }
 }