summaryrefslogtreecommitdiff
path: root/src/station.cpp
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2007-02-13 16:36:38 +0000
committercelestar <celestar@openttd.org>2007-02-13 16:36:38 +0000
commit72e74c29d45bc81c4d7a5ba84e42b26bf11a4ffb (patch)
tree95900e955779b893062a6fbfbae3fa7fcf8323d1 /src/station.cpp
parentbf147e395ee16d118cf5d4afcb3a47b3672c8a6c (diff)
downloadopenttd-72e74c29d45bc81c4d7a5ba84e42b26bf11a4ffb.tar.xz
(svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
Diffstat (limited to 'src/station.cpp')
-rw-r--r--src/station.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/station.cpp b/src/station.cpp
index 14f46abaf..e6e68631d 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -179,6 +179,56 @@ bool Station::TileBelongsToRailStation(TileIndex tile) const
}
+/** Obtain the length of a platform
+ * @pre tile must be a railway station tile
+ * @param tile A tile that contains the platform in question
+ * @returns The length of the platform
+ */
+uint Station::GetPlatformLength(TileIndex tile) const
+{
+ TileIndex t;
+ TileIndexDiff delta;
+ uint len = 0;
+ assert(TileBelongsToRailStation(tile));
+
+ delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
+
+ t = tile;
+ do {
+ t -= delta;
+ len++;
+ } while (IsCompatibleTrainStationTile(t, tile));
+
+ t = tile;
+ do {
+ t += delta;
+ len++;
+ } while (IsCompatibleTrainStationTile(t, tile));
+
+ 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 railway station tile
+ * @param dir The direction in which to search.
+ * @return The platform length
+ */
+uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
+{
+ TileIndex start_tile = tile;
+ uint length = 0;
+ assert(IsRailwayStationTile(tile));
+ assert(dir < DIAGDIR_END);
+
+ do {
+ length ++;
+ tile += TileOffsByDiagDir(dir);
+ } while (IsCompatibleTrainStationTile(tile, start_tile));
+
+ return length;
+}
+
/** Determines whether a station is a buoy only.
* @todo Ditch this encoding of buoys
*/