diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-10-31 22:07:22 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | eab18f06a47e558fe313cb86c855e8949b01feed (patch) | |
tree | a6dd29dc2ea3eb44ea2432151fa392ccd31c7d73 /src/script/api/script_object.cpp | |
parent | 0f64ee5ce1548d9cda69917f27c5b1a3cb91823d (diff) | |
download | openttd-eab18f06a47e558fe313cb86c855e8949b01feed.tar.xz |
Codechange: Pass additional data as byte stream to command callbacks.
Diffstat (limited to 'src/script/api/script_object.cpp')
-rw-r--r-- | src/script/api/script_object.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
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<CommandDataBuffer>::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); |