← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1658616-inputqueue-build19 into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1658616-inputqueue-build19 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1658616 in widelands: "InputQueue prevents old savegames from being loaded"
  https://bugs.launchpad.net/widelands/+bug/1658616

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1658616-inputqueue-build19/+merge/315742

Added missing support for loading build19 save games with the InputQueues.

Increases the packet version number of InputQueue, so games created by this branch can not be opened with trunk. Can be avoided but than we have packet version 1 for InputQueue and version 2 for the old WaresQueue.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1658616-inputqueue-build19 into lp:widelands.
=== modified file 'src/economy/input_queue.cc'
--- src/economy/input_queue.cc	2017-01-25 18:55:59 +0000
+++ src/economy/input_queue.cc	2017-01-27 08:07:11 +0000
@@ -120,13 +120,16 @@
 	update();
 }
 
-constexpr uint16_t kCurrentPacketVersion = 1;
+constexpr uint16_t kCurrentPacketVersion = 3;
 
 void InputQueue::read(FileRead& fr, Game& game, MapObjectLoader& mol) {
 
 	uint16_t const packet_version = fr.unsigned_16();
 	try {
-		if (packet_version == kCurrentPacketVersion) {
+		// A bit messy since InputQueue started with packet version 1 but has to support the build19
+		// WaresQueue packets with version 2 and has now be changed to version 3 while fixing
+		// Unfortunately, this will probably crash when loading old pre-buil19 save games
+		if (packet_version == 1 || packet_version == kCurrentPacketVersion) {
 			if (fr.unsigned_8() == 0) {
 				assert(type_ == wwWARE);
 				index_ = owner().tribe().ware_index(fr.c_string());
@@ -145,13 +148,27 @@
 			}
 
 			read_child(fr, game, mol);
-
-			//  Now Economy stuff. We have to add our filled items to the economy.
-			if (owner_.get_economy())
-				add_to_economy(*owner_.get_economy());
+		} else if (packet_version == 2) {
+			assert(type_ == wwWARE);
+			index_ = owner().tribe().ware_index(fr.c_string());
+			max_size_ = fr.unsigned_32();
+			max_fill_ = fr.signed_32();
+			// No read_child() call here, doing it manually since there is no child-version number
+			uint32_t filled = fr.unsigned_32();
+			consume_interval_ = fr.unsigned_32();
+			if (fr.unsigned_8()) {
+				request_.reset(new Request(owner_, 0, InputQueue::request_callback, type_));
+				request_->read(fr, game, mol);
+			} else {
+				request_.reset();
+			}
+			set_filled(filled);
 		} else {
 			throw UnhandledVersionError("InputQueue", packet_version, kCurrentPacketVersion);
 		}
+		//  Now Economy stuff. We have to add our filled items to the economy.
+		if (owner_.get_economy())
+			add_to_economy(*owner_.get_economy());
 	} catch (const GameDataError& e) {
 		throw GameDataError("inputqueue: %s", e.what());
 	}