← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/map_packet_loading into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/map_packet_loading into lp:widelands.

Commit message:
Map compatibility:
- No longer saving or loading unneeded packages in the editor.
- Removed compatibility code from MapBuildingPacket.


Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1531463 in widelands: "Do not load unneeded packages with map loading"
  https://bugs.launchpad.net/widelands/+bug/1531463

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/map_packet_loading/+merge/284470

Old maps now should load fine again, because the unneeded packets are omitted in the editor both when loading and saving.

I have used "Together We're Strong" from Build 18 and "The Green Plateau" as test cases.

Scenarios still load all available map packets, so I have deleted the unneeded ones and also fixed Island Hopping a bit - the hopping doesn't work, but it's already broken in trunk. Also, Smugglers will crash, especially when not using the zip filesystem, but that bug is also already present in trunk.

-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/map_packet_loading into lp:widelands.
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/binary/building'
Binary files maps/MP_Scenarios/Island_Hopping.wmf/binary/building	2010-11-22 11:40:06 +0000 and maps/MP_Scenarios/Island_Hopping.wmf/binary/building	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/binary/exploration'
Binary files maps/MP_Scenarios/Island_Hopping.wmf/binary/exploration	2010-11-22 11:40:06 +0000 and maps/MP_Scenarios/Island_Hopping.wmf/binary/exploration	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/binary/flag'
Binary files maps/MP_Scenarios/Island_Hopping.wmf/binary/flag	2010-11-22 11:40:06 +0000 and maps/MP_Scenarios/Island_Hopping.wmf/binary/flag	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/binary/node_ownership'
Binary files maps/MP_Scenarios/Island_Hopping.wmf/binary/node_ownership	2010-11-22 11:40:06 +0000 and maps/MP_Scenarios/Island_Hopping.wmf/binary/node_ownership	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/binary/road'
Binary files maps/MP_Scenarios/Island_Hopping.wmf/binary/road	2010-11-22 11:40:06 +0000 and maps/MP_Scenarios/Island_Hopping.wmf/binary/road	1970-01-01 00:00:00 +0000 differ
=== removed directory 'maps/MP_Scenarios/Island_Hopping.wmf/player'
=== removed directory 'maps/MP_Scenarios/Island_Hopping.wmf/player/1'
=== removed directory 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/binary'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/binary/areawatchers'
Binary files maps/MP_Scenarios/Island_Hopping.wmf/player/1/binary/areawatchers	2010-11-22 11:40:06 +0000 and maps/MP_Scenarios/Island_Hopping.wmf/player/1/binary/areawatchers	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/messages'
--- maps/MP_Scenarios/Island_Hopping.wmf/player/1/messages	2010-11-22 11:40:06 +0000
+++ maps/MP_Scenarios/Island_Hopping.wmf/player/1/messages	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-# Automatically created by Widelands bzr5747[widelands] (Debug)
-
-[global]
-packet_version="1"

=== removed directory 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/node_immovable_kinds_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/node_immovables_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/owners_0'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/roads_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/survey_amounts_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/survey_times_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/surveys_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/terrains_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/triangle_immovable_kinds_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/triangle_immovables_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/unseen_times_1'
=== removed file 'maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/vision_1'
Binary files maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/vision_1	2010-11-22 11:40:06 +0000 and maps/MP_Scenarios/Island_Hopping.wmf/player/1/view/vision_1	1970-01-01 00:00:00 +0000 differ
=== modified file 'maps/MP_Scenarios/Island_Hopping.wmf/scripting/first_island.lua'
--- maps/MP_Scenarios/Island_Hopping.wmf/scripting/first_island.lua	2015-10-31 12:11:44 +0000
+++ maps/MP_Scenarios/Island_Hopping.wmf/scripting/first_island.lua	2016-01-29 17:11:26 +0000
@@ -3,7 +3,7 @@
 -- ==========================
 function _wait_for_castle_on_finish_area(plr, island_idx)
    local finish_area = _finish_areas[island_idx][plr.number]
-   while not check_for_buildings(plr, {castle=1}, finish_area) do
+   while not check_for_buildings(plr, {atlanteans_castle=1}, finish_area) do
       sleep(1237)
    end
 end

=== modified file 'maps/MP_Scenarios/Island_Hopping.wmf/scripting/texts.lua'
--- maps/MP_Scenarios/Island_Hopping.wmf/scripting/texts.lua	2015-11-21 11:34:10 +0000
+++ maps/MP_Scenarios/Island_Hopping.wmf/scripting/texts.lua	2016-01-29 17:11:26 +0000
@@ -1,42 +1,44 @@
 -- =======================================================================
 --                          Texts for this scenario
 -- =======================================================================
-welcome_msg = rt(
-   h1(_"Welcome to Island Hopping") ..
-   h2(_"Rules") ..
-   p(_(
-[[Island Hopping is a traditional tournament in Atlantean culture. ]] ..
-[[The rules of the game are simple: you start with a headquarters on an island. ]] ..
-[[When you finish a castle at the end of the first island, you are granted a ]] ..
-[[second headquarters on a second island, which will contain all wares from your ]] ..
-[[first headquarters.]]
-)) ..
- p(_(
-[[If you finish a castle in the target area on the second island, you will get ]] ..
-[[a third headquarters on the third island. You must build a castle at ]] ..
-[[the center of the third island and hold it for 20 minutes to win the game.]]
-)) ..
- p(_(
-[[Whenever you finish an island, you will get bonus wares, depending on how many players ]] ..
-[[have finished the island before you. The earlier you finish, the fewer wares you will get. ]] ..
-[[See below for the details.]])) .. p(_(
-[[The point is that the first island only provides rocks and trees, the second only meadows and resources. The economies you leave behind will continue to work for you, but you will only reap the benefits at the moment you reach a new island.]])
-) ..
-p(_
-[[Finally, be careful not to waste your quartz and diamonds.]]
-) ..
-h2(_"Finish Rewards") ..
-h3(_"First Island") ..
-h4(_"1st to finish") .. p(format_rewards(_finish_rewards[1][1])) ..
-h4(_"2nd to finish") .. p(format_rewards(_finish_rewards[1][2])) ..
-h4(_"3rd to finish") .. p(format_rewards(_finish_rewards[1][3])) ..
-h4(_"4th to finish") .. p(format_rewards(_finish_rewards[1][4])) ..
-h3(_"Second Island") ..
-h4(_"1st to finish") .. p(format_rewards(_finish_rewards[2][1])) ..
-h4(_"2nd to finish") .. p(format_rewards(_finish_rewards[2][2])) ..
-h4(_"3rd to finish") .. p(format_rewards(_finish_rewards[2][3])) ..
-h4(_"4th to finish") .. p(format_rewards(_finish_rewards[2][4]))
-)
+welcome_msg = {
+	heading = _"Welcome to Island Hopping",
+   body = rt(
+		h2(_"Rules") ..
+		p(_(
+	[[Island Hopping is a traditional tournament in Atlantean culture. ]] ..
+	[[The rules of the game are simple: you start with a headquarters on an island. ]] ..
+	[[When you finish a castle at the end of the first island, you are granted a ]] ..
+	[[second headquarters on a second island, which will contain all wares from your ]] ..
+	[[first headquarters.]]
+	)) ..
+	 p(_(
+	[[If you finish a castle in the target area on the second island, you will get ]] ..
+	[[a third headquarters on the third island. You must build a castle at ]] ..
+	[[the center of the third island and hold it for 20 minutes to win the game.]]
+	)) ..
+	 p(_(
+	[[Whenever you finish an island, you will get bonus wares, depending on how many players ]] ..
+	[[have finished the island before you. The earlier you finish, the fewer wares you will get. ]] ..
+	[[See below for the details.]])) .. p(_(
+	[[The point is that the first island only provides rocks and trees, the second only meadows and resources. The economies you leave behind will continue to work for you, but you will only reap the benefits at the moment you reach a new island.]])
+	) ..
+	p(_
+	[[Finally, be careful not to waste your quartz and diamonds.]]
+	) ..
+	h2(_"Finish Rewards") ..
+	h3(_"First Island") ..
+	h4(_"1st to finish") .. p(format_rewards(_finish_rewards[1][1])) ..
+	h4(_"2nd to finish") .. p(format_rewards(_finish_rewards[1][2])) ..
+	h4(_"3rd to finish") .. p(format_rewards(_finish_rewards[1][3])) ..
+	h4(_"4th to finish") .. p(format_rewards(_finish_rewards[1][4])) ..
+	h3(_"Second Island") ..
+	h4(_"1st to finish") .. p(format_rewards(_finish_rewards[2][1])) ..
+	h4(_"2nd to finish") .. p(format_rewards(_finish_rewards[2][2])) ..
+	h4(_"3rd to finish") .. p(format_rewards(_finish_rewards[2][3])) ..
+	h4(_"4th to finish") .. p(format_rewards(_finish_rewards[2][4]))
+	)
+}
 
 msgs_finished_island = {
    _"%1$s was the first to reach Island number %2$i.",

=== removed file 'maps/MP_Scenarios/Smugglers.wmf/binary/building'
Binary files maps/MP_Scenarios/Smugglers.wmf/binary/building	2012-04-25 07:39:44 +0000 and maps/MP_Scenarios/Smugglers.wmf/binary/building	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Smugglers.wmf/binary/exploration'
Binary files maps/MP_Scenarios/Smugglers.wmf/binary/exploration	2012-04-25 07:39:44 +0000 and maps/MP_Scenarios/Smugglers.wmf/binary/exploration	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Smugglers.wmf/binary/flag'
Binary files maps/MP_Scenarios/Smugglers.wmf/binary/flag	2012-04-25 07:39:44 +0000 and maps/MP_Scenarios/Smugglers.wmf/binary/flag	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Smugglers.wmf/binary/node_ownership'
Binary files maps/MP_Scenarios/Smugglers.wmf/binary/node_ownership	2012-04-25 07:39:44 +0000 and maps/MP_Scenarios/Smugglers.wmf/binary/node_ownership	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/MP_Scenarios/Smugglers.wmf/binary/road'
Binary files maps/MP_Scenarios/Smugglers.wmf/binary/road	2011-10-01 10:13:21 +0000 and maps/MP_Scenarios/Smugglers.wmf/binary/road	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/Trident_of_Fire.wmf/binary/building'
Binary files maps/Trident_of_Fire.wmf/binary/building	2013-08-15 16:00:17 +0000 and maps/Trident_of_Fire.wmf/binary/building	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/Trident_of_Fire.wmf/binary/exploration'
Binary files maps/Trident_of_Fire.wmf/binary/exploration	2013-08-15 16:00:17 +0000 and maps/Trident_of_Fire.wmf/binary/exploration	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/Trident_of_Fire.wmf/binary/flag'
Binary files maps/Trident_of_Fire.wmf/binary/flag	2013-08-15 16:00:17 +0000 and maps/Trident_of_Fire.wmf/binary/flag	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/Trident_of_Fire.wmf/binary/node_ownership'
Binary files maps/Trident_of_Fire.wmf/binary/node_ownership	2013-08-15 16:00:17 +0000 and maps/Trident_of_Fire.wmf/binary/node_ownership	1970-01-01 00:00:00 +0000 differ
=== removed file 'maps/Trident_of_Fire.wmf/binary/road'
Binary files maps/Trident_of_Fire.wmf/binary/road	2013-08-15 16:00:17 +0000 and maps/Trident_of_Fire.wmf/binary/road	1970-01-01 00:00:00 +0000 differ
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc	2016-01-28 21:27:04 +0000
+++ src/editor/editorinteractive.cc	2016-01-29 17:11:26 +0000
@@ -42,6 +42,7 @@
 #include "logic/map_objects/world/resource_description.h"
 #include "logic/map_objects/world/world.h"
 #include "logic/player.h"
+#include "map_io/map_loader.h"
 #include "map_io/widelands_map_loader.h"
 #include "scripting/lua_interface.h"
 #include "scripting/lua_table.h"
@@ -223,7 +224,7 @@
 		egbase().add_player(p, 0, map.get_scenario_player_tribe(p), map.get_scenario_player_name(p));
 	}
 
-	ml->load_map_complete(egbase(), true);
+	ml->load_map_complete(egbase(), Widelands::MapLoader::LoadType::kEditor);
 	egbase().load_graphics(loader_ui);
 	map_changed(MapWas::kReplaced);
 }

=== modified file 'src/game_io/game_map_packet.cc'
--- src/game_io/game_map_packet.cc	2014-09-20 09:37:47 +0000
+++ src/game_io/game_map_packet.cc	2016-01-29 17:11:26 +0000
@@ -54,7 +54,7 @@
 
 
 void GameMapPacket::read_complete(Game & game) {
-	m_wml->load_map_complete(game, true);
+	m_wml->load_map_complete(game, MapLoader::LoadType::kScenario);
 	m_mol = m_wml->get_map_object_loader();
 }
 

=== modified file 'src/io/filesystem/layered_filesystem.cc'
--- src/io/filesystem/layered_filesystem.cc	2014-11-28 16:40:55 +0000
+++ src/io/filesystem/layered_filesystem.cc	2016-01-29 17:11:26 +0000
@@ -159,7 +159,7 @@
 		if ((*it)->is_writable())
 			return (*it)->write(fname, data, length);
 
-	throw wexception("LayeredFileSystem: No writable filesystem!");
+	throw wexception("LayeredFileSystem: No writable filesystem for %s!", fname.c_str());
 }
 
 /**
@@ -188,7 +188,7 @@
 		if ((*it)->is_writable())
 			return (*it)->open_stream_write(fname);
 
-	throw wexception("LayeredFileSystem: No writable filesystem!");
+	throw wexception("LayeredFileSystem: No writable filesystem for %s!", fname.c_str());
 }
 
 /**
@@ -202,7 +202,7 @@
 		if ((*it)->is_writable())
 			return (*it)->make_directory(dirname);
 
-	throw wexception("LayeredFileSystem: No writable filesystem!");
+	throw wexception("LayeredFileSystem: No writable filesystem for dir: %s!", dirname.c_str());
 }
 
 /**
@@ -216,7 +216,7 @@
 		if ((*it)->is_writable())
 			return (*it)->ensure_directory_exists(dirname);
 
-	throw wexception("LayeredFileSystem: No writable filesystem!");
+	throw wexception("LayeredFileSystem: No writable filesystem for dir: %s!", dirname.c_str());
 }
 
 /**
@@ -231,7 +231,8 @@
 		if ((*it)->is_writable() && (*it)->file_exists(dirname))
 			return (*it)->make_sub_file_system(dirname);
 
-	throw wexception("LayeredFileSystem: unable to create sub filesystem");
+	throw wexception("LayeredFileSystem: unable to create sub filesystem for existing dir: %s",
+						  dirname.c_str());
 }
 
 /**
@@ -246,7 +247,7 @@
 		if ((*it)->is_writable() && !(*it)->file_exists(dirname))
 			return (*it)->create_sub_file_system(dirname, type);
 
-	throw wexception("LayeredFileSystem: unable to create sub filesystem");
+	throw wexception("LayeredFileSystem: unable to create sub filesystem for new dir: %s", dirname.c_str());
 }
 
 /**

=== modified file 'src/logic/game.cc'
--- src/logic/game.cc	2016-01-08 21:00:39 +0000
+++ src/logic/game.cc	2016-01-29 17:11:26 +0000
@@ -254,7 +254,7 @@
 		 	(*this, g_options.pull_section("global"), 1, false));
 
 	loaderUI.step(_("Loading map"));
-	maploader->load_map_complete(*this, true);
+	maploader->load_map_complete(*this, Widelands::MapLoader::LoadType::kScenario);
 	maploader.reset();
 
 	set_game_controller(new SinglePlayerGameController(*this, true, 1));
@@ -340,7 +340,10 @@
 
 	if (loaderUI)
 		loaderUI->step(_("Loading map"));
-	maploader->load_map_complete(*this, settings.scenario);
+	maploader->load_map_complete(*this,
+										  settings.scenario ?
+											  Widelands::MapLoader::LoadType::kScenario :
+											  Widelands::MapLoader::LoadType::kGame);
 
 	// Check for win_conditions
 	if (!settings.scenario) {

=== modified file 'src/logic/map_info.cc'
--- src/logic/map_info.cc	2016-01-24 12:43:26 +0000
+++ src/logic/map_info.cc	2016-01-29 17:11:26 +0000
@@ -85,7 +85,7 @@
 		}
 
 		ml->preload_map(true);
-		ml->load_map_complete(egbase, true);
+		ml->load_map_complete(egbase, Widelands::MapLoader::LoadType::kScenario);
 
 		std::unique_ptr<Texture> minimap(
 		   draw_minimap(egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));

=== modified file 'src/map_io/map_building_packet.cc'
--- src/map_io/map_building_packet.cc	2015-11-28 22:29:26 +0000
+++ src/map_io/map_building_packet.cc	2016-01-29 17:11:26 +0000
@@ -38,8 +38,6 @@
 namespace Widelands {
 
 constexpr uint16_t kCurrentPacketVersion = 3;
-constexpr uint16_t kLowestSupportedVersion = 1;
-constexpr uint16_t kPrioritiesIntroducedInVersion = 2;
 
 // constants to handle special building types
 constexpr uint8_t kTypeBuilding = 0;
@@ -57,7 +55,7 @@
 	InteractiveBase & ibase = *egbase.get_ibase();
 	try {
 		uint16_t const packet_version = fr.unsigned_16();
-		if (packet_version >= kLowestSupportedVersion && packet_version <= kCurrentPacketVersion) {
+		if (packet_version == kCurrentPacketVersion) {
 			Map & map = egbase.map();
 			uint16_t const width  = map.get_width ();
 			uint16_t const height = map.get_height();
@@ -98,10 +96,7 @@
 							}
 
 							mol.register_object<Building> (serial, *building);
-
-							if (packet_version >= kPrioritiesIntroducedInVersion) {
-								read_priorities (*building, fr);
-							}
+							read_priorities (*building, fr);
 
 							//  Reference the players tribe if in editor.
 							if (g_gr) // but not on dedicated servers ;)

=== modified file 'src/map_io/map_loader.h'
--- src/map_io/map_loader.h	2014-10-04 09:40:18 +0000
+++ src/map_io/map_loader.h	2016-01-29 17:11:26 +0000
@@ -36,12 +36,18 @@
 /// must be selected.
 class MapLoader {
 public:
+	enum class LoadType {
+		kGame,
+		kScenario,
+		kEditor
+	};
+
 	MapLoader(const std::string& filename, Map & M)
 		: m_map(M), m_s(STATE_INIT) {m_map.set_filename(filename);}
 	virtual ~MapLoader() {}
 
 	virtual int32_t preload_map(bool as_scenario) = 0;
-	virtual int32_t load_map_complete(EditorGameBase &, bool as_scenario) = 0;
+	virtual int32_t load_map_complete(EditorGameBase &, MapLoader::LoadType) = 0;
 
 	Map & map() {return m_map;}
 

=== modified file 'src/map_io/map_saver.cc'
--- src/map_io/map_saver.cc	2016-01-18 19:08:41 +0000
+++ src/map_io/map_saver.cc	2016-01-29 17:11:26 +0000
@@ -76,6 +76,8 @@
 	delete m_mos;
 	m_mos = new MapObjectSaver();
 
+	bool is_game = is_a(Game, &m_egbase);
+
 	// The binary data is saved in an own directory
 	// to keep it hidden from the poor debuggers
 	m_fs.ensure_directory_exists("binary");
@@ -88,8 +90,7 @@
 	log("took %ums\n ", timer.ms_since_last_query());
 
 	log("Writing Player Names And Tribe Data ... ");
-	{MapPlayerNamesAndTribesPacket p; p.write(m_fs, m_egbase, *m_mos);
-	}
+	{MapPlayerNamesAndTribesPacket p; p.write(m_fs, m_egbase, *m_mos);}
 	log("took %ums\n ", timer.ms_since_last_query());
 	//  PRELOAD DATA END
 
@@ -109,12 +110,15 @@
 	{MapPlayerPositionPacket         p; p.write(m_fs, m_egbase, *m_mos);}
 	log("took %ums\n ", timer.ms_since_last_query());
 
-	//  This must come before anything that references messages, such as:
-	//    * command queue (PlayerMessageCommand, inherited by
-	//      Cmd_MessageSetStatusRead and Cmd_MessageSetStatusArchived)
-	log("Writing Player Message Data ... ");
-	{MapPlayersMessagesPacket        p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
+	// We don't save these when saving a map in the editor.
+	if (is_game) {
+		//  This must come before anything that references messages, such as:
+		//    * command queue (PlayerMessageCommand, inherited by
+		//      Cmd_MessageSetStatusRead and Cmd_MessageSetStatusArchived)
+		log("Writing Player Message Data ... ");
+		{MapPlayersMessagesPacket        p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+	}
 
 	log("Writing Resources Data ... ");
 	{MapResourcesPacket               p; p.write(m_fs, m_egbase);}
@@ -129,20 +133,19 @@
 	{MapVersionPacket               p; p.write(m_fs, m_egbase, *m_mos);}
 	log("took %ums\n ", timer.ms_since_last_query());
 
-
-	const Map & map = m_egbase.map();
-
-	PlayerNumber const nr_players = map.get_nrplayers();
-
-	//  allowed worker types
-	log("Writing Allowed Worker Types Data ... ");
-	{MapAllowedWorkerTypesPacket p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-    //  allowed building types
-    // Not saving this when in editor - it causes issues when changing tribe
-    // after next load in editor
-	if (is_a(Game, &m_egbase)) {
+	// We don't save these when saving a map in the editor.
+	if (is_game) {
+
+		const Map & map = m_egbase.map();
+
+		PlayerNumber const nr_players = map.get_nrplayers();
+
+		//  allowed worker types
+		log("Writing Allowed Worker Types Data ... ");
+		{MapAllowedWorkerTypesPacket p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		 //  allowed building types
 		iterate_players_existing_const(plnum, nr_players, m_egbase, player) {
 			for (DescriptionIndex i = 0; i < m_egbase.tribes().nrbuildings(); ++i) {
 				if (!player->is_building_type_allowed(i)) {
@@ -154,59 +157,64 @@
 				}
 			}
 		} end_find_a_forbidden_building_type_loop:;
+
+		// !!!!!!!!!! NOTE
+		// This packet must be written before any building or road packet. So do not
+		// change this order unless you know what you are doing
+		// EXISTING PACKETS
+		log("Writing Flag Data ... ");
+		{MapFlagPacket                   p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Writing Road Data ... ");
+		{MapRoadPacket                   p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Writing Building Data ... ");
+		{MapBuildingPacket               p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
 	}
 
-	// !!!!!!!!!! NOTE
-	// This packet must be before any building or road packet. So do not
-	// change this order without knowing what you do
-	// EXISTENT PACKETS
-	log("Writing Flag Data ... ");
-	{MapFlagPacket                   p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Writing Road Data ... ");
-	{MapRoadPacket                   p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Writing Building Data ... ");
-	{MapBuildingPacket               p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
+	// We do need to save this one in the editor!
 	log("Writing Map Objects ... ");
 	{MapObjectPacket                      p; p.write(m_fs, m_egbase, *m_mos);}
 	log("took %ums\n ", timer.ms_since_last_query());
 
-	// DATA PACKETS
-	if (m_mos->get_nr_flags()) {
-		log("Writing Flagdata Data ... ");
-		{MapFlagdataPacket            p; p.write(m_fs, m_egbase, *m_mos);}
-		log("took %ums\n ", timer.ms_since_last_query());
-	}
-
-	if (m_mos->get_nr_roads()) {
-		log("Writing Roaddata Data ... ");
-		{MapRoaddataPacket            p; p.write(m_fs, m_egbase, *m_mos);}
-		log("took %ums\n ", timer.ms_since_last_query());
-	}
-
-	if (m_mos->get_nr_buildings()) {
-		log("Writing Buildingdata Data ... ");
-		{MapBuildingdataPacket        p; p.write(m_fs, m_egbase, *m_mos);}
-		log("took %ums\n ", timer.ms_since_last_query());
-	}
-
-	log("Writing Node Ownership Data ... ");
-	{MapNodeOwnershipPacket         p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Writing Exploration Data ... ");
-	{MapExplorationPacket            p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Writing Players Unseen Data ... ");
-	{MapPlayersViewPacket           p; p.write(m_fs, m_egbase, *m_mos);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
+	if (is_game) {
+		// DATA PACKETS
+		if (m_mos->get_nr_flags()) {
+			log("Writing Flagdata Data ... ");
+			{MapFlagdataPacket            p; p.write(m_fs, m_egbase, *m_mos);}
+			log("took %ums\n ", timer.ms_since_last_query());
+		}
+
+		if (m_mos->get_nr_roads()) {
+			log("Writing Roaddata Data ... ");
+			{MapRoaddataPacket            p; p.write(m_fs, m_egbase, *m_mos);}
+			log("took %ums\n ", timer.ms_since_last_query());
+		}
+
+		if (m_mos->get_nr_buildings()) {
+			log("Writing Buildingdata Data ... ");
+			{MapBuildingdataPacket        p; p.write(m_fs, m_egbase, *m_mos);}
+			log("took %ums\n ", timer.ms_since_last_query());
+		}
+
+		log("Writing Node Ownership Data ... ");
+		{MapNodeOwnershipPacket         p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Writing Exploration Data ... ");
+		{MapExplorationPacket            p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Writing Players Unseen Data ... ");
+		{MapPlayersViewPacket           p; p.write(m_fs, m_egbase, *m_mos);}
+		log("took %ums\n ", timer.ms_since_last_query());
+	}
+
+	// We also want to write these in the editor.
 	log("Writing Scripting Data ... ");
 	{MapScriptingPacket              p; p.write(m_fs, m_egbase, *m_mos);}
 	log("took %ums\n ", timer.ms_since_last_query());
@@ -215,9 +223,11 @@
 	{MapObjectivePacket              p; p.write(m_fs, m_egbase, *m_mos);}
 	log("took %ums\n ", timer.ms_since_last_query());
 
-#ifndef NDEBUG
-	m_mos->detect_unsaved_objects();
-#endif
+	if (is_game) {
+		#ifndef NDEBUG
+			m_mos->detect_unsaved_objects();
+		#endif
+	}
 
 	// Write minimap
 	{

=== modified file 'src/map_io/s2map.cc'
--- src/map_io/s2map.cc	2016-01-17 20:04:07 +0000
+++ src/map_io/s2map.cc	2016-01-29 17:11:26 +0000
@@ -359,7 +359,7 @@
  * From now on the Map* can't be set to another one.
  */
 int32_t S2MapLoader::load_map_complete
-	(Widelands::EditorGameBase & egbase, bool)
+	(Widelands::EditorGameBase& egbase, MapLoader::LoadType)
 {
 	ScopedTimer timer("S2MapLoader::load_map_complete() took %ums");
 

=== modified file 'src/map_io/s2map.h'
--- src/map_io/s2map.h	2014-10-04 09:40:18 +0000
+++ src/map_io/s2map.h	2016-01-29 17:11:26 +0000
@@ -38,7 +38,7 @@
 
 	int32_t preload_map(bool) override;
 	virtual int32_t load_map_complete
-		(Widelands::EditorGameBase &, bool scenario) override;
+		(Widelands::EditorGameBase&, Widelands::MapLoader::LoadType) override;
 
 private:
 	const std::string m_filename;

=== modified file 'src/map_io/widelands_map_loader.cc'
--- src/map_io/widelands_map_loader.cc	2016-01-06 19:11:20 +0000
+++ src/map_io/widelands_map_loader.cc	2016-01-29 17:11:26 +0000
@@ -106,11 +106,13 @@
  * Load the complete map and make sure that it runs without problems
  */
 int32_t WidelandsMapLoader::load_map_complete
-	(EditorGameBase & egbase, bool const scenario)
+	(EditorGameBase & egbase, MapLoader::LoadType load_type)
 {
 	ScopedTimer timer("WidelandsMapLoader::load_map_complete() took %ums");
 
-	preload_map(scenario);
+	bool is_game = load_type == MapLoader::LoadType::kGame;
+
+	preload_map(!is_game);
 	m_map.set_size(m_map.m_width, m_map.m_height);
 	m_mol.reset(new MapObjectLoader());
 
@@ -118,7 +120,7 @@
 	// PRELOAD DATA BEGIN
 	log("Reading Elemental Data ... ");
 	MapElementalPacket elemental_data_packet;
-	elemental_data_packet.read(*m_fs, egbase, !scenario, *m_mol);
+	elemental_data_packet.read(*m_fs, egbase, is_game, *m_mol);
 	log("took %ums\n ", timer.ms_since_last_query());
 
 	egbase.allocate_player_maps(); //  Can do this now that map size is known.
@@ -127,7 +129,7 @@
 	log("Reading Player Names And Tribe Data ... ");
 	{
 		MapPlayerNamesAndTribesPacket p;
-		p.read(*m_fs, egbase, !scenario, *m_mol);
+		p.read(*m_fs, egbase, is_game, *m_mol);
 	}
 	log("took %ums\n ", timer.ms_since_last_query());
 	// PRELOAD DATA END
@@ -136,13 +138,13 @@
 		log("Reading Port Spaces Data ... ");
 
 		MapPortSpacesPacket p;
-		p.read(*m_fs, egbase, !scenario, *m_mol);
+		p.read(*m_fs, egbase, is_game, *m_mol);
 
 		log("took %ums\n ", timer.ms_since_last_query());
 	}
 
 	log("Reading Heights Data ... ");
-	{MapHeightsPacket        p; p.read(*m_fs, egbase, !scenario, *m_mol);}
+	{MapHeightsPacket        p; p.read(*m_fs, egbase, is_game, *m_mol);}
 	log("took %ums\n ", timer.ms_since_last_query());
 
 	std::unique_ptr<WorldLegacyLookupTable> world_lookup_table
@@ -161,7 +163,7 @@
 	log("Reading Player Start Position Data ... ");
 	{
 		MapPlayerPositionPacket p;
-		p.read(*m_fs, egbase, !scenario, *m_mol);
+		p.read(*m_fs, egbase, is_game, *m_mol);
 	}
 	log("took %ums\n ", timer.ms_since_last_query());
 
@@ -182,111 +184,117 @@
 	log("took %ums\n ", timer.ms_since_last_query());
 
 	//  NON MANDATORY PACKETS BELOW THIS POINT
-	log("Reading Map Extra Data ... ");
-	{MapExtradataPacket      p; p.read(*m_fs, !scenario);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Map Version Data ... ");
-	{MapVersionPacket      p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-
-	log("Reading Allowed Worker Types Data ... ");
-	{
-		MapAllowedWorkerTypesPacket p;
-		p.read(*m_fs, egbase, !scenario, *m_mol);
-	}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Allowed Building Types Data ... ");
-	{
-		MapAllowedBuildingTypesPacket p;
-		p.read(*m_fs, egbase, !scenario, *m_mol);
-	}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Node Ownership Data ... ");
-	{MapNodeOwnershipPacket p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Exploration Data ... ");
-	{MapExplorationPacket    p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	//  !!!!!!!!!! NOTE
-	//  This packet must be before any building or road packet. So do not change
-	//  this order without knowing what you do
-	//  EXISTENT PACKETS
-	log("Reading Flag Data ... ");
-	{MapFlagPacket           p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Road Data ... ");
-	{MapRoadPacket           p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Building Data ... ");
-	{MapBuildingPacket       p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	//  DATA PACKETS
-	log("Reading Flagdata Data ... ");
-	{MapFlagdataPacket       p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Roaddata Data ... ");
-	{MapRoaddataPacket       p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Reading Buildingdata Data ... ");
-	{MapBuildingdataPacket   p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	log("Second and third phase loading Map Objects ... ");
-	mapobjects.load_finish();
-	{
-		const Field & fields_end = map()[map().max_index()];
-		for (Field * field = &map()[0]; field < &fields_end; ++field)
-			if (BaseImmovable * const imm = field->get_immovable()) {
-				if (upcast(Building const, building, imm))
-					if (field != &map()[building->get_position()])
-						continue; //  not the building's main position
-				imm->load_finish(egbase);
-			}
-	}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	//  This should be at least after loading Soldiers (Bobs).
-	//  NOTE DO NOT CHANGE THE PLACE UNLESS YOU KNOW WHAT ARE YOU DOING
-	//  Must be loaded after every kind of object that can see.
-	log("Reading Players View Data ... ");
-	{MapPlayersViewPacket   p; p.read(*m_fs, egbase, !scenario, *m_mol);}
-	log("took %ums\n ", timer.ms_since_last_query());
-
-	//  This must come before anything that references messages, such as:
-	//    * command queue (PlayerMessageCommand, inherited by
-	//      Cmd_MessageSetStatusRead and Cmd_MessageSetStatusArchived)
-	log("Reading Player Message Data ... ");
-	{
-		MapPlayersMessagesPacket p;
-		p.read(*m_fs, egbase, !scenario, *m_mol);
-	}
-	log("took %ums\n ", timer.ms_since_last_query());
+	// Do not load unneeded packages in the editor
+	if (load_type != MapLoader::LoadType::kEditor) {
+		log("Reading Map Extra Data ... ");
+		{MapExtradataPacket      p; p.read(*m_fs, is_game);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Map Version Data ... ");
+		{MapVersionPacket      p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+
+		log("Reading Allowed Worker Types Data ... ");
+		{
+			MapAllowedWorkerTypesPacket p;
+			p.read(*m_fs, egbase, is_game, *m_mol);
+		}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Allowed Building Types Data ... ");
+		{
+			MapAllowedBuildingTypesPacket p;
+			p.read(*m_fs, egbase, is_game, *m_mol);
+		}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Node Ownership Data ... ");
+		{MapNodeOwnershipPacket p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Exploration Data ... ");
+		{MapExplorationPacket    p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		//  !!!!!!!!!! NOTE
+		//  This packet must be before any building or road packet. So do not change
+		//  this order without knowing what you do
+		//  EXISTENT PACKETS
+		log("Reading Flag Data ... ");
+		{MapFlagPacket           p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Road Data ... ");
+		{MapRoadPacket           p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Building Data ... ");
+		{MapBuildingPacket       p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		//  DATA PACKETS
+		log("Reading Flagdata Data ... ");
+		{MapFlagdataPacket       p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Roaddata Data ... ");
+		{MapRoaddataPacket       p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Reading Buildingdata Data ... ");
+		{MapBuildingdataPacket   p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		log("Second and third phase loading Map Objects ... ");
+		mapobjects.load_finish();
+		{
+			const Field & fields_end = map()[map().max_index()];
+			for (Field * field = &map()[0]; field < &fields_end; ++field)
+				if (BaseImmovable * const imm = field->get_immovable()) {
+					if (upcast(Building const, building, imm))
+						if (field != &map()[building->get_position()])
+							continue; //  not the building's main position
+					imm->load_finish(egbase);
+				}
+		}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		//  This should be at least after loading Soldiers (Bobs).
+		//  NOTE DO NOT CHANGE THE PLACE UNLESS YOU KNOW WHAT ARE YOU DOING
+		//  Must be loaded after every kind of object that can see.
+		log("Reading Players View Data ... ");
+		{MapPlayersViewPacket   p; p.read(*m_fs, egbase, is_game, *m_mol);}
+		log("took %ums\n ", timer.ms_since_last_query());
+
+		//  This must come before anything that references messages, such as:
+		//    * command queue (PlayerMessageCommand, inherited by
+		//      Cmd_MessageSetStatusRead and Cmd_MessageSetStatusArchived)
+		log("Reading Player Message Data ... ");
+		{
+			MapPlayersMessagesPacket p;
+			p.read(*m_fs, egbase, is_game, *m_mol);
+		}
+		log("took %ums\n ", timer.ms_since_last_query());
+	} // load_type != MapLoader::LoadType::kEditor
 
 	//  Objectives
 	log("Reading Objective Data ... ");
-	{MapObjectivePacket      p; p.read(*m_fs, egbase, !scenario, *m_mol);}
+	{MapObjectivePacket      p; p.read(*m_fs, egbase, is_game, *m_mol);}
 	log("took %ums\n ", timer.ms_since_last_query());
 
 	log("Reading Scripting Data ... ");
-	{MapScriptingPacket      p; p.read(*m_fs, egbase, !scenario, *m_mol);}
+	{MapScriptingPacket      p; p.read(*m_fs, egbase, is_game, *m_mol);}
 	log("took %ums\n ", timer.ms_since_last_query());
 
-	if (m_mol->get_nr_unloaded_objects())
-		log
-			("WARNING: There are %i unloaded objects. This is a bug, please "
-			 "consider committing!\n",
-			 m_mol->get_nr_unloaded_objects());
+	if (load_type != MapLoader::LoadType::kEditor) {
+		if (m_mol->get_nr_unloaded_objects()) {
+			log
+				("WARNING: There are %i unloaded objects. This is a bug, please "
+				 "consider committing!\n",
+				 m_mol->get_nr_unloaded_objects());
+		}
+	} // load_type != MapLoader::LoadType::kEditor
 
 	m_map.recalc_whole_map(egbase.world());
 

=== modified file 'src/map_io/widelands_map_loader.h'
--- src/map_io/widelands_map_loader.h	2015-01-27 20:43:52 +0000
+++ src/map_io/widelands_map_loader.h	2016-01-29 17:11:26 +0000
@@ -41,7 +41,7 @@
 	virtual ~WidelandsMapLoader();
 
 	int32_t preload_map(bool) override;
-	int32_t load_map_complete(EditorGameBase &, bool) override;
+	int32_t load_map_complete(EditorGameBase &, MapLoader::LoadType load_type) override;
 
 	MapObjectLoader * get_map_object_loader() {return m_mol.get();}
 


Follow ups