mirror of https://github.com/OpenTTD/OpenTTD
Add: Tiles/second wallclock mode for tiles/day velocity unit
parent
4c331ed7a2
commit
0b4311bf13
|
@ -214,7 +214,8 @@ STR_COLOUR_SECONDARY_SAME_AS_PRIMARY :Same As Primary
|
|||
STR_UNITS_VELOCITY_IMPERIAL :{DECIMAL}{NBSP}mph
|
||||
STR_UNITS_VELOCITY_METRIC :{DECIMAL}{NBSP}km/h
|
||||
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_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_METRIC :Metric (km/h)
|
||||
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_POWER :Vehicle power units: {STRING2}
|
||||
|
|
|
@ -746,12 +746,21 @@ struct UnitsLong {
|
|||
};
|
||||
|
||||
/** Unit conversions for velocity. */
|
||||
static const Units _units_velocity[] = {
|
||||
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
|
||||
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
|
||||
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
|
||||
{ { 0.578125 }, STR_UNITS_VELOCITY_GAMEUNITS, 1 },
|
||||
{ { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
|
||||
static const Units _units_velocity_calendar[] = {
|
||||
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
|
||||
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
|
||||
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
|
||||
{ { 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 },
|
||||
};
|
||||
|
||||
/** Unit conversions for power. */
|
||||
|
@ -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.
|
||||
* @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
|
||||
* conversion for speed. So, don't round it and keep the
|
||||
* 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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>();
|
||||
// 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));
|
||||
const auto &x = _units_velocity[units];
|
||||
const auto &x = GetVelocityUnits(vt);
|
||||
auto tmp_params = MakeParameters(ConvertKmhishSpeedToDisplaySpeed(GB(arg, 0, 56), vt), x.decimal_places);
|
||||
FormatString(builder, GetStringPtr(x.s), tmp_params);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue