Feature: [NewGRF] Engine name callback.

(cherry picked from commit 05ed9f56fd)
This commit is contained in:
Michael Lutz
2023-01-22 22:06:48 +01:00
committed by Jonathan G Rennison
parent 5daaa45e4a
commit 07c923eceb
12 changed files with 62 additions and 19 deletions

View File

@@ -36,6 +36,7 @@
#include "tracerestrict.h"
#include "game/game_text.hpp"
#include "network/network_content_gui.h"
#include "newgrf_engine.h"
#include "core/y_combinator.hpp"
#include <stack>
@@ -1717,17 +1718,38 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
}
case SCC_ENGINE_NAME: { // {ENGINE}
const Engine *e = Engine::GetIfValid(args->GetInt32(SCC_ENGINE_NAME));
int64 arg = args->GetInt64(SCC_ENGINE_NAME);
const Engine *e = Engine::GetIfValid(static_cast<EngineID>(arg));
if (e == nullptr) break;
if (!e->name.empty() && e->IsEnabled()) {
int64 args_array[] = {(int64)(size_t)e->name.c_str()};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
StringParameters tmp_params(nullptr, 0, nullptr);
buff = GetStringWithArgs(buff, e->info.string_id, &tmp_params, last);
break;
}
if (HasBit(e->info.callback_mask, CBM_VEHICLE_NAME)) {
uint16 callback = GetVehicleCallback(CBID_VEHICLE_NAME, static_cast<uint32>(arg >> 32), 0, e->index, nullptr);
/* Not calling ErrorUnknownCallbackResult due to being inside string processing. */
if (callback != CALLBACK_FAILED && callback < 0x400) {
const GRFFile *grffile = e->GetGRF();
assert(grffile != nullptr);
StartTextRefStackUsage(grffile, 6);
uint64 tmp_dparam[6] = { 0 };
WChar tmp_type[6] = { 0 };
StringParameters tmp_params(tmp_dparam, 6, tmp_type);
buff = GetStringWithArgs(buff, GetGRFStringID(grffile->grfid, 0xD000 + callback), &tmp_params, last);
StopTextRefStackUsage();
break;
}
}
StringParameters tmp_params(nullptr, 0, nullptr);
buff = GetStringWithArgs(buff, e->info.string_id, &tmp_params, last);
break;
}