summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp2
-rw-r--r--src/station.cpp50
-rw-r--r--src/station.h4
-rw-r--r--src/station_cmd.cpp51
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/yapf/follow_track.hpp2
6 files changed, 55 insertions, 56 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index b97e8df55..8ac68e8b9 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1519,7 +1519,7 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived)
if (v->type == VEH_Train) {
// Each platform tile is worth 2 rail vehicles.
- int overhang = v->u.rail.cached_total_length - GetStationPlatforms(st, v->tile) * TILE_SIZE;
+ int overhang = v->u.rail.cached_total_length - st->GetPlatformLength(v->tile) * TILE_SIZE;
if (overhang > 0) {
unloading_time <<= 1;
unloading_time += (overhang * unloading_time) / 8;
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
*/
diff --git a/src/station.h b/src/station.h
index 38fcf058f..6d5113b2f 100644
--- a/src/station.h
+++ b/src/station.h
@@ -167,6 +167,8 @@ struct Station {
void MarkDirty() const;
void MarkTilesDirty() const;
bool TileBelongsToRailStation(TileIndex tile) const;
+ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
+ uint GetPlatformLength(TileIndex tile) const;
bool IsBuoy() const;
bool IsValid() const;
@@ -260,8 +262,6 @@ DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000)
void AfterLoadStations(void);
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad);
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad);
-uint GetStationPlatforms(const Station *st, TileIndex tile);
-uint GetPlatformLength(TileIndex tile, DiagDirection dir);
const DrawTileSprites *GetStationTileLayout(byte gfx);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index be67f3712..5ab33781e 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1140,57 +1140,6 @@ int32 CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint
return _price.remove_rail_station;
}
-// determine the number of platforms for the station
-uint GetStationPlatforms(const Station *st, TileIndex tile)
-{
- TileIndex t;
- TileIndexDiff delta;
- Axis axis;
- uint len;
- assert(st->TileBelongsToRailStation(tile));
-
- len = 0;
- axis = GetRailStationAxis(tile);
- delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
-
- // find starting tile..
- t = tile;
- do {
- t -= delta;
- len++;
- } while (st->TileBelongsToRailStation(t) && GetRailStationAxis(t) == axis);
-
- // find ending tile
- t = tile;
- do {
- t += delta;
- len++;
- } while (st->TileBelongsToRailStation(t) && GetRailStationAxis(t) == axis);
-
- 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 GetPlatformLength(TileIndex tile, DiagDirection dir)
-{
- 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;
-}
-
static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
{
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 16f5bf915..98bdb7be6 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -356,7 +356,7 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
if (TrainShouldStop(v, v->tile)) {
- int station_length = GetPlatformLength(v->tile, DirToDiagDir(v->direction));
+ int station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction));
int delta_v;
max_speed = 120;
diff --git a/src/yapf/follow_track.hpp b/src/yapf/follow_track.hpp
index 4c81caeb4..04ffecf5d 100644
--- a/src/yapf/follow_track.hpp
+++ b/src/yapf/follow_track.hpp
@@ -197,7 +197,7 @@ protected:
if (IsRailTT() && m_is_station) {
// entered railway station
// get platform length
- uint length = GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
+ uint length = GetStationByTile(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