summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base_station_base.h18
-rw-r--r--src/npf.cpp2
-rw-r--r--src/order_cmd.cpp22
-rw-r--r--src/pathfind.h6
-rw-r--r--src/station.cpp17
-rw-r--r--src/station_base.h4
-rw-r--r--src/waypoint_base.h10
-rw-r--r--src/yapf/follow_track.hpp4
-rw-r--r--src/yapf/yapf_costrail.hpp2
-rw-r--r--src/yapf/yapf_destrail.hpp9
10 files changed, 50 insertions, 44 deletions
diff --git a/src/base_station_base.h b/src/base_station_base.h
index 407370260..a5dbd124f 100644
--- a/src/base_station_base.h
+++ b/src/base_station_base.h
@@ -85,6 +85,24 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
*/
virtual void GetTileArea(TileArea *ta, StationType type) const = 0;
+
+ /**
+ * Obtain the length of a platform
+ * @pre tile must be a rail station tile
+ * @param tile A tile that contains the platform in question
+ * @return The length of the platform
+ */
+ virtual uint GetPlatformLength(TileIndex tile, DiagDirection dir) const = 0;
+
+ /**
+ * Determines the REMAINING length of a platform, starting at (and including)
+ * the given tile.
+ * @param tile the tile from which to start searching. Must be a rail station tile
+ * @param dir The direction in which to search.
+ * @return The platform length
+ */
+ virtual uint GetPlatformLength(TileIndex tile) const = 0;
+
/**
* Get the base station belonging to a specific tile.
* @param tile The tile to get the base station from.
diff --git a/src/npf.cpp b/src/npf.cpp
index dccb5a0cd..6f64227e7 100644
--- a/src/npf.cpp
+++ b/src/npf.cpp
@@ -1103,7 +1103,7 @@ void NPFFillWithOrderData(NPFFindStationOrTileData *fstd, Vehicle *v, bool reser
* dest_tile, not just any stop of that station.
* So only for train orders to stations we fill fstd->station_index, for all
* others only dest_coords */
- if (v->current_order.IsType(OT_GOTO_STATION) && v->type == VEH_TRAIN) {
+ if (v->type == VEH_TRAIN && (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_WAYPOINT))) {
fstd->station_index = v->current_order.GetDestination();
/* Let's take the closest tile of the station as our target for trains */
fstd->dest_coords = CalcClosestStationTile(fstd->station_index, v->tile);
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 3b1a319ee..7e2b3757a 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -412,9 +412,9 @@ static TileIndex GetOrderLocation(const Order& o)
{
switch (o.GetType()) {
default: NOT_REACHED();
- case OT_GOTO_WAYPOINT: // This function is only called for ships, thus waypoints are buoys which are stations.
- case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy;
- case OT_GOTO_DEPOT: return Depot::Get(o.GetDestination())->xy;
+ case OT_GOTO_WAYPOINT: return Waypoint::Get(o.GetDestination())->xy;
+ case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy;
+ case OT_GOTO_DEPOT: return Depot::Get(o.GetDestination())->xy;
}
}
@@ -1688,11 +1688,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
break;
case OT_GOTO_WAYPOINT:
- if (v->type == VEH_TRAIN) {
- v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
- } else {
- v->dest_tile = Station::Get(order->GetDestination())->xy;
- }
+ v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
return true;
case OT_CONDITIONAL: {
@@ -1755,17 +1751,11 @@ bool ProcessOrders(Vehicle *v)
*/
bool may_reverse = v->current_order.IsType(OT_NOTHING);
- /* Check if we've reached the waypoint? */
- if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) {
- UpdateVehicleTimetable(v, true);
- v->IncrementOrderIndex();
- }
-
/* Check if we've reached a non-stop station.. */
- if (v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) &&
+ if (((v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) || v->current_order.IsType(OT_GOTO_WAYPOINT)) &&
IsTileType(v->tile, MP_STATION) &&
v->current_order.GetDestination() == GetStationIndex(v->tile)) {
- v->last_station_visited = v->current_order.GetDestination();
+ if (v->current_order.IsType(OT_GOTO_STATION)) v->last_station_visited = v->current_order.GetDestination();
UpdateVehicleTimetable(v, true);
v->IncrementOrderIndex();
}
diff --git a/src/pathfind.h b/src/pathfind.h
index db758f0a6..c3f28cb67 100644
--- a/src/pathfind.h
+++ b/src/pathfind.h
@@ -7,6 +7,7 @@
#include "direction_type.h"
#include "station_base.h"
+#include "waypoint_base.h"
enum {
STR_FACTOR = 2,
@@ -89,7 +90,10 @@ void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagD
*/
static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile)
{
- const Station *st = Station::Get(station);
+ const BaseStation *bst = BaseStation::Get(station);
+ if (Waypoint::IsExpected(bst)) return bst->xy;
+
+ const Station *st = Station::From(bst);
/* If the rail station is (temporarily) not present, use the station sign to drive near the station */
if (st->train_tile == INVALID_TILE) return st->xy;
diff --git a/src/station.cpp b/src/station.cpp
index 0f2555ffb..59664e289 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -181,12 +181,7 @@ void Station::MarkTilesDirty(bool cargo_change) const
}
}
-/** Obtain the length of a platform
- * @pre tile must be a rail station tile
- * @param tile A tile that contains the platform in question
- * @return The length of the platform
- */
-uint Station::GetPlatformLength(TileIndex tile) const
+/* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
{
assert(this->TileBelongsToRailStation(tile));
@@ -208,13 +203,7 @@ uint Station::GetPlatformLength(TileIndex tile) const
return len - 1;
}
-/** Determines the REMAINING length of a platform, starting at (and including)
- * the given tile.
- * @param tile the tile from which to start searching. Must be a rail station tile
- * @param dir The direction in which to search.
- * @return The platform length
- */
-uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
+/* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
{
TileIndex start_tile = tile;
uint length = 0;
@@ -222,7 +211,7 @@ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
assert(dir < DIAGDIR_END);
do {
- length ++;
+ length++;
tile += TileOffsByDiagDir(dir);
} while (IsCompatibleTrainStationTile(tile, start_tile));
diff --git a/src/station_base.h b/src/station_base.h
index d9c7369b3..7006676cc 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -124,8 +124,8 @@ public:
void UpdateVirtCoord();
- uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
- uint GetPlatformLength(TileIndex tile) const;
+ /* virtual */ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
+ /* virtual */ uint GetPlatformLength(TileIndex tile) const;
void RecomputeIndustriesNear();
static void RecomputeIndustriesNearForAll();
diff --git a/src/waypoint_base.h b/src/waypoint_base.h
index 199dae975..952503260 100644
--- a/src/waypoint_base.h
+++ b/src/waypoint_base.h
@@ -24,6 +24,16 @@ struct Waypoint : SpecializedStation<Waypoint, true> {
/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
/* virtual */ void GetTileArea(TileArea *ta, StationType type) const;
+
+ /* virtual */ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const
+ {
+ return 1;
+ }
+
+ /* virtual */ uint GetPlatformLength(TileIndex tile) const
+ {
+ return 1;
+ }
};
#define FOR_ALL_WAYPOINTS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Waypoint, var)
diff --git a/src/yapf/follow_track.hpp b/src/yapf/follow_track.hpp
index 5d0a1e83b..8b2c27066 100644
--- a/src/yapf/follow_track.hpp
+++ b/src/yapf/follow_track.hpp
@@ -191,7 +191,7 @@ protected:
m_new_tile = TILE_ADD(m_old_tile, diff);
/* special handling for stations */
- if (IsRailTT() && IsRailStationTile(m_new_tile)) {
+ if (IsRailTT() && HasStationTileRail(m_new_tile)) {
m_is_station = true;
} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
m_is_station = true;
@@ -346,7 +346,7 @@ protected:
if (IsRailTT() && m_is_station) {
/* entered railway station
* get platform length */
- uint length = Station::GetByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
+ uint length = BaseStation::GetByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
/* how big step we must do to get to the last platform tile; */
m_tiles_skipped = length - 1;
/* move to the platform end */
diff --git a/src/yapf/yapf_costrail.hpp b/src/yapf/yapf_costrail.hpp
index cda82f1d7..7c0f522a7 100644
--- a/src/yapf/yapf_costrail.hpp
+++ b/src/yapf/yapf_costrail.hpp
@@ -543,7 +543,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
/* Station platform-length penalty. */
if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) {
- Station *st = Station::GetByTile(n.GetLastTile());
+ const BaseStation *st = BaseStation::GetByTile(n.GetLastTile());
assert(st != NULL);
uint platform_length = st->GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir())));
/* Reduce the extra cost caused by passing-station penalty (each station receives it in the segment cost). */
diff --git a/src/yapf/yapf_destrail.hpp b/src/yapf/yapf_destrail.hpp
index 928f10065..dea651789 100644
--- a/src/yapf/yapf_destrail.hpp
+++ b/src/yapf/yapf_destrail.hpp
@@ -129,17 +129,12 @@ public:
{
switch (v->current_order.GetType()) {
case OT_GOTO_STATION:
+ case OT_GOTO_WAYPOINT:
m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile);
m_dest_station_id = v->current_order.GetDestination();
m_destTrackdirs = INVALID_TRACKDIR_BIT;
break;
- case OT_GOTO_WAYPOINT:
- m_destTile = Waypoint::Get(v->current_order.GetDestination())->xy;
- m_dest_station_id = INVALID_STATION;
- m_destTrackdirs = IsRailWaypointTile(m_destTile) ? TrackToTrackdirBits(GetRailStationTrack(m_destTile)) : INVALID_TRACKDIR_BIT;
- break;
-
default:
m_destTile = v->dest_tile;
m_dest_station_id = INVALID_STATION;
@@ -160,7 +155,7 @@ public:
{
bool bDest;
if (m_dest_station_id != INVALID_STATION) {
- bDest = IsRailStationTile(tile)
+ bDest = HasStationTileRail(tile)
&& (GetStationIndex(tile) == m_dest_station_id)
&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
} else {