diff options
author | rubidium <rubidium@openttd.org> | 2011-01-26 17:35:03 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-01-26 17:35:03 +0000 |
commit | 430fda01dcaf6c6abd3a6b6b4b0a4ae6bae51e65 (patch) | |
tree | ce0edac2369883f7012c0db8290ba9cea05f1cc5 | |
parent | b4a175ba41a4e731c145f5282630265d471c52ff (diff) | |
download | openttd-430fda01dcaf6c6abd3a6b6b4b0a4ae6bae51e65.tar.xz |
(svn r21915) -Codechange: rename RoadVehicleAccelerate to RoadVehicle::UpdateSpeed (to match the naming used by Trains), and make use of the algorithm implemented in GroundVehicle
-rw-r--r-- | src/roadveh.h | 1 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 28 |
2 files changed, 9 insertions, 20 deletions
diff --git a/src/roadveh.h b/src/roadveh.h index 3cfecd609..516257512 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -120,6 +120,7 @@ struct RoadVehicle : public GroundVehicle<RoadVehicle, VEH_ROAD> { bool IsBus() const; int GetCurrentMaxSpeed() const; + int UpdateSpeed(); protected: // These functions should not be called outside acceleration code. diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index ce5d380b5..d13c94b91 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -649,28 +649,16 @@ static void RoadVehArrivesAt(const RoadVehicle *v, Station *st) * the distance to drive before moving a step on the map. * @return distance to drive. */ -static int RoadVehAccelerate(RoadVehicle *v) +int RoadVehicle::UpdateSpeed() { - uint accel = v->overtaking != 0 ? 256 : 0; - accel += (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) ? 256 : v->GetAcceleration(); - uint spd = v->subspeed + accel; - - v->subspeed = (uint8)spd; + switch (_settings_game.vehicle.roadveh_acceleration_model) { + default: NOT_REACHED(); + case AM_ORIGINAL: + return this->DoUpdateSpeed(this->overtaking != 0 ? 512 : 256, 0, this->GetCurrentMaxSpeed()); - int tempmax = v->GetCurrentMaxSpeed(); - if (v->cur_speed > tempmax) { - tempmax = v->cur_speed - (v->cur_speed / 10) - 1; + case AM_REALISTIC: + return this->DoUpdateSpeed(this->GetAcceleration() + (this->overtaking != 0 ? 256 : 0), this->GetAccelerationStatus() == AS_BRAKE ? 0 : 4, this->GetCurrentMaxSpeed()); } - - /* Force a minimum speed of 1 km/h when realistic acceleration is on. */ - int min_speed = (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) ? 0 : 4; - v->cur_speed = spd = Clamp(v->cur_speed + ((int)spd >> 8), min_speed, tempmax); - - int scaled_spd = v->GetAdvanceSpeed(spd); - - scaled_spd += v->progress; - v->progress = 0; - return scaled_spd; } static Direction RoadVehGetNewDirection(const RoadVehicle *v, int x, int y) @@ -1466,7 +1454,7 @@ static bool RoadVehController(RoadVehicle *v) v->ShowVisualEffect(); /* Check how far the vehicle needs to proceed */ - int j = RoadVehAccelerate(v); + int j = v->UpdateSpeed(); int adv_spd = v->GetAdvanceDistance(); bool blocked = false; |