Codechange: Pass additional data as byte stream to command callbacks.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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.
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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.
|
||||
|
@@ -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),
|
||||
|
Reference in New Issue
Block a user