Feature: Display power-to-weight ratio in ground vehicle details GUI
This commit is contained in:

committed by
Michael Lutz

parent
b304c06a4a
commit
59dbcdb5ba
@@ -2987,3 +2987,29 @@ void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the maximum weight of the ground vehicle when loaded.
|
||||
* @return Weight in tonnes
|
||||
*/
|
||||
uint32 Vehicle::GetDisplayMaxWeight() const
|
||||
{
|
||||
uint32 max_weight = 0;
|
||||
|
||||
for (const Vehicle* u = this; u != nullptr; u = u->Next()) {
|
||||
max_weight += u->GetMaxWeight();
|
||||
}
|
||||
|
||||
return max_weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the minimum power-to-weight ratio using the maximum weight of the ground vehicle
|
||||
* @return power-to-weight ratio in 10ths of hp(I) per tonne
|
||||
*/
|
||||
uint32 Vehicle::GetDisplayMinPowerToWeight() const
|
||||
{
|
||||
uint32 max_weight = GetDisplayMaxWeight();
|
||||
if (max_weight == 0) return 0;
|
||||
return GetGroundVehicleCache()->cached_power * 10u / max_weight;
|
||||
}
|
||||
|
Reference in New Issue
Block a user