(svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
authorrubidium
Mon, 28 May 2007 21:32:26 +0000
changeset 6734 b87538491b71
parent 6733 733f7bbba1fb
child 6735 dd792fed65e2
(svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
src/tunnelbridge_cmd.cpp
--- a/src/tunnelbridge_cmd.cpp	Mon May 28 20:46:59 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Mon May 28 21:32:26 2007 +0000
@@ -1325,7 +1325,14 @@
 	if (new_player != PLAYER_SPECTATOR) {
 		SetTileOwner(tile, new_player);
 	} else {
-		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+		if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+			/* When clearing the bridge/tunnel failed there are still vehicles on/in
+			 * the bridge/tunnel. As all *our* vehicles are already removed, they
+			 * must be of another owner. Therefor this must be a road bridge/tunnel.
+			 * In that case we can safely reassign the ownership to OWNER_NONE. */
+			assert((IsTunnel(tile) ? GetTunnelTransportType(tile) : GetBridgeTransportType(tile)) == TRANSPORT_ROAD);
+			SetTileOwner(tile, OWNER_NONE);
+		}
 	}
 }