Add one decimal place to SI velocities

This commit is contained in:
Jonathan Haas 2015-12-20 11:20:01 +01:00
parent 229abec6bf
commit bf536ce7b7
5 changed files with 83 additions and 9 deletions

View File

@ -3921,7 +3921,7 @@ STR_5579 :Window scale factor:
STR_5580 :Czech koruna (Kc)
STR_5581 :Show FPS
STR_5582 :Trap mouse cursor in window
STR_5583 :{COMMA16}ms{POWERNEGATIVEONE}
STR_5583 :{COMMA1DP16}ms{POWERNEGATIVEONE}
STR_5584 :SI
#####################

View File

@ -134,6 +134,7 @@ enum {
FORMAT_SYMBOL_RAILWAY = 20001,
FORMAT_SYMBOL_ROAD = 20002,
FORMAT_SYMBOL_FLAG = 20003,
FORMAT_COMMA1DP16 = 20004
};
#endif

View File

@ -109,7 +109,8 @@ format_code_token format_code_tokens[] = {
{ FORMAT_SMALLUP, "SMALLUP" },
{ FORMAT_SMALLDOWN, "SMALLDOWN" },
{ FORMAT_LEFT, "LEFT" },
{ FORMAT_INVERTEDQUESTION, "INVERTEDQUESTION" }
{ FORMAT_INVERTEDQUESTION, "INVERTEDQUESTION" },
{ FORMAT_COMMA1DP16, "COMMA1DP16" }
};
uint32 format_get_code(const char *token)
@ -275,6 +276,71 @@ void format_comma_separated_integer(char **dest, long long value)
*dest = finish;
}
void format_comma_separated_fixed_1dp(char **dest, long long value)
{
int digit, groupIndex;
char *dst = *dest;
char *finish;
char tmp;
const char *commaMark = language_get_string(5151);
const char *decimalMark = language_get_string(5152);
const char *ch;
// Negative sign
if (value < 0) {
*dst++ = '-';
value = -value;
}
*dest = dst;
// One decimal place
digit = value % 10;
value /= 10;
*dst++ = '0' + digit;
ch = decimalMark;
while (*ch != 0) {
*dst++ = *ch++;
}
if (value == 0) {
*dst++ = '0';
} else {
// Groups of three digits, right to left
groupIndex = 0;
while (value > 0) {
// Append group separator
if (groupIndex == 3) {
groupIndex = 0;
ch = commaMark;
while (*ch != 0) {
*dst++ = *ch++;
}
}
digit = value % 10;
value /= 10;
*dst++ = '0' + digit;
groupIndex++;
}
}
finish = dst;
// Reverse string
dst--;
while (*dest < dst) {
tmp = **dest;
**dest = *dst;
*dst = tmp;
(*dest)++;
dst--;
}
*dest = finish;
}
void format_comma_separated_fixed_2dp(char **dest, long long value)
{
int digit, groupIndex;
@ -461,7 +527,7 @@ void format_velocity(char **dest, uint16 value)
stringId = STR_UNIT_SUFFIX_KILOMETRES_PER_HOUR;
break;
case MEASUREMENT_FORMAT_SI:
value = mph_to_mps(value);
value = mph_to_dmps(value);
stringId = STR_UNIT_SUFFIX_METRES_PER_SECOND;
break;
}
@ -517,7 +583,7 @@ void format_realtime(char **dest, uint16 value)
(*dest)--;
}
void format_string_code(unsigned char format_code, char **dest, char **args)
void format_string_code(unsigned int format_code, char **dest, char **args)
{
int value;
@ -543,6 +609,13 @@ void format_string_code(unsigned char format_code, char **dest, char **args)
format_comma_separated_fixed_2dp(dest, value);
break;
case FORMAT_COMMA1DP16:
// Pop argument
value = *((sint16*)*args);
*args += 2;
format_comma_separated_fixed_1dp(dest, value);
break;
case FORMAT_COMMA16:
// Pop argument
value = *((sint16*)*args);
@ -676,7 +749,7 @@ void format_string_part_from_raw(utf8 **dest, const utf8 *src, char **args)
}
} else if (code <= 'z') {
*(*dest)++ = code;
} else if (code < 142) {
} else if (code < 142 || code == FORMAT_COMMA1DP16) {
format_string_code(code, dest, args);
} else {
*dest = utf8_write_codepoint(*dest, code);

View File

@ -43,10 +43,10 @@ int mph_to_kmph(int mph)
return (mph * 1648) >> 10;
}
int mph_to_mps(int mph)
int mph_to_dmps(int mph)
{
// 1 mph = 0.44704 m/s
return (mph * 58594) >> 17;
// 1 mph = 4.4704 decimeters/s
return (mph * 73243) >> 14;
}
bool filename_valid_characters(const utf8 *filename)

View File

@ -26,7 +26,7 @@
int squaredmetres_to_squaredfeet(int squaredMetres);
int metres_to_feet(int metres);
int mph_to_kmph(int mph);
int mph_to_mps(int mph);
int mph_to_dmps(int mph);
bool filename_valid_characters(const utf8 *filename);