mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
Codechange: Pass unpacked command arguments to command callbacks (except Script).
This commit is contained in:
parent
d85348b1d1
commit
8503854655
@ -113,7 +113,7 @@ void CcAI(Commands cmd, const CommandCost &result, TileIndex tile, const Command
|
||||
}
|
||||
}
|
||||
|
||||
CommandCallback *AIInstance::GetDoCommandCallback()
|
||||
CommandCallbackData *AIInstance::GetDoCommandCallback()
|
||||
{
|
||||
return &CcAI;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
private:
|
||||
void RegisterAPI() override;
|
||||
void Died() override;
|
||||
CommandCallback *GetDoCommandCallback() override;
|
||||
CommandCallbackData *GetDoCommandCallback() override;
|
||||
void LoadDummyScript() override;
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@ static void ShowBuildAirportPicker(Window *parent);
|
||||
|
||||
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout);
|
||||
|
||||
void CcBuildAirport(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcBuildAirport(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
|
@ -53,15 +53,14 @@ 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 data Additional bitstuffed command data.
|
||||
* @param tile_start start tile
|
||||
* @param transport_type transport type.
|
||||
*/
|
||||
void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, const CommandDataBuffer &data)
|
||||
void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
|
||||
|
||||
auto [tile, tile_start, transport_type, bridge_type, road_rail_type] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_BRIDGE>::Args>(data);
|
||||
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
|
||||
ConnectRoadToStructure(end_tile, end_direction);
|
||||
|
@ -284,7 +284,16 @@ protected:
|
||||
InternalPostResult(res, tile, estimate_only, only_sending, err_message, my_cmd);
|
||||
|
||||
if (!estimate_only && !only_sending && callback != nullptr) {
|
||||
callback(Tcmd, res, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args));
|
||||
if constexpr (std::is_same_v<Tcallback, CommandCallback>) {
|
||||
/* Callback that doesn't need any command arguments. */
|
||||
callback(Tcmd, res, tile);
|
||||
} else if constexpr (std::is_same_v<Tcallback, CommandCallbackData>) {
|
||||
/* Generic callback that takes packed arguments as a buffer. */
|
||||
callback(Tcmd, res, tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args));
|
||||
} else {
|
||||
/* Callback with arguments. We assume that the tile is only interesting if it actually is in the command arguments. */
|
||||
std::apply(callback, std::tuple_cat(std::make_tuple(Tcmd, res), args));
|
||||
}
|
||||
}
|
||||
|
||||
return res.Succeeded();
|
||||
|
@ -428,6 +428,20 @@ template <Commands Tcmd> struct CommandTraits;
|
||||
/** Storage buffer for serialized command data. */
|
||||
typedef std::vector<byte> CommandDataBuffer;
|
||||
|
||||
/**
|
||||
* Define a callback function for the client, after the command is finished.
|
||||
*
|
||||
* Functions of this type are called after the command is finished. The parameters
|
||||
* 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 tile The tile of the command action
|
||||
* @see CommandProc
|
||||
*/
|
||||
typedef void CommandCallback(Commands cmd, const CommandCost &result, TileIndex tile);
|
||||
|
||||
/**
|
||||
* Define a callback function for the client, after the command is finished.
|
||||
*
|
||||
@ -441,6 +455,6 @@ typedef std::vector<byte> CommandDataBuffer;
|
||||
* @param data Additional data of the command
|
||||
* @see CommandProc
|
||||
*/
|
||||
typedef void CommandCallback(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data);
|
||||
typedef void CommandCallbackData(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data);
|
||||
|
||||
#endif /* COMMAND_TYPE_H */
|
||||
|
@ -114,11 +114,11 @@ extern void DepotSortList(VehicleList *list);
|
||||
|
||||
/**
|
||||
* This is the Callback method after the cloning attempt of a vehicle
|
||||
* @param result the result of the cloning command
|
||||
* @param cmd unused
|
||||
* @param result the result of the cloning command
|
||||
* @param tile unused
|
||||
*/
|
||||
void CcCloneVehicle(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcCloneVehicle(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
|
@ -43,7 +43,7 @@ static void ShowBuildDocksDepotPicker(Window *parent);
|
||||
|
||||
static Axis _ship_depot_direction;
|
||||
|
||||
void CcBuildDocks(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcBuildDocks(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
@ -51,7 +51,7 @@ void CcBuildDocks(Commands cmd, const CommandCost &result, TileIndex tile, const
|
||||
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
||||
}
|
||||
|
||||
void CcPlaySound_CONSTRUCTION_WATER(Commands cmd, const CommandCost &result,TileIndex tile, const CommandDataBuffer &)
|
||||
void CcPlaySound_CONSTRUCTION_WATER(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_02_CONSTRUCTION_WATER, tile);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ void CcGame(Commands cmd, const CommandCost &result, TileIndex tile, const Comma
|
||||
}
|
||||
}
|
||||
|
||||
CommandCallback *GameInstance::GetDoCommandCallback()
|
||||
CommandCallbackData *GameInstance::GetDoCommandCallback()
|
||||
{
|
||||
return &CcGame;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
private:
|
||||
void RegisterAPI() override;
|
||||
void Died() override;
|
||||
CommandCallback *GetDoCommandCallback() override;
|
||||
CommandCallbackData *GetDoCommandCallback() override;
|
||||
void LoadDummyScript() override {}
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,7 @@ DEF_CMD_TRAIT(CMD_REMOVE_ALL_VEHICLES_GROUP, CmdRemoveAllVehiclesGroup, 0, CMDT_
|
||||
DEF_CMD_TRAIT(CMD_SET_GROUP_FLAG, CmdSetGroupFlag, 0, CMDT_ROUTE_MANAGEMENT)
|
||||
DEF_CMD_TRAIT(CMD_SET_GROUP_LIVERY, CmdSetGroupLivery, 0, CMDT_ROUTE_MANAGEMENT)
|
||||
|
||||
CommandCallback CcCreateGroup;
|
||||
CommandCallback CcAddVehicleNewGroup;
|
||||
void CcCreateGroup(Commands cmd, const CommandCost &result, VehicleType vt, GroupID parent_group);
|
||||
void CcAddVehicleNewGroup(Commands cmd, const CommandCost &result, GroupID, VehicleID veh_id, bool);
|
||||
|
||||
#endif /* GROUP_CMD_H */
|
||||
|
@ -1153,17 +1153,15 @@ static void CcCreateGroup(VehicleType veh_type)
|
||||
* Opens a 'Rename group' window for newly created group.
|
||||
* @param cmd Unused.
|
||||
* @param result Did command succeed?
|
||||
* @param tile Unused.
|
||||
* @param data Command data.
|
||||
* @param vt Vehicle type.
|
||||
* @param parent_group Parent group of the enw group.
|
||||
* @see CmdCreateGroup
|
||||
*/
|
||||
void CcCreateGroup(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcCreateGroup(Commands cmd, const CommandCost &result, VehicleType vt, GroupID parent_group)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
auto [vt, parent_group] = EndianBufferReader::ToValue<CommandTraits<CMD_CREATE_GROUP>::Args>(data);
|
||||
assert(vt <= VEH_AIRCRAFT);
|
||||
|
||||
CcCreateGroup(vt);
|
||||
}
|
||||
|
||||
@ -1171,16 +1169,13 @@ void CcCreateGroup(Commands cmd, const CommandCost &result, TileIndex tile, cons
|
||||
* 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.
|
||||
* @param veh_id vehicle to add to a group
|
||||
*/
|
||||
void CcAddVehicleNewGroup(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcAddVehicleNewGroup(Commands cmd, const CommandCost &result, GroupID, VehicleID veh_id, bool)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
auto [group_id, veh_id, shared] = EndianBufferReader::ToValue<CommandTraits<CMD_ADD_VEHICLE_GROUP>::Args>(data);
|
||||
assert(Vehicle::IsValidID(veh_id));
|
||||
|
||||
CcCreateGroup(Vehicle::Get(veh_id)->type);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,6 @@ CommandCost CmdIndustryCtrl(DoCommandFlag flags, IndustryID ind_id, IndustryActi
|
||||
DEF_CMD_TRAIT(CMD_BUILD_INDUSTRY, CmdBuildIndustry, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION)
|
||||
DEF_CMD_TRAIT(CMD_INDUSTRY_CTRL, CmdIndustryCtrl, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT)
|
||||
|
||||
CommandCallback CcBuildIndustry;
|
||||
void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32, bool, uint32);
|
||||
|
||||
#endif /* INDUSTRY_CMD_H */
|
||||
|
@ -222,13 +222,12 @@ void SortIndustryTypes()
|
||||
* @param cmd Unused.
|
||||
* @param result Result of the command.
|
||||
* @param tile Tile where the industry is placed.
|
||||
* @param data Additional data of the #CMD_BUILD_INDUSTRY command.
|
||||
* @param indtype Industry type.
|
||||
*/
|
||||
void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32, bool, uint32)
|
||||
{
|
||||
if (result.Succeeded()) return;
|
||||
|
||||
auto [tile_, indtype, first_layout, fund, seed] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_INDUSTRY>::Args>(data);
|
||||
if (indtype < NUM_INDUSTRYTYPES) {
|
||||
const IndustrySpec *indsp = GetIndustrySpec(indtype);
|
||||
if (indsp->enabled) {
|
||||
|
@ -77,7 +77,7 @@ bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyl
|
||||
}
|
||||
|
||||
|
||||
void CcPlaySound_EXPLOSION(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcPlaySound_EXPLOSION(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_12_EXPLOSION, tile);
|
||||
}
|
||||
|
@ -507,6 +507,13 @@ CommandDataBuffer SanitizeCmdStrings(const CommandDataBuffer &data)
|
||||
return EndianBufferWriter<CommandDataBuffer>::FromValue(args);
|
||||
}
|
||||
|
||||
|
||||
template <typename T> struct CallbackArgsHelper;
|
||||
template <typename... Targs>
|
||||
struct CallbackArgsHelper<void(* const)(Commands, const CommandCost &, Targs...)> {
|
||||
using Args = std::tuple<std::decay_t<Targs>...>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unpack a generic command packet into its actual typed components.
|
||||
* @tparam Tcmd Command type to be unpacked.
|
||||
@ -517,5 +524,12 @@ template <Commands Tcmd, size_t Tcb>
|
||||
void UnpackNetworkCommand(const CommandPacket* cp)
|
||||
{
|
||||
auto args = EndianBufferReader::ToValue<typename CommandTraits<Tcmd>::Args>(cp->data);
|
||||
Command<Tcmd>::PostFromNet(cp->err_msg, std::get<Tcb>(_callback_tuple), cp->my_cmd, cp->tile, args);
|
||||
|
||||
/* Check if the callback matches with the command arguments. If not, drop the callback. */
|
||||
using Tcallback = std::tuple_element_t<Tcb, decltype(_callback_tuple)>;
|
||||
if constexpr (std::is_same_v<Tcallback, CommandCallback * const> || std::is_same_v<Tcallback, CommandCallbackData * const> || std::is_same_v<typename CommandTraits<Tcmd>::Args, typename CallbackArgsHelper<Tcallback>::Args>) {
|
||||
Command<Tcmd>::PostFromNet(cp->err_msg, std::get<Tcb>(_callback_tuple), cp->my_cmd, cp->tile, args);
|
||||
} else {
|
||||
Command<Tcmd>::PostFromNet(cp->err_msg, (CommandCallback *)nullptr, cp->my_cmd, cp->tile, args);
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ DEF_CMD_TRAIT(CMD_BUILD_SIGNAL_TRACK, CmdBuildSignalTrack, CMD_AUTO,
|
||||
DEF_CMD_TRAIT(CMD_REMOVE_SIGNAL_TRACK, CmdRemoveSignalTrack, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)
|
||||
|
||||
CommandCallback CcPlaySound_CONSTRUCTION_RAIL;
|
||||
CommandCallback CcRailDepot;
|
||||
CommandCallback CcStation;
|
||||
CommandCallback CcBuildRailTunnel;
|
||||
void CcRailDepot(Commands cmd, const CommandCost &result, TileIndex tile, RailType rt, DiagDirection dir);
|
||||
|
||||
#endif /* RAIL_CMD_H */
|
||||
|
@ -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(Commands cmd, const CommandCost &result,TileIndex tile, const CommandDataBuffer &)
|
||||
void CcPlaySound_CONSTRUCTION_RAIL(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
|
||||
}
|
||||
@ -135,12 +135,10 @@ static const DiagDirection _place_depot_extra_dir[12] = {
|
||||
DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_NE,
|
||||
};
|
||||
|
||||
void CcRailDepot(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcRailDepot(Commands cmd, const CommandCost &result, TileIndex tile, RailType rt, DiagDirection dir)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
auto [tile_, rt, dir] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_TRAIN_DEPOT>::Args>(data);
|
||||
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
|
||||
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
||||
|
||||
@ -176,7 +174,7 @@ static void PlaceRail_Waypoint(TileIndex tile)
|
||||
}
|
||||
}
|
||||
|
||||
void CcStation(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcStation(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
@ -275,7 +273,7 @@ static void PlaceRail_Bridge(TileIndex tile, Window *w)
|
||||
}
|
||||
|
||||
/** Command callback for building a tunnel */
|
||||
void CcBuildRailTunnel(Commands cmd, const CommandCost &result,TileIndex tile, const CommandDataBuffer &)
|
||||
void CcBuildRailTunnel(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Succeeded()) {
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
|
||||
|
@ -31,7 +31,7 @@ DEF_CMD_TRAIT(CMD_CONVERT_ROAD, CmdConvertRoad, 0,
|
||||
|
||||
CommandCallback CcPlaySound_CONSTRUCTION_OTHER;
|
||||
CommandCallback CcBuildRoadTunnel;
|
||||
CommandCallback CcRoadDepot;
|
||||
CommandCallback CcRoadStop;
|
||||
void CcRoadDepot(Commands cmd, const CommandCost &result, TileIndex tile, RoadType rt, DiagDirection dir);
|
||||
void CcRoadStop(Commands cmd, const CommandCost &result, TileIndex tile, uint8 width, uint8 length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, StationID, bool);
|
||||
|
||||
#endif /* ROAD_CMD_H */
|
||||
|
@ -57,7 +57,7 @@ static RoadType _cur_roadtype;
|
||||
static DiagDirection _road_depot_orientation;
|
||||
static DiagDirection _road_station_picker_orientation;
|
||||
|
||||
void CcPlaySound_CONSTRUCTION_OTHER(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcPlaySound_CONSTRUCTION_OTHER(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
|
||||
}
|
||||
@ -84,7 +84,7 @@ static void PlaceRoad_Bridge(TileIndex tile, Window *w)
|
||||
* @param result Whether the build succeeded.
|
||||
* @param start_tile Starting tile of the tunnel.
|
||||
*/
|
||||
void CcBuildRoadTunnel(Commands cmd, const CommandCost &result, TileIndex start_tile, const CommandDataBuffer &)
|
||||
void CcBuildRoadTunnel(Commands cmd, const CommandCost &result, TileIndex start_tile)
|
||||
{
|
||||
if (result.Succeeded()) {
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, start_tile);
|
||||
@ -117,12 +117,10 @@ void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
|
||||
}
|
||||
}
|
||||
|
||||
void CcRoadDepot(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcRoadDepot(Commands cmd, const CommandCost &result, TileIndex tile, RoadType rt, DiagDirection dir)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
auto [tile_, rt, dir] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_DEPOT>::Args>(data);
|
||||
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
|
||||
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
||||
ConnectRoadToStructure(tile, dir);
|
||||
@ -130,18 +128,19 @@ void CcRoadDepot(Commands cmd, const CommandCost &result, TileIndex tile, const
|
||||
|
||||
/**
|
||||
* Command callback for building road stops.
|
||||
* @param result Result of the build road stop command.
|
||||
* @param cmd Unused.
|
||||
* @param result Result of the build road stop command.
|
||||
* @param tile Start tile.
|
||||
* @param data Command data.
|
||||
* @param width Width of the road stop.
|
||||
* @param length Length of the road stop.
|
||||
* @param is_drive_through False for normal stops, true for drive-through.
|
||||
* @param dir Entrance direction (#DiagDirection) for normal stops. Converted to the axis for drive-through stops.
|
||||
* @see CmdBuildRoadStop
|
||||
*/
|
||||
void CcRoadStop(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcRoadStop(Commands cmd, const CommandCost &result, TileIndex tile, uint8 width, uint8 length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, StationID, bool)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
auto [tile_, width, length, stop_type, is_drive_through, dir, rt, station_to_join, adjacent] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_ROAD_STOP>::Args>(data);
|
||||
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
|
||||
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
||||
TileArea roadstop_area(tile, width, length);
|
||||
|
@ -296,7 +296,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
return GetStorage()->callback_value[index];
|
||||
}
|
||||
|
||||
/* static */ CommandCallback *ScriptObject::GetDoCommandCallback()
|
||||
/* static */ CommandCallbackData *ScriptObject::GetDoCommandCallback()
|
||||
{
|
||||
return ScriptObject::GetActiveInstance()->GetDoCommandCallback();
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ private:
|
||||
/* Helper functions for DoCommand. */
|
||||
static std::tuple<bool, bool, bool> DoCommandPrep();
|
||||
static bool DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only);
|
||||
static CommandCallback *GetDoCommandCallback();
|
||||
static CommandCallbackData *GetDoCommandCallback();
|
||||
};
|
||||
|
||||
namespace ScriptObjectInternal {
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include "../command_type.h"
|
||||
|
||||
CommandCallback CcAI;
|
||||
CommandCallback CcGame;
|
||||
CommandCallbackData CcAI;
|
||||
CommandCallbackData CcGame;
|
||||
|
||||
#endif /* SCRIPT_CMD_H */
|
||||
|
@ -235,7 +235,7 @@ protected:
|
||||
/**
|
||||
* Get the callback handling DoCommands in case of networking.
|
||||
*/
|
||||
virtual CommandCallback *GetDoCommandCallback() = 0;
|
||||
virtual CommandCallbackData *GetDoCommandCallback() = 0;
|
||||
|
||||
/**
|
||||
* Load the dummy script.
|
||||
|
@ -105,14 +105,11 @@ CommandCost CmdRenameSign(DoCommandFlag flags, SignID sign_id, const std::string
|
||||
|
||||
/**
|
||||
* Callback function that is called after a sign is placed
|
||||
* @param result of the operation
|
||||
* @param cmd unused
|
||||
* @param result of the operation
|
||||
* @param tile unused
|
||||
* @param p1 unused
|
||||
* @param p2 unused
|
||||
* @param text unused
|
||||
*/
|
||||
void CcPlaceSign(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcPlaceSign(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
void CcTerraform(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcTerraform(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Succeeded()) {
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
|
||||
|
@ -1009,7 +1009,7 @@ void ShowTownDirectory()
|
||||
new TownDirectoryWindow(&_town_directory_desc);
|
||||
}
|
||||
|
||||
void CcFoundTown(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcFoundTown(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
@ -1017,7 +1017,7 @@ void CcFoundTown(Commands cmd, const CommandCost &result, TileIndex tile, const
|
||||
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
||||
}
|
||||
|
||||
void CcFoundRandomTown(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcFoundRandomTown(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(_new_town_id)->xy);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
* @param result The result of the command.
|
||||
* @param tile The tile the command was executed on.
|
||||
*/
|
||||
void CcBuildWagon(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &)
|
||||
void CcBuildWagon(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
|
@ -20,6 +20,6 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportT
|
||||
DEF_CMD_TRAIT(CMD_BUILD_BRIDGE, CmdBuildBridge, CMD_DEITY | CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION)
|
||||
DEF_CMD_TRAIT(CMD_BUILD_TUNNEL, CmdBuildTunnel, CMD_DEITY | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)
|
||||
|
||||
CommandCallback CcBuildBridge;
|
||||
void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte);
|
||||
|
||||
#endif /* TUNNELBRIDGE_CMD_H */
|
||||
|
@ -40,7 +40,7 @@ DEF_CMD_TRAIT(CMD_DEPOT_SELL_ALL_VEHICLES, CmdDepotSellAllVehicles, 0,
|
||||
DEF_CMD_TRAIT(CMD_DEPOT_MASS_AUTOREPLACE, CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION)
|
||||
|
||||
CommandCallback CcBuildPrimaryVehicle;
|
||||
CommandCallback CcStartStopVehicle;
|
||||
void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool);
|
||||
|
||||
template <typename Tcont, typename Titer>
|
||||
inline EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const VehicleListIdentifier &vli)
|
||||
|
@ -2617,16 +2617,14 @@ static const StringID _vehicle_msg_translation_table[][4] = {
|
||||
|
||||
/**
|
||||
* This is the Callback method after attempting to start/stop a vehicle
|
||||
* @param result the result of the start/stop command
|
||||
* @param cmd unused
|
||||
* @param tile unused
|
||||
* @param data Command data
|
||||
* @param result the result of the start/stop command
|
||||
* @param veh_id Vehicle ID.
|
||||
*/
|
||||
void CcStartStopVehicle(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcStartStopVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id, bool)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
VehicleID veh_id = std::get<0>(EndianBufferReader::ToValue<CommandTraits<CMD_START_STOP_VEHICLE>::Args>(data));
|
||||
const Vehicle *v = Vehicle::GetIfValid(veh_id);
|
||||
if (v == nullptr || !v->IsPrimaryVehicle() || v->owner != _local_company) return;
|
||||
|
||||
@ -3124,9 +3122,8 @@ void StopGlobalFollowVehicle(const Vehicle *v)
|
||||
* @param result indicates completion (or not) of the operation
|
||||
* @param cmd unused
|
||||
* @param tile unused
|
||||
* @param data unused
|
||||
*/
|
||||
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, TileIndex tile, const CommandDataBuffer &data)
|
||||
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, TileIndex tile)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user