summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-07-04 13:07:47 +0000
committerfrosch <frosch@openttd.org>2010-07-04 13:07:47 +0000
commita7d168b2e5be77e361336d61c21b2b22f932fcc5 (patch)
treeaca46a4f7a9e467b164537edb26b20769b9e1de8 /src/roadveh_cmd.cpp
parented2213df239a84c1ef7962e4cf7abe102f0fcb5f (diff)
downloadopenttd-a7d168b2e5be77e361336d61c21b2b22f932fcc5.tar.xz
(svn r20079) -Codechange [FS#3922]: Add helper functions to deal with the 192-256-magic of vehicle movement.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 2ff830922..63bc8f41f 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -756,6 +756,13 @@ static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
}
}
+/**
+ * This function looks at the vehicle and updates its speed (cur_speed
+ * and subspeed) variables. Furthermore, it returns the distance that
+ * the vehicle can drive this tick. #Vehicle::GetAdvanceDistance() determines
+ * the distance to drive before moving a step on the map.
+ * @return distance to drive.
+ */
static int RoadVehAccelerate(RoadVehicle *v)
{
uint oldspeed = v->cur_speed;
@@ -786,8 +793,7 @@ static int RoadVehAccelerate(RoadVehicle *v)
}
}
- /* Speed is scaled in the same manner as for trains. @see train_cmd.cpp */
- int scaled_spd = spd * 3 >> 2;
+ int scaled_spd = v->GetAdvanceSpeed(spd);
scaled_spd += v->progress;
v->progress = 0;
@@ -1595,7 +1601,7 @@ static bool RoadVehController(RoadVehicle *v)
/* Check how far the vehicle needs to proceed */
int j = RoadVehAccelerate(v);
- int adv_spd = (v->direction & 1) ? 192 : 256;
+ int adv_spd = v->GetAdvanceDistance();
bool blocked = false;
while (j >= adv_spd) {
j -= adv_spd;
@@ -1609,8 +1615,8 @@ static bool RoadVehController(RoadVehicle *v)
}
if (blocked) break;
- /* 192 spd used for going straight, 256 for going diagonally. */
- adv_spd = (v->direction & 1) ? 192 : 256;
+ /* Determine distance to next map position */
+ adv_spd = v->GetAdvanceDistance();
/* Test for a collision, but only if another movement will occur. */
if (j >= adv_spd && RoadVehCheckTrainCrash(v)) break;