removed 'inline' keyword (compilers are better at this today)
[rocksndiamonds.git] / src / libgame / setup.c
index 1d5a83bfffabcc9c064861e4c20c6ad292026282..80ebcfa79382be6f226be8b0dedce125328c093f 100644 (file)
@@ -31,6 +31,7 @@
 
 
 #define ENABLE_UNUSED_CODE     FALSE   /* for currently unused functions */
+#define DEBUG_NO_CONFIG_FILE   FALSE   /* for extra-verbose debug output */
 
 #define NUM_LEVELCLASS_DESC    8
 
@@ -156,7 +157,7 @@ static char *getLevelSetupDir(char *level_subdir)
   return levelsetup_dir;
 }
 
-static char *getCacheDir()
+static char *getCacheDir(void)
 {
   static char *cache_dir = NULL;
 
@@ -166,6 +167,16 @@ static char *getCacheDir()
   return cache_dir;
 }
 
+static char *getNetworkDir(void)
+{
+  static char *network_dir = NULL;
+
+  if (network_dir == NULL)
+    network_dir = getPath2(getUserGameDataDir(), NETWORK_DIRECTORY);
+
+  return network_dir;
+}
+
 static char *getLevelDirFromTreeInfo(TreeInfo *node)
 {
   static char *level_dir = NULL;
@@ -197,12 +208,28 @@ char *getUserLevelDir(char *level_subdir)
   return userlevel_dir;
 }
 
-char *getCurrentLevelDir()
+char *getNetworkLevelDir(char *level_subdir)
+{
+  static char *network_level_dir = NULL;
+  char *data_dir = getNetworkDir();
+  char *networklevel_subdir = LEVELS_DIRECTORY;
+
+  checked_free(network_level_dir);
+
+  if (level_subdir != NULL)
+    network_level_dir = getPath3(data_dir, networklevel_subdir, level_subdir);
+  else
+    network_level_dir = getPath2(data_dir, networklevel_subdir);
+
+  return network_level_dir;
+}
+
+char *getCurrentLevelDir(void)
 {
   return getLevelDirFromTreeInfo(leveldir_current);
 }
 
-char *getNewUserLevelSubdir()
+char *getNewUserLevelSubdir(void)
 {
   static char *new_level_subdir = NULL;
   char *subdir_prefix = getLoginName();
@@ -240,7 +267,7 @@ static char *getTapeDir(char *level_subdir)
   return tape_dir;
 }
 
-static char *getSolutionTapeDir()
+static char *getSolutionTapeDir(void)
 {
   static char *tape_dir = NULL;
   char *data_dir = getCurrentLevelDir();
@@ -312,7 +339,7 @@ static char *getClassicArtworkDir(int type)
          getDefaultMusicDir(MUS_CLASSIC_SUBDIR) : "");
 }
 
-static char *getUserGraphicsDir()
+static char *getUserGraphicsDir(void)
 {
   static char *usergraphics_dir = NULL;
 
@@ -322,7 +349,7 @@ static char *getUserGraphicsDir()
   return usergraphics_dir;
 }
 
-static char *getUserSoundsDir()
+static char *getUserSoundsDir(void)
 {
   static char *usersounds_dir = NULL;
 
@@ -332,7 +359,7 @@ static char *getUserSoundsDir()
   return usersounds_dir;
 }
 
-static char *getUserMusicDir()
+static char *getUserMusicDir(void)
 {
   static char *usermusic_dir = NULL;
 
@@ -409,7 +436,7 @@ char *setLevelArtworkDir(TreeInfo *ti)
   return *artwork_set_ptr;
 }
 
-inline static char *getLevelArtworkSet(int type)
+static char *getLevelArtworkSet(int type)
 {
   if (leveldir_current == NULL)
     return NULL;
@@ -417,7 +444,7 @@ inline static char *getLevelArtworkSet(int type)
   return LEVELDIR_ARTWORK_SET(leveldir_current, type);
 }
 
-inline static char *getLevelArtworkDir(int type)
+static char *getLevelArtworkDir(int type)
 {
   if (leveldir_current == NULL)
     return UNDEFINED_FILENAME;
@@ -542,12 +569,14 @@ char *getScoreFilename(int nr)
   checked_free(filename);
 
   sprintf(basename, "%03d.%s", nr, SCOREFILE_EXTENSION);
-  filename = getPath2(getScoreDir(leveldir_current->subdir), basename);
+
+  /* used instead of "leveldir_current->subdir" (for network games) */
+  filename = getPath2(getScoreDir(levelset.identifier), basename);
 
   return filename;
 }
 
-char *getSetupFilename()
+char *getSetupFilename(void)
 {
   static char *filename = NULL;
 
@@ -558,12 +587,12 @@ char *getSetupFilename()
   return filename;
 }
 
-char *getDefaultSetupFilename()
+char *getDefaultSetupFilename(void)
 {
   return program.config_filename;
 }
 
-char *getEditorSetupFilename()
+char *getEditorSetupFilename(void)
 {
   static char *filename = NULL;
 
@@ -579,7 +608,7 @@ char *getEditorSetupFilename()
   return filename;
 }
 
-char *getHelpAnimFilename()
+char *getHelpAnimFilename(void)
 {
   static char *filename = NULL;
 
@@ -590,7 +619,7 @@ char *getHelpAnimFilename()
   return filename;
 }
 
-char *getHelpTextFilename()
+char *getHelpTextFilename(void)
 {
   static char *filename = NULL;
 
@@ -601,7 +630,7 @@ char *getHelpTextFilename()
   return filename;
 }
 
-char *getLevelSetInfoFilename()
+char *getLevelSetInfoFilename(void)
 {
   static char *filename = NULL;
   char *basenames[] =
@@ -630,7 +659,7 @@ char *getLevelSetInfoFilename()
   return NULL;
 }
 
-char *getLevelSetTitleMessageBasename(int nr, boolean initial)
+static char *getLevelSetTitleMessageBasename(int nr, boolean initial)
 {
   static char basename[32];
 
@@ -1034,7 +1063,7 @@ void InitScoreDirectory(char *level_subdir)
   createDirectory(getScoreDir(level_subdir), "level score", permissions);
 }
 
-static void SaveUserLevelInfo();
+static void SaveUserLevelInfo(void);
 
 void InitUserLevelDirectory(char *level_subdir)
 {
@@ -1048,6 +1077,17 @@ void InitUserLevelDirectory(char *level_subdir)
   }
 }
 
+void InitNetworkLevelDirectory(char *level_subdir)
+{
+  if (!directoryExists(getNetworkLevelDir(level_subdir)))
+  {
+    createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE);
+    createDirectory(getNetworkDir(), "network data", PERMS_PRIVATE);
+    createDirectory(getNetworkLevelDir(NULL), "main network level", PERMS_PRIVATE);
+    createDirectory(getNetworkLevelDir(level_subdir), "network level", PERMS_PRIVATE);
+  }
+}
+
 void InitLevelSetupDirectory(char *level_subdir)
 {
   createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE);
@@ -1055,7 +1095,7 @@ void InitLevelSetupDirectory(char *level_subdir)
   createDirectory(getLevelSetupDir(level_subdir), "level setup", PERMS_PRIVATE);
 }
 
-void InitCacheDirectory()
+static void InitCacheDirectory(void)
 {
   createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE);
   createDirectory(getCacheDir(), "cache data", PERMS_PRIVATE);
@@ -1066,7 +1106,7 @@ void InitCacheDirectory()
 /* some functions to handle lists of level and artwork directories           */
 /* ------------------------------------------------------------------------- */
 
-TreeInfo *newTreeInfo()
+TreeInfo *newTreeInfo(void)
 {
   return checked_calloc(sizeof(TreeInfo));
 }
@@ -1200,8 +1240,8 @@ TreeInfo *getTreeInfoFromIdentifier(TreeInfo *node, char *identifier)
   return NULL;
 }
 
-TreeInfo *cloneTreeNode(TreeInfo **node_top, TreeInfo *node_parent,
-                       TreeInfo *node, boolean skip_sets_without_levels)
+static TreeInfo *cloneTreeNode(TreeInfo **node_top, TreeInfo *node_parent,
+                              TreeInfo *node, boolean skip_sets_without_levels)
 {
   TreeInfo *node_new;
 
@@ -1228,7 +1268,7 @@ TreeInfo *cloneTreeNode(TreeInfo **node_top, TreeInfo *node_parent,
   return node_new;
 }
 
-void cloneTree(TreeInfo **ti_new, TreeInfo *ti, boolean skip_empty_sets)
+static void cloneTree(TreeInfo **ti_new, TreeInfo *ti, boolean skip_empty_sets)
 {
   TreeInfo *ti_cloned = cloneTreeNode(ti_new, NULL, ti, skip_empty_sets);
 
@@ -1393,7 +1433,7 @@ void sortTreeInfo(TreeInfo **node_first)
 #define FILE_PERMS_PUBLIC_ALL  (MODE_R_ALL | MODE_W_ALL)
 
 
-char *getHomeDir()
+char *getHomeDir(void)
 {
   static char *dir = NULL;
 
@@ -1482,7 +1522,7 @@ char *getUserGameDataDir(void)
   return user_game_data_dir;
 }
 
-char *getSetupDir()
+char *getSetupDir(void)
 {
   return getUserGameDataDir();
 }
@@ -1505,7 +1545,7 @@ static int posix_mkdir(const char *pathname, mode_t mode)
 #endif
 }
 
-static boolean posix_process_running_setgid()
+static boolean posix_process_running_setgid(void)
 {
 #if defined(PLATFORM_UNIX)
   return (getgid() != getegid());
@@ -1548,7 +1588,7 @@ void createDirectory(char *dir, char *text, int permission_class)
   posix_umask(last_umask);             /* restore previous umask */
 }
 
-void InitUserDataDirectory()
+void InitUserDataDirectory(void)
 {
   createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE);
 }
@@ -1792,7 +1832,7 @@ static int keys_are_equal(void *key1, void *key2)
   return (strEqual((char *)key1, (char *)key2));
 }
 
-SetupFileHash *newSetupFileHash()
+SetupFileHash *newSetupFileHash(void)
 {
   SetupFileHash *new_hash =
     create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal);
@@ -2024,7 +2064,9 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename,
 
   if (!(file = openFile(filename, MODE_READ)))
   {
+#if DEBUG_NO_CONFIG_FILE
     Error(ERR_DEBUG, "cannot open configuration file '%s'", filename);
+#endif
 
     return FALSE;
   }
@@ -2165,7 +2207,7 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename,
   return TRUE;
 }
 
-void saveSetupFileHash(SetupFileHash *hash, char *filename)
+static void saveSetupFileHash(SetupFileHash *hash, char *filename)
 {
   FILE *file;
 
@@ -2749,7 +2791,7 @@ static TreeInfo *createTopTreeInfoNode(TreeInfo *node_first)
 /* functions for handling level and custom artwork info cache                 */
 /* -------------------------------------------------------------------------- */
 
-static void LoadArtworkInfoCache()
+static void LoadArtworkInfoCache(void)
 {
   InitCacheDirectory();
 
@@ -2771,7 +2813,7 @@ static void LoadArtworkInfoCache()
     artworkinfo_cache_new = newSetupFileHash();
 }
 
-static void SaveArtworkInfoCache()
+static void SaveArtworkInfoCache(void)
 {
   char *filename = getPath2(getCacheDir(), ARTWORKINFO_CACHE_FILE);
 
@@ -2966,7 +3008,9 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first,
 
   if (setup_file_hash == NULL)
   {
+#if DEBUG_NO_CONFIG_FILE
     Error(ERR_WARN, "ignoring level directory '%s'", directory_path);
+#endif
 
     free(directory_path);
     free(filename);
@@ -3124,7 +3168,7 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first,
          level_directory);
 }
 
-boolean AdjustGraphicsForEMC()
+boolean AdjustGraphicsForEMC(void)
 {
   boolean settings_changed = FALSE;
 
@@ -3134,7 +3178,7 @@ boolean AdjustGraphicsForEMC()
   return settings_changed;
 }
 
-void LoadLevelInfo()
+void LoadLevelInfo(void)
 {
   InitUserLevelDirectory(getLoginName());
 
@@ -3204,8 +3248,10 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
 
     if (!valid_file_found)
     {
+#if DEBUG_NO_CONFIG_FILE
       if (!strEqual(directory_name, "."))
        Error(ERR_WARN, "ignoring artwork directory '%s'", directory_path);
+#endif
 
       free(directory_path);
       free(filename);
@@ -3377,7 +3423,7 @@ static TreeInfo *getDummyArtworkInfo(int type)
   return artwork_new;
 }
 
-void LoadArtworkInfo()
+void LoadArtworkInfo(void)
 {
   LoadArtworkInfoCache();
 
@@ -3457,8 +3503,8 @@ void LoadArtworkInfo()
 #endif
 }
 
-void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
-                                 LevelDirTree *level_node)
+static void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
+                                        LevelDirTree *level_node)
 {
   int type = (*artwork_node)->type;
 
@@ -3513,7 +3559,7 @@ void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
   }
 }
 
-void LoadLevelArtworkInfo()
+void LoadLevelArtworkInfo(void)
 {
   print_timestamp_init("LoadLevelArtworkInfo");
 
@@ -3658,7 +3704,7 @@ TreeInfo *getArtworkTreeInfoForUserLevelSet(int type)
   return getTreeInfoFromIdentifier(artwork_first_node, artwork_set);
 }
 
-boolean checkIfCustomArtworkExistsForCurrentLevelSet()
+boolean checkIfCustomArtworkExistsForCurrentLevelSet(void)
 {
   char *graphics_set =
     getArtworkIdentifierForUserLevelSet(ARTWORK_TYPE_GRAPHICS);
@@ -3817,7 +3863,7 @@ boolean CreateUserLevelSet(char *level_subdir, char *level_name,
   return TRUE;
 }
 
-static void SaveUserLevelInfo()
+static void SaveUserLevelInfo(void)
 {
   CreateUserLevelSet(getLoginName(), getLoginName(), getRealName(), 100, FALSE);
 }
@@ -3929,7 +3975,7 @@ char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr)
   return line;
 }
 
-void LoadLevelSetup_LastSeries()
+void LoadLevelSetup_LastSeries(void)
 {
   /* ----------------------------------------------------------------------- */
   /* ~/.<program>/levelsetup.conf                                            */
@@ -4009,17 +4055,17 @@ static void SaveLevelSetup_LastSeries_Ext(boolean deactivate_last_level_series)
   free(filename);
 }
 
-void SaveLevelSetup_LastSeries()
+void SaveLevelSetup_LastSeries(void)
 {
   SaveLevelSetup_LastSeries_Ext(FALSE);
 }
 
-void SaveLevelSetup_LastSeries_Deactivate()
+void SaveLevelSetup_LastSeries_Deactivate(void)
 {
   SaveLevelSetup_LastSeries_Ext(TRUE);
 }
 
-static void checkSeriesInfo()
+static void checkSeriesInfo(void)
 {
   static char *level_directory = NULL;
   Directory *dir;
@@ -4041,7 +4087,7 @@ static void checkSeriesInfo()
   closeDirectory(dir);
 }
 
-void LoadLevelSetup_SeriesInfo()
+void LoadLevelSetup_SeriesInfo(void)
 {
   char *filename;
   SetupFileHash *level_setup_hash = NULL;
@@ -4139,7 +4185,7 @@ void LoadLevelSetup_SeriesInfo()
   free(filename);
 }
 
-void SaveLevelSetup_SeriesInfo()
+void SaveLevelSetup_SeriesInfo(void)
 {
   char *filename;
   char *level_subdir = leveldir_current->subdir;