mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 02:19:41 +00:00
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
This commit is contained in:
parent
25d1b2f54b
commit
18e3a3ddfc
@ -1232,8 +1232,15 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
|
|||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
t = u->vcache.cached_max_speed;
|
t = u->vcache.cached_max_speed;
|
||||||
break;
|
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();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,17 +717,12 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
|||||||
case 0x19: {
|
case 0x19: {
|
||||||
uint max_speed;
|
uint max_speed;
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN: /* FALL THROUGH */
|
|
||||||
case VEH_SHIP:
|
|
||||||
max_speed = v->vcache.cached_max_speed;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
|
max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
max_speed = v->max_speed;
|
max_speed = v->vcache.cached_max_speed;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
|
return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
|
||||||
|
@ -119,7 +119,7 @@ struct RoadVehicle : public GroundVehicle<RoadVehicle, VEH_ROAD> {
|
|||||||
bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
|
bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
|
||||||
SpriteID GetImage(Direction direction) const;
|
SpriteID GetImage(Direction direction) const;
|
||||||
int GetDisplaySpeed() const { return this->cur_speed / 2; }
|
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;
|
Money GetRunningCost() const;
|
||||||
int GetDisplayImageWidth(Point *offset = NULL) const;
|
int GetDisplayImageWidth(Point *offset = NULL) const;
|
||||||
bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
|
bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
|
||||||
|
@ -191,6 +191,8 @@ void RoadVehUpdateCache(RoadVehicle *v)
|
|||||||
/* Invalidate the vehicle colour map */
|
/* Invalidate the vehicle colour map */
|
||||||
u->colourmap = PAL_NONE;
|
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
|
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. */
|
/* Limit speed to 50% while reversing, 75% in curves. */
|
||||||
for (const RoadVehicle *u = this; u != NULL; u = u->Next()) {
|
for (const RoadVehicle *u = this; u != NULL; u = u->Next()) {
|
||||||
if (this->state <= RVSB_TRACKDIR_MASK && IsReversingRoadTrackdir((Trackdir)this->state)) {
|
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;
|
break;
|
||||||
} else if ((u->direction & 1) == 0) {
|
} 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.v = v;
|
||||||
od.u = u;
|
od.u = u;
|
||||||
|
|
||||||
if (u->max_speed >= v->max_speed &&
|
if (u->max_speed >= v->vcache.cached_max_speed &&
|
||||||
!(u->vehstatus & VS_STOPPED) &&
|
!(u->vehstatus & VS_STOPPED) &&
|
||||||
u->cur_speed != 0) {
|
u->cur_speed != 0) {
|
||||||
return;
|
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%
|
v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10%
|
||||||
} else {
|
} else {
|
||||||
uint16 spd = v->cur_speed + 2;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,12 +806,7 @@ static int CDECL VehicleReliabilitySorter(const Vehicle * const *a, const Vehicl
|
|||||||
/** Sort vehicles by their max speed */
|
/** Sort vehicles by their max speed */
|
||||||
static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle * const *b)
|
static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed;
|
||||||
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;
|
|
||||||
}
|
|
||||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user