Index: src/train_cmd.cpp =================================================================== --- src/train_cmd.cpp (revision 21532) +++ src/train_cmd.cpp (working copy) @@ -2917,19 +2917,32 @@ gp.x = v->x_pos; gp.y = v->y_pos; } else { - /* Not inside depot */ + /* Not inside depot. */ + if (prev == NULL) { + /* Reverse when we are at the end of the track already, do not move to the new position. */ + if (!TrainCheckIfLineEnds(v)) return; + /* Do not check on every tick if we can extend track reservation to save some computing time. */ + if (v->tick_counter % _settings_game.pf.path_backoff_interval == 0) CheckNextTrainTile(v); + } - /* Reverse when we are at the end of the track already, do not move to the new position */ - if (v->IsFrontEngine() && !TrainCheckIfLineEnds(v)) return; - uint32 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); - if (HasBit(r, VETS_CANNOT_ENTER)) { - goto invalid_rail; - } if (HasBit(r, VETS_ENTERED_STATION)) { - /* The new position is the end of the platform */ + /* The new position is the end of the platform. */ TrainEnterStation(v, r >> VETS_STATION_ID_OFFSET); } + + v->x_pos = gp.x; + v->y_pos = gp.y; + + if (HasBit(v->gv_flags, GVF_GOINGUP_BIT) || HasBit(v->gv_flags, GVF_GOINGDOWN_BIT)) { + /* Update the z position of the vehicle and adjust speed only + * if going up or going down flags are set. */ + byte old_z = v->UpdateInclination(false, false); + if (prev == NULL) AffectSpeedByZChange(v, old_z); + } else { + VehicleMove(v, true); + } + continue; } } else { /* A new tile is about to be entered. */ @@ -3208,9 +3221,6 @@ if (IsLevelCrossingTile(gp.old_tile)) UpdateLevelCrossing(gp.old_tile); } } - - /* Do not check on every tick to save some computing time. */ - if (v->IsFrontEngine() && v->tick_counter % _settings_game.pf.path_backoff_interval == 0) CheckNextTrainTile(v); } if (direction_changed) first->tcache.cached_max_curve_speed = first->GetCurveSpeedLimit();