rnd-20040310-1-src
[rocksndiamonds.git] / src / files.c
index a6b41e1ba640f2a226a87288ce45b98304be3971..154d228e6257993a10f00e67c448000976756128 100644 (file)
@@ -29,7 +29,7 @@
 #define CHUNK_SIZE_NONE                -1      /* do not write chunk size    */
 #define FILE_VERS_CHUNK_SIZE   8       /* size of file version chunk */
 #define LEVEL_HEADER_SIZE      80      /* size of level file header  */
-#define LEVEL_HEADER_UNUSED    7       /* unused level header bytes  */
+#define LEVEL_HEADER_UNUSED    6       /* unused level header bytes  */
 #define LEVEL_CHUNK_CNT2_SIZE  160     /* size of level CNT2 chunk   */
 #define LEVEL_CHUNK_CNT2_UNUSED        11      /* unused CNT2 chunk bytes    */
 #define LEVEL_CHUNK_CNT3_HEADER        16      /* size of level CNT3 header  */
@@ -164,6 +164,8 @@ static void setLevelInfoToDefaults(struct LevelInfo *level)
 
   level->can_move_into_acid_bits = ~0; /* everything can move into acid */
 
+  level->player_can_fall_into_acid = TRUE;
+
   level->use_step_counter = FALSE;
 
   level->use_custom_template = FALSE;
@@ -289,7 +291,7 @@ static void setLevelInfoToDefaults(struct LevelInfo *level)
 
   BorderElement = EL_STEELWALL;
 
-  level->no_level_file = FALSE;
+  level->no_valid_file = FALSE;
 
   if (leveldir_current == NULL)                /* only when dumping level */
     return;
@@ -687,6 +689,8 @@ static int LoadLevel_HEAD(FILE *file, int chunk_size, struct LevelInfo *level)
 
   level->use_step_counter      = (getFile8Bit(file) == 1 ? TRUE : FALSE);
 
+  level->player_can_fall_into_acid = (getFile8Bit(file) == 1 ? TRUE : FALSE);
+
   ReadUnusedBytesFromFile(file, LEVEL_HEADER_UNUSED);
 
   return chunk_size;
@@ -1182,7 +1186,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
 
   if (!(file = fopen(filename, MODE_READ)))
   {
-    level->no_level_file = TRUE;
+    level->no_valid_file = TRUE;
 
     if (level != &level_template)
       Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
@@ -1198,6 +1202,8 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
     getFileChunkBE(file, chunk_name, NULL);
     if (strcmp(chunk_name, "CAVE") != 0)
     {
+      level->no_valid_file = TRUE;
+
       Error(ERR_WARN, "unknown format of level file '%s'", filename);
       fclose(file);
       return;
@@ -1212,6 +1218,8 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
 
     if (!checkCookieString(cookie, LEVEL_COOKIE_TMPL))
     {
+      level->no_valid_file = TRUE;
+
       Error(ERR_WARN, "unknown format of level file '%s'", filename);
       fclose(file);
       return;
@@ -1219,6 +1227,8 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
 
     if ((level->file_version = getFileVersionFromCookieString(cookie)) == -1)
     {
+      level->no_valid_file = TRUE;
+
       Error(ERR_WARN, "unsupported version of level file '%s'", filename);
       fclose(file);
       return;
@@ -1632,7 +1642,7 @@ static void LoadLevelFromFileInfo_EM(struct LevelInfo *level,
 
   if (!(file = fopen(filename, MODE_READ)))
   {
-    level->no_level_file = TRUE;
+    level->no_valid_file = TRUE;
 
     Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
 
@@ -1824,7 +1834,7 @@ static void LoadLevelFromFileInfo_SP(struct LevelInfo *level,
 
   if (!(file = fopen(filename, MODE_READ)))
   {
-    level->no_level_file = TRUE;
+    level->no_valid_file = TRUE;
 
     Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
 
@@ -1834,7 +1844,7 @@ static void LoadLevelFromFileInfo_SP(struct LevelInfo *level,
   /* position file stream to the requested level inside the level package */
   if (fseek(file, nr * SP_LEVEL_SIZE, SEEK_SET) != 0)
   {
-    level->no_level_file = TRUE;
+    level->no_valid_file = TRUE;
 
     Error(ERR_WARN, "cannot fseek level '%s' -- using empty level", filename);
 
@@ -2415,6 +2425,8 @@ static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level)
 
   putFile8Bit(file, (level->use_step_counter ? 1 : 0));
 
+  putFile8Bit(file, (level->player_can_fall_into_acid ? 1 : 0));
+
   WriteUnusedBytesToFile(file, LEVEL_HEADER_UNUSED);
 }
 
@@ -2928,6 +2940,13 @@ void SaveLevelTemplate()
 
 void DumpLevel(struct LevelInfo *level)
 {
+  if (level->no_valid_file)
+  {
+    Error(ERR_WARN, "cannot dump -- no valid level file found");
+
+    return;
+  }
+
   printf_line("-", 79);
   printf("Level xxx (file version %08d, game version %08d)\n",
         level->file_version, level->game_version);
@@ -2986,6 +3005,8 @@ static void setTapeInfoToDefaults()
   tape.recording = FALSE;
   tape.playing = FALSE;
   tape.pausing = FALSE;
+
+  tape.no_valid_file = FALSE;
 }
 
 static int LoadTape_VERS(FILE *file, int chunk_size, struct TapeInfo *tape)
@@ -3150,7 +3171,15 @@ void LoadTapeFromFilename(char *filename)
   setTapeInfoToDefaults();
 
   if (!(file = fopen(filename, MODE_READ)))
+  {
+    tape.no_valid_file = TRUE;
+
+#if 0
+    Error(ERR_WARN, "cannot read tape '%s' -- using empty tape", filename);
+#endif
+
     return;
+  }
 
   getFileChunkBE(file, chunk_name, NULL);
   if (strcmp(chunk_name, "RND1") == 0)
@@ -3160,6 +3189,8 @@ void LoadTapeFromFilename(char *filename)
     getFileChunkBE(file, chunk_name, NULL);
     if (strcmp(chunk_name, "TAPE") != 0)
     {
+      tape.no_valid_file = TRUE;
+
       Error(ERR_WARN, "unknown format of tape file '%s'", filename);
       fclose(file);
       return;
@@ -3174,6 +3205,8 @@ void LoadTapeFromFilename(char *filename)
 
     if (!checkCookieString(cookie, TAPE_COOKIE_TMPL))
     {
+      tape.no_valid_file = TRUE;
+
       Error(ERR_WARN, "unknown format of tape file '%s'", filename);
       fclose(file);
       return;
@@ -3181,6 +3214,8 @@ void LoadTapeFromFilename(char *filename)
 
     if ((tape.file_version = getFileVersionFromCookieString(cookie)) == -1)
     {
+      tape.no_valid_file = TRUE;
+
       Error(ERR_WARN, "unsupported version of tape file '%s'", filename);
       fclose(file);
       return;
@@ -3397,11 +3432,21 @@ void DumpTape(struct TapeInfo *tape)
 {
   int i, j;
 
+#if 1
+  if (tape->no_valid_file)
+  {
+    Error(ERR_WARN, "cannot dump -- no valid tape file found");
+
+    return;
+  }
+#else
   if (TAPE_IS_EMPTY(*tape))
   {
     Error(ERR_WARN, "no tape available for level %d", tape->level_nr);
+
     return;
   }
+#endif
 
   printf_line("-", 79);
   printf("Tape of Level %03d (file version %08d, game version %08d)\n",