Merge branch 'master' into jgrpp

# Conflicts:
#	src/game/game_gui.cpp
#	src/graph_gui.cpp
#	src/linkgraph/linkgraph_gui.h
#	src/newgrf.cpp
#	src/order_gui.cpp
#	src/saveload/engine_sl.cpp
#	src/saveload/saveload.h
#	src/script/api/script_text.cpp
#	src/script/script_gui.cpp
#	src/settings_table.cpp
#	src/strings.cpp
#	src/table/settings/economy_settings.ini
#	src/table/settings/locale_settings.ini
#	src/timetable_gui.cpp
This commit is contained in:
Jonathan G Rennison
2023-04-10 15:11:53 +01:00
104 changed files with 527 additions and 293 deletions

View File

@@ -755,10 +755,11 @@ struct UnitsLong {
/** Unit conversions for velocity. */
static const Units _units_velocity[] = {
{ { 1, 0}, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 103, 6}, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 1831, 12}, STR_UNITS_VELOCITY_SI, 0 },
{ {37888, 16}, STR_UNITS_VELOCITY_GAMEUNITS, 1 },
{ { 1, 0}, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 103, 6}, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 1831, 12}, STR_UNITS_VELOCITY_SI, 0 },
{ { 37888, 16}, STR_UNITS_VELOCITY_GAMEUNITS, 1 },
{ { 7289499, 23}, STR_UNITS_VELOCITY_KNOTS, 0 },
};
/** Unit conversions for power. */
@@ -809,17 +810,29 @@ static const Units _units_height[] = {
{ { 1, 0}, STR_UNITS_HEIGHT_SI, 0 },
};
/**
* Get index for velocity conversion units for a vehicle type.
* @param type VehicleType to convert velocity for.
* @return Index within velocity conversion units for vehicle type.
*/
static byte GetVelocityUnits(VehicleType type)
{
if (type == VEH_SHIP || type == VEH_AIRCRAFT) return _settings_game.locale.units_velocity_nautical;
return _settings_game.locale.units_velocity;
}
/**
* Convert the given (internal) speed to the display speed.
* @param speed the speed to convert
* @return the converted speed.
*/
uint ConvertSpeedToDisplaySpeed(uint speed)
uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type)
{
/* For historical reasons we don't want to mess with the
* conversion for speed. So, don't round it and keep the
* original conversion factors instead of the real ones. */
return _units_velocity[_settings_game.locale.units_velocity].c.ToDisplay(speed, false);
return _units_velocity[GetVelocityUnits(type)].c.ToDisplay(speed, false);
}
/**
@@ -827,9 +840,9 @@ uint ConvertSpeedToDisplaySpeed(uint speed)
* @param speed the speed to convert
* @return the converted speed.
*/
uint ConvertSpeedToUnitDisplaySpeed(uint speed)
uint ConvertSpeedToUnitDisplaySpeed(uint speed, VehicleType type)
{
uint result = ConvertSpeedToDisplaySpeed(speed);
uint result = ConvertSpeedToDisplaySpeed(speed, type);
for (uint i = 0; i < _units_velocity[_settings_game.locale.units_velocity].decimal_places; i++) {
result /= 10;
}
@@ -841,9 +854,9 @@ uint ConvertSpeedToUnitDisplaySpeed(uint speed)
* @param speed the speed to convert
* @return the converted speed.
*/
uint ConvertDisplaySpeedToSpeed(uint speed)
uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type)
{
return _units_velocity[_settings_game.locale.units_velocity].c.FromDisplay(speed);
return _units_velocity[GetVelocityUnits(type)].c.FromDisplay(speed);
}
/**
@@ -851,9 +864,9 @@ uint ConvertDisplaySpeedToSpeed(uint speed)
* @param speed the speed to convert
* @return the converted speed.
*/
uint ConvertKmhishSpeedToDisplaySpeed(uint speed)
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
{
return _units_velocity[_settings_game.locale.units_velocity].c.ToDisplay(speed * 10, false) / 16;
return _units_velocity[GetVelocityUnits(type)].c.ToDisplay(speed * 10, false) / 16;
}
/**
@@ -861,9 +874,9 @@ uint ConvertKmhishSpeedToDisplaySpeed(uint speed)
* @param speed the speed to convert
* @return the converted speed.
*/
uint ConvertDisplaySpeedToKmhishSpeed(uint speed)
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
{
return _units_velocity[_settings_game.locale.units_velocity].c.FromDisplay(speed * 16, true, 10);
return _units_velocity[GetVelocityUnits(type)].c.FromDisplay(speed * 16, true, 10);
}
/**
@@ -1620,11 +1633,15 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
}
case SCC_VELOCITY: { // {VELOCITY}
assert(_settings_game.locale.units_velocity < lengthof(_units_velocity));
unsigned int decimal_places = _units_velocity[_settings_game.locale.units_velocity].decimal_places;
uint64 args_array[] = {ConvertKmhishSpeedToDisplaySpeed(args->GetInt64(SCC_VELOCITY)), decimal_places};
int64 arg = args->GetInt64(SCC_VELOCITY);
// Unpack vehicle type from packed argument to get desired units.
VehicleType vt = static_cast<VehicleType>(GB(arg, 56, 8));
byte units = GetVelocityUnits(vt);
assert(units < lengthof(_units_velocity));
unsigned int decimal_places = _units_velocity[units].decimal_places;
uint64 args_array[] = {ConvertKmhishSpeedToDisplaySpeed(GB(arg, 0, 56), vt), decimal_places};
StringParameters tmp_params(args_array, decimal_places ? 2 : 1, nullptr);
buff = FormatString(buff, GetStringPtr(_units_velocity[_settings_game.locale.units_velocity].s), &tmp_params, last);
buff = FormatString(buff, GetStringPtr(_units_velocity[units].s), &tmp_params, last);
break;
}