Changeset - r26104:2873b00a1dac
[Not reviewed]
master
0 23 0
Michael Lutz - 3 years ago 2021-10-31 21:07:22
michi@icosahedron.de
Codechange: Pass additional data as byte stream to command callbacks.
23 files changed with 98 insertions and 112 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_instance.cpp
Show inline comments
 
@@ -92,14 +92,12 @@ ScriptInfo *AIInstance::FindLibrary(cons
 

	
 
/**
 
 * DoCommand callback function for all commands executed by AIs.
 
 * @param cmd cmd as given to DoCommandPInternal.
 
 * @param result The result of the command.
 
 * @param cmd cmd as given to DoCommandPInternal.
 
 * @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 text text as given to DoCommandPInternal.
 
 * @param data Command data as given to Command<>::Post.
 
 */
 
void CcAI(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcAI(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	/*
 
	 * The company might not exist anymore. Check for this.
 
@@ -110,7 +108,7 @@ void CcAI(const CommandCost &result, Com
 
	const Company *c = Company::GetIfValid(_current_company);
 
	if (c == nullptr || c->ai_instance == nullptr) return;
 

	
 
	if (c->ai_instance->DoCommandCallback(result, tile, p1, p2, cmd)) {
 
	if (c->ai_instance->DoCommandCallback(result, tile, data, cmd)) {
 
		c->ai_instance->Continue();
 
	}
 
}
src/airport_gui.cpp
Show inline comments
 
@@ -43,7 +43,7 @@ static void ShowBuildAirportPicker(Windo
 

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

	
 
void CcBuildAirport(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildAirport(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Failed()) return;
 

	
src/bridge_gui.cpp
Show inline comments
 
@@ -53,18 +53,15 @@ typedef GUIList<BuildBridgeData> GUIBrid
 
 * @param result Whether the build succeeded
 
 * @param cmd unused
 
 * @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 text unused
 
 * @param data Additional bitstuffed command data.
 
 */
 
void CcBuildBridge(const CommandCost &result, Commands cmd, TileIndex end_tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
 

	
 
	auto [tile, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_BRIDGE>::Args>(data);
 

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

	
 
	if (transport_type == TRANSPORT_ROAD) {
src/command_func.h
Show inline comments
 
@@ -12,7 +12,7 @@
 

	
 
#include "command_type.h"
 
#include "company_type.h"
 
#include <vector>
 
#include "misc/endian_buffer.hpp"
 
#include "tile_map.h"
 

	
 
/**
 
@@ -34,9 +34,6 @@ static const CommandCost CMD_ERROR = Com
 
 */
 
#define return_cmd_error(errcode) return CommandCost(errcode);
 

	
 
/** Storage buffer for serialized command data. */
 
typedef std::vector<byte> CommandDataBuffer;
 

	
 
CommandCost DoCommandPInternal(Commands cmd, StringID err_message, CommandCallback *callback, bool my_cmd, bool estimate_only, bool network_command, TileIndex tile, uint32 p1, uint32 p2, const std::string &text);
 

	
 
void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, TileIndex tile, uint32 p1, uint32 p2, const std::string &text);
 
@@ -213,7 +210,7 @@ protected:
 
		InternalPostResult(res, tile, estimate_only, only_sending, err_message, my_cmd);
 

	
 
		if (!estimate_only && !only_sending && callback != nullptr) {
 
			std::apply(callback, std::tuple_cat(std::tuple<const CommandCost &, Commands>{ res, Tcmd }, args));
 
			callback(Tcmd, res, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args));
 
		}
 

	
 
		return res.Succeeded();
src/command_type.h
Show inline comments
 
@@ -13,6 +13,7 @@
 
#include "economy_type.h"
 
#include "strings_type.h"
 
#include "tile_type.h"
 
#include <vector>
 

	
 
struct GRFFile;
 

	
 
@@ -444,6 +445,9 @@ template <Commands Tcmd> struct CommandT
 
		static inline constexpr const char *name = #proc_; \
 
	};
 

	
 
/** Storage buffer for serialized command data. */
 
typedef std::vector<byte> CommandDataBuffer;
 

	
 
/**
 
 * Define a callback function for the client, after the command is finished.
 
 *
 
@@ -451,14 +455,12 @@ template <Commands Tcmd> struct CommandT
 
 * are from the #CommandProc callback type. The boolean parameter indicates if the
 
 * command succeeded or failed.
 
 *
 
 * @param cmd The command that was executed
 
 * @param result The result of the executed command
 
 * @param cmd The command that was executed
 
 * @param tile The tile of the command action
 
 * @param p1 Additional data of the command
 
 * @param p1 Additional data of the command
 
 * @param text Text of the command
 
 * @param data Additional data of the command
 
 * @see CommandProc
 
 */
 
typedef void CommandCallback(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text);
 
typedef void CommandCallback(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data);
 

	
 
#endif /* COMMAND_TYPE_H */
src/depot_gui.cpp
Show inline comments
 
@@ -117,11 +117,8 @@ extern void DepotSortList(VehicleList *l
 
 * @param result the result of the cloning command
 
 * @param cmd unused
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 */
 
void CcCloneVehicle(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcCloneVehicle(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Failed()) return;
 

	
src/dock_gui.cpp
Show inline comments
 
@@ -43,7 +43,7 @@ static void ShowBuildDocksDepotPicker(Wi
 

	
 
static Axis _ship_depot_direction;
 

	
 
void CcBuildDocks(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildDocks(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Failed()) return;
 

	
 
@@ -51,7 +51,7 @@ void CcBuildDocks(const CommandCost &res
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
void CcPlaySound_CONSTRUCTION_WATER(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcPlaySound_CONSTRUCTION_WATER(Commands cmd, const CommandCost &result,TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
 
}
src/game/game_instance.cpp
Show inline comments
 
@@ -81,16 +81,14 @@ void GameInstance::Died()
 

	
 
/**
 
 * DoCommand callback function for all commands executed by Game Scripts.
 
 * @param cmd cmd as given to DoCommandPInternal.
 
 * @param result The result of the command.
 
 * @param cmd cmd as given to DoCommandPInternal.
 
 * @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 text text as given to DoCommandPInternal.
 
 * @param data Command data as given to Command<>::Post.
 
 */
 
void CcGame(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcGame(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (Game::GetGameInstance()->DoCommandCallback(result, tile, p1, p2, cmd)) {
 
	if (Game::GetGameInstance()->DoCommandCallback(result, tile, data, cmd)) {
 
		Game::GetGameInstance()->Continue();
 
	}
 
}
src/group_gui.cpp
Show inline comments
 
@@ -1141,38 +1141,47 @@ static inline VehicleGroupWindow *FindVe
 

	
 
/**
 
 * Opens a 'Rename group' window for newly created group.
 
 * @param result Did command succeed?
 
 * @param cmd Unused.
 
 * @param tile Unused.
 
 * @param p1 Vehicle type.
 
 * @param p2 Unused.
 
 * @param text Unused.
 
 * @see CmdCreateGroup
 
 * @param veh_type Vehicle type.
 
 */
 
void CcCreateGroup(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
static void CcCreateGroup(VehicleType veh_type)
 
{
 
	if (result.Failed()) return;
 
	assert(p1 <= VEH_AIRCRAFT);
 

	
 
	VehicleGroupWindow *w = FindVehicleGroupWindow((VehicleType)p1, _current_company);
 
	VehicleGroupWindow *w = FindVehicleGroupWindow(veh_type, _current_company);
 
	if (w != nullptr) w->ShowRenameGroupWindow(_new_group_id, true);
 
}
 

	
 
/**
 
 * Open rename window after adding a vehicle to a new group via drag and drop.
 
 * Opens a 'Rename group' window for newly created group.
 
 * @param cmd Unused.
 
 * @param result Did command succeed?
 
 * @param cmd Unused.
 
 * @param tile Unused.
 
 * @param p1 Unused.
 
 * @param p2 Bit 0-19: Vehicle ID.
 
 * @param text Unused.
 
 * @param data Command data.
 
 * @see CmdCreateGroup
 
 */
 
void CcAddVehicleNewGroup(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcCreateGroup(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_CREATE_GROUP>::Args>(data);
 
	assert(p1 <= VEH_AIRCRAFT);
 

	
 
	CcCreateGroup((VehicleType)p1);
 
}
 

	
 
/**
 
 * Open rename window after adding a vehicle to a new group via drag and drop.
 
 * @param cmd Unused.
 
 * @param result Did command succeed?
 
 * @param tile Unused.
 
 * @param data Command data.
 
 */
 
void CcAddVehicleNewGroup(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_ADD_VEHICLE_GROUP>::Args>(data);
 
	assert(Vehicle::IsValidID(GB(p2, 0, 20)));
 

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

	
 
/**
src/industry_gui.cpp
Show inline comments
 
@@ -219,17 +219,16 @@ void SortIndustryTypes()
 

	
 
/**
 
 * Command callback. In case of failure to build an industry, show an error message.
 
 * @param cmd    Unused.
 
 * @param result Result of the command.
 
 * @param cmd    Unused.
 
 * @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 text   Unused.
 
 * @param data   Additional data of the #CMD_BUILD_INDUSTRY command.
 
 */
 
void CcBuildIndustry(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Succeeded()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_INDUSTRY>::Args>(data);
 
	uint8 indtype = GB(p1, 0, 8);
 
	if (indtype < NUM_INDUSTRYTYPES) {
 
		const IndustrySpec *indsp = GetIndustrySpec(indtype);
src/main_gui.cpp
Show inline comments
 
@@ -77,7 +77,7 @@ bool HandlePlacePushButton(Window *w, in
 
}
 

	
 

	
 
void CcPlaySound_EXPLOSION(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcPlaySound_EXPLOSION(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
 
}
src/rail_gui.cpp
Show inline comments
 
@@ -89,7 +89,7 @@ static bool IsStationAvailable(const Sta
 
	return Convert8bitBooleanCallback(statspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res);
 
}
 

	
 
void CcPlaySound_CONSTRUCTION_RAIL(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcPlaySound_CONSTRUCTION_RAIL(Commands cmd, const CommandCost &result,TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
 
}
 
@@ -135,10 +135,11 @@ static const DiagDirection _place_depot_
 
	DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_NE,
 
};
 

	
 
void CcRailDepot(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcRailDepot(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_TRAIN_DEPOT>::Args>(data);
 
	DiagDirection dir = (DiagDirection)p2;
 

	
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
 
@@ -176,7 +177,7 @@ static void PlaceRail_Waypoint(TileIndex
 
	}
 
}
 

	
 
void CcStation(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcStation(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Failed()) return;
 

	
 
@@ -293,7 +294,7 @@ static void PlaceRail_Bridge(TileIndex t
 
}
 

	
 
/** Command callback for building a tunnel */
 
void CcBuildRailTunnel(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildRailTunnel(Commands cmd, const CommandCost &result,TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded()) {
 
		if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
src/road_gui.cpp
Show inline comments
 
@@ -69,7 +69,7 @@ static RoadType _cur_roadtype;
 
static DiagDirection _road_depot_orientation;
 
static DiagDirection _road_station_picker_orientation;
 

	
 
void CcPlaySound_CONSTRUCTION_OTHER(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcPlaySound_CONSTRUCTION_OTHER(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
 
}
 
@@ -92,15 +92,11 @@ static void PlaceRoad_Bridge(TileIndex t
 
/**
 
 * Callback executed after a build road tunnel command has been called.
 
 *
 
 * @param cmd unused
 
 * @param result Whether the build succeeded.
 
 * @param cmd unused
 
 * @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 text unused
 
 */
 
void CcBuildRoadTunnel(const CommandCost &result, Commands cmd, TileIndex start_tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildRoadTunnel(Commands cmd, const CommandCost &result, TileIndex start_tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded()) {
 
		if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, start_tile);
 
@@ -133,10 +129,12 @@ void ConnectRoadToStructure(TileIndex ti
 
	}
 
}
 

	
 
void CcRoadDepot(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcRoadDepot(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_DEPOT>::Args>(data);
 

	
 
	DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
@@ -160,10 +158,12 @@ void CcRoadDepot(const CommandCost &resu
 
 * @param text Unused.
 
 * @see CmdBuildRoadStop
 
 */
 
void CcRoadStop(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcRoadStop(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_STOP>::Args>(data);
 

	
 
	DiagDirection dir = (DiagDirection)GB(p2, 3, 2);
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
src/script/api/script_object.cpp
Show inline comments
 
@@ -82,24 +82,22 @@ ScriptObject::ActiveInstance::~ActiveIns
 
	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::~ActiveIns
 
	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);
src/script/api/script_object.hpp
Show inline comments
 
@@ -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.
src/script/script_instance.cpp
Show inline comments
 
@@ -687,11 +687,11 @@ SQInteger ScriptInstance::GetOpsTillSusp
 
	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(c
 
		ScriptObject::SetLastCost(result.GetCost());
 
	}
 

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

	
 
	return true;
 
}
src/script/script_instance.hpp
Show inline comments
 
@@ -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.
src/script/script_storage.hpp
Show inline comments
 
@@ -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),
src/signs_cmd.cpp
Show inline comments
 
@@ -116,7 +116,7 @@ CommandCost CmdRenameSign(DoCommandFlag 
 
 * @param p2 unused
 
 * @param text unused
 
 */
 
void CcPlaceSign(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcPlaceSign(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Failed()) return;
 

	
src/terraform_gui.cpp
Show inline comments
 
@@ -44,7 +44,7 @@
 

	
 
#include "safeguards.h"
 

	
 
void CcTerraform(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcTerraform(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded()) {
 
		if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
src/town_gui.cpp
Show inline comments
 
@@ -1009,7 +1009,7 @@ void ShowTownDirectory()
 
	new TownDirectoryWindow(&_town_directory_desc);
 
}
 

	
 
void CcFoundTown(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcFoundTown(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Failed()) return;
 

	
 
@@ -1017,7 +1017,7 @@ void CcFoundTown(const CommandCost &resu
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
}
 

	
 
void CcFoundRandomTown(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcFoundRandomTown(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(_new_town_id)->xy);
 
}
src/train_gui.cpp
Show inline comments
 
@@ -22,14 +22,11 @@
 

	
 
/**
 
 * Callback for building wagons.
 
 * @param cmd Unused.
 
 * @param result The result of the command.
 
 * @param cmd Unused.
 
 * @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 text Unused.
 
 */
 
void CcBuildWagon(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildWagon(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
 
{
 
	if (result.Failed()) return;
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -2622,14 +2622,13 @@ static const StringID _vehicle_msg_trans
 
 * @param result the result of the start/stop command
 
 * @param cmd unused
 
 * @param tile unused
 
 * @param p1 vehicle ID
 
 * @param p2 unused
 
 * @param text unused
 
 * @param data Command data
 
 */
 
void CcStartStopVehicle(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcStartStopVehicle(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
 
	auto [tile_, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_START_STOP_VEHICLE>::Args>(data);
 
	const Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
 

	
 
@@ -3127,11 +3126,9 @@ void StopGlobalFollowVehicle(const Vehic
 
 * @param result indicates completion (or not) of the operation
 
 * @param cmd unused
 
 * @param tile unused
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @param data unused
 
 */
 
void CcBuildPrimaryVehicle(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
 
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
 
{
 
	if (result.Failed()) return;
 

	
0 comments (0 inline, 0 general)