added limiting amoeba handling in EM engine to the playfield area
[rocksndiamonds.git] / src / game_em / logic.c
index 0fec08c951243376901045fb92447573d7ad593f..d126415b774a3e8357a72a3189386f613a6b5cb7 100644 (file)
@@ -1228,7 +1228,7 @@ static void check_player(struct PLAYER *ply)
 
 static void set_nearest_player_xy(int x, int y, int *dx, int *dy)
 {
-  int distance, distance_shortest = EM_MAX_CAVE_WIDTH + EM_MAX_CAVE_HEIGHT;
+  int distance, distance_shortest = CAVE_WIDTH + CAVE_HEIGHT;
   int i;
 
   /* default values if no players are alive anymore */
@@ -6210,9 +6210,9 @@ void logic_1(void)
   int start_check_nr;
   int i;
 
-  cave = Cave;
-  next = Next;
-  boom = Boom;
+  cave = lev.cave;
+  next = lev.next;
+  boom = lev.boom;
 
   game_em.any_player_moving = FALSE;
   game_em.any_player_snapping = FALSE;
@@ -6266,15 +6266,15 @@ void logic_2(void)
 {
   int x, y;
 
-  cave = Cave;
-  next = Next;
-  boom = Boom;
+  cave = lev.cave;
+  next = lev.next;
+  boom = lev.boom;
 
   seed = RandomEM;
   score = 0;
 
-  for (y = 1; y < HEIGHT - 1; y++)
-    for (x = 0; x < 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)
@@ -6285,10 +6285,10 @@ void logic_2(void)
   RandomEM = seed;
 
   /* triple buffering */
-  void *temp = Cave;
-  Cave = Next;
-  Next = Draw;
-  Draw = temp;
+  void *temp = lev.cave;
+  lev.cave = lev.next;
+  lev.next = lev.draw;
+  lev.draw = temp;
 }
 
 void logic_3(void)
@@ -6298,9 +6298,9 @@ void logic_3(void)
   int count;
   unsigned int random;
 
-  cave = Cave;
-  next = Next;
-  boom = Boom;
+  cave = lev.cave;
+  next = lev.next;
+  boom = lev.boom;
 
   /* update variables */
 
@@ -6334,10 +6334,12 @@ void logic_3(void)
 
   for (count = lev.amoeba_time; count--;)
   {
-    x = (random >> 10) % (WIDTH - 2);
-    y = (random >> 20) % (HEIGHT - 2);
+    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 +6348,13 @@ void logic_3(void)
 
   /* handle explosions */
 
-  for (y = 1; y < HEIGHT - 1; y++)
-    for (x = 1; x < 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 < HEIGHT; y++)
-    for (x = 0; x < WIDTH; x++)
-      Next[x][y] = Cave[x][y];
+  for (y = lev.top; y < lev.bottom; y++)
+    for (x = lev.left; x < lev.right; x++)
+      next[x][y] = cave[x][y];
 }