Script: Store CommandCost::GetResultData

This commit is contained in:
Jonathan G Rennison
2022-12-03 14:29:37 +00:00
parent 44c4cc80a1
commit dc96fbc573
4 changed files with 24 additions and 0 deletions

View File

@@ -143,6 +143,16 @@ ScriptObject::ActiveInstance::~ActiveInstance()
return GetStorage()->last_cost;
}
/* static */ void ScriptObject::SetLastCommandResultData(uint32 last_result)
{
GetStorage()->last_result = last_result;
}
/* static */ uint32 ScriptObject::GetLastCommandResultData()
{
return GetStorage()->last_result;
}
/* static */ void ScriptObject::SetRoadType(RoadType road_type)
{
GetStorage()->road_type = road_type;
@@ -358,6 +368,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
/* Costs of this operation. */
SetLastCost(res.GetCost());
SetLastCommandResultData(res.GetResultData());
SetLastCommandRes(true);
if (_generating_world) {

View File

@@ -237,6 +237,16 @@ protected:
*/
static Money GetLastCost();
/**
* Set the result data of the last command.
*/
static void SetLastCommandResultData(uint32 last_result);
/**
* Get the result data of the last command.
*/
static uint32 GetLastCommandResultData();
/**
* Set a variable that can be used by callback functions to pass information.
*/

View File

@@ -737,6 +737,7 @@ bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile
} else {
ScriptObject::IncreaseDoCommandCosts(result.GetCost());
ScriptObject::SetLastCost(result.GetCost());
ScriptObject::SetLastCommandResultData(result.GetResultData());
}
ScriptObject::SetLastCommand(INVALID_TILE, 0, 0, 0, CMD_END);

View File

@@ -41,6 +41,7 @@ private:
CommandCost costs; ///< The costs the script is tracking.
Money last_cost; ///< The last cost of the command.
uint32 last_result; ///< The last result data of the command.
uint last_error; ///< The last error of the command.
bool last_command_res; ///< The last result of the command.
@@ -75,6 +76,7 @@ public:
allow_do_command (true),
/* costs (can't be set) */
last_cost (0),
last_result (0),
last_error (STR_NULL),
last_command_res (true),
last_tile (INVALID_TILE),