changed listing all invalid SP level file elements only in debug mode
[rocksndiamonds.git] / src / files.c
index 1f07c4894bd51a5e387e5aa62eb1042b902d8814..85d171287bebb4703b146aa53aa283d27ad2ae37 100644 (file)
@@ -3664,7 +3664,8 @@ void CopyNativeLevel_SP_to_RND(struct LevelInfo *level)
 {
   struct LevelInfo_SP *level_sp = level->native_sp_level;
   LevelInfoType *header = &level_sp->header;
-  int i, x, y;
+  boolean num_invalid_elements = 0;
+  int i, j, x, y;
 
   level->fieldx = level_sp->width;
   level->fieldy = level_sp->height;
@@ -3677,20 +3678,39 @@ void CopyNativeLevel_SP_to_RND(struct LevelInfo *level)
       int element_new = getMappedElement(map_element_SP_to_RND(element_old));
 
       if (element_new == EL_UNKNOWN)
-       Error(ERR_WARN, "invalid element %d at position %d, %d",
+      {
+       num_invalid_elements++;
+
+       Error(ERR_DEBUG, "invalid element %d at position %d, %d",
              element_old, x, y);
+      }
 
       level->field[x][y] = element_new;
     }
   }
 
+  if (num_invalid_elements > 0)
+    Error(ERR_WARN, "found %d invalid elements%s", num_invalid_elements,
+         (!options.debug ? " (use '--debug' for more details)" : ""));
+
   for (i = 0; i < MAX_PLAYERS; i++)
     level->initial_player_gravity[i] =
       (header->InitialGravity == 1 ? TRUE : FALSE);
 
+  /* skip leading spaces */
   for (i = 0; i < SP_LEVEL_NAME_LEN; i++)
-    level->name[i] = header->LevelTitle[i];
-  level->name[SP_LEVEL_NAME_LEN] = '\0';
+    if (header->LevelTitle[i] != ' ')
+      break;
+
+  /* copy level title */
+  for (j = 0; i < SP_LEVEL_NAME_LEN; i++, j++)
+    level->name[j] = header->LevelTitle[i];
+  level->name[j] = '\0';
+
+  /* cut trailing spaces */
+  for (; j > 0; j--)
+    if (level->name[j - 1] == ' ' && level->name[j] == '\0')
+      level->name[j - 1] = '\0';
 
   level->gems_needed = header->InfotronsNeeded;
 
@@ -3820,8 +3840,8 @@ static void CopyNativeTape_SP_to_RND(struct LevelInfo *level)
 
   TapeSetDateFromEpochSeconds(getFileTimestampEpochSeconds(filename));
 
-  tape.length = 0;
-  tape.pos[tape.length].delay = 0;
+  tape.counter = 0;
+  tape.pos[tape.counter].delay = 0;
 
   for (i = 0; i < demo->length; i++)
   {
@@ -3829,41 +3849,23 @@ static void CopyNativeTape_SP_to_RND(struct LevelInfo *level)
     int demo_repeat = (demo->data[i] & 0xf0) >> 4;
     int tape_action = map_key_SP_to_RND(demo_action);
     int tape_repeat = demo_repeat + 1;
-    int tape_entries = 1;      // one new tape entry may be added
+    byte action[MAX_PLAYERS] = { tape_action, 0, 0, 0 };
+    boolean success = 0;
+    int j;
 
-    if (tape.length + tape_entries >= MAX_TAPE_LEN)
+    for (j = 0; j < tape_repeat; j++)
+      success = TapeAddAction(action);
+
+    if (!success)
     {
       Error(ERR_WARN, "SP demo truncated: size exceeds maximum tape size %d",
            MAX_TAPE_LEN);
 
       break;
     }
-
-    if (tape.pos[tape.length].delay > 0)       /* already stored action */
-    {
-      if (tape.pos[tape.length].action[0] != tape_action ||
-         tape.pos[tape.length].delay + tape_repeat >= 256)
-      {
-       tape.length++;
-       tape.pos[tape.length].delay = 0;
-      }
-      else
-      {
-       tape.pos[tape.length].delay += tape_repeat;
-      }
-    }
-
-    if (tape.pos[tape.length].delay == 0)      /* store new action */
-    {
-      tape.pos[tape.length].action[0] = tape_action;
-      tape.pos[tape.length].delay = tape_repeat;
-    }
   }
 
-  tape.length++;
-
-  tape.length_frames  = GetTapeLengthFrames();
-  tape.length_seconds = GetTapeLengthSeconds();
+  TapeHaltRecording();
 }