Add command result flag for whether SetResultData was called

Use for tracerestrict validation result fail offset
pull/532/head
Jonathan G Rennison 1 year ago
parent 5dcbd9271b
commit 13183d3f13

@ -1390,6 +1390,8 @@ void CommandCost::SetTile(TileIndex tile)
void CommandCost::SetResultData(uint32 result)
{
this->flags |= CCIF_VALID_RESULT;
if (result == this->GetResultData()) return;
if (this->AddInlineData(CCIF_INLINE_RESULT)) {

@ -25,6 +25,7 @@ enum CommandCostIntlFlags : uint8 {
CCIF_INLINE_EXTRA_MSG = 1 << 1,
CCIF_INLINE_TILE = 1 << 2,
CCIF_INLINE_RESULT = 1 << 3,
CCIF_VALID_RESULT = 1 << 4,
};
DECLARE_ENUM_AS_BIT_SET(CommandCostIntlFlags)
@ -257,6 +258,11 @@ public:
void SetTile(TileIndex tile);
bool HasResultData() const
{
return (this->flags & CCIF_VALID_RESULT);
}
uint32 GetResultData() const
{
if (this->flags & CCIF_INLINE_RESULT) return this->inl.result;

@ -77,7 +77,7 @@ static void Load_TRRP()
char str[4096];
char *strend = str + seprintf(str, lastof(str), "Trace restrict program %d: %s\nProgram dump:",
index, GetStringPtr(validation_result.GetErrorMessage()));
uint fail_offset = validation_result.GetResultData() ^ (1 << 31);
uint fail_offset = validation_result.HasResultData() ? validation_result.GetResultData() : UINT32_MAX;
for (uint i = 0; i < (uint)prog->items.size(); i++) {
if ((i % 3) == 0) {
strend += seprintf(strend, lastof(str), "\n%4u:", i);

@ -971,7 +971,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector<TraceRestrictItem>
auto validation_error = [i](StringID str) -> CommandCost {
CommandCost result(str);
result.SetResultData((1 << 31) | (uint)i);
result.SetResultData((uint)i);
return result;
};

Loading…
Cancel
Save