← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1422347-no-scenario-replays into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1422347-no-scenario-replays into lp:widelands.

Commit message:
Stop writing replays for scenarios. Fixed "Scenario" localization for loadgame.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1422347 in widelands: "Replay for tutorial not working"
  https://bugs.launchpad.net/widelands/+bug/1422347

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1422347-no-scenario-replays/+merge/289582

In the attached bug, we decided not to write replays for scenarios, because the dialog boxes will break playing the replay.

So, you should get replays for new games or loadgames that aren't scenarios only.

This will only work with savegames created with this branch - older scenario savegames will still load unless you played them in English.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1422347-no-scenario-replays into lp:widelands.
=== modified file 'src/game_io/game_preload_packet.cc'
--- src/game_io/game_preload_packet.cc	2016-03-02 17:28:39 +0000
+++ src/game_io/game_preload_packet.cc	2016-03-20 16:09:57 +0000
@@ -46,6 +46,11 @@
 constexpr uint16_t kCurrentPacketVersion = 6;
 constexpr const char* kMinimapFilename = "minimap.png";
 
+std::string GamePreloadPacket::get_localized_win_condition() const {
+	i18n::Textdomain td("win_conditions");
+	return _(win_condition_);
+}
+
 void GamePreloadPacket::read
 	(FileSystem & fs, Game &, MapObjectLoader * const)
 {

=== modified file 'src/game_io/game_preload_packet.h'
--- src/game_io/game_preload_packet.h	2016-03-02 17:28:39 +0000
+++ src/game_io/game_preload_packet.h	2016-03-20 16:09:57 +0000
@@ -39,18 +39,19 @@
 	void read (FileSystem &, Game &, MapObjectLoader * = nullptr) override;
 	void write(FileSystem &, Game &, MapObjectSaver  * = nullptr) override;
 
-	char const * get_mapname()      {return mapname_.c_str();}
-	std::string get_background()    {return background_;}
-	std::string get_win_condition() {return win_condition_;}
-	uint32_t get_gametime() {return gametime_;}
-	uint8_t get_player_nr() {return player_nr_;}
-	std::string get_version() {return version_;}
-
-	uint8_t get_number_of_players() {return number_of_players_;}
-	std::string get_minimap_path() {return minimap_path_;}
-
-	time_t get_savetimestamp() {return savetimestamp_;}
-	GameController::GameType get_gametype() {return gametype_;}
+	char const * get_mapname()      const {return mapname_.c_str();}
+	std::string get_background()    const {return background_;}
+	std::string get_win_condition() const {return win_condition_;}
+	std::string get_localized_win_condition() const;
+	uint32_t get_gametime() const {return gametime_;}
+	uint8_t get_player_nr() const {return player_nr_;}
+	std::string get_version() const {return version_;}
+
+	uint8_t get_number_of_players() const {return number_of_players_;}
+	std::string get_minimap_path() const {return minimap_path_;}
+
+	time_t get_savetimestamp() const {return savetimestamp_;}
+	GameController::GameType get_gametype() const {return gametype_;}
 
 private:
 	std::string minimap_path_;

=== modified file 'src/logic/game.cc'
--- src/logic/game.cc	2016-03-19 11:47:00 +0000
+++ src/logic/game.cc	2016-03-20 16:09:57 +0000
@@ -206,6 +206,9 @@
 bool Game::run_splayer_scenario_direct(const std::string& mapname, const std::string& script_to_run) {
 	assert(!get_map());
 
+	// Replays can't handle scenarios
+	set_write_replay(false);
+
 	set_map(new Map);
 
 	std::unique_ptr<MapLoader> maploader(map().get_correct_loader(mapname));
@@ -235,7 +238,7 @@
 			 map().get_scenario_player_name (p));
 		get_player(p)->set_ai(map().get_scenario_player_ai(p));
 	}
-	win_condition_displayname_ = _("Scenario");
+	win_condition_displayname_ = "Scenario";
 
 	set_ibase
 		(new InteractivePlayer
@@ -335,7 +338,7 @@
 		std::unique_ptr<LuaCoroutine> cr = table->get_coroutine("func");
 		enqueue_command(new CmdLuaCoroutine(get_gametime() + 100, cr.release()));
 	} else {
-		win_condition_displayname_ = _("Scenario");
+		win_condition_displayname_ = "Scenario";
 	}
 }
 
@@ -361,6 +364,10 @@
 		Widelands::GamePreloadPacket gpdp;
 		gl.preload_game(gpdp);
 		win_condition_displayname_ = gpdp.get_win_condition();
+		if (win_condition_displayname_ == "Scenario") {
+			// Replays can't handle scenarios
+			set_write_replay(false);
+		}
 		std::string background(gpdp.get_background());
 		loader_ui->set_background(background);
 		loader_ui->step(_("Loading…"));
@@ -390,6 +397,10 @@
 		gl.preload_game(gpdp);
 		std::string background(gpdp.get_background());
 		win_condition_displayname_ = gpdp.get_win_condition();
+		if (win_condition_displayname_ == "Scenario") {
+			// Replays can't handle scenarios
+			set_write_replay(false);
+		}
 		loader_ui.set_background(background);
 		player_nr = gpdp.get_player_nr();
 		set_ibase
@@ -467,6 +478,8 @@
 			}
 		} else {
 			// Is a scenario!
+			// Replays can't handle scenarios
+			set_write_replay(false);
 			iterate_players_existing_novar(p, nr_players, *this) {
 				if (!map().get_starting_pos(p))
 				throw WLWarning

=== modified file 'src/ui_fsmenu/loadgame.cc'
--- src/ui_fsmenu/loadgame.cc	2016-02-07 16:31:06 +0000
+++ src/ui_fsmenu/loadgame.cc	2016-03-20 16:09:57 +0000
@@ -530,10 +530,7 @@
 				}
 			}
 
-			{
-				i18n::Textdomain td("win_conditions");
-				gamedata.wincondition = _(gpdp.get_win_condition());
-			}
+			gamedata.wincondition = _(gpdp.get_localized_win_condition());
 			gamedata.minimap_path = gpdp.get_minimap_path();
 			games_data_.push_back(gamedata);
 

=== modified file 'src/wui/game_main_menu_save_game.cc'
--- src/wui/game_main_menu_save_game.cc	2016-03-10 15:00:32 +0000
+++ src/wui/game_main_menu_save_game.cc	2016-03-20 16:09:57 +0000
@@ -176,7 +176,7 @@
 		// Keep label empty
 		players_label_.set_text("");
 	}
-	win_condition_.set_text(gpdp.get_win_condition());
+	win_condition_.set_text(_(gpdp.get_localized_win_condition()));
 }
 
 /**


Follow ups