summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-10-30 01:31:46 +0200
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commite740c24eb7a90bc771f5976d64d80639ee7576e5 (patch)
treeb3c8f0c87419cb11c106ba1cb58d6ae0648beef4
parentc88b104ec662ea80bec89f58aa7ad9d0baac7704 (diff)
downloadopenttd-e740c24eb7a90bc771f5976d64d80639ee7576e5.tar.xz
Codechange: Template DoCommand to automagically reflect the parameters of the command proc.
When finished, this will allow each command handler to take individually different parameters, obliviating the need for bit-packing.
-rw-r--r--src/aircraft_cmd.cpp7
-rw-r--r--src/airport_gui.cpp2
-rw-r--r--src/autoreplace_cmd.cpp32
-rw-r--r--src/bridge_gui.cpp3
-rw-r--r--src/build_vehicle_gui.cpp2
-rw-r--r--src/clear_cmd.cpp3
-rw-r--r--src/command.cpp92
-rw-r--r--src/command_func.h73
-rw-r--r--src/command_type.h3
-rw-r--r--src/company_cmd.cpp2
-rw-r--r--src/disaster_vehicle.cpp5
-rw-r--r--src/dock_gui.cpp2
-rw-r--r--src/economy.cpp11
-rw-r--r--src/group_cmd.cpp8
-rw-r--r--src/industry_cmd.cpp16
-rw-r--r--src/landscape.cpp4
-rw-r--r--src/misc_gui.cpp3
-rw-r--r--src/object_cmd.cpp13
-rw-r--r--src/order_backup.cpp5
-rw-r--r--src/order_cmd.cpp3
-rw-r--r--src/rail_cmd.cpp27
-rw-r--r--src/rail_gui.cpp9
-rw-r--r--src/road_cmd.cpp22
-rw-r--r--src/road_gui.cpp5
-rw-r--r--src/roadveh_cmd.cpp3
-rw-r--r--src/script/api/script_object.cpp2
-rw-r--r--src/script/api/script_vehicle.cpp5
-rw-r--r--src/station_cmd.cpp24
-rw-r--r--src/terraform_cmd.cpp7
-rw-r--r--src/terraform_gui.cpp3
-rw-r--r--src/town_cmd.cpp50
-rw-r--r--src/train_cmd.cpp4
-rw-r--r--src/tree_cmd.cpp5
-rw-r--r--src/tunnelbridge_cmd.cpp18
-rw-r--r--src/vehicle.cpp12
-rw-r--r--src/vehicle_cmd.cpp33
-rw-r--r--src/vehicle_gui.cpp5
-rw-r--r--src/water_cmd.cpp23
-rw-r--r--src/waypoint_cmd.cpp3
39 files changed, 320 insertions, 229 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 5e0eea35b..998f75e6b 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -38,6 +38,7 @@
#include "newgrf_airporttiles.h"
#include "framerate_type.h"
#include "aircraft_cmd.h"
+#include "vehicle_cmd.h"
#include "table/strings.h"
@@ -1275,7 +1276,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
const Station *st = GetTargetAirportIfValid(v);
if (st == nullptr) {
Backup<CompanyID> cur_company(_current_company, v->owner, FILE_LINE);
- CommandCost ret = DoCommand(DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT, v->tile, v->index, 0);
+ CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->tile, v->index, 0, {});
cur_company.Restore();
if (ret.Failed()) CrashAirplane(v);
@@ -1638,7 +1639,7 @@ static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass
/* Send the helicopter to a hangar if needed for replacement */
if (v->NeedsAutomaticServicing()) {
Backup<CompanyID> cur_company(_current_company, v->owner, FILE_LINE);
- DoCommand(DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT, v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0);
+ Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0, {});
cur_company.Restore();
}
}
@@ -1689,7 +1690,7 @@ static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc
/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
if (v->NeedsAutomaticServicing()) {
Backup<CompanyID> cur_company(_current_company, v->owner, FILE_LINE);
- DoCommand(DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT, v->tile, v->index | DEPOT_SERVICE, 0);
+ Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->tile, v->index | DEPOT_SERVICE, 0, {});
cur_company.Restore();
}
}
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 65c59784b..98776e52f 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -66,7 +66,7 @@ static void PlaceAirport(TileIndex tile)
auto proc = [=](bool test, StationID to_join) -> bool {
if (test) {
- return DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_AIRPORT)), CMD_BUILD_AIRPORT, tile, p1, p2).Succeeded();
+ return Command<CMD_BUILD_AIRPORT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_AIRPORT>()), tile, p1, p2, {}).Succeeded();
} else {
uint32 p2_final = p2;
if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index a4a4e88a2..4ba41942c 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -23,6 +23,10 @@
#include "news_func.h"
#include "strings_func.h"
#include "autoreplace_cmd.h"
+#include "group_cmd.h"
+#include "order_cmd.h"
+#include "train_cmd.h"
+#include "vehicle_cmd.h"
#include "table/strings.h"
@@ -341,7 +345,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
}
/* Build the new vehicle */
- cost = DoCommand(DC_EXEC | DC_AUTOREPLACE, CMD_BUILD_VEHICLE, old_veh->tile, e | (CT_INVALID << 24), 0);
+ cost = Command<CMD_BUILD_VEHICLE>::Do(DC_EXEC | DC_AUTOREPLACE, old_veh->tile, e | (CT_INVALID << 24), 0, {});
if (cost.Failed()) return cost;
Vehicle *new_veh = Vehicle::Get(_new_vehicle_id);
@@ -351,13 +355,13 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
if (refit_cargo != CT_NO_REFIT) {
byte subtype = GetBestFittingSubType(old_veh, new_veh, refit_cargo);
- cost.AddCost(DoCommand(DC_EXEC, CMD_REFIT_VEHICLE, 0, new_veh->index, refit_cargo | (subtype << 8)));
+ cost.AddCost(Command<CMD_REFIT_VEHICLE>::Do(DC_EXEC, 0, new_veh->index, refit_cargo | (subtype << 8), {}));
assert(cost.Succeeded()); // This should be ensured by GetNewCargoTypeForReplace()
}
/* Try to reverse the vehicle, but do not care if it fails as the new type might not be reversible */
if (new_veh->type == VEH_TRAIN && HasBit(Train::From(old_veh)->flags, VRF_REVERSE_DIRECTION)) {
- DoCommand(DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION, 0, new_veh->index, true);
+ Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DC_EXEC, 0, new_veh->index, true, {});
}
return cost;
@@ -371,7 +375,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
*/
static inline CommandCost CmdStartStopVehicle(const Vehicle *v, bool evaluate_callback)
{
- return DoCommand(DC_EXEC | DC_AUTOREPLACE, CMD_START_STOP_VEHICLE, 0, v->index, evaluate_callback ? 1 : 0);
+ return Command<CMD_START_STOP_VEHICLE>::Do(DC_EXEC | DC_AUTOREPLACE, 0, v->index, evaluate_callback ? 1 : 0, {});
}
/**
@@ -384,7 +388,7 @@ static inline CommandCost CmdStartStopVehicle(const Vehicle *v, bool evaluate_ca
*/
static inline CommandCost CmdMoveVehicle(const Vehicle *v, const Vehicle *after, DoCommandFlag flags, bool whole_chain)
{
- return DoCommand(flags | DC_NO_CARGO_CAP_CHECK, CMD_MOVE_RAIL_VEHICLE, 0, v->index | (whole_chain ? 1 : 0) << 20, after != nullptr ? after->index : INVALID_VEHICLE);
+ return Command<CMD_MOVE_RAIL_VEHICLE>::Do(flags | DC_NO_CARGO_CAP_CHECK, 0, v->index | (whole_chain ? 1 : 0) << 20, after != nullptr ? after->index : INVALID_VEHICLE, {});
}
/**
@@ -398,10 +402,10 @@ static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head,
CommandCost cost = CommandCost();
/* Share orders */
- if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(DC_EXEC, CMD_CLONE_ORDER, 0, new_head->index | CO_SHARE << 30, old_head->index));
+ if (cost.Succeeded() && old_head != new_head) cost.AddCost(Command<CMD_CLONE_ORDER>::Do(DC_EXEC, 0, new_head->index | CO_SHARE << 30, old_head->index, {}));
/* Copy group membership */
- if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(DC_EXEC, CMD_ADD_VEHICLE_GROUP, 0, old_head->group_id, new_head->index));
+ if (cost.Succeeded() && old_head != new_head) cost.AddCost(Command<CMD_ADD_VEHICLE_GROUP>::Do(DC_EXEC, 0, old_head->group_id, new_head->index, {}));
/* Perform start/stop check whether the new vehicle suits newgrf restrictions etc. */
if (cost.Succeeded()) {
@@ -467,11 +471,11 @@ static CommandCost ReplaceFreeUnit(Vehicle **single_unit, DoCommandFlag flags, b
}
/* Sell the old vehicle */
- cost.AddCost(DoCommand(flags, CMD_SELL_VEHICLE, 0, old_v->index, 0));
+ cost.AddCost(Command<CMD_SELL_VEHICLE>::Do(flags, 0, old_v->index, 0, {}));
/* If we are not in DC_EXEC undo everything */
if ((flags & DC_EXEC) == 0) {
- DoCommand(DC_EXEC, CMD_SELL_VEHICLE, 0, new_v->index, 0);
+ Command<CMD_SELL_VEHICLE>::Do(DC_EXEC, 0, new_v->index, 0, {});
}
}
@@ -598,7 +602,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
assert(RailVehInfo(wagon->engine_type)->railveh_type == RAILVEH_WAGON);
/* Sell wagon */
- [[maybe_unused]] CommandCost ret = DoCommand(DC_EXEC, CMD_SELL_VEHICLE, 0, wagon->index, 0);
+ [[maybe_unused]] CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(DC_EXEC, 0, wagon->index, 0, {});
assert(ret.Succeeded());
new_vehs[i] = nullptr;
@@ -630,7 +634,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
/* Sell the vehicle.
* Note: This might temporarily construct new trains, so use DC_AUTOREPLACE to prevent
* it from failing due to engine limits. */
- cost.AddCost(DoCommand(flags | DC_AUTOREPLACE, CMD_SELL_VEHICLE, 0, w->index, 0));
+ cost.AddCost(Command<CMD_SELL_VEHICLE>::Do(flags | DC_AUTOREPLACE, 0, w->index, 0, {}));
if ((flags & DC_EXEC) != 0) {
old_vehs[i] = nullptr;
if (i == 0) old_head = nullptr;
@@ -661,7 +665,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
if ((flags & DC_EXEC) == 0) {
for (int i = num_units - 1; i >= 0; i--) {
if (new_vehs[i] != nullptr) {
- DoCommand(DC_EXEC, CMD_SELL_VEHICLE, 0, new_vehs[i]->index, 0);
+ Command<CMD_SELL_VEHICLE>::Do(DC_EXEC, 0, new_vehs[i]->index, 0, {});
new_vehs[i] = nullptr;
}
}
@@ -692,12 +696,12 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
}
/* Sell the old vehicle */
- cost.AddCost(DoCommand(flags, CMD_SELL_VEHICLE, 0, old_head->index, 0));
+ cost.AddCost(Command<CMD_SELL_VEHICLE>::Do(flags, 0, old_head->index, 0, {}));
}
/* If we are not in DC_EXEC undo everything */
if ((flags & DC_EXEC) == 0) {
- DoCommand(DC_EXEC, CMD_SELL_VEHICLE, 0, new_head->index, 0);
+ Command<CMD_SELL_VEHICLE>::Do(DC_EXEC, 0, new_head->index, 0, {});
}
}
}
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index 3524b357c..abd1f3da5 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -23,6 +23,7 @@
#include "cmd_helper.h"
#include "tunnelbridge_map.h"
#include "road_gui.h"
+#include "tunnelbridge_cmd.h"
#include "widgets/bridge_widget.h"
@@ -391,7 +392,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
/* only query bridge building possibility once, result is the same for all bridges!
* returns CMD_ERROR on failure, and price on success */
StringID errmsg = INVALID_STRING_ID;
- CommandCost ret = DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_QUERY_COST, CMD_BUILD_BRIDGE, end, start, type);
+ CommandCost ret = Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()) | DC_QUERY_COST, end, start, type, {});
GUIBridgeList *bl = nullptr;
if (ret.Failed()) {
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 7901b4574..9082de5a9 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -1228,7 +1228,7 @@ struct BuildVehicleWindow : Window {
if (!this->listview_mode) {
/* Query for cost and refitted capacity */
- CommandCost ret = DoCommand(DC_QUERY_COST, CMD_BUILD_VEHICLE, this->window_number, this->sel_engine | (cargo << 24), 0);
+ CommandCost ret = Command<CMD_BUILD_VEHICLE>::Do(DC_QUERY_COST, this->window_number, this->sel_engine | (cargo << 24), 0, {});
if (ret.Succeeded()) {
this->te.cost = ret.GetCost() - e->GetCost();
this->te.capacity = _returned_refit_capacity;
diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp
index 918f5c373..f2f7ecc19 100644
--- a/src/clear_cmd.cpp
+++ b/src/clear_cmd.cpp
@@ -16,6 +16,7 @@
#include "water.h"
#include "core/random_func.hpp"
#include "newgrf_generic.h"
+#include "landscape_cmd.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -381,7 +382,7 @@ static void ChangeTileOwner_Clear(TileIndex tile, Owner old_owner, Owner new_own
static CommandCost TerraformTile_Clear(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
{
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
extern const TileTypeProcs _tile_type_clear_procs = {
diff --git a/src/command.cpp b/src/command.cpp
index 06025a949..69cbaa6c9 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -164,64 +164,6 @@ bool IsCommandAllowedWhilePaused(Commands cmd)
return _game_mode == GM_EDITOR || command_type_lookup[_command_proc_table[cmd].type] <= _settings_game.construction.command_pause_level;
}
-
-/*!
- * This function executes a given command with the parameters from the #CommandProc parameter list.
- * Depending on the flags parameter it execute or test a command.
- *
- * @param flags Flags for the command and how to execute the command
- * @param cmd The command-id to execute (a value of the CMD_* enums)
- * @param tile The tile to apply the command on (for the #CommandProc)
- * @param p1 Additional data for the command (for the #CommandProc)
- * @param p2 Additional data for the command (for the #CommandProc)
- * @param text The text to pass
- * @see CommandProc
- * @return the cost
- */
-CommandCost DoCommand(DoCommandFlag flags, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
-{
- CommandCost res;
-
- /* Do not even think about executing out-of-bounds tile-commands */
- if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (flags & DC_ALL_TILES) == 0))) return CMD_ERROR;
-
- /* Chop of any CMD_MSG or other flags; we don't need those here */
- CommandProc *proc = _command_proc_table[cmd].proc;
-
- RecursiveCommandCounter counter{};
-
- /* only execute the test call if it's toplevel, or we're not execing. */
- if (counter.IsTopLevel() || !(flags & DC_EXEC) ) {
- if (counter.IsTopLevel()) _cleared_object_areas.clear();
- SetTownRatingTestMode(true);
- res = proc(flags & ~DC_EXEC, tile, p1, p2, text);
- SetTownRatingTestMode(false);
- if (res.Failed()) return res;
-
- if (counter.IsTopLevel() &&
- !(flags & DC_QUERY_COST) &&
- !(flags & DC_BANKRUPT) &&
- !CheckCompanyHasMoney(res)) { // CheckCompanyHasMoney() modifies 'res' to an error if it fails.
- return res;
- }
-
- if (!(flags & DC_EXEC)) return res;
- }
-
- /* Execute the command here. All cost-relevant functions set the expenses type
- * themselves to the cost object at some point */
- if (counter.IsTopLevel()) _cleared_object_areas.clear();
- res = proc(flags, tile, p1, p2, text);
- if (res.Failed()) return res;
-
- /* if toplevel, subtract the money. */
- if (counter.IsTopLevel() && !(flags & DC_BANKRUPT)) {
- SubtractMoneyFromCompany(res);
- }
-
- return res;
-}
-
/*!
* This functions returns the money which can be used to execute a command.
* This is either the money of the current company or INT64_MAX if there
@@ -237,6 +179,40 @@ Money GetAvailableMoneyForCommand()
}
+/**
+ * Prepare for calling a command proc.
+ * @param top_level Top level of command execution, i.e. command from a command.
+ * @param test Test run of command?
+ */
+void CommandHelperBase::InternalDoBefore(bool top_level, bool test)
+{
+ if (top_level) _cleared_object_areas.clear();
+ if (test) SetTownRatingTestMode(true);
+}
+
+/**
+ * Process result after calling a command proc.
+ * @param[in,out] res Command result, may be modified.
+ * @param flags Command flags.
+ * @param top_level Top level of command execution, i.e. command from a command.
+ * @param test Test run of command?
+ */
+void CommandHelperBase::InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test)
+{
+ if (test) {
+ SetTownRatingTestMode(false);
+
+ if (res.Succeeded() && top_level && !(flags & DC_QUERY_COST) && !(flags & DC_BANKRUPT)) {
+ CheckCompanyHasMoney(res); // CheckCompanyHasMoney() modifies 'res' to an error if it fails.
+ }
+ } else {
+ /* If top-level, subtract the money. */
+ if (res.Succeeded() && top_level && !(flags & DC_BANKRUPT)) {
+ SubtractMoneyFromCompany(res);
+ }
+ }
+}
+
/*!
* Toplevel network safe docommand function for the current company. Must not be called recursively.
* The callback is called when the command succeeded or failed. The parameters
diff --git a/src/command_func.h b/src/command_func.h
index 2a6f0c68a..1c24221cd 100644
--- a/src/command_func.h
+++ b/src/command_func.h
@@ -13,6 +13,7 @@
#include "command_type.h"
#include "company_type.h"
#include <vector>
+#include "tile_map.h"
/**
* Define a default return value for a failed command.
@@ -36,7 +37,6 @@ static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
/** Storage buffer for serialized command data. */
typedef std::vector<byte> CommandDataBuffer;
-CommandCost DoCommand(DoCommandFlag flags, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
bool DoCommandP(Commands cmd, StringID err_message, CommandCallback *callback, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
bool DoCommandP(Commands cmd, StringID err_message, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
@@ -58,12 +58,18 @@ const char *GetCommandName(Commands cmd);
Money GetAvailableMoneyForCommand();
bool IsCommandAllowedWhilePaused(Commands cmd);
+template <Commands Tcmd>
+constexpr CommandFlags GetCommandFlags()
+{
+ return CommandTraits<Tcmd>::flags;
+}
+
/**
* Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
* @param cmd_flags Flags from GetCommandFlags
* @return flags for DoCommand
*/
-static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
+static constexpr inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
{
DoCommandFlag flags = DC_NONE;
if (cmd_flags & CMD_NO_WATER) flags |= DC_NO_WATER;
@@ -83,4 +89,67 @@ private:
static int _counter;
};
+
+template<Commands TCmd, typename T> struct CommandHelper;
+
+class CommandHelperBase {
+protected:
+ static void InternalDoBefore(bool top_level, bool test);
+ static void InternalDoAfter(CommandCost &res, DoCommandFlag flags, bool top_level, bool test);
+};
+
+/**
+ * Templated wrapper that exposes the command parameter arguments
+ * for the various Command::Do/Post calls.
+ * @tparam Tcmd The command-id to execute.
+ * @tparam Targs The command parameter types.
+ */
+template <Commands Tcmd, typename... Targs>
+struct CommandHelper<Tcmd, CommandCost(*)(DoCommandFlag, Targs...)> : protected CommandHelperBase {
+public:
+ /**
+ * This function executes a given command with the parameters from the #CommandProc parameter list.
+ * Depending on the flags parameter it executes or tests a command.
+ *
+ * @note This function is to be called from the StateGameLoop or from within the execution of a Command.
+ * This function must not be called from the context of a "player" (real person, AI, game script).
+ * Use ::Post for commands directly triggered by "players".
+ *
+ * @param flags Flags for the command and how to execute the command
+ * @param args Parameters for the command
+ * @see CommandProc
+ * @return the cost
+ */
+ static CommandCost Do(DoCommandFlag flags, Targs... args)
+ {
+ if constexpr (std::is_same_v<TileIndex, std::tuple_element_t<0, std::tuple<Targs...>>>) {
+ /* Do not even think about executing out-of-bounds tile-commands. */
+ TileIndex tile = std::get<0>(std::make_tuple(args...));
+ if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (flags & DC_ALL_TILES) == 0))) return CMD_ERROR;
+ }
+
+ RecursiveCommandCounter counter{};
+
+ /* Only execute the test call if it's toplevel, or we're not execing. */
+ if (counter.IsTopLevel() || !(flags & DC_EXEC)) {
+ InternalDoBefore(counter.IsTopLevel(), true);
+ CommandCost res = CommandTraits<Tcmd>::proc(flags & ~DC_EXEC, args...);
+ InternalDoAfter(res, flags, counter.IsTopLevel(), true); // Can modify res.
+
+ if (res.Failed() || !(flags & DC_EXEC)) return res;
+ }
+
+ /* Execute the command here. All cost-relevant functions set the expenses type
+ * themselves to the cost object at some point. */
+ InternalDoBefore(counter.IsTopLevel(), false);
+ CommandCost res = CommandTraits<Tcmd>::proc(flags, args...);
+ InternalDoAfter(res, flags, counter.IsTopLevel(), false);
+
+ return res;
+ }
+};
+
+template <Commands Tcmd>
+using Command = CommandHelper<Tcmd, typename CommandTraits<Tcmd>::ProcType>;
+
#endif /* COMMAND_FUNC_H */
diff --git a/src/command_type.h b/src/command_type.h
index cc5e97795..c182ca393 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -435,7 +435,8 @@ template <Commands Tcmd> struct CommandTraits;
#define DEF_CMD_TRAIT(cmd_, proc_, flags_, type_) \
template<> struct CommandTraits<cmd_> { \
- using Args = typename CommandFunctionTraitHelper<decltype(&proc_)>::Args; \
+ using ProcType = decltype(&proc_); \
+ using Args = typename CommandFunctionTraitHelper<ProcType>::Args; \
static constexpr Commands cmd = cmd_; \
static constexpr auto &proc = proc_; \
static constexpr CommandFlags flags = (CommandFlags)(flags_); \
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index f659a4367..6bd60659b 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -1128,7 +1128,7 @@ CommandCost CmdRenamePresident(DoCommandFlag flags, TileIndex tile, uint32 p1, u
c->president_name = text;
if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) {
- DoCommand(DC_EXEC, CMD_RENAME_COMPANY, 0, 0, 0, text + " Transport");
+ Command<CMD_RENAME_COMPANY>::Do(DC_EXEC, 0, 0, 0, text + " Transport");
}
}
diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp
index 63f4188a8..6319af0ab 100644
--- a/src/disaster_vehicle.cpp
+++ b/src/disaster_vehicle.cpp
@@ -45,6 +45,7 @@
#include "company_base.h"
#include "core/random_func.hpp"
#include "core/backup_type.hpp"
+#include "landscape_cmd.h"
#include "table/strings.h"
@@ -61,7 +62,7 @@ static void DisasterClearSquare(TileIndex tile)
case MP_RAILWAY:
if (Company::IsHumanID(GetTileOwner(tile)) && !IsRailDepot(tile)) {
Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
- DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, tile, 0, 0, {});
cur_company.Restore();
/* update signals in buffer */
@@ -71,7 +72,7 @@ static void DisasterClearSquare(TileIndex tile)
case MP_HOUSE: {
Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
- DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, tile, 0, 0, {});
cur_company.Restore();
break;
}
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index da7e0518f..571bfdcec 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -215,7 +215,7 @@ struct BuildDocksToolbarWindow : Window {
auto proc = [=](bool test, StationID to_join) -> bool {
if (test) {
- return DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_DOCK)), CMD_BUILD_DOCK, tile, p1, p2).Succeeded();
+ return Command<CMD_BUILD_DOCK>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_DOCK>()), tile, p1, p2, {}).Succeeded();
} else {
uint32 p2_final = p2;
if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
diff --git a/src/economy.cpp b/src/economy.cpp
index 39e98342f..e7daf8e3d 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -49,6 +49,7 @@
#include "story_base.h"
#include "linkgraph/refresh.h"
#include "economy_cmd.h"
+#include "vehicle_cmd.h"
#include "table/strings.h"
#include "table/pricebase.h"
@@ -313,7 +314,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
for (i = 0; i < 4; i++) {
if (c->share_owners[i] == old_owner) {
/* Sell its shares */
- CommandCost res = DoCommand(DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY, 0, c->index, 0);
+ CommandCost res = Command<CMD_SELL_SHARE_IN_COMPANY>::Do(DC_EXEC | DC_BANKRUPT, 0, c->index, 0, {});
/* Because we are in a DoCommand, we can't just execute another one and
* expect the money to be removed. We need to do it ourself! */
SubtractMoneyFromCompany(res);
@@ -333,7 +334,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
} else {
cur_company2.Change(c->share_owners[i]);
/* Sell the shares */
- CommandCost res = DoCommand(DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY, 0, old_owner, 0);
+ CommandCost res = Command<CMD_SELL_SHARE_IN_COMPANY>::Do(DC_EXEC | DC_BANKRUPT, 0, old_owner, 0, {});
/* Because we are in a DoCommand, we can't just execute another one and
* expect the money to be removed. We need to do it ourself! */
SubtractMoneyFromCompany(res);
@@ -449,7 +450,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
* However, do not rely on that behaviour.
*/
int interval = CompanyServiceInterval(new_company, v->type);
- DoCommand(DC_EXEC | DC_BANKRUPT, CMD_CHANGE_SERVICE_INT, v->tile, v->index, interval | (new_company->settings.vehicle.servint_ispercent << 17));
+ Command<CMD_CHANGE_SERVICE_INT>::Do(DC_EXEC | DC_BANKRUPT, v->tile, v->index, interval | (new_company->settings.vehicle.servint_ispercent << 17), {});
}
v->owner = new_owner;
@@ -1486,7 +1487,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station
if (st->goods[cid].cargo.HasCargoFor(next_station)) {
/* Try to find out if auto-refitting would succeed. In case the refit is allowed,
* the returned refit capacity will be greater than zero. */
- DoCommand(DC_QUERY_COST, CMD_REFIT_VEHICLE, v_start->tile, v_start->index, cid | 1U << 24 | 0xFF << 8 | 1U << 16); // Auto-refit and only this vehicle including artic parts.
+ Command<CMD_REFIT_VEHICLE>::Do(DC_QUERY_COST, v_start->tile, v_start->index, cid | 1U << 24 | 0xFF << 8 | 1U << 16, {}); // Auto-refit and only this vehicle including artic parts.
/* Try to balance different loadable cargoes between parts of the consist, so that
* all of them can be loaded. Avoid a situation where all vehicles suddenly switch
* to the first loadable cargo for which there is only one packet. If the capacities
@@ -1509,7 +1510,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station
* "via any station" before reserving. We rather produce some more "any station" cargo than
* misrouting it. */
IterateVehicleParts(v_start, ReturnCargoAction(st, INVALID_STATION));
- CommandCost cost = DoCommand(DC_EXEC, CMD_REFIT_VEHICLE, v_start->tile, v_start->index, new_cid | 1U << 24 | 0xFF << 8 | 1U << 16); // Auto-refit and only this vehicle including artic parts.
+ CommandCost cost = Command<CMD_REFIT_VEHICLE>::Do(DC_EXEC, v_start->tile, v_start->index, new_cid | 1U << 24 | 0xFF << 8 | 1U << 16, {}); // Auto-refit and only this vehicle including artic parts.
if (cost.Succeeded()) v->First()->profit_this_year -= cost.GetCost() << 8;
}
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index fbe08ffd0..2ff8a09df 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -357,12 +357,12 @@ CommandCost CmdDeleteGroup(DoCommandFlag flags, TileIndex tile, uint32 p1, uint3
if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
/* Remove all vehicles from the group */
- DoCommand(flags, CMD_REMOVE_ALL_VEHICLES_GROUP, 0, p1, 0);
+ Command<CMD_REMOVE_ALL_VEHICLES_GROUP>::Do(flags, 0, p1, 0, {});
/* Delete sub-groups */
for (const Group *gp : Group::Iterate()) {
if (gp->parent == g->index) {
- DoCommand(flags, CMD_DELETE_GROUP, 0, gp->index, 0);
+ Command<CMD_DELETE_GROUP>::Do(flags, 0, gp->index, 0, {});
}
}
@@ -581,7 +581,7 @@ CommandCost CmdAddSharedVehicleGroup(DoCommandFlag flags, TileIndex tile, uint32
/* For each shared vehicles add it to the group */
for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
- if (v2->group_id != id_g) DoCommand(flags, CMD_ADD_VEHICLE_GROUP, tile, id_g, v2->index, text);
+ if (v2->group_id != id_g) Command<CMD_ADD_VEHICLE_GROUP>::Do(flags, tile, id_g, v2->index, text);
}
}
}
@@ -617,7 +617,7 @@ CommandCost CmdRemoveAllVehiclesGroup(DoCommandFlag flags, TileIndex tile, uint3
if (v->group_id != old_g) continue;
/* Add The Vehicle to the default group */
- DoCommand(flags, CMD_ADD_VEHICLE_GROUP, tile, DEFAULT_GROUP, v->index, text);
+ Command<CMD_ADD_VEHICLE_GROUP>::Do(flags,tile, DEFAULT_GROUP, v->index, text);
}
}
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index e2fa1b776..b7d6d3714 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -43,6 +43,8 @@
#include "cmd_helper.h"
#include "string_func.h"
#include "industry_cmd.h"
+#include "landscape_cmd.h"
+#include "terraform_cmd.h"
#include "table/strings.h"
#include "table/industry_land.h"
@@ -1101,7 +1103,7 @@ static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
_industry_sound_tile = tile;
if (_settings_client.sound.ambient) SndPlayTileFx(SND_38_LUMBER_MILL_1, tile);
- DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, tile, 0, 0, {});
cur_company.Restore();
return true;
@@ -1483,13 +1485,13 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil
/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
- CommandCost ret = DoCommand(DC_NONE, CMD_LANDSCAPE_CLEAR, cur_tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_NONE, cur_tile, 0, 0, {});
cur_company.Restore();
if (ret.Failed()) return ret;
} else {
/* Clear the tiles, but do not affect town ratings */
- CommandCost ret = DoCommand(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, cur_tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile, 0, 0, {});
if (ret.Failed()) return ret;
}
@@ -1599,7 +1601,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
}
/* This is not 100% correct check, but the best we can do without modifying the map.
* What is missing, is if the difference in height is more than 1.. */
- if (DoCommand(flags & ~DC_EXEC, CMD_TERRAFORM_LAND, tile_walk, SLOPE_N, (curh > h) ? 0 : 1).Failed()) {
+ if (Command<CMD_TERRAFORM_LAND>::Do(flags & ~DC_EXEC, tile_walk, SLOPE_N, (curh > h) ? 0 : 1, {}).Failed()) {
cur_company.Restore();
return false;
}
@@ -1614,7 +1616,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
/* We give the terraforming for free here, because we can't calculate
* exact cost in the test-round, and as we all know, that will cause
* a nice assert if they don't match ;) */
- DoCommand(flags, CMD_TERRAFORM_LAND, tile_walk, SLOPE_N, (curh > h) ? 0 : 1);
+ Command<CMD_TERRAFORM_LAND>::Do(flags, tile_walk, SLOPE_N, (curh > h) ? 0 : 1, {});
curh += (curh > h) ? -1 : 1;
}
}
@@ -1884,7 +1886,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID);
- DoCommand(DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, cur_tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile, 0, 0, {});
MakeIndustry(cur_tile, i->index, it.gfx, Random(), wc);
@@ -3060,7 +3062,7 @@ static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, i
}
}
}
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
extern const TileTypeProcs _tile_type_industry_procs = {
diff --git a/src/landscape.cpp b/src/landscape.cpp
index 1259617ac..6efa8dba2 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -756,7 +756,7 @@ CommandCost CmdClearArea(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(tile, p1);
for (; *iter != INVALID_TILE; ++(*iter)) {
TileIndex t = *iter;
- CommandCost ret = DoCommand(flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR, t, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_EXEC, t, 0, 0, {});
if (ret.Failed()) {
last_error = ret;
@@ -773,7 +773,7 @@ CommandCost CmdClearArea(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
delete iter;
return cost;
}
- DoCommand(flags, CMD_LANDSCAPE_CLEAR, t, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(flags, t, 0, 0, {});
/* draw explosion animation...
* Disable explosions when game is paused. Looks silly and blocks the view. */
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 859798deb..b2e8b886e 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -26,6 +26,7 @@
#include "zoom_func.h"
#include "guitimer_func.h"
#include "viewport_func.h"
+#include "landscape_cmd.h"
#include "rev.h"
#include "widgets/misc_widget.h"
@@ -191,7 +192,7 @@ public:
Company *c = Company::GetIfValid(_local_company);
if (c != nullptr) {
assert(_current_company == _local_company);
- CommandCost costclear = DoCommand(DC_QUERY_COST, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ CommandCost costclear = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_QUERY_COST, tile, 0, 0, {});
if (costclear.Succeeded()) {
Money cost = costclear.GetCost();
if (cost < 0) {
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index b5271727c..a651239ba 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -34,6 +34,7 @@
#include "vehicle_func.h"
#include "station_func.h"
#include "object_cmd.h"
+#include "landscape_cmd.h"
#include "table/strings.h"
#include "table/object_land.h"
@@ -230,7 +231,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, uint32 p1, uint3
if (type == OBJECT_OWNED_LAND) {
/* Owned land is special as it can be placed on any slope. */
- cost.AddCost(DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0));
+ cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {}));
} else {
/* Check the surface to build on. At this time we can't actually execute the
* the CLEAR_TILE commands since the newgrf callback later on can check
@@ -243,7 +244,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, uint32 p1, uint3
if (!IsWaterTile(t)) {
/* Normal water tiles don't have to be cleared. For all other tile types clear
* the tile but leave the water. */
- cost.AddCost(DoCommand(flags & ~DC_NO_WATER & ~DC_EXEC, CMD_LANDSCAPE_CLEAR, t, 0, 0));
+ cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_NO_WATER & ~DC_EXEC, t, 0, 0, {}));
} else {
/* Can't build on water owned by another company. */
Owner o = GetTileOwner(t);
@@ -261,7 +262,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, uint32 p1, uint3
IsTileType(t, MP_OBJECT) &&
IsTileOwner(t, _current_company) &&
IsObjectType(t, OBJECT_HQ))) {
- cost.AddCost(DoCommand(flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR, t, 0, 0));
+ cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_EXEC, t, 0, 0, {}));
}
}
}
@@ -293,10 +294,10 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, uint32 p1, uint3
for (TileIndex t : ta) {
if (HasTileWaterGround(t)) {
if (!IsWaterTile(t)) {
- DoCommand((flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, t, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do((flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, t, 0, 0, {});
}
} else {
- DoCommand(flags | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, t, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DC_NO_MODIFY_TOWN_RATING, t, 0, 0, {});
}
}
}
@@ -848,7 +849,7 @@ static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, int
}
}
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
extern const TileTypeProcs _tile_type_object_procs = {
diff --git a/src/order_backup.cpp b/src/order_backup.cpp
index 76c416abd..80fc9fa6d 100644
--- a/src/order_backup.cpp
+++ b/src/order_backup.cpp
@@ -17,6 +17,7 @@
#include "window_func.h"
#include "station_map.h"
#include "order_cmd.h"
+#include "group_cmd.h"
#include "safeguards.h"
@@ -74,7 +75,7 @@ void OrderBackup::DoRestore(Vehicle *v)
{
/* If we had shared orders, recover that */
if (this->clone != nullptr) {
- DoCommand(DC_EXEC, CMD_CLONE_ORDER, 0, v->index | CO_SHARE << 30, this->clone->index);
+ Command<CMD_CLONE_ORDER>::Do(DC_EXEC, 0, v->index | CO_SHARE << 30, this->clone->index, {});
} else if (this->orders != nullptr && OrderList::CanAllocateItem()) {
v->orders.list = new OrderList(this->orders, v);
this->orders = nullptr;
@@ -89,7 +90,7 @@ void OrderBackup::DoRestore(Vehicle *v)
if (v->cur_implicit_order_index >= v->GetNumOrders()) v->cur_implicit_order_index = v->cur_real_order_index;
/* Restore vehicle group */
- DoCommand(DC_EXEC, CMD_ADD_VEHICLE_GROUP, 0, this->group, v->index);
+ Command<CMD_ADD_VEHICLE_GROUP>::Do(DC_EXEC, 0, this->group, v->index, {});
}
/**
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index e48cc95c1..45a0db99f 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -27,6 +27,7 @@
#include "order_backup.h"
#include "cheat_type.h"
#include "order_cmd.h"
+#include "train_cmd.h"
#include "table/strings.h"
@@ -2037,7 +2038,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo());
/* If there is no depot in front, reverse automatically (trains only) */
- if (v->type == VEH_TRAIN && reverse) DoCommand(DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION, v->tile, v->index, 0);
+ if (v->type == VEH_TRAIN && reverse) Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DC_EXEC, v->tile, v->index, 0, {});
if (v->type == VEH_AIRCRAFT) {
Aircraft *a = Aircraft::From(v);
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index af99b03ae..066fb7820 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -32,6 +32,7 @@
#include "company_gui.h"
#include "object_map.h"
#include "rail_cmd.h"
+#include "landscape_cmd.h"
#include "table/strings.h"
#include "table/railtypes.h"
@@ -452,7 +453,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, uint32 p1, u
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret;
- if (!IsPlainRail(tile)) return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0); // just get appropriate error message
+ if (!IsPlainRail(tile)) return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {}); // just get appropriate error message
if (!IsCompatibleRail(GetRailType(tile), railtype)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
@@ -470,7 +471,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, uint32 p1, u
for (Track track_it = TRACK_BEGIN; track_it < TRACK_END; track_it++) {
if (HasTrack(tile, track_it) && HasSignalOnTrack(tile, track_it)) {
- CommandCost ret_remove_signals = DoCommand(flags, CMD_REMOVE_SIGNALS, tile, track_it, 0);
+ CommandCost ret_remove_signals = Command<CMD_REMOVE_SIGNALS>::Do(flags, tile, track_it, 0, {});
if (ret_remove_signals.Failed()) return ret_remove_signals;
cost.AddCost(ret_remove_signals);
}
@@ -482,7 +483,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, uint32 p1, u
* the present rail type are powered on the new rail type. */
if (GetRailType(tile) != railtype && !HasPowerOnRail(railtype, GetRailType(tile))) {
if (HasPowerOnRail(GetRailType(tile), railtype)) {
- ret = DoCommand(flags, CMD_CONVERT_RAIL, tile, tile, railtype);
+ ret = Command<CMD_CONVERT_RAIL>::Do(flags, tile, tile, railtype, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
} else {
@@ -582,7 +583,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, uint32 p1, u
if (ret.Failed()) return ret;
cost.AddCost(ret);
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
@@ -692,7 +693,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, uint32 p1,
/* Charge extra to remove signals on the track, if they are there */
if (HasSignalOnTrack(tile, track)) {
- cost.AddCost(DoCommand(flags, CMD_REMOVE_SIGNALS, tile, track, 0));
+ cost.AddCost(Command<CMD_REMOVE_SIGNALS>::Do(flags, tile, track, 0, {}));
}
if (flags & DC_EXEC) {
@@ -785,7 +786,7 @@ bool FloodHalftile(TileIndex t)
TrackBits to_remove = lower_track & rail_bits;
if (to_remove != 0) {
Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
- flooded = DoCommand(DC_EXEC, CMD_REMOVE_SINGLE_RAIL, t, 0, FIND_FIRST_BIT(to_remove)).Succeeded();
+ flooded = Command<CMD_REMOVE_SINGLE_RAIL>::Do(DC_EXEC, t, 0, FIND_FIRST_BIT(to_remove), {}).Succeeded();
cur_company.Restore();
if (!flooded) return flooded; // not yet floodable
rail_bits = rail_bits & ~to_remove;
@@ -904,7 +905,8 @@ static CommandCost CmdRailTrackHelper(DoCommandFlag flags, TileIndex tile, uint3
bool had_success = false;
CommandCost last_error = CMD_ERROR;
for (;;) {
- CommandCost ret = DoCommand(flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL, tile, remove ? 0 : railtype, TrackdirToTrack(trackdir) | (auto_remove_signals << 3));
+ uint32 p2 = TrackdirToTrack(trackdir) | (auto_remove_signals << 3);
+ CommandCost ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, 0, p2, {}) : Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, p2, {});
if (ret.Failed()) {
last_error = ret;
@@ -1008,7 +1010,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, uint32 p1, u
cost.AddCost(_price[PR_BUILD_FOUNDATION]);
}
- cost.AddCost(DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0));
+ cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {}));
if (cost.Failed()) return cost;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
@@ -1359,7 +1361,8 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, uin
if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
- CommandCost ret = DoCommand(test_only ? flags & ~DC_EXEC : flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS, tile, param1, signals);
+ DoCommandFlag do_flags = test_only ? flags & ~DC_EXEC : flags;
+ CommandCost ret = remove ? Command<CMD_REMOVE_SIGNALS>::Do(do_flags, tile, param1, signals, {}) : Command<CMD_BUILD_SIGNALS>::Do(do_flags, tile, param1, signals, {});
if (test_only) return ret.Succeeded();
@@ -1879,7 +1882,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
TrackBits tracks = GetTrackBits(tile);
while (tracks != TRACK_BIT_NONE) {
Track track = RemoveFirstTrack(&tracks);
- CommandCost ret = DoCommand(flags, CMD_REMOVE_SINGLE_RAIL, tile, 0, track);
+ CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, 0, track, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
}
@@ -2953,7 +2956,7 @@ static void ChangeTileOwner_Track(TileIndex tile, Owner old_owner, Owner new_own
SetTileOwner(tile, new_owner);
} else {
- DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile, 0, 0, {});
}
}
@@ -3141,7 +3144,7 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int
AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) {
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
}
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 76d51ccb2..f88352f9e 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -37,6 +37,7 @@
#include "stringfilter_type.h"
#include "string_func.h"
#include "station_cmd.h"
+#include "tunnelbridge_cmd.h"
#include "waypoint_cmd.h"
#include "station_map.h"
@@ -202,7 +203,7 @@ static void PlaceRail_Station(TileIndex tile)
auto proc = [=](bool test, StationID to_join) -> bool {
if (test) {
- return DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_RAIL_STATION)), CMD_BUILD_RAIL_STATION, tile, p1, p2).Succeeded();
+ return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), tile, p1, p2, {}).Succeeded();
} else {
uint32 p2_final = p2;
if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
@@ -738,7 +739,7 @@ struct BuildRailToolbarWindow : Window {
auto proc = [=](bool test, StationID to_join) -> bool {
if (test) {
- return DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_RAIL_WAYPOINT)), CMD_BUILD_RAIL_WAYPOINT, ta.tile, p1, p2).Succeeded();
+ return Command<CMD_BUILD_RAIL_WAYPOINT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_WAYPOINT>()), ta.tile, p1, p2, {}).Succeeded();
} else {
uint32 p2_final = p2;
if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
@@ -773,7 +774,7 @@ struct BuildRailToolbarWindow : Window {
void OnPlacePresize(Point pt, TileIndex tile) override
{
- DoCommand(DC_AUTO, CMD_BUILD_TUNNEL, tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0);
+ Command<CMD_BUILD_TUNNEL>::Do(DC_AUTO, tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0, {});
VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
}
@@ -907,7 +908,7 @@ static void HandleStationPlacement(TileIndex start, TileIndex end)
auto proc = [=](bool test, StationID to_join) -> bool {
if (test) {
- return DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_RAIL_STATION)), CMD_BUILD_RAIL_STATION, ta.tile, p1, p2).Succeeded();
+ return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), ta.tile, p1, p2, {}).Succeeded();
} else {
uint32 p2_final = p2;
if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 6fa8244e1..637b476d0 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -38,6 +38,8 @@
#include "company_gui.h"
#include "road_func.h"
#include "road_cmd.h"
+#include "landscape_cmd.h"
+#include "rail_cmd.h"
#include "table/strings.h"
#include "table/roadtypes.h"
@@ -367,7 +369,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
if (!IsTileType(tile, MP_ROAD)) {
/* If it's the last roadtype, just clear the whole tile */
- if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
CommandCost cost(EXPENSES_CONSTRUCTION);
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
@@ -822,7 +824,7 @@ do_clear:;
}
if (need_to_clear) {
- CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
}
@@ -868,7 +870,7 @@ do_clear:;
if (HasPowerOnRoad(rt, existing_rt)) {
rt = existing_rt;
} else if (HasPowerOnRoad(existing_rt, rt)) {
- CommandCost ret = DoCommand(flags, CMD_CONVERT_ROAD, tile, tile, rt);
+ CommandCost ret = Command<CMD_CONVERT_ROAD>::Do(flags, tile, tile, rt, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
} else {
@@ -1039,7 +1041,7 @@ CommandCost CmdBuildLongRoad(DoCommandFlag flags, TileIndex start_tile, uint32 p
if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
}
- CommandCost ret = DoCommand(flags, CMD_BUILD_ROAD, tile, drd << 11 | rt << 4 | bits, 0);
+ CommandCost ret = Command<CMD_BUILD_ROAD>::Do(flags, tile, drd << 11 | rt << 4 | bits, 0, {});
if (ret.Failed()) {
last_error = ret;
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
@@ -1130,7 +1132,7 @@ CommandCost CmdRemoveLongRoad(DoCommandFlag flags, TileIndex start_tile, uint32
if (flags & DC_EXEC) {
money_spent += ret.GetCost();
if (money_spent > 0 && money_spent > money_available) {
- _additional_cash_required = DoCommand(flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD, start_tile, end_tile, p2).GetCost();
+ _additional_cash_required = Command<CMD_REMOVE_LONG_ROAD>::Do(flags & ~DC_EXEC, start_tile, end_tile, p2, {}).GetCost();
return cost;
}
RemoveRoad(tile, flags, bits, rtt, true, false);
@@ -1181,7 +1183,7 @@ CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, uint32 p1, ui
cost.AddCost(_price[PR_BUILD_FOUNDATION]);
}
- cost.AddCost(DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0));
+ cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {}));
if (cost.Failed()) return cost;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
@@ -1267,7 +1269,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
}
if (flags & DC_EXEC) {
- DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
return ret;
}
@@ -2195,7 +2197,7 @@ static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owne
if (IsRoadDepot(tile)) {
if (GetTileOwner(tile) == old_owner) {
if (new_owner == INVALID_OWNER) {
- DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile, 0, 0, {});
} else {
/* A road depot has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
RoadType rt = GetRoadTypeRoad(tile);
@@ -2232,7 +2234,7 @@ static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owne
if (IsLevelCrossing(tile)) {
if (GetTileOwner(tile) == old_owner) {
if (new_owner == INVALID_OWNER) {
- DoCommand(DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL, tile, 0, GetCrossingRailTrack(tile));
+ Command<CMD_REMOVE_SINGLE_RAIL>::Do(DC_EXEC | DC_BANKRUPT, tile, 0, GetCrossingRailTrack(tile), {});
} else {
/* Update infrastructure counts. No need to dirty windows here, we'll redraw the whole screen anyway. */
Company::Get(old_owner)->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR;
@@ -2281,7 +2283,7 @@ static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, int z
}
}
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
/** Update power of road vehicle under which is the roadtype being converted */
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index 00ea29042..145934ffc 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -32,6 +32,7 @@
#include "core/geometry_func.hpp"
#include "date_func.h"
#include "station_cmd.h"
+#include "tunnelbridge_cmd.h"
#include "widgets/road_widget.h"
@@ -199,7 +200,7 @@ static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, S
auto proc = [=](bool test, StationID to_join) -> bool {
if (test) {
- return DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_ROAD_STOP)), CMD_BUILD_ROAD_STOP, ta.tile, p1, p2).Succeeded();
+ return Command<CMD_BUILD_ROAD_STOP>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_ROAD_STOP>()), ta.tile, p1, p2, {}).Succeeded();
} else {
uint32 p2_final = p2;
if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join);
@@ -722,7 +723,7 @@ struct BuildRoadToolbarWindow : Window {
void OnPlacePresize(Point pt, TileIndex tile) override
{
- DoCommand(DC_AUTO, CMD_BUILD_TUNNEL, tile, _cur_roadtype | (TRANSPORT_ROAD << 8), 0);
+ Command<CMD_BUILD_TUNNEL>::Do(DC_AUTO, tile, _cur_roadtype | (TRANSPORT_ROAD << 8), 0, {});
VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 4c8381403..efe45c507 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -35,6 +35,7 @@
#include "zoom_func.h"
#include "framerate_type.h"
#include "roadveh_cmd.h"
+#include "road_cmd.h"
#include "table/strings.h"
@@ -1134,7 +1135,7 @@ static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadType rt, RoadB
/* The 'current' company is not necessarily the owner of the vehicle. */
Backup<CompanyID> cur_company(_current_company, c, FILE_LINE);
- CommandCost ret = DoCommand(DC_NO_WATER, CMD_BUILD_ROAD, t, rt << 4 | r, 0);
+ CommandCost ret = Command<CMD_BUILD_ROAD>::Do(DC_NO_WATER, t, rt << 4 | r, 0, {});
cur_company.Restore();
return ret.Succeeded();
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index 720e922f1..56fdde826 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -9,13 +9,13 @@
#include "../../stdafx.h"
#include "../../script/squirrel.hpp"
-#include "../../command_func.h"
#include "../../company_func.h"
#include "../../company_base.h"
#include "../../network/network.h"
#include "../../genworld.h"
#include "../../string_func.h"
#include "../../strings_func.h"
+#include "../../command_func.h"
#include "../script_storage.hpp"
#include "../script_instance.hpp"
diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp
index 9e2a56e92..a06261618 100644
--- a/src/script/api/script_vehicle.cpp
+++ b/src/script/api/script_vehicle.cpp
@@ -20,6 +20,7 @@
#include "../../train.h"
#include "../../vehicle_func.h"
#include "../../aircraft.h"
+#include "../../vehicle_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -91,7 +92,7 @@
if (!ScriptEngine::IsBuildable(engine_id)) return -1;
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
- CommandCost res = ::DoCommand(DC_QUERY_COST, CMD_BUILD_VEHICLE, depot, engine_id | (cargo << 24), 0);
+ CommandCost res = ::Command<CMD_BUILD_VEHICLE>::Do(DC_QUERY_COST, depot, engine_id | (cargo << 24), 0, {});
return res.Succeeded() ? _returned_refit_capacity : -1;
}
@@ -140,7 +141,7 @@
if (!IsValidVehicle(vehicle_id)) return -1;
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
- CommandCost res = ::DoCommand(DC_QUERY_COST, CMD_REFIT_VEHICLE, 0, vehicle_id, cargo);
+ CommandCost res = ::Command<CMD_REFIT_VEHICLE>::Do(DC_QUERY_COST, 0, vehicle_id, cargo, {});
return res.Succeeded() ? _returned_refit_capacity : -1;
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index f53523bc3..33f86146c 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -58,6 +58,8 @@
#include "tunnelbridge_map.h"
#include "station_cmd.h"
#include "waypoint_cmd.h"
+#include "landscape_cmd.h"
+#include "rail_cmd.h"
#include "table/strings.h"
@@ -843,7 +845,7 @@ static CommandCost CheckFlatLandAirport(AirportTileTableIterator tile_iter, DoCo
if (ret.Failed()) return ret;
cost.AddCost(ret);
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_iter, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_iter, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
}
@@ -923,14 +925,14 @@ static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag fl
affected_vehicles.push_back(v);
}
}
- CommandCost ret = DoCommand(flags, CMD_REMOVE_SINGLE_RAIL, tile_cur, 0, track);
+ CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile_cur, 0, track, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
continue;
}
}
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_cur, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
}
@@ -1048,7 +1050,7 @@ static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags
cost.AddCost(RoadBuildCost(rt) * 2);
}
} else {
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, cur_tile, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, cur_tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(RoadBuildCost(rt) * 2);
@@ -1754,7 +1756,7 @@ static CommandCost RemoveRailStation(TileIndex tile, DoCommandFlag flags)
{
/* if there is flooding, remove platforms tile by tile */
if (_current_company == OWNER_WATER) {
- return DoCommand(DC_EXEC, CMD_REMOVE_FROM_RAIL_STATION, tile, 0, 0);
+ return Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(DC_EXEC, tile, 0, 0, {});
}
Station *st = Station::GetByTile(tile);
@@ -1775,7 +1777,7 @@ static CommandCost RemoveRailWaypoint(TileIndex tile, DoCommandFlag flags)
{
/* if there is flooding, remove waypoints tile by tile */
if (_current_company == OWNER_WATER) {
- return DoCommand(DC_EXEC, CMD_REMOVE_FROM_RAIL_WAYPOINT, tile, 0, 0);
+ return Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(DC_EXEC, tile, 0, 0, {});
}
return RemoveRailStation(Waypoint::GetByTile(tile), flags, _price[PR_CLEAR_WAYPOINT_RAIL]);
@@ -2537,7 +2539,7 @@ CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]);
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
@@ -2552,7 +2554,7 @@ CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
/* Get the water class of the water tile before it is cleared.*/
WaterClass wc = GetWaterClass(tile_cur);
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_cur, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur, 0, 0, {});
if (ret.Failed()) return ret;
tile_cur += TileOffsByDiagDir(direction);
@@ -4242,12 +4244,12 @@ static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_o
} else {
if (IsDriveThroughStopTile(tile)) {
/* Remove the drive-through road stop */
- DoCommand(DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP, tile, 1 | 1 << 8, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS);
+ Command<CMD_REMOVE_ROAD_STOP>::Do(DC_EXEC | DC_BANKRUPT, tile, 1 | 1 << 8, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, {});
assert(IsTileType(tile, MP_ROAD));
/* Change owner of tile and all roadtypes */
ChangeTileOwner(tile, old_owner, new_owner);
} else {
- DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile, 0, 0, {});
/* Set tile owner of water under (now removed) buoy and dock to OWNER_NONE.
* Update owner of buoy if it was not removed (was in orders).
* Do not update when owned by OWNER_WATER (sea and rivers). */
@@ -4364,7 +4366,7 @@ static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlag flags, in
}
}
}
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
/**
diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp
index 17da36ecc..df178e3ab 100644
--- a/src/terraform_cmd.cpp
+++ b/src/terraform_cmd.cpp
@@ -18,6 +18,7 @@
#include "company_func.h"
#include "core/backup_type.hpp"
#include "terraform_cmd.h"
+#include "landscape_cmd.h"
#include "table/strings.h"
@@ -290,7 +291,7 @@ CommandCost CmdTerraformLand(DoCommandFlag flags, TileIndex tile, uint32 p1, uin
}
CommandCost cost;
if (indirectly_cleared) {
- cost = DoCommand(tile_flags, CMD_LANDSCAPE_CLEAR, t, 0, 0);
+ cost = Command<CMD_LANDSCAPE_CLEAR>::Do(tile_flags, t, 0, 0, {});
} else {
cost = _tile_type_procs[GetTileType(t)]->terraform_tile_proc(t, tile_flags, z_min, tileh);
}
@@ -379,7 +380,7 @@ CommandCost CmdLevelLand(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
TileIndex t = *iter;
uint curh = TileHeight(t);
while (curh != h) {
- CommandCost ret = DoCommand(flags & ~DC_EXEC, CMD_TERRAFORM_LAND, t, SLOPE_N, (curh > h) ? 0 : 1);
+ CommandCost ret = Command<CMD_TERRAFORM_LAND>::Do(flags & ~DC_EXEC, t, SLOPE_N, (curh > h) ? 0 : 1, {});
if (ret.Failed()) {
last_error = ret;
@@ -395,7 +396,7 @@ CommandCost CmdLevelLand(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
delete iter;
return cost;
}
- DoCommand(flags, CMD_TERRAFORM_LAND, t, SLOPE_N, (curh > h) ? 0 : 1);
+ Command<CMD_TERRAFORM_LAND>::Do(flags, t, SLOPE_N, (curh > h) ? 0 : 1, {});
} else {
/* When we're at the terraform limit we better bail (unneeded) testing as well.
* This will probably cause the terraforming cost to be underestimated, but only
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index 498d057aa..71d897c3d 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -34,6 +34,7 @@
#include "terraform_cmd.h"
#include "zoom_func.h"
#include "rail_cmd.h"
+#include "landscape_cmd.h"
#include "widgets/terraform_widget.h"
@@ -513,7 +514,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
/* Delete all station signs */
for (BaseStation *st : BaseStation::Iterate()) {
/* There can be buoys, remove them */
- if (IsBuoyTile(st->xy)) DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, st->xy, 0, 0);
+ if (IsBuoyTile(st->xy)) Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, st->xy, 0, 0, {});
if (!st->IsInUse()) delete st;
}
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 2f961b9cb..8e87739d3 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -49,6 +49,10 @@
#include "ai/ai.hpp"
#include "game/game.hpp"
#include "town_cmd.h"
+#include "landscape_cmd.h"
+#include "road_cmd.h"
+#include "terraform_cmd.h"
+#include "tunnelbridge_cmd.h"
#include "table/strings.h"
#include "table/town_land.h"
@@ -939,8 +943,8 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
* If that fails clear the land, and if that fails exit.
* This is to make sure that we can build a road here later. */
RoadType rt = GetTownRoadType(t);
- if (DoCommand(DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0).Failed() &&
- DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Failed()) {
+ if (Command<CMD_BUILD_ROAD>::Do(DC_AUTO | DC_NO_WATER, tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0, {}).Failed() &&
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_WATER, tile, 0, 0, {}).Failed()) {
return false;
}
}
@@ -957,8 +961,8 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
CommandCost res = CMD_ERROR;
if (!_generating_world && Chance16(1, 10)) {
/* Note: Do not replace "^ SLOPE_ELEVATED" with ComplementSlope(). The slope might be steep. */
- res = DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND,
- tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0);
+ res = Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO | DC_NO_WATER,
+ tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0, {});
}
if (res.Failed() && Chance16(1, 3)) {
/* We can consider building on the slope, though. */
@@ -974,9 +978,9 @@ static bool TerraformTownTile(TileIndex tile, int edges, int dir)
{
assert(tile < MapSize());
- CommandCost r = DoCommand(DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND, tile, edges, dir);
+ CommandCost r = Command<CMD_TERRAFORM_LAND>::Do(DC_AUTO | DC_NO_WATER, tile, edges, dir, {});
if (r.Failed() || r.GetCost() >= (_price[PR_TERRAFORM] + 2) * 8) return false;
- DoCommand(DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND, tile, edges, dir);
+ Command<CMD_TERRAFORM_LAND>::Do(DC_AUTO | DC_NO_WATER | DC_EXEC, tile, edges, dir, {});
return true;
}
@@ -1108,7 +1112,7 @@ static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
{
RoadType rt = GetTownRoadType(t);
- if (DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, tile, rcmd | (rt << 4), t->index).Succeeded()) {
+ if (Command<CMD_BUILD_ROAD>::Do(DC_EXEC | DC_AUTO | DC_NO_WATER, tile, rcmd | (rt << 4), t->index, {}).Succeeded()) {
_grow_town_result = GROWTH_SUCCEED;
return true;
}
@@ -1155,7 +1159,7 @@ static bool CanRoadContinueIntoNextTile(const Town *t, const TileIndex tile, con
if (IsTileType(next_tile, MP_RAILWAY) && !_settings_game.economy.allow_town_level_crossings) return false;
/* If a road tile can be built, the construction is allowed. */
- return DoCommand(DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, next_tile, rcmd | (rt << 4), t->index).Succeeded();
+ return Command<CMD_BUILD_ROAD>::Do(DC_AUTO | DC_NO_WATER, next_tile, rcmd | (rt << 4), t->index, {}).Succeeded();
}
/**
@@ -1223,8 +1227,8 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi
/* Can we actually build the bridge? */
RoadType rt = GetTownRoadType(t);
- if (DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE, tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15).Succeeded()) {
- DoCommand(DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE, tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15);
+ if (Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()), tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, {}).Succeeded()) {
+ Command<CMD_BUILD_BRIDGE>::Do(DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()), tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, {});
_grow_town_result = GROWTH_SUCCEED;
return true;
}
@@ -1294,8 +1298,8 @@ static bool GrowTownWithTunnel(const Town *t, const TileIndex tile, const DiagDi
/* Attempt to build the tunnel. Return false if it fails to let the town build a road instead. */
RoadType rt = GetTownRoadType(t);
- if (DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL, tile, rt | (TRANSPORT_ROAD << 8), 0).Succeeded()) {
- DoCommand(DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL, tile, rt | (TRANSPORT_ROAD << 8), 0);
+ if (Command<CMD_BUILD_TUNNEL>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_TUNNEL>()), tile, rt | (TRANSPORT_ROAD << 8), 0, {}).Succeeded()) {
+ Command<CMD_BUILD_TUNNEL>::Do(DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_TUNNEL>()), tile, rt | (TRANSPORT_ROAD << 8), 0, {});
_grow_town_result = GROWTH_SUCCEED;
return true;
}
@@ -1733,9 +1737,9 @@ static bool GrowTown(Town *t)
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
/* Only work with plain land that not already has a house */
if (!IsTileType(tile, MP_HOUSE) && IsTileFlat(tile)) {
- if (DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded()) {
+ if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_WATER, tile, 0, 0, {}).Succeeded()) {
RoadType rt = GetTownRoadType(t);
- DoCommand(DC_EXEC | DC_AUTO, CMD_BUILD_ROAD, tile, GenRandomRoadBits() | (rt << 4), t->index);
+ Command<CMD_BUILD_ROAD>::Do(DC_EXEC | DC_AUTO, tile, GenRandomRoadBits() | (rt << 4), t->index, {});
cur_company.Restore();
return true;
}
@@ -2180,7 +2184,7 @@ static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size
if (t->cache.population > 0) return t;
Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
- [[maybe_unused]] CommandCost rc = DoCommand(DC_EXEC, CMD_DELETE_TOWN, t->xy, t->index, 0);
+ [[maybe_unused]] CommandCost rc = Command<CMD_DELETE_TOWN>::Do(DC_EXEC, t->xy, t->index, 0, {});
cur_company.Restore();
assert(rc.Succeeded());
@@ -2281,7 +2285,7 @@ HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
*/
static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
{
- [[maybe_unused]] CommandCost cc = DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ [[maybe_unused]] CommandCost cc = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_AUTO | DC_NO_WATER, tile, 0, 0, {});
assert(cc.Succeeded());
IncreaseBuildingCount(t, type);
@@ -2338,7 +2342,7 @@ static inline bool CanBuildHouseHere(TileIndex tile, bool noslope)
if (IsBridgeAbove(tile)) return false;
/* can we clear the land? */
- return DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded();
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_WATER, tile, 0, 0, {}).Succeeded();
}
@@ -2973,7 +2977,7 @@ CommandCost CmdDeleteTown(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
/* Non-oil rig stations are always a problem. */
if (!(st->facilities & FACIL_AIRPORT) || st->airport.type != AT_OILRIG) return CMD_ERROR;
/* We can only automatically delete oil rigs *if* there's no vehicle on them. */
- CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, st->airport.tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, st->airport.tile, 0, 0, {});
if (ret.Failed()) return ret;
}
}
@@ -2989,7 +2993,7 @@ CommandCost CmdDeleteTown(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
* tile was already deleted earlier in the loop. */
for (TileIndex current_tile = 0; current_tile < MapSize(); ++current_tile) {
if (IsTileType(current_tile, MP_TUNNELBRIDGE) && TestTownOwnsBridge(current_tile, t)) {
- CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile, 0, 0, {});
if (ret.Failed()) return ret;
}
}
@@ -3032,7 +3036,7 @@ CommandCost CmdDeleteTown(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
break;
}
if (try_clear) {
- CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile, 0, 0, {});
if (ret.Failed()) return ret;
}
}
@@ -3108,7 +3112,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
static bool TryClearTile(TileIndex tile)
{
Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
- CommandCost r = DoCommand(DC_NONE, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ CommandCost r = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_NONE, tile, 0, 0, {});
cur_company.Restore();
return r.Succeeded();
}
@@ -3180,7 +3184,7 @@ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags)
if (flags & DC_EXEC) {
Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
- DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, statue_data.best_position, 0, 0);
+ Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, statue_data.best_position, 0, 0, {});
cur_company.Restore();
BuildObject(OBJECT_STATUE, statue_data.best_position, _current_company, t);
SetBit(t->statues, _current_company); // Once found and built, "inform" the Town.
@@ -3787,7 +3791,7 @@ static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, int z
}
}
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
/** Tile callback functions for a town */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 5a36d0d86..b060ecdba 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -655,7 +655,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlag flags, TileIndex tile, const
w->engine_type == e->index && ///< Same type
w->First() != v && ///< Don't connect to ourself
!(w->vehstatus & VS_CRASHED)) { ///< Not crashed/flooded
- if (DoCommand(DC_EXEC, CMD_MOVE_RAIL_VEHICLE, 0, v->index | 1 << 20, w->Last()->index).Succeeded()) {
+ if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DC_EXEC, 0, v->index | 1 << 20, w->Last()->index, {}).Succeeded()) {
break;
}
}
@@ -671,7 +671,7 @@ static void NormalizeTrainVehInDepot(const Train *u)
for (const Train *v : Train::Iterate()) {
if (v->IsFreeWagon() && v->tile == u->tile &&
v->track == TRACK_BIT_DEPOT) {
- if (DoCommand(DC_EXEC, CMD_MOVE_RAIL_VEHICLE, 0, v->index | 1 << 20, u->index).Failed()) {
+ if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DC_EXEC, 0, v->index | 1 << 20, u->index, {}).Failed()) {
break;
}
}
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index ab439cd58..79eaa0421 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -24,6 +24,7 @@
#include "newgrf_generic.h"
#include "date_func.h"
#include "tree_cmd.h"
+#include "landscape_cmd.h"
#include "table/strings.h"
#include "table/tree_land.h"
@@ -461,7 +462,7 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
switch (GetRawClearGround(current_tile)) {
case CLEAR_FIELDS:
case CLEAR_ROCKS: {
- CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
break;
@@ -882,7 +883,7 @@ void InitializeTrees()
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
{
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 07fcd4446..85c611ae5 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -41,6 +41,8 @@
#include "company_gui.h"
#include "station_func.h"
#include "tunnelbridge_cmd.h"
+#include "landscape_cmd.h"
+#include "terraform_cmd.h"
#include "table/strings.h"
#include "table/bridge_land.h"
@@ -419,7 +421,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex end_tile, uint32 p1, u
bool allow_on_slopes = (_settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER);
/* Try and clear the start landscape */
- CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_start, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_start, 0, 0, {});
if (ret.Failed()) return ret;
cost = ret;
@@ -427,7 +429,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex end_tile, uint32 p1, u
cost.AddCost(terraform_cost_north);
/* Try and clear the end landscape */
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_end, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_end, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
@@ -499,7 +501,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex end_tile, uint32 p1, u
default:
not_valid_below:;
/* try and clear the middle landscape */
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
break;
@@ -673,7 +675,7 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, uint32 p1,
if (HasTileWaterGround(start_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
- CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, start_tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, start_tile, 0, 0, {});
if (ret.Failed()) return ret;
/* XXX - do NOT change 'ret' in the loop, as it is used as the price
@@ -733,7 +735,7 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, uint32 p1,
if (HasTileWaterGround(end_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
/* Clear the tile in any case */
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, end_tile, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, end_tile, 0, 0, {});
if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
cost.AddCost(ret);
@@ -765,7 +767,7 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, uint32 p1,
assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself
coa = nullptr;
- ret = DoCommand(flags, CMD_TERRAFORM_LAND, end_tile, end_tileh & start_tileh, 0);
+ ret = Command<CMD_TERRAFORM_LAND>::Do(flags, end_tile, end_tileh & start_tileh, 0, {});
_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
cost.AddCost(ret);
@@ -1847,7 +1849,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner
if (tt == TRANSPORT_RAIL) {
/* Since all of our vehicles have been removed, it is safe to remove the rail
* bridge / tunnel. */
- [[maybe_unused]] CommandCost ret = DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ [[maybe_unused]] CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile, 0, 0, {});
assert(ret.Succeeded());
} else {
/* In any other case, we can safely reassign the ownership to OWNER_NONE. */
@@ -2038,7 +2040,7 @@ static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlag flag
if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
}
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
}
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 82170ed4c..f09edc909 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -51,6 +51,10 @@
#include "linkgraph/linkgraph.h"
#include "linkgraph/refresh.h"
#include "framerate_type.h"
+#include "autoreplace_cmd.h"
+#include "misc_cmd.h"
+#include "train_cmd.h"
+#include "vehicle_cmd.h"
#include "table/strings.h"
@@ -307,7 +311,7 @@ void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRF
SetDParamStr(0, grfconfig->GetName());
SetDParam(1, engine);
ShowErrorMessage(part1, part2, WL_CRITICAL);
- if (!_networking) DoCommand(DC_EXEC, CMD_PAUSE, 0, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, 1);
+ if (!_networking) Command<CMD_PAUSE>::Do(DC_EXEC, 0, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, 1, {});
}
/* debug output */
@@ -1055,7 +1059,7 @@ void CallVehicleTicks()
const Company *c = Company::Get(_current_company);
SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, (Money)c->settings.engine_renew_money));
- CommandCost res = DoCommand(DC_EXEC, CMD_AUTOREPLACE_VEHICLE, 0, v->index, 0);
+ CommandCost res = Command<CMD_AUTOREPLACE_VEHICLE>::Do(DC_EXEC, 0, v->index, 0, {});
SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, -(Money)c->settings.engine_renew_money));
if (!IsLocalCompany()) continue;
@@ -1561,7 +1565,7 @@ void VehicleEnterDepot(Vehicle *v)
if (v->current_order.IsRefit()) {
Backup<CompanyID> cur_company(_current_company, v->owner, FILE_LINE);
- CommandCost cost = DoCommand(DC_EXEC, CMD_REFIT_VEHICLE, v->tile, v->index, v->current_order.GetRefitCargo() | 0xFF << 8);
+ CommandCost cost = Command<CMD_REFIT_VEHICLE>::Do(DC_EXEC, v->tile, v->index, v->current_order.GetRefitCargo() | 0xFF << 8, {});
cur_company.Restore();
if (cost.Failed()) {
@@ -2443,7 +2447,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
/* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */
if (this->type == VEH_TRAIN && (reverse ^ HasBit(Train::From(this)->flags, VRF_REVERSING))) {
- DoCommand(DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION, this->tile, this->index, 0);
+ Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DC_EXEC, this->tile, this->index, 0, {});
}
if (this->type == VEH_AIRCRAFT) {
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index fe400bdab..aeaefe68f 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -32,6 +32,9 @@
#include "core/random_func.hpp"
#include "vehicle_cmd.h"
#include "aircraft_cmd.h"
+#include "autoreplace_cmd.h"
+#include "group_cmd.h"
+#include "order_cmd.h"
#include "roadveh_cmd.h"
#include "train_cmd.h"
#include "ship_cmd.h"
@@ -180,7 +183,7 @@ CommandCost CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
/* If we are not in DC_EXEC undo everything */
if (flags != subflags) {
- DoCommand(DC_EXEC, CMD_SELL_VEHICLE, 0, v->index, 0);
+ Command<CMD_SELL_VEHICLE>::Do(DC_EXEC, 0, v->index, 0, {});
}
}
@@ -661,7 +664,7 @@ CommandCost CmdMassStartStopVehicle(DoCommandFlag flags, TileIndex tile, uint32
if (!vehicle_list_window && !v->IsChainInDepot()) continue;
/* Just try and don't care if some vehicle's can't be stopped. */
- DoCommand(flags, CMD_START_STOP_VEHICLE, tile, v->index, 0);
+ Command<CMD_START_STOP_VEHICLE>::Do(flags, tile, v->index, 0, {});
}
return CommandCost();
@@ -691,7 +694,7 @@ CommandCost CmdDepotSellAllVehicles(DoCommandFlag flags, TileIndex tile, uint32
CommandCost last_error = CMD_ERROR;
bool had_success = false;
for (uint i = 0; i < list.size(); i++) {
- CommandCost ret = DoCommand(flags, CMD_SELL_VEHICLE, tile, list[i]->index | (1 << 20), 0);
+ CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(flags, tile, list[i]->index | (1 << 20), 0, {});
if (ret.Succeeded()) {
cost.AddCost(ret);
had_success = true;
@@ -730,7 +733,7 @@ CommandCost CmdDepotMassAutoReplace(DoCommandFlag flags, TileIndex tile, uint32
/* Ensure that the vehicle completely in the depot */
if (!v->IsChainInDepot()) continue;
- CommandCost ret = DoCommand(flags, CMD_AUTOREPLACE_VEHICLE, 0, v->index, 0);
+ CommandCost ret = Command<CMD_AUTOREPLACE_VEHICLE>::Do(flags, 0, v->index, 0, {});
if (ret.Succeeded()) cost.AddCost(ret);
}
@@ -869,11 +872,11 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
DoCommandFlag build_flags = flags;
if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
- CommandCost cost = DoCommand(build_flags, CMD_BUILD_VEHICLE, tile, v->engine_type | (1 << 16) | (CT_INVALID << 24), 0);
+ CommandCost cost = Command<CMD_BUILD_VEHICLE>::Do(build_flags, tile, v->engine_type | (1 << 16) | (CT_INVALID << 24), 0, {});
if (cost.Failed()) {
/* Can't build a part, then sell the stuff we already made; clear up the mess */
- if (w_front != nullptr) DoCommand(flags, CMD_SELL_VEHICLE, w_front->tile, w_front->index | (1 << 20), 0);
+ if (w_front != nullptr) Command<CMD_SELL_VEHICLE>::Do(flags, w_front->tile, w_front->index | (1 << 20), 0, {});
return cost;
}
@@ -889,12 +892,12 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
if (v->type == VEH_TRAIN && !v->IsFrontEngine()) {
/* this s a train car
* add this unit to the end of the train */
- CommandCost result = DoCommand(flags, CMD_MOVE_RAIL_VEHICLE, 0, w->index | 1 << 20, w_rear->index);
+ CommandCost result = Command<CMD_MOVE_RAIL_VEHICLE>::Do(flags, 0, w->index | 1 << 20, w_rear->index, {});
if (result.Failed()) {
/* The train can't be joined to make the same consist as the original.
* Sell what we already made (clean up) and return an error. */
- DoCommand(flags, CMD_SELL_VEHICLE, w_front->tile, w_front->index | 1 << 20, 0);
- DoCommand(flags, CMD_SELL_VEHICLE, w_front->tile, w->index | 1 << 20, 0);
+ Command<CMD_SELL_VEHICLE>::Do(flags, w_front->tile, w_front->index | 1 << 20, 0, {});
+ Command<CMD_SELL_VEHICLE>::Do(flags, w_front->tile, w->index | 1 << 20, 0, {});
return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
}
} else {
@@ -915,7 +918,7 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
if (flags & DC_EXEC) {
/* Cloned vehicles belong to the same group */
- DoCommand(flags, CMD_ADD_VEHICLE_GROUP, 0, v_front->group_id, w_front->index);
+ Command<CMD_ADD_VEHICLE_GROUP>::Do(flags, 0, v_front->group_id, w_front->index, {});
}
@@ -937,7 +940,7 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
/* Find out what's the best sub type */
byte subtype = GetBestFittingSubType(v, w, v->cargo_type);
if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
- CommandCost cost = DoCommand(flags, CMD_REFIT_VEHICLE, 0, w->index, v->cargo_type | 1U << 25 | (subtype << 8));
+ CommandCost cost = Command<CMD_REFIT_VEHICLE>::Do(flags, 0, w->index, v->cargo_type | 1U << 25 | (subtype << 8), {});
if (cost.Succeeded()) total_cost.AddCost(cost);
}
@@ -972,10 +975,10 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
* the vehicle refitted before doing this, otherwise the moved
* cargo types might not match (passenger vs non-passenger)
*/
- CommandCost result = DoCommand(flags, CMD_CLONE_ORDER, 0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index);
+ CommandCost result = Command<CMD_CLONE_ORDER>::Do(flags, 0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index, {});
if (result.Failed()) {
/* The vehicle has already been bought, so now it must be sold again. */
- DoCommand(flags, CMD_SELL_VEHICLE, w_front->tile, w_front->index | 1 << 20, 0);
+ Command<CMD_SELL_VEHICLE>::Do(flags, w_front->tile, w_front->index | 1 << 20, 0, {});
return result;
}
@@ -986,7 +989,7 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
* check whether the company has enough money manually. */
if (!CheckCompanyHasMoney(total_cost)) {
/* The vehicle has already been bought, so now it must be sold again. */
- DoCommand(flags, CMD_SELL_VEHICLE, w_front->tile, w_front->index | 1 << 20, 0);
+ Command<CMD_SELL_VEHICLE>::Do(flags, w_front->tile, w_front->index | 1 << 20, 0, {});
return total_cost;
}
}
@@ -1011,7 +1014,7 @@ static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, con
bool had_success = false;
for (uint i = 0; i < list.size(); i++) {
const Vehicle *v = list[i];
- CommandCost ret = DoCommand(flags, CMD_SEND_VEHICLE_TO_DEPOT, v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0);
+ CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(flags, v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, {});
if (ret.Succeeded()) {
had_success = true;
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index cac1985b9..d5d6978cc 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -37,6 +37,7 @@
#include "tilehighlight_func.h"
#include "zoom_func.h"
#include "depot_cmd.h"
+#include "vehicle_cmd.h"
#include "safeguards.h"
@@ -773,8 +774,8 @@ struct RefitWindow : public Window {
{
assert(_current_company == _local_company);
Vehicle *v = Vehicle::Get(this->window_number);
- CommandCost cost = DoCommand(DC_QUERY_COST, CMD_REFIT_VEHICLE, v->tile, this->selected_vehicle, option->cargo |
- option->subtype << 8 | this->num_vehicles << 16 | (int)this->auto_refit << 24);
+ CommandCost cost = Command<CMD_REFIT_VEHICLE>::Do(DC_QUERY_COST, v->tile, this->selected_vehicle, option->cargo |
+ option->subtype << 8 | this->num_vehicles << 16 | (int)this->auto_refit << 24, {});
if (cost.Failed()) return INVALID_STRING_ID;
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 6e357f9c6..07c13adcd 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -39,6 +39,7 @@
#include "newgrf_generic.h"
#include "industry.h"
#include "water_cmd.h"
+#include "landscape_cmd.h"
#include "table/strings.h"
@@ -123,13 +124,13 @@ CommandCost CmdBuildShipDepot(DoCommandFlag flags, TileIndex tile, uint32 p1, ui
CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
bool add_cost = !IsWaterTile(tile);
- CommandCost ret = DoCommand(flags | DC_AUTO, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DC_AUTO, tile, 0, 0, {});
if (ret.Failed()) return ret;
if (add_cost) {
cost.AddCost(ret);
}
add_cost = !IsWaterTile(tile2);
- ret = DoCommand(flags | DC_AUTO, CMD_LANDSCAPE_CLEAR, tile2, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DC_AUTO, tile2, 0, 0, {});
if (ret.Failed()) return ret;
if (add_cost) {
cost.AddCost(ret);
@@ -307,13 +308,13 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag
/* middle tile */
WaterClass wc_middle = HasTileWaterGround(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL;
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
/* lower tile */
if (!IsWaterTile(tile - delta)) {
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile - delta, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile - delta, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(_price[PR_BUILD_CANAL]);
@@ -325,7 +326,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag
/* upper tile */
if (!IsWaterTile(tile + delta)) {
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile + delta, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile + delta, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(_price[PR_BUILD_CANAL]);
@@ -481,7 +482,7 @@ CommandCost CmdBuildCanal(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
/* Outside the editor, prevent building canals over your own or OWNER_NONE owned canals */
if (water && IsCanal(current_tile) && _game_mode != GM_EDITOR && (IsTileOwner(current_tile, _current_company) || IsTileOwner(current_tile, OWNER_NONE))) continue;
- ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
+ ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile, 0, 0, {});
if (ret.Failed()) return ret;
if (!water) cost.AddCost(ret);
@@ -1136,7 +1137,7 @@ void DoFloodTile(TileIndex target)
FALLTHROUGH;
case MP_CLEAR:
- if (DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, target, 0, 0).Succeeded()) {
+ if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, target, 0, 0, {}).Succeeded()) {
MakeShore(target);
MarkTileDirtyByTile(target);
flooded = true;
@@ -1151,7 +1152,7 @@ void DoFloodTile(TileIndex target)
FloodVehicles(target);
/* flood flat tile */
- if (DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, target, 0, 0).Succeeded()) {
+ if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, target, 0, 0, {}).Succeeded()) {
MakeSea(target);
MarkTileDirtyByTile(target);
flooded = true;
@@ -1203,7 +1204,7 @@ static void DoDryUp(TileIndex tile)
case MP_WATER:
assert(IsCoast(tile));
- if (DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded()) {
+ if (Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, tile, 0, 0, {}).Succeeded()) {
MakeClear(tile, CLEAR_GRASS, 3);
MarkTileDirtyByTile(tile);
}
@@ -1362,7 +1363,7 @@ static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_own
}
/* Remove depot */
- if (IsShipDepot(tile)) DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ if (IsShipDepot(tile)) Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile, 0, 0, {});
/* Set owner of canals and locks ... and also canal under dock there was before.
* Check if the new owner after removing depot isn't OWNER_WATER. */
@@ -1382,7 +1383,7 @@ static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlag flags, int
/* Canals can't be terraformed */
if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
- return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ return Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, tile, 0, 0, {});
}
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index a95d5c954..a3edf71e8 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -29,6 +29,7 @@
#include "water.h"
#include "company_gui.h"
#include "waypoint_cmd.h"
+#include "landscape_cmd.h"
#include "table/strings.h"
@@ -316,7 +317,7 @@ CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
if (!IsWaterTile(tile)) {
- CommandCost ret = DoCommand(flags | DC_AUTO, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
+ CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DC_AUTO, tile, 0, 0, {});
if (ret.Failed()) return ret;
cost.AddCost(ret);
}