mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
This commit is contained in:
parent
a74b7ecd80
commit
3222ace3e1
@ -209,6 +209,7 @@ public:
|
||||
inline void SetConditionValue(uint16 value) { SB(this->dest, 0, 11, value); }
|
||||
|
||||
bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
|
||||
TileIndex GetLocation(const Vehicle *v) const;
|
||||
|
||||
/** Checks if this order has travel_time and if needed wait_time set. */
|
||||
inline bool IsCompletelyTimetabled() const
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -996,23 +996,7 @@ public:
|
||||
int sel = this->GetOrderFromPt(pt.y);
|
||||
|
||||
if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
|
||||
const Order *ord = this->vehicle->GetOrder(sel);
|
||||
TileIndex xy = INVALID_TILE;
|
||||
|
||||
switch (ord->GetType()) {
|
||||
case OT_GOTO_WAYPOINT:
|
||||
case OT_GOTO_STATION:
|
||||
xy = BaseStation::Get(ord->GetDestination())->xy;
|
||||
break;
|
||||
|
||||
case OT_GOTO_DEPOT:
|
||||
if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
|
||||
xy = (this->vehicle->type == VEH_AIRCRAFT) ? Station::Get(ord->GetDestination())->xy : Depot::Get(ord->GetDestination())->xy;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
|
||||
if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user