1
0
Fork 0

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

release/1.1
frosch 2010-02-22 20:36:20 +00:00
parent a74b7ecd80
commit 3222ace3e1
3 changed files with 20 additions and 27 deletions

View File

@ -209,6 +209,7 @@ public:
inline void SetConditionValue(uint16 value) { SB(this->dest, 0, 11, value); } inline void SetConditionValue(uint16 value) { SB(this->dest, 0, 11, value); }
bool ShouldStopAtStation(const Vehicle *v, StationID station) const; 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. */ /** Checks if this order has travel_time and if needed wait_time set. */
inline bool IsCompletelyTimetabled() const inline bool IsCompletelyTimetabled() const

View File

@ -408,16 +408,24 @@ static void DeleteOrderWarnings(const Vehicle *v)
DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_INVALID_ENTRY); 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()) { switch (this->GetType()) {
default: NOT_REACHED(); case OT_GOTO_WAYPOINT:
case OT_GOTO_WAYPOINT: return Waypoint::Get(o.GetDestination())->xy; case OT_GOTO_STATION:
case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy; return BaseStation::Get(this->GetDestination())->xy;
case OT_GOTO_DEPOT: case OT_GOTO_DEPOT:
if ((o.GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE; if ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE;
return Depot::Get(o.GetDestination())->xy; 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); return max(dist1, dist2);
} }
TileIndex prev_tile = GetOrderLocation(*prev); TileIndex prev_tile = prev->GetLocation(v);
TileIndex cur_tile = GetOrderLocation(*cur); TileIndex cur_tile = cur->GetLocation(v);
if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0; if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0;
return DistanceManhattan(prev_tile, cur_tile); return DistanceManhattan(prev_tile, cur_tile);
} }

View File

@ -996,23 +996,7 @@ public:
int sel = this->GetOrderFromPt(pt.y); int sel = this->GetOrderFromPt(pt.y);
if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) { if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
const Order *ord = this->vehicle->GetOrder(sel); TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
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;
}
if (xy != INVALID_TILE) ScrollMainWindowToTile(xy); if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
return; return;
} }