Changeset - r23818:7609f20f2104
[Not reviewed]
src/ai/ai_instance.cpp
Show inline comments
 
@@ -248,26 +248,28 @@ ScriptInfo *AIInstance::FindLibrary(cons
 
/**
 
 * DoCommand callback function for all commands executed by AIs.
 
 * @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 cmd cmd as given to DoCommandPInternal.
 
 */
 
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	/*
 
	 * The company might not exist anymore. Check for this.
 
	 * The command checks are not useful since this callback
 
	 * is also called when the command fails, which is does
 
	 * when the company does not exist anymore.
 
	 */
 
	const Company *c = Company::GetIfValid(_current_company);
 
	if (c == nullptr || c->ai_instance == nullptr) return;
 

	
 
	c->ai_instance->DoCommandCallback(result, tile, p1, p2);
 
	c->ai_instance->Continue();
 
	if (c->ai_instance->DoCommandCallback(result, tile, p1, p2, cmd)) {
 
		c->ai_instance->Continue();
 
	}
 
}
 

	
 
CommandCallback *AIInstance::GetDoCommandCallback()
 
{
 
	return &CcAI;
 
}
src/airport_gui.cpp
Show inline comments
 
@@ -39,13 +39,13 @@ static int _selected_airport_index;     
 
static byte _selected_airport_layout;          ///< selected airport layout number.
 

	
 
static void ShowBuildAirportPicker(Window *parent);
 

	
 
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout);
 

	
 
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
src/bridge_gui.cpp
Show inline comments
 
@@ -55,14 +55,15 @@ typedef GUIList<BuildBridgeData> GUIBrid
 
 * @param end_tile End tile of the bridge.
 
 * @param p1 packed start tile coords (~ dx)
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - bridge type (hi bh)
 
 * - p2 = (bit  8-13) - rail type or road types.
 
 * - p2 = (bit 15-16) - transport type.
 
 * @param cmd unused
 
 */
 
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2)
 
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, end_tile);
 

	
 
	TransportType transport_type = Extract<TransportType, 15, 2>(p2);
 

	
src/command.cpp
Show inline comments
 
@@ -595,13 +595,13 @@ bool DoCommandP(TileIndex tile, uint32 p
 
		 * something. Furthermore in the editor there is no
 
		 * concept of cost, so don't show it there either. */
 
		ShowCostOrIncomeAnimation(x, y, GetSlopePixelZ(x, y), res.GetCost());
 
	}
 

	
 
	if (!estimate_only && !only_sending && callback != nullptr) {
 
		callback(res, tile, p1, p2);
 
		callback(res, tile, p1, p2, cmd);
 
	}
 

	
 
	return res.Succeeded();
 
}
 

	
 

	
src/command_type.h
Show inline comments
 
@@ -466,13 +466,13 @@ struct Command {
 
 * @param result The result of the executed command
 
 * @param tile The tile of the command action
 
 * @param p1 Additional data of the command
 
 * @param p1 Additional data of the command
 
 * @see CommandProc
 
 */
 
typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
 
typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd);
 

	
 
/**
 
 * Structure for buffering the build command when selecting a station to join.
 
 */
 
struct CommandContainer {
 
	TileIndex tile;                  ///< tile command being executed on.
src/depot_gui.cpp
Show inline comments
 
@@ -114,14 +114,15 @@ extern void DepotSortList(VehicleList *l
 
/**
 
 * This is the Callback method after the cloning attempt of a vehicle
 
 * @param result the result of the cloning command
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param cmd unused
 
 */
 
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	const Vehicle *v = Vehicle::Get(_new_vehicle_id);
 

	
 
	ShowVehicleViewWindow(v);
src/dock_gui.cpp
Show inline comments
 
@@ -37,21 +37,21 @@
 

	
 
static void ShowBuildDockStationPicker(Window *parent);
 
static void ShowBuildDocksDepotPicker(Window *parent);
 

	
 
static Axis _ship_depot_direction;
 

	
 
void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildDocks(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
void CcPlaySound_SPLAT_WATER(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaySound_SPLAT_WATER(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_SPLAT_WATER, tile);
 
}
 

	
 

	
 
/**
src/game/game_instance.cpp
Show inline comments
 
@@ -254,17 +254,19 @@ void GameInstance::Died()
 
/**
 
 * DoCommand callback function for all commands executed by Game 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 cmd cmd as given to DoCommandPInternal.
 
 */
 
void CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	Game::GetGameInstance()->DoCommandCallback(result, tile, p1, p2);
 
	Game::GetGameInstance()->Continue();
 
	if (Game::GetGameInstance()->DoCommandCallback(result, tile, p1, p2, cmd)) {
 
		Game::GetGameInstance()->Continue();
 
	}
 
}
 

	
 
CommandCallback *GameInstance::GetDoCommandCallback()
 
{
 
	return &CcGame;
 
}
src/group_gui.cpp
Show inline comments
 
@@ -1043,15 +1043,16 @@ static inline VehicleGroupWindow *FindVe
 
/**
 
 * Opens a 'Rename group' window for newly created group.
 
 * @param result Did command succeed?
 
 * @param tile Unused.
 
 * @param p1 Vehicle type.
 
 * @param p2 Unused.
 
 * @param cmd Unused.
 
 * @see CmdCreateGroup
 
 */
 
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 
	assert(p1 <= VEH_AIRCRAFT);
 

	
 
	VehicleGroupWindow *w = FindVehicleGroupWindow((VehicleType)p1, _current_company);
 
	if (w != nullptr) w->ShowRenameGroupWindow(_new_group_id, true);
 
@@ -1060,19 +1061,20 @@ void CcCreateGroup(const CommandCost &re
 
/**
 
 * Open rename window after adding a vehicle to a new group via drag and drop.
 
 * @param result Did command succeed?
 
 * @param tile Unused.
 
 * @param p1 Unused.
 
 * @param p2 Bit 0-19: Vehicle ID.
 
 * @param cmd Unused.
 
 */
 
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 
	assert(Vehicle::IsValidID(GB(p2, 0, 20)));
 

	
 
	CcCreateGroup(result, 0, Vehicle::Get(GB(p2, 0, 20))->type, 0);
 
	CcCreateGroup(result, 0, Vehicle::Get(GB(p2, 0, 20))->type, 0, cmd);
 
}
 

	
 
/**
 
 * Removes the highlight of a vehicle in a group window
 
 * @param *v Vehicle to remove all highlights from
 
 */
src/industry_gui.cpp
Show inline comments
 
@@ -219,14 +219,15 @@ void SortIndustryTypes()
 
/**
 
 * Command callback. In case of failure to build an industry, show an error message.
 
 * @param result Result of the command.
 
 * @param tile   Tile where the industry is placed.
 
 * @param p1     Additional data of the #CMD_BUILD_INDUSTRY command.
 
 * @param p2     Additional data of the #CMD_BUILD_INDUSTRY command.
 
 * @param cmd    Unused.
 
 */
 
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded()) return;
 

	
 
	uint8 indtype = GB(p1, 0, 8);
 
	if (indtype < NUM_INDUSTRYTYPES) {
 
		const IndustrySpec *indsp = GetIndustrySpec(indtype);
src/main_gui.cpp
Show inline comments
 
@@ -48,13 +48,13 @@
 

	
 
#include "safeguards.h"
 

	
 
static int _rename_id = 1;
 
static int _rename_what = -1;
 

	
 
void CcGiveMoney(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcGiveMoney(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed() || !_settings_game.economy.give_money) return;
 

	
 
	/* Inform the company of the action of one of its clients (controllers). */
 
	char msg[64];
 
	SetDParam(0, p2);
 
@@ -112,13 +112,13 @@ bool HandlePlacePushButton(Window *w, in
 
	SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
 
	w->LowerWidget(widget);
 
	return true;
 
}
 

	
 

	
 
void CcPlaySound_EXPLOSION(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaySound_EXPLOSION(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
 
}
 

	
 
void ShowNetworkGiveMoneyWindow(CompanyID company)
 
{
src/rail_gui.cpp
Show inline comments
 
@@ -83,13 +83,13 @@ static bool IsStationAvailable(const Sta
 
	uint16 cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE);
 
	if (cb_res == CALLBACK_FAILED) return true;
 

	
 
	return Convert8bitBooleanCallback(statspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res);
 
}
 

	
 
void CcPlaySound_SPLAT_RAIL(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaySound_SPLAT_RAIL(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
 
}
 

	
 
static void GenericPlaceRail(TileIndex tile, int cmd)
 
{
 
@@ -126,13 +126,13 @@ static const Track _place_depot_extra_tr
 
static const DiagDirection _place_depot_extra_dir[12] = {
 
	DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, DIAGDIR_SW,
 
	DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_SE,
 
	DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_NE,
 
};
 

	
 
void CcRailDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcRailDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	DiagDirection dir = (DiagDirection)p2;
 

	
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
 
@@ -167,13 +167,13 @@ static void PlaceRail_Waypoint(TileIndex
 
		/* Tile where we can't build rail waypoints. This is always going to fail,
 
		 * but provides the user with a proper error message. */
 
		DoCommandP(tile, 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, CMD_BUILD_RAIL_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT));
 
	}
 
}
 

	
 
void CcStation(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcStation(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
 
	/* Only close the station builder window if the default station and non persistent building is chosen. */
 
	if (_railstation.station_class == STAT_CLASS_DFLT && _railstation.station_type == 0 && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
@@ -269,13 +269,13 @@ static void PlaceRail_Bridge(TileIndex t
 
	} else {
 
		VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
 
	}
 
}
 

	
 
/** Command callback for building a tunnel */
 
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded()) {
 
		if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	} else {
 
		SetRedErrorSquare(_build_tunnel_endtile);
src/road_gui.cpp
Show inline comments
 
@@ -65,13 +65,13 @@ static RoadFlags _place_road_flag;
 

	
 
static RoadType _cur_roadtype;
 

	
 
static DiagDirection _road_depot_orientation;
 
static DiagDirection _road_station_picker_orientation;
 

	
 
void CcPlaySound_SPLAT_OTHER(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaySound_SPLAT_OTHER(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
 
}
 

	
 
/**
 
 * Callback to start placing a bridge.
 
@@ -93,14 +93,15 @@ static void PlaceRoad_Bridge(TileIndex t
 
 *
 
 * @param result Whether the build succeeded.
 
 * @param start_tile Starting tile of the tunnel.
 
 * @param p1 bit 0-3 railtype or roadtypes
 
 *           bit 8-9 transport type
 
 * @param p2 unused
 
 * @param cmd unused
 
 */
 
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2)
 
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded()) {
 
		if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, start_tile);
 
		if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 

	
 
		DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(start_tile));
 
@@ -127,13 +128,13 @@ void ConnectRoadToStructure(TileIndex ti
 
		if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) {
 
			DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, CMD_BUILD_ROAD);
 
		}
 
	}
 
}
 

	
 
void CcRoadDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcRoadDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
@@ -150,15 +151,16 @@ void CcRoadDepot(const CommandCost &resu
 
 *           bit 1: 0 For normal stops, 1 for drive-through.
 
 *           bit 2: Allow stations directly adjacent to other stations.
 
 *           bit 3..4: Entrance direction (#DiagDirection) for normal stops.
 
 *           bit 3: #Axis of the road for drive-through stops.
 
 *           bit 5..9: The roadtype.
 
 *           bit 16..31: Station ID to join (NEW_STATION if build new one).
 
 * @param cmd Unused.
 
 * @see CmdBuildRoadStop
 
 */
 
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	DiagDirection dir = (DiagDirection)GB(p2, 3, 2);
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
src/script/api/script_object.cpp
Show inline comments
 
@@ -80,12 +80,29 @@ ScriptObject::ActiveInstance::~ActiveIns
 

	
 
/* static */ ScriptObject *ScriptObject::GetDoCommandModeInstance()
 
{
 
	return GetStorage()->mode_instance;
 
}
 

	
 
/* static */ void ScriptObject::SetLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	GetStorage()->last_tile = tile;
 
	GetStorage()->last_p1 = p1;
 
	GetStorage()->last_p2 = p2;
 
	GetStorage()->last_cmd = cmd;
 
}
 

	
 
/* static */ bool ScriptObject::CheckLastCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (GetStorage()->last_tile != tile) return false;
 
	if (GetStorage()->last_p1 != p1) return false;
 
	if (GetStorage()->last_p2 != p2) return false;
 
	if (GetStorage()->last_cmd != cmd) return false;
 
	return true;
 
}
 

	
 
/* static */ void ScriptObject::SetDoCommandCosts(Money value)
 
{
 
	GetStorage()->costs = CommandCost(value);
 
}
 

	
 
/* static */ void ScriptObject::IncreaseDoCommandCosts(Money value)
 
@@ -301,12 +318,15 @@ ScriptObject::ActiveInstance::~ActiveIns
 
	/* Are we only interested in the estimate costs? */
 
	bool estimate_only = GetDoCommandMode() != nullptr && !GetDoCommandMode()();
 

	
 
	/* Only set p2 when the command does not come from the network. */
 
	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);
 

	
 
	/* Try to perform the command. */
 
	CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, text, false, estimate_only);
 

	
 
	/* We failed; set the error and bail out */
 
	if (res.Failed()) {
 
		SetLastError(ScriptError::StringToError(res.GetErrorMessage()));
src/script/api/script_object.hpp
Show inline comments
 
@@ -71,12 +71,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);
 

	
 
	/**
 
	 * 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.
 
	 */
 
	static void SetDoCommandCosts(Money value);
 

	
 
	/**
 
	 * Increase the current value of the DoCommand costs counter.
src/script/script_instance.cpp
Show inline comments
 
@@ -677,24 +677,30 @@ bool ScriptInstance::CallLoad()
 

	
 
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)) return false;
 

	
 
	ScriptObject::SetLastCommandRes(result.Succeeded());
 

	
 
	if (result.Failed()) {
 
		ScriptObject::SetLastError(ScriptError::StringToError(result.GetErrorMessage()));
 
	} else {
 
		ScriptObject::IncreaseDoCommandCosts(result.GetCost());
 
		ScriptObject::SetLastCost(result.GetCost());
 
	}
 

	
 
	ScriptObject::SetLastCommand(INVALID_TILE, 0, 0, CMD_END);
 

	
 
	return true;
 
}
 

	
 
void ScriptInstance::InsertEvent(class ScriptEvent *event)
 
{
 
	ScriptObject::ActiveInstance active(this);
 

	
src/script/script_instance.hpp
Show inline comments
 
@@ -179,14 +179,16 @@ 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 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.
 
	 * @param event The event to insert.
 
	 */
 
	void InsertEvent(class ScriptEvent *event);
src/script/script_storage.hpp
Show inline comments
 
@@ -43,12 +43,17 @@ private:
 

	
 
	CommandCost costs;               ///< The costs the script is tracking.
 
	Money last_cost;                 ///< The last cost of the command.
 
	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.
 
	GoalID new_goal_id;              ///< The ID of the new Goal.
 
	StoryPageID new_story_page_id;   ///< The ID of the new StoryPage.
 
	StoryPageID new_story_page_element_id; ///< The ID of the new StoryPageElement.
 
@@ -70,12 +75,16 @@ public:
 
		delay             (1),
 
		allow_do_command  (true),
 
		/* costs (can't be set) */
 
		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),
 
		new_goal_id       (0),
 
		new_story_page_id (0),
 
		new_story_page_element_id(0),
src/signs_cmd.cpp
Show inline comments
 
@@ -114,14 +114,15 @@ CommandCost CmdRenameSign(TileIndex tile
 
/**
 
 * Callback function that is called after a sign is placed
 
 * @param result of the operation
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param cmd unused
 
 */
 
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	ShowRenameSignWindow(Sign::Get(_new_sign_id));
 
	ResetObjectToPlace();
 
}
src/terraform_gui.cpp
Show inline comments
 
@@ -37,13 +37,13 @@
 
#include "widgets/terraform_widget.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
void CcTerraform(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcTerraform(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded()) {
 
		if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
 
	} else {
 
		extern TileIndex _terraform_err_tile;
 
		SetRedErrorSquare(_terraform_err_tile);
src/town_gui.cpp
Show inline comments
 
@@ -1047,21 +1047,21 @@ static WindowDesc _town_directory_desc(
 
void ShowTownDirectory()
 
{
 
	if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
 
	new TownDirectoryWindow(&_town_directory_desc);
 
}
 

	
 
void CcFoundTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcFoundTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
void CcFoundRandomTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcFoundRandomTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(_new_town_id)->xy);
 
}
 

	
 
static const NWidgetPart _nested_found_town_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
src/train_gui.cpp
Show inline comments
 
@@ -24,14 +24,15 @@
 
/**
 
 * Callback for building wagons.
 
 * @param result The result of the command.
 
 * @param tile   The tile the command was executed on.
 
 * @param p1 Additional data for the command (for the #CommandProc)
 
 * @param p2 Additional data for the command (for the #CommandProc)
 
 * @param cmd Unused.
 
 */
 
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	/* find a locomotive in the depot. */
 
	const Vehicle *found = nullptr;
 
	const Train *t;
src/vehicle_gui.cpp
Show inline comments
 
@@ -2374,13 +2374,13 @@ static const uint32 _vehicle_command_tra
 
 * This is the Callback method after attempting to start/stop a vehicle
 
 * @param result the result of the start/stop command
 
 * @param tile unused
 
 * @param p1 vehicle ID
 
 * @param p2 unused
 
 */
 
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	const Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
 

	
 
@@ -2819,14 +2819,15 @@ void StopGlobalFollowVehicle(const Vehic
 
/**
 
 * This is the Callback method after the construction attempt of a primary vehicle
 
 * @param result indicates completion (or not) of the operation
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param cmd unused
 
 */
 
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
 
{
 
	if (result.Failed()) return;
 

	
 
	const Vehicle *v = Vehicle::Get(_new_vehicle_id);
 
	ShowVehicleViewWindow(v);
 
}
0 comments (0 inline, 0 general)