Changeset - r25562:30716ba6a396
[Not reviewed]
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -706,25 +706,25 @@ static CommandCost ReplaceChain(Vehicle 
 
}
 

	
 
/**
 
 * Autoreplaces a vehicle
 
 * Trains are replaced as a whole chain, free wagons in depot are replaced on their own
 
 * @param tile not used
 
 * @param flags type of operation
 
 * @param p1 Index of vehicle
 
 * @param p2 not used
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (!v->IsChainInDepot()) return CMD_ERROR;
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	bool free_wagon = false;
 
	if (v->type == VEH_TRAIN) {
 
@@ -799,25 +799,25 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
 * Change engine renewal parameters
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 packed data
 
 *   - bit      0 = replace when engine gets old?
 
 *   - bits 16-31 = engine group
 
 * @param p2 packed data
 
 *   - bits  0-15 = old engine type
 
 *   - bits 16-31 = new engine type
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Company *c = Company::GetIfValid(_current_company);
 
	if (c == nullptr) return CMD_ERROR;
 

	
 
	EngineID old_engine_type = GB(p2, 0, 16);
 
	EngineID new_engine_type = GB(p2, 16, 16);
 
	GroupID id_g = GB(p1, 16, 16);
 
	CommandCost cost;
 

	
 
	if (Group::IsValidID(id_g) ? Group::Get(id_g)->owner != _current_company : !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
 
	if (!Engine::IsValidID(old_engine_type)) return CMD_ERROR;
 

	
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -1221,25 +1221,25 @@ struct BuildVehicleWindow : Window {
 

	
 
		if (this->sel_engine == INVALID_ENGINE) return;
 

	
 
		const Engine *e = Engine::Get(this->sel_engine);
 
		if (!e->CanCarryCargo()) {
 
			this->te.cost = 0;
 
			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), nullptr);
 
			CommandCost ret = DoCommand(this->window_number, this->sel_engine | (cargo << 24), 0, DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type));
 
			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;
 
			}
 
		}
 

	
 
		/* Purchase test was not possible or failed, fill in the defaults instead. */
 
		this->te.cost     = 0;
 
		this->te.capacity = e->GetDisplayDefaultCapacity(&this->te.mail_capacity);
src/command.cpp
Show inline comments
 
@@ -456,25 +456,25 @@ CommandCost DoCommand(const CommandConta
 
 * 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 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 char *text)
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const std::string &text)
 
{
 
	CommandCost res;
 

	
 
	/* Do not even think about executing out-of-bounds tile-commands */
 
	if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (flags & DC_ALL_TILES) == 0))) return CMD_ERROR;
 

	
 
	/* Chop of any CMD_MSG or other flags; we don't need those here */
 
	CommandProc *proc = _command_proc_table[cmd & CMD_ID_MASK].proc;
 

	
 
	_docommand_recursive++;
 

	
 
	/* only execute the test call if it's toplevel, or we're not execing. */
 
@@ -549,25 +549,25 @@ bool DoCommandP(const CommandContainer *
 
 * \a tile, \a p1, and \a p2 are from the #CommandProc function. The parameter \a cmd is the command to execute.
 
 * The parameter \a my_cmd is used to indicate if the command is from a company or the server.
 
 *
 
 * @param tile The tile to perform a command on (see #CommandProc)
 
 * @param p1 Additional data for the command (see #CommandProc)
 
 * @param p2 Additional data for the command (see #CommandProc)
 
 * @param cmd The command to execute (a CMD_* value)
 
 * @param callback A callback function to call after the command is finished
 
 * @param text The text to pass
 
 * @param my_cmd indicator if the command is from a company or server (to display error messages for a user)
 
 * @return \c true if the command succeeded, else \c false.
 
 */
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd)
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, bool my_cmd)
 
{
 
	/* Cost estimation is generally only done when the
 
	 * local user presses shift while doing something.
 
	 * However, in case of incoming network commands,
 
	 * map generation or the pause button we do want
 
	 * to execute. */
 
	bool estimate_only = _shift_pressed && IsLocalCompany() &&
 
			!_generating_world &&
 
			!(cmd & CMD_NETWORK_COMMAND) &&
 
			!(GetCommandFlags(cmd) & CMD_NO_EST);
 

	
 
	/* We're only sending the command, so don't do
 
@@ -622,25 +622,25 @@ bool DoCommandP(TileIndex tile, uint32 p
 
 * Helper function for the toplevel network safe docommand function for the current company.
 
 *
 
 * @param tile The tile to perform a command on (see #CommandProc)
 
 * @param p1 Additional data for the command (see #CommandProc)
 
 * @param p2 Additional data for the command (see #CommandProc)
 
 * @param cmd The command to execute (a CMD_* value)
 
 * @param callback A callback function to call after the command is finished
 
 * @param text The text to pass
 
 * @param my_cmd indicator if the command is from a company or server (to display error messages for a user)
 
 * @param estimate_only whether to give only the estimate or also execute the command
 
 * @return the command cost of this function.
 
 */
 
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only)
 
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, bool my_cmd, bool estimate_only)
 
{
 
	/* Prevent recursion; it gives a mess over the network */
 
	assert(_docommand_recursive == 0);
 
	_docommand_recursive = 1;
 

	
 
	/* Reset the state. */
 
	_additional_cash_required = 0;
 

	
 
	/* Get pointer to command handler */
 
	byte cmd_id = cmd & CMD_ID_MASK;
 
	assert(cmd_id < lengthof(_command_proc_table));
 

	
 
@@ -687,45 +687,45 @@ CommandCost DoCommandPInternal(TileIndex
 
	assert(exec_as_spectator ? _current_company == COMPANY_SPECTATOR : cur_company.Verify());
 

	
 
	/* If the command fails, we're doing an estimate
 
	 * or the player does not have enough money
 
	 * (unless it's a command where the test and
 
	 * execution phase might return different costs)
 
	 * we bail out here. */
 
	if (res.Failed() || estimate_only ||
 
			(!test_and_exec_can_differ && !CheckCompanyHasMoney(res))) {
 
		if (!_networking || _generating_world || (cmd & CMD_NETWORK_COMMAND) != 0) {
 
			/* Log the failed command as well. Just to be able to be find
 
			 * causes of desyncs due to bad command test implementations. */
 
			DEBUG(desync, 1, "cmdf: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, GetCommandName(cmd));
 
			DEBUG(desync, 1, "cmdf: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text.c_str(), GetCommandName(cmd));
 
		}
 
		cur_company.Restore();
 
		return_dcpi(res);
 
	}
 

	
 
	/*
 
	 * If we are in network, and the command is not from the network
 
	 * send it to the command-queue and abort execution
 
	 */
 
	if (_networking && !_generating_world && !(cmd & CMD_NETWORK_COMMAND)) {
 
		NetworkSendCommand(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text, _current_company);
 
		cur_company.Restore();
 

	
 
		/* Don't return anything special here; no error, no costs.
 
		 * This way it's not handled by DoCommand and only the
 
		 * actual execution of the command causes messages. Also
 
		 * reset the storages as we've not executed the command. */
 
		return_dcpi(CommandCost());
 
	}
 
	DEBUG(desync, 1, "cmd: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, GetCommandName(cmd));
 
	DEBUG(desync, 1, "cmd: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text.c_str(), GetCommandName(cmd));
 

	
 
	/* Actually try and execute the command. If no cost-type is given
 
	 * use the construction one */
 
	_cleared_object_areas.clear();
 
	BasePersistentStorageArray::SwitchMode(PSM_ENTER_COMMAND);
 
	CommandCost res2 = proc(tile, flags | DC_EXEC, p1, p2, text);
 
	BasePersistentStorageArray::SwitchMode(PSM_LEAVE_COMMAND);
 

	
 
	if (cmd_id == CMD_COMPANY_CTRL) {
 
		cur_company.Trash();
 
		/* We are a new company                  -> Switch to new local company.
 
		 * We were closed down                   -> Switch to spectator
src/command_func.h
Show inline comments
 
@@ -23,33 +23,33 @@
 
static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
 

	
 
/**
 
 * Returns from a function with a specific StringID as error.
 
 *
 
 * This macro is used to return from a function. The parameter contains the
 
 * 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 char *text = nullptr);
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, 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 char *text = nullptr, bool my_cmd = true);
 
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 char *text, bool my_cmd, bool estimate_only);
 
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, bool my_cmd, bool estimate_only);
 

	
 
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company);
 
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, CompanyID company);
 

	
 
extern Money _additional_cash_required;
 

	
 
bool IsValidCommand(uint32 cmd);
 
CommandFlags GetCommandFlags(uint32 cmd);
 
const char *GetCommandName(uint32 cmd);
 
Money GetAvailableMoneyForCommand();
 
bool IsCommandAllowedWhilePaused(uint32 cmd);
 

	
 
/**
 
 * Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
 
 * @param cmd_flags Flags from GetCommandFlags
src/command_type.h
Show inline comments
 
@@ -434,25 +434,25 @@ enum CommandPauseLevel {
 
 * The flag parameter is filled with flags from the DC_* enumeration. The parameters
 
 * p1 and p2 are filled with parameters for the command like "which road type", "which
 
 * order" or "direction". Each function should mentioned in there doxygen comments
 
 * the usage of these parameters.
 
 *
 
 * @param tile The tile to apply a command on
 
 * @param flags Flags for the command, from the DC_* enumeration
 
 * @param p1 Additional data for the command
 
 * @param p2 Additional data for the command
 
 * @param text Additional text
 
 * @return The CommandCost of the command, which can be succeeded or failed.
 
 */
 
typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
 
typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text);
 

	
 
/**
 
 * Define a command with the flags which belongs to it.
 
 *
 
 * This struct connect a command handler function with the flags created with
 
 * the #CMD_AUTO, #CMD_OFFLINE and #CMD_SERVER values.
 
 */
 
struct Command {
 
	CommandProc *proc;  ///< The procedure to actually executing
 
	const char *name;   ///< A human readable name for the procedure
 
	CommandFlags flags; ///< The (command) flags to that apply to this command
 
	CommandType type;   ///< The type of command.
src/company_cmd.cpp
Show inline comments
 
@@ -798,25 +798,25 @@ void CompanyAdminRemove(CompanyID compan
 
/**
 
 * Control the companies: add, delete, etc.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various functionality
 
 * - bits 0..15: CompanyCtrlAction
 
 * - bits 16..23: CompanyID
 
 * - bits 24..31: CompanyRemoveReason (with CCA_DELETE)
 
 * @param p2 ClientID
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
 
	CompanyID company_id = (CompanyID)GB(p1, 16, 8);
 

	
 
	switch ((CompanyCtrlAction)GB(p1, 0, 16)) {
 
		case CCA_NEW: { // Create a new company
 
			/* This command is only executed in a multiplayer game */
 
			if (!_networking) return CMD_ERROR;
 

	
 
			/* Has the network client a correct ClientIndex? */
 
			if (!(flags & DC_EXEC)) return CommandCost();
 

	
 
@@ -923,49 +923,49 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Change the company manager's face.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 face bitmasked
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CompanyManagerFace cmf = (CompanyManagerFace)p2;
 

	
 
	if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Company::Get(_current_company)->face = cmf;
 
		MarkWholeScreenDirty();
 
	}
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Change the company's company-colour
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 bitstuffed:
 
 * p1 bits 0-7 scheme to set
 
 * p1 bit 8 set first/second colour
 
 * @param p2 new colour for vehicles, property, etc.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Colours colour = Extract<Colours, 0, 8>(p2);
 
	LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
 
	bool second = HasBit(p1, 8);
 

	
 
	if (scheme >= LS_END || (colour >= COLOUR_END && colour != INVALID_COLOUR)) return CMD_ERROR;
 

	
 
	/* Default scheme can't be reset to invalid. */
 
	if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;
 

	
 
	Company *c = Company::Get(_current_company);
 

	
 
@@ -1058,27 +1058,27 @@ static bool IsUniqueCompanyName(const st
 
	return true;
 
}
 

	
 
/**
 
 * Change the name of the company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_COMPANY_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Company *c = Company::Get(_current_company);
 
		if (reset) {
 
			c->name.clear();
 
		} else {
 
			c->name = text;
 
@@ -1104,46 +1104,43 @@ static bool IsUniquePresidentName(const 
 
	return true;
 
}
 

	
 
/**
 
 * Change the name of the president.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Company *c = Company::Get(_current_company);
 

	
 
		if (reset) {
 
			c->president_name.clear();
 
		} else {
 
			c->president_name = text;
 

	
 
			if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) {
 
				char buf[80];
 

	
 
				seprintf(buf, lastof(buf), "%s Transport", text);
 
				DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, buf);
 
				DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, text + " Transport");
 
			}
 
		}
 

	
 
		MarkWholeScreenDirty();
 
		CompanyAdminUpdate(c);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Get the service interval for the given company and vehicle type.
 
@@ -1192,25 +1189,25 @@ uint32 CompanyInfrastructure::GetTramTot
 
/**
 
 * Transfer funds (money) from one company to another.
 
 * To prevent abuse in multiplayer games you can only send money to other
 
 * companies if you have paid off your loan (either explicitly, or implicitly
 
 * given the fact that you have more money than loan).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to transfer; max 20.000.000
 
 * @param p2 the company to transfer the money to
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (!_settings_game.economy.give_money) return CMD_ERROR;
 

	
 
	const Company *c = Company::Get(_current_company);
 
	CommandCost amount(EXPENSES_OTHER, std::min<Money>(p1, 20000000LL));
 
	CompanyID dest_company = (CompanyID)p2;
 

	
 
	/* You can only transfer funds that is in excess of your loan */
 
	if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return_cmd_error(STR_ERROR_INSUFFICIENT_FUNDS);
 
	if (!Company::IsValidID(dest_company)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
src/depot_cmd.cpp
Show inline comments
 
@@ -35,33 +35,33 @@ static bool IsUniqueDepotName(const std:
 
	return true;
 
}
 

	
 
/**
 
 * Rename a depot.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 id of depot
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Depot *d = Depot::GetIfValid(p1);
 
	if (d == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckTileOwnership(d->xy);
 
	if (ret.Failed()) return ret;
 

	
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_DEPOT_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueDepotName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (reset) {
 
			d->name.clear();
 
			MakeDefaultName(d);
 
		} else {
 
			d->name = text;
src/economy.cpp
Show inline comments
 
@@ -2008,25 +2008,25 @@ static void DoAcquireCompany(Company *c)
 

	
 
extern int GetAmountOwnedBy(const Company *c, Owner owner);
 

	
 
/**
 
 * Acquire shares in an opposing company.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 company to buy the shares from
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CommandCost cost(EXPENSES_OTHER);
 
	CompanyID target_company = (CompanyID)p1;
 
	Company *c = Company::GetIfValid(target_company);
 

	
 
	/* Check if buying shares is allowed (protection against modified clients)
 
	 * Cannot buy own shares */
 
	if (c == nullptr || !_settings_game.economy.allow_shares || _current_company == target_company) return CMD_ERROR;
 

	
 
	/* Protect new companies from hostile takeovers */
 
	if (_cur_year - c->inaugurated_year < _settings_game.economy.min_years_for_shares) return_cmd_error(STR_ERROR_PROTECTED);
 

	
 
@@ -2060,25 +2060,25 @@ CommandCost CmdBuyShareInCompany(TileInd
 
	return cost;
 
}
 

	
 
/**
 
 * Sell shares in an opposing company.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 company to sell the shares from
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CompanyID target_company = (CompanyID)p1;
 
	Company *c = Company::GetIfValid(target_company);
 

	
 
	/* Cannot sell own shares */
 
	if (c == nullptr || _current_company == target_company) return CMD_ERROR;
 

	
 
	/* Check if selling shares is allowed (protection against modified clients).
 
	 * However, we must sell shares of companies being closed down. */
 
	if (!_settings_game.economy.allow_shares && !(flags & DC_BANKRUPT)) return CMD_ERROR;
 

	
 
	/* Those lines are here for network-protection (clients can be slow) */
 
@@ -2101,25 +2101,25 @@ CommandCost CmdSellShareInCompany(TileIn
 
/**
 
 * Buy up another company.
 
 * When a competing company is gone bankrupt you get the chance to purchase
 
 * that company.
 
 * @todo currently this only works for AI companies
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 company to buy up
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CompanyID target_company = (CompanyID)p1;
 
	Company *c = Company::GetIfValid(target_company);
 
	if (c == nullptr) return CMD_ERROR;
 

	
 
	/* Disable takeovers when not asked */
 
	if (!HasBit(c->bankrupt_asked, _current_company)) return CMD_ERROR;
 

	
 
	/* Disable taking over the local company in singleplayer mode */
 
	if (!_networking && _local_company == c->index) return CMD_ERROR;
 

	
 
	/* Do not allow companies to take over themselves */
src/engine.cpp
Show inline comments
 
@@ -873,70 +873,70 @@ void ClearEnginesHiddenFlagOfCompany(Com
 
	}
 
}
 

	
 
/**
 
 * Set the visibility of an engine.
 
 * @param tile Unused.
 
 * @param flags Operation to perform.
 
 * @param p1 Unused.
 
 * @param p2 Bit 31: 0=visible, 1=hidden, other bits for the #EngineID.
 
 * @param text Unused.
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Engine *e = Engine::GetIfValid(GB(p2, 0, 31));
 
	if (e == nullptr || _current_company >= MAX_COMPANIES) return CMD_ERROR;
 
	if (!IsEngineBuildable(e->index, e->type, _current_company)) return CMD_ERROR;
 

	
 
	if ((flags & DC_EXEC) != 0) {
 
		SB(e->company_hidden, _current_company, 1, GB(p2, 31, 1));
 
		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Accept an engine prototype. XXX - it is possible that the top-company
 
 * changes while you are waiting to accept the offer? Then it becomes invalid
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 engine-prototype offered
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Engine *e = Engine::GetIfValid(p1);
 
	if (e == nullptr || !(e->flags & ENGINE_EXCLUSIVE_PREVIEW) || e->preview_company != _current_company) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company);
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Allow or forbid a specific company to use an engine
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 engine id
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0 - 7) - Company to allow/forbid the use of an engine.
 
 * - p2 = (bit 31) - 0 to forbid, 1 to allow.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdEngineCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdEngineCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	EngineID engine_id = (EngineID)p1;
 
	CompanyID company_id = (CompanyID)GB(p2, 0, 8);
 
	bool allow = HasBit(p2, 31);
 

	
 
	if (!Engine::IsValidID(engine_id) || !Company::IsValidID(company_id)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (allow) {
 
			EnableEngineForCompany(engine_id, company_id);
 
		} else {
 
@@ -1070,30 +1070,30 @@ static bool IsUniqueEngineName(const std
 
	return true;
 
}
 

	
 
/**
 
 * Rename an engine.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 engine ID to rename
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Engine *e = Engine::GetIfValid(p1);
 
	if (e == nullptr) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_ENGINE_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueEngineName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (reset) {
 
			e->name.clear();
 
		} else {
 
			e->name = text;
 
		}
src/goal.cpp
Show inline comments
 
@@ -34,33 +34,33 @@ INSTANTIATE_POOL_METHODS(Goal)
 

	
 
/**
 
 * Create a new goal.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  7) - GoalType of destination.
 
 * - p1 = (bit  8 - 15) - Company for which this goal is.
 
 * @param p2 GoalTypeID of destination.
 
 * @param text Text of the goal.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (!Goal::CanAllocateItem()) return CMD_ERROR;
 

	
 
	GoalType type = (GoalType)GB(p1, 0, 8);
 
	CompanyID company = (CompanyID)GB(p1, 8, 8);
 

	
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (StrEmpty(text)) return CMD_ERROR;
 
	if (text.empty()) return CMD_ERROR;
 
	if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
 

	
 
	switch (type) {
 
		case GT_NONE:
 
			if (p2 != 0) return CMD_ERROR;
 
			break;
 

	
 
		case GT_TILE:
 
			if (!IsValidTile(p2)) return CMD_ERROR;
 
			break;
 

	
 
		case GT_INDUSTRY:
 
@@ -81,25 +81,25 @@ CommandCost CmdCreateGoal(TileIndex tile
 
			if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return CMD_ERROR;
 
			break;
 
		}
 

	
 
		default: return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Goal *g = new Goal();
 
		g->type = type;
 
		g->dst = p2;
 
		g->company = company;
 
		g->text = stredup(text);
 
		g->text = stredup(text.c_str());
 
		g->progress = nullptr;
 
		g->completed = false;
 

	
 
		if (g->company == INVALID_COMPANY) {
 
			InvalidateWindowClassesData(WC_GOALS_LIST);
 
		} else {
 
			InvalidateWindowData(WC_GOALS_LIST, g->company);
 
		}
 
		if (Goal::GetNumItems() == 1) InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
 

	
 
		_new_goal_id = g->index;
 
	}
 
@@ -107,25 +107,25 @@ CommandCost CmdCreateGoal(TileIndex tile
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Remove a goal.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 GoalID to remove.
 
 * @param p2 unused.
 
 * @param text unused.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (!Goal::IsValidID(p1)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Goal *g = Goal::Get(p1);
 
		CompanyID c = g->company;
 
		delete g;
 

	
 
		if (c == INVALID_COMPANY) {
 
			InvalidateWindowClassesData(WC_GOALS_LIST);
 
		} else {
 
@@ -137,88 +137,88 @@ CommandCost CmdRemoveGoal(TileIndex tile
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Update goal text of a goal.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 GoalID to update.
 
 * @param p2 unused
 
 * @param text Text of the goal.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetGoalText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetGoalText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (!Goal::IsValidID(p1)) return CMD_ERROR;
 
	if (StrEmpty(text)) return CMD_ERROR;
 
	if (text.empty()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Goal *g = Goal::Get(p1);
 
		free(g->text);
 
		g->text = stredup(text);
 
		g->text = stredup(text.c_str());
 

	
 
		if (g->company == INVALID_COMPANY) {
 
			InvalidateWindowClassesData(WC_GOALS_LIST);
 
		} else {
 
			InvalidateWindowData(WC_GOALS_LIST, g->company);
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Update progress text of a goal.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 GoalID to update.
 
 * @param p2 unused
 
 * @param text Progress text of the goal.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetGoalProgress(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetGoalProgress(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (!Goal::IsValidID(p1)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Goal *g = Goal::Get(p1);
 
		free(g->progress);
 
		if (StrEmpty(text)) {
 
		if (text.empty()) {
 
			g->progress = nullptr;
 
		} else {
 
			g->progress = stredup(text);
 
			g->progress = stredup(text.c_str());
 
		}
 

	
 
		if (g->company == INVALID_COMPANY) {
 
			InvalidateWindowClassesData(WC_GOALS_LIST);
 
		} else {
 
			InvalidateWindowData(WC_GOALS_LIST, g->company);
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Update completed state of a goal.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 GoalID to update.
 
 * @param p2 completed state. If goal is completed, set to 1, otherwise 0.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetGoalCompleted(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetGoalCompleted(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (!Goal::IsValidID(p1)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Goal *g = Goal::Get(p1);
 
		g->completed = p2 == 1;
 

	
 
		if (g->company == INVALID_COMPANY) {
 
			InvalidateWindowClassesData(WC_GOALS_LIST);
 
		} else {
 
			InvalidateWindowData(WC_GOALS_LIST, g->company);
 
@@ -233,72 +233,72 @@ CommandCost CmdSetGoalCompleted(TileInde
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 - 15) - Unique ID to use for this question.
 
 * - p1 = (bit 16 - 31) - Company or client for which this question is.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0 - 17) - Buttons of the question.
 
 * - p2 = (bit 29 - 30) - Question type.
 
 * - p2 = (bit 31) - Question target: 0 - company, 1 - client.
 
 * @param text Text of the question.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	uint16 uniqueid = (uint16)GB(p1, 0, 16);
 
	CompanyID company = (CompanyID)GB(p1, 16, 8);
 
	ClientID client = (ClientID)GB(p1, 16, 16);
 

	
 
	static_assert(GOAL_QUESTION_BUTTON_COUNT < 29);
 
	uint32 button_mask = GB(p2, 0, GOAL_QUESTION_BUTTON_COUNT);
 
	byte type = GB(p2, 29, 2);
 
	bool is_client = HasBit(p2, 31);
 

	
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (StrEmpty(text)) return CMD_ERROR;
 
	if (text.empty()) return CMD_ERROR;
 
	if (is_client) {
 
		/* Only check during pre-flight; the client might have left between
 
		 * testing and executing. In that case it is fine to just ignore the
 
		 * fact the client is no longer here. */
 
		if (!(flags & DC_EXEC) && _network_server && NetworkClientInfo::GetByClientID(client) == nullptr) return CMD_ERROR;
 
	} else {
 
		if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
 
	}
 
	uint min_buttons = (type == GQT_QUESTION ? 1 : 0);
 
	if (CountBits(button_mask) < min_buttons || CountBits(button_mask) > 3) return CMD_ERROR;
 
	if (type >= GQT_END) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (is_client) {
 
			if (client != _network_own_client_id) return CommandCost();
 
		} else {
 
			if (company == INVALID_COMPANY && !Company::IsValidID(_local_company)) return CommandCost();
 
			if (company != INVALID_COMPANY && company != _local_company) return CommandCost();
 
		}
 
		ShowGoalQuestion(uniqueid, type, button_mask, text);
 
		ShowGoalQuestion(uniqueid, type, button_mask, text.c_str());
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Reply to a goal question.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 Unique ID to use for this question.
 
 * @param p2 Button the company pressed
 
 * @param text Text of the question.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdGoalQuestionAnswer(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdGoalQuestionAnswer(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (p1 > UINT16_MAX) return CMD_ERROR;
 
	if (p2 >= GOAL_QUESTION_BUTTON_COUNT) return CMD_ERROR;
 

	
 
	if (_current_company == OWNER_DEITY) {
 
		/* It has been requested to close this specific question on all clients */
 
		if (flags & DC_EXEC) DeleteWindowById(WC_GOAL_QUESTION, p1);
 
		return CommandCost();
 
	}
 

	
 
	if (_networking && _local_company == _current_company) {
 
		/* Somebody in the same company answered the question. Close the window */
src/group_cmd.cpp
Show inline comments
 
@@ -291,25 +291,25 @@ Group::Group(Owner owner)
 
}
 

	
 

	
 
/**
 
 * Create a new vehicle group.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1   vehicle type
 
 * @param p2   parent groupid
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleType vt = Extract<VehicleType, 0, 3>(p1);
 
	if (!IsCompanyBuildableVehicleType(vt)) return CMD_ERROR;
 

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

	
 
	const Group *pg = Group::GetIfValid(GB(p2, 0, 16));
 
	if (pg != nullptr) {
 
		if (pg->owner != _current_company) return CMD_ERROR;
 
		if (pg->vehicle_type != vt) return CMD_ERROR;
 
	}
 

	
 
@@ -341,25 +341,25 @@ CommandCost CmdCreateGroup(TileIndex til
 

	
 

	
 
/**
 
 * Add all vehicles in the given group to the default group and then deletes the group.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1   index of array group
 
 *      - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
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);
 

	
 
	/* Delete sub-groups */
 
	for (const Group *gp : Group::Iterate()) {
 
		if (gp->parent == g->index) {
 
			DoCommand(0, gp->index, 0, flags, CMD_DELETE_GROUP);
 
		}
 
@@ -395,32 +395,32 @@ CommandCost CmdDeleteGroup(TileIndex til
 
/**
 
 * Alter a group
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 *   - p1 bit 16: 0 - Rename grouop
 
 *                1 - Set group parent
 
 * @param p2   parent group index
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdAlterGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAlterGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Group *g = Group::GetIfValid(GB(p1, 0, 16));
 
	if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
 

	
 
	if (!HasBit(p1, 16)) {
 
		/* Rename group */
 
		bool reset = StrEmpty(text);
 
		bool reset = text.empty();
 

	
 
		if (!reset) {
 
			if (Utf8StringLength(text) >= MAX_LENGTH_GROUP_NAME_CHARS) return CMD_ERROR;
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			/* Assign the new one */
 
			if (reset) {
 
				g->name.clear();
 
			} else {
 
				g->name = text;
 
			}
 
@@ -499,41 +499,41 @@ static void AddVehicleToGroup(Vehicle *v
 
/**
 
 * Add a vehicle to a group
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 * @param p2   vehicle to add to a group
 
 *   - p2 bit 0-19 : VehicleID
 
 *   - p2 bit   31 : Add shared vehicles as well.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(GB(p2, 0, 20));
 
	GroupID new_g = p1;
 

	
 
	if (v == nullptr || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g) && new_g != NEW_GROUP)) return CMD_ERROR;
 

	
 
	if (Group::IsValidID(new_g)) {
 
		Group *g = Group::Get(new_g);
 
		if (g->owner != _current_company || g->vehicle_type != v->type) return CMD_ERROR;
 
	}
 

	
 
	if (v->owner != _current_company || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	if (new_g == NEW_GROUP) {
 
		/* Create new group. */
 
		CommandCost ret = CmdCreateGroup(0, flags, v->type, INVALID_GROUP, nullptr);
 
		CommandCost ret = CmdCreateGroup(0, flags, v->type, INVALID_GROUP, {});
 
		if (ret.Failed()) return ret;
 

	
 
		new_g = _new_group_id;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		AddVehicleToGroup(v, new_g);
 

	
 
		if (HasBit(p2, 31)) {
 
			/* Add vehicles in the shared order list as well. */
 
			for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
 
				if (v2->group_id != new_g) AddVehicleToGroup(v2, new_g);
 
@@ -556,25 +556,25 @@ CommandCost CmdAddVehicleGroup(TileIndex
 
}
 

	
 
/**
 
 * Add all shared vehicles of all vehicles from a group
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1   index of group array
 
 *  - p1 bit 0-15 : GroupID
 
 * @param p2   type of vehicles
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleType type = Extract<VehicleType, 0, 3>(p2);
 
	GroupID id_g = p1;
 
	if (!Group::IsValidID(id_g) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* Find the first front engine which belong to the group id_g
 
		 * then add all shared vehicles of this front engine to the group id_g */
 
		for (const Vehicle *v : Vehicle::Iterate()) {
 
			if (v->type == type && v->IsPrimaryVehicle()) {
 
				if (v->group_id != id_g) continue;
 

	
 
@@ -593,25 +593,25 @@ CommandCost CmdAddSharedVehicleGroup(Til
 

	
 

	
 
/**
 
 * Remove all vehicles from a group
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1   index of group array
 
 * - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	GroupID old_g = p1;
 
	Group *g = Group::GetIfValid(old_g);
 

	
 
	if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* 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;
 

	
 
@@ -627,25 +627,25 @@ CommandCost CmdRemoveAllVehiclesGroup(Ti
 
}
 

	
 
/**
 
 * Set the livery for a vehicle group.
 
 * @param tile      Unused.
 
 * @param flags     Command flags.
 
 * @param p1
 
 * - p1 bit  0-15   Group ID.
 
 * @param p2
 
 * - p2 bit  8      Set secondary instead of primary colour
 
 * - p2 bit 16-23   Colour.
 
 */
 
CommandCost CmdSetGroupLivery(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetGroupLivery(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Group *g = Group::GetIfValid(p1);
 
	bool primary = !HasBit(p2, 8);
 
	Colours colour = Extract<Colours, 16, 8>(p2);
 

	
 
	if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
 

	
 
	if (colour >= COLOUR_END && colour != INVALID_COLOUR) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (primary) {
 
			SB(g->livery.in_use, 0, 1, colour != INVALID_COLOUR);
 
@@ -688,25 +688,25 @@ static void SetGroupFlag(Group *g, Group
 
 * (Un)set group flag from a group
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1   index of group array
 
 * - p1 bit 0-15  : GroupID
 
 * - p1 bit 16-18 : Flag to set, by value not bit.
 
 * @param p2
 
 * - p2 bit 0    : 1 to set or 0 to clear protection.
 
 * - p2 bit 1    : 1 to apply to sub-groups.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetGroupFlag(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetGroupFlag(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Group *g = Group::GetIfValid(GB(p1, 0, 16));
 
	if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
 

	
 
	/* GroupFlags are stored in as an 8 bit bitfield but passed here by value,
 
	 * so 3 bits is sufficient to cover each possible value. */
 
	GroupFlags flag = (GroupFlags)GB(p1, 16, 3);
 
	if (flag >= GroupFlags::GF_END) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		SetGroupFlag(g, flag, HasBit(p2, 0), HasBit(p2, 1));
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -1973,25 +1973,25 @@ static CommandCost CreateNewIndustryHelp
 
/**
 
 * Build/Fund an industry
 
 * @param tile tile where industry is built
 
 * @param flags of operations to conduct
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  7) - industry type see build_industry.h and see industry.h
 
 * - p1 = (bit  8 - 15) - first layout to try
 
 * - p1 = (bit 16     ) - 0 = prospect, 1 = fund (only valid if current company is DEITY)
 
 * @param p2 seed to use for desyncfree randomisations
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	IndustryType it = GB(p1, 0, 8);
 
	if (it >= NUM_INDUSTRYTYPES) return CMD_ERROR;
 

	
 
	const IndustrySpec *indspec = GetIndustrySpec(it);
 

	
 
	/* Check if the to-be built/founded industry is available for this climate. */
 
	if (!indspec->enabled || indspec->layouts.empty()) return CMD_ERROR;
 

	
 
	/* If the setting for raw-material industries is not on, you cannot build raw-material industries.
 
	 * Raw material industries are industries that do not accept cargo (at least for now) */
 
	if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
 
@@ -2065,25 +2065,25 @@ CommandCost CmdBuildIndustry(TileIndex t
 
 * @param flags Type of operation.
 
 * @param p1 IndustryID
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0 - 7) - IndustryAction to perform
 
 * - p2 = (bit 8 - 15) - IndustryControlFlags
 
 *                       (only used with set control flags)
 
 * - p2 = (bit 16 - 23) - CompanyID to set or INVALID_OWNER (available to everyone) or
 
 *                        OWNER_NONE (neutral stations only) or OWNER_DEITY (no one)
 
 *                        (only used with set exclusive supplier / consumer)
 
 * @param text - Additional industry text (only used with set text action)
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	Industry *ind = Industry::GetIfValid(p1);
 
	if (ind == nullptr) return CMD_ERROR;
 

	
 
	auto action = static_cast<IndustryAction>(GB(p2, 0, 8));
 

	
 
	switch (action) {
 
		case IndustryAction::SetControlFlags: {
 
			IndustryControlFlags ctlflags = (IndustryControlFlags)GB(p2, 8, 8) & INDCTL_MASK;
 

	
 
@@ -2103,25 +2103,25 @@ CommandCost CmdIndustryCtrl(TileIndex ti
 
				if (action == IndustryAction::SetExclusiveSupplier) {
 
					ind->exclusive_supplier = company_id;
 
				} else {
 
					ind->exclusive_consumer = company_id;
 
				}
 
			}
 

	
 
			break;
 
		}
 

	
 
		case IndustryAction::SetText: {
 
			ind->text.clear();
 
			if (!StrEmpty(text)) ind->text = text;
 
			if (!text.empty()) ind->text = text;
 
			InvalidateWindowData(WC_INDUSTRY_VIEW, ind->index);
 
			break;
 
		}
 

	
 
		default:
 
			NOT_REACHED();
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
src/landscape.cpp
Show inline comments
 
@@ -681,25 +681,25 @@ void ClearSnowLine()
 
	_snow_line = nullptr;
 
}
 

	
 
/**
 
 * Clear a piece of landscape
 
 * @param tile tile to clear
 
 * @param flags of operation to conduct
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	bool do_clear = false;
 
	/* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */
 
	if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
 
		if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
 
		do_clear = true;
 
		cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
 
	}
 

	
 
	Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
 
	if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) {
 
@@ -731,25 +731,25 @@ CommandCost CmdLandscapeClear(TileIndex 
 
}
 

	
 
/**
 
 * Clear a big piece of landscape
 
 * @param tile end tile of area dragging
 
 * @param flags of operation to conduct
 
 * @param p1 start tile of area dragging
 
 * @param p2 various bitstuffed data.
 
 *  bit      0: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	Money money = GetAvailableMoneyForCommand();
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost last_error = CMD_ERROR;
 
	bool had_success = false;
 

	
 
	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);
src/misc_cmd.cpp
Show inline comments
 
@@ -33,25 +33,25 @@ static_assert((LOAN_INTERVAL & 3) == 0);
 
/**
 
 * Increase the loan of your company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 higher half of amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2.
 
 * @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0)
 
 *           (bit 0-1)  - when 0: loans LOAN_INTERVAL
 
 *                        when 1: loans the maximum loan permitting money (press CTRL),
 
 *                        when 2: loans the amount specified in p1 and p2
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Company *c = Company::Get(_current_company);
 

	
 
	if (c->current_loan >= _economy.max_loan) {
 
		SetDParam(0, _economy.max_loan);
 
		return_cmd_error(STR_ERROR_MAXIMUM_PERMITTED_LOAN);
 
	}
 

	
 
	Money loan;
 
	switch (p2 & 3) {
 
		default: return CMD_ERROR; // Invalid method
 
		case 0: // Take some extra loan
 
@@ -81,25 +81,25 @@ CommandCost CmdIncreaseLoan(TileIndex ti
 
/**
 
 * Decrease the loan of your company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 higher half of amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2.
 
 * @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0)
 
 *           (bit 0-1)  - when 0: pays back LOAN_INTERVAL
 
 *                        when 1: pays back the maximum loan permitting money (press CTRL),
 
 *                        when 2: pays back the amount specified in p1 and p2
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Company *c = Company::Get(_current_company);
 

	
 
	if (c->current_loan == 0) return_cmd_error(STR_ERROR_LOAN_ALREADY_REPAYED);
 

	
 
	Money loan;
 
	switch (p2 & 3) {
 
		default: return CMD_ERROR; // Invalid method
 
		case 0: // Pay back one step
 
			loan = std::min(c->current_loan, (Money)LOAN_INTERVAL);
 
			break;
 
		case 1: // Pay back as much as possible
 
@@ -141,25 +141,25 @@ static void AskUnsafeUnpauseCallback(Win
 
/**
 
 * Pause/Unpause the game (server-only).
 
 * Set or unset a bit in the pause mode. If pause mode is zero the game is
 
 * unpaused. A bitset is used instead of a boolean value/counter to have
 
 * more control over the game when saving/loading, etc.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the pause mode to change
 
 * @param p2 1 pauses, 0 unpauses this mode
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	switch (p1) {
 
		case PM_PAUSED_SAVELOAD:
 
		case PM_PAUSED_ERROR:
 
		case PM_PAUSED_NORMAL:
 
		case PM_PAUSED_GAME_SCRIPT:
 
		case PM_PAUSED_LINK_GRAPH:
 
			break;
 

	
 
		case PM_PAUSED_JOIN:
 
		case PM_PAUSED_ACTIVE_CLIENTS:
 
			if (!_networking) return CMD_ERROR;
 
@@ -193,40 +193,40 @@ CommandCost CmdPause(TileIndex tile, DoC
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Change the financial flow of your company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to receive (if positive), or spend (if negative)
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdMoneyCheat(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMoneyCheat(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	return CommandCost(EXPENSES_OTHER, -(int32)p1);
 
}
 

	
 
/**
 
 * Change the bank bank balance of a company by inserting or removing money without affecting the loan.
 
 * @param tile tile to show text effect on (if not 0)
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to receive (if positive), or spend (if negative)
 
 * @param p2 (bit 0-7)  - the company ID.
 
 *           (bit 8-15) - the expenses type which should register the cost/income @see ExpensesType.
 
 * @param text unused
 
 * @return zero cost or an error
 
 */
 
CommandCost CmdChangeBankBalance(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeBankBalance(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	int32 delta = (int32)p1;
 
	CompanyID company = (CompanyID) GB(p2, 0, 8);
 
	ExpensesType expenses_type = Extract<ExpensesType, 8, 8>(p2);
 

	
 
	if (!Company::IsValidID(company)) return CMD_ERROR;
 
	if (expenses_type >= EXPENSES_END) return CMD_ERROR;
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* Change company bank balance of company. */
 
		Backup<CompanyID> cur_company(_current_company, company, FILE_LINE);
src/network/network_command.cpp
Show inline comments
 
@@ -124,37 +124,37 @@ static CommandQueue _local_wait_queue;
 
static CommandQueue _local_execution_queue;
 

	
 
/**
 
 * Prepare a DoCommand to be send over the network
 
 * @param tile The tile to perform a command on (see #CommandProc)
 
 * @param p1 Additional data for the command (see #CommandProc)
 
 * @param p2 Additional data for the command (see #CommandProc)
 
 * @param cmd The command to execute (a CMD_* value)
 
 * @param callback A callback function to call after the command is finished
 
 * @param text The text to pass
 
 * @param company The company that wants to send the command
 
 */
 
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
 
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, CompanyID company)
 
{
 
	assert((cmd & CMD_FLAGS_MASK) == 0);
 

	
 
	CommandPacket c;
 
	c.company  = company;
 
	c.tile     = tile;
 
	c.p1       = p1;
 
	c.p2       = p2;
 
	c.cmd      = cmd;
 
	c.callback = callback;
 

	
 
	strecpy(c.text, (text != nullptr) ? text : "", lastof(c.text));
 
	strecpy(c.text, text.c_str(), lastof(c.text));
 

	
 
	if (_network_server) {
 
		/* If we are the server, we queue the command in our 'special' queue.
 
		 *   In theory, we could execute the command right away, but then the
 
		 *   client on the server can do everything 1 tick faster than others.
 
		 *   So to keep the game fair, we delay the command with 1 tick
 
		 *   which gives about the same speed as most clients.
 
		 */
 
		c.frame = _frame_counter_max + 1;
 
		c.my_cmd = true;
 

	
 
		_local_wait_queue.Append(&c);
src/news_gui.cpp
Show inline comments
 
@@ -831,35 +831,35 @@ void AddNewsItem(StringID string, NewsTy
 
/**
 
 * Create a new custom news item.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  7) - NewsType of the message.
 
 * - p1 = (bit  8 - 15) - NewsReferenceType of first reference.
 
 * - p1 = (bit 16 - 23) - Company this news message is for.
 
 * @param p2 First reference of the news message.
 
 * @param text The text of the news message.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	NewsType type = (NewsType)GB(p1, 0, 8);
 
	NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8);
 
	CompanyID company = (CompanyID)GB(p1, 16, 8);
 

	
 
	if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
 
	if (type >= NT_END) return CMD_ERROR;
 
	if (StrEmpty(text)) return CMD_ERROR;
 
	if (text.empty()) return CMD_ERROR;
 

	
 
	switch (reftype1) {
 
		case NR_NONE: break;
 
		case NR_TILE:
 
			if (!IsValidTile(p2)) return CMD_ERROR;
 
			break;
 

	
 
		case NR_VEHICLE:
 
			if (!Vehicle::IsValidID(p2)) return CMD_ERROR;
 
			break;
 

	
 
		case NR_STATION:
 
@@ -875,25 +875,25 @@ CommandCost CmdCustomNewsItem(TileIndex 
 
			break;
 

	
 
		case NR_ENGINE:
 
			if (!Engine::IsValidID(p2)) return CMD_ERROR;
 
			break;
 

	
 
		default: return CMD_ERROR;
 
	}
 

	
 
	if (company != INVALID_OWNER && company != _local_company) return CommandCost();
 

	
 
	if (flags & DC_EXEC) {
 
		char *news = stredup(text);
 
		char *news = stredup(text.c_str());
 
		SetDParamStr(0, news);
 
		AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Delete a news item type about a vehicle.
 
 * When the news item type is INVALID_STRING_ID all news about the vehicle gets deleted.
 
 * @param vid  The vehicle to remove the news for.
 
 * @param news The news type to remove.
src/object_cmd.cpp
Show inline comments
 
@@ -190,25 +190,25 @@ void UpdateObjectColours(const Company *
 
extern CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge);
 
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags);
 

	
 
/**
 
 * Build an object object
 
 * @param tile tile where the object will be located
 
 * @param flags type of operation
 
 * @param p1 the object type to build
 
 * @param p2 the view for the object
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CommandCost cost(EXPENSES_PROPERTY);
 

	
 
	ObjectType type = (ObjectType)GB(p1, 0, 16);
 
	if (type >= NUM_OBJECTS) return CMD_ERROR;
 
	uint8 view = GB(p2, 0, 2);
 
	const ObjectSpec *spec = ObjectSpec::Get(type);
 
	if (_game_mode == GM_NORMAL && !spec->IsAvailable() && !_generating_world) return CMD_ERROR;
 
	if ((_game_mode == GM_EDITOR || _generating_world) && !spec->WasEverAvailable()) return CMD_ERROR;
 

	
 
	if ((spec->flags & OBJECT_FLAG_ONLY_IN_SCENEDIT) != 0 && ((!_generating_world && _game_mode != GM_EDITOR) || _current_company != OWNER_NONE)) return CMD_ERROR;
 
	if ((spec->flags & OBJECT_FLAG_ONLY_IN_GAME) != 0 && (_generating_world || _game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR;
 
@@ -760,25 +760,25 @@ void GenerateObjects()
 
		for (uint j = ScaleByMapSize(1000); j != 0 && amount != 0 && Object::CanAllocateItem(); j--) {
 
			switch (i) {
 
				case OBJECT_TRANSMITTER:
 
					if (TryBuildTransmitter()) amount--;
 
					break;
 

	
 
				case OBJECT_LIGHTHOUSE:
 
					if (TryBuildLightHouse()) amount--;
 
					break;
 

	
 
				default:
 
					uint8 view = RandomRange(spec->views);
 
					if (CmdBuildObject(RandomTile(), DC_EXEC | DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, i, view, nullptr).Succeeded()) amount--;
 
					if (CmdBuildObject(RandomTile(), DC_EXEC | DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, i, view, {}).Succeeded()) amount--;
 
					break;
 
			}
 
		}
 
		IncreaseGeneratingWorldProgress(GWP_OBJECT);
 
	}
 
}
 

	
 
static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	if (!IsTileOwner(tile, old_owner)) return;
 

	
 
	bool do_clear = false;
src/order_backup.cpp
Show inline comments
 
@@ -138,25 +138,25 @@ void OrderBackup::DoRestore(Vehicle *v)
 
	}
 
}
 

	
 
/**
 
 * Clear an OrderBackup
 
 * @param tile  Tile related to the to-be-cleared OrderBackup.
 
 * @param flags For command.
 
 * @param p1    Unused.
 
 * @param p2    User that had the OrderBackup.
 
 * @param text  Unused.
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	/* No need to check anything. If the tile or user don't exist we just ignore it. */
 
	if (flags & DC_EXEC) OrderBackup::ResetOfUser(tile == 0 ? INVALID_TILE : tile, p2);
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Reset an user's OrderBackup if needed.
 
 * @param user The user associated with the OrderBackup.
 
 * @pre _network_server.
 
 * @note Must not be used from a command.
src/order_cmd.cpp
Show inline comments
 
@@ -726,25 +726,25 @@ uint GetOrderDistance(const Order *prev,
 
 * Add an order to the orderlist of a vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 - 19) - ID of the vehicle
 
 * - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
 
 *                        the order will be inserted before that one
 
 *                        the maximum vehicle order id is 254.
 
 * @param p2 packed order to insert
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh          = GB(p1,  0, 20);
 
	VehicleOrderID sel_ord = GB(p1, 20, 8);
 
	Order new_order(p2);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Check if the inserted order is to the correct destination (owner, type),
 
@@ -1001,25 +1001,25 @@ static CommandCost DecloneOrder(Vehicle 
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Delete an order from the orderlist of a vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the ID of the vehicle
 
 * @param p2 the order to delete (max 255)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh_id = GB(p1, 0, 20);
 
	VehicleOrderID sel_ord = GB(p2, 0, 8);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh_id);
 

	
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	/* If we did not select an order, we maybe want to de-clone the orders */
 
@@ -1106,25 +1106,25 @@ void DeleteOrder(Vehicle *v, VehicleOrde
 
	InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 
}
 

	
 
/**
 
 * Goto order of order-list.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 The ID of the vehicle which order is skipped
 
 * @param p2 the selected order to which we want to skip
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh_id = GB(p1, 0, 20);
 
	VehicleOrderID sel_ord = GB(p2, 0, 8);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh_id);
 

	
 
	if (v == nullptr || !v->IsPrimaryVehicle() || sel_ord == v->cur_implicit_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -1147,25 +1147,25 @@ CommandCost CmdSkipToOrder(TileIndex til
 
 * Move an order inside the orderlist
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the ID of the vehicle
 
 * @param p2 order to move and target
 
 *           bit 0-15  : the order to move
 
 *           bit 16-31 : the target order
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @note The target order will move one place down in the orderlist
 
 *  if you move the order upwards else it'll move it one place down
 
 */
 
CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh = GB(p1, 0, 20);
 
	VehicleOrderID moving_order = GB(p2,  0, 16);
 
	VehicleOrderID target_order = GB(p2, 16, 16);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Don't make senseless movements */
 
@@ -1250,25 +1250,25 @@ CommandCost CmdMoveOrder(TileIndex tile,
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 - 19) - ID of the vehicle
 
 * - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
 
 *                        the order will be inserted before that one
 
 *                        the maximum vehicle order id is 254.
 
 * @param p2 various bitstuffed elements
 
 *  - p2 = (bit 0 -  3) - what data to modify (@see ModifyOrderFlags)
 
 *  - p2 = (bit 4 - 15) - the data to modify
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleOrderID sel_ord = GB(p1, 20,  8);
 
	VehicleID veh          = GB(p1,  0, 20);
 
	ModifyOrderFlags mof   = Extract<ModifyOrderFlags, 0, 4>(p2);
 
	uint16 data            = GB(p2,  4, 11);
 

	
 
	if (mof >= MOF_END) return CMD_ERROR;
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
@@ -1519,25 +1519,25 @@ static bool CheckAircraftOrderDistance(c
 

	
 
/**
 
 * Clone/share/copy an order-list of another vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0-19) - destination vehicle to clone orders to
 
 * - p1 = (bit 30-31) - action to perform
 
 * @param p2 source vehicle to clone orders from, if any (none for CO_UNSHARE)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh_src = GB(p2, 0, 20);
 
	VehicleID veh_dst = GB(p1, 0, 20);
 

	
 
	Vehicle *dst = Vehicle::GetIfValid(veh_dst);
 
	if (dst == nullptr || !dst->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(dst->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	switch (GB(p1, 30, 2)) {
 
		case CO_SHARE: {
 
@@ -1666,25 +1666,25 @@ CommandCost CmdCloneOrder(TileIndex tile
 

	
 
/**
 
 * Add/remove refit orders from an order
 
 * @param tile Not used
 
 * @param flags operation to perform
 
 * @param p1 VehicleIndex of the vehicle having the order
 
 * @param p2 bitmask
 
 *   - bit 0-7 CargoID
 
 *   - bit 16-23 number of order to modify
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh = GB(p1, 0, 20);
 
	VehicleOrderID order_number  = GB(p2, 16, 8);
 
	CargoID cargo = GB(p2, 0, 8);
 

	
 
	if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR;
 

	
 
	const Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
src/rail_cmd.cpp
Show inline comments
 
@@ -425,25 +425,25 @@ static inline bool ValParamTrackOrientat
 

	
 
/**
 
 * Build a single piece of rail
 
 * @param tile tile  to build on
 
 * @param flags operation to perform
 
 * @param p1 railtype of being built piece (normal, mono, maglev)
 
 * @param p2 various bitstuffed elements
 
 *           - (bit  0- 2) - track-orientation, valid values: 0-5 (@see Track)
 
 *           - (bit  3)    - 0 = error on signal in the way, 1 = auto remove signals when in the way
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	RailType railtype = Extract<RailType, 0, 6>(p1);
 
	Track track = Extract<Track, 0, 3>(p2);
 
	bool auto_remove_signals = HasBit(p2, 3);
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile);
 
	TrackBits trackbit = TrackToTrackBits(track);
 

	
 
	switch (GetTileType(tile)) {
 
@@ -613,25 +613,25 @@ CommandCost CmdBuildSingleRail(TileIndex
 
	return cost;
 
}
 

	
 
/**
 
 * Remove a single piece of track
 
 * @param tile tile to remove track from
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 rail orientation
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Track track = Extract<Track, 0, 3>(p2);
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	bool crossing = false;
 

	
 
	if (!ValParamTrackOrientation(track)) return CMD_ERROR;
 
	TrackBits trackbit = TrackToTrackBits(track);
 

	
 
	/* Need to read tile owner now because it may change when the rail is removed
 
	 * Also, in case of floods, _current_company != owner
 
	 * There may be invalid tiletype even in exec run (when removing long track),
 
	 * so do not call GetTileOwner(tile) in any case here */
 
@@ -875,25 +875,25 @@ static CommandCost ValidateAutoDrag(Trac
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1 end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-5) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building
 
 * - p2 = (bit 6-8) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 9)   - 0 = build, 1 = remove tracks
 
 * - p2 = (bit 10)  - 0 = build up to an obstacle, 1 = fail if an obstacle is found (used for AIs).
 
 * - p2 = (bit 11)  - 0 = error on signal in the way, 1 = auto remove signals when in the way
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	Track track = Extract<Track, 6, 3>(p2);
 
	bool remove = HasBit(p2, 9);
 
	bool auto_remove_signals = HasBit(p2, 11);
 
	RailType railtype = Extract<RailType, 0, 6>(p2);
 

	
 
	if ((!remove && !ValParamRailtype(railtype)) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	TileIndex end_tile = p1;
 
	Trackdir trackdir = TrackToTrackdir(track);
 

	
 
@@ -936,61 +936,61 @@ static CommandCost CmdRailTrackHelper(Ti
 
 * Stub for the unified rail builder/remover
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1 end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-5) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 6-8) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 9)   - 0 = build, 1 = remove tracks
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @see CmdRailTrackHelper
 
 */
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 9), text);
 
}
 

	
 
/**
 
 * Build rail on a stretch of track.
 
 * Stub for the unified rail builder/remover
 
 * @param tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1 end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-5) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building
 
 * - p2 = (bit 6-8) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 9)   - 0 = build, 1 = remove tracks
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @see CmdRailTrackHelper
 
 */
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 9), text);
 
}
 

	
 
/**
 
 * Build a train depot
 
 * @param tile position of the train depot
 
 * @param flags operation to perform
 
 * @param p1 rail type
 
 * @param p2 bit 0..1 entrance direction (DiagDirection)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 *
 
 * @todo When checking for the tile slope,
 
 * distinguish between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
 
	RailType railtype = Extract<RailType, 0, 6>(p1);
 
	if (!ValParamRailtype(railtype)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile);
 

	
 
	DiagDirection dir = Extract<DiagDirection, 0, 2>(p2);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	/* Prohibit construction if
 
@@ -1046,25 +1046,25 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
 * - p1 = (bit 4)   - 0 = signals, 1 = semaphores
 
 * - p1 = (bit 5-7) - type of the signal, for valid values see enum SignalType in rail_map.h
 
 * - p1 = (bit 8)   - convert the present signal type and variant
 
 * - p1 = (bit 9-11)- start cycle from this signal type
 
 * - p1 = (bit 12-14)-wrap around after this signal type
 
 * - p1 = (bit 15-16)-cycle the signal direction this many times
 
 * - p1 = (bit 17)  - 1 = don't modify an existing signal but don't fail either, 0 = always set new signal type
 
 * @param p2 used for CmdBuildManySignals() to copy direction of first signal
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @todo p2 should be replaced by two bits for "along" and "against" the track.
 
 */
 
CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Track track = Extract<Track, 0, 3>(p1);
 
	bool ctrl_pressed = HasBit(p1, 3); // was the CTRL button pressed
 
	SignalVariant sigvar = (ctrl_pressed ^ HasBit(p1, 4)) ? SIG_SEMAPHORE : SIG_ELECTRIC; // the signal variant of the new signal
 
	SignalType sigtype = Extract<SignalType, 5, 3>(p1); // the signal type of the new signal
 
	bool convert_signal = HasBit(p1, 8); // convert button pressed
 
	SignalType cycle_start = Extract<SignalType, 9, 3>(p1);
 
	SignalType cycle_stop = Extract<SignalType, 12, 3>(p1);
 
	uint num_dir_cycle = GB(p1, 15, 2);
 

	
 
	if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
 
	if (cycle_start > cycle_stop || cycle_stop > SIGTYPE_LAST) return CMD_ERROR;
 
@@ -1272,25 +1272,25 @@ static bool CheckSignalAutoFill(TileInde
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
 
 * - p2 = (bit  7- 9) - default signal type
 
 * - p2 = (bit 10)    - 0 = keep fixed distance, 1 = minimise gaps between signals
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	TileIndex start_tile = tile;
 

	
 
	Track track = Extract<Track, 0, 3>(p2);
 
	bool mode = HasBit(p2, 3);
 
	bool semaphores = HasBit(p2, 4);
 
	bool remove = HasBit(p2, 5);
 
	bool autofill = HasBit(p2, 6);
 
	bool minimise_gaps = HasBit(p2, 10);
 
	byte signal_density = GB(p2, 24, 8);
 

	
 
@@ -1442,42 +1442,42 @@ static CommandCost CmdSignalTrackHelper(
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
 
 * - p2 = (bit  7- 9) - default signal type
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @see CmdSignalTrackHelper
 
 */
 
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	return CmdSignalTrackHelper(tile, flags, p1, p2, text);
 
}
 

	
 
/**
 
 * Remove signals
 
 * @param tile coordinates where signal is being deleted from
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements, only track information is used
 
 *           - (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 *           - (bit  3)    - override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 *           - (bit  4)    - 0 = signals, 1 = semaphores
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Track track = Extract<Track, 0, 3>(p1);
 

	
 
	if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) {
 
		return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 
	}
 
	if (!HasSignalOnTrack(tile, track)) {
 
		return_cmd_error(STR_ERROR_THERE_ARE_NO_SIGNALS);
 
	}
 

	
 
	/* Only water can remove signals from anyone */
 
	if (_current_company != OWNER_WATER) {
 
@@ -1534,25 +1534,25 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 2) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit  3)    - 1 = override signal/semaphore, or pre/exit/combo signal (CTRL-toggle)
 
 * - p2 = (bit  4)    - 0 = signals, 1 = semaphores
 
 * - p2 = (bit  5)    - 0 = build, 1 = remove signals
 
 * - p2 = (bit  6)    - 0 = selected stretch, 1 = auto fill
 
 * - p2 = (bit  7- 9) - default signal type
 
 * - p2 = (bit 24-31) - user defined signals_density
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @see CmdSignalTrackHelper
 
 */
 
CommandCost CmdRemoveSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	return CmdSignalTrackHelper(tile, flags, p1, SetBit(p2, 5), text); // bit 5 is remove bit
 
}
 

	
 
/** Update power of train under which is the railtype being converted */
 
static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
 
{
 
	if (v->type != VEH_TRAIN) return nullptr;
 

	
 
	TrainList *affected_trains = static_cast<TrainList*>(data);
 
	include(*affected_trains, Train::From(v)->First());
 

	
 
@@ -1562,25 +1562,25 @@ static Vehicle *UpdateTrainPowerProc(Veh
 
/**
 
 * Convert one rail type to the other. You can convert normal rail to
 
 * monorail/maglev easily or vice-versa.
 
 * @param tile end tile of rail conversion drag
 
 * @param flags operation to perform
 
 * @param p1 start tile of drag
 
 * @param p2 various bitstuffed elements:
 
 * - p2 = (bit  0- 5) new railtype to convert to.
 
 * - p2 = (bit  6)    build diagonally or not.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	RailType totype = Extract<RailType, 0, 6>(p2);
 
	TileIndex area_start = p1;
 
	TileIndex area_end = tile;
 
	bool diagonal = HasBit(p2, 6);
 

	
 
	if (!ValParamRailtype(totype)) return CMD_ERROR;
 
	if (area_start >= MapSize()) return CMD_ERROR;
 

	
 
	TrainList affected_trains;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
src/road_cmd.cpp
Show inline comments
 
@@ -601,25 +601,25 @@ static CommandCost CheckRoadSlope(Slope 
 

	
 
/**
 
 * Build a piece of road.
 
 * @param tile tile where to build road
 
 * @param flags operation to perform
 
 * @param p1 bit 0..3 road pieces to build (RoadBits)
 
 *           bit 4..9 road type
 
 *           bit 11..12 disallowed directions to toggle
 
 * @param p2 the town that is building the road (0 if not applicable)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CompanyID company = _current_company;
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	RoadBits existing = ROAD_NONE;
 
	RoadBits other_bits = ROAD_NONE;
 

	
 
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
 
	 * if a non-company is building the road */
 
	if ((Company::IsValidID(company) && p2 != 0) || (company == OWNER_TOWN && !Town::IsValidID(p2)) || (company == OWNER_DEITY && p2 != 0)) return CMD_ERROR;
 
	if (company != OWNER_TOWN) {
 
		const Town *town = CalcClosestTownFromTile(tile);
 
@@ -972,25 +972,25 @@ static bool CanConnectToRoad(TileIndex t
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1). Only used if bit 6 is set or if we are building a single tile
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2). Only used if bit 6 is set or if we are building a single tile
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 * - p2 = (bit 3..8) - road type
 
 * - p2 = (bit 10) - set road direction
 
 * - p2 = (bit 11) - defines two different behaviors for this command:
 
 *      - 0 = Build up to an obstacle. Do not build the first and last roadbits unless they can be connected to something, or if we are building a single tile
 
 *      - 1 = Fail if an obstacle is found. Always take into account bit 0 and 1. This behavior is used for scripts
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	TileIndex end_tile = p1;
 

	
 
	RoadType rt = Extract<RoadType, 3, 6>(p2);
 
	if (!ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	Axis axis = Extract<Axis, 2, 1>(p2);
 
	/* Only drag in X or Y direction dictated by the direction variable */
 
	if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
 
@@ -1077,25 +1077,25 @@ CommandCost CmdBuildLongRoad(TileIndex s
 
 * Remove a long piece of road.
 
 * @param start_tile start tile of drag
 
 * @param flags operation to perform
 
 * @param p1 end tile of drag
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 * - p2 = (bit 3 - 8) - road type
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	TileIndex end_tile = p1;
 
	RoadType rt = Extract<RoadType, 3, 6>(p2);
 
	if (!ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	Axis axis = Extract<Axis, 2, 1>(p2);
 
	/* Only drag in X or Y direction dictated by the direction variable */
 
	if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
 
@@ -1154,25 +1154,25 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
 * Build a road depot.
 
 * @param tile tile where to build the depot
 
 * @param flags operation to perform
 
 * @param p1 bit 0..1 entrance direction (DiagDirection)
 
 *           bit 2..7 road type
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 *
 
 * @todo When checking for the tile slope,
 
 * distinguish between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	DiagDirection dir = Extract<DiagDirection, 0, 2>(p1);
 

	
 
	RoadType rt = Extract<RoadType, 2, 6>(p1);
 
	if (!ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	Slope tileh = GetTileSlope(tile);
 
	if (tileh != SLOPE_FLAT) {
 
		if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) {
 
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
@@ -2341,25 +2341,25 @@ static void ConvertRoadTypeOwner(TileInd
 
/**
 
 * Convert one road subtype to another.
 
 * Not meant to convert from road to tram.
 
 *
 
 * @param tile end tile of road conversion drag
 
 * @param flags operation to perform
 
 * @param p1 start tile of drag
 
 * @param p2 various bitstuffed elements:
 
 * - p2 = (bit  0..5) new roadtype to convert to.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	RoadType to_type = Extract<RoadType, 0, 6>(p2);
 

	
 
	TileIndex area_start = p1;
 
	TileIndex area_end = tile;
 

	
 
	if (!ValParamRoadType(to_type)) return CMD_ERROR;
 
	if (area_start >= MapSize()) return CMD_ERROR;
 

	
 
	RoadVehicleList affected_rvs;
 
	RoadTramType rtt = GetRoadTramType(to_type);
 

	
src/roadveh_cmd.cpp
Show inline comments
 
@@ -357,25 +357,25 @@ bool RoadVehicle::FindClosestDepot(TileI
 
	return true;
 
}
 

	
 
/**
 
 * Turn a roadvehicle around.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to turn
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	RoadVehicle *v = RoadVehicle::GetIfValid(p1);
 
	if (v == nullptr) return CMD_ERROR;
 

	
 
	if (!v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if ((v->vehstatus & VS_STOPPED) ||
 
			(v->vehstatus & VS_CRASHED) ||
 
			v->breakdown_ctr != 0 ||
src/script/api/script_object.cpp
Show inline comments
 
@@ -320,25 +320,25 @@ ScriptObject::ActiveInstance::~ActiveIns
 
	if (callback == nullptr) callback = &ScriptInstance::DoCommandReturn;
 

	
 
	/* Are we only interested in the estimate costs? */
 
	bool estimate_only = GetDoCommandMode() != nullptr && !GetDoCommandMode()();
 

	
 
	/* Only set p2 when the command does not come from the network. */
 
	if (GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = UINT32_MAX;
 

	
 
	/* Store the command for command callback validation. */
 
	if (!estimate_only && _networking && !_generating_world) SetLastCommand(tile, p1, p2, cmd);
 

	
 
	/* Try to perform the command. */
 
	CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, command_text.c_str(), false, estimate_only);
 
	CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, command_text, false, estimate_only);
 

	
 
	/* We failed; set the error and bail out */
 
	if (res.Failed()) {
 
		SetLastError(ScriptError::StringToError(res.GetErrorMessage()));
 
		return false;
 
	}
 

	
 
	/* No error, then clear it. */
 
	SetLastError(ScriptError::ERR_NONE);
 

	
 
	/* Estimates, update the cost for the estimate and be done */
 
	if (estimate_only) {
src/settings.cpp
Show inline comments
 
@@ -1711,25 +1711,25 @@ void IntSettingDesc::ChangeValue(const v
 

	
 
/**
 
 * Network-safe changing of settings (server-only).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the index of the setting in the SettingDesc array which identifies it
 
 * @param p2 the new value for the setting
 
 * The new value is properly clamped to its minimum/maximum when setting
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 * @see _settings
 
 */
 
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	const SettingDesc *sd = GetSettingDescription(p1);
 

	
 
	if (sd == nullptr) return CMD_ERROR;
 
	if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
 
	if (!sd->IsIntSetting()) return CMD_ERROR;
 

	
 
	if (!sd->IsEditable(true)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		sd->AsIntSetting()->ChangeValue(&GetGameSettings(), p2);
 
	}
 
@@ -1738,25 +1738,25 @@ CommandCost CmdChangeSetting(TileIndex t
 
}
 

	
 
/**
 
 * Change one of the per-company settings.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the index of the setting in the _company_settings array which identifies it
 
 * @param p2 the new value for the setting
 
 * The new value is properly clamped to its minimum/maximum when setting
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	const SettingDesc *sd = GetCompanySettingDescription(p1);
 
	if (sd == nullptr) return CMD_ERROR;
 
	if (!sd->IsIntSetting()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		sd->AsIntSetting()->ChangeValue(&Company::Get(_current_company)->settings, p2);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
src/signs_cmd.cpp
Show inline comments
 
@@ -27,71 +27,71 @@ SignID _new_sign_id;
 

	
 
/**
 
 * Place a sign at the given coordinates. Ownership of sign has
 
 * no effect whatsoever except for the colour the sign gets for easy recognition,
 
 * but everybody is able to rename/remove it.
 
 * @param tile tile to place sign at
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	/* Try to locate a new sign */
 
	if (!Sign::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_SIGNS);
 

	
 
	/* Check sign text length if any */
 
	if (!StrEmpty(text) && Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
 
	if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
 

	
 
	/* When we execute, really make the sign */
 
	if (flags & DC_EXEC) {
 
		Sign *si = new Sign(_game_mode == GM_EDITOR ? OWNER_DEITY : _current_company);
 
		int x = TileX(tile) * TILE_SIZE;
 
		int y = TileY(tile) * TILE_SIZE;
 

	
 
		si->x = x;
 
		si->y = y;
 
		si->z = GetSlopePixelZ(x, y);
 
		if (!StrEmpty(text)) {
 
		if (!text.empty()) {
 
			si->name = text;
 
		}
 
		si->UpdateVirtCoord();
 
		InvalidateWindowData(WC_SIGN_LIST, 0, 0);
 
		_new_sign_id = si->index;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Rename a sign. If the new name of the sign is empty, we assume
 
 * the user wanted to delete it. So delete it. Ownership of signs
 
 * has no meaning/effect whatsoever except for eyecandy
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 index of the sign to be renamed/removed
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Sign *si = Sign::GetIfValid(p1);
 
	if (si == nullptr) return CMD_ERROR;
 
	if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY && _game_mode != GM_EDITOR) return CMD_ERROR;
 

	
 
	/* Rename the signs when empty, otherwise remove it */
 
	if (!StrEmpty(text)) {
 
	if (!text.empty()) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			/* Assign the new one */
 
			si->name = text;
 
			if (_game_mode != GM_EDITOR) si->owner = _current_company;
 

	
 
			si->UpdateVirtCoord();
 
			InvalidateWindowData(WC_SIGN_LIST, 0, 1);
 
		}
 
	} else { // Delete sign
 
		if (flags & DC_EXEC) {
src/station_cmd.cpp
Show inline comments
 
@@ -1241,25 +1241,25 @@ static void RestoreTrainReservation(Trai
 
 * - p1 = (bit  0- 5) - railtype
 
 * - p1 = (bit  6)    - orientation (Axis)
 
 * - p1 = (bit  8-15) - number of tracks
 
 * - p1 = (bit 16-23) - platform length
 
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - custom station class
 
 * - p2 = (bit  8-15) - custom station id
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	/* Unpack parameters */
 
	RailType rt    = Extract<RailType, 0, 6>(p1);
 
	Axis axis      = Extract<Axis, 6, 1>(p1);
 
	byte numtracks = GB(p1,  8, 8);
 
	byte plat_len  = GB(p1, 16, 8);
 
	bool adjacent  = HasBit(p1, 24);
 

	
 
	StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
 
	byte spec_index           = GB(p2, 8, 8);
 
	StationID station_to_join = GB(p2, 16, 16);
 

	
 
@@ -1650,25 +1650,25 @@ CommandCost RemoveFromRailBaseStation(Ti
 

	
 
/**
 
 * Remove a single tile from a rail station.
 
 * This allows for custom-built station with holes and weird layouts
 
 * @param start tile of station piece to remove
 
 * @param flags operation to perform
 
 * @param p1 start_tile
 
 * @param p2 various bitstuffed elements
 
 * - p2 = bit 0 - if set keep the rail
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	TileIndex end = p1 == 0 ? start : p1;
 
	if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
 

	
 
	TileArea ta(start, end);
 
	std::vector<Station *> affected_stations;
 

	
 
	CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_STATION_RAIL], HasBit(p2, 0));
 
	if (ret.Failed()) return ret;
 

	
 
	/* Do all station specific functions here. */
 
	for (Station *st : affected_stations) {
 
@@ -1684,25 +1684,25 @@ CommandCost CmdRemoveFromRailStation(Til
 

	
 
/**
 
 * Remove a single tile from a waypoint.
 
 * This allows for custom-built waypoint with holes and weird layouts
 
 * @param start tile of waypoint piece to remove
 
 * @param flags operation to perform
 
 * @param p1 start_tile
 
 * @param p2 various bitstuffed elements
 
 * - p2 = bit 0 - if set keep the rail
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	TileIndex end = p1 == 0 ? start : p1;
 
	if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
 

	
 
	TileArea ta(start, end);
 
	std::vector<Waypoint *> affected_stations;
 

	
 
	return RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_WAYPOINT_RAIL], HasBit(p2, 0));
 
}
 

	
 

	
 
/**
 
@@ -1823,25 +1823,25 @@ static CommandCost FindJoiningRoadStop(S
 
 * @param p1 bit 0..7: Width of the road stop.
 
 *           bit 8..15: Length of the road stop.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 *           bit 1: 0 For normal stops, 1 for drive-through.
 
 *           bit 2: Allow stations directly adjacent to other stations.
 
 *           bit 3..4: Entrance direction (#DiagDirection) for normal stops.
 
 *           bit 3: #Axis of the road for drive-through stops.
 
 *           bit 5..10: The roadtype.
 
 *           bit 16..31: Station ID to join (NEW_STATION if build new one).
 
 * @param text Unused.
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	bool type = HasBit(p2, 0);
 
	bool is_drive_through = HasBit(p2, 1);
 
	RoadType rt = Extract<RoadType, 5, 6>(p2);
 
	if (!ValParamRoadType(rt)) return CMD_ERROR;
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	uint8 width = (uint8)GB(p1, 0, 8);
 
	uint8 length = (uint8)GB(p1, 8, 8);
 
@@ -2073,25 +2073,25 @@ static CommandCost RemoveRoadStop(TileIn
 

	
 
/**
 
 * Remove bus or truck stops.
 
 * @param tile Northernmost tile of the removal area.
 
 * @param flags Operation to perform.
 
 * @param p1 bit 0..7: Width of the removal area.
 
 *           bit 8..15: Height of the removal area.
 
 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
 
 * @param p2 bit 1: 0 to keep roads of all drive-through stops, 1 to remove them.
 
 * @param text Unused.
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	uint8 width = (uint8)GB(p1, 0, 8);
 
	uint8 height = (uint8)GB(p1, 8, 8);
 
	bool keep_drive_through_roads = !HasBit(p2, 1);
 

	
 
	/* Check for incorrect width / height. */
 
	if (width == 0 || height == 0) return CMD_ERROR;
 
	/* Check if the first tile and the last tile are valid */
 
	if (!IsValidTile(tile) || TileAddWrap(tile, width - 1, height - 1) == INVALID_TILE) return CMD_ERROR;
 
	/* Bankrupting company is not supposed to remove roads, there may be road vehicles. */
 
	if (!keep_drive_through_roads && (flags & DC_BANKRUPT)) return CMD_ERROR;
 

	
 
@@ -2232,25 +2232,25 @@ void UpdateAirportsNoise()
 
 * Place an Airport.
 
 * @param tile tile where airport will be built
 
 * @param flags operation to perform
 
 * @param p1
 
 * - p1 = (bit  0- 7) - airport type, @see airport.h
 
 * - p1 = (bit  8-15) - airport layout
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit     0) - allow airports directly adjacent to other airports.
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 
	byte airport_type = GB(p1, 0, 8);
 
	byte layout = GB(p1, 8, 8);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
 

	
 
	if (airport_type >= NUM_AIRPORTS) return CMD_ERROR;
 

	
 
@@ -2449,25 +2449,25 @@ static CommandCost RemoveAirport(TileInd
 
	return cost;
 
}
 

	
 
/**
 
 * Open/close an airport to incoming aircraft.
 
 * @param tile Unused.
 
 * @param flags Operation to perform.
 
 * @param p1 Station ID of the airport.
 
 * @param p2 Unused.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (!Station::IsValidID(p1)) return CMD_ERROR;
 
	Station *st = Station::Get(p1);
 

	
 
	if (!(st->facilities & FACIL_AIRPORT) || st->owner == OWNER_NONE) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(st->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		st->airport.flags ^= AIRPORT_CLOSED_block;
 
		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_CLOSE_AIRPORT);
 
@@ -2504,25 +2504,25 @@ static const TileIndexDiffC _dock_tileof
 
static const byte _dock_w_chk[4] = { 2, 1, 2, 1 };
 
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
 

	
 
/**
 
 * Build a dock/haven.
 
 * @param tile tile where dock will be built
 
 * @param flags operation to perform
 
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
 
 * @param p2 bit 16-31: station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
 

	
 
	DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile));
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	direction = ReverseDiagDir(direction);
 

	
 
@@ -3924,33 +3924,33 @@ static bool IsUniqueStationName(const st
 
	return true;
 
}
 

	
 
/**
 
 * Rename a station
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 station ID that is to be renamed
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Station *st = Station::GetIfValid(p1);
 
	if (st == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(st->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueStationName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		st->cached_name.clear();
 
		if (reset) {
 
			st->name.clear();
 
		} else {
 
			st->name = text;
src/story.cpp
Show inline comments
 
@@ -195,181 +195,181 @@ bool StoryPageButtonData::ValidateVehicl
 
}
 

	
 
/**
 
 * Create a new story page.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  7) - Company for which this story page belongs to.
 
 * @param p2 unused.
 
 * @param text Title of the story page. Null is allowed in which case a generic page title is provided by OpenTTD.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCreateStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCreateStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (!StoryPage::CanAllocateItem()) return CMD_ERROR;
 

	
 
	CompanyID company = (CompanyID)GB(p1, 0, 8);
 

	
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (_story_page_pool.items == 0) {
 
			/* Initialize the next sort value variable. */
 
			_story_page_next_sort_value = 0;
 
		}
 

	
 
		StoryPage *s = new StoryPage();
 
		s->sort_value = _story_page_next_sort_value;
 
		s->date = _date;
 
		s->company = company;
 
		if (StrEmpty(text)) {
 
		if (text.empty()) {
 
			s->title = nullptr;
 
		} else {
 
			s->title = stredup(text);
 
			s->title = stredup(text.c_str());
 
		}
 

	
 
		InvalidateWindowClassesData(WC_STORY_BOOK, -1);
 
		if (StoryPage::GetNumItems() == 1) InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
 

	
 
		_new_story_page_id = s->index;
 
		_story_page_next_sort_value++;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Create a new story page element.
 
 * @param tile Tile location if it is a location page element, otherwise unused.
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  15) - The page which the element belongs to.
 
 *        (bit  16 -  23) - Page element type
 
 * @param p2 Id of referenced object
 
 * @param text Text content in case it is a text or location page element
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCreateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCreateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (!StoryPageElement::CanAllocateItem()) return CMD_ERROR;
 

	
 
	StoryPageID page_id = (StoryPageID)GB(p1, 0, 16);
 
	StoryPageElementType type = Extract<StoryPageElementType, 16, 8>(p1);
 

	
 
	/* Allow at most 128 elements per page. */
 
	uint16 element_count = 0;
 
	for (StoryPageElement *iter : StoryPageElement::Iterate()) {
 
		if (iter->page == page_id) element_count++;
 
	}
 
	if (element_count >= 128) return CMD_ERROR;
 

	
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (!StoryPage::IsValidID(page_id)) return CMD_ERROR;
 
	if (!VerifyElementContentParameters(page_id, type, tile, p2, text)) return CMD_ERROR;
 
	if (!VerifyElementContentParameters(page_id, type, tile, p2, text.c_str())) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (_story_page_element_pool.items == 0) {
 
			/* Initialize the next sort value variable. */
 
			_story_page_element_next_sort_value = 0;
 
		}
 

	
 
		StoryPageElement *pe = new StoryPageElement();
 
		pe->sort_value = _story_page_element_next_sort_value;
 
		pe->type = type;
 
		pe->page = page_id;
 
		UpdateElement(*pe, tile, p2, text);
 
		UpdateElement(*pe, tile, p2, text.c_str());
 

	
 
		InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
 

	
 
		_new_story_page_element_id = pe->index;
 
		_story_page_element_next_sort_value++;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Update a new story page element.
 
 * @param tile Tile location if it is a location page element, otherwise unused.
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  15) - The page element to update.
 
 *        (bit  16 -  31) - unused
 
 * @param p2 Id of referenced object
 
 * @param text Text content in case it is a text or location page element
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdUpdateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdUpdateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	StoryPageElementID page_element_id = (StoryPageElementID)GB(p1, 0, 16);
 

	
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (!StoryPageElement::IsValidID(page_element_id)) return CMD_ERROR;
 

	
 
	StoryPageElement *pe = StoryPageElement::Get(page_element_id);
 
	StoryPageID page_id = pe->page;
 
	StoryPageElementType type = pe->type;
 

	
 
	if (!VerifyElementContentParameters(page_id, type, tile, p2, text)) return CMD_ERROR;
 
	if (!VerifyElementContentParameters(page_id, type, tile, p2, text.c_str())) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		UpdateElement(*pe, tile, p2, text);
 
		UpdateElement(*pe, tile, p2, text.c_str());
 
		InvalidateWindowClassesData(WC_STORY_BOOK, pe->page);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Update title of a story page.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 = (bit 0 - 15) - StoryPageID to update.
 
 * @param p2 unused
 
 * @param text title text of the story page.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	StoryPageID page_id = (StoryPageID)GB(p1, 0, 16);
 
	if (!StoryPage::IsValidID(page_id)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		StoryPage *p = StoryPage::Get(page_id);
 
		free(p->title);
 
		if (StrEmpty(text)) {
 
		if (text.empty()) {
 
			p->title = nullptr;
 
		} else {
 
			p->title = stredup(text);
 
			p->title = stredup(text.c_str());
 
		}
 

	
 
		InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Update date of a story page.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 = (bit 0 - 15) - StoryPageID to update.
 
 * @param p2 = (bit 0 - 31) - date
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetStoryPageDate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetStoryPageDate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	StoryPageID page_id = (StoryPageID)GB(p1, 0, 16);
 
	if (!StoryPage::IsValidID(page_id)) return CMD_ERROR;
 
	Date date = (Date)p2;
 

	
 
	if (flags & DC_EXEC) {
 
		StoryPage *p = StoryPage::Get(page_id);
 
		p->date = date;
 

	
 
		InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
 
	}
 
@@ -378,47 +378,47 @@ CommandCost CmdSetStoryPageDate(TileInde
 
}
 

	
 
/**
 
 * Display a story page for all clients that are allowed to
 
 * view the story page.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 = (bit 0 - 15) - StoryPageID to show.
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdShowStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdShowStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	StoryPageID page_id = (StoryPageID)GB(p1, 0, 16);
 
	if (!StoryPage::IsValidID(page_id)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		StoryPage *g = StoryPage::Get(page_id);
 
		if ((g->company != INVALID_COMPANY && g->company == _local_company) || (g->company == INVALID_COMPANY && Company::IsValidID(_local_company))) ShowStoryBook(_local_company, page_id);
 
	}
 

	
 
	return CommandCost();
 
}
 
/**
 
 * Remove a story page and associated story page elements.
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 = (bit 0 - 15) - StoryPageID to remove.
 
 * @param p2 unused.
 
 * @param text unused.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	StoryPageID page_id = (StoryPageID)p1;
 
	if (!StoryPage::IsValidID(page_id)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		StoryPage *p = StoryPage::Get(page_id);
 

	
 
		for (StoryPageElement *pe : StoryPageElement::Iterate()) {
 
			if (pe->page == p->index) {
 
				delete pe;
 
			}
 
@@ -433,25 +433,25 @@ CommandCost CmdRemoveStoryPage(TileIndex
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Remove a story page element
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 = (bit 0 - 15) - StoryPageElementID to remove.
 
 * @param p2 unused.
 
 * @param text unused.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveStoryPageElement(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	StoryPageElementID page_element_id = (StoryPageElementID)p1;
 
	if (!StoryPageElement::IsValidID(page_element_id)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		StoryPageElement *pe = StoryPageElement::Get(page_element_id);
 
		StoryPageID page_id = pe->page;
 

	
 
		delete pe;
 

	
 
		InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
 
@@ -460,25 +460,25 @@ CommandCost CmdRemoveStoryPageElement(Ti
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Clicked/used a button on a story page.
 
 * @param tile   Tile selected, for tile selection buttons, otherwise unused.
 
 * @param flags  Type of operation.
 
 * @param p1     Bit 0..15 = story page element id of button.
 
 * @param p2     ID of selected item for buttons that select an item (e.g. vehicle), otherwise unused.
 
 * @param text   Unused.
 
 * @return The cost of the operation, or an error.
 
 */
 
CommandCost CmdStoryPageButton(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdStoryPageButton(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	StoryPageElementID page_element_id = (StoryPageElementID)GB(p1, 0, 16);
 

	
 
	if (!StoryPageElement::IsValidID(page_element_id)) return CMD_ERROR;
 
	const StoryPageElement *const pe = StoryPageElement::Get(page_element_id);
 

	
 
	/* Check the player belongs to the company that owns the page. */
 
	const StoryPage *const sp = StoryPage::Get(pe->page);
 
	if (sp->company != INVALID_COMPANY && sp->company != _current_company) return CMD_ERROR;
 

	
 
	switch (pe->type) {
 
		case SPET_BUTTON_PUSH:
src/subsidy.cpp
Show inline comments
 
@@ -231,25 +231,25 @@ void CreateSubsidy(CargoID cid, SourceTy
 
 * @param tile unused.
 
 * @param flags type of operation
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 -  7) - SourceType of source.
 
 * - p1 = (bit  8 - 23) - SourceID of source.
 
 * - p1 = (bit 24 - 31) - CargoID of subsidy.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0 -  7) - SourceType of destination.
 
 * - p2 = (bit  8 - 23) - SourceID of destination.
 
 * @param text unused.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCreateSubsidy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCreateSubsidy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (!Subsidy::CanAllocateItem()) return CMD_ERROR;
 

	
 
	CargoID cid = GB(p1, 24, 8);
 
	SourceType src_type = (SourceType)GB(p1, 0, 8);
 
	SourceID src = GB(p1, 8, 16);
 
	SourceType dst_type = (SourceType)GB(p2, 0, 8);
 
	SourceID dst = GB(p2, 8, 16);
 

	
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	if (cid >= NUM_CARGO || !::CargoSpec::Get(cid)->IsValid()) return CMD_ERROR;
src/terraform_cmd.cpp
Show inline comments
 
@@ -175,25 +175,25 @@ static CommandCost TerraformTileHeight(T
 
	return total_cost;
 
}
 

	
 
/**
 
 * Terraform land
 
 * @param tile tile to terraform
 
 * @param flags for this command type
 
 * @param p1 corners to terraform (SLOPE_xxx)
 
 * @param p2 direction; eg up (non-zero) or down (zero)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	_terraform_err_tile = INVALID_TILE;
 

	
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	int direction = (p2 != 0 ? 1 : -1);
 
	TerraformerState ts;
 

	
 
	/* Compute the costs and the terraforming result in a model of the landscape */
 
	if ((p1 & SLOPE_W) != 0 && tile + TileDiffXY(1, 0) < MapSize()) {
 
		TileIndex t = tile + TileDiffXY(1, 0);
 
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
 
		if (cost.Failed()) return cost;
 
@@ -332,25 +332,25 @@ CommandCost CmdTerraformLand(TileIndex t
 

	
 
/**
 
 * Levels a selected (rectangle) area of land
 
 * @param tile end tile of area-drag
 
 * @param flags for this command type
 
 * @param p1 start tile of area drag
 
 * @param p2 various bitstuffed data.
 
 *  bit      0: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
 
 *  bits 1 - 2: Mode of leveling \c LevelMode.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	_terraform_err_tile = INVALID_TILE;
 

	
 
	/* remember level height */
 
	uint oldh = TileHeight(p1);
 

	
 
	/* compute new height */
 
	uint h = oldh;
 
	LevelMode lm = (LevelMode)GB(p2, 1, 2);
 
	switch (lm) {
src/timetable_cmd.cpp
Show inline comments
 
@@ -88,25 +88,25 @@ static void ChangeTimetable(Vehicle *v, 
 
 * @param tile Not used.
 
 * @param flags Operation to perform.
 
 * @param p1 Various bitstuffed elements
 
 * - p1 = (bit  0-19) - Vehicle with the orders to change.
 
 * - p1 = (bit 20-27) - Order index to modify.
 
 * - p1 = (bit 28-29) - Timetable data to change (@see ModifyTimetableFlags)
 
 * @param p2 The amount of time to wait.
 
 * - p2 = (bit  0-15) - The data to modify as specified by p1 bits 28-29.
 
 *                      0 to clear times, UINT16_MAX to clear speed limit.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh = GB(p1, 0, 20);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	VehicleOrderID order_number = GB(p1, 20, 8);
 
	Order *order = v->GetOrder(order_number);
 
	if (order == nullptr || order->IsType(OT_IMPLICIT)) return CMD_ERROR;
 
@@ -182,25 +182,25 @@ CommandCost CmdChangeTimetable(TileIndex
 
}
 

	
 
/**
 
 * Clear the lateness counter to make the vehicle on time.
 
 * @param tile Not used.
 
 * @param flags Operation to perform.
 
 * @param p1 Various bitstuffed elements
 
 * - p1 = (bit  0-19) - Vehicle with the orders to change.
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh = GB(p1, 0, 20);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		v->lateness_counter = 0;
 
		SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
 
@@ -249,25 +249,25 @@ static bool VehicleTimetableSorter(Vehic
 

	
 
/**
 
 * Set the start date of the timetable.
 
 * @param tile Not used.
 
 * @param flags Operation to perform.
 
 * @param p2 Various bitstuffed elements
 
 * - p2 = (bit 0-19) - Vehicle ID.
 
 * - p2 = (bit 20)   - Set to 1 to set timetable start for all vehicles sharing this order
 
 * @param p2 The timetable start date.
 
 * @param text Not used.
 
 * @return The error or cost of the operation.
 
 */
 
CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	bool timetable_all = HasBit(p1, 20);
 
	Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
 
	if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
 
	Date start_date = (Date)p2;
 
	if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR;
 
	if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
 
@@ -314,25 +314,25 @@ CommandCost CmdSetTimetableStart(TileInd
 
 * Start or stop filling the timetable automatically from the time the vehicle
 
 * actually takes to complete it. When starting to autofill the current times
 
 * are cleared and the timetable will start again from scratch.
 
 * @param tile Not used.
 
 * @param flags Operation to perform.
 
 * @param p1 Vehicle index.
 
 * @param p2 Various bitstuffed elements
 
 * - p2 = (bit 0) - Set to 1 to enable, 0 to disable autofill.
 
 * - p2 = (bit 1) - Set to 1 to preserve waiting times in non-destructive mode
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID veh = GB(p1, 0, 20);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		if (HasBit(p2, 0)) {
 
			/* Start autofilling the timetable, which clears the
src/town_cmd.cpp
Show inline comments
 
@@ -1919,50 +1919,50 @@ static bool IsUniqueTownName(const std::
 
/**
 
 * Create a new town.
 
 * @param tile coordinates where town is built
 
 * @param flags type of operation
 
 * @param p1  0..1 size of the town (@see TownSize)
 
 *               2 true iff it should be a city
 
 *            3..5 town road layout (@see TownLayout)
 
 *               6 use random location (randomize \c tile )
 
 * @param p2 town name parts
 
 * @param text Custom name for the town. If empty, the town name parts will be used.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	TownSize size = Extract<TownSize, 0, 2>(p1);
 
	bool city = HasBit(p1, 2);
 
	TownLayout layout = Extract<TownLayout, 3, 3>(p1);
 
	TownNameParams par(_settings_game.game_creation.town_name);
 
	bool random = HasBit(p1, 6);
 
	uint32 townnameparts = p2;
 

	
 
	if (size >= TSZ_END) return CMD_ERROR;
 
	if (layout >= NUM_TLS) return CMD_ERROR;
 

	
 
	/* Some things are allowed only in the scenario editor and for game scripts. */
 
	if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) {
 
		if (_settings_game.economy.found_town == TF_FORBIDDEN) return CMD_ERROR;
 
		if (size == TSZ_LARGE) return CMD_ERROR;
 
		if (random) return CMD_ERROR;
 
		if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT && layout != _settings_game.economy.town_layout) {
 
			return CMD_ERROR;
 
		}
 
	} else if (_current_company == OWNER_DEITY && random) {
 
		/* Random parameter is not allowed for Game Scripts. */
 
		return CMD_ERROR;
 
	}
 

	
 
	if (StrEmpty(text)) {
 
	if (text.empty()) {
 
		/* If supplied name is empty, townnameparts has to generate unique automatic name */
 
		if (!VerifyTownName(townnameparts, &par)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	} else {
 
		/* If name is not empty, it has to be unique custom name */
 
		if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueTownName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	/* Allocate town struct */
 
	if (!Town::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_TOWNS);
 

	
 
	if (!random) {
 
@@ -1994,25 +1994,25 @@ CommandCost CmdFoundTown(TileIndex tile,
 
			if (t == nullptr) {
 
				cost = CommandCost(STR_ERROR_NO_SPACE_FOR_TOWN);
 
			} else {
 
				_new_town_id = t->index;
 
			}
 
		} else {
 
			t = new Town(tile);
 
			DoCreateTown(t, tile, townnameparts, size, city, layout, true);
 
		}
 
		UpdateNearestTownForRoadTiles(false);
 
		old_generating_world.Restore();
 

	
 
		if (t != nullptr && !StrEmpty(text)) {
 
		if (t != nullptr && !text.empty()) {
 
			t->name = text;
 
			t->UpdateVirtCoord();
 
		}
 

	
 
		if (_game_mode != GM_EDITOR) {
 
			/* 't' can't be nullptr since 'random' is false outside scenedit */
 
			assert(!random);
 

	
 
			if (_current_company == OWNER_DEITY) {
 
				SetDParam(0, t->index);
 
				AddTileNewsItem(STR_NEWS_NEW_TOWN_UNSPONSORED, NT_INDUSTRY_OPEN, tile);
 
			} else {
 
@@ -2734,30 +2734,30 @@ void ClearTownHouse(Town *t, TileIndex t
 
	UpdateTownRadius(t);
 
}
 

	
 
/**
 
 * Rename a town (server-only).
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 town ID to rename
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Town *t = Town::GetIfValid(p1);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueTownName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		t->cached_name.clear();
 
		if (reset) {
 
			t->name.clear();
 
		} else {
 
			t->name = text;
 
@@ -2787,25 +2787,25 @@ const CargoSpec *FindFirstCargoWithTownE
 

	
 
/**
 
 * Change the cargo goal of a town.
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 - 15) - Town ID to cargo game of.
 
 * - p1 = (bit 16 - 23) - TownEffect to change the game of.
 
 * @param p2 The new goal value.
 
 * @param text Unused.
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdTownCargoGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTownCargoGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	TownEffect te = (TownEffect)GB(p1, 16, 8);
 
	if (te < TE_BEGIN || te >= TE_END) return CMD_ERROR;
 

	
 
	uint16 index = GB(p1, 0, 16);
 
	Town *t = Town::GetIfValid(index);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	/* Validate if there is a cargo which is the requested TownEffect */
 
	const CargoSpec *cargo = FindFirstCargoWithTownEffect(te);
 
@@ -2820,49 +2820,49 @@ CommandCost CmdTownCargoGoal(TileIndex t
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Set a custom text in the Town window.
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 Town ID to change the text of.
 
 * @param p2 Unused.
 
 * @param text The new text (empty to remove the text).
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	Town *t = Town::GetIfValid(p1);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		t->text.clear();
 
		if (!StrEmpty(text)) t->text = text;
 
		if (!text.empty()) t->text = text;
 
		InvalidateWindowData(WC_TOWN_VIEW, p1);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Change the growth rate of the town.
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 Town ID to cargo game of.
 
 * @param p2 Amount of days between growth, or TOWN_GROWTH_RATE_NONE, or 0 to reset custom growth rate.
 
 * @param text Unused.
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (GB(p2, 16, 16) != 0) return CMD_ERROR;
 

	
 
	Town *t = Town::GetIfValid(p1);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (p2 == 0) {
 
			/* Just clear the flag, UpdateTownGrowth will determine a proper growth rate */
 
			ClrBit(t->flags, TOWN_CUSTOM_GROWTH);
 
		} else {
 
@@ -2884,25 +2884,25 @@ CommandCost CmdTownGrowthRate(TileIndex 
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Change the rating of a company in a town
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 Bit 0..15 = Town ID to change, bit 16..23 = Company ID to change.
 
 * @param p2 Bit 0..15 = New rating of company (signed int16).
 
 * @param text Unused.
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdTownRating(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTownRating(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	TownID town_id = (TownID)GB(p1, 0, 16);
 
	Town *t = Town::GetIfValid(town_id);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	CompanyID company_id = (CompanyID)GB(p1, 16, 8);
 
	if (!Company::IsValidID(company_id)) return CMD_ERROR;
 

	
 
	int16 new_rating = Clamp((int16)GB(p2, 0, 16), RATING_MINIMUM, RATING_MAXIMUM);
 
	if (flags & DC_EXEC) {
 
@@ -2913,25 +2913,25 @@ CommandCost CmdTownRating(TileIndex tile
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Expand a town (scenario editor only).
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 Town ID to expand.
 
 * @param p2 Amount to grow, or 0 to grow a random size up to the current amount of houses.
 
 * @param text Unused.
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) return CMD_ERROR;
 
	Town *t = Town::GetIfValid(p1);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* The more houses, the faster we grow */
 
		if (p2 == 0) {
 
			uint amount = RandomRange(ClampToU16(t->cache.num_houses / 10)) + 3;
 
			t->cache.num_houses += amount;
 
			UpdateTownRadius(t);
 

	
 
@@ -2953,25 +2953,25 @@ CommandCost CmdExpandTown(TileIndex tile
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Delete a town (scenario editor or worldgen only).
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 Town ID to delete.
 
 * @param p2 Unused.
 
 * @param text Unused.
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_game_mode != GM_EDITOR && !_generating_world) return CMD_ERROR;
 
	Town *t = Town::GetIfValid(p1);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	/* 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);
 
@@ -3342,25 +3342,25 @@ uint GetMaskOfTownActions(int *nump, Com
 

	
 
/**
 
 * Do a town action.
 
 * This performs an action such as advertising, building a statue, funding buildings,
 
 * but also bribing the town-council
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 town to do the action at
 
 * @param p2 action to perform, @see _town_action_proc for the list of available actions
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Town *t = Town::GetIfValid(p1);
 
	if (t == nullptr || p2 >= lengthof(_town_action_proc)) return CMD_ERROR;
 

	
 
	if (!HasBit(GetMaskOfTownActions(nullptr, _current_company, t), p2)) return CMD_ERROR;
 

	
 
	CommandCost cost(EXPENSES_OTHER, _price[PR_TOWN_ACTION] * _town_action_costs[p2] >> 8);
 

	
 
	CommandCost ret = _town_action_proc[p2](t, flags);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
src/train_cmd.cpp
Show inline comments
 
@@ -1151,25 +1151,25 @@ static void NormaliseTrainHead(Train *he
 
/**
 
 * Move a rail vehicle around inside the depot.
 
 * @param tile unused
 
 * @param flags type of operation
 
 *              Note: DC_AUTOREPLACE is set when autoreplace tries to undo its modifications or moves vehicles to temporary locations inside the depot.
 
 * @param p1 various bitstuffed elements
 
 * - p1 (bit  0 - 19) source vehicle index
 
 * - p1 (bit      20) move all vehicles following the source vehicle
 
 * @param p2 what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleID s = GB(p1, 0, 20);
 
	VehicleID d = GB(p2, 0, 20);
 
	bool move_chain = HasBit(p1, 20);
 

	
 
	Train *src = Train::GetIfValid(s);
 
	if (src == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(src->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */
 
@@ -1889,25 +1889,25 @@ void ReverseTrainDirection(Train *v)
 
	}
 
}
 

	
 
/**
 
 * Reverse train.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to reverse
 
 * @param p2 if true, reverse a unit in a train (needs to be in a depot)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Train *v = Train::GetIfValid(p1);
 
	if (v == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (p2 != 0) {
 
		/* turn a single unit around */
 

	
 
		if (v->IsMultiheaded() || HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) {
 
			return_cmd_error(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE_MULTIPLE_UNITS);
 
@@ -1962,25 +1962,25 @@ CommandCost CmdReverseTrainDirection(Til
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Force a train through a red signal
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to ignore the red signal
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Train *t = Train::GetIfValid(p1);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	if (!t->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(t->owner);
 
	if (ret.Failed()) return ret;
 

	
 

	
 
	if (flags & DC_EXEC) {
 
		/* If we are forced to proceed, cancel that order.
src/tree_cmd.cpp
Show inline comments
 
@@ -369,25 +369,25 @@ void GenerateTrees()
 
	}
 
}
 

	
 
/**
 
 * Plant a tree.
 
 * @param tile end tile of area-drag
 
 * @param flags type of operation
 
 * @param p1 tree type, TREE_INVALID means random.
 
 * @param p2 start tile of area-drag of tree plantation
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	StringID msg = INVALID_STRING_ID;
 
	CommandCost cost(EXPENSES_OTHER);
 
	const byte tree_to_plant = GB(p1, 0, 8); // We cannot use Extract as min and max are climate specific.
 

	
 
	if (p2 >= MapSize()) return CMD_ERROR;
 
	/* Check the tree type within the current climate */
 
	if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR;
 

	
 
	Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
 
	int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
 

	
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -248,25 +248,25 @@ static Money TunnelBridgeClearCost(TileI
 
/**
 
 * Build a Bridge
 
 * @param end_tile end tile
 
 * @param flags type of operation
 
 * @param p1 packed start tile coords (~ dx)
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - bridge type (hi bh)
 
 * - p2 = (bit  8-13) - rail type or road types.
 
 * - p2 = (bit 15-16) - transport type.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CompanyID company = _current_company;
 

	
 
	RailType railtype = INVALID_RAILTYPE;
 
	RoadType roadtype = INVALID_ROADTYPE;
 

	
 
	/* unpack parameters */
 
	BridgeType bridge_type = GB(p2, 0, 8);
 

	
 
	if (!IsValidTile(p1)) return_cmd_error(STR_ERROR_BRIDGE_THROUGH_MAP_BORDER);
 

	
 
	TransportType transport_type = Extract<TransportType, 15, 2>(p2);
 
@@ -621,25 +621,25 @@ CommandCost CmdBuildBridge(TileIndex end
 

	
 

	
 
/**
 
 * Build Tunnel.
 
 * @param start_tile start tile of tunnel
 
 * @param flags type of operation
 
 * @param p1 bit 0-5 railtype or roadtype
 
 *           bit 8-9 transport type
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CompanyID company = _current_company;
 

	
 
	TransportType transport_type = Extract<TransportType, 8, 2>(p1);
 
	RailType railtype = INVALID_RAILTYPE;
 
	RoadType roadtype = INVALID_ROADTYPE;
 
	_build_tunnel_endtile = 0;
 
	switch (transport_type) {
 
		case TRANSPORT_RAIL:
 
			railtype = Extract<RailType, 0, 6>(p1);
 
			if (!ValParamRailtype(railtype)) return CMD_ERROR;
 
			break;
src/vehicle_cmd.cpp
Show inline comments
 
@@ -63,39 +63,39 @@ const uint32 _send_to_depot_proc_table[]
 
	CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT),
 
	CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT),
 
	CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT),
 
	CMD_SEND_VEHICLE_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR),
 
};
 

	
 

	
 
CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
 
CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
 
CommandCost CmdBuildShip       (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
 
CommandCost CmdBuildAircraft   (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
 

	
 
CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
 
CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text);
 

	
 
/**
 
 * Build a vehicle.
 
 * @param tile tile of depot where the vehicle is built
 
 * @param flags for command
 
 * @param p1 various bitstuffed data
 
 *  bits  0-15: vehicle type being built.
 
 *  bits 16-23: vehicle type specific bits passed on to the vehicle build functions.
 
 *  bits 24-31: refit cargo type.
 
 * @param p2 User
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	/* Elementary check for valid location. */
 
	if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
 

	
 
	VehicleType type = GetDepotVehicleType(tile);
 

	
 
	/* Validate the engine type. */
 
	EngineID eid = GB(p1, 0, 16);
 
	if (!IsEngineBuildable(eid, type, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type);
 

	
 
	/* Validate the cargo type. */
 
	CargoID cargo = GB(p1, 24, 8);
 
@@ -145,25 +145,25 @@ CommandCost CmdBuildVehicle(TileIndex ti
 
		case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft   (tile, subflags, e, GB(p1, 16, 8), &v)); break;
 
		default: NOT_REACHED(); // Safe due to IsDepotTile()
 
	}
 

	
 
	if (value.Succeeded()) {
 
		if (subflags & DC_EXEC) {
 
			v->unitnumber = unit_num;
 
			v->value      = value.GetCost();
 
		}
 

	
 
		if (refitting) {
 
			/* Refit only one vehicle. If we purchased an engine, it may have gained free wagons. */
 
			value.AddCost(CmdRefitVehicle(tile, flags, v->index, cargo | (1 << 16), nullptr));
 
			value.AddCost(CmdRefitVehicle(tile, flags, v->index, cargo | (1 << 16), {}));
 
		} else {
 
			/* Fill in non-refitted capacities */
 
			_returned_refit_capacity = e->GetDisplayDefaultCapacity(&_returned_mail_refit_capacity);
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
			InvalidateWindowClassesData(GetWindowClassForVehicleType(type), 0);
 
			SetWindowDirty(WC_COMPANY, _current_company);
 
			if (IsLocalCompany()) {
 
				InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the auto replace window (must be called before incrementing num_engines)
 
			}
 
@@ -197,25 +197,25 @@ CommandCost CmdSellRailWagon(DoCommandFl
 
/**
 
 * Sell a vehicle.
 
 * @param tile unused.
 
 * @param flags for command.
 
 * @param p1 various bitstuffed data.
 
 *  bits  0-19: vehicle ID being sold.
 
 *  bits 20-30: vehicle type specific bits passed on to the vehicle build functions.
 
 *  bit     31: make a backup of the vehicle's order (if an engine).
 
 * @param p2 User.
 
 * @param text unused.
 
 * @return the cost of this operation or an error.
 
 */
 
CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
 
	if (v == nullptr) return CMD_ERROR;
 

	
 
	Vehicle *front = v->First();
 

	
 
	CommandCost ret = CheckOwnership(front->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
 

	
 
	if (!front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
 
@@ -459,25 +459,25 @@ static CommandCost RefitVehicle(Vehicle 
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to refit
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7)   - New cargo type to refit to.
 
 * - p2 = (bit 8-15)  - New cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
 
 * - p2 = (bit 16-23) - Number of vehicles to refit (not counting articulated parts). Zero means all vehicles.
 
 *                      Only used if "refit only this vehicle" is false.
 
 * - p2 = (bit 24)     - Automatic refitting.
 
 * - p2 = (bit 25)     - Refit only this vehicle. Used only for cloning vehicles.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr) return CMD_ERROR;
 

	
 
	/* Don't allow disasters and sparks and such to be refitted.
 
	 * We cannot check for IsPrimaryVehicle as autoreplace also refits in free wagon chains. */
 
	if (!IsCompanyBuildableVehicleType(v->type)) return CMD_ERROR;
 

	
 
	Vehicle *front = v->First();
 

	
 
	CommandCost ret = CheckOwnership(front->owner);
 
	if (ret.Failed()) return ret;
 
@@ -547,25 +547,25 @@ CommandCost CmdRefitVehicle(TileIndex ti
 
	return cost;
 
}
 

	
 
/**
 
 * Start/Stop a vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle to start/stop, don't forget to change CcStartStopVehicle if you modify this!
 
 * @param p2 bit 0: Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	/* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */
 
	if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
 

	
 
@@ -631,25 +631,25 @@ CommandCost CmdStartStopVehicle(TileInde
 

	
 
/**
 
 * Starts or stops a lot of vehicles
 
 * @param tile Tile of the depot where the vehicles are started/stopped (only used for depots)
 
 * @param flags type of operation
 
 * @param p1 bitmask
 
 *   - bit 0 set = start vehicles, unset = stop vehicles
 
 *   - bit 1 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
 
 * @param p2 packed VehicleListIdentifier
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleList list;
 
	bool do_start = HasBit(p1, 0);
 
	bool vehicle_list_window = HasBit(p1, 1);
 

	
 
	VehicleListIdentifier vli;
 
	if (!vli.UnpackIfValid(p2)) return CMD_ERROR;
 
	if (!IsCompanyBuildableVehicleType(vli.vtype)) return CMD_ERROR;
 

	
 
	if (vehicle_list_window) {
 
		if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
 
	} else {
 
@@ -671,25 +671,25 @@ CommandCost CmdMassStartStopVehicle(Tile
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Sells all vehicles in a depot
 
 * @param tile Tile of the depot where the depot is
 
 * @param flags type of operation
 
 * @param p1 Vehicle type
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleList list;
 

	
 
	CommandCost cost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
 

	
 
	if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
 

	
 
	uint sell_command = GetCmdSellVeh(vehicle_type);
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list);
 
@@ -709,25 +709,25 @@ CommandCost CmdDepotSellAllVehicles(Tile
 
	return had_success ? cost : last_error;
 
}
 

	
 
/**
 
 * Autoreplace all vehicles in the depot
 
 * @param tile Tile of the depot where the vehicles are
 
 * @param flags type of operation
 
 * @param p1 Type of vehicle
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	VehicleList list;
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
 

	
 
	if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
 
	if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list, true);
 

	
 
	for (uint i = 0; i < list.size(); i++) {
 
@@ -813,25 +813,25 @@ static void CloneVehicleName(const Vehic
 
	/* All done. If we didn't find a name, it'll just use its default. */
 
}
 

	
 
/**
 
 * Clone a vehicle. If it is a train, it will clone all the cars too
 
 * @param tile tile of the depot where the cloned vehicle is build
 
 * @param flags type of operation
 
 * @param p1 the original vehicle's index
 
 * @param p2 1 = shared orders, else copied orders
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	CommandCost total_cost(EXPENSES_NEW_VEHICLES);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 
	Vehicle *v_front = v;
 
	Vehicle *w = nullptr;
 
	Vehicle *w_front = nullptr;
 
	Vehicle *w_rear = nullptr;
 

	
 
	/*
 
	 * v_front is the front engine in the original vehicle
 
@@ -1035,58 +1035,58 @@ static CommandCost SendAllVehiclesToDepo
 

	
 
/**
 
 * Send a vehicle to the depot.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 bitmask
 
 * - p1 0-20: bitvehicle ID to send to the depot
 
 * - p1 bits 25-8  - DEPOT_ flags (see vehicle_type.h)
 
 * @param p2 packed VehicleListIdentifier.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (p1 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		VehicleListIdentifier vli;
 
		if (!vli.UnpackIfValid(p2)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(flags, (p1 & DEPOT_SERVICE) != 0, vli);
 
	}
 

	
 
	Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
 
	if (v == nullptr) return CMD_ERROR;
 
	if (!v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	return v->SendToDepot(flags, (DepotCommand)(p1 & DEPOT_COMMAND_MASK));
 
}
 

	
 
/**
 
 * Give a custom name to your vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to name
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_VEHICLE_NAME_CHARS) return CMD_ERROR;
 
		if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (reset) {
 
			v->name.clear();
 
		} else {
 
			v->name = text;
 
		}
 
@@ -1101,25 +1101,25 @@ CommandCost CmdRenameVehicle(TileIndex t
 
/**
 
 * Change the service interval of a vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID that is being service-interval-changed
 
 * @param p2 bitmask
 
 * - p2 = (bit  0-15) - new service interval
 
 * - p2 = (bit 16)    - service interval is custom flag
 
 * - p2 = (bit 17)    - service interval is percentage flag
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	const Company *company = Company::Get(v->owner);
 
	bool iscustom  = HasBit(p2, 16);
 
	bool ispercent = iscustom ? HasBit(p2, 17) : company->settings.vehicle.servint_ispercent;
 

	
 
	uint16 serv_int;
src/viewport.cpp
Show inline comments
 
@@ -3463,25 +3463,25 @@ void InitializeSpriteSorter()
 
	assert(_vp_sprite_sorter != nullptr);
 
}
 

	
 
/**
 
 * Scroll players main viewport.
 
 * @param tile tile to center viewport on
 
 * @param flags type of operation
 
 * @param p1 ViewportScrollTarget of scroll target
 
 * @param p2 company or client id depending on the target
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdScrollViewport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdScrollViewport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	ViewportScrollTarget target = (ViewportScrollTarget)p1;
 
	switch (target) {
 
		case VST_EVERYONE:
 
			break;
 
		case VST_COMPANY:
 
			if (_local_company != (CompanyID)p2) return CommandCost();
 
			break;
 
		case VST_CLIENT:
 
			if (_network_own_client_id != (ClientID)p2) return CommandCost();
 
			break;
src/water_cmd.cpp
Show inline comments
 
@@ -89,25 +89,25 @@ static void MarkCanalsAndRiversAroundDir
 
}
 

	
 

	
 
/**
 
 * Build a ship depot.
 
 * @param tile tile where ship depot is built
 
 * @param flags type of operation
 
 * @param p1 bit 0 depot orientation (Axis)
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Axis axis = Extract<Axis, 0, 1>(p1);
 

	
 
	TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 

	
 
	if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
 
		return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
 
	}
 

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

	
 
	if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
 
@@ -408,25 +408,25 @@ static CommandCost RemoveLock(TileIndex 
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]);
 
}
 

	
 
/**
 
 * Builds a lock.
 
 * @param tile tile where to place the lock
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
 
	if (dir == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
	return DoBuildLock(tile, dir, flags);
 
}
 

	
 
/** Callback to create non-desert around a river tile. */
 
bool RiverModifyDesertZone(TileIndex tile, void *)
 
{
 
	if (GetTropicZone(tile) == TROPICZONE_DESERT) SetTropicZone(tile, TROPICZONE_NORMAL);
 
	return false;
 
@@ -434,25 +434,25 @@ bool RiverModifyDesertZone(TileIndex til
 

	
 
/**
 
 * Build a piece of canal.
 
 * @param tile end tile of stretch-dragging
 
 * @param flags type of operation
 
 * @param p1 start tile of stretch-dragging
 
 * @param p2 various bitstuffed data
 
 *  bits  0-1: waterclass to build. sea and river can only be built in scenario editor
 
 *  bit     2: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	WaterClass wc = Extract<WaterClass, 0, 2>(p2);
 
	if (p1 >= MapSize() || wc == WATER_CLASS_INVALID) return CMD_ERROR;
 

	
 
	/* Outside of the editor you can only build canals, not oceans */
 
	if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;
 

	
 
	/* Outside the editor you can only drag canals, and not areas */
 
	if (_game_mode != GM_EDITOR) {
 
		TileArea ta(tile, p1);
 
		if (ta.w != 1 && ta.h != 1) return CMD_ERROR;
 
	}
src/waypoint_cmd.cpp
Show inline comments
 
@@ -165,25 +165,25 @@ extern CommandCost CanExpandRailStation(
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0- 5) - railtype (not used)
 
 * - p1 = (bit  6)    - orientation (Axis)
 
 * - p1 = (bit  8-15) - width of waypoint
 
 * - p1 = (bit 16-23) - height of waypoint
 
 * - p1 = (bit 24)    - allow waypoints directly adjacent to other waypoints.
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - custom station class
 
 * - p2 = (bit  8-15) - custom station id
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	/* Unpack parameters */
 
	Axis axis      = Extract<Axis, 6, 1>(p1);
 
	byte width     = GB(p1,  8, 8);
 
	byte height    = GB(p1, 16, 8);
 
	bool adjacent  = HasBit(p1, 24);
 

	
 
	StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
 
	byte spec_index           = GB(p2, 8, 8);
 
	StationID station_to_join = GB(p2, 16, 16);
 

	
 
	/* Check if the given station class is valid */
 
@@ -293,25 +293,25 @@ CommandCost CmdBuildRailWaypoint(TileInd
 
	return CommandCost(EXPENSES_CONSTRUCTION, count * _price[PR_BUILD_WAYPOINT_RAIL]);
 
}
 

	
 
/**
 
 * Build a buoy.
 
 * @param tile tile where to place the buoy
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 

	
 
	/* 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)) {
 
@@ -404,35 +404,35 @@ static bool IsUniqueWaypointName(const s
 
	return true;
 
}
 

	
 
/**
 
 * Rename a waypoint.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 id of waypoint
 
 * @param p2 unused
 
 * @param text the new name or an empty string when resetting to the default
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	Waypoint *wp = Waypoint::GetIfValid(p1);
 
	if (wp == nullptr) return CMD_ERROR;
 

	
 
	if (wp->owner != OWNER_NONE) {
 
		CommandCost ret = CheckOwnership(wp->owner);
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	bool reset = StrEmpty(text);
 
	bool reset = text.empty();
 

	
 
	if (!reset) {
 
		if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueWaypointName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (reset) {
 
			wp->name.clear();
 
		} else {
 
			wp->name = text;
 
		}
0 comments (0 inline, 0 general)