changeset 14367:de46f55c4e38 draft

(svn r18924) -Fix [NoAI]: AIOrder::GetOrderDestination could return a non-waypoint tile when the waypoint was a multitile waypoint
author yexo <yexo@openttd.org>
date Wed, 27 Jan 2010 12:45:41 +0000
parents be9a32dedb76
children c0763b00a33f
files src/ai/api/ai_order.cpp
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/api/ai_order.cpp
+++ b/src/ai/api/ai_order.cpp
@@ -188,8 +188,7 @@
 		case OT_GOTO_STATION: {
 			const Station *st = ::Station::Get(order->GetDestination());
 			if (st->train_station.tile != INVALID_TILE) {
-				for (uint i = 0; i < st->train_station.w; i++) {
-					TileIndex t = st->train_station.tile + TileDiffXY(i, 0);
+				TILE_AREA_LOOP(t, st->train_station) {
 					if (st->TileBelongsToRailStation(t)) return t;
 				}
 			} else if (st->dock_tile != INVALID_TILE) {
@@ -206,7 +205,16 @@
 			}
 			return INVALID_TILE;
 		}
-		case OT_GOTO_WAYPOINT: return ::Waypoint::Get(order->GetDestination())->xy;
+
+		case OT_GOTO_WAYPOINT: {
+			const Waypoint *wp = ::Waypoint::Get(order->GetDestination());
+			if (wp->train_station.tile != INVALID_TILE) {
+				TILE_AREA_LOOP(t, wp->train_station) {
+					if (wp->TileBelongsToRailStation(t)) return t;
+				}
+			}
+			return INVALID_TILE;
+		}
 		default:               return INVALID_TILE;
 	}
 }