diff options
author | frosch <frosch@openttd.org> | 2010-02-22 20:36:20 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-02-22 20:36:20 +0000 |
commit | 3222ace3e1f522d8095cc5e1979f98499e2f09fe (patch) | |
tree | a6b8e00360992b8fe5339029d5c418cdcf66042a /src/order_cmd.cpp | |
parent | a74b7ecd809e49c8f236edadf1baa3277a5ce080 (diff) | |
download | openttd-3222ace3e1f522d8095cc5e1979f98499e2f09fe.tar.xz |
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
Diffstat (limited to 'src/order_cmd.cpp')
-rw-r--r-- | src/order_cmd.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index c87493fc4..e1985893e 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -408,16 +408,24 @@ static void DeleteOrderWarnings(const Vehicle *v) DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_INVALID_ENTRY); } - -static TileIndex GetOrderLocation(const Order& o) +/** + * Returns a tile somewhat representing the order destination (not suitable for pathfinding). + * @param v The vehicle to get the location for. + * @return destination of order, or INVALID_TILE if none. + */ +TileIndex Order::GetLocation(const Vehicle *v) const { - switch (o.GetType()) { - default: NOT_REACHED(); - case OT_GOTO_WAYPOINT: return Waypoint::Get(o.GetDestination())->xy; - case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy; + switch (this->GetType()) { + case OT_GOTO_WAYPOINT: + case OT_GOTO_STATION: + return BaseStation::Get(this->GetDestination())->xy; + case OT_GOTO_DEPOT: - if ((o.GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE; - return Depot::Get(o.GetDestination())->xy; + if ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE; + return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination())->xy : Depot::Get(this->GetDestination())->xy; + + default: + return INVALID_TILE; } } @@ -435,8 +443,8 @@ static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle return max(dist1, dist2); } - TileIndex prev_tile = GetOrderLocation(*prev); - TileIndex cur_tile = GetOrderLocation(*cur); + TileIndex prev_tile = prev->GetLocation(v); + TileIndex cur_tile = cur->GetLocation(v); if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0; return DistanceManhattan(prev_tile, cur_tile); } |