1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-29 09:44:52 +01:00
Files
OpenRCT2/src/openrct2/localisation/Localisation.h
Duncan 0702808692 Use a game action result for clear at function (#10576)
* Use a game action result for clear at function

* Clean up callers of set_error_text

* Make it compile

* Make suggested changes

* fix compile

* Fix nullptr deref
2020-01-19 13:14:37 +00:00

111 lines
4.9 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#ifndef LOCALISATION_H
#define LOCALISATION_H
#include "../management/Marketing.h"
#include "Currency.h"
#include "Date.h"
#include "FormatCodes.h"
#include "Language.h"
#include "StringIds.h"
#include <cstring>
#include <string>
bool utf8_is_format_code(char32_t codepoint);
bool utf8_is_colour_code(char32_t codepoint);
bool utf8_should_use_sprite_for_codepoint(char32_t codepoint);
int32_t utf8_get_format_code_arg_length(char32_t codepoint);
void utf8_remove_formatting(utf8* string, bool allowColours);
std::string format_string(rct_string_id format, const void* args);
void format_string(char* dest, size_t size, rct_string_id format, const void* args);
void format_string_raw(char* dest, size_t size, const char* src, const void* args);
void format_string_to_upper(char* dest, size_t size, rct_string_id format, const void* args);
void generate_string_file();
/**
* Formats sizeBytes into buf as a human readable text, e.x.: "1024 MB"
*/
void format_readable_size(char* buf, size_t bufSize, uint64_t sizeBytes);
/**
* Formats sizeBytesPerSec into buf as a human readable text, e.x.: "1024 MB/sec"
*/
void format_readable_speed(char* buf, size_t bufSize, uint64_t sizeBytesPerSec);
utf8* get_string_end(const utf8* text);
size_t get_string_size(const utf8* text);
int32_t get_string_length(const utf8* text);
// The maximum number of characters allowed for string/money conversions (anything above will risk integer overflow issues)
#define MONEY_STRING_MAXLENGTH 14
money32 string_to_money(const char* string_to_monetise);
void money_to_string(money32 amount, char* buffer_to_put_value_to, size_t buffer_len, bool forceDecimals);
bool is_user_string_id(rct_string_id stringId);
#define MAX_USER_STRINGS 1024
#define USER_STRING_MAX_LENGTH 32
#define USER_STRING_START 0x8000
#define USER_STRING_END 0x8FFF
#define REAL_NAME_START 0xA000
#define REAL_NAME_END 0xDFFF
// Real name data
extern const char real_name_initials[16];
extern const char* real_names[1024];
extern thread_local char gCommonStringFormatBuffer[512];
extern thread_local uint8_t gCommonFormatArgs[80];
extern thread_local uint8_t gMapTooltipFormatArgs[40];
extern bool gDebugStringFormatting;
extern const rct_string_id SpeedNames[5];
extern const rct_string_id ObjectiveNames[12];
extern const rct_string_id ResearchFundingLevelNames[4];
extern const rct_string_id MarketingCampaignNames[ADVERTISING_CAMPAIGN_COUNT][3];
extern const rct_string_id RideInspectionIntervalNames[];
extern const rct_string_id PeepThoughts[174];
extern const rct_string_id DateDayNames[31];
extern const rct_string_id DateGameMonthNames[MONTH_COUNT];
extern const rct_string_id DateGameShortMonthNames[MONTH_COUNT];
[[maybe_unused]] static inline void set_format_arg_body(uint8_t* args, size_t offset, uintptr_t value, size_t size)
{
std::memcpy(args + offset, &value, size);
}
template<typename T> void constexpr set_format_arg(uint8_t* args, size_t offset, uintptr_t value)
{
static_assert(sizeof(T) <= sizeof(uintptr_t), "Type too large");
set_format_arg_body(args, offset, value, sizeof(T));
}
#define set_format_arg(offset, type, value) \
do \
{ \
static_assert(sizeof(type) <= sizeof(uintptr_t), "Type too large"); \
set_format_arg_body(gCommonFormatArgs, offset, (uintptr_t)(value), sizeof(type)); \
} while (false)
#define set_format_arg_on(args, offset, type, value) set_format_arg_body(args, offset, (uintptr_t)(value), sizeof(type))
#define set_map_tooltip_format_arg(offset, type, value) \
do \
{ \
static_assert(sizeof(type) <= sizeof(uintptr_t), "Type too large"); \
set_format_arg_body(gMapTooltipFormatArgs, offset, (uintptr_t)(value), sizeof(type)); \
} while (false)
#endif