Codechange: make GetSpecialNameString less magic-number heavy

This commit is contained in:
Rubidium 2025-01-04 11:11:55 +01:00 committed by rubidium42
parent 1e383d576b
commit 76cc3438bf

View File

@ -191,7 +191,7 @@ bool HaveDParamChanged(const std::span<const StringParameterData> backup)
static void StationGetSpecialString(StringBuilder &builder, StationFacility x);
static void GetSpecialTownNameString(StringBuilder &builder, int ind, uint32_t seed);
static void GetSpecialNameString(StringBuilder &builder, int ind, StringParameters &args);
static bool GetSpecialNameString(StringBuilder &builder, StringID string, StringParameters &args);
static void FormatString(StringBuilder &builder, const char *str, StringParameters &args, uint case_index = 0, bool game_script = false, bool dry_run = false);
@ -278,14 +278,14 @@ void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters
break;
case TEXT_TAB_SPECIAL:
if (index >= 0xE4 && !game_script) {
if (!game_script) {
try {
GetSpecialNameString(builder, index.base() - 0xE4, args);
if (GetSpecialNameString(builder, string, args)) return;
} catch (const std::runtime_error &e) {
Debug(misc, 0, "GetStringWithArgs: {}", e.what());
builder += "(invalid string parameter)";
return;
}
return;
}
break;
@ -1873,30 +1873,30 @@ static void GenPresidentName(StringBuilder &builder, uint32_t seed)
builder += GetSurname(seed);
}
static void GetSpecialNameString(StringBuilder &builder, int ind, StringParameters &args)
static bool GetSpecialNameString(StringBuilder &builder, StringID string, StringParameters &args)
{
switch (ind) {
case 1: // not used
switch (string) {
case SPECSTR_SILLY_NAME: // Not used in new companies, but retained for old-loader savegames
builder += _silly_company_names[std::min<size_t>(args.GetNextParameter<uint16_t>(), std::size(_silly_company_names) - 1)];
return;
return true;
case 2: // used for Foobar & Co company names
case SPECSTR_ANDCO_NAME: // used for Foobar & Co company names
GenAndCoName(builder, args.GetNextParameter<uint32_t>());
return;
return true;
case 3: // President name
case SPECSTR_PRESIDENT_NAME: // President name
GenPresidentName(builder, args.GetNextParameter<uint32_t>());
return;
return true;
}
/* town name? */
if (IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_END - SPECSTR_TOWNNAME_START)) {
GetSpecialTownNameString(builder, ind - 6, args.GetNextParameter<uint32_t>());
/* TownName Transport company names, with the appropriate town name. */
if (IsInsideMM(string, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_END)) {
GetSpecialTownNameString(builder, string - SPECSTR_COMPANY_NAME_START, args.GetNextParameter<uint32_t>());
builder += " Transport";
return;
return true;
}
NOT_REACHED();
return false;
}
/**