mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r27758) -Change: Increase the maximum number of GameScript texts to 64k, and NewGRF texts to 512k.
This commit is contained in:
parent
fc4c4d080c
commit
2bb80d280c
@ -156,7 +156,7 @@ struct GRFTextEntry {
|
||||
|
||||
|
||||
static uint _num_grf_texts = 0;
|
||||
static GRFTextEntry _grf_text[TAB_SIZE * 3];
|
||||
static GRFTextEntry _grf_text[TAB_SIZE_NEWGRF];
|
||||
static byte _currentLangID = GRFLX_ENGLISH; ///< by default, english is used.
|
||||
|
||||
/**
|
||||
@ -693,7 +693,7 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
|
||||
|
||||
grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s'", id, grfid, stringid, newtext->langid, newtext->text);
|
||||
|
||||
return MakeStringID(TEXT_TAB_NEWGRF1, 0) + id; // Id reaches across multiple tabs
|
||||
return MakeStringID(TEXT_TAB_NEWGRF_START, id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -703,7 +703,7 @@ StringID GetGRFStringID(uint32 grfid, uint16 stringid)
|
||||
{
|
||||
for (uint id = 0; id < _num_grf_texts; id++) {
|
||||
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
|
||||
return MakeStringID(TEXT_TAB_NEWGRF1, 0) + id; // Id reaches across multiple tabs
|
||||
return MakeStringID(TEXT_TAB_NEWGRF_START, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,8 @@ ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::S
|
||||
{
|
||||
uint index = GetStringIndex(internal_string_id);
|
||||
switch (GetStringTab(internal_string_id)) {
|
||||
case TEXT_TAB_NEWGRF1:
|
||||
case TEXT_TAB_NEWGRF2:
|
||||
case TEXT_TAB_NEWGRF3:
|
||||
case TEXT_TAB_NEWGRF_START:
|
||||
case TEXT_TAB_GAMESCRIPT_START:
|
||||
return ERR_NEWGRF_SUPPLIED_ERROR; // NewGRF strings.
|
||||
|
||||
case TEXT_TAB_SPECIAL:
|
||||
|
@ -195,12 +195,10 @@ static bool _scan_for_gender_data = false; ///< Are we scanning for the gender
|
||||
const char *GetStringPtr(StringID string)
|
||||
{
|
||||
switch (GetStringTab(string)) {
|
||||
case TEXT_TAB_GAMESCRIPT: return GetGameStringPtr(GetStringIndex(string));
|
||||
case TEXT_TAB_GAMESCRIPT_START: return GetGameStringPtr(GetStringIndex(string));
|
||||
/* 0xD0xx and 0xD4xx IDs have been converted earlier. */
|
||||
case TEXT_TAB_OLD_NEWGRF: NOT_REACHED();
|
||||
case TEXT_TAB_NEWGRF1: return GetGRFStringPtr(GetStringIndex(string));
|
||||
case TEXT_TAB_NEWGRF2: return GetGRFStringPtr(GetStringIndex(string) + 0x0800);
|
||||
case TEXT_TAB_NEWGRF3: return GetGRFStringPtr(GetStringIndex(string) + 0x1000);
|
||||
case TEXT_TAB_NEWGRF_START: return GetGRFStringPtr(GetStringIndex(string));
|
||||
default: return _langpack_offs[_langtab_start[GetStringTab(string)] + GetStringIndex(string)];
|
||||
}
|
||||
}
|
||||
@ -242,21 +240,15 @@ char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, co
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXT_TAB_GAMESCRIPT:
|
||||
case TEXT_TAB_GAMESCRIPT_START:
|
||||
return FormatString(buffr, GetGameStringPtr(index), args, last, case_index, true);
|
||||
|
||||
case TEXT_TAB_OLD_NEWGRF:
|
||||
NOT_REACHED();
|
||||
|
||||
case TEXT_TAB_NEWGRF1:
|
||||
case TEXT_TAB_NEWGRF_START:
|
||||
return FormatString(buffr, GetGRFStringPtr(index), args, last, case_index);
|
||||
|
||||
case TEXT_TAB_NEWGRF2:
|
||||
return FormatString(buffr, GetGRFStringPtr(index + 0x0800), args, last, case_index);
|
||||
|
||||
case TEXT_TAB_NEWGRF3:
|
||||
return FormatString(buffr, GetGRFStringPtr(index + 0x1000), args, last, case_index);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -825,17 +817,16 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
sub_args.ClearTypeInformation();
|
||||
memset(sub_args_need_free, 0, sizeof(sub_args_need_free));
|
||||
|
||||
uint16 stringid;
|
||||
const char *s = str;
|
||||
char *p;
|
||||
stringid = strtol(str, &p, 16);
|
||||
uint32 stringid = strtoul(str, &p, 16);
|
||||
if (*p != ':' && *p != '\0') {
|
||||
while (*p != '\0') p++;
|
||||
str = p;
|
||||
buff = strecat(buff, "(invalid SCC_ENCODED)", last);
|
||||
break;
|
||||
}
|
||||
if (stringid >= TAB_SIZE) {
|
||||
if (stringid >= TAB_SIZE_GAMESCRIPT) {
|
||||
while (*p != '\0') p++;
|
||||
str = p;
|
||||
buff = strecat(buff, "(invalid StringID)", last);
|
||||
@ -883,13 +874,13 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
param = strtoull(s, &p, 16);
|
||||
|
||||
if (lookup) {
|
||||
if (param >= TAB_SIZE) {
|
||||
if (param >= TAB_SIZE_GAMESCRIPT) {
|
||||
while (*p != '\0') p++;
|
||||
str = p;
|
||||
buff = strecat(buff, "(invalid sub-StringID)", last);
|
||||
break;
|
||||
}
|
||||
param = MakeStringID(TEXT_TAB_GAMESCRIPT, param);
|
||||
param = MakeStringID(TEXT_TAB_GAMESCRIPT_START, param);
|
||||
}
|
||||
|
||||
sub_args.SetParam(i++, param);
|
||||
@ -904,7 +895,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
/* If we didn't error out, we can actually print the string. */
|
||||
if (*str != '\0') {
|
||||
str = p;
|
||||
buff = GetStringWithArgs(buff, MakeStringID(TEXT_TAB_GAMESCRIPT, stringid), &sub_args, last, true);
|
||||
buff = GetStringWithArgs(buff, MakeStringID(TEXT_TAB_GAMESCRIPT_START, stringid), &sub_args, last, true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
@ -1020,7 +1011,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
|
||||
case SCC_STRING: {// {STRING}
|
||||
StringID str = args->GetInt32(SCC_STRING);
|
||||
if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT) break;
|
||||
if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break;
|
||||
/* WARNING. It's prohibited for the included string to consume any arguments.
|
||||
* For included strings that consume argument, you should use STRING1, STRING2 etc.
|
||||
* To debug stuff you can set argv to NULL and it will tell you */
|
||||
@ -1039,7 +1030,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
case SCC_STRING7: { // {STRING1..7}
|
||||
/* Strings that consume arguments */
|
||||
StringID str = args->GetInt32(b);
|
||||
if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT) break;
|
||||
if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break;
|
||||
uint size = b - SCC_STRING1 + 1;
|
||||
if (game_script && size > args->GetDataLeft()) {
|
||||
buff = strecat(buff, "(too many parameters)", last);
|
||||
|
@ -24,7 +24,10 @@
|
||||
*/
|
||||
static inline StringTab GetStringTab(StringID str)
|
||||
{
|
||||
return (StringTab)GB(str, TAB_SIZE_BITS, 5);
|
||||
StringTab result = (StringTab)(str >> TAB_SIZE_BITS);
|
||||
if (result >= TEXT_TAB_NEWGRF_START) return TEXT_TAB_NEWGRF_START;
|
||||
if (result >= TEXT_TAB_GAMESCRIPT_START) return TEXT_TAB_GAMESCRIPT_START;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +37,7 @@ static inline StringTab GetStringTab(StringID str)
|
||||
*/
|
||||
static inline uint GetStringIndex(StringID str)
|
||||
{
|
||||
return GB(str, 0, TAB_SIZE_BITS);
|
||||
return str - (GetStringTab(str) << TAB_SIZE_BITS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,9 +48,15 @@ static inline uint GetStringIndex(StringID str)
|
||||
*/
|
||||
static inline StringID MakeStringID(StringTab tab, uint index)
|
||||
{
|
||||
assert(tab < TEXT_TAB_END);
|
||||
assert(index < TAB_SIZE);
|
||||
return tab << TAB_SIZE_BITS | index;
|
||||
if (tab == TEXT_TAB_NEWGRF_START) {
|
||||
assert(index < TAB_SIZE_NEWGRF);
|
||||
} else if (tab == TEXT_TAB_GAMESCRIPT_START) {
|
||||
assert(index < TAB_SIZE_GAMESCRIPT);
|
||||
} else {
|
||||
assert(tab < TEXT_TAB_END);
|
||||
assert(index < TAB_SIZE);
|
||||
}
|
||||
return (tab << TAB_SIZE_BITS) + index;
|
||||
}
|
||||
|
||||
class StringParameters {
|
||||
|
@ -36,12 +36,10 @@ enum StringTab {
|
||||
TEXT_TAB_OLD_CUSTOM = 15,
|
||||
TEXT_TAB_VEHICLE = 16,
|
||||
/* Tab 17 for regular strings */
|
||||
TEXT_TAB_GAMESCRIPT = 18,
|
||||
TEXT_TAB_OLD_NEWGRF = 26,
|
||||
TEXT_TAB_NEWGRF1 = 28,
|
||||
TEXT_TAB_NEWGRF2 = 29,
|
||||
TEXT_TAB_NEWGRF3 = 30,
|
||||
TEXT_TAB_END = 32
|
||||
TEXT_TAB_END = 32, ///< End of language files.
|
||||
TEXT_TAB_GAMESCRIPT_START = 32, ///< Start of GameScript supplied strings.
|
||||
TEXT_TAB_NEWGRF_START = 64, ///< Start of NewGRF supplied strings.
|
||||
};
|
||||
|
||||
/** Number of bits for the StringIndex within a StringTab */
|
||||
@ -49,6 +47,12 @@ static const uint TAB_SIZE_BITS = 11;
|
||||
/** Number of strings per StringTab */
|
||||
static const uint TAB_SIZE = 1 << TAB_SIZE_BITS;
|
||||
|
||||
/** Number of strings for GameScripts */
|
||||
static const uint TAB_SIZE_GAMESCRIPT = TAB_SIZE * 32;
|
||||
|
||||
/** Number of strings for NewGRFs */
|
||||
static const uint TAB_SIZE_NEWGRF = TAB_SIZE * 256;
|
||||
|
||||
/** Special string constants */
|
||||
enum SpecialStrings {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user