Implement critical breakdown speed reduction for road vehicles

This commit is contained in:
Jonathan G Rennison
2018-01-04 19:18:24 +00:00
parent beda7ebb39
commit 0a80aec634
8 changed files with 42 additions and 6 deletions

View File

@@ -430,13 +430,29 @@ void RoadVehicle::UpdateDeltaXY(Direction direction)
this->z_extent = 6;
}
/**
* Calculates the maximum speed of the vehicle, taking into account speed reductions following critical breakdowns
* @return Maximum speed of the vehicle.
*/
int RoadVehicle::GetEffectiveMaxSpeed() const
{
int max_speed = this->vcache.cached_max_speed;
for (uint i = 0; i < this->critical_breakdown_count; i++) {
max_speed = min(max_speed - (max_speed / 3) + 1, max_speed);
}
/* clamp speed to be no less than lower of 5mph and 1/8 of base speed */
return max<uint16>(max_speed, min<uint16>(10, (this->vcache.cached_max_speed + 7) >> 3));
}
/**
* Calculates the maximum speed of the vehicle under its current conditions.
* @return Maximum speed of the vehicle.
*/
inline int RoadVehicle::GetCurrentMaxSpeed() const
{
int max_speed = this->vcache.cached_max_speed;
int max_speed = this->GetEffectiveMaxSpeed();
/* Limit speed to 50% while reversing, 75% in curves. */
for (const RoadVehicle *u = this; u != NULL; u = u->Next()) {