Add function for speed unit conversion to unit values

This commit is contained in:
Jonathan G Rennison
2021-06-13 22:41:17 +01:00
parent 8e27202524
commit f786b372c0
2 changed files with 15 additions and 0 deletions

View File

@@ -798,6 +798,20 @@ uint ConvertSpeedToDisplaySpeed(uint speed)
return _units_velocity[_settings_game.locale.units_velocity].c.ToDisplay(speed, false);
}
/**
* Convert the given (internal) speed to the display speed, in units (not decimal values).
* @param speed the speed to convert
* @return the converted speed.
*/
uint ConvertSpeedToUnitDisplaySpeed(uint speed)
{
uint result = ConvertSpeedToDisplaySpeed(speed);
for (uint i = 0; i < _units_velocity[_settings_game.locale.units_velocity].decimal_places; i++) {
result /= 10;
}
return result;
}
/**
* Convert the given display speed to the (internal) speed.
* @param speed the speed to convert

View File

@@ -8,6 +8,7 @@
/** @file unit_conversion.h Functions related to unit conversion. */
uint ConvertSpeedToDisplaySpeed(uint speed);
uint ConvertSpeedToUnitDisplaySpeed(uint speed);
uint ConvertDisplaySpeedToSpeed(uint speed);
uint ConvertWeightToDisplayWeight(uint weight);
uint ConvertDisplayWeightToWeight(uint weight);