fixed single-step mode for wrap-around levels in EM engine
[rocksndiamonds.git] / src / game_em / game.c
index 48d1bfc1b42282897fdfa2c990eb6db6305af736..8443ff0535dede2d67982d5150138b042a72ec00 100644 (file)
@@ -16,29 +16,33 @@ struct EngineSnapshotInfo_EM engine_snapshot_em;
 
 static void readjoy(byte action, struct PLAYER *ply)
 {
-  int north = 0, east = 0, south = 0, west = 0;
-  int snap = 0, drop = 0;
+  boolean north        = FALSE;
+  boolean east = FALSE;
+  boolean south        = FALSE;
+  boolean west = FALSE;
+  boolean snap = FALSE;
+  boolean drop = FALSE;
 
   if (game_em.use_single_button && action & (JOY_BUTTON_1 | JOY_BUTTON_2))
     action |= JOY_BUTTON_1 | JOY_BUTTON_2;
 
   if (action & JOY_LEFT)
-    west = 1;
+    west = TRUE;
 
   if (action & JOY_RIGHT)
-    east = 1;
+    east = TRUE;
 
   if (action & JOY_UP)
-    north = 1;
+    north = TRUE;
 
   if (action & JOY_DOWN)
-    south = 1;
+    south = TRUE;
 
   if (action & JOY_BUTTON_1)
-    snap = 1;
+    snap = TRUE;
 
   if (action & JOY_BUTTON_2)
-    drop = 1;
+    drop = TRUE;
 
   /* always update drop action */
   ply->joy_drop = drop;
@@ -71,6 +75,8 @@ void InitGameEngine_EM(void)
 {
   prepare_em_level();
 
+  logic_init();
+
   game_initscreen();
 
   RedrawPlayfield_EM(FALSE);
@@ -83,12 +89,15 @@ void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
 
   game_em.random = game_em.random * 129 + 1;
 
-  frame = (frame - 1) & 7;
+  frame = (frame + 1) % 8;
 
   for (i = 0; i < MAX_PLAYERS; i++)
     readjoy(action[i], &ply[i]);
 
-  UpdateEngineValues(screen_x / TILEX, screen_y / TILEY, ply[0].x, ply[0].y);
+  UpdateEngineValues(CAVE_POS_X(screen_x / TILEX),
+                    CAVE_POS_Y(screen_y / TILEY),
+                    CAVE_POS_X(ply[0].x),
+                    CAVE_POS_Y(ply[0].y));
 
   logic();
 
@@ -99,8 +108,13 @@ void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode)
        ply[i].dynamite_cnt < 5)
       any_player_dropping = TRUE;
 
-  CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
-                        game_em.any_player_snapping, any_player_dropping);
+  boolean single_step_mode_paused =
+    CheckSingleStepMode_EM(action, frame, game_em.any_player_moving,
+                          game_em.any_player_snapping, any_player_dropping);
+
+  // draw wrapping around before going to single step pause mode
+  if (single_step_mode_paused && logic_check_wrap())
+    logic_move();
 
   RedrawPlayfield_EM(FALSE);
 }