mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-18 12:09:10 +00:00
Feature: [NewGRF] Engine name callback.
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "debug.h"
|
||||
#include "game/game_text.hpp"
|
||||
#include "network/network_content_gui.h"
|
||||
#include "newgrf_engine.h"
|
||||
#include <stack>
|
||||
|
||||
#include "table/strings.h"
|
||||
@@ -1371,17 +1372,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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user