diff options
author | rubidium <rubidium@openttd.org> | 2011-02-06 16:45:27 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-02-06 16:45:27 +0000 |
commit | fd86b0608d051d14d5c1eba2a9730d94f4c505d2 (patch) | |
tree | 85cd7e8da10629fde7b6310ab1e318cf368ec0d0 /src | |
parent | fd94ed3009ab4a3f1016d32c6884b696412ec152 (diff) | |
download | openttd-fd86b0608d051d14d5c1eba2a9730d94f4c505d2.tar.xz |
(svn r21997) -Fix [FS#4473]: when the difference between force and resistance is smaller than the mass(*4) there would be no acceleration anymore, even when at higher (or lower) speed the force and resistance balance out better
Diffstat (limited to 'src')
-rw-r--r-- | src/ground_vehicle.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp index cc2360d3f..1c706b5c6 100644 --- a/src/ground_vehicle.cpp +++ b/src/ground_vehicle.cpp @@ -151,8 +151,16 @@ int GroundVehicle<T, Type>::GetAcceleration() const } if (mode == AS_ACCEL) { - /* Divide by 4 to compensate for the wacky game scale. */ - return (force - resistance) / (mass * 4); + /* Easy way out when there is no acceleration. */ + if (force == resistance) return 0; + + /* When we accelerate, make sure we always keep doing that, even when + * the excess force is more than the mass. Otherwise a vehicle going + * down hill will never slow down enough, and a vehicle that came up + * a hill will never speed up enough to (eventually) get back to the + * same (maximum) speed. */ + int accel = (force - resistance) / (mass * 4); + return force < resistance ? min(-1, accel) : max(1, accel); } else { return min(-force - resistance, -10000) / mass; } |