added limiting amoeba handling in EM engine to the playfield area
[rocksndiamonds.git] / src / game_em / convert.c
index c5f563b2397ca4012d752b959becd298e89f86df..65efdcc13f78f88ee89ed9a0851bb08e68620126 100644 (file)
@@ -11,8 +11,6 @@
 #include "main_em.h"
 
 
 #include "main_em.h"
 
 
-#define ALLOW_ROLLING_SPRING
-
 static unsigned char remap_v6[256] =
 {
   /* filter crap for v6 */
 static unsigned char remap_v6[256] =
 {
   /* filter crap for v6 */
@@ -22,11 +20,7 @@ static unsigned char remap_v6[256] =
   0,16,2,18,       36,37,37,37,     40,41,42,43,     44,45,128,128,
   128,148,148,     148,45,45,45,    148,0,57,58,     59,60,61,62,63,
 
   0,16,2,18,       36,37,37,37,     40,41,42,43,     44,45,128,128,
   128,148,148,     148,45,45,45,    148,0,57,58,     59,60,61,62,63,
 
-#ifdef ALLOW_ROLLING_SPRING
   64,65,66,67,     68,69,69,71,     72,73,74,75,     118,75,75,75,
   64,65,66,67,     68,69,69,71,     72,73,74,75,     118,75,75,75,
-#else
-  64,65,66,67,     68,69,69,69,     69,73,74,75,     118,75,75,75,
-#endif
   75,75,75,75,     75,153,153,153,  153,153,153,153, 153,153,153,153,
   153,153,153,99,  100,68,68,68,    68,68,68,68,     68,118,118,118,
   118,118,114,115, 131,118,118,119, 120,121,122,118, 118,118,118,118,
   75,75,75,75,     75,153,153,153,  153,153,153,153, 153,153,153,153,
   153,153,153,99,  100,68,68,68,    68,68,68,68,     68,118,118,118,
   118,118,114,115, 131,118,118,119, 120,121,122,118, 118,118,118,118,
@@ -517,19 +511,23 @@ int cleanup_em_level(unsigned char *src, int length, char *filename)
  * - introduced ALLOW_ROLLING_SPRING; if defined, do NOT turn rolling spring
  *   into regular spring, because this breaks at least E.M.C. Mine 3, level 79
  *   (see comment directly above)
  * - introduced ALLOW_ROLLING_SPRING; if defined, do NOT turn rolling spring
  *   into regular spring, because this breaks at least E.M.C. Mine 3, level 79
  *   (see comment directly above)
+ *
+ * 2020-01-19
+ * - always use BAD_ROLL and ALLOW_ROLLING_SPRING code when converting caves
+ *   (that is, always allow initial rolling objects in caves now)
  */
 
 static unsigned short remap_emerald[256] =
 {
   Xstone,              Xstone,         Xdiamond,       Xdiamond,
   Xalien,              Xalien,         Xblank,         Xblank,
  */
 
 static unsigned short remap_emerald[256] =
 {
   Xstone,              Xstone,         Xdiamond,       Xdiamond,
   Xalien,              Xalien,         Xblank,         Xblank,
-  Xtank_n,             Xtank_e,        Xtank_s,        Xtank_w,
-  Xtank_gon,           Xtank_goe,      Xtank_gos,      Xtank_gow,
+  Xtank_1_n,           Xtank_1_e,      Xtank_1_s,      Xtank_1_w,
+  Xtank_2_n,           Xtank_2_e,      Xtank_2_s,      Xtank_2_w,
 
   Xbomb,               Xbomb,          Xemerald,       Xemerald,
 
   Xbomb,               Xbomb,          Xemerald,       Xemerald,
-  Xbug_n,              Xbug_e,         Xbug_s,         Xbug_w,
-  Xbug_gon,            Xbug_goe,       Xbug_gos,       Xbug_gow,
-  Xdrip_eat,           Xdrip_eat,      Xdrip_eat,      Xdrip_eat,
+  Xbug_1_n,            Xbug_1_e,       Xbug_1_s,       Xbug_1_w,
+  Xbug_2_n,            Xbug_2_e,       Xbug_2_s,       Xbug_2_w,
+  Xdrip,               Xdrip,          Xdrip,          Xdrip,
 
   Xstone,              Xbomb,          Xdiamond,       Xemerald,
   Xwonderwall,         Xnut,           Xnut,           Xnut,
 
   Xstone,              Xbomb,          Xdiamond,       Xemerald,
   Xwonderwall,         Xnut,           Xnut,           Xnut,
@@ -538,56 +536,33 @@ static unsigned short remap_emerald[256] =
 
   Xblank,              Xsand,          Xsand,          Xsand,
   Xsand_stone,         Xsand_stone,    Xsand_stone,    Xsand,
 
   Xblank,              Xsand,          Xsand,          Xsand,
   Xsand_stone,         Xsand_stone,    Xsand_stone,    Xsand,
-  Xstone,              Xgrow_ew,       Xgrow_ns,       Xdynamite_1,
+  Xstone,              Xslidewall_ew,  Xslidewall_ns,  Xdynamite_1,
   Xdynamite_2,         Xdynamite_3,    Xdynamite_4,    Xacid_s,
 
   Xdynamite_2,         Xdynamite_3,    Xdynamite_4,    Xacid_s,
 
-#ifdef ALLOW_ROLLING_SPRING
   Xexit_1,             Xexit_2,        Xexit_3,        Xballoon,
   Xplant,              Xspring,        Xspring_fall,   Xspring_w,
   Xspring_e,           Xball_1,        Xball_2,        Xandroid,
   Xblank,              Xandroid,       Xandroid,       Xandroid,
   Xexit_1,             Xexit_2,        Xexit_3,        Xballoon,
   Xplant,              Xspring,        Xspring_fall,   Xspring_w,
   Xspring_e,           Xball_1,        Xball_2,        Xandroid,
   Xblank,              Xandroid,       Xandroid,       Xandroid,
-#else
-  Xexit_1,             Xexit_2,        Xexit_3,        Xballoon,
-  Xplant,              Xspring,        Xspring,        Xspring,
-  Xspring,             Xball_1,        Xball_2,        Xandroid,
-  Xblank,              Xandroid,       Xandroid,       Xandroid,
-#endif
 
   Xandroid,            Xandroid,       Xandroid,       Xandroid,
   Xandroid,            Xblank,         Xblank,         Xblank,
   Xblank,              Xblank,         Xblank,         Xblank,
   Xblank,              Xblank,         Xblank,         Xblank,
 
 
   Xandroid,            Xandroid,       Xandroid,       Xandroid,
   Xandroid,            Xblank,         Xblank,         Xblank,
   Xblank,              Xblank,         Xblank,         Xblank,
   Xblank,              Xblank,         Xblank,         Xblank,
 
-#ifdef BAD_ROLL
-
-  Xblank,              Xblank,         Xblank,         Xspring_force_w,
-  Xspring_force_e,     Xacid_1,        Xacid_2,        Xacid_3,
+  Xblank,              Xblank,         Xblank,         Xpush_spring_w,
+  Xpush_spring_e,      Xacid_1,        Xacid_2,        Xacid_3,
   Xacid_4,             Xacid_5,        Xacid_6,        Xacid_7,
   Xacid_8,             Xblank,         Xblank,         Xblank,
 
   Xacid_4,             Xacid_5,        Xacid_6,        Xacid_7,
   Xacid_8,             Xblank,         Xblank,         Xblank,
 
-  Xblank,              Xblank,         Xnut_force_w,   Xnut_force_e,
-  Xsteel_1,            Xblank,         Xblank,         Xbomb_force_w,
-  Xbomb_force_e,       Xstone_force_w, Xstone_force_e, Xblank,
+  Xblank,              Xblank,         Xpush_nut_w,    Xpush_nut_e,
+  Xsteel_1,            Xblank,         Xblank,         Xpush_bomb_w,
+  Xpush_bomb_e,                Xpush_stone_w,  Xpush_stone_e,  Xblank,
   Xblank,              Xblank,         Xblank,         Xblank,
 
   Xblank,              Xblank,         Xblank,         Xblank,
 
-#else
-
-  Xblank,              Xblank,         Xblank,         Xspring,
-  Xspring,             Xacid_1,        Xacid_2,        Xacid_3,
-  Xacid_4,             Xacid_5,        Xacid_6,        Xacid_7,
-  Xacid_8,             Xblank,         Xblank,         Xblank,
-
-  Xblank,              Xblank,         Xnut,           Xnut,
-  Xsteel_1,            Xblank,         Xblank,         Xbomb,
-  Xbomb,               Xstone,         Xstone,         Xblank,
-  Xblank,              Xblank,         Xblank,         Xblank,
-
-#endif
-
-  Xblank,              Xround_wall_1,  Xgrass,         Xsteel_1,
+  Xblank,              Xroundwall_1,   Xgrass,         Xsteel_1,
   Xwall_1,             Xkey_1,         Xkey_2,         Xkey_3,
   Xkey_4,              Xdoor_1,        Xdoor_2,        Xdoor_3,
   Xwall_1,             Xkey_1,         Xkey_2,         Xkey_3,
   Xkey_4,              Xdoor_1,        Xdoor_2,        Xdoor_3,
-  Xdoor_4,             Xdripper,       Xfake_door_1,   Xfake_door_2,
+  Xdoor_4,             Xfake_amoeba,   Xfake_door_1,   Xfake_door_2,
 
   Xfake_door_3,                Xfake_door_4,   Xwonderwall,    Xwheel,
   Xsand,               Xacid_nw,       Xacid_ne,       Xacid_sw,
 
   Xfake_door_3,                Xfake_door_4,   Xwonderwall,    Xwheel,
   Xsand,               Xacid_nw,       Xacid_ne,       Xacid_sw,
@@ -600,8 +575,8 @@ static unsigned short remap_emerald[256] =
   Xalpha_comma,                Xalpha_quote,   Xalpha_minus,   Xdynamite,
 
   Xsteel_3,            Xdecor_6,       Xdecor_7,       Xsteel_2,
   Xalpha_comma,                Xalpha_quote,   Xalpha_minus,   Xdynamite,
 
   Xsteel_3,            Xdecor_6,       Xdecor_7,       Xsteel_2,
-  Xround_wall_2,       Xdecor_2,       Xdecor_4,       Xdecor_3,
-  Xwind_nesw,          Xwind_e,        Xwind_s,        Xwind_w,
+  Xroundwall_2,                Xdecor_2,       Xdecor_4,       Xdecor_3,
+  Xwind_any,           Xwind_e,        Xwind_s,        Xwind_w,
   Xwind_n,             Xdirt,          Xplant,         Xkey_5,
 
   Xkey_6,              Xkey_7,         Xkey_8,         Xdoor_5,
   Xwind_n,             Xdirt,          Xplant,         Xkey_5,
 
   Xkey_6,              Xkey_7,         Xkey_8,         Xdoor_5,
@@ -668,8 +643,8 @@ void convert_em_level(unsigned char *src, int file_version)
   for (i = 0; i < 2; i++)
   {
     temp = src[0x830 + i * 2] << 8 | src[0x831 + i * 2];
   for (i = 0; i < 2; i++)
   {
     temp = src[0x830 + i * 2] << 8 | src[0x831 + i * 2];
-    ply[i].x_initial = (temp & 63) + 1;
-    ply[i].y_initial = (temp >> 6 & 31) + 1;
+    ply[i].x_initial = (temp & 63);
+    ply[i].y_initial = (temp >> 6 & 31);
   }
 
   temp = (src[0x834] << 8 | src[0x835]) * 28;
   }
 
   temp = (src[0x834] << 8 | src[0x835]) * 28;
@@ -791,29 +766,29 @@ void convert_em_level(unsigned char *src, int file_version)
 
   if (temp & 32)
   {
 
   if (temp & 32)
   {
-    lev.android_array[Xtank_n]         = Xtank_n;
-    lev.android_array[Xtank_gon]       = Xtank_n;
-    lev.android_array[Ytank_nB]                = Xtank_n;
-    lev.android_array[Ytank_n_e]       = Xtank_n;
-    lev.android_array[Ytank_n_w]       = Xtank_n;
-
-    lev.android_array[Xtank_e]         = Xtank_e;
-    lev.android_array[Xtank_goe]       = Xtank_e;
-    lev.android_array[Ytank_eB]                = Xtank_e;
-    lev.android_array[Ytank_e_s]       = Xtank_e;
-    lev.android_array[Ytank_e_n]       = Xtank_e;
-
-    lev.android_array[Xtank_s]         = Xtank_s;
-    lev.android_array[Xtank_gos]       = Xtank_s;
-    lev.android_array[Ytank_sB]                = Xtank_s;
-    lev.android_array[Ytank_s_w]       = Xtank_s;
-    lev.android_array[Ytank_s_e]       = Xtank_s;
-
-    lev.android_array[Xtank_w]         = Xtank_w;
-    lev.android_array[Xtank_gow]       = Xtank_w;
-    lev.android_array[Ytank_wB]                = Xtank_w;
-    lev.android_array[Ytank_w_n]       = Xtank_w;
-    lev.android_array[Ytank_w_s]       = Xtank_w;
+    lev.android_array[Xtank_1_n]       = Xtank_1_n;
+    lev.android_array[Xtank_2_n]       = Xtank_1_n;
+    lev.android_array[Ytank_nB]                = Xtank_1_n;
+    lev.android_array[Ytank_n_e]       = Xtank_1_n;
+    lev.android_array[Ytank_n_w]       = Xtank_1_n;
+
+    lev.android_array[Xtank_1_e]       = Xtank_1_e;
+    lev.android_array[Xtank_2_e]       = Xtank_1_e;
+    lev.android_array[Ytank_eB]                = Xtank_1_e;
+    lev.android_array[Ytank_e_s]       = Xtank_1_e;
+    lev.android_array[Ytank_e_n]       = Xtank_1_e;
+
+    lev.android_array[Xtank_1_s]       = Xtank_1_s;
+    lev.android_array[Xtank_2_s]       = Xtank_1_s;
+    lev.android_array[Ytank_sB]                = Xtank_1_s;
+    lev.android_array[Ytank_s_w]       = Xtank_1_s;
+    lev.android_array[Ytank_s_e]       = Xtank_1_s;
+
+    lev.android_array[Xtank_1_w]       = Xtank_1_w;
+    lev.android_array[Xtank_2_w]       = Xtank_1_w;
+    lev.android_array[Ytank_wB]                = Xtank_1_w;
+    lev.android_array[Ytank_w_n]       = Xtank_1_w;
+    lev.android_array[Ytank_w_s]       = Xtank_1_w;
   }
 
   if (temp & 64)
   }
 
   if (temp & 64)
@@ -833,29 +808,29 @@ void convert_em_level(unsigned char *src, int file_version)
 
   if (temp & 128)
   {
 
   if (temp & 128)
   {
-    lev.android_array[Xbug_n]          = Xbug_gon;
-    lev.android_array[Xbug_gon]                = Xbug_gon;
-    lev.android_array[Ybug_nB]         = Xbug_gon;
-    lev.android_array[Ybug_n_e]                = Xbug_gon;
-    lev.android_array[Ybug_n_w]                = Xbug_gon;
-
-    lev.android_array[Xbug_e]          = Xbug_goe;
-    lev.android_array[Xbug_goe]                = Xbug_goe;
-    lev.android_array[Ybug_eB]         = Xbug_goe;
-    lev.android_array[Ybug_e_s]                = Xbug_goe;
-    lev.android_array[Ybug_e_n]                = Xbug_goe;
-
-    lev.android_array[Xbug_s]          = Xbug_gos;
-    lev.android_array[Xbug_gos]                = Xbug_gos;
-    lev.android_array[Ybug_sB]         = Xbug_gos;
-    lev.android_array[Ybug_s_w]                = Xbug_gos;
-    lev.android_array[Ybug_s_e]                = Xbug_gos;
-
-    lev.android_array[Xbug_w]          = Xbug_gow;
-    lev.android_array[Xbug_gow]                = Xbug_gow;
-    lev.android_array[Ybug_wB]         = Xbug_gow;
-    lev.android_array[Ybug_w_n]                = Xbug_gow;
-    lev.android_array[Ybug_w_s]                = Xbug_gow;
+    lev.android_array[Xbug_1_n]                = Xbug_2_n;
+    lev.android_array[Xbug_2_n]                = Xbug_2_n;
+    lev.android_array[Ybug_nB]         = Xbug_2_n;
+    lev.android_array[Ybug_n_e]                = Xbug_2_n;
+    lev.android_array[Ybug_n_w]                = Xbug_2_n;
+
+    lev.android_array[Xbug_1_e]                = Xbug_2_e;
+    lev.android_array[Xbug_2_e]                = Xbug_2_e;
+    lev.android_array[Ybug_eB]         = Xbug_2_e;
+    lev.android_array[Ybug_e_s]                = Xbug_2_e;
+    lev.android_array[Ybug_e_n]                = Xbug_2_e;
+
+    lev.android_array[Xbug_1_s]                = Xbug_2_s;
+    lev.android_array[Xbug_2_s]                = Xbug_2_s;
+    lev.android_array[Ybug_sB]         = Xbug_2_s;
+    lev.android_array[Ybug_s_w]                = Xbug_2_s;
+    lev.android_array[Ybug_s_e]                = Xbug_2_s;
+
+    lev.android_array[Xbug_1_w]                = Xbug_2_w;
+    lev.android_array[Xbug_2_w]                = Xbug_2_w;
+    lev.android_array[Ybug_wB]         = Xbug_2_w;
+    lev.android_array[Ybug_w_n]                = Xbug_2_w;
+    lev.android_array[Ybug_w_s]                = Xbug_2_w;
   }
 
   if (temp & 256)
   }
 
   if (temp & 256)
@@ -874,10 +849,10 @@ void convert_em_level(unsigned char *src, int file_version)
     lev.android_array[Xspring_pause]   = Xspring;
     lev.android_array[Xspring_e]       = Xspring;
     lev.android_array[Yspring_eB]      = Xspring;
     lev.android_array[Xspring_pause]   = Xspring;
     lev.android_array[Xspring_e]       = Xspring;
     lev.android_array[Yspring_eB]      = Xspring;
-    lev.android_array[Yspring_kill_eB] = Xspring;
+    lev.android_array[Yspring_alien_eB]        = Xspring;
     lev.android_array[Xspring_w]       = Xspring;
     lev.android_array[Yspring_wB]      = Xspring;
     lev.android_array[Xspring_w]       = Xspring;
     lev.android_array[Yspring_wB]      = Xspring;
-    lev.android_array[Yspring_kill_wB] = Xspring;
+    lev.android_array[Yspring_alien_wB]        = Xspring;
     lev.android_array[Xspring_fall]    = Xspring;
     lev.android_array[Yspring_sB]      = Xspring;
   }
     lev.android_array[Xspring_fall]    = Xspring;
     lev.android_array[Yspring_sB]      = Xspring;
   }
@@ -893,16 +868,16 @@ void convert_em_level(unsigned char *src, int file_version)
 
   if (temp & 2048)
   {
 
   if (temp & 2048)
   {
-    lev.android_array[Xdripper]                = Xdrip_eat;
-    lev.android_array[XdripperB]       = Xdrip_eat;
-    lev.android_array[Xamoeba_1]       = Xdrip_eat;
-    lev.android_array[Xamoeba_2]       = Xdrip_eat;
-    lev.android_array[Xamoeba_3]       = Xdrip_eat;
-    lev.android_array[Xamoeba_4]       = Xdrip_eat;
-    lev.android_array[Xamoeba_5]       = Xdrip_eat;
-    lev.android_array[Xamoeba_6]       = Xdrip_eat;
-    lev.android_array[Xamoeba_7]       = Xdrip_eat;
-    lev.android_array[Xamoeba_8]       = Xdrip_eat;
+    lev.android_array[Xfake_amoeba]    = Xdrip;
+    lev.android_array[Xfake_amoebaB]   = Xdrip;
+    lev.android_array[Xamoeba_1]       = Xdrip;
+    lev.android_array[Xamoeba_2]       = Xdrip;
+    lev.android_array[Xamoeba_3]       = Xdrip;
+    lev.android_array[Xamoeba_4]       = Xdrip;
+    lev.android_array[Xamoeba_5]       = Xdrip;
+    lev.android_array[Xamoeba_6]       = Xdrip;
+    lev.android_array[Xamoeba_7]       = Xdrip;
+    lev.android_array[Xamoeba_8]       = Xdrip;
   }
 
   if (temp & 4096)
   }
 
   if (temp & 4096)
@@ -925,48 +900,6 @@ void convert_em_level(unsigned char *src, int file_version)
        lev.wheel_cnt_initial = lev.wheel_time;
        break;
 
        lev.wheel_cnt_initial = lev.wheel_time;
        break;
 
-#ifndef BAD_ROLL
-      case 0x63:                               /* spring roll left */
-       src[temp - 1] = 0x45;
-       src[temp] = 0x80;
-       break;
-
-      case 0x64:                               /* spring roll right */
-       src[temp + 1] = 0x45;
-       src[temp] = 0x80;
-       break;
-
-      case 0x72:                               /* nut roll left */
-       src[temp - 1] = 0x25;
-       src[temp] = 0x80;
-       break;
-
-      case 0x73:                               /* nut roll right */
-       src[temp + 1] = 0x25;
-       src[temp] = 0x80;
-       break;
-
-      case 0x77:                               /* bomb roll left */
-       src[temp - 1] = 0x10;
-       src[temp] = 0x80;
-       break;
-
-      case 0x78:                               /* bomb roll right */
-       src[temp + 1] = 0x10;
-       src[temp] = 0x80;
-       break;
-
-      case 0x79:                               /* stone roll left */
-       src[temp - 1] = 0x00;
-       src[temp] = 0x80;
-       break;
-
-      case 0x7A:                               /* stone roll right */
-       src[temp + 1] = 0x00;
-       src[temp] = 0x80;
-       break;
-#endif
-
       case 0xA3:                               /* fake blank */
        lev.lenses_cnt_initial = 9999;
        break;
       case 0xA3:                               /* fake blank */
        lev.lenses_cnt_initial = 9999;
        break;
@@ -978,15 +911,15 @@ void convert_em_level(unsigned char *src, int file_version)
   }
 
   /* first fill the complete playfield with the default border element */
   }
 
   /* first fill the complete playfield with the default border element */
-  for (y = 0; y < HEIGHT; y++)
-    for (x = 0; x < WIDTH; x++)
-      native_em_level.cave[x][y] = ZBORDER;
+  for (y = 0; y < CAVE_HEIGHT; y++)
+    for (x = 0; x < CAVE_WIDTH; x++)
+      native_em_level.cave[x][y] = Zborder;
 
   /* then copy the real level contents from level file into the playfield */
   temp = 0;
   for (y = 0; y < lev.height; y++)
     for (x = 0; x < lev.width; x++)
 
   /* then copy the real level contents from level file into the playfield */
   temp = 0;
   for (y = 0; y < lev.height; y++)
     for (x = 0; x < lev.width; x++)
-      native_em_level.cave[x + 1][y + 1] =
+      native_em_level.cave[x][y] =
        get_em_element(src[temp++], file_version);
 
   /* at last, set the two players at their positions in the playfield */
        get_em_element(src[temp++], file_version);
 
   /* at last, set the two players at their positions in the playfield */
@@ -1005,17 +938,20 @@ void prepare_em_level(void)
 
   /* reset all runtime variables to their initial values */
 
 
   /* reset all runtime variables to their initial values */
 
-  for (y = 0; y < HEIGHT; y++)
-    for (x = 0; x < WIDTH; x++)
-      Cave[y][x] = native_em_level.cave[x][y];
+  game_init_cave_buffers();
 
 
-  for (y = 0; y < HEIGHT; y++)
-    for (x = 0; x < WIDTH; x++)
-      Next[y][x] = Cave[y][x];
+  lev.left = CAVE_BUFFER_XOFFSET;
+  lev.top  = CAVE_BUFFER_YOFFSET;
+  lev.right = lev.left + lev.width;
+  lev.bottom = lev.top + lev.height;
 
 
-  for (y = 0; y < HEIGHT; y++)
-    for (x = 0; x < WIDTH; x++)
-      Draw[y][x] = Cave[y][x];
+  for (x = 0; x < lev.width; x++)
+    for (y = 0; y < lev.height; y++)
+      lev.cave[lev.left + x][lev.top + y] = native_em_level.cave[x][y];
+
+  for (x = lev.left; x < lev.right; x++)
+    for (y = lev.top; y < lev.bottom; y++)
+      lev.next[x][y] = lev.draw[x][y] = lev.cave[x][y];
 
   lev.time_initial = lev.time_seconds;
   lev.time = lev.time_initial;
 
   lev.time_initial = lev.time_seconds;
   lev.time = lev.time_initial;
@@ -1056,7 +992,7 @@ void prepare_em_level(void)
     ply[i].exists = 0;
     ply[i].alive_initial = FALSE;
 
     ply[i].exists = 0;
     ply[i].alive_initial = FALSE;
 
-    if (ply[i].x_initial > 0 && ply[i].y_initial > 0)
+    if (ply[i].x_initial != -1 && ply[i].y_initial != -1)
     {
       ply[i].exists = 1;
 
     {
       ply[i].exists = 1;
 
@@ -1088,7 +1024,9 @@ void prepare_em_level(void)
 
        native_em_level.cave[x][y] = Xblank;
 
 
        native_em_level.cave[x][y] = Xblank;
 
-       Cave[y][x] = Next[y][x] = Draw[y][x] = Xblank;
+       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;
       }
     }
   }
       }
     }
   }
@@ -1101,8 +1039,8 @@ void prepare_em_level(void)
     ply[i].dynamite_cnt = 0;
     ply[i].keys = 0;
     ply[i].anim = 0;
     ply[i].dynamite_cnt = 0;
     ply[i].keys = 0;
     ply[i].anim = 0;
-    ply[i].oldx = ply[i].x = ply[i].x_initial;
-    ply[i].oldy = ply[i].y = ply[i].y_initial;
+    ply[i].oldx = ply[i].x = ply[i].x_initial + lev.left;
+    ply[i].oldy = ply[i].y = ply[i].y_initial + lev.top;
     ply[i].last_move_dir = MV_NONE;
     ply[i].joy_n = ply[i].joy_e = ply[i].joy_s = ply[i].joy_w = 0;
     ply[i].joy_snap  = ply[i].joy_drop = 0;
     ply[i].last_move_dir = MV_NONE;
     ply[i].joy_n = ply[i].joy_e = ply[i].joy_s = ply[i].joy_w = 0;
     ply[i].joy_snap  = ply[i].joy_drop = 0;
@@ -1115,6 +1053,9 @@ void prepare_em_level(void)
   // - game_em.use_single_button (default: TRUE)
   // - game_em.use_snap_key_bug (default: FALSE)
 
   // - game_em.use_single_button (default: TRUE)
   // - game_em.use_snap_key_bug (default: FALSE)
 
+  game_em.level_solved = FALSE;
+  game_em.game_over = FALSE;
+
   game_em.any_player_moving = FALSE;
   game_em.any_player_snapping = FALSE;
 
   game_em.any_player_moving = FALSE;
   game_em.any_player_snapping = FALSE;