summaryrefslogtreecommitdiff
path: root/src/station_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r--src/station_cmd.cpp48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index e601e57e9..563c440a9 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2671,25 +2671,35 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
if (v->type == VEH_TRAIN) {
if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
- if (IsRailwayStation(tile) && IsFrontEngine(v) &&
- !IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
- DiagDirection dir = DirToDiagDir(v->direction);
-
- x &= 0xF;
- y &= 0xF;
-
- if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
- if (y == TILE_SIZE / 2) {
- if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
- int stop = TILE_SIZE - (v->u.rail.cached_veh_length + 1) / 2;
- if (x == stop) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); // enter station
- if (x < stop) {
- uint16 spd;
-
- v->vehstatus |= VS_TRAIN_SLOWING;
- spd = max(0, (stop - x) * 20 - 15);
- if (spd < v->cur_speed) v->cur_speed = spd;
- }
+ if (!IsRailwayStation(tile) || !IsFrontEngine(v)) return VETSB_CONTINUE;
+
+ int station_ahead;
+ int station_length;
+ int stop = GetTrainStopLocation(station_id, tile, v, &station_ahead, &station_length);
+
+ /* Stop whenever that amount of station ahead + the distance from the
+ * begin of the platform to the stop location is longer than the length
+ * of the platform. Station ahead 'includes' the current tile where the
+ * vehicle is on, so we need to substract that. */
+ if (station_length <= stop + station_ahead - TILE_SIZE) return VETSB_CONTINUE;
+
+ DiagDirection dir = DirToDiagDir(v->direction);
+
+ x &= 0xF;
+ y &= 0xF;
+
+ if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
+ if (y == TILE_SIZE / 2) {
+ if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
+ stop &= TILE_SIZE - 1;
+
+ if (x == stop) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); // enter station
+ if (x < stop) {
+ uint16 spd;
+
+ v->vehstatus |= VS_TRAIN_SLOWING;
+ spd = max(0, (stop - x) * 20 - 15);
+ if (spd < v->cur_speed) v->cur_speed = spd;
}
}
} else if (v->type == VEH_ROAD) {