Merge branch 'master' into jgrpp-nrt
# Conflicts: # config.lib # src/core/bitmath_func.hpp # src/lang/korean.txt # src/main_gui.cpp # src/order_gui.cpp # src/script/api/script_object.cpp # src/station_cmd.cpp # src/video/cocoa/wnd_quartz.mm
This commit is contained in:
@@ -35,6 +35,9 @@
|
||||
* \li AIEngine::HasPowerOnRoad
|
||||
* \li AIRoadTypeList::RoadTypeList
|
||||
*
|
||||
* Other changes:
|
||||
* \li AITile::DemolishTile works without a selected company
|
||||
*
|
||||
* \b 1.9.0
|
||||
*
|
||||
* API additions:
|
||||
|
||||
@@ -1263,6 +1263,7 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TD_SCROLLBAR, "WID_TD_SCROLLBAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TD_WORLD_POPULATION, "WID_TD_WORLD_POPULATION");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TA_CAPTION, "WID_TA_CAPTION");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TA_ZONE_BUTTON, "WID_TA_ZONE_BUTTON");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TA_RATING_INFO, "WID_TA_RATING_INFO");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TA_COMMAND_LIST, "WID_TA_COMMAND_LIST");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TA_SCROLLBAR, "WID_TA_SCROLLBAR");
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "../script_instance.hpp"
|
||||
#include "../script_fatalerror.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "../../debug.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
@@ -85,6 +86,27 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
return GetStorage()->mode_instance;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, 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);
|
||||
s->last_tile = tile;
|
||||
s->last_p1 = p1;
|
||||
s->last_p2 = p2;
|
||||
s->last_cmd = cmd & CMD_ID_MASK;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, 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);
|
||||
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 & CMD_ID_MASK)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetDoCommandCosts(Money value)
|
||||
{
|
||||
GetStorage()->costs = CommandCost(value);
|
||||
@@ -309,6 +331,9 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
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);
|
||||
|
||||
/* Store the command for command callback validation. */
|
||||
if (!estimate_only && _networking && !_generating_world) SetLastCommand(tile, p1, p2, 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);
|
||||
|
||||
|
||||
@@ -73,6 +73,16 @@ protected:
|
||||
*/
|
||||
static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = nullptr, Script_SuspendCallbackProc *callback = nullptr);
|
||||
|
||||
/**
|
||||
* Store the latest command executed by the script.
|
||||
*/
|
||||
static void SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd);
|
||||
|
||||
/**
|
||||
* Check if it's the latest command executed by the script.
|
||||
*/
|
||||
static bool CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd);
|
||||
|
||||
/**
|
||||
* Sets the DoCommand costs counter to a value.
|
||||
*/
|
||||
|
||||
@@ -262,7 +262,6 @@
|
||||
|
||||
/* static */ bool ScriptTile::DemolishTile(TileIndex tile)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, ::IsValidTile(tile));
|
||||
|
||||
return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
|
||||
|
||||
@@ -445,7 +445,6 @@ public:
|
||||
* Destroy everything on the given tile.
|
||||
* @param tile The tile to demolish.
|
||||
* @pre ScriptMap::IsValidTile(tile).
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @exception ScriptError::ERR_AREA_NOT_CLEAR
|
||||
* @return True if and only if the tile was demolished.
|
||||
*/
|
||||
|
||||
@@ -680,10 +680,15 @@ SQInteger ScriptInstance::GetOpsTillSuspend()
|
||||
return this->engine->GetOpsTillSuspend();
|
||||
}
|
||||
|
||||
void ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
||||
bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
|
||||
{
|
||||
ScriptObject::ActiveInstance active(this);
|
||||
|
||||
if (!ScriptObject::CheckLastCommand(tile, p1, p2, cmd)) {
|
||||
DEBUG(script, 1, "DoCommandCallback terminating a script, last command does not match expected command");
|
||||
return false;
|
||||
}
|
||||
|
||||
ScriptObject::SetLastCommandRes(result.Succeeded());
|
||||
|
||||
if (result.Failed()) {
|
||||
@@ -692,6 +697,10 @@ void ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile
|
||||
ScriptObject::IncreaseDoCommandCosts(result.GetCost());
|
||||
ScriptObject::SetLastCost(result.GetCost());
|
||||
}
|
||||
|
||||
ScriptObject::SetLastCommand(INVALID_TILE, 0, 0, CMD_END);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptInstance::InsertEvent(class ScriptEvent *event)
|
||||
|
||||
@@ -182,8 +182,10 @@ 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 cmd cmd as given to DoCommandPInternal.
|
||||
* @return true if we handled result.
|
||||
*/
|
||||
void DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
|
||||
bool DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd);
|
||||
|
||||
/**
|
||||
* Insert an event for this script.
|
||||
|
||||
@@ -46,6 +46,11 @@ private:
|
||||
uint last_error; ///< The last error of the command.
|
||||
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.
|
||||
uint32 last_cmd; ///< The last cmd passed to a command.
|
||||
|
||||
VehicleID new_vehicle_id; ///< The ID of the new Vehicle.
|
||||
SignID new_sign_id; ///< The ID of the new Sign.
|
||||
GroupID new_group_id; ///< The ID of the new Group.
|
||||
@@ -73,6 +78,10 @@ public:
|
||||
last_cost (0),
|
||||
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),
|
||||
new_group_id (0),
|
||||
|
||||
Reference in New Issue
Block a user