diff options
author | rubidium <rubidium@openttd.org> | 2011-01-26 17:34:07 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-01-26 17:34:07 +0000 |
commit | b4a175ba41a4e731c145f5282630265d471c52ff (patch) | |
tree | cc968ff01ef1487b8ae4869d4d1a59afdf88c26a /src/train_cmd.cpp | |
parent | 982de9cf86ad7d4c6bb4e77b19953999a1ee9eb6 (diff) | |
download | openttd-b4a175ba41a4e731c145f5282630265d471c52ff.tar.xz |
(svn r21914) -Codechange: move the algorithmic part of Train::UpdateSpeed to a function in GroundVehicle
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r-- | src/train_cmd.cpp | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 2c816c280..42ceb8ae8 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2630,38 +2630,14 @@ void Train::MarkDirty() */ int Train::UpdateSpeed() { - uint accel; - uint16 max_speed; - switch (_settings_game.vehicle.train_acceleration_model) { default: NOT_REACHED(); case AM_ORIGINAL: - max_speed = this->gcache.cached_max_track_speed; - accel = this->acceleration * (this->GetAccelerationStatus() == AS_BRAKE ? -4 : 2); - break; - case AM_REALISTIC: - max_speed = this->GetCurrentMaxSpeed(); - accel = this->GetAcceleration(); - break; - } + return this->DoUpdateSpeed(this->acceleration * (this->GetAccelerationStatus() == AS_BRAKE ? -4 : 2), 0, this->gcache.cached_max_track_speed); - uint spd = this->subspeed + accel; - this->subspeed = (byte)spd; - { - int tempmax = max_speed; - if (this->cur_speed > max_speed) { - tempmax = max(this->cur_speed - (this->cur_speed / 10) - 1, tempmax); - } - /* Force a minimum speed of 1 km/h when realistic acceleration is on and the train is not braking. */ - int min_speed = (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL || this->GetAccelerationStatus() == AS_BRAKE) ? 0 : 2; - this->cur_speed = spd = Clamp(this->cur_speed + ((int)spd >> 8), min_speed, tempmax); + case AM_REALISTIC: + return this->DoUpdateSpeed(this->GetAcceleration(), this->GetAccelerationStatus() == AS_BRAKE ? 0 : 2, this->GetCurrentMaxSpeed()); } - - int scaled_spd = this->GetAdvanceSpeed(spd); - - scaled_spd += this->progress; - this->progress = 0; // set later in TrainLocoHandler or TrainController - return scaled_spd; } /** |