1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-09-02 03:19:10 +00:00

(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.

This commit is contained in:
frosch
2010-02-22 20:36:20 +00:00
parent a74b7ecd80
commit 3222ace3e1
3 changed files with 20 additions and 27 deletions

View File

@@ -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);
}