summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/newgrf.cpp48
-rw-r--r--src/newgrf_text.cpp62
-rw-r--r--src/newgrf_text.h2
3 files changed, 65 insertions, 47 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 6745f13e2..5b94adfff 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -266,18 +266,6 @@ StringIDToGRFIDMapping _string_to_grf_mapping;
*/
StringID MapGRFStringID(uint32 grfid, StringID str)
{
- /* StringID table for TextIDs 0x4E->0x6D */
- static const StringID units_volume[] = {
- STR_NOTHING, STR_PASSENGERS, STR_TONS, STR_BAGS,
- STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS,
- STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
- STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
- STR_TONS, STR_TONS, STR_BAGS, STR_LITERS,
- STR_TONS, STR_LITERS, STR_TONS, STR_NOTHING,
- STR_BAGS, STR_LITERS, STR_TONS, STR_NOTHING,
- STR_TONS, STR_NOTHING, STR_LITERS, STR_NOTHING
- };
-
/* 0xD0 and 0xDC stand for all the TextIDs in the range
* of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts).
* These strings are unique to each grf file, and thus require to be used with the
@@ -295,41 +283,7 @@ StringID MapGRFStringID(uint32 grfid, StringID str)
default: break;
}
-#define TEXTID_TO_STRINGID(begin, end, stringid) if (str >= begin && str <= end) return str + (stringid - begin)
- /* We have some changes in our cargo strings, resulting in some missing. */
- TEXTID_TO_STRINGID(0x000E, 0x002D, STR_CARGO_PLURAL_NOTHING);
- TEXTID_TO_STRINGID(0x002E, 0x004D, STR_CARGO_SINGULAR_NOTHING);
- if (str >= 0x004E && str <= 0x006D) return units_volume[str - 0x004E];
- TEXTID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING);
- TEXTID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING);
-
- /* Map building names according to our lang file changes. There are several
- * ranges of house ids, all of which need to be remapped to allow newgrfs
- * to use original house names. */
- TEXTID_TO_STRINGID(0x200F, 0x201F, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1);
- TEXTID_TO_STRINGID(0x2036, 0x2041, STR_TOWN_BUILDING_NAME_COTTAGES_1);
- TEXTID_TO_STRINGID(0x2059, 0x205C, STR_TOWN_BUILDING_NAME_IGLOO_1);
-
- /* Same thing for industries */
- TEXTID_TO_STRINGID(0x4802, 0x4826, STR_INDUSTRY_NAME_COAL_MINE);
- TEXTID_TO_STRINGID(0x4827, 0x4829, STR_INDUSTRY_VIEW_REQUIRES_CARGO);
- TEXTID_TO_STRINGID(0x482D, 0x482E, STR_NEWS_INDUSTRY_CONSTRUCTION);
- TEXTID_TO_STRINGID(0x4832, 0x4834, STR_NEWS_INDUSTRY_CLOSURE_GENERAL);
- TEXTID_TO_STRINGID(0x4835, 0x4838, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_GENERAL);
- TEXTID_TO_STRINGID(0x4839, 0x483A, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_GENERAL);
-
- switch (str) {
- case 0x4830: return STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY;
- case 0x4831: return STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED;
- case 0x483B: return STR_ERROR_CAN_ONLY_BE_POSITIONED;
- }
-#undef TEXTID_TO_STRINGID
-
- if (str == STR_NULL) return STR_EMPTY;
-
- DEBUG(grf, 0, "Unknown StringID 0x%04X remapped to STR_EMPTY. Please open a Feature Request if you need it", str);
-
- return STR_EMPTY;
+ return TTDPStringIDToOTTDStringIDMapping(str);
}
static inline uint8 MapDOSColour(uint8 colour)
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index 302bc589f..8e081b396 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -22,6 +22,7 @@
#include "newgrf_storage.h"
#include "string_func.h"
#include "date_type.h"
+#include "debug.h"
#include "table/strings.h"
#include "table/control_codes.h"
@@ -30,6 +31,67 @@
#define TABSIZE 11
/**
+ * Perform a mapping from TTDPatch's string IDs to OpenTTD's
+ * string IDs, but only for the ones we are aware off; the rest
+ * like likely unused and will show a warning.
+ * @param str the string ID to convert
+ * @return the converted string ID
+ */
+StringID TTDPStringIDToOTTDStringIDMapping(StringID str)
+{
+ /* StringID table for TextIDs 0x4E->0x6D */
+ static const StringID units_volume[] = {
+ STR_NOTHING, STR_PASSENGERS, STR_TONS, STR_BAGS,
+ STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS,
+ STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
+ STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
+ STR_TONS, STR_TONS, STR_BAGS, STR_LITERS,
+ STR_TONS, STR_LITERS, STR_TONS, STR_NOTHING,
+ STR_BAGS, STR_LITERS, STR_TONS, STR_NOTHING,
+ STR_TONS, STR_NOTHING, STR_LITERS, STR_NOTHING
+ };
+
+ /* A string straight from a NewGRF; no need to remap this as it's already mapped. */
+ if (IsInsideMM(str, 0xD000, 0xD7FF) || IsInsideMM(str, 0xDC00, 0xDCFF)) return str;
+
+#define TEXTID_TO_STRINGID(begin, end, stringid) if (str >= begin && str <= end) return str + (stringid - begin)
+ /* We have some changes in our cargo strings, resulting in some missing. */
+ TEXTID_TO_STRINGID(0x000E, 0x002D, STR_CARGO_PLURAL_NOTHING);
+ TEXTID_TO_STRINGID(0x002E, 0x004D, STR_CARGO_SINGULAR_NOTHING);
+ if (str >= 0x004E && str <= 0x006D) return units_volume[str - 0x004E];
+ TEXTID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING);
+ TEXTID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING);
+
+ /* Map building names according to our lang file changes. There are several
+ * ranges of house ids, all of which need to be remapped to allow newgrfs
+ * to use original house names. */
+ TEXTID_TO_STRINGID(0x200F, 0x201F, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1);
+ TEXTID_TO_STRINGID(0x2036, 0x2041, STR_TOWN_BUILDING_NAME_COTTAGES_1);
+ TEXTID_TO_STRINGID(0x2059, 0x205C, STR_TOWN_BUILDING_NAME_IGLOO_1);
+
+ /* Same thing for industries */
+ TEXTID_TO_STRINGID(0x4802, 0x4826, STR_INDUSTRY_NAME_COAL_MINE);
+ TEXTID_TO_STRINGID(0x4827, 0x4829, STR_INDUSTRY_VIEW_REQUIRES_CARGO);
+ TEXTID_TO_STRINGID(0x482D, 0x482E, STR_NEWS_INDUSTRY_CONSTRUCTION);
+ TEXTID_TO_STRINGID(0x4832, 0x4834, STR_NEWS_INDUSTRY_CLOSURE_GENERAL);
+ TEXTID_TO_STRINGID(0x4835, 0x4838, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_GENERAL);
+ TEXTID_TO_STRINGID(0x4839, 0x483A, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_GENERAL);
+
+ switch (str) {
+ case 0x4830: return STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY;
+ case 0x4831: return STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED;
+ case 0x483B: return STR_ERROR_CAN_ONLY_BE_POSITIONED;
+ }
+#undef TEXTID_TO_STRINGID
+
+ if (str == STR_NULL) return STR_EMPTY;
+
+ DEBUG(grf, 0, "Unknown StringID 0x%04X remapped to STR_EMPTY. Please open a Feature Request if you need it", str);
+
+ return STR_EMPTY;
+}
+
+/**
* Explains the newgrf shift bit positionning.
* the grf base will not be used in order to find the string, but rather for
* jumping from standard langID scheme to the new one.
diff --git a/src/newgrf_text.h b/src/newgrf_text.h
index 88bf59f61..8a237c1e3 100644
--- a/src/newgrf_text.h
+++ b/src/newgrf_text.h
@@ -28,4 +28,6 @@ void SwitchToErrorRefStack();
void RewindTextRefStack();
uint RemapNewGRFStringControlCode(uint scc, char **buff, const char **str, int64 *argv);
+StringID TTDPStringIDToOTTDStringIDMapping(StringID string);
+
#endif /* NEWGRF_TEXT_H */