← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1797213-idle-wares-at-flags-carrier into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1797213-idle-wares-at-flags-carrier into lp:widelands.

Commit message:
Fixing ware staying at flag if its destination changes while it is carried.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1797213 in widelands: "Sometimes ware(s) are lying at a flag and get not transported."
  https://bugs.launchpad.net/widelands/+bug/1797213

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1797213-idle-wares-at-flags-carrier/+merge/357920

If a ware ends being requested while it is carried, it will be dropped at the next flag and not touched again. To reproduce:

- Start a new game
- Start building a Quarry and connect it to the warehouse/HQ
- While the carrier is carrying the ware, set the allowed number of trunks in the construction site to zero
- The ware will now be placed at the next flag and won't be moved again (that is: not being transported back to the warehouse)

This can be repeated over and over again in both directions (to construction site / to warehouse):
- Changing the request while the ware is carried will result in the ware getting stuck
- Changing the request while the ware is at a flag will work correctly
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1797213-idle-wares-at-flags-carrier into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/carrier.cc'
--- src/logic/map_objects/tribes/carrier.cc	2018-09-04 15:48:47 +0000
+++ src/logic/map_objects/tribes/carrier.cc	2018-10-28 20:06:36 +0000
@@ -216,13 +216,19 @@
 			return schedule_act(game, 20);
 		}
 
-		WareInstance* otherware = flag.fetch_pending_ware(game, otherware_idx);
-
 		if (ware) {
+			const bool ware_astray = (ware->get_next_move_step(game) == nullptr);
 			// Drop our ware
 			flag.add_ware(game, *fetch_carried_ware(game));
+			// If the destination of the dropped ware changed while carrying it and we don't have
+			// anything else we should carry, we might pick it up again immediately, so check again
+			if (ware_astray && otherware_idx == kNotFoundAppropriate) {
+				otherware_idx = flag.find_pending_ware(otherflag);
+			}
 		}
 
+		WareInstance* otherware = flag.fetch_pending_ware(game, otherware_idx);
+
 		// Pick up new load, if any
 		if (otherware) {
 			// pay before getting the ware, while checking for road promotion


Follow ups