Codechange: Preprocess text ref stack parameters. (#13642)

NewGRF text ref stack is now processed in advance, creating parameters as necessary, and then encoding this into an EncodedString.
This commit is contained in:
Peter Nelson
2025-02-22 22:03:38 +00:00
committed by GitHub
parent 4ac81656ee
commit b28dca2222
12 changed files with 168 additions and 354 deletions
+7 -8
View File
@@ -473,6 +473,13 @@ CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, const GRF
if (cb_res < 0x400) {
res = CommandCost(GetGRFStringID(grffile->grfid, GRFSTR_MISC_GRF_TEXT + cb_res));
/* If this error isn't for the local player then it won't be seen, so don't bother encoding anything. */
if (!IsLocalCompany()) return res;
StringID stringid = GetGRFStringID(grffile->grfid, GRFSTR_MISC_GRF_TEXT + cb_res);
auto params = GetGRFSringTextStackParameters(grffile, stringid, 4);
res.SetEncodedMessage(GetEncodedStringWithArgs(stringid, params));
} else {
switch (cb_res) {
case 0x400: return res; // No error.
@@ -490,14 +497,6 @@ CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, const GRF
}
}
/* If this error isn't for the local player then it won't be seen, so don't bother encoding anything. */
if (!IsLocalCompany()) return res;
/* Copy some parameters from the registers to the error message text ref. stack */
std::array<StringParameter, 20> params{};
res.UseTextRefStack(grffile, 4);
res.SetEncodedMessage(GetEncodedStringWithArgs(res.GetErrorMessage(), params));
return res;
}