widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #09010
[Merge] lp:~widelands-dev/widelands/bug-1647033-immovable-packet-no into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1647033-immovable-packet-no into lp:widelands.
Commit message:
Immovables now have a dynamic packet number, so maps will still load with Build 19: The packet number is only increased if the immovable has a former building.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1647033 in widelands: "Editor: packet 'Immovable' incompatibility in B19"
https://bugs.launchpad.net/widelands/+bug/1647033
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1647033-immovable-packet-no/+merge/312530
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1647033-immovable-packet-no into lp:widelands.
=== modified file 'src/logic/map_objects/immovable.cc'
--- src/logic/map_objects/immovable.cc 2016-11-22 19:54:02 +0000
+++ src/logic/map_objects/immovable.cc 2016-12-06 07:39:39 +0000
@@ -532,6 +532,11 @@
==============================
*/
+// We neeed 2 packet versions for map loading: Packet version 7 will load in older versions of
+// Widelands, so we have a dynamic version number - it is only set higher than
+// kCurrentPacketVersionImmovableNoFormerBuildings during saving if we have an immovable with
+// a former building assigned to it.
+constexpr uint8_t kCurrentPacketVersionImmovableNoFormerBuildings = 7;
constexpr uint8_t kCurrentPacketVersionImmovable = 8;
// Supporting older versions for map loading
@@ -554,7 +559,7 @@
imm.position_ = read_coords_32(&fr, egbase().map().extent());
imm.set_position(egbase(), imm.position_);
- if (packet_version >= 8) {
+ if (packet_version > kCurrentPacketVersionImmovableNoFormerBuildings) {
Player* owner = imm.get_owner();
if (owner) {
DescriptionIndex idx = owner->tribe().building_index(fr.string());
@@ -645,7 +650,10 @@
// This is in front because it is required to obtain the description
// necessary to create the Immovable
fw.unsigned_8(HeaderImmovable);
- fw.unsigned_8(kCurrentPacketVersionImmovable);
+ const uint8_t packet_version = former_building_descr_ == nullptr ?
+ kCurrentPacketVersionImmovableNoFormerBuildings :
+ kCurrentPacketVersionImmovable;
+ fw.unsigned_8(packet_version);
if (descr().owner_type() == MapObjectDescr::OwnerType::kTribe) {
if (get_owner() == nullptr)
@@ -662,8 +670,11 @@
fw.unsigned_8(get_owner() ? get_owner()->player_number() : 0);
write_coords_32(&fw, position_);
- if (get_owner()) {
- fw.string(former_building_descr_ ? former_building_descr_->name() : "");
+ if (get_owner() && former_building_descr_) {
+ assert(packet_version > kCurrentPacketVersionImmovableNoFormerBuildings);
+ fw.string(former_building_descr_->name());
+ } else {
+ assert(packet_version == kCurrentPacketVersionImmovableNoFormerBuildings);
}
// Animations
Follow ups