fixed compiler warnings (after adding "-Wmissing-prototypes")
[rocksndiamonds.git] / src / files.c
index b590641afc20b05848461be6327ae59081e52da5..4ca23663e68e4bfbd4101ec9aa522a6e57a94b37 100644 (file)
@@ -251,6 +251,12 @@ static struct LevelFileConfigInfo chunk_config_INFO[] =
     &li.auto_count_gems,               FALSE
   },
 
+  {
+    -1,                                        -1,
+    TYPE_BOOLEAN,                      CONF_VALUE_8_BIT(11),
+    &li.solved_by_one_player,          FALSE
+  },
+
   {
     -1,                                        -1,
     -1,                                        -1,
@@ -1398,7 +1404,7 @@ static boolean check_special_flags(char *flag)
   return FALSE;
 }
 
-static struct DateInfo getCurrentDate()
+static struct DateInfo getCurrentDate(void)
 {
   time_t epoch_seconds = time(NULL);
   struct tm *now = localtime(&epoch_seconds);
@@ -1421,7 +1427,7 @@ static void resetEventFlags(struct ElementChangeInfo *change)
     change->has_event[i] = FALSE;
 }
 
-static void resetEventBits()
+static void resetEventBits(void)
 {
   int i;
 
@@ -1862,7 +1868,7 @@ static void setFileInfoToDefaults(struct LevelFileInfo *level_file_info)
 
 int getMappedElement_SB(int, boolean);
 
-static void ActivateLevelTemplate()
+static void ActivateLevelTemplate(void)
 {
   int x, y;
 
@@ -1915,6 +1921,9 @@ static void ActivateLevelTemplate()
     /* overwrite all individual level settings from template level settings */
     level = level_template;
 
+    /* restore level file info */
+    level.file_info = level_backup.file_info;
+
     /* restore playfield size */
     level.fieldx = level_backup.fieldx;
     level.fieldy = level_backup.fieldy;
@@ -1935,14 +1944,13 @@ static void ActivateLevelTemplate()
 
 static char *getLevelFilenameFromBasename(char *basename)
 {
-  static char *filename[2] = { NULL, NULL };
-  int pos = (strEqual(basename, LEVELTEMPLATE_FILENAME) ? 0 : 1);
+  static char *filename = NULL;
 
-  checked_free(filename[pos]);
+  checked_free(filename);
 
-  filename[pos] = getPath2(getCurrentLevelDir(), basename);
+  filename = getPath2(getCurrentLevelDir(), basename);
 
-  return filename[pos];
+  return filename;
 }
 
 static int getFileTypeFromBasename(char *basename)
@@ -2151,12 +2159,12 @@ static int getFiletypeFromID(char *filetype_id)
   return filetype;
 }
 
-char *getLocalLevelTemplateFilename()
+char *getLocalLevelTemplateFilename(void)
 {
   return getDefaultLevelFilename(-1);
 }
 
-char *getGlobalLevelTemplateFilename()
+char *getGlobalLevelTemplateFilename(void)
 {
   /* global variable "leveldir_current" must be modified in the loop below */
   LevelDirTree *leveldir_current_last = leveldir_current;
@@ -2288,11 +2296,22 @@ static void setLevelFileInfo(struct LevelFileInfo *level_file_info, int nr)
   determineLevelFileInfo_Filetype(level_file_info);
 }
 
+static void copyLevelFileInfo(struct LevelFileInfo *lfi_from,
+                             struct LevelFileInfo *lfi_to)
+{
+  lfi_to->nr     = lfi_from->nr;
+  lfi_to->type   = lfi_from->type;
+  lfi_to->packed = lfi_from->packed;
+
+  setString(&lfi_to->basename, lfi_from->basename);
+  setString(&lfi_to->filename, lfi_from->filename);
+}
+
 /* ------------------------------------------------------------------------- */
 /* functions for loading R'n'D level                                         */
 /* ------------------------------------------------------------------------- */
 
-int getMappedElement(int element)
+static int getMappedElement(int element)
 {
   /* remap some (historic, now obsolete) elements */
 
@@ -2343,7 +2362,7 @@ int getMappedElement(int element)
   return element;
 }
 
-int getMappedElementByVersion(int element, int game_version)
+static int getMappedElementByVersion(int element, int game_version)
 {
   /* remap some elements due to certain game version */
 
@@ -3465,7 +3484,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
 /* functions for loading EM level                                            */
 /* ------------------------------------------------------------------------- */
 
-void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
+static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
 {
   static int ball_xy[8][2] =
   {
@@ -3593,7 +3612,7 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
   }
 }
 
-void CopyNativeLevel_EM_to_RND(struct LevelInfo *level)
+static void CopyNativeLevel_EM_to_RND(struct LevelInfo *level)
 {
   static int ball_xy[8][2] =
   {
@@ -3694,7 +3713,7 @@ void CopyNativeLevel_EM_to_RND(struct LevelInfo *level)
 /* functions for loading SP level                                            */
 /* ------------------------------------------------------------------------- */
 
-void CopyNativeLevel_RND_to_SP(struct LevelInfo *level)
+static void CopyNativeLevel_RND_to_SP(struct LevelInfo *level)
 {
   struct LevelInfo_SP *level_sp = level->native_sp_level;
   LevelInfoType *header = &level_sp->header;
@@ -3778,7 +3797,7 @@ void CopyNativeLevel_RND_to_SP(struct LevelInfo *level)
   }
 }
 
-void CopyNativeLevel_SP_to_RND(struct LevelInfo *level)
+static void CopyNativeLevel_SP_to_RND(struct LevelInfo *level)
 {
   struct LevelInfo_SP *level_sp = level->native_sp_level;
   LevelInfoType *header = &level_sp->header;
@@ -3938,7 +3957,7 @@ static void CopyNativeTape_RND_to_SP(struct LevelInfo *level)
   demo->is_available = TRUE;
 }
 
-static void setTapeInfoToDefaults();
+static void setTapeInfoToDefaults(void);
 
 static void CopyNativeTape_SP_to_RND(struct LevelInfo *level)
 {
@@ -3991,7 +4010,7 @@ static void CopyNativeTape_SP_to_RND(struct LevelInfo *level)
 /* functions for loading MM level                                            */
 /* ------------------------------------------------------------------------- */
 
-void CopyNativeLevel_RND_to_MM(struct LevelInfo *level)
+static void CopyNativeLevel_RND_to_MM(struct LevelInfo *level)
 {
   struct LevelInfo_MM *level_mm = level->native_mm_level;
   int x, y;
@@ -4028,7 +4047,7 @@ void CopyNativeLevel_RND_to_MM(struct LevelInfo *level)
        level_mm->field[x][y] = map_element_RND_to_MM(level->field[x][y]);
 }
 
-void CopyNativeLevel_MM_to_RND(struct LevelInfo *level)
+static void CopyNativeLevel_MM_to_RND(struct LevelInfo *level)
 {
   struct LevelInfo_MM *level_mm = level->native_mm_level;
   int x, y;
@@ -4074,7 +4093,8 @@ void CopyNativeLevel_MM_to_RND(struct LevelInfo *level)
 
 #define DC_LEVEL_HEADER_SIZE           344
 
-unsigned short getDecodedWord_DC(unsigned short data_encoded, boolean init)
+static unsigned short getDecodedWord_DC(unsigned short data_encoded,
+                                       boolean init)
 {
   static int last_data_encoded;
   static int offset1;
@@ -4113,7 +4133,7 @@ unsigned short getDecodedWord_DC(unsigned short data_encoded, boolean init)
   return data_decoded;
 }
 
-int getMappedElement_DC(int element)
+static int getMappedElement_DC(int element)
 {
   switch (element)
   {
@@ -6382,6 +6402,10 @@ static void LoadLevel_InitVersion(struct LevelInfo *level)
   /* EM style elements always chain-exploded in R'n'D engine before 3.2.6 */
   if (level->game_version < VERSION_IDENT(3,2,6,0))
     level->em_explodes_by_fire = TRUE;
+
+  /* levels were solved by the first player entering an exit up to 4.1.0.0 */
+  if (level->game_version <= VERSION_IDENT(4,1,0,0))
+    level->solved_by_one_player = TRUE;
 }
 
 static void LoadLevel_InitStandardElements(struct LevelInfo *level)
@@ -6583,6 +6607,16 @@ static void LoadLevel_InitNativeEngines(struct LevelInfo *level)
     CopyNativeLevel_RND_to_Native(level);
 }
 
+static void LoadLevelTemplate_LoadAndInit(void)
+{
+  LoadLevelFromFileInfo(&level_template, &level_template.file_info, FALSE);
+
+  LoadLevel_InitVersion(&level_template);
+  LoadLevel_InitElements(&level_template);
+
+  ActivateLevelTemplate();
+}
+
 void LoadLevelTemplate(int nr)
 {
   if (!fileExists(getGlobalLevelTemplateFilename()))
@@ -6594,22 +6628,27 @@ void LoadLevelTemplate(int nr)
 
   setLevelFileInfo(&level_template.file_info, nr);
 
-  LoadLevelFromFileInfo(&level_template, &level_template.file_info, FALSE);
+  LoadLevelTemplate_LoadAndInit();
+}
 
-  LoadLevel_InitVersion(&level_template);
-  LoadLevel_InitElements(&level_template);
+static void LoadNetworkLevelTemplate(struct NetworkLevelInfo *network_level)
+{
+  copyLevelFileInfo(&network_level->tmpl_info, &level_template.file_info);
 
-  ActivateLevelTemplate();
+  LoadLevelTemplate_LoadAndInit();
 }
 
-void LoadLevel(int nr)
+static void LoadLevel_LoadAndInit(struct NetworkLevelInfo *network_level)
 {
-  setLevelFileInfo(&level.file_info, nr);
-
   LoadLevelFromFileInfo(&level, &level.file_info, FALSE);
 
   if (level.use_custom_template)
-    LoadLevelTemplate(-1);
+  {
+    if (network_level != NULL)
+      LoadNetworkLevelTemplate(network_level);
+    else
+      LoadLevelTemplate(-1);
+  }
 
   LoadLevel_InitVersion(&level);
   LoadLevel_InitElements(&level);
@@ -6618,6 +6657,15 @@ void LoadLevel(int nr)
   LoadLevel_InitNativeEngines(&level);
 }
 
+void LoadLevel(int nr)
+{
+  SetLevelSetInfo(leveldir_current->identifier, nr);
+
+  setLevelFileInfo(&level.file_info, nr);
+
+  LoadLevel_LoadAndInit(NULL);
+}
+
 void LoadLevelInfoOnly(int nr)
 {
   setLevelFileInfo(&level.file_info, nr);
@@ -6625,6 +6673,16 @@ void LoadLevelInfoOnly(int nr)
   LoadLevelFromFileInfo(&level, &level.file_info, TRUE);
 }
 
+void LoadNetworkLevel(struct NetworkLevelInfo *network_level)
+{
+  SetLevelSetInfo(network_level->leveldir_identifier,
+                 network_level->file_info.nr);
+
+  copyLevelFileInfo(&network_level->file_info, &level.file_info);
+
+  LoadLevel_LoadAndInit(network_level);
+}
+
 static int SaveLevel_VERS(FILE *file, struct LevelInfo *level)
 {
   int chunk_size = 0;
@@ -7457,7 +7515,7 @@ void SaveLevel(int nr)
   SaveLevelFromFilename(&level, filename, FALSE);
 }
 
-void SaveLevelTemplate()
+void SaveLevelTemplate(void)
 {
   char *filename = getLocalLevelTemplateFilename();
 
@@ -7527,7 +7585,7 @@ void DumpLevel(struct LevelInfo *level)
 /* tape file functions                                                       */
 /* ========================================================================= */
 
-static void setTapeInfoToDefaults()
+static void setTapeInfoToDefaults(void)
 {
   int i;
 
@@ -7727,7 +7785,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
   return chunk_size;
 }
 
-void LoadTape_SokobanSolution(char *filename)
+static void LoadTape_SokobanSolution(char *filename)
 {
   File *file;
   int move_delay = TILESIZE / level.initial_player_stepsize[0];
@@ -8241,7 +8299,8 @@ void SaveScore(int nr)
   char *filename = getScoreFilename(nr);
   FILE *file;
 
-  InitScoreDirectory(leveldir_current->subdir);
+  /* used instead of "leveldir_current->subdir" (for network games) */
+  InitScoreDirectory(levelset.identifier);
 
   if (!(file = fopen(filename, MODE_WRITE)))
   {
@@ -9220,7 +9279,7 @@ void LoadSetupFromFilename(char *filename)
   }
 }
 
-static void LoadSetup_SpecialPostProcessing()
+static void LoadSetup_SpecialPostProcessing(void)
 {
   char *player_name_new;
 
@@ -9241,7 +9300,7 @@ static void LoadSetup_SpecialPostProcessing()
     MIN(MAX(MIN_SCROLL_DELAY, setup.scroll_delay_value), MAX_SCROLL_DELAY);
 }
 
-void LoadSetup()
+void LoadSetup(void)
 {
   char *filename;
 
@@ -9262,7 +9321,7 @@ void LoadSetup()
   LoadSetup_SpecialPostProcessing();
 }
 
-void LoadSetup_AutoSetup()
+void LoadSetup_AutoSetup(void)
 {
   char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME);
   SetupFileHash *setup_file_hash = NULL;
@@ -9282,7 +9341,7 @@ void LoadSetup_AutoSetup()
   free(filename);
 }
 
-void LoadSetup_EditorCascade()
+void LoadSetup_EditorCascade(void)
 {
   char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
   SetupFileHash *setup_file_hash = NULL;
@@ -9351,7 +9410,7 @@ static void LoadSetup_ReadGameControllerMappings(SetupFileHash *mappings_hash,
   fclose(file);
 }
 
-void SaveSetup()
+void SaveSetup(void)
 {
   char *filename = getSetupFilename();
   FILE *file;
@@ -9464,7 +9523,7 @@ void SaveSetup()
   SetFilePermissions(filename, PERMS_PRIVATE);
 }
 
-void SaveSetup_AutoSetup()
+void SaveSetup_AutoSetup(void)
 {
   char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME);
   FILE *file;
@@ -9492,7 +9551,7 @@ void SaveSetup_AutoSetup()
   free(filename);
 }
 
-void SaveSetup_EditorCascade()
+void SaveSetup_EditorCascade(void)
 {
   char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
   FILE *file;
@@ -9561,7 +9620,7 @@ void SaveSetup_AddGameControllerMapping(char *mapping)
   free(filename);
 }
 
-void LoadCustomElementDescriptions()
+void LoadCustomElementDescriptions(void)
 {
   char *filename = getCustomArtworkConfigFilename(ARTWORK_TYPE_GRAPHICS);
   SetupFileHash *setup_file_hash;
@@ -9623,7 +9682,7 @@ static int get_token_parameter_value(char *token, char *value_raw)
   return get_parameter_value(value_raw, suffix, TYPE_INTEGER);
 }
 
-void InitMenuDesignSettings_Static()
+void InitMenuDesignSettings_Static(void)
 {
   int i;
 
@@ -9638,7 +9697,7 @@ void InitMenuDesignSettings_Static()
   }
 }
 
-static void InitMenuDesignSettings_SpecialPreProcessing()
+static void InitMenuDesignSettings_SpecialPreProcessing(void)
 {
   int i;
 
@@ -9730,7 +9789,7 @@ static void InitMenuDesignSettings_SpecialPreProcessing()
   }
 }
 
-static void InitMenuDesignSettings_SpecialPostProcessing()
+static void InitMenuDesignSettings_SpecialPostProcessing(void)
 {
   static struct
   {
@@ -9759,7 +9818,7 @@ static void InitMenuDesignSettings_SpecialPostProcessing()
       *game_buttons_xy[i].dst = *game_buttons_xy[i].src;
 }
 
-static void InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics()
+static void InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics(void)
 {
   static struct
   {
@@ -10193,7 +10252,7 @@ static void LoadMenuDesignSettingsFromFilename(char *filename)
   freeSetupFileHash(setup_file_hash);
 }
 
-void LoadMenuDesignSettings()
+void LoadMenuDesignSettings(void)
 {
   char *filename_base = UNDEFINED_FILENAME, *filename_local;
 
@@ -10217,7 +10276,7 @@ void LoadMenuDesignSettings()
   InitMenuDesignSettings_SpecialPostProcessing();
 }
 
-void LoadMenuDesignSettings_AfterGraphics()
+void LoadMenuDesignSettings_AfterGraphics(void)
 {
   InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics();
 }
@@ -10419,7 +10478,7 @@ static boolean sound_info_listed(struct MusicFileInfo *list, char *basename)
   return music_info_listed_ext(list, basename, TRUE);
 }
 
-void LoadMusicInfo()
+void LoadMusicInfo(void)
 {
   char *music_directory = getCustomMusicDirectory();
   int num_music = getMusicListSize();
@@ -10546,8 +10605,8 @@ void LoadMusicInfo()
   }
 }
 
-void add_helpanim_entry(int element, int action, int direction, int delay,
-                       int *num_list_entries)
+static void add_helpanim_entry(int element, int action, int direction,
+                              int delay, int *num_list_entries)
 {
   struct HelpAnimInfo *new_list_entry;
   (*num_list_entries)++;
@@ -10563,7 +10622,7 @@ void add_helpanim_entry(int element, int action, int direction, int delay,
   new_list_entry->delay = delay;
 }
 
-void print_unknown_token(char *filename, char *token, int token_nr)
+static void print_unknown_token(char *filename, char *token, int token_nr)
 {
   if (token_nr == 0)
   {
@@ -10575,13 +10634,13 @@ void print_unknown_token(char *filename, char *token, int token_nr)
   Error(ERR_INFO, "- token: '%s'", token);
 }
 
-void print_unknown_token_end(int token_nr)
+static void print_unknown_token_end(int token_nr)
 {
   if (token_nr > 0)
     Error(ERR_INFO_LINE, "-");
 }
 
-void LoadHelpAnimInfo()
+void LoadHelpAnimInfo(void)
 {
   char *filename = getHelpAnimFilename();
   SetupFileList *setup_file_list = NULL, *list;
@@ -10791,7 +10850,7 @@ void LoadHelpAnimInfo()
 #endif
 }
 
-void LoadHelpTextInfo()
+void LoadHelpTextInfo(void)
 {
   char *filename = getHelpTextFilename();
   int i;
@@ -10833,7 +10892,7 @@ void LoadHelpTextInfo()
 
 #define MAX_NUM_CONVERT_LEVELS         1000
 
-void ConvertLevels()
+void ConvertLevels(void)
 {
   static LevelDirTree *convert_leveldir = NULL;
   static int convert_level_nr = -1;
@@ -10945,7 +11004,7 @@ void ConvertLevels()
 /* create and save images for use in level sketches (raw BMP format)         */
 /* ------------------------------------------------------------------------- */
 
-void CreateLevelSketchImages()
+void CreateLevelSketchImages(void)
 {
 #if defined(TARGET_SDL)
   Bitmap *bitmap1;