diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5f7847ff8a..3886fa5f21 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -342,6 +342,9 @@ add_files(
picker_func.h
picker_gui.cpp
picker_gui.h
+ platform_func.h
+ platform_type.h
+ platform.cpp
progress.cpp
progress.h
querystring_gui.h
diff --git a/src/base_station_base.h b/src/base_station_base.h
index 0c0ad22770..de8688006e 100644
--- a/src/base_station_base.h
+++ b/src/base_station_base.h
@@ -140,24 +140,6 @@ 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) 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, DiagDirection dir) 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/economy.cpp b/src/economy.cpp
index 5c0d4f7bec..9a9e54cfc2 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -56,6 +56,7 @@
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "depot_base.h"
+#include "platform_func.h"
#include "table/strings.h"
#include "table/pricebase.h"
@@ -1621,14 +1622,13 @@ static void ReserveConsist(Station *st, Vehicle *u, CargoArray *consist_capleft,
* Update the vehicle's load_unload_ticks, the time it will wait until it tries to load or unload
* again. Adjust for overhang of trains and set it at least to 1.
* @param front The vehicle to be updated.
- * @param st The station the vehicle is loading at.
* @param ticks The time it would normally wait, based on cargo loaded and unloaded.
*/
-static void UpdateLoadUnloadTicks(Vehicle *front, const Station *st, int ticks)
+static void UpdateLoadUnloadTicks(Vehicle *front, int ticks)
{
if (front->type == VEH_TRAIN && _settings_game.order.station_length_loading_penalty) {
/* Each platform tile is worth 2 rail vehicles. */
- int overhang = front->GetGroundVehicleCache()->cached_total_length - st->GetPlatformLength(front->tile) * TILE_SIZE;
+ int overhang = front->GetGroundVehicleCache()->cached_total_length - GetPlatformLength(front->tile) * TILE_SIZE;
if (overhang > 0) {
ticks <<= 1;
ticks += (overhang * ticks) / 8;
@@ -1890,9 +1890,9 @@ static void LoadUnloadVehicle(Vehicle *front)
SetBit(front->vehicle_flags, VF_STOP_LOADING);
}
- UpdateLoadUnloadTicks(front, st, new_load_unload_ticks);
+ UpdateLoadUnloadTicks(front, new_load_unload_ticks);
} else {
- UpdateLoadUnloadTicks(front, st, 20); // We need the ticks for link refreshing.
+ UpdateLoadUnloadTicks(front, 20); // We need the ticks for link refreshing.
bool finished_loading = true;
if (front->current_order.GetLoadType() & OLFB_FULL_LOAD) {
if (front->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) {
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index af67fbf648..86462ff4b9 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -24,6 +24,7 @@
#include "newgrf_animation_base.h"
#include "newgrf_class_func.h"
#include "timer/timer_game_calendar.h"
+#include "platform_func.h"
#include "safeguards.h"
diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp
index 9a16bcba93..ed9e24a240 100644
--- a/src/pathfinder/follow_track.hpp
+++ b/src/pathfinder/follow_track.hpp
@@ -18,6 +18,7 @@
#include "../tunnelbridge_map.h"
#include "../depot_map.h"
#include "pathfinder_func.h"
+#include "../platform_func.h"
/**
* Track follower helper template class (can serve pathfinders and vehicle
@@ -370,12 +371,11 @@ protected:
/* special handling for rail stations - get to the end of platform */
if (IsRailTT() && m_is_station) {
- /* entered railway station
- * get platform length */
- 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 */
+ /* Entered a platform. */
+ assert(HasStationTileRail(m_new_tile));
+ /* How big step we must do to get to the last platform tile? */
+ m_tiles_skipped = GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td)) - 1;
+ /* Move to the platform end. */
TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
diff *= m_tiles_skipped;
m_new_tile = TileAdd(m_new_tile, diff);
diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp
index d50bb24377..2a5bc290d6 100644
--- a/src/pathfinder/yapf/yapf_costrail.hpp
+++ b/src/pathfinder/yapf/yapf_costrail.hpp
@@ -590,12 +590,11 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
}
}
- /* Station platform-length penalty. */
+ /* Platform-length penalty. */
if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) {
- const BaseStation *st = BaseStation::GetByTile(n.GetLastTile());
- assert(st != nullptr);
- 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). */
+ assert(HasStationTileRail(n.GetLastTile()));
+ uint platform_length = GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir())));
+ /* Reduce the extra cost caused by passing-platform penalty (each platform receives it in the segment cost). */
extra_cost -= Yapf().PfGetSettings().rail_station_penalty * platform_length;
/* Add penalty for the inappropriate platform length. */
extra_cost += PlatformLengthPenalty(platform_length);
diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp
index 979cfb060b..8d7e55267e 100644
--- a/src/pathfinder/yapf/yapf_rail.cpp
+++ b/src/pathfinder/yapf/yapf_rail.cpp
@@ -16,6 +16,7 @@
#include "yapf_destrail.hpp"
#include "../../viewport_func.h"
#include "../../newgrf_station.h"
+#include "../../platform_func.h"
#include "../../safeguards.h"
diff --git a/src/pbs.cpp b/src/pbs.cpp
index 209f2c0acf..6cc6a33aa2 100644
--- a/src/pbs.cpp
+++ b/src/pbs.cpp
@@ -47,28 +47,6 @@ TrackBits GetReservedTrackbits(TileIndex t)
return TRACK_BIT_NONE;
}
-/**
- * Set the reservation for a complete station platform.
- * @pre IsRailStationTile(start)
- * @param start starting tile of the platform
- * @param dir the direction in which to follow the platform
- * @param b the state the reservation should be set to
- */
-void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
-{
- TileIndex tile = start;
- TileIndexDiff diff = TileOffsByDiagDir(dir);
-
- assert(IsRailStationTile(start));
- assert(GetRailStationAxis(start) == DiagDirToAxis(dir));
-
- do {
- SetRailStationReservation(tile, b);
- MarkTileDirtyByTile(tile);
- tile = TileAdd(tile, diff);
- } while (IsCompatibleTrainStationTile(tile, start));
-}
-
/**
* Try to reserve a specific track on a tile
* @param tile the tile
diff --git a/src/platform.cpp b/src/platform.cpp
new file mode 100644
index 0000000000..103d5a29f2
--- /dev/null
+++ b/src/platform.cpp
@@ -0,0 +1,138 @@
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see .
+ */
+
+/** @file platform.cpp Implementation of platform functions. */
+
+#include "stdafx.h"
+#include "station_map.h"
+#include "platform_func.h"
+#include "viewport_func.h"
+
+/**
+ * Set the reservation for a complete station platform.
+ * @pre IsRailStationTile(start)
+ * @param start starting tile of the platform
+ * @param dir the direction in which to follow the platform
+ * @param b the state the reservation should be set to
+ */
+void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
+{
+ TileIndex tile = start;
+ TileIndexDiff diff = TileOffsByDiagDir(dir);
+
+ assert(IsRailStationTile(start));
+ assert(GetRailStationAxis(start) == DiagDirToAxis(dir));
+
+ do {
+ SetRailStationReservation(tile, b);
+ MarkTileDirtyByTile(tile);
+ tile = TileAdd(tile, diff);
+ } while (IsCompatibleTrainStationTile(tile, start));
+}
+
+/**
+ * Set the reservation for a complete platform in a given direction.
+ * @param start starting tile of the platform
+ * @param dir the direction in which to follow the platform
+ * @param b the state the reservation should be set to
+ */
+void SetPlatformReservation(TileIndex start, DiagDirection dir, bool b)
+{
+ switch (GetPlatformType(start)) {
+ case PT_RAIL_STATION:
+ SetRailStationPlatformReservation(start, dir, b);
+ return;
+ case PT_RAIL_WAYPOINT:
+ SetRailStationReservation(start, b);
+ return;
+ default: NOT_REACHED();
+ }
+}
+
+/**
+ * Get the length of a rail station platform.
+ * @pre IsRailStationTile(tile)
+ * @param tile Tile to check
+ * @return The length of the platform in tile length.
+ */
+uint GetRailStationPlatformLength(TileIndex tile)
+{
+ assert(IsRailStationTile(tile));
+
+ TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
+
+ TileIndex t = tile;
+ uint len = 0;
+ do {
+ t -= delta;
+ len++;
+ } while (IsCompatibleTrainStationTile(t, tile));
+
+ t = tile;
+ do {
+ t += delta;
+ len++;
+ } while (IsCompatibleTrainStationTile(t, tile));
+
+ return len - 1;
+}
+
+/**
+ * Get the length of a rail station platform in a given direction.
+ * @pre IsRailStationTile(tile)
+ * @param tile Tile to check
+ * @param dir Direction to check
+ * @return The length of the platform in tile length in the given direction.
+ */
+uint GetRailStationPlatformLength(TileIndex tile, DiagDirection dir)
+{
+ TileIndex start_tile = tile;
+ uint length = 0;
+ assert(IsRailStationTile(tile));
+ assert(dir < DIAGDIR_END);
+
+ do {
+ length++;
+ tile += TileOffsByDiagDir(dir);
+ } while (IsCompatibleTrainStationTile(tile, start_tile));
+
+ return length;
+}
+
+/**
+ * Get the length of a platform.
+ * @param tile Tile to check
+ * @return The length of the platform in tile length.
+ */
+uint GetPlatformLength(TileIndex tile)
+{
+ switch (GetPlatformType(tile)) {
+ case PT_RAIL_STATION:
+ return GetRailStationPlatformLength(tile);
+ case PT_RAIL_WAYPOINT:
+ return 1;
+ default: NOT_REACHED();
+ }
+}
+
+/**
+ * Get the length of a rail depot platform in a given direction.
+ * @pre IsRailDepotTile(tile)
+ * @param tile Tile to check
+ * @param dir Direction to check
+ * @return The length of the platform in tile length in the given direction.
+ */
+uint GetPlatformLength(TileIndex tile, DiagDirection dir)
+{
+ switch (GetPlatformType(tile)) {
+ case PT_RAIL_STATION:
+ return GetRailStationPlatformLength(tile, dir);
+ case PT_RAIL_WAYPOINT:
+ return 1;
+ default: NOT_REACHED();
+ }
+}
diff --git a/src/platform_func.h b/src/platform_func.h
new file mode 100644
index 0000000000..5b1275d3ef
--- /dev/null
+++ b/src/platform_func.h
@@ -0,0 +1,104 @@
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see .
+ */
+
+/** @file platform_func.h Functions related with platforms (tiles in a row that are connected somehow). */
+
+#ifndef PLATFORM_FUNC_H
+#define PLATFORM_FUNC_H
+
+#include "station_map.h"
+#include "platform_type.h"
+
+/**
+ * Check if a tile is a valid continuation to a railstation tile.
+ * The tile \a test_tile is a valid continuation to \a station_tile, if all of the following are true:
+ * \li \a test_tile is a rail station tile
+ * \li the railtype of \a test_tile is compatible with the railtype of \a station_tile
+ * \li the tracks on \a test_tile and \a station_tile are in the same direction
+ * \li both tiles belong to the same station
+ * \li \a test_tile is not blocked (@see IsStationTileBlocked)
+ * @param test_tile Tile to test
+ * @param station_tile Station tile to compare with
+ * @pre IsRailStationTile(station_tile)
+ * @return true if the two tiles are compatible
+ */
+static inline bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
+{
+ assert(IsRailStationTile(station_tile));
+ return IsRailStationTile(test_tile) && !IsStationTileBlocked(test_tile) &&
+ IsCompatibleRail(GetRailType(test_tile), GetRailType(station_tile)) &&
+ GetRailStationAxis(test_tile) == GetRailStationAxis(station_tile) &&
+ GetStationIndex(test_tile) == GetStationIndex(station_tile);
+}
+
+/**
+ * Returns the type of platform of a given tile.
+ * @param tile Tile to check
+ * @return the type of platform (rail station, rail waypoint...)
+ */
+static inline PlatformType GetPlatformType(TileIndex tile)
+{
+ switch (GetTileType(tile)) {
+ case MP_STATION:
+ if (IsRailStation(tile)) return PT_RAIL_STATION;
+ if (IsRailWaypoint(tile)) return PT_RAIL_WAYPOINT;
+ break;
+ default: break;
+ }
+
+ return INVALID_PLATFORM_TYPE;
+}
+
+/**
+ * Check whether a tile is a known platform type.
+ * @param tile to check
+ * @return whether the tile is a known platform type.
+ */
+static inline bool IsPlatformTile(TileIndex tile)
+{
+ return GetPlatformType(tile) != INVALID_PLATFORM_TYPE;
+}
+
+/**
+ * Check whether a platform tile is reserved.
+ * @param tile to check
+ * @return whether the platform tile is reserved
+ */
+static inline bool HasPlatformReservation(TileIndex tile)
+{
+ switch(GetPlatformType(tile)) {
+ case PT_RAIL_STATION:
+ case PT_RAIL_WAYPOINT:
+ return HasStationReservation(tile);
+ default: NOT_REACHED();
+ }
+}
+
+/**
+ * Check whether two tiles are compatible platform tiles: they must have the same
+ * platform type and (depending on the platform type) its railtype or other specs.
+ * @param test_tile the tile to check
+ * @param orig_tile the tile with the platform type we are interested in
+ * @return whether the two tiles are compatible tiles for defining a platform
+ */
+static inline bool IsCompatiblePlatformTile(TileIndex test_tile, TileIndex orig_tile)
+{
+ switch (GetPlatformType(orig_tile)) {
+ case PT_RAIL_STATION:
+ return IsCompatibleTrainStationTile(test_tile, orig_tile);
+ case PT_RAIL_WAYPOINT:
+ return test_tile == orig_tile;
+ default: NOT_REACHED();
+ }
+}
+
+void SetPlatformReservation(TileIndex start, DiagDirection dir, bool b);
+
+uint GetPlatformLength(TileIndex tile);
+uint GetPlatformLength(TileIndex tile, DiagDirection dir);
+
+#endif /* PLATFORM_FUNC_H */
diff --git a/src/platform_type.h b/src/platform_type.h
new file mode 100644
index 0000000000..a2a48c90b3
--- /dev/null
+++ b/src/platform_type.h
@@ -0,0 +1,22 @@
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see .
+ */
+
+/** @file platform_type.h Types related to platforms. */
+
+#ifndef PLATFORM_TYPE_H
+#define PLATFORM_TYPE_H
+
+#include "core/enum_type.hpp"
+
+enum PlatformType {
+ PT_RAIL_STATION,
+ PT_RAIL_WAYPOINT,
+ PT_END,
+ INVALID_PLATFORM_TYPE = PT_END,
+};
+
+#endif /* PLATFORM_TYPE_H */
diff --git a/src/station.cpp b/src/station.cpp
index cf07e27f92..95475eba6a 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -269,43 +269,6 @@ void Station::MarkTilesDirty(bool cargo_change) const
}
}
-/* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
-{
- assert(this->TileBelongsToRailStation(tile));
-
- TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
-
- TileIndex t = tile;
- uint len = 0;
- do {
- t -= delta;
- len++;
- } while (IsCompatibleTrainStationTile(t, tile));
-
- t = tile;
- do {
- t += delta;
- len++;
- } while (IsCompatibleTrainStationTile(t, tile));
-
- return len - 1;
-}
-
-/* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
-{
- TileIndex start_tile = tile;
- uint length = 0;
- assert(IsRailStationTile(tile));
- assert(dir < DIAGDIR_END);
-
- do {
- length++;
- tile += TileOffsByDiagDir(dir);
- } while (IsCompatibleTrainStationTile(tile, start_tile));
-
- return length;
-}
-
/**
* Get the catchment size of an individual station tile.
* @param tile Station tile to get catchment size of.
diff --git a/src/station_base.h b/src/station_base.h
index f5db44f23b..531339b85b 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -488,9 +488,6 @@ public:
void MoveSign(TileIndex new_xy) override;
void AfterStationTileSetChange(bool adding, StationType type);
-
- uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override;
- uint GetPlatformLength(TileIndex tile) const override;
void RecomputeCatchment(bool no_clear_nearby_lists = false);
static void RecomputeCatchmentForAll();
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index a0e8f8c805..9d4da2f958 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -68,6 +68,7 @@
#include "cheat_type.h"
#include "road_func.h"
#include "depot_base.h"
+#include "platform_func.h"
#include "widgets/station_widget.h"
@@ -1240,9 +1241,10 @@ CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_
static void FreeTrainReservation(Train *v)
{
FreeTrainTrackReservation(v);
- if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), false);
+ if (IsPlatformTile(v->tile)) SetPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), false);
v = v->Last();
- if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), false);
+ if (IsPlatformTile(v->tile)) SetPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), false);
+
}
/**
@@ -1251,10 +1253,10 @@ static void FreeTrainReservation(Train *v)
*/
static void RestoreTrainReservation(Train *v)
{
- if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
+ if (IsPlatformTile(v->tile)) SetPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
TryPathReserve(v, true, true);
v = v->Last();
- if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
+ if (IsPlatformTile(v->tile)) SetPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
}
/**
@@ -1522,21 +1524,21 @@ CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailTyp
TileIndex platform_end = tile;
/* We can only account for tiles that are reachable from this tile, so ignore primarily blocked tiles while finding the platform begin and end. */
- for (TileIndex next_tile = platform_begin - tile_offset; IsCompatibleTrainStationTile(next_tile, platform_begin); next_tile -= tile_offset) {
+ for (TileIndex next_tile = platform_begin - tile_offset; IsCompatiblePlatformTile(next_tile, platform_begin); next_tile -= tile_offset) {
platform_begin = next_tile;
}
- for (TileIndex next_tile = platform_end + tile_offset; IsCompatibleTrainStationTile(next_tile, platform_end); next_tile += tile_offset) {
+ for (TileIndex next_tile = platform_end + tile_offset; IsCompatiblePlatformTile(next_tile, platform_end); next_tile += tile_offset) {
platform_end = next_tile;
}
/* If there is at least on reservation on the platform, we reserve the whole platform. */
bool reservation = false;
for (TileIndex t = platform_begin; !reservation && t <= platform_end; t += tile_offset) {
- reservation = HasStationReservation(t);
+ reservation = HasPlatformReservation(t);
}
if (reservation) {
- SetRailStationPlatformReservation(platform_begin, dir, true);
+ SetPlatformReservation(platform_begin, dir, true);
}
}
diff --git a/src/station_map.h b/src/station_map.h
index 906ad6193b..0869d49db5 100644
--- a/src/station_map.h
+++ b/src/station_map.h
@@ -521,28 +521,6 @@ inline TrackBits GetRailStationTrackBits(Tile t)
return AxisToTrackBits(GetRailStationAxis(t));
}
-/**
- * Check if a tile is a valid continuation to a railstation tile.
- * The tile \a test_tile is a valid continuation to \a station_tile, if all of the following are true:
- * \li \a test_tile is a rail station tile
- * \li the railtype of \a test_tile is compatible with the railtype of \a station_tile
- * \li the tracks on \a test_tile and \a station_tile are in the same direction
- * \li both tiles belong to the same station
- * \li \a test_tile is not blocked (@see IsStationTileBlocked)
- * @param test_tile Tile to test
- * @param station_tile Station tile to compare with
- * @pre IsRailStationTile(station_tile)
- * @return true if the two tiles are compatible
- */
-inline bool IsCompatibleTrainStationTile(Tile test_tile, Tile station_tile)
-{
- assert(IsRailStationTile(station_tile));
- return IsRailStationTile(test_tile) && !IsStationTileBlocked(test_tile) &&
- IsCompatibleRail(GetRailType(test_tile), GetRailType(station_tile)) &&
- GetRailStationAxis(test_tile) == GetRailStationAxis(station_tile) &&
- GetStationIndex(test_tile) == GetStationIndex(station_tile);
-}
-
/**
* Get the reservation state of the rail station
* @pre HasStationRail(t)
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 8f8dc12eb9..52bc2c839b 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -39,6 +39,7 @@
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "depot_base.h"
+#include "platform_func.h"
#include "table/strings.h"
#include "table/train_sprites.h"
@@ -263,9 +264,9 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
*/
int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length)
{
- const Station *st = Station::Get(station_id);
- *station_ahead = st->GetPlatformLength(tile, DirToDiagDir(v->direction)) * TILE_SIZE;
- *station_length = st->GetPlatformLength(tile) * TILE_SIZE;
+ assert(IsRailStationTile(tile));
+ *station_ahead = GetPlatformLength(tile, DirToDiagDir(v->direction)) * TILE_SIZE;
+ *station_length = GetPlatformLength(tile) * TILE_SIZE;
/* Default to the middle of the station for stations stops that are not in
* the order list like intermediate stations when non-stop is disabled */
@@ -2183,7 +2184,7 @@ void ReverseTrainDirection(Train *v)
/* If we are on a depot tile facing outwards, do not treat the current tile as safe. */
if (IsStandardRailDepotTile(v->tile) && TrackdirToExitdir(v->GetVehicleTrackdir()) == GetRailDepotDirection(v->tile)) first_tile_okay = false;
- if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
+ if (IsPlatformTile(v->tile)) SetPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
if (TryPathReserve(v, false, first_tile_okay)) {
/* Do a look-ahead now in case our current tile was already a safe tile. */
CheckNextTrainTile(v);
@@ -2526,8 +2527,8 @@ static void ClearPathReservation(const Train *v, TileIndex tile, Trackdir track_
TileIndex new_tile = TileAddByDiagDir(tile, dir);
/* If the new tile is not a further tile of the same station, we
* clear the reservation for the whole platform. */
- if (!IsCompatibleTrainStationTile(new_tile, tile)) {
- SetRailStationPlatformReservation(tile, ReverseDiagDir(dir), false);
+ if (!IsCompatiblePlatformTile(new_tile, tile)) {
+ SetPlatformReservation(tile, ReverseDiagDir(dir), false);
}
} else {
/* Any other tile */
diff --git a/src/waypoint_base.h b/src/waypoint_base.h
index cbf2e1e608..a7017d9acb 100644
--- a/src/waypoint_base.h
+++ b/src/waypoint_base.h
@@ -45,16 +45,6 @@ struct Waypoint final : SpecializedStation {
void GetTileArea(TileArea *ta, StationType type) const override;
- uint GetPlatformLength(TileIndex, DiagDirection) const override
- {
- return 1;
- }
-
- uint GetPlatformLength(TileIndex) const override
- {
- return 1;
- }
-
/**
* Is this a single tile waypoint?
* @return true if it is.