void format_currency_2dp(char **dest, int value) { const rct_currency_spec *currencySpec = &g_currency_specs[gGeneral_config.currency_format]; int rate = currencySpec->rate; value *= rate; // Negative sign if (value < 0) { *(*dest)++ = '-'; value = -value; } // Currency symbol const char *symbol = currencySpec->symbol; // Prefix if (currencySpec->affix == CURRENCY_PREFIX) { strcpy(*dest, symbol); *dest += strlen(*dest); } // Drop the pennies for "large" currencies if (rate > 10) { format_comma_separated_integer(dest, value / 100); } else { format_comma_separated_fixed_2dp(dest, value); } // Currency symbol suffix if (currencySpec->affix == CURRENCY_SUFFIX) { strcpy(*dest, symbol); *dest += strlen(*dest); } }
void format_currency_2dp(char **dest, long long value) { const currency_descriptor *currencyDesc = &CurrencyDescriptors[gConfigGeneral.currency_format]; int rate = currencyDesc->rate; value *= rate; // Negative sign if (value < 0) { *(*dest)++ = '-'; value = -value; } // Currency symbol const utf8 *symbol = currencyDesc->symbol_unicode; uint8 affix = currencyDesc->affix_unicode; if (!font_supports_string(symbol, FONT_SIZE_MEDIUM)) { symbol = currencyDesc->symbol_ascii; affix = currencyDesc->affix_ascii; } // Prefix if (affix == CURRENCY_PREFIX) { safe_strcpy(*dest, symbol, CURRENCY_SYMBOL_MAX_SIZE); *dest += strlen(*dest); } // Drop the pennies for "large" currencies if (rate > 10) { format_comma_separated_integer(dest, value / 100); } else { format_comma_separated_fixed_2dp(dest, value); } // Currency symbol suffix if (affix == CURRENCY_SUFFIX) { safe_strcpy(*dest, symbol, CURRENCY_SYMBOL_MAX_SIZE); *dest += strlen(*dest); } }
void format_string_code(unsigned int format_code, char **dest, char **args) { int value; switch (format_code) { case FORMAT_COMMA32: // Pop argument value = *((sint32*)*args); *args += 4; format_comma_separated_integer(dest, value); break; case FORMAT_INT32: // Pop argument value = *((sint32*)*args); *args += 4; format_integer(dest, value); break; case FORMAT_COMMA2DP32: // Pop argument value = *((sint32*)*args); *args += 4; 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); *args += 2; format_comma_separated_integer(dest, value); break; case FORMAT_UINT16: // Pop argument value = *((uint16*)*args); *args += 2; format_integer(dest, value); break; case FORMAT_CURRENCY2DP: // Pop argument value = *((sint32*)*args); *args += 4; format_currency_2dp(dest, value); break; case FORMAT_CURRENCY: // Pop argument value = *((sint32*)*args); *args += 4; format_currency(dest, value); break; case FORMAT_STRINGID: case FORMAT_STRINGID2: // Pop argument value = *((uint16*)*args); *args += 2; format_string_part(dest, value, args); (*dest)--; break; case FORMAT_STRING: // Pop argument value = *((uint32*)*args); *args += 4; if (value != 0) { strcpy(*dest, (char*)value); *dest += strlen(*dest); } break; case FORMAT_MONTHYEAR: // Pop argument value = *((uint16*)*args); *args += 2; format_date(dest, value); break; case FORMAT_MONTH: // Pop argument value = *((uint16*)*args); *args += 2; strcpy(*dest, language_get_string(STR_MONTH_MARCH + date_get_month(value))); *dest += strlen(*dest); break; case FORMAT_VELOCITY: // Pop argument value = *((sint16*)*args); *args += 2; format_velocity(dest, value); break; case FORMAT_POP16: *args += 2; break; case FORMAT_PUSH16: *args -= 2; break; case FORMAT_DURATION: // Pop argument value = *((uint16*)*args); *args += 2; format_duration(dest, value); break; case FORMAT_REALTIME: // Pop argument value = *((uint16*)*args); *args += 2; format_realtime(dest, value); break; case FORMAT_LENGTH: // Pop argument value = *((sint16*)*args); *args += 2; format_length(dest, value); break; case FORMAT_SPRITE: // Pop argument value = *((uint32*)*args); *args += 4; *(*dest)++ = 23; *((uint32*)(*dest)) = value; *dest += 4; break; } }
void format_string_code(unsigned char format_code, char **dest, char **args) { int value; switch (format_code) { case FORMAT_COMMA32: // Pop argument value = *((sint32*)*args); *args += 4; format_comma_separated_integer(dest, value); break; case FORMAT_INT32: // Pop argument value = *((sint32*)*args); *args += 4; format_integer(dest, value); break; case FORMAT_COMMA2DP32: // Pop argument value = *((sint32*)*args); *args += 4; format_comma_separated_fixed_2dp(dest, value); break; case FORMAT_COMMA16: // Pop argument value = *((sint16*)*args); *args += 2; format_comma_separated_integer(dest, value); break; case FORMAT_UINT16: // Pop argument value = *((uint16*)*args); *args += 2; format_integer(dest, value); break; case FORMAT_CURRENCY2DP: // Pop argument value = *((sint32*)*args); *args += 4; format_currency_2dp(dest, value); break; case FORMAT_CURRENCY: // Pop argument value = *((sint32*)*args); *args += 4; format_currency(dest, value); break; case FORMAT_STRINGID: case FORMAT_STRINGID2: // Pop argument value = *((uint16*)*args); *args += 2; format_string_part(dest, value, args); (*dest)--; break; case FORMAT_STRING: // Pop argument value = *((uint32*)*args); *args += 4; strcpy(*dest, (char*)value); *dest += strlen(*dest); break; case FORMAT_MONTHYEAR: // Pop argument value = *((uint16*)*args); *args += 2; uint16 dateArgs[] = { date_get_month(value), date_get_year(value) + 1 }; uint16 *dateArgs2 = dateArgs; char formatString[] = "?, Year ?"; formatString[0] = FORMAT_MONTH; formatString[8] = FORMAT_COMMA16; format_string_part_from_raw(dest, formatString, (char**)&dateArgs2); (*dest)--; break; case FORMAT_MONTH: // Pop argument value = *((uint16*)*args); *args += 2; strcpy(*dest, get_string(STR_MONTH_MARCH + date_get_month(value))); *dest += strlen(*dest); break; case FORMAT_VELOCITY: // Pop argument value = *((sint16*)*args); *args += 2; if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, uint8)) { format_comma_separated_integer(dest, mph_to_kmph(value)); strcat(*dest, "kmh"); *dest += strlen(*dest); } else { format_comma_separated_integer(dest, value); strcat(*dest, "mph"); *dest += strlen(*dest); } break; case FORMAT_POP16: *args += 2; break; case FORMAT_PUSH16: *args -= 2; break; case FORMAT_DURATION: // Pop argument value = *((uint16*)*args); *args += 2; if (value / 60 > 0) { format_integer(dest, value / 60); strcpy(*dest, value / 60 == 1 ? "min:" : "mins:"); *dest += strlen(*dest); } format_integer(dest, value % 60); strcpy(*dest, value % 60 == 1 ? "sec:" : "secs:"); *dest += strlen(*dest); break; case FORMAT_REALTIME: // Pop argument value = *((uint16*)*args); *args += 2; if (value / 60 > 0) { format_integer(dest, value / 60); strcpy(*dest, value / 60 == 1 ? "hour:" : "hours:"); *dest += strlen(*dest); } format_integer(dest, value % 60); strcpy(*dest, value % 60 == 1 ? "min:" : "mins:"); *dest += strlen(*dest); break; case FORMAT_LENGTH: // Pop argument value = *((sint16*)*args); *args += 2; if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, uint8)) { format_comma_separated_integer(dest, value); strcat(*dest, "m"); *dest += strlen(*dest); } else { format_comma_separated_integer(dest, metres_to_feet(value)); strcat(*dest, "ft"); *dest += strlen(*dest); } break; case FORMAT_SPRITE: // Pop argument value = *((uint32*)*args); *args += 4; *(*dest)++ = 23; *((uint32*)(*dest)) = value; *dest += 4; break; } }