added support for wrap-around levels in EM engine
[rocksndiamonds.git] / src / game_em / convert.c
index 5553772e62f6ece5654cf91c702e8cf14adfbed9..d25c4593eb4c1d1817f37382f5ac9c3b44d0f739 100644 (file)
@@ -938,22 +938,34 @@ void prepare_em_level(void)
 
   /* reset all runtime variables to their initial values */
 
+  game_init_cave_buffers();
+
   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 < CAVE_HEIGHT; y++)
-    for (x = 0; x < CAVE_WIDTH; x++)
-      lev.cave[lev.left + x][lev.top + y] = native_em_level.cave[x][y];
+  /* add linked cave buffer columns for wrap-around movement */
+  for (x = 0; x < lev.left; x++)
+  {
+    lev.cavecol[x] = lev.cavecol[lev.width + x];
+    lev.nextcol[x] = lev.nextcol[lev.width + x];
+    lev.drawcol[x] = lev.drawcol[lev.width + x];
+    lev.boomcol[x] = lev.boomcol[lev.width + x];
+
+    lev.cavecol[lev.right + x] = lev.cavecol[lev.left + x];
+    lev.nextcol[lev.right + x] = lev.nextcol[lev.left + x];
+    lev.drawcol[lev.right + x] = lev.drawcol[lev.left + x];
+    lev.boomcol[lev.right + x] = lev.boomcol[lev.left + x];
+  }
 
-  for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
-    for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
-      lev.next[x][y] = lev.cave[x][y];
+  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 (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
-    for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
-      lev.draw[x][y] = lev.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;