widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #10057
[Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
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-oldsaves/+merge/323442
Fixes problems with loading pre-barracks savegames. These savegames load without problems, but do not have the barracks building allowed. Since at the same time soldiers can no longer be created in the headquarters, continue playing the savegames becomes quite hard.
This branch fixes this problem by enabling the barracks on loading of old savegames. The savegame is recognized by an error in the warehouses when they notice the missing data about recruits in the file. Since this error only happens with old savegames, the barracks are not enabled for new savegames from e.g. the campaign (where the barracks are disabled by design).
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands.
=== modified file 'data/tribes/atlanteans.lua'
--- data/tribes/atlanteans.lua 2016-12-03 16:37:13 +0000
+++ data/tribes/atlanteans.lua 2017-04-30 12:47:37 +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-04-30 12:47:37 +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-04-30 12:47:37 +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-04-30 12:47:37 +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-04-30 12:47:37 +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-04-30 12:47:37 +0000
@@ -366,6 +366,26 @@
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);
+ // Check if it is an recruit. If it is, enable barracks.
+ // We are most likely loading a pre-barracks savegame in that case, so when not
+ // adding the barracks the game becomes unplayable. Note that this might be strange in
+ // old savegames of campaigns or scenarios (e.g. barracks allowed but no weapons possible)
+ const DescriptionIndex barracks_id = owner().tribe().barracks();
+ const ProductionSiteDescr* barracksDescr =
+ dynamic_cast<const ProductionSiteDescr*>(owner().tribe().get_building_descr(barracks_id));
+ assert(barracksDescr != nullptr);
+ const BillOfMaterials& recruits = barracksDescr->input_workers();
+ for (const WareAmount& amount : recruits) {
+ if (amount.first == worker_index) {
+ // The found worker is one input of the barracks -> a recruit
+ // Enable barracks
+ if (!owner().is_building_type_allowed(barracks_id)) {
+ log("WARNING: Enabling barracks for player %u\n", owner().player_number());
+ owner().allow_building_type(barracks_id, true);
+ }
+ break;
+ }
+ }
}
}
Follow ups
-
[Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: GunChleoc, 2017-05-03
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: GunChleoc, 2017-05-02
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: Notabilis, 2017-05-01
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: Notabilis, 2017-05-01
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: GunChleoc, 2017-05-01
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: GunChleoc, 2017-05-01
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: Notabilis, 2017-04-30
-
[Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: bunnybot, 2017-04-30
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: Notabilis, 2017-04-30
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1685331-oldsaves into lp:widelands
From: GunChleoc, 2017-04-30