From a7d168b2e5be77e361336d61c21b2b22f932fcc5 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 4 Jul 2010 13:07:47 +0000 Subject: (svn r20079) -Codechange [FS#3922]: Add helper functions to deal with the 192-256-magic of vehicle movement. --- src/roadveh_cmd.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/roadveh_cmd.cpp') 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; -- cgit v1.2.3-54-g00ecf