summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-02-02 22:06:14 +0000
committerrubidium <rubidium@openttd.org>2011-02-02 22:06:14 +0000
commitbbe94dc4971cdf3db042173f67c9815dec2600a9 (patch)
treea776e16ee2f05ae88d9ae6aec1f5e7ac3d8ade79
parenta42c0ea88b7024172d9cf326dabdbc407acee07c (diff)
downloadopenttd-bbe94dc4971cdf3db042173f67c9815dec2600a9.tar.xz
(svn r21945) -Codechange: simplify setting the overtaking counter and remove the magic from its numbers
-rw-r--r--src/roadveh.h3
-rw-r--r--src/roadveh_cmd.cpp13
2 files changed, 8 insertions, 8 deletions
diff --git a/src/roadveh.h b/src/roadveh.h
index bc9453adc..58b7d0750 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -76,6 +76,9 @@ static const uint RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16;
static const uint RVC_DRIVE_THROUGH_STOP_FRAME = 11;
static const uint RVC_DEPOT_STOP_FRAME = 11;
+/** The number of ticks a vehicle has for overtaking. */
+static const byte RV_OVERTAKE_TIMEOUT = 35;
+
void RoadVehUpdateCache(RoadVehicle *v);
/**
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index cf33c9c9d..825e9ac3f 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -773,13 +773,10 @@ static void RoadVehCheckOvertake(RoadVehicle *v, RoadVehicle *u)
od.tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
if (CheckRoadBlockedForOvertaking(&od)) return;
- if (od.u->cur_speed == 0 || (od.u->vehstatus & VS_STOPPED)) {
- v->overtaking_ctr = 0x11;
- v->overtaking = RVSB_DRIVE_SIDE;
- } else {
- v->overtaking_ctr = 0;
- v->overtaking = RVSB_DRIVE_SIDE;
- }
+ /* When the vehicle in front of us is stopped we may only take
+ * half the time to pass it than when the vehicle is moving. */
+ v->overtaking_ctr = (od.u->cur_speed == 0 || (od.u->vehstatus & VS_STOPPED)) ? RV_OVERTAKE_TIMEOUT / 2 : 0;
+ v->overtaking = RVSB_DRIVE_SIDE;
}
static void RoadZPosAffectSpeed(RoadVehicle *v, byte old_z)
@@ -1043,7 +1040,7 @@ static bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *p
if (IsTileType(v->tile, MP_STATION)) {
/* Force us to be not overtaking! */
v->overtaking = 0;
- } else if (++v->overtaking_ctr >= 35) {
+ } else if (++v->overtaking_ctr >= RV_OVERTAKE_TIMEOUT) {
/* If overtaking just aborts at a random moment, we can have a out-of-bound problem,
* if the vehicle started a corner. To protect that, only allow an abort of
* overtake if we are on straight roads */