MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateSpeed

Method UpdateSpeed

src/train_cmd.cpp:3019–3029  ·  view source on GitHub ↗

* This function looks at the vehicle and updates its speed (cur_speed * and subspeed) variables. Furthermore, it returns the distance that * the train can drive this tick. #Vehicle::GetAdvanceDistance() determines * the distance to drive before moving a step on the map. * @return distance to drive. */

Source from the content-addressed store, hash-verified

3017 * @return distance to drive.
3018 */
3019int Train::UpdateSpeed()
3020{
3021 switch (_settings_game.vehicle.train_acceleration_model) {
3022 default: NOT_REACHED();
3023 case AM_ORIGINAL:
3024 return this->DoUpdateSpeed(this->acceleration * (this->GetAccelerationStatus() == AS_BRAKE ? -4 : 2), 0, this->GetCurrentMaxSpeed());
3025
3026 case AM_REALISTIC:
3027 return this->DoUpdateSpeed(this->GetAcceleration(), this->GetAccelerationStatus() == AS_BRAKE ? 0 : 2, this->GetCurrentMaxSpeed());
3028 }
3029}
3030
3031/**
3032 * Trains enters a station, send out a news item if it is the first train, and start loading.

Callers 1

TrainLocoHandlerFunction · 0.45

Calls 5

GetAccelerationStatusMethod · 0.95
GetCurrentMaxSpeedMethod · 0.95
NOT_REACHEDFunction · 0.85
DoUpdateSpeedMethod · 0.80
GetAccelerationMethod · 0.80

Tested by

no test coverage detected