1
0
Fork 0

(svn r22036) -Codechange: rename units to match coding style, and give conversion variables a more descriptive name

release/1.1
rubidium 2011-02-09 13:05:04 +00:00
parent fbb5f87801
commit f4f5de5be1
1 changed files with 45 additions and 45 deletions

View File

@ -570,24 +570,24 @@ struct UnitConversion {
}; };
struct Units { struct Units {
UnitConversion s; ///< Multiplier for velocity UnitConversion c_velocity; ///< Conversion for velocity
StringID velocity; ///< String for velocity StringID velocity; ///< String for velocity
UnitConversion p; ///< Multiplier for power UnitConversion c_power; ///< Conversion for power
StringID power; ///< String for velocity StringID power; ///< String for velocity
UnitConversion w; ///< Multiplier for weight UnitConversion c_weight; ///< Conversion for weight
StringID s_weight; ///< Short string for weight StringID s_weight; ///< Short string for weight
StringID l_weight; ///< Long string for weight StringID l_weight; ///< Long string for weight
UnitConversion v; ///< Multiplier for volume UnitConversion c_volume; ///< Conversion for volume
StringID s_volume; ///< Short string for volume StringID s_volume; ///< Short string for volume
StringID l_volume; ///< Long string for volume StringID l_volume; ///< Long string for volume
UnitConversion f; ///< Multiplier for force UnitConversion c_force; ///< Conversion for force
StringID force; ///< String for force StringID force; ///< String for force
UnitConversion h; ///< Multiplier for height UnitConversion c_height; ///< Conversion for height
StringID height; ///< String for height StringID height; ///< String for height
}; };
/* Unit conversions */ /* Unit conversions */
static const Units units[] = { static const Units _units[] = {
{ // Imperial (Original, mph, hp, metric ton, litre, kN, ft) { // Imperial (Original, mph, hp, metric ton, litre, kN, ft)
{ 1, 0}, STR_UNITS_VELOCITY_IMPERIAL, { 1, 0}, STR_UNITS_VELOCITY_IMPERIAL,
{ 1, 0}, STR_UNITS_POWER_IMPERIAL, { 1, 0}, STR_UNITS_POWER_IMPERIAL,
@ -621,7 +621,7 @@ static const Units units[] = {
*/ */
uint ConvertSpeedToDisplaySpeed(uint speed) uint ConvertSpeedToDisplaySpeed(uint speed)
{ {
return units[_settings_game.locale.units].s.ToDisplay(speed); return _units[_settings_game.locale.units].c_velocity.ToDisplay(speed);
} }
/** /**
@ -631,7 +631,7 @@ uint ConvertSpeedToDisplaySpeed(uint speed)
*/ */
uint ConvertDisplaySpeedToSpeed(uint speed) uint ConvertDisplaySpeedToSpeed(uint speed)
{ {
return units[_settings_game.locale.units].s.FromDisplay(speed); return _units[_settings_game.locale.units].c_velocity.FromDisplay(speed);
} }
/** /**
@ -733,16 +733,16 @@ static char *FormatString(char *buff, const char *str_arg, int64 *argv, const in
case SCC_VELOCITY: { // {VELOCITY} case SCC_VELOCITY: { // {VELOCITY}
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv, argve, &argt, SCC_VELOCITY) * 10 / 16); args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv, argve, &argt, SCC_VELOCITY) * 10 / 16);
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].velocity), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].velocity), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
case SCC_HEIGHT: { // {HEIGHT} case SCC_HEIGHT: { // {HEIGHT}
int64 args[1] = {units[_settings_game.locale.units].h.ToDisplay(GetInt32(&argv, argve, &argt))}; int64 args[1] = {_units[_settings_game.locale.units].c_height.ToDisplay(GetInt32(&argv, argve, &argt))};
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].height), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].height), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
@ -763,18 +763,18 @@ static char *FormatString(char *buff, const char *str_arg, int64 *argv, const in
switch (cargo_str) { switch (cargo_str) {
case STR_TONS: { case STR_TONS: {
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].w.ToDisplay(GetInt32(&argv, argve, &argt)); args[0] = _units[_settings_game.locale.units].c_weight.ToDisplay(GetInt32(&argv, argve, &argt));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].l_weight), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
case STR_LITERS: { case STR_LITERS: {
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].v.ToDisplay(GetInt32(&argv, argve, &argt)); args[0] = _units[_settings_game.locale.units].c_volume.ToDisplay(GetInt32(&argv, argve, &argt));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].l_volume), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
@ -858,9 +858,9 @@ static char *FormatString(char *buff, const char *str_arg, int64 *argv, const in
case SCC_VOLUME: { // {VOLUME} case SCC_VOLUME: { // {VOLUME}
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].v.ToDisplay(GetInt32(&argv, argve, &argt, SCC_VOLUME)); args[0] = _units[_settings_game.locale.units].c_volume.ToDisplay(GetInt32(&argv, argve, &argt, SCC_VOLUME));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].l_volume), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
@ -916,45 +916,45 @@ static char *FormatString(char *buff, const char *str_arg, int64 *argv, const in
case SCC_POWER: { // {POWER} case SCC_POWER: { // {POWER}
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].p.ToDisplay(GetInt32(&argv, argve, &argt)); args[0] = _units[_settings_game.locale.units].c_power.ToDisplay(GetInt32(&argv, argve, &argt));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].power), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].power), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
case SCC_VOLUME_SHORT: { // {VOLUME_S} case SCC_VOLUME_SHORT: { // {VOLUME_S}
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].v.ToDisplay(GetInt32(&argv, argve, &argt)); args[0] = _units[_settings_game.locale.units].c_volume.ToDisplay(GetInt32(&argv, argve, &argt));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_volume), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].s_volume), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
case SCC_WEIGHT: { // {WEIGHT} case SCC_WEIGHT: { // {WEIGHT}
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].w.ToDisplay(GetInt32(&argv, argve, &argt, SCC_WEIGHT)); args[0] = _units[_settings_game.locale.units].c_weight.ToDisplay(GetInt32(&argv, argve, &argt, SCC_WEIGHT));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].l_weight), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
case SCC_WEIGHT_SHORT: { // {WEIGHT_S} case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].w.ToDisplay(GetInt32(&argv, argve, &argt)); args[0] = _units[_settings_game.locale.units].c_weight.ToDisplay(GetInt32(&argv, argve, &argt));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_weight), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].s_weight), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }
case SCC_FORCE: { // {FORCE} case SCC_FORCE: { // {FORCE}
int64 args[1]; int64 args[1];
assert(_settings_game.locale.units < lengthof(units)); assert(_settings_game.locale.units < lengthof(_units));
args[0] = units[_settings_game.locale.units].f.ToDisplay(GetInt32(&argv, argve, &argt)); args[0] = _units[_settings_game.locale.units].c_force.ToDisplay(GetInt32(&argv, argve, &argt));
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].force), args, endof(args), modifier >> 24, last); buff = FormatString(buff, GetStringPtr(_units[_settings_game.locale.units].force), args, endof(args), modifier >> 24, last);
modifier = 0; modifier = 0;
break; break;
} }