mirror of https://github.com/OpenTTD/OpenTTD
(svn r27768) -Codechange: Use if and IsInsideMM instead of switch-case sequences to test for consecutive values.
parent
b5d1e58b0e
commit
5846aa5bfc
|
@ -550,24 +550,28 @@ static StringID TTDPStringIDToOTTDStringIDMapping(StringID str)
|
||||||
*/
|
*/
|
||||||
StringID MapGRFStringID(uint32 grfid, StringID str)
|
StringID MapGRFStringID(uint32 grfid, StringID str)
|
||||||
{
|
{
|
||||||
/* 0xD0 and 0xDC stand for all the TextIDs in the range
|
if (IsInsideMM(str, 0xDC00, 0xDD00)) {
|
||||||
* of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts).
|
/* General text provided by NewGRF.
|
||||||
* These strings are unique to each grf file, and thus require to be used with the
|
* In the specs this is called the 0xDCxx range (misc presistent texts).
|
||||||
* grfid in which they are declared */
|
* Note: We are not involved in the "persistent" business, since we do not store
|
||||||
switch (GB(str, 8, 8)) {
|
* any NewGRF strings in savegames. */
|
||||||
case 0xD0: case 0xD1: case 0xD2: case 0xD3:
|
return GetGRFStringID(grfid, str);
|
||||||
case 0xDC:
|
} else if (IsInsideMM(str, 0xD000, 0xD800)) {
|
||||||
return GetGRFStringID(grfid, str);
|
/* Callback text provided by NewGRF.
|
||||||
|
* In the specs this is called the 0xD0xx range (misc graphics texts).
|
||||||
case 0xD4: case 0xD5: case 0xD6: case 0xD7:
|
* These texts can be returned by various callbacks.
|
||||||
/* Strings embedded via 0x81 have 0x400 added to them (no real
|
*
|
||||||
* explanation why...) */
|
* Due to how TTDP implements the GRF-local- to global-textid translation
|
||||||
return GetGRFStringID(grfid, str - 0x400);
|
* texts included via 0x80 or 0x81 control codes have to add 0x400 to the textid.
|
||||||
|
* We do not care about that difference and just mask out the 0x400 bit.
|
||||||
default: break;
|
*/
|
||||||
|
str &= ~0x400;
|
||||||
|
return GetGRFStringID(grfid, str);
|
||||||
|
} else {
|
||||||
|
/* The NewGRF wants to include/reference an original TTD string.
|
||||||
|
* Try our best to find an equivalent one. */
|
||||||
|
return TTDPStringIDToOTTDStringIDMapping(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TTDPStringIDToOTTDStringIDMapping(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::map<uint32, uint32> _grf_id_overrides;
|
static std::map<uint32, uint32> _grf_id_overrides;
|
||||||
|
@ -5475,6 +5479,11 @@ static void FeatureNewName(ByteReader *buf)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
if (IsInsideMM(id, 0xD000, 0xD400) || IsInsideMM(id, 0xDC00, 0xDD00)) {
|
||||||
|
AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, true, name, STR_UNDEFINED);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (GB(id, 8, 8)) {
|
switch (GB(id, 8, 8)) {
|
||||||
case 0xC4: // Station class name
|
case 0xC4: // Station class name
|
||||||
if (_cur.grffile->stations == NULL || _cur.grffile->stations[GB(id, 0, 8)] == NULL) {
|
if (_cur.grffile->stations == NULL || _cur.grffile->stations[GB(id, 0, 8)] == NULL) {
|
||||||
|
@ -5509,14 +5518,6 @@ static void FeatureNewName(ByteReader *buf)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xD0:
|
|
||||||
case 0xD1:
|
|
||||||
case 0xD2:
|
|
||||||
case 0xD3:
|
|
||||||
case 0xDC:
|
|
||||||
AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, true, name, STR_UNDEFINED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
|
grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue