diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/script_object.cpp | 16 | ||||
-rw-r--r-- | src/script/api/script_object.hpp | 4 | ||||
-rw-r--r-- | src/script/script_instance.cpp | 6 | ||||
-rw-r--r-- | src/script/script_instance.hpp | 5 | ||||
-rw-r--r-- | src/script/script_storage.hpp | 5 |
5 files changed, 15 insertions, 21 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); 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. diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 03fad1491..ecf846b9f 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -687,11 +687,11 @@ SQInteger ScriptInstance::GetOpsTillSuspend() return this->engine->GetOpsTillSuspend(); } -bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, Commands cmd) +bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, const CommandDataBuffer &data, Commands cmd) { ScriptObject::ActiveInstance active(this); - if (!ScriptObject::CheckLastCommand(tile, p1, p2, cmd)) { + if (!ScriptObject::CheckLastCommand(tile, data, cmd)) { Debug(script, 1, "DoCommandCallback terminating a script, last command does not match expected command"); return false; } @@ -705,7 +705,7 @@ bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile ScriptObject::SetLastCost(result.GetCost()); } - ScriptObject::SetLastCommand(INVALID_TILE, 0, 0, CMD_END); + ScriptObject::SetLastCommand(INVALID_TILE, {}, CMD_END); return true; } diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index 01415d4d4..c30fd1499 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -178,12 +178,11 @@ public: * DoCommand callback function for all commands executed by scripts. * @param result The result of the command. * @param tile The tile on which the command was executed. - * @param p1 p1 as given to DoCommandPInternal. - * @param p2 p2 as given to DoCommandPInternal. + * @param data Command data as given to DoCommandPInternal. * @param cmd cmd as given to DoCommandPInternal. * @return true if we handled result. */ - bool DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, Commands cmd); + bool DoCommandCallback(const CommandCost &result, TileIndex tile, const CommandDataBuffer &data, Commands cmd); /** * Insert an event for this script. diff --git a/src/script/script_storage.hpp b/src/script/script_storage.hpp index 8dadf59ae..3735adc1d 100644 --- a/src/script/script_storage.hpp +++ b/src/script/script_storage.hpp @@ -45,8 +45,7 @@ private: bool last_command_res; ///< The last result of the command. TileIndex last_tile; ///< The last tile passed to a command. - uint32 last_p1; ///< The last p1 passed to a command. - uint32 last_p2; ///< The last p2 passed to a command. + CommandDataBuffer last_data; ///< The last data passed to a command. Commands last_cmd; ///< The last cmd passed to a command. VehicleID new_vehicle_id; ///< The ID of the new Vehicle. @@ -77,8 +76,6 @@ public: last_error (STR_NULL), last_command_res (true), last_tile (INVALID_TILE), - last_p1 (0), - last_p2 (0), last_cmd (CMD_END), new_vehicle_id (0), new_sign_id (0), |