summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-02-22 20:36:20 +0000
committerfrosch <frosch@openttd.org>2010-02-22 20:36:20 +0000
commit3222ace3e1f522d8095cc5e1979f98499e2f09fe (patch)
treea6b8e00360992b8fe5339029d5c418cdcf66042a /src
parenta74b7ecd809e49c8f236edadf1baa3277a5ce080 (diff)
downloadopenttd-3222ace3e1f522d8095cc5e1979f98499e2f09fe.tar.xz
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
Diffstat (limited to 'src')
-rw-r--r--src/order_base.h1
-rw-r--r--src/order_cmd.cpp28
-rw-r--r--src/order_gui.cpp18
3 files changed, 20 insertions, 27 deletions
diff --git a/src/order_base.h b/src/order_base.h
index e75733a49..3e74f4c79 100644
--- a/src/order_base.h
+++ b/src/order_base.h
@@ -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
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);
}
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index d591bb438..9f974f8b8 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -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;
}