Changeset - r26090:5a592dbf1c28
[Not reviewed]
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1271,13 +1271,13 @@ void HandleMissingAircraftOrders(Aircraf
 
	 *    go to a depot, we have to keep that order so the aircraft
 
	 *    actually stops.
 
	 */
 
	const Station *st = GetTargetAirportIfValid(v);
 
	if (st == nullptr) {
 
		Backup<CompanyID> cur_company(_current_company, v->owner, FILE_LINE);
 
		CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
 
		CommandCost ret = DoCommand(DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT, v->tile, v->index, 0);
 
		cur_company.Restore();
 

	
 
		if (ret.Failed()) CrashAirplane(v);
 
	} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		v->current_order.Free();
 
	}
 
@@ -1634,13 +1634,13 @@ static void AircraftEventHandler_HeliTak
 
	/* get the next position to go to, differs per airport */
 
	AircraftNextAirportPos_and_Order(v);
 

	
 
	/* Send the helicopter to a hangar if needed for replacement */
 
	if (v->NeedsAutomaticServicing()) {
 
		Backup<CompanyID> cur_company(_current_company, v->owner, FILE_LINE);
 
		DoCommand(v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
 
		DoCommand(DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT, v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0);
 
		cur_company.Restore();
 
	}
 
}
 

	
 
static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
 
{
 
@@ -1685,13 +1685,13 @@ static void AircraftEventHandler_Landing
 
	v->state = ENDLANDING;
 
	AircraftLandAirplane(v);  // maybe crash airplane
 

	
 
	/* 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(v->tile, v->index | DEPOT_SERVICE, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
 
		DoCommand(DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT, v->tile, v->index | DEPOT_SERVICE, 0);
 
		cur_company.Restore();
 
	}
 
}
 

	
 
static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)
 
{
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -337,29 +337,29 @@ static CommandCost BuildReplacementVehic
 

	
 
		AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_AUTORENEW_FAILED, old_veh->index);
 
		return CommandCost();
 
	}
 

	
 
	/* Build the new vehicle */
 
	cost = DoCommand(old_veh->tile, e | (CT_INVALID << 24), 0, DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_veh));
 
	cost = DoCommand(DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_veh), old_veh->tile, e | (CT_INVALID << 24), 0);
 
	if (cost.Failed()) return cost;
 

	
 
	Vehicle *new_veh = Vehicle::Get(_new_vehicle_id);
 
	*new_vehicle = new_veh;
 

	
 
	/* Refit the vehicle if needed */
 
	if (refit_cargo != CT_NO_REFIT) {
 
		byte subtype = GetBestFittingSubType(old_veh, new_veh, refit_cargo);
 

	
 
		cost.AddCost(DoCommand(0, new_veh->index, refit_cargo | (subtype << 8), DC_EXEC, GetCmdRefitVeh(new_veh)));
 
		cost.AddCost(DoCommand(DC_EXEC, GetCmdRefitVeh(new_veh), 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(0, new_veh->index, true, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 
		DoCommand(DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION, 0, new_veh->index, true);
 
	}
 

	
 
	return cost;
 
}
 

	
 
/**
 
@@ -367,26 +367,26 @@ static CommandCost BuildReplacementVehic
 
 * @param v a vehicle
 
 * @param evaluate_callback shall the start/stop callback be evaluated?
 
 * @return success or error
 
 */
 
static inline CommandCost CmdStartStopVehicle(const Vehicle *v, bool evaluate_callback)
 
{
 
	return DoCommand(0, v->index, evaluate_callback ? 1 : 0, DC_EXEC | DC_AUTOREPLACE, CMD_START_STOP_VEHICLE);
 
	return DoCommand(DC_EXEC | DC_AUTOREPLACE, CMD_START_STOP_VEHICLE, 0, v->index, evaluate_callback ? 1 : 0);
 
}
 

	
 
/**
 
 * Issue a train vehicle move command
 
 * @param v The vehicle to move
 
 * @param after The vehicle to insert 'v' after, or nullptr to start new chain
 
 * @param flags the command flags to use
 
 * @param whole_chain move all vehicles following 'v' (true), or only 'v' (false)
 
 * @return success or error
 
 */
 
static inline CommandCost CmdMoveVehicle(const Vehicle *v, const Vehicle *after, DoCommandFlag flags, bool whole_chain)
 
{
 
	return DoCommand(0, v->index | (whole_chain ? 1 : 0) << 20, after != nullptr ? after->index : INVALID_VEHICLE, flags | DC_NO_CARGO_CAP_CHECK, CMD_MOVE_RAIL_VEHICLE);
 
	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);
 
}
 

	
 
/**
 
 * Copy head specific things to the new vehicle chain after it was successfully constructed
 
 * @param old_head The old front vehicle (no wagons attached anymore)
 
 * @param new_head The new head of the completely replaced vehicle chain
 
@@ -394,16 +394,16 @@ static inline CommandCost CmdMoveVehicle
 
 */
 
static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head, DoCommandFlag flags)
 
{
 
	CommandCost cost = CommandCost();
 

	
 
	/* Share orders */
 
	if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(0, new_head->index | CO_SHARE << 30, old_head->index, DC_EXEC, CMD_CLONE_ORDER));
 
	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));
 

	
 
	/* Copy group membership */
 
	if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(0, old_head->group_id, new_head->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP));
 
	if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(DC_EXEC, CMD_ADD_VEHICLE_GROUP, 0, old_head->group_id, new_head->index));
 

	
 
	/* Perform start/stop check whether the new vehicle suits newgrf restrictions etc. */
 
	if (cost.Succeeded()) {
 
		/* Start the vehicle, might be denied by certain things */
 
		assert((new_head->vehstatus & VS_STOPPED) != 0);
 
		cost.AddCost(CmdStartStopVehicle(new_head, true));
 
@@ -463,17 +463,17 @@ static CommandCost ReplaceFreeUnit(Vehic
 
			*single_unit = new_v;
 

	
 
			AI::NewEvent(old_v->owner, new ScriptEventVehicleAutoReplaced(old_v->index, new_v->index));
 
		}
 

	
 
		/* Sell the old vehicle */
 
		cost.AddCost(DoCommand(0, old_v->index, 0, flags, GetCmdSellVeh(old_v)));
 
		cost.AddCost(DoCommand(flags, GetCmdSellVeh(old_v), 0, old_v->index, 0));
 

	
 
		/* If we are not in DC_EXEC undo everything */
 
		if ((flags & DC_EXEC) == 0) {
 
			DoCommand(0, new_v->index, 0, DC_EXEC, GetCmdSellVeh(new_v));
 
			DoCommand(DC_EXEC, GetCmdSellVeh(new_v), 0, new_v->index, 0);
 
		}
 
	}
 

	
 
	return cost;
 
}
 

	
 
@@ -594,13 +594,13 @@ static CommandCost ReplaceChain(Vehicle 
 
					if (wagon == nullptr) continue;
 
					if (wagon->First() == new_head) break;
 

	
 
					assert(RailVehInfo(wagon->engine_type)->railveh_type == RAILVEH_WAGON);
 

	
 
					/* Sell wagon */
 
					[[maybe_unused]] CommandCost ret = DoCommand(0, wagon->index, 0, DC_EXEC, GetCmdSellVeh(wagon));
 
					[[maybe_unused]] CommandCost ret = DoCommand(DC_EXEC, GetCmdSellVeh(wagon), 0, wagon->index, 0);
 
					assert(ret.Succeeded());
 
					new_vehs[i] = nullptr;
 

	
 
					/* Revert the money subtraction when the vehicle was built.
 
					 * This value is different from the sell value, esp. because of refitting */
 
					cost.AddCost(-new_costs[i]);
 
@@ -626,13 +626,13 @@ static CommandCost ReplaceChain(Vehicle 
 

	
 
					if ((flags & DC_EXEC) != 0) TransferCargo(w, new_head, true);
 

	
 
					/* 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(0, w->index, 0, flags | DC_AUTOREPLACE, GetCmdSellVeh(w)));
 
					cost.AddCost(DoCommand(flags | DC_AUTOREPLACE, GetCmdSellVeh(w), 0, w->index, 0));
 
					if ((flags & DC_EXEC) != 0) {
 
						old_vehs[i] = nullptr;
 
						if (i == 0) old_head = nullptr;
 
					}
 
				}
 

	
 
@@ -657,13 +657,13 @@ static CommandCost ReplaceChain(Vehicle 
 
		}
 

	
 
		/* Finally undo buying of new vehicles */
 
		if ((flags & DC_EXEC) == 0) {
 
			for (int i = num_units - 1; i >= 0; i--) {
 
				if (new_vehs[i] != nullptr) {
 
					DoCommand(0, new_vehs[i]->index, 0, DC_EXEC, GetCmdSellVeh(new_vehs[i]));
 
					DoCommand(DC_EXEC, GetCmdSellVeh(new_vehs[i]), 0, new_vehs[i]->index, 0);
 
					new_vehs[i] = nullptr;
 
				}
 
			}
 
		}
 

	
 
		free(old_vehs);
 
@@ -688,18 +688,18 @@ static CommandCost ReplaceChain(Vehicle 
 
					*chain = new_head;
 

	
 
					AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index));
 
				}
 

	
 
				/* Sell the old vehicle */
 
				cost.AddCost(DoCommand(0, old_head->index, 0, flags, GetCmdSellVeh(old_head)));
 
				cost.AddCost(DoCommand(flags, GetCmdSellVeh(old_head), 0, old_head->index, 0));
 
			}
 

	
 
			/* If we are not in DC_EXEC undo everything */
 
			if ((flags & DC_EXEC) == 0) {
 
				DoCommand(0, new_head->index, 0, DC_EXEC, GetCmdSellVeh(new_head));
 
				DoCommand(DC_EXEC, GetCmdSellVeh(new_head), 0, new_head->index, 0);
 
			}
 
		}
 
	}
 

	
 
	return cost;
 
}
src/bridge_gui.cpp
Show inline comments
 
@@ -387,13 +387,13 @@ void ShowBuildBridgeWindow(TileIndex sta
 
		return;
 
	}
 

	
 
	/* 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(end, start, type, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_QUERY_COST, CMD_BUILD_BRIDGE);
 
	CommandCost ret = DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_QUERY_COST, CMD_BUILD_BRIDGE, end, start, type);
 

	
 
	GUIBridgeList *bl = nullptr;
 
	if (ret.Failed()) {
 
		errmsg = ret.GetErrorMessage();
 
	} else {
 
		/* check which bridges can be built */
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -1223,13 +1223,13 @@ struct BuildVehicleWindow : Window {
 
			this->te.cargo = CT_INVALID;
 
			return;
 
		}
 

	
 
		if (!this->listview_mode) {
 
			/* Query for cost and refitted capacity */
 
			CommandCost ret = DoCommand(this->window_number, this->sel_engine | (cargo << 24), 0, DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type));
 
			CommandCost ret = DoCommand(DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type), 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;
 
				this->te.mail_capacity = _returned_mail_refit_capacity;
 
				this->te.cargo         = (cargo == CT_INVALID) ? e->GetDefaultCargoType() : cargo;
 
				return;
src/clear_cmd.cpp
Show inline comments
 
@@ -378,13 +378,13 @@ static void ChangeTileOwner_Clear(TileIn
 
{
 
	return;
 
}
 

	
 
static CommandCost TerraformTile_Clear(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 
{
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
extern const TileTypeProcs _tile_type_clear_procs = {
 
	DrawTile_Clear,           ///< draw_tile_proc
 
	GetSlopePixelZ_Clear,     ///< get_slope_z_proc
 
	ClearTile_Clear,          ///< clear_tile_proc
src/command.cpp
Show inline comments
 
@@ -446,29 +446,29 @@ static int _docommand_recursive = 0;
 
 * @param flags Flags for the command and how to execute the command
 
 * @see CommandProc
 
 * @return the cost
 
 */
 
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
 
{
 
	return DoCommand(container->tile, container->p1, container->p2, flags, container->cmd & CMD_ID_MASK, container->text);
 
	return DoCommand(flags, container->cmd & CMD_ID_MASK, container->tile, container->p1, container->p2, container->text);
 
}
 

	
 
/*!
 
 * 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 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 text The text to pass
 
 * @see CommandProc
 
 * @return the cost
 
 */
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const std::string &text)
 
CommandCost DoCommand(DoCommandFlag flags, uint32 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;
 

	
src/command_func.h
Show inline comments
 
@@ -29,13 +29,13 @@ static const CommandCost CMD_ERROR = Com
 
 * StringID which will be returned.
 
 *
 
 * @param errcode The StringID to return
 
 */
 
#define return_cmd_error(errcode) return CommandCost(errcode);
 

	
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const std::string &text = {});
 
CommandCost DoCommand(DoCommandFlag flags, uint32 cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text = {});
 
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
 

	
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = nullptr, const std::string &text = {}, bool my_cmd = true);
 
bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
 

	
 
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, bool my_cmd, bool estimate_only);
src/company_cmd.cpp
Show inline comments
 
@@ -1124,13 +1124,13 @@ CommandCost CmdRenamePresident(TileIndex
 
		if (reset) {
 
			c->president_name.clear();
 
		} else {
 
			c->president_name = text;
 

	
 
			if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) {
 
				DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, text + " Transport");
 
				DoCommand(DC_EXEC, CMD_RENAME_COMPANY, 0, 0, 0, text + " Transport");
 
			}
 
		}
 

	
 
		MarkWholeScreenDirty();
 
		CompanyAdminUpdate(c);
 
	}
src/disaster_vehicle.cpp
Show inline comments
 
@@ -58,23 +58,23 @@ static void DisasterClearSquare(TileInde
 
	if (EnsureNoVehicleOnGround(tile).Failed()) return;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if (Company::IsHumanID(GetTileOwner(tile)) && !IsRailDepot(tile)) {
 
				Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
 
				DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
				cur_company.Restore();
 

	
 
				/* update signals in buffer */
 
				UpdateSignalsInBuffer();
 
			}
 
			break;
 

	
 
		case MP_HOUSE: {
 
			Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
			DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
			cur_company.Restore();
 
			break;
 
		}
 

	
 
		case MP_TREES:
 
		case MP_CLEAR:
src/economy.cpp
Show inline comments
 
@@ -309,13 +309,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 

	
 
		/* See if the old_owner had shares in other companies */
 
		for (const Company *c : Company::Iterate()) {
 
			for (i = 0; i < 4; i++) {
 
				if (c->share_owners[i] == old_owner) {
 
					/* Sell its shares */
 
					CommandCost res = DoCommand(0, c->index, 0, DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY);
 
					CommandCost res = DoCommand(DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY, 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);
 
				}
 
			}
 
		}
 
@@ -329,13 +329,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
			if (c->bankrupt_value == 0 && c->share_owners[i] == new_owner) {
 
				/* You are the one buying the company; so don't sell the shares back to you. */
 
				Company::Get(new_owner)->share_owners[i] = INVALID_OWNER;
 
			} else {
 
				cur_company2.Change(c->share_owners[i]);
 
				/* Sell the shares */
 
				CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY);
 
				CommandCost res = DoCommand(DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY, 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);
 
			}
 
		}
 
		cur_company2.Restore();
 
@@ -445,13 +445,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
					Company *new_company = Company::Get(new_owner);
 

	
 
					/* Technically, passing the interval is not needed as the command will query the default value itself.
 
					 * However, do not rely on that behaviour.
 
					 */
 
					int interval = CompanyServiceInterval(new_company, v->type);
 
					DoCommand(v->tile, v->index, interval | (new_company->settings.vehicle.servint_ispercent << 17), DC_EXEC | DC_BANKRUPT, CMD_CHANGE_SERVICE_INT);
 
					DoCommand(DC_EXEC | DC_BANKRUPT, CMD_CHANGE_SERVICE_INT, v->tile, v->index, interval | (new_company->settings.vehicle.servint_ispercent << 17));
 
				}
 

	
 
				v->owner = new_owner;
 

	
 
				/* Owner changes, clear cache */
 
				v->colourmap = PAL_NONE;
 
@@ -1482,13 +1482,13 @@ static void HandleStationRefit(Vehicle *
 
		/* Get a refittable cargo type with waiting cargo for next_station or INVALID_STATION. */
 
		new_cid = v_start->cargo_type;
 
		for (CargoID cid : SetCargoBitIterator(refit_mask)) {
 
			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(v_start->tile, v_start->index, cid | 1U << 24 | 0xFF << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
				DoCommand(DC_QUERY_COST, GetCmdRefitVeh(v_start), 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
 
				 * are equal refit to the cargo of which most is available. This is important for
 
				 * consists of only a single vehicle as those will generally have a consist_capleft
 
				 * of 0 for all cargoes. */
 
@@ -1505,13 +1505,13 @@ static void HandleStationRefit(Vehicle *
 
	if (new_cid < NUM_CARGO && new_cid != v_start->cargo_type) {
 
		/* INVALID_STATION because in the DT_MANUAL case that's correct and in the DT_(A)SYMMETRIC
 
		 * cases the next hop of the vehicle doesn't really tell us anything if the cargo had been
 
		 * "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(v_start->tile, v_start->index, new_cid | 1U << 24 | 0xFF << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
 
		CommandCost cost = DoCommand(DC_EXEC, GetCmdRefitVeh(v_start), 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;
 
	}
 

	
 
	/* Add new capacity to consist capacity and reserve cargo */
 
	IterateVehicleParts(v_start, FinalizeRefitAction(consist_capleft, st, next_station,
 
			is_auto_refit || (v->First()->current_order.GetLoadType() & OLFB_FULL_LOAD) != 0));
src/group_cmd.cpp
Show inline comments
 
@@ -353,18 +353,18 @@ CommandCost CmdCreateGroup(TileIndex til
 
CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Group *g = Group::GetIfValid(p1);
 
	if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
 

	
 
	/* Remove all vehicles from the group */
 
	DoCommand(0, p1, 0, flags, CMD_REMOVE_ALL_VEHICLES_GROUP);
 
	DoCommand(flags, CMD_REMOVE_ALL_VEHICLES_GROUP, 0, p1, 0);
 

	
 
	/* Delete sub-groups */
 
	for (const Group *gp : Group::Iterate()) {
 
		if (gp->parent == g->index) {
 
			DoCommand(0, gp->index, 0, flags, CMD_DELETE_GROUP);
 
			DoCommand(flags, CMD_DELETE_GROUP, 0, gp->index, 0);
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Update backupped orders if needed */
 
		OrderBackup::ClearGroup(g->index);
 
@@ -577,13 +577,13 @@ CommandCost CmdAddSharedVehicleGroup(Til
 
		for (const Vehicle *v : Vehicle::Iterate()) {
 
			if (v->type == type && v->IsPrimaryVehicle()) {
 
				if (v->group_id != id_g) continue;
 

	
 
				/* 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(tile, id_g, v2->index, flags, CMD_ADD_VEHICLE_GROUP, text);
 
					if (v2->group_id != id_g) DoCommand(flags, CMD_ADD_VEHICLE_GROUP, tile, id_g, v2->index, text);
 
				}
 
			}
 
		}
 

	
 
		InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).Pack());
 
	}
 
@@ -613,13 +613,13 @@ CommandCost CmdRemoveAllVehiclesGroup(Ti
 
		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
 
		for (const Vehicle *v : Vehicle::Iterate()) {
 
			if (v->IsPrimaryVehicle()) {
 
				if (v->group_id != old_g) continue;
 

	
 
				/* Add The Vehicle to the default group */
 
				DoCommand(tile, DEFAULT_GROUP, v->index, flags, CMD_ADD_VEHICLE_GROUP, text);
 
				DoCommand(flags, CMD_ADD_VEHICLE_GROUP, tile, DEFAULT_GROUP, v->index, text);
 
			}
 
		}
 

	
 
		InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack());
 
	}
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -1097,13 +1097,13 @@ static bool SearchLumberMillTrees(TileIn
 
		Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
		_industry_sound_ctr = 1;
 
		_industry_sound_tile = tile;
 
		if (_settings_client.sound.ambient) SndPlayTileFx(SND_38_LUMBER_MILL_1, tile);
 

	
 
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
		DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 

	
 
		cur_company.Restore();
 
		return true;
 
	}
 
	return false;
 
}
 
@@ -1479,19 +1479,19 @@ static CommandCost CheckIfIndustryTilesA
 
				if (!IsTileType(cur_tile, MP_HOUSE)) {
 
					return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS);
 
				}
 

	
 
				/* 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(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
 
				CommandCost ret = DoCommand(DC_NONE, CMD_LANDSCAPE_CLEAR, 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(cur_tile, 0, 0, DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
				CommandCost ret = DoCommand(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, cur_tile, 0, 0);
 

	
 
				if (ret.Failed()) return ret;
 
			}
 
		}
 
	}
 

	
 
@@ -1595,13 +1595,13 @@ static bool CheckIfCanLevelIndustryPlatf
 
			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
 
				cur_company.Restore();
 
				return false;
 
			}
 
			/* 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(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND).Failed()) {
 
			if (DoCommand(flags & ~DC_EXEC, CMD_TERRAFORM_LAND, tile_walk, SLOPE_N, (curh > h) ? 0 : 1).Failed()) {
 
				cur_company.Restore();
 
				return false;
 
			}
 
		}
 
	}
 

	
 
@@ -1610,13 +1610,13 @@ static bool CheckIfCanLevelIndustryPlatf
 
		for (TileIndex tile_walk : ta) {
 
			uint curh = TileHeight(tile_walk);
 
			while (curh != h) {
 
				/* 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(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
 
				DoCommand(flags, CMD_TERRAFORM_LAND, tile_walk, SLOPE_N, (curh > h) ? 0 : 1);
 
				curh += (curh > h) ? -1 : 1;
 
			}
 
		}
 
	}
 

	
 
	cur_company.Restore();
 
@@ -1880,13 +1880,13 @@ static void DoCreateNewIndustry(Industry
 

	
 
		if (it.gfx != GFX_WATERTILE_SPECIALCHECK) {
 
			i->location.Add(cur_tile);
 

	
 
			WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID);
 

	
 
			DoCommand(cur_tile, 0, 0, DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
			DoCommand(DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, cur_tile, 0, 0);
 

	
 
			MakeIndustry(cur_tile, i->index, it.gfx, Random(), wc);
 

	
 
			if (_generating_world) {
 
				SetIndustryConstructionCounter(cur_tile, 3);
 
				SetIndustryConstructionStage(cur_tile, 2);
 
@@ -3056,13 +3056,13 @@ static CommandCost TerraformTile_Industr
 
			} else {
 
				/* allow autoslope */
 
				return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
			}
 
		}
 
	}
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
extern const TileTypeProcs _tile_type_industry_procs = {
 
	DrawTile_Industry,           // draw_tile_proc
 
	GetSlopePixelZ_Industry,     // get_slope_z_proc
 
	ClearTile_Industry,          // clear_tile_proc
src/landscape.cpp
Show inline comments
 
@@ -752,13 +752,13 @@ CommandCost CmdClearArea(TileIndex tile,
 
	const Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
 
	int limit = (c == nullptr ? INT32_MAX : GB(c->clear_limit, 16, 16));
 

	
 
	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(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
		CommandCost ret = DoCommand(flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR, t, 0, 0);
 
		if (ret.Failed()) {
 
			last_error = ret;
 

	
 
			/* We may not clear more tiles. */
 
			if (c != nullptr && GB(c->clear_limit, 16, 16) < 1) break;
 
			continue;
 
@@ -769,13 +769,13 @@ CommandCost CmdClearArea(TileIndex tile,
 
			money -= ret.GetCost();
 
			if (ret.GetCost() > 0 && money < 0) {
 
				_additional_cash_required = ret.GetCost();
 
				delete iter;
 
				return cost;
 
			}
 
			DoCommand(t, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			DoCommand(flags, CMD_LANDSCAPE_CLEAR, t, 0, 0);
 

	
 
			/* draw explosion animation...
 
			 * Disable explosions when game is paused. Looks silly and blocks the view. */
 
			if ((t == tile || t == p1) && _pause_mode == PM_UNPAUSED) {
 
				/* big explosion in two corners, or small explosion for single tiles */
 
				CreateEffectVehicleAbove(TileX(t) * TILE_SIZE + TILE_SIZE / 2, TileY(t) * TILE_SIZE + TILE_SIZE / 2, 2,
src/misc_gui.cpp
Show inline comments
 
@@ -188,13 +188,13 @@ public:
 

	
 
		/* Cost to clear/revenue when cleared */
 
		StringID str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A;
 
		Company *c = Company::GetIfValid(_local_company);
 
		if (c != nullptr) {
 
			assert(_current_company == _local_company);
 
			CommandCost costclear = DoCommand(tile, 0, 0, DC_QUERY_COST, CMD_LANDSCAPE_CLEAR);
 
			CommandCost costclear = DoCommand(DC_QUERY_COST, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
			if (costclear.Succeeded()) {
 
				Money cost = costclear.GetCost();
 
				if (cost < 0) {
 
					cost = -cost; // Negate negative cost to a positive revenue
 
					str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
 
				} else {
src/object_cmd.cpp
Show inline comments
 
@@ -226,26 +226,26 @@ CommandCost CmdBuildObject(TileIndex til
 
	for (TileIndex t : ta) {
 
		if (!IsValidTile(t)) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); // Might be off the map
 
	}
 

	
 
	if (type == OBJECT_OWNED_LAND) {
 
		/* Owned land is special as it can be placed on any slope. */
 
		cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
 
		cost.AddCost(DoCommand(flags, CMD_LANDSCAPE_CLEAR, 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
 
		 * some information about the tiles. */
 
		bool allow_water = (spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0;
 
		bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
 
		for (TileIndex t : ta) {
 
			if (HasTileWaterGround(t)) {
 
				if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 
				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(t, 0, 0, flags & ~DC_NO_WATER & ~DC_EXEC, CMD_LANDSCAPE_CLEAR));
 
					cost.AddCost(DoCommand(flags & ~DC_NO_WATER & ~DC_EXEC, CMD_LANDSCAPE_CLEAR, t, 0, 0));
 
				} else {
 
					/* Can't build on water owned by another company. */
 
					Owner o = GetTileOwner(t);
 
					if (o != OWNER_NONE && o != OWNER_WATER) cost.AddCost(CheckOwnership(o, t));
 

	
 
					/* However, the tile has to be clear of vehicles. */
 
@@ -257,13 +257,13 @@ CommandCost CmdBuildObject(TileIndex til
 

	
 
				/* When relocating HQ, allow it to be relocated (partial) on itself. */
 
				if (!(type == OBJECT_HQ &&
 
						IsTileType(t, MP_OBJECT) &&
 
						IsTileOwner(t, _current_company) &&
 
						IsObjectType(t, OBJECT_HQ))) {
 
					cost.AddCost(DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR));
 
					cost.AddCost(DoCommand(flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR, t, 0, 0));
 
				}
 
			}
 
		}
 

	
 
		/* So, now the surface is checked... check the slope of said surface. */
 
		int allowed_z;
 
@@ -289,16 +289,16 @@ CommandCost CmdBuildObject(TileIndex til
 
		if (flags & DC_EXEC) {
 
			/* This is basically a copy of the loop above with the exception that we now
 
			 * execute the commands and don't check for errors, since that's already done. */
 
			for (TileIndex t : ta) {
 
				if (HasTileWaterGround(t)) {
 
					if (!IsWaterTile(t)) {
 
						DoCommand(t, 0, 0, (flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
						DoCommand((flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, t, 0, 0);
 
					}
 
				} else {
 
					DoCommand(t, 0, 0, flags | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
					DoCommand(flags | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR, t, 0, 0);
 
				}
 
			}
 
		}
 
	}
 
	if (cost.Failed()) return cost;
 

	
 
@@ -844,13 +844,13 @@ static CommandCost TerraformTile_Object(
 
				/* allow autoslope */
 
				return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
			}
 
		}
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
extern const TileTypeProcs _tile_type_object_procs = {
 
	DrawTile_Object,             // draw_tile_proc
 
	GetSlopePixelZ_Object,       // get_slope_z_proc
 
	ClearTile_Object,            // clear_tile_proc
src/order_backup.cpp
Show inline comments
 
@@ -70,13 +70,13 @@ OrderBackup::OrderBackup(const Vehicle *
 
 * @param v The vehicle to restore to.
 
 */
 
void OrderBackup::DoRestore(Vehicle *v)
 
{
 
	/* If we had shared orders, recover that */
 
	if (this->clone != nullptr) {
 
		DoCommand(0, v->index | CO_SHARE << 30, this->clone->index, DC_EXEC, CMD_CLONE_ORDER);
 
		DoCommand(DC_EXEC, CMD_CLONE_ORDER, 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;
 
		/* Make sure buoys/oil rigs are updated in the station list. */
 
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
 
	}
 
@@ -85,13 +85,13 @@ void OrderBackup::DoRestore(Vehicle *v)
 

	
 
	/* Make sure orders are in range */
 
	v->UpdateRealOrderIndex();
 
	if (v->cur_implicit_order_index >= v->GetNumOrders()) v->cur_implicit_order_index = v->cur_real_order_index;
 

	
 
	/* Restore vehicle group */
 
	DoCommand(0, this->group, v->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP);
 
	DoCommand(DC_EXEC, CMD_ADD_VEHICLE_GROUP, 0, this->group, v->index);
 
}
 

	
 
/**
 
 * Create an order backup for the given vehicle.
 
 * @param v    The vehicle to make a backup of.
 
 * @param user The user that is requesting the backup.
src/order_cmd.cpp
Show inline comments
 
@@ -2033,13 +2033,13 @@ bool UpdateOrderDest(Vehicle *v, const O
 
					if (pbs_look_ahead && reverse) return false;
 

	
 
					v->SetDestTile(location);
 
					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(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 
					if (v->type == VEH_TRAIN && reverse) DoCommand(DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION, v->tile, v->index, 0);
 

	
 
					if (v->type == VEH_AIRCRAFT) {
 
						Aircraft *a = Aircraft::From(v);
 
						if (a->state == FLYING && a->targetairport != destination) {
 
							/* The aircraft is now heading for a different hangar than the next in the orders */
 
							extern void AircraftNextAirportPos_and_Order(Aircraft *a);
src/rail_cmd.cpp
Show inline comments
 
@@ -448,13 +448,13 @@ CommandCost CmdBuildSingleRail(TileIndex
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY: {
 
			CommandCost ret = CheckTileOwnership(tile);
 
			if (ret.Failed()) return ret;
 

	
 
			if (!IsPlainRail(tile)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); // just get appropriate error message
 
			if (!IsPlainRail(tile)) return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0); // just get appropriate error message
 

	
 
			if (!IsCompatibleRail(GetRailType(tile), railtype)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
 

	
 
			ret = CheckTrackCombination(tile, trackbit, flags);
 
			if (ret.Succeeded()) ret = EnsureNoTrainOnTrack(tile, track);
 
			if (ret.Failed()) return ret;
 
@@ -466,25 +466,25 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			if (HasSignals(tile) && TracksOverlap(GetTrackBits(tile) | TrackToTrackBits(track))) {
 
				/* If adding the new track causes any overlap, all signals must be removed first */
 
				if (!auto_remove_signals) return_cmd_error(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
 

	
 
				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(tile, track_it, 0, flags, CMD_REMOVE_SIGNALS);
 
						CommandCost ret_remove_signals = DoCommand(flags, CMD_REMOVE_SIGNALS, tile, track_it, 0);
 
						if (ret_remove_signals.Failed()) return ret_remove_signals;
 
						cost.AddCost(ret_remove_signals);
 
					}
 
				}
 
			}
 

	
 
			/* If the rail types don't match, try to convert only if engines of
 
			 * the new rail type are not powered on the present rail type and engines of
 
			 * 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(tile, tile, railtype, flags, CMD_CONVERT_RAIL);
 
					ret = DoCommand(flags, CMD_CONVERT_RAIL, tile, tile, railtype);
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
				} else {
 
					return CMD_ERROR;
 
				}
 
			}
 
@@ -578,13 +578,13 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			bool water_ground = IsTileType(tile, MP_WATER) && IsSlopeWithOneCornerRaised(tileh);
 

	
 
			CommandCost ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 

	
 
			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 

	
 
			if (water_ground) {
 
				cost.AddCost(-_price[PR_CLEAR_WATER]);
 
				cost.AddCost(_price[PR_CLEAR_ROUGH]);
 
@@ -688,13 +688,13 @@ CommandCost CmdRemoveSingleRail(TileInde
 
			if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
 

	
 
			cost.AddCost(RailClearCost(GetRailType(tile)));
 

	
 
			/* Charge extra to remove signals on the track, if they are there */
 
			if (HasSignalOnTrack(tile, track)) {
 
				cost.AddCost(DoCommand(tile, track, 0, flags, CMD_REMOVE_SIGNALS));
 
				cost.AddCost(DoCommand(flags, CMD_REMOVE_SIGNALS, tile, track, 0));
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				if (HasReservedTracks(tile, trackbit)) {
 
					v = GetTrainForReservation(tile, track);
 
					if (v != nullptr) FreeTrainTrackReservation(v);
 
@@ -781,13 +781,13 @@ bool FloodHalftile(TileIndex t)
 
	if (IsSlopeWithOneCornerRaised(tileh)) {
 
		TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
 

	
 
		TrackBits to_remove = lower_track & rail_bits;
 
		if (to_remove != 0) {
 
			Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
 
			flooded = DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL).Succeeded();
 
			flooded = DoCommand(DC_EXEC, CMD_REMOVE_SINGLE_RAIL, t, 0, FIND_FIRST_BIT(to_remove)).Succeeded();
 
			cur_company.Restore();
 
			if (!flooded) return flooded; // not yet floodable
 
			rail_bits = rail_bits & ~to_remove;
 
			if (rail_bits == 0) {
 
				MakeShore(t);
 
				MarkTileDirtyByTile(t);
 
@@ -900,13 +900,13 @@ static CommandCost CmdRailTrackHelper(Ti
 
	CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
 
	if (ret.Failed()) return ret;
 

	
 
	bool had_success = false;
 
	CommandCost last_error = CMD_ERROR;
 
	for (;;) {
 
		CommandCost ret = DoCommand(tile, remove ? 0 : railtype, TrackdirToTrack(trackdir) | (auto_remove_signals << 3), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
 
		CommandCost ret = DoCommand(flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL, tile, remove ? 0 : railtype, TrackdirToTrack(trackdir) | (auto_remove_signals << 3));
 

	
 
		if (ret.Failed()) {
 
			last_error = ret;
 
			if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
 
				if (HasBit(p2, 10)) return last_error;
 
				break;
 
@@ -1004,13 +1004,13 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
		if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) {
 
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
		}
 
		cost.AddCost(_price[PR_BUILD_FOUNDATION]);
 
	}
 

	
 
	cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
 
	cost.AddCost(DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0));
 
	if (cost.Failed()) return cost;
 

	
 
	if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
@@ -1355,13 +1355,13 @@ static CommandCost CmdSignalTrackHelper(
 

	
 
		/* Pick the correct orientation for the track direction */
 
		byte signals = 0;
 
		if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
 
		if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
 

	
 
		CommandCost ret = DoCommand(tile, param1, signals, test_only ? flags & ~DC_EXEC : flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
 
		CommandCost ret = DoCommand(test_only ? flags & ~DC_EXEC : flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS, tile, param1, signals);
 

	
 
		if (test_only) return ret.Succeeded();
 

	
 
		if (ret.Succeeded()) {
 
			had_success = true;
 
			total_cost.AddCost(ret);
 
@@ -1875,13 +1875,13 @@ static CommandCost ClearTile_Track(TileI
 
			/* Is there flat water on the lower halftile that gets cleared expensively? */
 
			bool water_ground = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh));
 

	
 
			TrackBits tracks = GetTrackBits(tile);
 
			while (tracks != TRACK_BIT_NONE) {
 
				Track track = RemoveFirstTrack(&tracks);
 
				CommandCost ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
 
				CommandCost ret = DoCommand(flags, CMD_REMOVE_SINGLE_RAIL, tile, 0, track);
 
				if (ret.Failed()) return ret;
 
				cost.AddCost(ret);
 
			}
 

	
 
			/* When bankrupting, don't make water dirty, there could be a ship on lower halftile.
 
			 * Same holds for non-companies clearing the tile, e.g. disasters. */
 
@@ -2949,13 +2949,13 @@ static void ChangeTileOwner_Track(TileIn
 
			Company::Get(old_owner)->infrastructure.signal -= num_sigs;
 
			Company::Get(new_owner)->infrastructure.signal += num_sigs;
 
		}
 

	
 
		SetTileOwner(tile, new_owner);
 
	} else {
 
		DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
		DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	}
 
}
 

	
 
static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
 
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
 
static const int8 _deltacoord_leaveoffset[8] = {
 
@@ -3137,13 +3137,13 @@ static CommandCost TerraformTile_Track(T
 
		/* allow terraforming */
 
		return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price[PR_CLEAR_WATER] : (Money)0);
 
	} else if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() &&
 
			AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) {
 
		return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
	}
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_rail_procs = {
 
	DrawTile_Track,           // draw_tile_proc
 
	GetSlopePixelZ_Track,     // get_slope_z_proc
src/rail_gui.cpp
Show inline comments
 
@@ -753,13 +753,13 @@ struct BuildRailToolbarWindow : Window {
 
		CloseWindowById(WC_SELECT_STATION, 0);
 
		CloseWindowByClass(WC_BUILD_BRIDGE);
 
	}
 

	
 
	void OnPlacePresize(Point pt, TileIndex tile) override
 
	{
 
		DoCommand(tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
		DoCommand(DC_AUTO, CMD_BUILD_TUNNEL, tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0);
 
		VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
 
	}
 

	
 
	EventState OnCTRLStateChange() override
 
	{
 
		/* do not toggle Remove button by Ctrl when placing station */
src/road_cmd.cpp
Show inline comments
 
@@ -363,13 +363,13 @@ static CommandCost RemoveRoad(TileIndex 
 

	
 
	CommandCost ret = CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rtt), rtt, flags, town_check);
 
	if (ret.Failed()) return ret;
 

	
 
	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(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 

	
 
		CommandCost cost(EXPENSES_CONSTRUCTION);
 
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			/* Removing any roadbit in the bridge axis removes the roadtype (that's the behaviour remove-long-roads needs) */
 
			if ((AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) & pieces) == ROAD_NONE) return_cmd_error((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
 

	
 
@@ -818,13 +818,13 @@ do_clear:;
 
			need_to_clear = true;
 
			break;
 
		}
 
	}
 

	
 
	if (need_to_clear) {
 
		CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 
	}
 

	
 
	if (other_bits != pieces) {
 
		/* Check the foundation/slopes when adding road/tram bits */
 
@@ -864,13 +864,13 @@ do_clear:;
 
			 * the present road type are powered on the new road type. */
 
			RoadType existing_rt = GetRoadType(tile, rtt);
 
			if (existing_rt != INVALID_ROADTYPE && existing_rt != rt) {
 
				if (HasPowerOnRoad(rt, existing_rt)) {
 
					rt = existing_rt;
 
				} else if (HasPowerOnRoad(existing_rt, rt)) {
 
					CommandCost ret = DoCommand(tile, tile, rt, flags, CMD_CONVERT_ROAD);
 
					CommandCost ret = DoCommand(flags, CMD_CONVERT_ROAD, tile, tile, rt);
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
				} else {
 
					return CMD_ERROR;
 
				}
 
			}
 
@@ -1035,13 +1035,13 @@ CommandCost CmdBuildLongRoad(TileIndex s
 
		} else {
 
			/* Road parts only have to be built at the start tile or at the end tile. */
 
			if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
 
			if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
 
		}
 

	
 
		CommandCost ret = DoCommand(tile, drd << 11 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
 
		CommandCost ret = DoCommand(flags, CMD_BUILD_ROAD, tile, drd << 11 | rt << 4 | bits, 0);
 
		if (ret.Failed()) {
 
			last_error = ret;
 
			if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
 
				if (is_ai) return last_error;
 
				break;
 
			}
 
@@ -1126,13 +1126,13 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
			RoadTramType rtt = GetRoadTramType(rt);
 
			CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rtt, true);
 
			if (ret.Succeeded()) {
 
				if (flags & DC_EXEC) {
 
					money_spent += ret.GetCost();
 
					if (money_spent > 0 && money_spent > money_available) {
 
						_additional_cash_required = DoCommand(start_tile, end_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
 
						_additional_cash_required = DoCommand(flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD, start_tile, end_tile, p2).GetCost();
 
						return cost;
 
					}
 
					RemoveRoad(tile, flags, bits, rtt, true, false);
 
				}
 
				cost.AddCost(ret);
 
				had_success = true;
 
@@ -1177,13 +1177,13 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
		if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) {
 
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
		}
 
		cost.AddCost(_price[PR_BUILD_FOUNDATION]);
 
	}
 

	
 
	cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
 
	cost.AddCost(DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0));
 
	if (cost.Failed()) return cost;
 

	
 
	if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
@@ -1263,13 +1263,13 @@ static CommandCost ClearTile_Road(TileIn
 
				CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rtt, false);
 
				if (tmp_ret.Failed()) return tmp_ret;
 
				ret.AddCost(tmp_ret);
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
				DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
			}
 
			return ret;
 
		}
 

	
 
		default:
 
		case ROAD_TILE_DEPOT:
 
@@ -2191,13 +2191,13 @@ static VehicleEnterTileStatus VehicleEnt
 

	
 
static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	if (IsRoadDepot(tile)) {
 
		if (GetTileOwner(tile) == old_owner) {
 
			if (new_owner == INVALID_OWNER) {
 
				DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
				DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, 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);
 
				if (rt == INVALID_ROADTYPE) rt = GetRoadTypeTram(tile);
 
				Company::Get(old_owner)->infrastructure.road[rt] -= 2;
 
				Company::Get(new_owner)->infrastructure.road[rt] += 2;
 
@@ -2228,13 +2228,13 @@ static void ChangeTileOwner_Road(TileInd
 
		}
 
	}
 

	
 
	if (IsLevelCrossing(tile)) {
 
		if (GetTileOwner(tile) == old_owner) {
 
			if (new_owner == INVALID_OWNER) {
 
				DoCommand(tile, 0, GetCrossingRailTrack(tile), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
 
				DoCommand(DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL, 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;
 
				Company::Get(new_owner)->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
 

	
 
				SetTileOwner(tile, new_owner);
 
@@ -2277,13 +2277,13 @@ static CommandCost TerraformTile_Road(Ti
 
			}
 

	
 
			default: NOT_REACHED();
 
		}
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
/** Update power of road vehicle under which is the roadtype being converted */
 
static Vehicle *UpdateRoadVehPowerProc(Vehicle *v, void *data)
 
{
 
	if (v->type != VEH_ROAD) return nullptr;
src/road_gui.cpp
Show inline comments
 
@@ -705,13 +705,13 @@ struct BuildRoadToolbarWindow : Window {
 
			}
 
		}
 
	}
 

	
 
	void OnPlacePresize(Point pt, TileIndex tile) override
 
	{
 
		DoCommand(tile, _cur_roadtype | (TRANSPORT_ROAD << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL);
 
		DoCommand(DC_AUTO, CMD_BUILD_TUNNEL, tile, _cur_roadtype | (TRANSPORT_ROAD << 8), 0);
 
		VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
 
	}
 

	
 
	EventState OnCTRLStateChange() override
 
	{
 
		if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1130,13 +1130,13 @@ static Trackdir FollowPreviousRoadVehicl
 
 */
 
static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadType rt, RoadBits r)
 
{
 
	/* The 'current' company is not necessarily the owner of the vehicle. */
 
	Backup<CompanyID> cur_company(_current_company, c, FILE_LINE);
 

	
 
	CommandCost ret = DoCommand(t, rt << 4 | r, 0, DC_NO_WATER, CMD_BUILD_ROAD);
 
	CommandCost ret = DoCommand(DC_NO_WATER, CMD_BUILD_ROAD, t, rt << 4 | r, 0);
 

	
 
	cur_company.Restore();
 
	return ret.Succeeded();
 
}
 

	
 
bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
src/script/api/script_vehicle.cpp
Show inline comments
 
@@ -90,13 +90,13 @@
 
{
 
	if (!ScriptEngine::IsBuildable(engine_id)) return -1;
 
	if (!ScriptCargo::IsValidCargo(cargo)) return -1;
 

	
 
	::VehicleType type = ::Engine::Get(engine_id)->type;
 

	
 
	CommandCost res = ::DoCommand(depot, engine_id | (cargo << 24), 0, DC_QUERY_COST, ::GetCmdBuildVeh(type));
 
	CommandCost res = ::DoCommand(DC_QUERY_COST, ::GetCmdBuildVeh(type), depot, engine_id | (cargo << 24), 0);
 
	return res.Succeeded() ? _returned_refit_capacity : -1;
 
}
 

	
 
/* static */ VehicleID ScriptVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
 
@@ -139,13 +139,13 @@
 

	
 
/* static */ int ScriptVehicle::GetRefitCapacity(VehicleID vehicle_id, CargoID cargo)
 
{
 
	if (!IsValidVehicle(vehicle_id)) return -1;
 
	if (!ScriptCargo::IsValidCargo(cargo)) return -1;
 

	
 
	CommandCost res = ::DoCommand(0, vehicle_id, cargo, DC_QUERY_COST, GetCmdRefitVeh(::Vehicle::Get(vehicle_id)));
 
	CommandCost res = ::DoCommand(DC_QUERY_COST, GetCmdRefitVeh(::Vehicle::Get(vehicle_id)), 0, vehicle_id, cargo);
 
	return res.Succeeded() ? _returned_refit_capacity : -1;
 
}
 

	
 
/* static */ bool ScriptVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo)
 
{
 
	EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
src/station_cmd.cpp
Show inline comments
 
@@ -838,13 +838,13 @@ static CommandCost CheckFlatLandAirport(
 

	
 
	for (; tile_iter != INVALID_TILE; ++tile_iter) {
 
		CommandCost ret = CheckBuildableTile(tile_iter, 0, allowed_z, true);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		ret = DoCommand(tile_iter, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_iter, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 
	}
 

	
 
	return cost;
 
}
 
@@ -918,20 +918,20 @@ static CommandCost CheckFlatLandRailStat
 
					if (HasBit(GetRailReservationTrackBits(tile_cur), track)) {
 
						Train *v = GetTrainForReservation(tile_cur, track);
 
						if (v != nullptr) {
 
							affected_vehicles.push_back(v);
 
						}
 
					}
 
					CommandCost ret = DoCommand(tile_cur, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
 
					CommandCost ret = DoCommand(flags, CMD_REMOVE_SINGLE_RAIL, 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(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_cur, 0, 0);
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 
		}
 
	}
 

	
 
	return cost;
 
@@ -1043,13 +1043,13 @@ static CommandCost CheckFlatLandRoadStop
 

	
 
					cost.AddCost(RoadBuildCost(tram_rt) * (2 - num_pieces));
 
				} else if (RoadTypeIsTram(rt)) {
 
					cost.AddCost(RoadBuildCost(rt) * 2);
 
				}
 
			} else {
 
				ret = DoCommand(cur_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
				ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, cur_tile, 0, 0);
 
				if (ret.Failed()) return ret;
 
				cost.AddCost(ret);
 
				cost.AddCost(RoadBuildCost(rt) * 2);
 
			}
 
		}
 
	}
 
@@ -1749,13 +1749,13 @@ CommandCost RemoveRailStation(T *st, DoC
 
 * @return cost or failure of operation
 
 */
 
static CommandCost RemoveRailStation(TileIndex tile, DoCommandFlag flags)
 
{
 
	/* if there is flooding, remove platforms tile by tile */
 
	if (_current_company == OWNER_WATER) {
 
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAIL_STATION);
 
		return DoCommand(DC_EXEC, CMD_REMOVE_FROM_RAIL_STATION, tile, 0, 0);
 
	}
 

	
 
	Station *st = Station::GetByTile(tile);
 
	CommandCost cost = RemoveRailStation(st, flags, _price[PR_CLEAR_STATION_RAIL]);
 

	
 
	if (flags & DC_EXEC) st->RecomputeCatchment();
 
@@ -1770,13 +1770,13 @@ static CommandCost RemoveRailStation(Til
 
 * @return cost or failure of operation
 
 */
 
static CommandCost RemoveRailWaypoint(TileIndex tile, DoCommandFlag flags)
 
{
 
	/* if there is flooding, remove waypoints tile by tile */
 
	if (_current_company == OWNER_WATER) {
 
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAIL_WAYPOINT);
 
		return DoCommand(DC_EXEC, CMD_REMOVE_FROM_RAIL_WAYPOINT, tile, 0, 0);
 
	}
 

	
 
	return RemoveRailStation(Waypoint::GetByTile(tile), flags, _price[PR_CLEAR_WAYPOINT_RAIL]);
 
}
 

	
 

	
 
@@ -2532,13 +2532,13 @@ CommandCost CmdBuildDock(TileIndex tile,
 
	CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
 
	if (ret.Failed()) return ret;
 

	
 
	if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]);
 
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	if (ret.Failed()) return ret;
 
	cost.AddCost(ret);
 

	
 
	TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
 

	
 
	if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) {
 
@@ -2547,13 +2547,13 @@ CommandCost CmdBuildDock(TileIndex tile,
 

	
 
	if (IsBridgeAbove(tile_cur)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	/* Get the water class of the water tile before it is cleared.*/
 
	WaterClass wc = GetWaterClass(tile_cur);
 

	
 
	ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_cur, 0, 0);
 
	if (ret.Failed()) return ret;
 

	
 
	tile_cur += TileOffsByDiagDir(direction);
 
	if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) {
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
 
@@ -4237,18 +4237,18 @@ static void ChangeTileOwner_Station(Tile
 
		/* for buoys, owner of tile is owner of water, st->owner == OWNER_NONE */
 
		SetTileOwner(tile, new_owner);
 
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
 
	} else {
 
		if (IsDriveThroughStopTile(tile)) {
 
			/* Remove the drive-through road stop */
 
			DoCommand(tile, 1 | 1 << 8, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
 
			DoCommand(DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP, 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(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
			DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, 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). */
 
			if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && IsTileOwner(tile, old_owner)) SetTileOwner(tile, OWNER_NONE);
 
		}
 
	}
 
@@ -4359,13 +4359,13 @@ static CommandCost TerraformTile_Station
 
				}
 

	
 
				default: break;
 
			}
 
		}
 
	}
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
/**
 
 * Get flow for a station.
 
 * @param st Station to get flow for.
 
 * @return Flow for st.
src/terraform_cmd.cpp
Show inline comments
 
@@ -286,13 +286,13 @@ CommandCost CmdTerraformLand(TileIndex t
 
			if (pass == 0) {
 
				tile_flags &= ~DC_EXEC;
 
				tile_flags |= DC_NO_MODIFY_TOWN_RATING;
 
			}
 
			CommandCost cost;
 
			if (indirectly_cleared) {
 
				cost = DoCommand(t, 0, 0, tile_flags, CMD_LANDSCAPE_CLEAR);
 
				cost = DoCommand(tile_flags, CMD_LANDSCAPE_CLEAR, t, 0, 0);
 
			} else {
 
				cost = _tile_type_procs[GetTileType(t)]->terraform_tile_proc(t, tile_flags, z_min, tileh);
 
			}
 
			old_generating_world.Restore();
 
			if (cost.Failed()) {
 
				_terraform_err_tile = t;
 
@@ -375,13 +375,13 @@ CommandCost CmdLevelLand(TileIndex tile,
 

	
 
	TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(tile, p1);
 
	for (; *iter != INVALID_TILE; ++(*iter)) {
 
		TileIndex t = *iter;
 
		uint curh = TileHeight(t);
 
		while (curh != h) {
 
			CommandCost ret = DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
 
			CommandCost ret = DoCommand(flags & ~DC_EXEC, CMD_TERRAFORM_LAND, t, SLOPE_N, (curh > h) ? 0 : 1);
 
			if (ret.Failed()) {
 
				last_error = ret;
 

	
 
				/* Did we reach the limit? */
 
				if (ret.GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
 
				break;
 
@@ -391,13 +391,13 @@ CommandCost CmdLevelLand(TileIndex tile,
 
				money -= ret.GetCost();
 
				if (money < 0) {
 
					_additional_cash_required = ret.GetCost();
 
					delete iter;
 
					return cost;
 
				}
 
				DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
 
				DoCommand(flags, CMD_TERRAFORM_LAND, 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
 
				 * when it's near the terraforming limit. Even then, the estimation is
 
				 * completely off due to it basically counting terraforming double, so it being
 
				 * cut off earlier might even give a better estimate in some cases. */
src/terraform_gui.cpp
Show inline comments
 
@@ -508,13 +508,13 @@ static void ResetLandscapeConfirmationCa
 

	
 
		old_generating_world.Restore();
 

	
 
		/* Delete all station signs */
 
		for (BaseStation *st : BaseStation::Iterate()) {
 
			/* There can be buoys, remove them */
 
			if (IsBuoyTile(st->xy)) DoCommand(st->xy, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
			if (IsBuoyTile(st->xy)) DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, st->xy, 0, 0);
 
			if (!st->IsInUse()) delete st;
 
		}
 

	
 
		/* Now that all vehicles are gone, we can reset the engine pool. Maybe it reduces some NewGRF changing-mess */
 
		EngineOverrideManager::ResetToCurrentNewGRFConfig();
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -935,14 +935,14 @@ static bool IsRoadAllowedHere(Town *t, T
 
	/* Check if there already is a road at this point? */
 
	if (GetTownRoadBits(tile) == ROAD_NONE) {
 
		/* No, try if we are able to build a road piece there.
 
		 * 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(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Failed() &&
 
				DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Failed()) {
 
		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()) {
 
			return false;
 
		}
 
	}
 

	
 
	Slope cur_slope = _settings_game.construction.build_on_slopes ? GetFoundationSlope(tile) : GetTileSlope(tile);
 
	bool ret = !IsNeighborRoadTile(tile, dir, t->layout == TL_ORIGINAL ? 1 : 2);
 
@@ -953,14 +953,14 @@ static bool IsRoadAllowedHere(Town *t, T
 
	Slope desired_slope = (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? SLOPE_NW : SLOPE_NE;
 
	if (desired_slope != cur_slope && ComplementSlope(desired_slope) != cur_slope) {
 
		if (Chance16(1, 8)) {
 
			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(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0,
 
						DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
 
				res = DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND,
 
						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. */
 
				return ret;
 
			}
 
		}
 
@@ -970,15 +970,15 @@ static bool IsRoadAllowedHere(Town *t, T
 
}
 

	
 
static bool TerraformTownTile(TileIndex tile, int edges, int dir)
 
{
 
	assert(tile < MapSize());
 

	
 
	CommandCost r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
 
	CommandCost r = DoCommand(DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND, tile, edges, dir);
 
	if (r.Failed() || r.GetCost() >= (_price[PR_TERRAFORM] + 2) * 8) return false;
 
	DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND);
 
	DoCommand(DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND, tile, edges, dir);
 
	return true;
 
}
 

	
 
static void LevelTownLand(TileIndex tile)
 
{
 
	assert(tile < MapSize());
 
@@ -1104,13 +1104,13 @@ static bool GrowTownWithExtraHouse(Town 
 
 * @param rcmd The RoadBits we want to build on the tile
 
 * @return true if the RoadBits have been added else false
 
 */
 
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
 
{
 
	RoadType rt = GetTownRoadType(t);
 
	if (DoCommand(tile, rcmd | (rt << 4), t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded()) {
 
	if (DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, tile, rcmd | (rt << 4), t->index).Succeeded()) {
 
		_grow_town_result = GROWTH_SUCCEED;
 
		return true;
 
	}
 
	return false;
 
}
 

	
 
@@ -1151,13 +1151,13 @@ static bool CanRoadContinueIntoNextTile(
 

	
 
	/* If the next tile is a railroad track, check if towns are allowed to build level crossings.
 
	 * If level crossing are not allowed, reject the construction. Else allow DoCommand to determine if the rail track is buildable. */
 
	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(next_tile, rcmd | (rt << 4), t->index, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded();
 
	return DoCommand(DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, next_tile, rcmd | (rt << 4), t->index).Succeeded();
 
}
 

	
 
/**
 
 * Grows the town with a bridge.
 
 *  At first we check if a bridge is reasonable.
 
 *  If so we check if we are able to build it.
 
@@ -1219,14 +1219,14 @@ static bool GrowTownWithBridge(const Tow
 

	
 
	for (uint8 times = 0; times <= 22; times++) {
 
		byte bridge_type = RandomRange(MAX_BRIDGES - 1);
 

	
 
		/* Can we actually build the bridge? */
 
		RoadType rt = GetTownRoadType(t);
 
		if (DoCommand(tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE).Succeeded()) {
 
			DoCommand(tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE);
 
		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);
 
			_grow_town_result = GROWTH_SUCCEED;
 
			return true;
 
		}
 
	}
 
	/* Quit if it selecting an appropriate bridge type fails a large number of times. */
 
	return false;
 
@@ -1290,14 +1290,14 @@ static bool GrowTownWithTunnel(const Tow
 

	
 
	/* Make sure the road can be continued past the tunnel. At this point, tunnel_tile holds the end tile of the tunnel. */
 
	if (!CanRoadContinueIntoNextTile(t, tunnel_tile, tunnel_dir)) return false;
 

	
 
	/* Attempt to build the tunnel. Return false if it fails to let the town build a road instead. */
 
	RoadType rt = GetTownRoadType(t);
 
	if (DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL).Succeeded()) {
 
		DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL);
 
	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);
 
		_grow_town_result = GROWTH_SUCCEED;
 
		return true;
 
	}
 

	
 
	return false;
 
}
 
@@ -1729,15 +1729,15 @@ static bool GrowTown(Town *t)
 
	 * clearing some land and then building a road there. */
 
	if (_settings_game.economy.allow_town_roads || _generating_world) {
 
		tile = t->xy;
 
		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(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
				if (DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded()) {
 
					RoadType rt = GetTownRoadType(t);
 
					DoCommand(tile, GenRandomRoadBits() | (rt << 4), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
 
					DoCommand(DC_EXEC | DC_AUTO, CMD_BUILD_ROAD, tile, GenRandomRoadBits() | (rt << 4), t->index);
 
					cur_company.Restore();
 
					return true;
 
				}
 
			}
 
			tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
 
		}
 
@@ -2176,13 +2176,13 @@ static Town *CreateRandomTown(uint attem
 

	
 
		/* if the population is still 0 at the point, then the
 
		 * placement is so bad it couldn't grow at all */
 
		if (t->cache.population > 0) return t;
 

	
 
		Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 
		[[maybe_unused]] CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN);
 
		[[maybe_unused]] CommandCost rc = DoCommand(DC_EXEC, CMD_DELETE_TOWN, t->xy, t->index, 0);
 
		cur_company.Restore();
 
		assert(rc.Succeeded());
 

	
 
		/* We already know that we can allocate a single town when
 
		 * entering this function. However, we create and delete
 
		 * a town which "resets" the allocation checks. As such we
 
@@ -2277,13 +2277,13 @@ HouseZonesBits GetTownRadiusGroup(const 
 
 * @param type of house. Index into house specs array
 
 * @param random_bits required for newgrf houses
 
 * @pre house can be built here
 
 */
 
static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
 
{
 
	[[maybe_unused]] CommandCost cc = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
 
	[[maybe_unused]] CommandCost cc = DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	assert(cc.Succeeded());
 

	
 
	IncreaseBuildingCount(t, type);
 
	MakeHouseTile(tile, t->index, counter, stage, type, random_bits);
 
	if (HouseSpec::Get(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(tile);
 

	
 
@@ -2334,13 +2334,13 @@ static inline bool CanBuildHouseHere(Til
 
	if (!RoadTypesAllowHouseHere(tile)) return false;
 

	
 
	/* building under a bridge? */
 
	if (IsBridgeAbove(tile)) return false;
 

	
 
	/* can we clear the land? */
 
	return DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded();
 
	return DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded();
 
}
 

	
 

	
 
/**
 
 * Checks if a house can be built at this tile, must have the same max z as parameter.
 
 * @param tile tile to check
 
@@ -2969,13 +2969,13 @@ CommandCost CmdDeleteTown(TileIndex tile
 
	/* Stations refer to towns. */
 
	for (const Station *st : Station::Iterate()) {
 
		if (st->town == t) {
 
			/* 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(st->airport.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, st->airport.tile, 0, 0);
 
			if (ret.Failed()) return ret;
 
		}
 
	}
 

	
 
	/* Depots refer to towns. */
 
	for (const Depot *d : Depot::Iterate()) {
 
@@ -2985,13 +2985,13 @@ CommandCost CmdDeleteTown(TileIndex tile
 
	/* Check all tiles for town ownership. First check for bridge tiles, as
 
	 * these do not directly have an owner so we need to check adjacent
 
	 * tiles. This won't work correctly in the same loop if the adjacent
 
	 * 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(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
 
			if (ret.Failed()) return ret;
 
		}
 
	}
 

	
 
	/* Check all remaining tiles for town ownership. */
 
	for (TileIndex current_tile = 0; current_tile < MapSize(); ++current_tile) {
 
@@ -3028,13 +3028,13 @@ CommandCost CmdDeleteTown(TileIndex tile
 
				break;
 

	
 
			default:
 
				break;
 
		}
 
		if (try_clear) {
 
			CommandCost ret = DoCommand(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
 
			if (ret.Failed()) return ret;
 
		}
 
	}
 

	
 
	/* The town destructor will delete the other things related to the town. */
 
	if (flags & DC_EXEC) {
 
@@ -3104,13 +3104,13 @@ static CommandCost TownActionRoadRebuild
 
 * @param tile Tile to check.
 
 * @return The tile can be cleared.
 
 */
 
static bool TryClearTile(TileIndex tile)
 
{
 
	Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
	CommandCost r = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
 
	CommandCost r = DoCommand(DC_NONE, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	cur_company.Restore();
 
	return r.Succeeded();
 
}
 

	
 
/** Structure for storing data while searching the best place to build a statue. */
 
struct StatueBuildSearchData {
 
@@ -3176,13 +3176,13 @@ static CommandCost TownActionBuildStatue
 
	TileIndex tile = t->xy;
 
	StatueBuildSearchData statue_data(INVALID_TILE, 0);
 
	if (!CircularTileSearch(&tile, 9, SearchTileForStatue, &statue_data)) return_cmd_error(STR_ERROR_STATUE_NO_SUITABLE_PLACE);
 

	
 
	if (flags & DC_EXEC) {
 
		Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
		DoCommand(statue_data.best_position, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
		DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, 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.
 
		MarkTileDirtyByTile(statue_data.best_position);
 
	}
 
	return CommandCost();
 
@@ -3783,13 +3783,13 @@ static CommandCost TerraformTile_Town(Ti
 
			}
 

	
 
			if (allow_terraform) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
		}
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
/** Tile callback functions for a town */
 
extern const TileTypeProcs _tile_type_town_procs = {
 
	DrawTile_Town,           // draw_tile_proc
 
	GetSlopePixelZ_Town,     // get_slope_z_proc
src/train_cmd.cpp
Show inline comments
 
@@ -651,13 +651,13 @@ static CommandCost CmdBuildRailWagon(Til
 
		for (Train *w : Train::Iterate()) {
 
			if (w->tile == tile &&              ///< Same depot
 
					w->IsFreeWagon() &&             ///< A free wagon chain
 
					w->engine_type == e->index &&   ///< Same type
 
					w->First() != v &&              ///< Don't connect to ourself
 
					!(w->vehstatus & VS_CRASHED)) { ///< Not crashed/flooded
 
				if (DoCommand(0, v->index | 1 << 20, w->Last()->index, DC_EXEC, CMD_MOVE_RAIL_VEHICLE).Succeeded()) {
 
				if (DoCommand(DC_EXEC, CMD_MOVE_RAIL_VEHICLE, 0, v->index | 1 << 20, w->Last()->index).Succeeded()) {
 
					break;
 
				}
 
			}
 
		}
 
	}
 

	
 
@@ -667,18 +667,18 @@ static CommandCost CmdBuildRailWagon(Til
 
/** Move all free vehicles in the depot to the train */
 
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(0, v->index | 1 << 20, u->index, DC_EXEC,
 
					CMD_MOVE_RAIL_VEHICLE).Failed())
 
			if (DoCommand(DC_EXEC, CMD_MOVE_RAIL_VEHICLE, 0, v->index | 1 << 20, u->index).Failed()) {
 
				break;
 
		}
 
	}
 
}
 
}
 

	
 
static void AddRearEngineToMultiheadedTrain(Train *v)
 
{
 
	Train *u = new Train();
 
	v->value >>= 1;
 
	u->value = v->value;
src/tree_cmd.cpp
Show inline comments
 
@@ -457,13 +457,13 @@ CommandCost CmdPlantTree(TileIndex tile,
 

	
 
				if (IsTileType(current_tile, MP_CLEAR)) {
 
					/* Remove fields or rocks. Note that the ground will get barrened */
 
					switch (GetRawClearGround(current_tile)) {
 
						case CLEAR_FIELDS:
 
						case CLEAR_ROCKS: {
 
							CommandCost ret = DoCommand(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
							CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
 
							if (ret.Failed()) return ret;
 
							cost.AddCost(ret);
 
							break;
 
						}
 

	
 
						default: break;
 
@@ -878,13 +878,13 @@ void InitializeTrees()
 
{
 
	_trees_tick_ctr = 0;
 
}
 

	
 
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 
{
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_trees_procs = {
 
	DrawTile_Trees,           // draw_tile_proc
 
	GetSlopePixelZ_Trees,     // get_slope_z_proc
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -415,21 +415,21 @@ CommandCost CmdBuildBridge(TileIndex end
 
	} else {
 
		/* Build a new bridge. */
 

	
 
		bool allow_on_slopes = (_settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER);
 

	
 
		/* Try and clear the start landscape */
 
		CommandCost ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_start, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost = ret;
 

	
 
		if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_north);
 

	
 
		/* Try and clear the end landscape */
 
		ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_end, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		/* false - end tile slope check */
 
		if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_south);
 
@@ -495,13 +495,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
				case MP_CLEAR:
 
					break;
 

	
 
				default:
 
	not_valid_below:;
 
					/* try and clear the middle landscape */
 
					ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
					ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
					break;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
@@ -669,13 +669,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
	Slope start_tileh = GetTileSlope(start_tile, &start_z);
 
	DiagDirection direction = GetInclinedSlopeDirection(start_tileh);
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE_FOR_TUNNEL);
 

	
 
	if (HasTileWaterGround(start_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 

	
 
	CommandCost ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, start_tile, 0, 0);
 
	if (ret.Failed()) return ret;
 

	
 
	/* XXX - do NOT change 'ret' in the loop, as it is used as the price
 
	 * for the clearing of the entrance of the tunnel. Assigning it to
 
	 * cost before the loop will yield different costs depending on start-
 
	 * position, because of increased-cost-by-length: 'cost += cost >> 3' */
 
@@ -729,13 +729,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 

	
 
	if (tiles > _settings_game.construction.max_tunnel_length) return_cmd_error(STR_ERROR_TUNNEL_TOO_LONG);
 

	
 
	if (HasTileWaterGround(end_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 

	
 
	/* Clear the tile in any case */
 
	ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, end_tile, 0, 0);
 
	if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 
	cost.AddCost(ret);
 

	
 
	/* slope of end tile must be complementary to the slope of the start tile */
 
	if (end_tileh != ComplementSlope(start_tileh)) {
 
		/* Mark the tile as already cleared for the terraform command.
 
@@ -761,13 +761,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
		ClearedObjectArea *begin = _cleared_object_areas.data();
 
		assert(coa >= begin && coa < begin + _cleared_object_areas.size());
 
		size_t coa_index = coa - begin;
 
		assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself
 
		coa = nullptr;
 

	
 
		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
 
		ret = DoCommand(flags, CMD_TERRAFORM_LAND, 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);
 
	}
 
	cost.AddCost(_price[PR_BUILD_TUNNEL]);
 

	
 
@@ -1843,13 +1843,13 @@ static void ChangeTileOwner_TunnelBridge
 
	if (new_owner != INVALID_OWNER) {
 
		SetTileOwner(tile, new_owner);
 
	} else {
 
		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(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
			[[maybe_unused]] CommandCost ret = DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
			assert(ret.Succeeded());
 
		} else {
 
			/* In any other case, we can safely reassign the ownership to OWNER_NONE. */
 
			SetTileOwner(tile, OWNER_NONE);
 
		}
 
	}
 
@@ -2034,13 +2034,13 @@ static CommandCost TerraformTile_TunnelB
 
		}
 

	
 
		/* Surface slope is valid and remains unchanged? */
 
		if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
 
	DrawTile_TunnelBridge,           // draw_tile_proc
 
	GetSlopePixelZ_TunnelBridge,     // get_slope_z_proc
 
	ClearTile_TunnelBridge,          // clear_tile_proc
src/vehicle.cpp
Show inline comments
 
@@ -304,13 +304,13 @@ void ShowNewGrfVehicleError(EngineID eng
 

	
 
	if (!HasBit(grfconfig->grf_bugs, bug_type)) {
 
		SetBit(grfconfig->grf_bugs, bug_type);
 
		SetDParamStr(0, grfconfig->GetName());
 
		SetDParam(1, engine);
 
		ShowErrorMessage(part1, part2, WL_CRITICAL);
 
		if (!_networking) DoCommand(0, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, 1, DC_EXEC, CMD_PAUSE);
 
		if (!_networking) DoCommand(DC_EXEC, CMD_PAUSE, 0, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, 1);
 
	}
 

	
 
	/* debug output */
 
	char buffer[512];
 

	
 
	SetDParamStr(0, grfconfig->GetName());
 
@@ -1052,13 +1052,13 @@ void CallVehicleTicks()
 
		int x = v->x_pos;
 
		int y = v->y_pos;
 
		int z = v->z_pos;
 

	
 
		const Company *c = Company::Get(_current_company);
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, (Money)c->settings.engine_renew_money));
 
		CommandCost res = DoCommand(0, v->index, 0, DC_EXEC, CMD_AUTOREPLACE_VEHICLE);
 
		CommandCost res = DoCommand(DC_EXEC, CMD_AUTOREPLACE_VEHICLE, 0, v->index, 0);
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, -(Money)c->settings.engine_renew_money));
 

	
 
		if (!IsLocalCompany()) continue;
 

	
 
		if (res.Succeeded() && res.GetCost() != 0) {
 
			ShowCostOrIncomeAnimation(x, y, z, res.GetCost());
 
@@ -1558,13 +1558,13 @@ void VehicleEnterDepot(Vehicle *v)
 
			/* We are heading for another depot, keep driving. */
 
			return;
 
		}
 

	
 
		if (v->current_order.IsRefit()) {
 
			Backup<CompanyID> cur_company(_current_company, v->owner, FILE_LINE);
 
			CommandCost cost = DoCommand(v->tile, v->index, v->current_order.GetRefitCargo() | 0xFF << 8, DC_EXEC, GetCmdRefitVeh(v));
 
			CommandCost cost = DoCommand(DC_EXEC, GetCmdRefitVeh(v), v->tile, v->index, v->current_order.GetRefitCargo() | 0xFF << 8);
 
			cur_company.Restore();
 

	
 
			if (cost.Failed()) {
 
				_vehicles_to_autoreplace[v] = false;
 
				if (v->owner == _local_company) {
 
					/* Notify the user that we stopped the vehicle */
 
@@ -2440,13 +2440,13 @@ CommandCost Vehicle::SendToDepot(DoComma
 
		this->current_order.MakeGoToDepot(destination, ODTF_MANUAL);
 
		if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT);
 
		SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
 

	
 
		/* 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(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 
			DoCommand(DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION, this->tile, this->index, 0);
 
		}
 

	
 
		if (this->type == VEH_AIRCRAFT) {
 
			Aircraft *a = Aircraft::From(this);
 
			if (a->state == FLYING && a->targetairport != destination) {
 
				/* The aircraft is now heading for a different hangar than the next in the orders */
src/vehicle_cmd.cpp
Show inline comments
 
@@ -179,13 +179,13 @@ CommandCost CmdBuildVehicle(TileIndex ti
 
			}
 
		}
 

	
 

	
 
		/* If we are not in DC_EXEC undo everything */
 
		if (flags != subflags) {
 
			DoCommand(0, v->index, 0, DC_EXEC, GetCmdSellVeh(v));
 
			DoCommand(DC_EXEC, GetCmdSellVeh(v), 0, v->index, 0);
 
		}
 
	}
 

	
 
	/* Only restore if we actually did some refitting */
 
	if (flags != subflags) RestoreRandomSeeds(saved_seeds);
 

	
 
@@ -662,13 +662,13 @@ CommandCost CmdMassStartStopVehicle(Tile
 

	
 
		if (!!(v->vehstatus & VS_STOPPED) != do_start) continue;
 

	
 
		if (!vehicle_list_window && !v->IsChainInDepot()) continue;
 

	
 
		/* Just try and don't care if some vehicle's can't be stopped. */
 
		DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE);
 
		DoCommand(flags, CMD_START_STOP_VEHICLE, tile, v->index, 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
@@ -694,13 +694,13 @@ CommandCost CmdDepotSellAllVehicles(Tile
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list);
 

	
 
	CommandCost last_error = CMD_ERROR;
 
	bool had_success = false;
 
	for (uint i = 0; i < list.size(); i++) {
 
		CommandCost ret = DoCommand(tile, list[i]->index | (1 << 20), 0, flags, sell_command);
 
		CommandCost ret = DoCommand(flags, sell_command, tile, list[i]->index | (1 << 20), 0);
 
		if (ret.Succeeded()) {
 
			cost.AddCost(ret);
 
			had_success = true;
 
		} else {
 
			last_error = ret;
 
		}
 
@@ -733,13 +733,13 @@ CommandCost CmdDepotMassAutoReplace(Tile
 
	for (uint i = 0; i < list.size(); i++) {
 
		const Vehicle *v = list[i];
 

	
 
		/* Ensure that the vehicle completely in the depot */
 
		if (!v->IsChainInDepot()) continue;
 

	
 
		CommandCost ret = DoCommand(0, v->index, 0, flags, CMD_AUTOREPLACE_VEHICLE);
 
		CommandCost ret = DoCommand(flags, CMD_AUTOREPLACE_VEHICLE, 0, v->index, 0);
 

	
 
		if (ret.Succeeded()) cost.AddCost(ret);
 
	}
 
	return cost;
 
}
 

	
 
@@ -872,17 +872,17 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
		 * 'new' vehicles whereas they would immediately be joined with a primary
 
		 * engine. This caused the vehicle to be not build as 'the limit' had been
 
		 * reached, resulting in partially build vehicles and such. */
 
		DoCommandFlag build_flags = flags;
 
		if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
 

	
 
		CommandCost cost = DoCommand(tile, v->engine_type | (1 << 16) | (CT_INVALID << 24), 0, build_flags, GetCmdBuildVeh(v));
 
		CommandCost cost = DoCommand(build_flags, GetCmdBuildVeh(v), 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(w_front->tile, w_front->index | (1 << 20), 0, flags, GetCmdSellVeh(w_front));
 
			if (w_front != nullptr) DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | (1 << 20), 0);
 
			return cost;
 
		}
 

	
 
		total_cost.AddCost(cost);
 

	
 
		if (flags & DC_EXEC) {
 
@@ -892,18 +892,18 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
				SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION);
 
			}
 

	
 
			if (v->type == VEH_TRAIN && !v->IsFrontEngine()) {
 
				/* this s a train car
 
				 * add this unit to the end of the train */
 
				CommandCost result = DoCommand(0, w->index | 1 << 20, w_rear->index, flags, CMD_MOVE_RAIL_VEHICLE);
 
				CommandCost result = DoCommand(flags, CMD_MOVE_RAIL_VEHICLE, 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(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
 
					DoCommand(w_front->tile, w->index       | 1 << 20, 0, flags, GetCmdSellVeh(w));
 
					DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | 1 << 20, 0);
 
					DoCommand(flags, GetCmdSellVeh(w)      , w_front->tile, w->index       | 1 << 20, 0);
 
					return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
 
				}
 
			} else {
 
				/* this is a front engine or not a train. */
 
				w_front = w;
 
				w->service_interval = v->service_interval;
 
@@ -918,13 +918,13 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
		/* for trains this needs to be the front engine due to the callback function */
 
		_new_vehicle_id = w_front->index;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Cloned vehicles belong to the same group */
 
		DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP);
 
		DoCommand(flags, CMD_ADD_VEHICLE_GROUP, 0, v_front->group_id, w_front->index);
 
	}
 

	
 

	
 
	/* Take care of refitting. */
 
	w = w_front;
 
	v = v_front;
 
@@ -940,13 +940,13 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
			if (flags & DC_EXEC) {
 
				assert(w != nullptr);
 

	
 
				/* 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(0, w->index, v->cargo_type | 1U << 25 | (subtype << 8), flags, GetCmdRefitVeh(v));
 
					CommandCost cost = DoCommand(flags, GetCmdRefitVeh(v), 0, w->index, v->cargo_type | 1U << 25 | (subtype << 8));
 
					if (cost.Succeeded()) total_cost.AddCost(cost);
 
				}
 

	
 
				if (w->IsGroundVehicle() && w->HasArticulatedPart()) {
 
					w = w->GetNextArticulatedPart();
 
				} else {
 
@@ -975,27 +975,27 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
	if (flags & DC_EXEC) {
 
		/*
 
		 * Set the orders of the vehicle. Cannot do it earlier as we need
 
		 * the vehicle refitted before doing this, otherwise the moved
 
		 * cargo types might not match (passenger vs non-passenger)
 
		 */
 
		CommandCost result = DoCommand(0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index, flags, CMD_CLONE_ORDER);
 
		CommandCost result = DoCommand(flags, CMD_CLONE_ORDER, 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(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
 
			DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | 1 << 20, 0);
 
			return result;
 
		}
 

	
 
		/* Now clone the vehicle's name, if it has one. */
 
		if (!v_front->name.empty()) CloneVehicleName(v_front, w_front);
 

	
 
		/* Since we can't estimate the cost of cloning a vehicle accurately we must
 
		 * 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(w_front->tile, w_front->index | 1 << 20, 0, flags, GetCmdSellVeh(w_front));
 
			DoCommand(flags, GetCmdSellVeh(w_front), w_front->tile, w_front->index | 1 << 20, 0);
 
			return total_cost;
 
		}
 
	}
 

	
 
	return total_cost;
 
}
 
@@ -1014,13 +1014,13 @@ static CommandCost SendAllVehiclesToDepo
 
	if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
 

	
 
	/* Send all the vehicles to a depot */
 
	bool had_success = false;
 
	for (uint i = 0; i < list.size(); i++) {
 
		const Vehicle *v = list[i];
 
		CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(vli.vtype));
 
		CommandCost ret = DoCommand(flags, GetCmdSendToDepot(vli.vtype), v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0);
 

	
 
		if (ret.Succeeded()) {
 
			had_success = true;
 

	
 
			/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
 
			 * In this case we know that at least one vehicle can be sent to a depot
src/vehicle_gui.cpp
Show inline comments
 
@@ -769,14 +769,14 @@ struct RefitWindow : public Window {
 
	 * @post String parameters have been set.
 
	 */
 
	StringID GetCapacityString(RefitOption *option) const
 
	{
 
		assert(_current_company == _local_company);
 
		Vehicle *v = Vehicle::Get(this->window_number);
 
		CommandCost cost = DoCommand(v->tile, this->selected_vehicle, option->cargo | option->subtype << 8 | this->num_vehicles << 16 |
 
				(int)this->auto_refit << 24, DC_QUERY_COST, GetCmdRefitVeh(v->type));
 
		CommandCost cost = DoCommand(DC_QUERY_COST, GetCmdRefitVeh(v->type), 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;
 

	
 
		SetDParam(0, option->cargo);
 
		SetDParam(1, _returned_refit_capacity);
 

	
src/water_cmd.cpp
Show inline comments
 
@@ -119,19 +119,19 @@ CommandCost CmdBuildShipDepot(TileIndex 
 

	
 
	WaterClass wc1 = GetWaterClass(tile);
 
	WaterClass wc2 = GetWaterClass(tile2);
 
	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
 

	
 
	bool add_cost = !IsWaterTile(tile);
 
	CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
 
	CommandCost ret = DoCommand(flags | DC_AUTO, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	if (ret.Failed()) return ret;
 
	if (add_cost) {
 
		cost.AddCost(ret);
 
	}
 
	add_cost = !IsWaterTile(tile2);
 
	ret = DoCommand(tile2, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
 
	ret = DoCommand(flags | DC_AUTO, CMD_LANDSCAPE_CLEAR, tile2, 0, 0);
 
	if (ret.Failed()) return ret;
 
	if (add_cost) {
 
		cost.AddCost(ret);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
@@ -303,31 +303,31 @@ static CommandCost DoBuildLock(TileIndex
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
 
	if (ret.Failed()) return ret;
 

	
 
	/* middle tile */
 
	WaterClass wc_middle = HasTileWaterGround(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL;
 
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	if (ret.Failed()) return ret;
 
	cost.AddCost(ret);
 

	
 
	/* lower tile */
 
	if (!IsWaterTile(tile - delta)) {
 
		ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile - delta, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 
		cost.AddCost(_price[PR_BUILD_CANAL]);
 
	}
 
	if (!IsTileFlat(tile - delta)) {
 
		return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
	}
 
	WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
 

	
 
	/* upper tile */
 
	if (!IsWaterTile(tile + delta)) {
 
		ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile + delta, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 
		cost.AddCost(_price[PR_BUILD_CANAL]);
 
	}
 
	if (!IsTileFlat(tile + delta)) {
 
		return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
@@ -477,13 +477,13 @@ CommandCost CmdBuildCanal(TileIndex tile
 

	
 
		bool water = IsWaterTile(current_tile);
 

	
 
		/* 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(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
 
		if (ret.Failed()) return ret;
 

	
 
		if (!water) cost.AddCost(ret);
 

	
 
		if (flags & DC_EXEC) {
 
			switch (wc) {
 
@@ -1132,13 +1132,13 @@ void DoFloodTile(TileIndex target)
 
					flooded = true;
 
					break;
 
				}
 
				FALLTHROUGH;
 

	
 
			case MP_CLEAR:
 
				if (DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
				if (DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, target, 0, 0).Succeeded()) {
 
					MakeShore(target);
 
					MarkTileDirtyByTile(target);
 
					flooded = true;
 
				}
 
				break;
 

	
 
@@ -1147,13 +1147,13 @@ void DoFloodTile(TileIndex target)
 
		}
 
	} else {
 
		/* Flood vehicles */
 
		FloodVehicles(target);
 

	
 
		/* flood flat tile */
 
		if (DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
		if (DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, target, 0, 0).Succeeded()) {
 
			MakeSea(target);
 
			MarkTileDirtyByTile(target);
 
			flooded = true;
 
		}
 
	}
 

	
 
@@ -1199,13 +1199,13 @@ static void DoDryUp(TileIndex tile)
 
			MarkTileDirtyByTile(tile);
 
			break;
 

	
 
		case MP_WATER:
 
			assert(IsCoast(tile));
 

	
 
			if (DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
			if (DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded()) {
 
				MakeClear(tile, CLEAR_GRASS, 3);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
@@ -1358,13 +1358,13 @@ static void ChangeTileOwner_Water(TileIn
 

	
 
		SetTileOwner(tile, new_owner);
 
		return;
 
	}
 

	
 
	/* Remove depot */
 
	if (IsShipDepot(tile)) DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
	if (IsShipDepot(tile)) DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, 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. */
 
	if (IsTileOwner(tile, old_owner)) {
 
		if (GetWaterClass(tile) == WATER_CLASS_CANAL && !is_lock_middle) Company::Get(old_owner)->infrastructure.water--;
 
		SetTileOwner(tile, OWNER_NONE);
 
@@ -1378,13 +1378,13 @@ static VehicleEnterTileStatus VehicleEnt
 

	
 
static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 
{
 
	/* Canals can't be terraformed */
 
	if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_water_procs = {
 
	DrawTile_Water,           // draw_tile_proc
 
	GetSlopePixelZ_Water,     // get_slope_z_proc
src/waypoint_cmd.cpp
Show inline comments
 
@@ -312,13 +312,13 @@ CommandCost CmdBuildBuoy(TileIndex tile,
 
	/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
 
	Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
 
	if (wp == nullptr && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
 
	if (!IsWaterTile(tile)) {
 
		CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
 
		CommandCost ret = DoCommand(flags | DC_AUTO, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (wp == nullptr) {
0 comments (0 inline, 0 general)