← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1685331-always-enable into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1685331-always-enable into lp:widelands.

Commit message:
Savegame compatibility: If the Barracks is the only building not allowed when loading a savegame, allow it.

Requested reviews:
  Notabilis (notabilis27)
Related bugs:
  Bug #1685331 in widelands: "Barracks can't be built with old savegames"
  https://bugs.launchpad.net/widelands/+bug/1685331

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1685331-always-enable/+merge/323481
-- 
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1685331-always-enable.
=== modified file 'data/tribes/atlanteans.lua'
--- data/tribes/atlanteans.lua	2016-12-03 16:37:13 +0000
+++ data/tribes/atlanteans.lua	2017-05-02 07:29:42 +0000
@@ -351,4 +351,5 @@
    ship = "atlanteans_ship",
    headquarters = "atlanteans_headquarters",
    port = "atlanteans_port",
+   barracks = "atlanteans_barracks",
 }

=== modified file 'data/tribes/barbarians.lua'
--- data/tribes/barbarians.lua	2016-11-12 06:50:18 +0000
+++ data/tribes/barbarians.lua	2017-05-02 07:29:42 +0000
@@ -284,4 +284,5 @@
    ship = "barbarians_ship",
    headquarters = "barbarians_headquarters",
    port = "barbarians_port",
+   barracks = "barbarians_barracks",
 }

=== modified file 'data/tribes/empire.lua'
--- data/tribes/empire.lua	2016-11-12 06:50:18 +0000
+++ data/tribes/empire.lua	2017-05-02 07:29:42 +0000
@@ -325,4 +325,5 @@
    ship = "empire_ship",
    headquarters = "empire_headquarters",
    port = "empire_port",
+   barracks = "empire_barracks",
 }

=== modified file 'src/logic/map_objects/tribes/tribe_descr.cc'
--- src/logic/map_objects/tribes/tribe_descr.cc	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/tribe_descr.cc	2017-05-02 07:29:42 +0000
@@ -204,6 +204,7 @@
 
 		headquarters_ = add_special_building(table.get_string("headquarters"));
 		port_ = add_special_building(table.get_string("port"));
+		barracks_ = add_special_building(table.get_string("barracks"));
 
 	} catch (const GameDataError& e) {
 		throw GameDataError("tribe %s: %s", name_.c_str(), e.what());
@@ -328,6 +329,10 @@
 	assert(tribes_.building_exists(port_));
 	return port_;
 }
+DescriptionIndex TribeDescr::barracks() const {
+	assert(tribes_.building_exists(barracks_));
+	return barracks_;
+}
 const std::vector<DescriptionIndex>& TribeDescr::worker_types_without_cost() const {
 	return worker_types_without_cost_;
 }

=== modified file 'src/logic/map_objects/tribes/tribe_descr.h'
--- src/logic/map_objects/tribes/tribe_descr.h	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/tribe_descr.h	2017-05-02 07:29:42 +0000
@@ -104,6 +104,7 @@
 	DescriptionIndex ship() const;
 	DescriptionIndex headquarters() const;
 	DescriptionIndex port() const;
+	DescriptionIndex barracks() const;
 	const std::vector<DescriptionIndex>& worker_types_without_cost() const;
 
 	uint32_t frontier_animation() const;
@@ -183,6 +184,7 @@
 	DescriptionIndex ship_;          // The ship that this tribe uses
 	DescriptionIndex headquarters_;  // The tribe's default headquarters, needed by the editor
 	DescriptionIndex port_;          // The port that this tribe uses
+	DescriptionIndex barracks_;      // The barracks to create soldiers
 	std::vector<DescriptionIndex> worker_types_without_cost_;
 	// Order and positioning of wares in the warehouse display
 	WaresOrder wares_order_;

=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
--- src/logic/map_objects/tribes/warehouse.cc	2017-04-23 12:11:19 +0000
+++ src/logic/map_objects/tribes/warehouse.cc	2017-05-02 07:29:42 +0000
@@ -364,8 +364,8 @@
 			    "%s %u at (%i, %i) does not have a next_spawn time set for that "
 			    "worker type; setting it to %u\n",
 			    owner().player_number(),
-			    owner().tribe().get_worker_descr(worker_index)->descname().c_str(),
-			    descr().descname().c_str(), serial(), get_position().x, get_position().y, next_spawn);
+			    owner().tribe().get_worker_descr(worker_index)->name().c_str(),
+			    descr().name().c_str(), serial(), get_position().x, get_position().y, next_spawn);
 		}
 	}
 

=== modified file 'src/map_io/map_allowed_building_types_packet.cc'
--- src/map_io/map_allowed_building_types_packet.cc	2017-01-25 18:55:59 +0000
+++ src/map_io/map_allowed_building_types_packet.cc	2017-05-02 07:29:42 +0000
@@ -85,6 +85,25 @@
 				} catch (const WException& e) {
 					throw GameDataError("player %u (%s): %s", p, tribe.name().c_str(), e.what());
 				}
+
+				// Savegame compatibility: If all buildings except for the barracks are allowed, allow
+				// it too. This will make games playable again except for scenarios that restrict the
+				// number of buildings and need soldier creation.
+				// TODO(Notabilis): Remove this when we break save game compatibility anyway
+				if (!player->is_building_type_allowed(player->tribe().barracks())) {
+					int tribe_buildings = 0;
+					int allowed_buildings = 0;
+					for (const Widelands::DescriptionIndex& index : player->tribe().buildings()) {
+						if (player->is_building_type_allowed(index)) {
+							++allowed_buildings;
+						}
+						++tribe_buildings;
+					}
+					if (tribe_buildings - 1 == allowed_buildings) {
+						log("WARNING: Enabling barracks for player %u.\n", player->player_number());
+						player->allow_building_type(player->tribe().barracks(), true);
+					}
+				}
 			}
 		} else {
 			throw UnhandledVersionError(


Follow ups