fixed support for wrap-around levels in EM engine for old tapes
[rocksndiamonds.git] / src / game_em / convert.c
index 03dacc4e4f5d132d903617559447d285fa3b9f7a..bae0130c3920adcd4ed56a4e3e0ea4a0474855d5 100644 (file)
@@ -376,9 +376,9 @@ void prepare_em_level(void)
   for (i = 0; i < GAME_TILE_MAX; i++)
     lev.android_array[i] = map[cav.android_array[i]];
 
-  /* determine number of players in this level */
   lev.home_initial = 0;
 
+  /* check for players in this level */
   for (i = 0; i < MAX_PLAYERS; i++)
   {
     ply[i].exists = FALSE;
@@ -401,46 +401,56 @@ void prepare_em_level(void)
   lev.home = lev.home_initial;
   players_left = lev.home_initial;
 
+  /* assign active players */
   for (i = 0; i < MAX_PLAYERS; i++)
   {
-    if (ply[i].exists)
+    if (ply[i].exists && isActivePlayer_EM(i))
     {
       if (players_left)
       {
        ply[i].alive = TRUE;
        players_left--;
       }
-      else
-      {
-       int x = cav.player_x[i];
-       int y = cav.player_y[i];
+    }
+  }
 
-       lev.cave[lev.left + x][lev.top + y] = Xblank;
-       lev.next[lev.left + x][lev.top + y] = Xblank;
-       lev.draw[lev.left + x][lev.top + y] = Xblank;
-      }
+  /* remove inactive players */
+  for (i = 0; i < MAX_PLAYERS; i++)
+  {
+    if (ply[i].exists && !ply[i].alive)
+    {
+      int x = cav.player_x[i];
+      int y = cav.player_y[i];
+
+      lev.cave[lev.left + x][lev.top + y] = Xblank;
+      lev.next[lev.left + x][lev.top + y] = Xblank;
+      lev.draw[lev.left + x][lev.top + y] = Xblank;
     }
   }
 
   for (i = 0; i < MAX_PLAYERS; i++)
   {
     ply[i].num = i;
-    ply[i].dynamite = 0;
-    ply[i].dynamite_cnt = 0;
-    ply[i].keys = 0;
     ply[i].anim = PLY_still;
+
     ply[i].x = cav.player_x[i] + lev.left;
     ply[i].y = cav.player_y[i] + lev.top;
     ply[i].prev_x = ply[i].x;
     ply[i].prev_y = ply[i].y;
+
+    ply[i].dynamite    = 0;
+    ply[i].dynamite_cnt        = 0;
+    ply[i].keys                = 0;
+
     ply[i].last_move_dir = MV_NONE;
-    ply[i].joy_n = 0;
-    ply[i].joy_e = 0;
-    ply[i].joy_s = 0;
-    ply[i].joy_w = 0;
-    ply[i].joy_snap = 0;
-    ply[i].joy_drop = 0;
-    ply[i].joy_stick = 0;
+
+    ply[i].joy_n       = FALSE;
+    ply[i].joy_e       = FALSE;
+    ply[i].joy_s       = FALSE;
+    ply[i].joy_w       = FALSE;
+    ply[i].joy_snap    = FALSE;
+    ply[i].joy_drop    = FALSE;
+    ply[i].joy_stick   = FALSE;
   }
 
   // the following engine variables are initialized to version-specific values
@@ -449,6 +459,7 @@ void prepare_em_level(void)
   // - game_em.use_single_button (default: TRUE)
   // - game_em.use_snap_key_bug (default: FALSE)
   // - game_em.use_old_explosions (default: FALSE)
+  // - game_em.use_wrap_around (default: TRUE)
 
   game_em.level_solved = FALSE;
   game_em.game_over = FALSE;