Include setting name in command log for setting change commands

pull/279/head
Jonathan G Rennison 3 years ago
parent a8ce0ac787
commit eeece0928c

@ -28,6 +28,7 @@
#include "string_func.h"
#include "scope_info.h"
#include "core/random_func.hpp"
#include "settings_func.h"
#include <array>
#include "table/strings.h"
@ -596,8 +597,20 @@ static void DumpSubCommandLog(char *&buffer, const char *last, const CommandLog
if (entry.p3 != 0) {
buffer += seprintf(buffer, last, "p3: 0x" OTTD_PRINTFHEX64PAD ", ", entry.p3);
}
buffer += seprintf(buffer, last, "cc: %3u, lc: %3u, cmd: 0x%08X (%s)\n",
buffer += seprintf(buffer, last, "cc: %3u, lc: %3u, cmd: 0x%08X (%s)",
(uint) entry.current_company, (uint) entry.local_company, entry.cmd, GetCommandName(entry.cmd));
switch (entry.cmd & CMD_ID_MASK) {
case CMD_CHANGE_SETTING:
buffer += seprintf(buffer, last, " [%s]", GetSettingNameByIndex(entry.p1));
break;
case CMD_CHANGE_COMPANY_SETTING:
buffer += seprintf(buffer, last, " [%s]", GetCompanySettingNameByIndex(entry.p1));
break;
}
buffer += seprintf(buffer, last, "\n");
}
}

@ -2363,6 +2363,14 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
return CommandCost();
}
const char *GetSettingNameByIndex(uint32 idx)
{
const SettingDesc *sd = GetSettingDescription(idx);
if (sd == nullptr) return nullptr;
return sd->desc.name;
}
/**
* Change one of the per-company settings.
* @param tile unused
@ -2400,6 +2408,13 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32
return CommandCost();
}
const char *GetCompanySettingNameByIndex(uint32 idx)
{
if (idx >= lengthof(_company_settings)) return nullptr;
return _company_settings[idx].desc.name;
}
/**
* Top function to save the new value of an element of the Settings struct
* @param index offset in the SettingDesc array of the Settings struct which

@ -39,4 +39,7 @@ void SyncCompanySettings();
void SetupTimeSettings();
const char *GetSettingNameByIndex(uint32 idx);
const char *GetCompanySettingNameByIndex(uint32 idx);
#endif /* SETTINGS_FUNC_H */

Loading…
Cancel
Save