rnd-20131028-1-src
[rocksndiamonds.git] / src / files.c
index fd0c4010c290f068d07b1f77b5254c0a71bfb018..0f74fc00a00e31f9ed5843ce4be57b0e40ccfa71 100644 (file)
@@ -2584,13 +2584,21 @@ static int LoadLevel_CNT2(FILE *file, int chunk_size, struct LevelInfo *level)
 {
   int i, x, y;
   int element;
-  int num_contents, content_xsize, content_ysize;
+  int num_contents;
+#if 0
+  int content_xsize, content_ysize;
+#endif
   int content_array[MAX_ELEMENT_CONTENTS][3][3];
 
   element = getMappedElement(getFile16BitBE(file));
   num_contents = getFile8Bit(file);
+#if 1
+  getFile8Bit(file);   /* content x size (unused) */
+  getFile8Bit(file);   /* content y size (unused) */
+#else
   content_xsize = getFile8Bit(file);
   content_ysize = getFile8Bit(file);
+#endif
 
   ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT2_UNUSED);
 
@@ -3356,7 +3364,8 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
   else /* check for pre-2.0 file format with cookie string */
   {
     strcpy(cookie, chunk_name);
-    fgets(&cookie[4], MAX_LINE_LEN - 4, file);
+    if (fgets(&cookie[4], MAX_LINE_LEN - 4, file) == NULL)
+      cookie[4] = '\0';
     if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
       cookie[strlen(cookie) - 1] = '\0';
 
@@ -6408,7 +6417,8 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
   if (level_file_info->packed)
   {
     /* read "magic bytes" from start of file */
-    fgets(magic_bytes, num_magic_bytes + 1, file);
+    if (fgets(magic_bytes, num_magic_bytes + 1, file) == NULL)
+      magic_bytes[0] = '\0';
 
     /* check "magic bytes" for correct file format */
     if (!strPrefix(magic_bytes, "DC2"))
@@ -7580,10 +7590,14 @@ void LoadLevel(int nr)
 
 void LoadLevelInfoOnly(int nr)
 {
+#if 0
   char *filename;
+#endif
 
   setLevelFileInfo(&level.file_info, nr);
+#if 0
   filename = level.file_info.filename;
+#endif
 
   LoadLevelFromFileInfo(&level, &level.file_info, TRUE);
 }
@@ -8787,7 +8801,8 @@ void LoadTapeFromFilename(char *filename)
   else /* check for pre-2.0 file format with cookie string */
   {
     strcpy(cookie, chunk_name);
-    fgets(&cookie[4], MAX_LINE_LEN - 4, file);
+    if (fgets(&cookie[4], MAX_LINE_LEN - 4, file) == NULL)
+      cookie[4] = '\0';
     if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
       cookie[strlen(cookie) - 1] = '\0';
 
@@ -9130,7 +9145,8 @@ void LoadScore(int nr)
     return;
 
   /* check file identifier */
-  fgets(cookie, MAX_LINE_LEN, file);
+  if (fgets(cookie, MAX_LINE_LEN, file) == NULL)
+    cookie[0] = '\0';
   if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
     cookie[strlen(cookie) - 1] = '\0';
 
@@ -9143,10 +9159,12 @@ void LoadScore(int nr)
 
   for (i = 0; i < MAX_SCORE_ENTRIES; i++)
   {
-    fscanf(file, "%d", &highscore[i].Score);
-    fgets(line, MAX_LINE_LEN, file);
+    if (fscanf(file, "%d", &highscore[i].Score) == EOF)
+      Error(ERR_WARN, "fscanf() failed; %s", strerror(errno));
+    if (fgets(line, MAX_LINE_LEN, file) == NULL)
+      line[0] = '\0';
 
-    if (line[strlen(line) - 1] == '\n')
+    if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
       line[strlen(line) - 1] = '\0';
 
     for (line_ptr = line; *line_ptr; line_ptr++)
@@ -9228,8 +9246,11 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS    30
 #define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS      31
 #define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC       32
+#define SETUP_TOKEN_VOLUME_SIMPLE              33
+#define SETUP_TOKEN_VOLUME_LOOPS               34
+#define SETUP_TOKEN_VOLUME_MUSIC               35
 
-#define NUM_GLOBAL_SETUP_TOKENS                        33
+#define NUM_GLOBAL_SETUP_TOKENS                        36
 
 /* editor setup */
 #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH      0
@@ -9372,6 +9393,9 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_SWITCH3,&si.override_level_graphics, "override_level_graphics"        },
   { TYPE_SWITCH3,&si.override_level_sounds,   "override_level_sounds"  },
   { TYPE_SWITCH3,&si.override_level_music,    "override_level_music"   },
+  { TYPE_INTEGER,&si.volume_simple,           "volume_simple"          },
+  { TYPE_INTEGER,&si.volume_loops,            "volume_loops"           },
+  { TYPE_INTEGER,&si.volume_music,            "volume_music"           },
 };
 
 static boolean not_used = FALSE;
@@ -9542,6 +9566,10 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->override_level_sounds = FALSE;
   si->override_level_music = FALSE;
 
+  si->volume_simple = 100;     /* percent */
+  si->volume_loops = 100;      /* percent */
+  si->volume_music = 100;      /* percent */
+
   si->editor.el_boulderdash            = TRUE;
   si->editor.el_emerald_mine           = TRUE;
   si->editor.el_emerald_mine_club      = TRUE;
@@ -9804,7 +9832,8 @@ void SaveSetup()
   {
     /* just to make things nicer :) */
     if (i == SETUP_TOKEN_PLAYER_NAME + 1 ||
-       i == SETUP_TOKEN_GRAPHICS_SET)
+       i == SETUP_TOKEN_GRAPHICS_SET ||
+       i == SETUP_TOKEN_VOLUME_SIMPLE)
       fprintf(file, "\n");
 
     fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i));