added support for wrap-around levels in EM engine
[rocksndiamonds.git] / src / game_em / logic.c
index 808db47d18ef338d4841b642cfc046df2f1bb863..616e80c1d37dfab726e327bc6e195f1bc4aec135 100644 (file)
@@ -6228,6 +6228,16 @@ void logic_1(void)
 
   for (i = 0; i < MAX_PLAYERS; i++)
   {
+    /* check for wrap-around movement */
+    if (ply[i].x < lev.left ||
+       ply[i].x > lev.right - 1)
+    {
+      ply[i].x = (ply[i].x < lev.left ? lev.right - 1 : lev.left);
+
+      game.centered_player_nr_next = i;
+      game.set_centered_player = TRUE;
+    }
+
     ply[i].oldx = ply[i].x;
     ply[i].oldy = ply[i].y;
     ply[i].anim = PLY_still;
@@ -6273,8 +6283,8 @@ void logic_2(void)
   seed = RandomEM;
   score = 0;
 
-  for (y = 1; y < CAVE_BUFFER_HEIGHT - 1; y++)
-    for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
+  for (y = lev.top; y < lev.bottom; y++)
+    for (x = lev.left; x < lev.right; x++)
       handle_tile(x, y);
 
   if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive)
@@ -6337,7 +6347,9 @@ void logic_3(void)
     x = lev.left - 1 + (random >> 10) % CAVE_WIDTH;
     y = lev.top  - 1 + (random >> 20) % CAVE_HEIGHT;
 
-    Lamoeba(x, y);
+    if (x >= lev.left && x < lev.right &&
+       y >= lev.top  && y < lev.bottom)
+      Lamoeba(x, y);
 
     random = random * 129 + 1;
   }
@@ -6346,13 +6358,13 @@ void logic_3(void)
 
   /* handle explosions */
 
-  for (y = 1; y < CAVE_BUFFER_HEIGHT - 1; y++)
-    for (x = 1; x < CAVE_BUFFER_WIDTH - 1; x++)
+  for (y = lev.top; y < lev.bottom; y++)
+    for (x = lev.left; x < lev.right; x++)
       Lexplode(x, y);
 
   /* triple buffering */
 
-  for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
-    for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
+  for (y = lev.top; y < lev.bottom; y++)
+    for (x = lev.left; x < lev.right; x++)
       next[x][y] = cave[x][y];
 }