summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-10-31 22:07:22 +0100
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commiteab18f06a47e558fe313cb86c855e8949b01feed (patch)
treea6dd29dc2ea3eb44ea2432151fa392ccd31c7d73
parent0f64ee5ce1548d9cda69917f27c5b1a3cb91823d (diff)
downloadopenttd-eab18f06a47e558fe313cb86c855e8949b01feed.tar.xz
Codechange: Pass additional data as byte stream to command callbacks.
-rw-r--r--src/ai/ai_instance.cpp10
-rw-r--r--src/airport_gui.cpp2
-rw-r--r--src/bridge_gui.cpp11
-rw-r--r--src/command_func.h7
-rw-r--r--src/command_type.h12
-rw-r--r--src/depot_gui.cpp5
-rw-r--r--src/dock_gui.cpp4
-rw-r--r--src/game/game_instance.cpp10
-rw-r--r--src/group_gui.cpp35
-rw-r--r--src/industry_gui.cpp9
-rw-r--r--src/main_gui.cpp2
-rw-r--r--src/rail_gui.cpp9
-rw-r--r--src/road_gui.cpp18
-rw-r--r--src/script/api/script_object.cpp16
-rw-r--r--src/script/api/script_object.hpp4
-rw-r--r--src/script/script_instance.cpp6
-rw-r--r--src/script/script_instance.hpp5
-rw-r--r--src/script/script_storage.hpp5
-rw-r--r--src/signs_cmd.cpp2
-rw-r--r--src/terraform_gui.cpp2
-rw-r--r--src/town_gui.cpp4
-rw-r--r--src/train_gui.cpp7
-rw-r--r--src/vehicle_gui.cpp13
23 files changed, 92 insertions, 106 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 509ed70d2..576a81637 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -92,14 +92,12 @@ ScriptInfo *AIInstance::FindLibrary(const char *library, int version)
/**
* DoCommand callback function for all commands executed by AIs.
- * @param result The result of the command.
* @param cmd cmd as given to DoCommandPInternal.
+ * @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 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, Commands cmd, TileIndex tile, uint32 p1, ui
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();
}
}
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index af1fb1309..0de11c954 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -43,7 +43,7 @@ static void ShowBuildAirportPicker(Window *parent);
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;
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index e9e1f48f5..38ff698eb 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -53,18 +53,15 @@ typedef GUIList<BuildBridgeData> GUIBridgeList; ///< List of bridges, used in #B
* @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) {
diff --git a/src/command_func.h b/src/command_func.h
index 6a9b93ff5..9d603abcf 100644
--- a/src/command_func.h
+++ b/src/command_func.h
@@ -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 = CommandCost(INVALID_STRING_ID);
*/
#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();
diff --git a/src/command_type.h b/src/command_type.h
index c182ca393..59331dc7c 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -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 CommandTraits;
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 CommandTraits;
* are from the #CommandProc callback type. The boolean parameter indicates if the
* command succeeded or failed.
*
- * @param result The result of the executed command
* @param cmd The command that was executed
+ * @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
- * @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 */
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 76e03ef39..d316d97ca 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -117,11 +117,8 @@ extern void DepotSortList(VehicleList *list);
* @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;
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index 3cb101f7a..328ce1c20 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -43,7 +43,7 @@ static void ShowBuildDocksDepotPicker(Window *parent);
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 &result, Commands cmd, TileIndex tile, uint3
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);
}
diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp
index 47374525f..8433567c7 100644
--- a/src/game/game_instance.cpp
+++ b/src/game/game_instance.cpp
@@ -81,16 +81,14 @@ void GameInstance::Died()
/**
* DoCommand callback function for all commands executed by Game Scripts.
- * @param result The result of the command.
* @param cmd cmd as given to DoCommandPInternal.
+ * @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 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();
}
}
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index b2deba309..22f288971 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -1141,38 +1141,47 @@ static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner o
/**
* Opens a 'Rename group' window for newly created group.
- * @param result Did command succeed?
+ * @param veh_type Vehicle type.
+ */
+static void CcCreateGroup(VehicleType veh_type)
+{
+ VehicleGroupWindow *w = FindVehicleGroupWindow(veh_type, _current_company);
+ if (w != nullptr) w->ShowRenameGroupWindow(_new_group_id, true);
+}
+
+/**
+ * Opens a 'Rename group' window for newly created group.
* @param cmd Unused.
+ * @param result Did command succeed?
* @param tile Unused.
- * @param p1 Vehicle type.
- * @param p2 Unused.
- * @param text Unused.
+ * @param data Command data.
* @see CmdCreateGroup
*/
-void CcCreateGroup(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);
- VehicleGroupWindow *w = FindVehicleGroupWindow((VehicleType)p1, _current_company);
- if (w != nullptr) w->ShowRenameGroupWindow(_new_group_id, true);
+ CcCreateGroup((VehicleType)p1);
}
/**
* Open rename window after adding a vehicle to a new group via drag and drop.
- * @param result Did command succeed?
* @param cmd Unused.
+ * @param result Did command succeed?
* @param tile Unused.
- * @param p1 Unused.
- * @param p2 Bit 0-19: Vehicle ID.
- * @param text Unused.
+ * @param data Command data.
*/
-void CcAddVehicleNewGroup(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
+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);
}
/**
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 29da3c76e..b66d4f8bf 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -219,17 +219,16 @@ void SortIndustryTypes()
/**
* Command callback. In case of failure to build an industry, show an error message.
- * @param result Result of the command.
* @param cmd Unused.
+ * @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 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);
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 847d32845..680493c12 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -77,7 +77,7 @@ bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyl
}
-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);
}
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index a57e2f8e5..c1c45d5d7 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -89,7 +89,7 @@ static bool IsStationAvailable(const StationSpec *statspec)
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_extra_dir[12] = {
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 tile)
}
}
-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 tile, Window *w)
}
/** 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);
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index 948095f77..a777c9c1d 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -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 tile, Window *w)
/**
* Callback executed after a build road tunnel command has been called.
*
- * @param result Whether the build succeeded.
* @param cmd unused
+ * @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 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 tile, DiagDirection direction)
}
}
-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 &result, Commands cmd, TileIndex tile, uint32
* @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();
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index 56fdde826..c63d2a2ea 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -82,24 +82,22 @@ ScriptObject::ActiveInstance::~ActiveInstance()
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::~ActiveInstance()
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);
diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp
index a1134aa5c..40c8eaf85 100644
--- a/src/script/api/script_object.hpp
+++ b/src/script/api/script_object.hpp
@@ -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.
diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp
index 03fad1491..ecf846b9f 100644
--- a/src/script/script_instance.cpp
+++ b/src/script/script_instance.cpp
@@ -687,11 +687,11 @@ SQInteger ScriptInstance::GetOpsTillSuspend()
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(const CommandCost &result, TileIndex tile
ScriptObject::SetLastCost(result.GetCost());
}
- ScriptObject::SetLastCommand(INVALID_TILE, 0, 0, CMD_END);
+ ScriptObject::SetLastCommand(INVALID_TILE, {}, CMD_END);
return true;
}
diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp
index 01415d4d4..c30fd1499 100644
--- a/src/script/script_instance.hpp
+++ b/src/script/script_instance.hpp
@@ -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.
diff --git a/src/script/script_storage.hpp b/src/script/script_storage.hpp
index 8dadf59ae..3735adc1d 100644
--- a/src/script/script_storage.hpp
+++ b/src/script/script_storage.hpp
@@ -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),
diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp
index 4fdfc0ab5..00baf45a8 100644
--- a/src/signs_cmd.cpp
+++ b/src/signs_cmd.cpp
@@ -116,7 +116,7 @@ CommandCost CmdRenameSign(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
* @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;
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index c65adad7d..7399d6ffa 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -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);
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 8f315a055..6e955e103 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -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 &result, Commands cmd, TileIndex tile, uint32
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);
}
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index 8fc97d857..e41bdf6ac 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -22,14 +22,11 @@
/**
* Callback for building wagons.
- * @param result The result of the command.
* @param cmd Unused.
+ * @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 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;
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index c54910150..80b75e7ce 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -2622,14 +2622,13 @@ static const StringID _vehicle_msg_translation_table[][4] = {
* @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 Vehicle *v)
* @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;