diff --git a/src/command.cpp b/src/command.cpp index 140ea0ea47..9d3ef3c632 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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)) { diff --git a/src/command_type.h b/src/command_type.h index 5850800837..a022766fe5 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -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; diff --git a/src/saveload/tracerestrict_sl.cpp b/src/saveload/tracerestrict_sl.cpp index ed773121ae..c923da5cc8 100644 --- a/src/saveload/tracerestrict_sl.cpp +++ b/src/saveload/tracerestrict_sl.cpp @@ -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); diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 498c95ebc3..39511ce720 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -971,7 +971,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector auto validation_error = [i](StringID str) -> CommandCost { CommandCost result(str); - result.SetResultData((1 << 31) | (uint)i); + result.SetResultData((uint)i); return result; };