Add third DoCommand parameter p3
This commit is contained in:
@@ -84,23 +84,25 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
return GetStorage()->mode_instance;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
|
||||
/* static */ void ScriptObject::SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
|
||||
{
|
||||
ScriptStorage *s = GetStorage();
|
||||
DEBUG(script, 6, "SetLastCommand company=%02d tile=%06x p1=%08x p2=%08x cmd=%d", s->root_company, tile, p1, p2, cmd);
|
||||
DEBUG(script, 6, "SetLastCommand company=%02d tile=%06x p1=%08x p2=%08x p3=" OTTD_PRINTFHEX64PAD " cmd=%d", s->root_company, tile, p1, p2, p3, cmd);
|
||||
s->last_tile = tile;
|
||||
s->last_p1 = p1;
|
||||
s->last_p2 = p2;
|
||||
s->last_p3 = p3;
|
||||
s->last_cmd = cmd & CMD_ID_MASK;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
|
||||
/* static */ bool ScriptObject::CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
|
||||
{
|
||||
ScriptStorage *s = GetStorage();
|
||||
DEBUG(script, 6, "CheckLastCommand company=%02d tile=%06x p1=%08x p2=%08x cmd=%d", s->root_company, tile, p1, p2, cmd);
|
||||
DEBUG(script, 6, "CheckLastCommand company=%02d tile=%06x p1=%08x p2=%08x p3=" OTTD_PRINTFHEX64PAD " cmd=%d", s->root_company, tile, p1, p2, p3, cmd);
|
||||
if (s->last_tile != tile) return false;
|
||||
if (s->last_p1 != p1) return false;
|
||||
if (s->last_p2 != p2) return false;
|
||||
if (s->last_p3 != p3) return false;
|
||||
if (s->last_cmd != (cmd & CMD_ID_MASK)) return false;
|
||||
return true;
|
||||
}
|
||||
@@ -300,7 +302,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
return GetStorage()->callback_value[index];
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text, Script_SuspendCallbackProc *callback)
|
||||
/* static */ bool ScriptObject::DoCommandEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint cmd, const char *text, uint32 binary_length, Script_SuspendCallbackProc *callback)
|
||||
{
|
||||
if (!ScriptObject::CanSuspend()) {
|
||||
throw Script_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator.");
|
||||
@@ -311,7 +313,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!StrEmpty(text) && (GetCommandFlags(cmd) & CMD_STR_CTRL) == 0) {
|
||||
if (binary_length == 0 && !StrEmpty(text) && (GetCommandFlags(cmd) & CMD_STR_CTRL) == 0) {
|
||||
/* The string must be valid, i.e. not contain special codes. Since some
|
||||
* can be made with GSText, make sure the control codes are removed. */
|
||||
::str_validate(const_cast<char *>(text), text + strlen(text), SVS_NONE);
|
||||
@@ -326,14 +328,14 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
/* Only set p2 when the command does not come from the network. */
|
||||
if (GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = UINT32_MAX;
|
||||
|
||||
SCOPE_INFO_FMT([=], "ScriptObject::DoCommand: tile: %X (%d x %d), p1: 0x%X, p2: 0x%X, company: %s, cmd: 0x%X (%s), estimate_only: %d",
|
||||
tile, TileX(tile), TileY(tile), p1, p2, scope_dumper().CompanyInfo(_current_company), cmd, GetCommandName(cmd), estimate_only);
|
||||
SCOPE_INFO_FMT([=], "ScriptObject::DoCommand: tile: %X (%d x %d), p1: 0x%X, p2: 0x%X, p3: 0x" OTTD_PRINTFHEX64 ", company: %s, cmd: 0x%X (%s), estimate_only: %d",
|
||||
tile, TileX(tile), TileY(tile), p1, p2, p3, scope_dumper().CompanyInfo(_current_company), cmd, GetCommandName(cmd), estimate_only);
|
||||
|
||||
/* 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, p1, p2, p3, cmd);
|
||||
|
||||
/* Try to perform the command. */
|
||||
CommandCost res = ::DoCommandPScript(tile, p1, p2, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, text, false, estimate_only, 0);
|
||||
CommandCost res = ::DoCommandPScript(tile, p1, p2, p3, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, text, false, estimate_only, binary_length);
|
||||
|
||||
/* We failed; set the error and bail out */
|
||||
if (res.Failed()) {
|
||||
|
||||
@@ -69,17 +69,22 @@ protected:
|
||||
/**
|
||||
* Executes a raw DoCommand for the script.
|
||||
*/
|
||||
static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = nullptr, Script_SuspendCallbackProc *callback = nullptr);
|
||||
static bool DoCommandEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint cmd, const char *text = nullptr, uint32 binary_length = 0, Script_SuspendCallbackProc *callback = nullptr);
|
||||
|
||||
static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = nullptr, Script_SuspendCallbackProc *callback = nullptr)
|
||||
{
|
||||
return ScriptObject::DoCommandEx(tile, p1, p2, 0, cmd, text, 0, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the latest command executed by the script.
|
||||
*/
|
||||
static void SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd);
|
||||
static void SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint cmd);
|
||||
|
||||
/**
|
||||
* Check if it's the latest command executed by the script.
|
||||
*/
|
||||
static bool CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd);
|
||||
static bool CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint cmd);
|
||||
|
||||
/**
|
||||
* Sets the DoCommand costs counter to a value.
|
||||
|
||||
@@ -720,11 +720,11 @@ void ScriptInstance::LimitOpsTillSuspend(SQInteger suspend)
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
|
||||
bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
|
||||
{
|
||||
ScriptObject::ActiveInstance active(this);
|
||||
|
||||
if (!ScriptObject::CheckLastCommand(tile, p1, p2, cmd)) {
|
||||
if (!ScriptObject::CheckLastCommand(tile, p1, p2, p3, cmd)) {
|
||||
DEBUG(script, 1, "DoCommandCallback terminating a script, last command does not match expected command");
|
||||
return false;
|
||||
}
|
||||
@@ -738,7 +738,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, 0, 0, 0, CMD_END);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -182,10 +182,11 @@ public:
|
||||
* @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 p3 p3 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, uint32 cmd);
|
||||
bool DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd);
|
||||
|
||||
/**
|
||||
* Insert an event for this script.
|
||||
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
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.
|
||||
uint64 last_p3; ///< The last p3 passed to a command.
|
||||
uint32 last_cmd; ///< The last cmd passed to a command.
|
||||
|
||||
VehicleID new_vehicle_id; ///< The ID of the new Vehicle.
|
||||
@@ -79,6 +80,7 @@ public:
|
||||
last_tile (INVALID_TILE),
|
||||
last_p1 (0),
|
||||
last_p2 (0),
|
||||
last_p3 (0),
|
||||
last_cmd (CMD_END),
|
||||
new_vehicle_id (0),
|
||||
new_sign_id (0),
|
||||
|
||||
Reference in New Issue
Block a user