From eab18f06a47e558fe313cb86c855e8949b01feed Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sun, 31 Oct 2021 22:07:22 +0100 Subject: Codechange: Pass additional data as byte stream to command callbacks. --- src/script/api/script_object.cpp | 16 +++++++--------- src/script/api/script_object.hpp | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src/script/api') diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 56fdde826..c63d2a2ea 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -82,24 +82,22 @@ ScriptObject::ActiveInstance::~ActiveInstance() return GetStorage()->mode_instance; } -/* static */ void ScriptObject::SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, Commands cmd) +/* static */ void ScriptObject::SetLastCommand(TileIndex tile, const CommandDataBuffer &data, Commands cmd) { ScriptStorage *s = GetStorage(); - Debug(script, 6, "SetLastCommand company={:02d} tile={:06x} p1={:08x} p2={:08x} cmd={}", s->root_company, tile, p1, p2, cmd); + Debug(script, 6, "SetLastCommand company={:02d} tile={:06x} cmd={} data={}", s->root_company, tile, cmd, FormatArrayAsHex(data)); s->last_tile = tile; - s->last_p1 = p1; - s->last_p2 = p2; + s->last_data = data; s->last_cmd = cmd; } -/* static */ bool ScriptObject::CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, Commands cmd) +/* static */ bool ScriptObject::CheckLastCommand(TileIndex tile, const CommandDataBuffer &data, Commands cmd) { ScriptStorage *s = GetStorage(); - Debug(script, 6, "CheckLastCommand company={:02d} tile={:06x} p1={:08x} p2={:08x} cmd={}", s->root_company, tile, p1, p2, cmd); + Debug(script, 6, "CheckLastCommand company={:02d} tile={:06x} cmd={} data={}", s->root_company, tile, cmd, FormatArrayAsHex(data)); if (s->last_tile != tile) return false; - if (s->last_p1 != p1) return false; - if (s->last_p2 != p2) return false; if (s->last_cmd != cmd) return false; + if (s->last_data != data) return false; return true; } @@ -326,7 +324,7 @@ ScriptObject::ActiveInstance::~ActiveInstance() if (GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = UINT32_MAX; /* Store the command for command callback validation. */ - if (!estimate_only && _networking && !_generating_world) SetLastCommand(tile, p1, p2, cmd); + if (!estimate_only && _networking && !_generating_world) SetLastCommand(tile, EndianBufferWriter::FromValue(std::make_tuple(tile, p1, p2, command_text)), cmd); /* Try to perform the command. */ CommandCost res = ::DoCommandPInternal(cmd, STR_NULL, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, false, estimate_only, false, tile, p1, p2, command_text); diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index a1134aa5c..40c8eaf85 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -75,12 +75,12 @@ protected: /** * Store the latest command executed by the script. */ - static void SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, Commands cmd); + static void SetLastCommand(TileIndex tile, const CommandDataBuffer &data, Commands cmd); /** * Check if it's the latest command executed by the script. */ - static bool CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, Commands cmd); + static bool CheckLastCommand(TileIndex tile, const CommandDataBuffer &data, Commands cmd); /** * Sets the DoCommand costs counter to a value. -- cgit v1.2.3-70-g09d2