Changeset - r26102:502baaa2877d
[Not reviewed]
master
0 39 0
Michael Lutz - 2 years ago 2021-10-29 23:31:46
michi@icosahedron.de
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.
39 files changed with 320 insertions and 229 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -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(Aircraf
 
	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_HeliTak
 
	/* 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
 
	/* 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();
 
	}
 
}
src/airport_gui.cpp
Show inline comments
 
@@ -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);
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -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 BuildReplacementVehic
 
	}
 

	
 
	/* 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 BuildReplacementVehic
 
	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 BuildReplacementVehic
 
 */
 
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 CmdStartStopVe
 
 */
 
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 CopyHeadSpecificThing
 
	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(Vehic
 
		}
 

	
 
		/* 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 
 
					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 
 
					/* 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 
 
		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 
 
				}
 

	
 
				/* 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, {});
 
			}
 
		}
 
	}
src/bridge_gui.cpp
Show inline comments
 
@@ -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 sta
 
	/* 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()) {
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -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;
src/clear_cmd.cpp
Show inline comments
 
@@ -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(TileIn
 

	
 
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 = {
src/command.cpp
Show inline comments
 
@@ -164,64 +164,6 @@ bool IsCommandAllowedWhilePaused(Command
 
	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
src/command_func.h
Show inline comments
 
@@ -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 = Com
 
/** 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 */
src/command_type.h
Show inline comments
 
@@ -435,7 +435,8 @@ template <Commands Tcmd> struct CommandT
 

	
 
#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_); \
src/company_cmd.cpp
Show inline comments
 
@@ -1128,7 +1128,7 @@ CommandCost CmdRenamePresident(DoCommand
 
			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");
 
			}
 
		}
 

	
src/disaster_vehicle.cpp
Show inline comments
 
@@ -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(TileInde
 
		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(TileInde
 

	
 
		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;
 
		}
src/dock_gui.cpp
Show inline comments
 
@@ -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);
src/economy.cpp
Show inline comments
 
@@ -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
 
			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
 
			} 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
 
					 * 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 *
 
			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 *
 
		 * "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;
 
	}
 

	
src/group_cmd.cpp
Show inline comments
 
@@ -357,12 +357,12 @@ CommandCost CmdDeleteGroup(DoCommandFlag
 
	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(DoC
 

	
 
				/* 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(Do
 
				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);
 
			}
 
		}
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -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(TileIn
 
		_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 CheckIfIndustryTilesA
 

	
 
				/* 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 CheckIfCanLevelIndustryPlatf
 
			}
 
			/* 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 CheckIfCanLevelIndustryPlatf
 
				/* 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
 

	
 
			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_Industr
 
			}
 
		}
 
	}
 
	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 = {
src/landscape.cpp
Show inline comments
 
@@ -756,7 +756,7 @@ CommandCost CmdClearArea(DoCommandFlag f
 
	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 f
 
				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. */
src/misc_gui.cpp
Show inline comments
 
@@ -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) {
src/object_cmd.cpp
Show inline comments
 
@@ -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
 

	
 
	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
 
				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
 
						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
 
			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(
 
		}
 
	}
 

	
 
	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 = {
src/order_backup.cpp
Show inline comments
 
@@ -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, {});
 
}
 

	
 
/**
src/order_cmd.cpp
Show inline comments
 
@@ -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 O
 
					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);
src/rail_cmd.cpp
Show inline comments
 
@@ -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(DoCommand
 
			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(DoCommand
 

	
 
				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(DoCommand
 
			 * 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(DoCommand
 
			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(DoComman
 

	
 
			/* 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(Do
 
	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(DoCommand
 
		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(
 
		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(TileI
 
			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(TileIn
 

	
 
		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(T
 
			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, {});
 
}
 

	
 

	
src/rail_gui.cpp
Show inline comments
 
@@ -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 
 

	
 
		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(TileI
 

	
 
	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);
src/road_cmd.cpp
Show inline comments
 
@@ -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 
 

	
 
	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(DoCommandFl
 
			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(DoCommandF
 
				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(DoCommandF
 
		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(TileIn
 
			}
 

	
 
			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(TileInd
 
	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(TileInd
 
	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(Ti
 
		}
 
	}
 

	
 
	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 */
src/road_gui.cpp
Show inline comments
 
@@ -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 star
 

	
 
	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);
 
	}
 

	
src/roadveh_cmd.cpp
Show inline comments
 
@@ -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(Comp
 
	/* 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();
src/script/api/script_object.cpp
Show inline comments
 
@@ -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"
src/script/api/script_vehicle.cpp
Show inline comments
 
@@ -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;
 
}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -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(
 
		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 CheckFlatLandRailStat
 
							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
 
					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(Til
 
{
 
	/* 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(Ti
 
{
 
	/* 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 f
 
	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 f
 
	/* 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(Tile
 
	} 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
 
			}
 
		}
 
	}
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile, 0, 0, {});
 
}
 

	
 
/**
src/terraform_cmd.cpp
Show inline comments
 
@@ -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(DoCommandFl
 
			}
 
			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 f
 
		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 f
 
					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
src/terraform_gui.cpp
Show inline comments
 
@@ -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 ResetLandscapeConfirmationCa
 
		/* 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;
 
		}
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -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, T
 
		 * 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, T
 
			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 
 
{
 
	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 
 
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(
 
	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 Tow
 

	
 
		/* 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 Tow
 

	
 
	/* 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 attem
 
		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 
 
 */
 
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(Til
 
	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 
 
			/* 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 
 
	 * 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 
 
				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
 
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
 

	
 
	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(Ti
 
		}
 
	}
 

	
 
	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 */
src/train_cmd.cpp
Show inline comments
 
@@ -655,7 +655,7 @@ static CommandCost CmdBuildRailWagon(DoC
 
					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(con
 
	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;
 
			}
 
		}
src/tree_cmd.cpp
Show inline comments
 
@@ -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 f
 
					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, {});
 
}
 

	
 

	
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -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
 
		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
 
		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
 
				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
 

	
 
	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
 
	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
 
		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
 
		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_TunnelB
 
		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 = {
src/vehicle.cpp
Show inline comments
 
@@ -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 eng
 
		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(DoComma
 

	
 
		/* 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) {
src/vehicle_cmd.cpp
Show inline comments
 
@@ -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(DoCommandFla
 

	
 
		/* 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(DoCo
 
		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(DoCo
 
	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(DoCo
 
		/* 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(DoCommandFla
 
		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(DoCommandFla
 
			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(DoCommandFla
 

	
 
	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(DoCommandFla
 
				/* 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(DoCommandFla
 
		 * 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(DoCommandFla
 
		 * 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 SendAllVehiclesToDepo
 
	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;
src/vehicle_gui.cpp
Show inline comments
 
@@ -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;
 

	
src/water_cmd.cpp
Show inline comments
 
@@ -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(DoCommandF
 
	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
 

	
 
	/* 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
 

	
 
	/* 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 
 
		/* 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(TileIn
 
	}
 

	
 
	/* 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(T
 
	/* 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, {});
 
}
 

	
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -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 f
 

	
 
	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);
 
	}
0 comments (0 inline, 0 general)