diff options
author | terkhen <terkhen@openttd.org> | 2010-11-06 13:05:11 +0000 |
---|---|---|
committer | terkhen <terkhen@openttd.org> | 2010-11-06 13:05:11 +0000 |
commit | 18e3a3ddfc7c9eee4d1023485a4c23b3cc40fbb3 (patch) | |
tree | 719e279d32005d7032a509a6aea06ab70124a667 | |
parent | 25d1b2f54b9cac01e2737848c208f6d8096a4a92 (diff) | |
download | openttd-18e3a3ddfc7c9eee4d1023485a4c23b3cc40fbb3.tar.xz |
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
-rw-r--r-- | src/economy.cpp | 11 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 7 | ||||
-rw-r--r-- | src/roadveh.h | 2 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 14 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 7 |
5 files changed, 20 insertions, 21 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index ecccc99a1..ebeb4384c 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1232,8 +1232,15 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) case VEH_SHIP: t = u->vcache.cached_max_speed; break; - case VEH_ROAD: t = u->max_speed / 2; break; - case VEH_AIRCRAFT: t = Aircraft::From(u)->GetSpeedOldUnits(); break; // Convert to old units. + + case VEH_ROAD: + t = u->vcache.cached_max_speed / 2; + break; + + case VEH_AIRCRAFT: + t = Aircraft::From(u)->GetSpeedOldUnits(); // Convert to old units. + break; + default: NOT_REACHED(); } diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 04e71c8fb..5d5979cd9 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -717,17 +717,12 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x19: { uint max_speed; switch (v->type) { - case VEH_TRAIN: /* FALL THROUGH */ - case VEH_SHIP: - max_speed = v->vcache.cached_max_speed; - break; - case VEH_AIRCRAFT: max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units. break; default: - max_speed = v->max_speed; + max_speed = v->vcache.cached_max_speed; break; } return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8); diff --git a/src/roadveh.h b/src/roadveh.h index a8fcccd00..96a86bafa 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -119,7 +119,7 @@ struct RoadVehicle : public GroundVehicle<RoadVehicle, VEH_ROAD> { bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); } SpriteID GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed / 2; } - int GetDisplayMaxSpeed() const { return this->max_speed / 2; } + int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; } Money GetRunningCost() const; int GetDisplayImageWidth(Point *offset = NULL) const; bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 1254dc269..1b9fef366 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -191,6 +191,8 @@ void RoadVehUpdateCache(RoadVehicle *v) /* Invalidate the vehicle colour map */ u->colourmap = PAL_NONE; } + + v->vcache.cached_max_speed = RoadVehInfo(v->engine_type)->max_speed; } /** @@ -384,17 +386,17 @@ void RoadVehicle::UpdateDeltaXY(Direction direction) */ FORCEINLINE int RoadVehicle::GetCurrentMaxSpeed() const { - if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) return this->max_speed; + if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) return this->vcache.cached_max_speed; - int max_speed = this->max_speed; + int max_speed = this->vcache.cached_max_speed; /* Limit speed to 50% while reversing, 75% in curves. */ for (const RoadVehicle *u = this; u != NULL; u = u->Next()) { if (this->state <= RVSB_TRACKDIR_MASK && IsReversingRoadTrackdir((Trackdir)this->state)) { - max_speed = this->max_speed / 2; + max_speed = this->vcache.cached_max_speed / 2; break; } else if ((u->direction & 1) == 0) { - max_speed = this->max_speed * 3 / 4; + max_speed = this->vcache.cached_max_speed * 3 / 4; } } @@ -753,7 +755,7 @@ static void RoadVehCheckOvertake(RoadVehicle *v, RoadVehicle *u) od.v = v; od.u = u; - if (u->max_speed >= v->max_speed && + if (u->max_speed >= v->vcache.cached_max_speed && !(u->vehstatus & VS_STOPPED) && u->cur_speed != 0) { return; @@ -806,7 +808,7 @@ static void RoadZPosAffectSpeed(RoadVehicle *v, byte old_z) v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10% } else { uint16 spd = v->cur_speed + 2; - if (spd <= v->max_speed) v->cur_speed = spd; + if (spd <= v->vcache.cached_max_speed) v->cur_speed = spd; } } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 7adacc88c..a5215f914 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -806,12 +806,7 @@ static int CDECL VehicleReliabilitySorter(const Vehicle * const *a, const Vehicl /** Sort vehicles by their max speed */ static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle * const *b) { - int r = 0; - if ((*a)->type != VEH_ROAD && (*b)->type != VEH_ROAD) { - r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed; - } else { - r = (*a)->max_speed - (*b)->max_speed; - } + int r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed; return (r != 0) ? r : VehicleNumberSorter(a, b); } |