summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2015-01-01 22:39:35 +0000
committermichi_cc <michi_cc@openttd.org>2015-01-01 22:39:35 +0000
commit8621ca411578f0c0a98fc17e6dc28f9d52f3f791 (patch)
tree8cd4056c98f0852eb4079c2f034c66bba5aacb9d /src/roadveh_cmd.cpp
parent30f778e933881837b33f891d9e8b0b109b5b2561 (diff)
downloadopenttd-8621ca411578f0c0a98fc17e6dc28f9d52f3f791.tar.xz
(svn r27106) -Fix [FS#6176]: Use the actual max speed of the vehicle in front when determining if a RV can overtake.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 3f9d3616f..45d1c2747 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -806,12 +806,6 @@ static void RoadVehCheckOvertake(RoadVehicle *v, RoadVehicle *u)
od.v = v;
od.u = u;
- if (u->vcache.cached_max_speed >= v->vcache.cached_max_speed &&
- !(u->vehstatus & VS_STOPPED) &&
- u->cur_speed != 0) {
- return;
- }
-
/* Trams can't overtake other trams */
if (v->roadtype == ROADTYPE_TRAM) return;
@@ -827,6 +821,15 @@ static void RoadVehCheckOvertake(RoadVehicle *v, RoadVehicle *u)
/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
if (v->state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->state & RVSB_TRACKDIR_MASK))) return;
+ /* Can't overtake a vehicle that is moving faster than us. If the vehicle in front is
+ * accelerating, take the maximum speed for the comparison, else the current speed. */
+ int u_speed = u->GetAcceleration() > 0 ? u->GetCurrentMaxSpeed() : u->cur_speed;
+ if (u_speed >= v->GetCurrentMaxSpeed() &&
+ !(u->vehstatus & VS_STOPPED) &&
+ u->cur_speed != 0) {
+ return;
+ }
+
od.trackdir = DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
/* Are the current and the next tile suitable for overtaking?