added using global levelset identifier and level number for network games
authorHolger Schemel <info@artsoft.org>
Thu, 30 Aug 2018 19:51:16 +0000 (21:51 +0200)
committerHolger Schemel <info@artsoft.org>
Thu, 30 Aug 2018 19:56:40 +0000 (21:56 +0200)
This change/addition was required for correctly handling identifiers
and level numbers when playing network games (for which the related
levelset possibly does not exist locally, but was sent by the network
server). This includes showing the correct level number for the level
that is played over the network, and saving the resulting high scores
for the correct level in the correct levelset score directory (again,
even if this levelset or level number does not exist locally).

src/files.c
src/game.c
src/libgame/setup.c

index bb1ce49770b1e3b4a85995485ecb586cd958b0b6..efbc26f8cb2797a1784498ae81fedea88e140acf 100644 (file)
@@ -8281,7 +8281,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)))
   {
index a84acfb8f5b90cfe87c819c8e270b4aec70d6e49..d63944fa4acd4bd6c9437a917624103ee9b6a406 100644 (file)
@@ -2224,8 +2224,8 @@ void UpdateGameControlValues()
 
   /* update game panel control values */
 
-  /* use "level.file_info.nr" instead of "level_nr" (for network games) */
-  game_panel_controls[GAME_PANEL_LEVEL_NUMBER].value = level.file_info.nr;
+  /* used instead of "level_nr" (for network games) */
+  game_panel_controls[GAME_PANEL_LEVEL_NUMBER].value = levelset.level_nr;
   game_panel_controls[GAME_PANEL_GEMS].value = gems;
 
   game_panel_controls[GAME_PANEL_INVENTORY_COUNT].value = 0;
@@ -4661,7 +4661,6 @@ void GameWon()
 void GameEnd()
 {
   int hi_pos;
-  int last_level_nr = level_nr;
 
   local_player->LevelSolved_GameEnd = TRUE;
 
@@ -4717,13 +4716,14 @@ void GameEnd()
     }
   }
 
-  hi_pos = NewHiScore(last_level_nr);
+  /* used instead of last "level_nr" (for network games) */
+  hi_pos = NewHiScore(levelset.level_nr);
 
   if (hi_pos >= 0 && !setup.skip_scores_after_game)
   {
     SetGameStatus(GAME_MODE_SCORES);
 
-    DrawHallOfFame(last_level_nr, hi_pos);
+    DrawHallOfFame(levelset.level_nr, hi_pos);
   }
   else if (setup.auto_play_next_level && setup.increment_levels &&
           !network_playing)
index 802c673a54d232db51dc336d6b0de18e0878eb7c..e9f2848699502377b2693522e834dc19c9cefc09 100644 (file)
@@ -569,7 +569,9 @@ 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;
 }