Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / newgrf_text.h
blob66f591f588baf8f2aaa0dbb21f4e1e88768d531d
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file newgrf_text.h Header of Action 04 "universal holder" structure and functions */
10 #ifndef NEWGRF_TEXT_H
11 #define NEWGRF_TEXT_H
13 #include "string_type.h"
14 #include "strings_type.h"
15 #include "table/control_codes.h"
16 #include <utility>
18 /** This character, the thorn ('รพ'), indicates a unicode string to NFO. */
19 static const char32_t NFO_UTF8_IDENTIFIER = 0x00DE;
21 /** A GRF text with associated language ID. */
22 struct GRFText {
23 byte langid; ///< The language associated with this GRFText.
24 std::string text; ///< The actual (translated) text.
27 /** A GRF text with a list of translations. */
28 typedef std::vector<GRFText> GRFTextList;
29 /** Reference counted wrapper around a GRFText pointer. */
30 typedef std::shared_ptr<GRFTextList> GRFTextWrapper;
32 StringID AddGRFString(uint32_t grfid, uint16_t stringid, byte langid, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string);
33 StringID GetGRFStringID(uint32_t grfid, StringID stringid);
34 const char *GetGRFStringFromGRFText(const GRFTextList &text_list);
35 const char *GetGRFStringFromGRFText(const GRFTextWrapper &text);
36 const char *GetGRFStringPtr(uint32_t stringid);
37 void CleanUpStrings();
38 void SetCurrentGrfLangID(byte language_id);
39 std::string TranslateTTDPatchCodes(uint32_t grfid, uint8_t language_id, bool allow_newlines, const std::string &str, StringControlCode byte80 = SCC_NEWGRF_PRINT_WORD_STRING_ID);
40 void AddGRFTextToList(GRFTextList &list, byte langid, uint32_t grfid, bool allow_newlines, const char *text_to_add);
41 void AddGRFTextToList(GRFTextWrapper &list, byte langid, uint32_t grfid, bool allow_newlines, const char *text_to_add);
42 void AddGRFTextToList(GRFTextWrapper &list, const std::string &text_to_add);
44 bool CheckGrfLangID(byte lang_id, byte grf_version);
46 void StartTextRefStackUsage(const struct GRFFile *grffile, byte numEntries, const uint32_t *values = nullptr);
47 void StopTextRefStackUsage();
48 bool UsingNewGRFTextStack();
49 struct TextRefStack *CreateTextRefStackBackup();
50 void RestoreTextRefStackBackup(struct TextRefStack *backup);
52 /** Mapping of language data between a NewGRF and OpenTTD. */
53 struct LanguageMap {
54 /** Mapping between NewGRF and OpenTTD IDs. */
55 struct Mapping {
56 byte newgrf_id; ///< NewGRF's internal ID for a case/gender.
57 byte openttd_id; ///< OpenTTD's internal ID for a case/gender.
60 /* We need a vector and can't use SmallMap due to the fact that for "setting" a
61 * gender of a string or requesting a case for a substring we want to map from
62 * the NewGRF's internal ID to OpenTTD's ID whereas for the choice lists we map
63 * the genders/cases/plural OpenTTD IDs to the NewGRF's internal IDs. In this
64 * case a NewGRF developer/translator might want a different translation for
65 * both cases. Thus we are basically implementing a multi-map. */
66 std::vector<Mapping> gender_map; ///< Mapping of NewGRF and OpenTTD IDs for genders.
67 std::vector<Mapping> case_map; ///< Mapping of NewGRF and OpenTTD IDs for cases.
68 int plural_form; ///< The plural form used for this language.
70 int GetMapping(int newgrf_id, bool gender) const;
71 int GetReverseMapping(int openttd_id, bool gender) const;
72 static const LanguageMap *GetLanguageMap(uint32_t grfid, uint8_t language_id);
75 #endif /* NEWGRF_TEXT_H */