← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1428396 into lp:widelands

 

TiborB has proposed merging lp:~widelands-dev/widelands/bug-1428396 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1428396 in widelands: "savefile broken when enemy deafed"
  https://bugs.launchpad.net/widelands/+bug/1428396

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1428396/+merge/256857

This fixes special situation, when two ships (both in expedition mode) of two players are on same field in the time of game saving.

See the also the bug report. A savefile attached to the bug is functional now and I run regression tests as well.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1428396 into lp:widelands.
=== modified file 'src/game_io/game_player_economies_packet.cc'
--- src/game_io/game_player_economies_packet.cc	2014-09-20 09:37:47 +0000
+++ src/game_io/game_player_economies_packet.cc	2015-04-20 20:00:58 +0000
@@ -64,11 +64,16 @@
 
 							Bob* bob = map[read_map_index_32(&fr, max_index)].get_first_bob();
 							while (bob) {
-								if (upcast(Ship const, ship, bob)) {
-									assert(ship->get_economy());
-									EconomyDataPacket d(ship->get_economy());
-									d.read(fr);
-									read_this_economy = true;
+								if (upcast(Ship, ship, bob)) {
+
+									//We are interested only in curent player's ships
+									if (ship->get_owner() == player) {
+										assert(ship->get_economy());
+										EconomyDataPacket d(ship->get_economy());
+										d.read(fr);
+										read_this_economy = true;
+										break;
+									}
 								}
 								bob = bob->get_next_bob();
 							}
@@ -128,15 +133,18 @@
 			for (Field const* field = &field_0; field < &map[map.max_index()]; ++field) {
 					Bob* bob = field->get_first_bob();
 					while (bob) {
-						if (upcast(Ship const, ship, bob)) {
-							if (ship->get_economy() == temp_economy) {
-								// TODO(sirver): the 0xffffffff is ugly and fragile.
-								fw.unsigned_32(0xffffffff); // Sentinel value.
-								fw.unsigned_32(field - &field_0);
-
-								EconomyDataPacket d(ship->get_economy());
-								d.write(fw);
-								wrote_this_economy = true;
+						if (upcast(Ship, ship, bob)) {
+							if (ship->state_is_expedition()){
+								if (ship->get_economy() == temp_economy) {
+									// TODO(sirver): the 0xffffffff is ugly and fragile.
+									fw.unsigned_32(0xffffffff); // Sentinel value.
+									fw.unsigned_32(field - &field_0);
+	
+									EconomyDataPacket d(ship->get_economy());
+									d.write(fw);
+									wrote_this_economy = true;
+									break;
+								}
 							}
 						}
 						bob = bob->get_next_bob();


Follow ups