1
0
Fork 0

Add: Tiles/second wallclock mode for tiles/day velocity unit

pull/11341/head
Tyler Trahan 2023-09-28 09:40:02 -04:00
parent 4c331ed7a2
commit 0b4311bf13
2 changed files with 33 additions and 20 deletions

View File

@ -214,7 +214,8 @@ STR_COLOUR_SECONDARY_SAME_AS_PRIMARY :Same As Primary
STR_UNITS_VELOCITY_IMPERIAL :{DECIMAL}{NBSP}mph STR_UNITS_VELOCITY_IMPERIAL :{DECIMAL}{NBSP}mph
STR_UNITS_VELOCITY_METRIC :{DECIMAL}{NBSP}km/h STR_UNITS_VELOCITY_METRIC :{DECIMAL}{NBSP}km/h
STR_UNITS_VELOCITY_SI :{DECIMAL}{NBSP}m/s STR_UNITS_VELOCITY_SI :{DECIMAL}{NBSP}m/s
STR_UNITS_VELOCITY_GAMEUNITS :{DECIMAL}{NBSP}tiles/day STR_UNITS_VELOCITY_GAMEUNITS_DAY :{DECIMAL}{NBSP}tiles/day
STR_UNITS_VELOCITY_GAMEUNITS_SEC :{DECIMAL}{NBSP}tiles/sec
STR_UNITS_VELOCITY_KNOTS :{DECIMAL}{NBSP}knots STR_UNITS_VELOCITY_KNOTS :{DECIMAL}{NBSP}knots
STR_UNITS_POWER_IMPERIAL :{DECIMAL}{NBSP}hp STR_UNITS_POWER_IMPERIAL :{DECIMAL}{NBSP}hp
@ -2025,7 +2026,7 @@ STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_HELPTEXT :Whenever a spee
STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_IMPERIAL :Imperial (mph) STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_IMPERIAL :Imperial (mph)
STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_METRIC :Metric (km/h) STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_METRIC :Metric (km/h)
STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_SI :SI (m/s) STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_SI :SI (m/s)
STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_GAMEUNITS :Game units (tiles/day) STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_GAMEUNITS :Game units ({TKM "tiles/day" "tiles/sec"})
STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_KNOTS :Knots STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_KNOTS :Knots
STR_CONFIG_SETTING_LOCALISATION_UNITS_POWER :Vehicle power units: {STRING2} STR_CONFIG_SETTING_LOCALISATION_UNITS_POWER :Vehicle power units: {STRING2}

View File

@ -746,11 +746,20 @@ struct UnitsLong {
}; };
/** Unit conversions for velocity. */ /** Unit conversions for velocity. */
static const Units _units_velocity[] = { static const Units _units_velocity_calendar[] = {
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 }, { { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 }, { { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 }, { { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
{ { 0.578125 }, STR_UNITS_VELOCITY_GAMEUNITS, 1 }, { { 0.578125 }, STR_UNITS_VELOCITY_GAMEUNITS_DAY, 1 },
{ { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
};
/** Unit conversions for velocity. */
static const Units _units_velocity_realtime[] = {
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
{ { 0.289352 }, STR_UNITS_VELOCITY_GAMEUNITS_SEC, 1 },
{ { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 }, { { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
}; };
@ -827,15 +836,20 @@ static const Units _units_time_years_or_minutes[] = {
}; };
/** /**
* Get index for velocity conversion units for a vehicle type. * Get the correct velocity units depending on the vehicle type and whether we're using real-time units.
* @param type VehicleType to convert velocity for. * @param type VehicleType to convert velocity for.
* @return Index within velocity conversion units for vehicle type. * @return The Units for the proper vehicle and time mode.
*/ */
static byte GetVelocityUnits(VehicleType type) static const Units GetVelocityUnits(VehicleType type)
{ {
if (type == VEH_SHIP || type == VEH_AIRCRAFT) return _settings_game.locale.units_velocity_nautical; byte setting = (type == VEH_SHIP || type == VEH_AIRCRAFT) ? _settings_game.locale.units_velocity_nautical : _settings_game.locale.units_velocity;
return _settings_game.locale.units_velocity; assert(setting < lengthof(_units_velocity_calendar));
assert(setting < lengthof(_units_velocity_realtime));
if (TimerGameEconomy::UsingWallclockUnits()) return _units_velocity_realtime[setting];
return _units_velocity_calendar[setting];
} }
/** /**
@ -848,7 +862,7 @@ uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type)
/* For historical reasons we don't want to mess with the /* For historical reasons we don't want to mess with the
* conversion for speed. So, don't round it and keep the * conversion for speed. So, don't round it and keep the
* original conversion factors instead of the real ones. */ * original conversion factors instead of the real ones. */
return _units_velocity[GetVelocityUnits(type)].c.ToDisplay(speed, false); return GetVelocityUnits(type).c.ToDisplay(speed, false);
} }
/** /**
@ -858,7 +872,7 @@ uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type)
*/ */
uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type) uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type)
{ {
return _units_velocity[GetVelocityUnits(type)].c.FromDisplay(speed); return GetVelocityUnits(type).c.FromDisplay(speed);
} }
/** /**
@ -868,7 +882,7 @@ uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type)
*/ */
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type) uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
{ {
return _units_velocity[GetVelocityUnits(type)].c.ToDisplay(speed * 10, false) / 16; return GetVelocityUnits(type).c.ToDisplay(speed * 10, false) / 16;
} }
/** /**
@ -878,7 +892,7 @@ uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
*/ */
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type) uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
{ {
return _units_velocity[GetVelocityUnits(type)].c.FromDisplay(speed * 16, true, 10); return GetVelocityUnits(type).c.FromDisplay(speed * 16, true, 10);
} }
/** /**
@ -1358,9 +1372,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
int64_t arg = args.GetNextParameter<int64_t>(); int64_t arg = args.GetNextParameter<int64_t>();
// Unpack vehicle type from packed argument to get desired units. // Unpack vehicle type from packed argument to get desired units.
VehicleType vt = static_cast<VehicleType>(GB(arg, 56, 8)); VehicleType vt = static_cast<VehicleType>(GB(arg, 56, 8));
byte units = GetVelocityUnits(vt); const auto &x = GetVelocityUnits(vt);
assert(units < lengthof(_units_velocity));
const auto &x = _units_velocity[units];
auto tmp_params = MakeParameters(ConvertKmhishSpeedToDisplaySpeed(GB(arg, 0, 56), vt), x.decimal_places); auto tmp_params = MakeParameters(ConvertKmhishSpeedToDisplaySpeed(GB(arg, 0, 56), vt), x.decimal_places);
FormatString(builder, GetStringPtr(x.s), tmp_params); FormatString(builder, GetStringPtr(x.s), tmp_params);
break; break;