Changeset - r11090:9276cea703d4
src/aircraft_cmd.cpp
Show inline comments
 
@@ -237,25 +237,25 @@ uint16 AircraftDefaultCargoCapacity(Carg
 
		default:
 
			return (avi->passenger_capacity + avi->mail_capacity) / 4;
 
	}
 
}
 

	
 
/** Build an aircraft.
 
 * @param tile tile of depot where aircraft is built
 
 * @param flags for command
 
 * @param p1 aircraft type being built (engine)
 
 * @param p2 unused
 
 * return result of operation.  Could be cost, error
 
 */
 
CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_company)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE);
 

	
 
	const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
 
	const Engine *e = GetEngine(p1);
 
	CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
 

	
 
	/* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */
 
	if (flags & DC_QUERY_COST) return value;
 

	
 
	if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
 

	
 
@@ -440,25 +440,25 @@ CommandCost CmdBuildAircraft(TileIndex t
 

	
 
	return value;
 
}
 

	
 

	
 
/** Sell an aircraft.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 * @return result of operation.  Error or sold value
 
 */
 
CommandCost CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
	CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
 

	
 
@@ -488,25 +488,25 @@ bool Aircraft::FindClosestDepot(TileInde
 
	return true;
 
}
 

	
 
/** Send an aircraft to the hangar.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID to send to the hangar
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 * @return o if everything went well
 
 */
 
CommandCost CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSendAircraftToHangar(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_AIRCRAFT) return CMD_ERROR;
 
@@ -516,25 +516,25 @@ CommandCost CmdSendAircraftToHangar(Tile
 

	
 

	
 
/** Refits an aircraft to the specified cargo type.
 
 * @param tile unused
 
 * @param flags for command type
 
 * @param p1 vehicle ID of the aircraft to refit
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle (ignored)
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	byte new_subtype = GB(p2, 8, 8);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
 
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);
 

	
 
	/* Check cargo */
src/autoreplace.cpp
Show inline comments
 
@@ -38,50 +38,50 @@ void RemoveAllEngineReplacement(EngineRe
 
}
 

	
 
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
 
{
 
	const EngineRenew *er = GetEngineReplacement(erl, engine, group);
 
	if (er == NULL && (group == DEFAULT_GROUP || (IsValidGroupID(group) && !GetGroup(group)->replace_protection))) {
 
		/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
 
		er = GetEngineReplacement(erl, engine, ALL_GROUP);
 
	}
 
	return er == NULL ? INVALID_ENGINE : er->to;
 
}
 

	
 
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
 
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, DoCommandFlag flags)
 
{
 
	EngineRenew *er;
 

	
 
	/* Check if the old vehicle is already in the list */
 
	er = GetEngineReplacement(*erl, old_engine, group);
 
	if (er != NULL) {
 
		if (flags & DC_EXEC) er->to = new_engine;
 
		return CommandCost();
 
	}
 

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

	
 
	if (flags & DC_EXEC) {
 
		er = new EngineRenew(old_engine, new_engine);
 
		er->group_id = group;
 

	
 
		/* Insert before the first element */
 
		er->next = (EngineRenew *)(*erl);
 
		*erl = (EngineRenewList)er;
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags)
 
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags)
 
{
 
	EngineRenew *er = (EngineRenew *)(*erl);
 
	EngineRenew *prev = NULL;
 

	
 
	while (er)
 
	{
 
		if (er->from == engine && er->group_id == group) {
 
			if (flags & DC_EXEC) {
 
				if (prev == NULL) { // First element
 
					/* The second becomes the new first element */
 
					*erl = (EngineRenewList)er->next;
 
				} else {
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -283,35 +283,35 @@ static CommandCost BuildReplacementVehic
 
 */
 
static inline CommandCost StartStopVehicle(const Vehicle *v, bool evaluate_callback)
 
{
 
	return DoCommand(0, v->index, evaluate_callback ? 1 : 0, DC_EXEC | DC_AUTOREPLACE, CMD_START_STOP_VEHICLE);
 
}
 

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

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

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

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

	
 
	/* Perform start/stop check whether the new vehicle suits newgrf restrictions etc. */
 
	if (cost.Succeeded()) {
 
		/* Start the vehicle, might be denied by certain things */
 
@@ -337,25 +337,25 @@ static CommandCost CopyHeadSpecificThing
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Replace a single unit in a free wagon chain
 
 * @param single_unit vehicle to let autoreplace/renew operator on
 
 * @param flags command flags
 
 * @param wagon_removal remove wagons when the resulting chain occupies more tiles than the old did
 
 * @param nothing_to_do is set to 'false' when something was done (only valid when not failed)
 
 * @return cost or error
 
 */
 
static CommandCost ReplaceFreeUnit(Vehicle **single_unit, uint32 flags, bool *nothing_to_do)
 
static CommandCost ReplaceFreeUnit(Vehicle **single_unit, DoCommandFlag flags, bool *nothing_to_do)
 
{
 
	Vehicle *old_v = *single_unit;
 
	assert(old_v->type == VEH_TRAIN && !IsArticulatedPart(old_v) && !IsRearDualheaded(old_v));
 

	
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
 

	
 
	/* Build and refit replacement vehicle */
 
	Vehicle *new_v = NULL;
 
	cost.AddCost(BuildReplacementVehicle(old_v, &new_v, false));
 

	
 
	/* Was a new vehicle constructed? */
 
	if (cost.Succeeded() && new_v != NULL) {
 
@@ -386,25 +386,25 @@ static CommandCost ReplaceFreeUnit(Vehic
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Replace a whole vehicle chain
 
 * @param chain vehicle chain to let autoreplace/renew operator on
 
 * @param flags command flags
 
 * @param wagon_removal remove wagons when the resulting chain occupies more tiles than the old did
 
 * @param nothing_to_do is set to 'false' when something was done (only valid when not failed)
 
 * @return cost or error
 
 */
 
static CommandCost ReplaceChain(Vehicle **chain, uint32 flags, bool wagon_removal, bool *nothing_to_do)
 
static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon_removal, bool *nothing_to_do)
 
{
 
	Vehicle *old_head = *chain;
 
	assert(old_head->IsPrimaryVehicle());
 

	
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
 

	
 
	if (old_head->type == VEH_TRAIN) {
 
		/* Store the length of the old vehicle chain, rounded up to whole tiles */
 
		uint16 old_total_length = (old_head->u.rail.cached_total_length + TILE_SIZE - 1) / TILE_SIZE * TILE_SIZE;
 

	
 
		int num_units = 0; ///< Number of units in the chain
 
		for (Vehicle *w = old_head; w != NULL; w = GetNextUnit(w)) num_units++;
 
@@ -592,25 +592,25 @@ static CommandCost ReplaceChain(Vehicle 
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** 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
 
 */
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
 
	bool nothing_to_do = true;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
	Vehicle *v = GetVehicle(p1);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!v->IsInDepot()) return CMD_ERROR;
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return CMD_ERROR;
 

	
 
	bool free_wagon = false;
 
	if (v->type == VEH_TRAIN) {
src/autoreplace_func.h
Show inline comments
 
@@ -23,34 +23,34 @@ void RemoveAllEngineReplacement(EngineRe
 
 * replacement is in the list.
 
 */
 
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group);
 

	
 
/**
 
 * Add an engine replacement to the given renewlist.
 
 * @param erl The renewlist to add to.
 
 * @param old_engine The original engine type.
 
 * @param new_engine The replacement engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags);
 
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, DoCommandFlag flags);
 

	
 
/**
 
 * Remove an engine replacement from a given renewlist.
 
 * @param erl The renewlist from which to remove the replacement
 
 * @param engine The original engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags);
 
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags);
 

	
 
/**
 
 * Remove all engine replacement settings for the given company.
 
 * @param c the company.
 
 */
 
static inline void RemoveAllEngineReplacementForCompany(Company *c)
 
{
 
	RemoveAllEngineReplacement(&c->engine_renew_list);
 
}
 

	
 
/**
 
 * Retrieve the engine replacement for the given company and original engine type.
 
@@ -74,32 +74,32 @@ static inline bool EngineHasReplacementF
 
{
 
	return EngineReplacementForCompany(c, engine, group) != INVALID_ENGINE;
 
}
 

	
 
/**
 
 * Add an engine replacement for the company.
 
 * @param c Company.
 
 * @param old_engine The original engine type.
 
 * @param new_engine The replacement engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
 
static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, DoCommandFlag flags)
 
{
 
	return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, flags);
 
}
 

	
 
/**
 
 * Remove an engine replacement for the company.
 
 * @param c Company.
 
 * @param engine The original engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
static inline CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, uint32 flags)
 
static inline CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, DoCommandFlag flags)
 
{
 
	return RemoveEngineReplacement(&c->engine_renew_list, engine, group, flags);
 
}
 

	
 
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company);
 

	
 
#endif /* AUTOREPLACE_FUNC_H */
src/bridge.h
Show inline comments
 
@@ -52,18 +52,18 @@ extern BridgeSpec _bridge[MAX_BRIDGES];
 

	
 
Foundation GetBridgeFoundation(Slope tileh, Axis axis);
 
bool HasBridgeFlatRamp(Slope tileh, Axis axis);
 

	
 
static inline const BridgeSpec *GetBridgeSpec(BridgeType i)
 
{
 
	assert(i < lengthof(_bridge));
 
	return &_bridge[i];
 
}
 

	
 
void DrawBridgeMiddle(const TileInfo *ti);
 

	
 
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len, uint32 flags = 0);
 
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags = DC_NONE);
 
int CalcBridgeLenCostFactor(int x);
 

	
 
void ResetBridges();
 

	
 
#endif /* BRIDGE_H */
src/clear_cmd.cpp
Show inline comments
 
@@ -11,25 +11,25 @@
 
#include "genworld.h"
 
#include "industry.h"
 
#include "functions.h"
 
#include "economy_func.h"
 
#include "viewport_func.h"
 
#include "water.h"
 
#include "settings_type.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#include "table/clear_land.h"
 

	
 
static CommandCost ClearTile_Clear(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Clear(TileIndex tile, DoCommandFlag flags)
 
{
 
	static const Money *clear_price_table[] = {
 
		&_price.clear_grass,
 
		&_price.clear_roughland,
 
		&_price.clear_rocks,
 
		&_price.clear_fields,
 
		&_price.clear_roughland,
 
		&_price.clear_roughland,
 
	};
 
	CommandCost price(EXPENSES_CONSTRUCTION);
 

	
 
	if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) {
 
@@ -348,25 +348,25 @@ static void GetTileDesc_Clear(TileIndex 
 
}
 

	
 
static void ChangeTileOwner_Clear(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	return;
 
}
 

	
 
void InitializeClearLand()
 
{
 
	_settings_game.game_creation.snow_line = _settings_game.game_creation.snow_line_height * TILE_HEIGHT;
 
}
 

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

	
 
extern const TileTypeProcs _tile_type_clear_procs = {
 
	DrawTile_Clear,           ///< draw_tile_proc
 
	GetSlopeZ_Clear,          ///< get_slope_z_proc
 
	ClearTile_Clear,          ///< clear_tile_proc
 
	GetAcceptedCargo_Clear,   ///< get_accepted_cargo_proc
 
	GetTileDesc_Clear,        ///< get_tile_desc_proc
 
	GetTileTrackStatus_Clear, ///< get_tile_track_status_proc
 
	ClickTile_Clear,          ///< click_tile_proc
src/command.cpp
Show inline comments
 
@@ -25,25 +25,25 @@
 

	
 
StringID _error_message;
 

	
 
/**
 
 * Helper macro to define the header of all command handler macros.
 
 *
 
 * This macro create the function header for a given command handler function, as
 
 * all command handler functions got the parameters from the #CommandProc callback
 
 * type.
 
 *
 
 * @param yyyy The desired function name of the new command handler function.
 
 */
 
#define DEF_COMMAND(yyyy) CommandCost yyyy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
#define DEF_COMMAND(yyyy) CommandCost yyyy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 

	
 
DEF_COMMAND(CmdBuildRailroadTrack);
 
DEF_COMMAND(CmdRemoveRailroadTrack);
 
DEF_COMMAND(CmdBuildSingleRail);
 
DEF_COMMAND(CmdRemoveSingleRail);
 

	
 
DEF_COMMAND(CmdLandscapeClear);
 

	
 
DEF_COMMAND(CmdBuildBridge);
 

	
 
DEF_COMMAND(CmdBuildRailroadStation);
 
DEF_COMMAND(CmdRemoveFromRailroadStation);
 
@@ -367,42 +367,42 @@ byte GetCommandFlags(uint32 cmd)
 
}
 

	
 
static int _docommand_recursive = 0;
 

	
 
/**
 
 * Shorthand for calling the long DoCommand with a container.
 
 *
 
 * @param container Container with (almost) all information
 
 * @param flags Flags for the command and how to execute the command
 
 * @see CommandProc
 
 * @return the cost
 
 */
 
CommandCost DoCommand(const CommandContainer *container, uint32 flags)
 
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
 
{
 
	return DoCommand(container->tile, container->p1, container->p2, flags, container->cmd & CMD_ID_MASK, container->text);
 
}
 

	
 
/*!
 
 * This function executes a given command with the parameters from the #CommandProc parameter list.
 
 * Depending on the flags parameter it execute or test a command.
 
 *
 
 * @param 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)
 
 * @see CommandProc
 
 * @return the cost
 
 */
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text)
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *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;
 

	
 
	CommandProc *proc = _command_proc_table[cmd].proc;
 

	
 
	if (_docommand_recursive == 0) _error_message = INVALID_STRING_ID;
 

	
 
	_docommand_recursive++;
 

	
 
@@ -511,25 +511,25 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	}
 

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

	
 
	CommandProc *proc = _command_proc_table[cmd_id].proc;
 
	if (proc == NULL) return false;
 

	
 
	/* Command flags are used internally */
 
	uint cmd_flags = GetCommandFlags(cmd);
 
	/* Flags get send to the DoCommand */
 
	uint32 flags = CommandFlagsToDCFlags(cmd_flags);
 
	DoCommandFlag flags = CommandFlagsToDCFlags(cmd_flags);
 

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

	
 
	/* If the server is a spectator, it may only do server commands! */
 
	if (_current_company == COMPANY_SPECTATOR && (cmd_flags & (CMD_SPECTATOR | CMD_SERVER)) == 0) return false;
 

	
 
	bool notest = (cmd_flags & CMD_NO_TEST) != 0;
 

	
 
	_docommand_recursive = 1;
 

	
 
	/* cost estimation only? */
src/command_func.h
Show inline comments
 
@@ -44,26 +44,26 @@ static const CommandCost CMD_ERROR = Com
 
 * 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);
 

	
 
/**
 
 * Execute a command
 
 */
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text = NULL);
 
CommandCost DoCommand(const CommandContainer *container, uint32 flags);
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text = NULL);
 
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
 

	
 
/**
 
 * Execute a network safe DoCommand function
 
 */
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = NULL, const char *text = NULL, bool my_cmd = true);
 
bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
/**
 
 * Send a command over the network
 
 */
 
@@ -82,22 +82,22 @@ bool IsValidCommand(uint32 cmd);
 
 */
 
byte GetCommandFlags(uint32 cmd);
 
/**
 
 * Returns the current money available which can be used for a command.
 
 */
 
Money GetAvailableMoneyForCommand();
 

	
 
/**
 
 * Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
 
 * @param cmd_flags Flags from GetCommandFlags
 
 * @return flags for DoCommand
 
 */
 
static inline uint32 CommandFlagsToDCFlags(uint cmd_flags)
 
static inline DoCommandFlag CommandFlagsToDCFlags(uint cmd_flags)
 
{
 
	uint32 flags = 0;
 
	DoCommandFlag flags = DC_NONE;
 
	if (cmd_flags & CMD_NO_WATER) flags |= DC_NO_WATER;
 
	if (cmd_flags & CMD_AUTO) flags |= DC_AUTO;
 
	if (cmd_flags & CMD_ALL_TILES) flags |= DC_ALL_TILES;
 
	return flags;
 
}
 

	
 
#endif /* COMMAND_FUNC_H */
src/command_type.h
Show inline comments
 
@@ -284,35 +284,37 @@ enum {
 

	
 
	CMD_MOVE_ORDER,                   ///< move an order
 
	CMD_CHANGE_TIMETABLE,             ///< change the timetable for a vehicle
 
	CMD_SET_VEHICLE_ON_TIME,          ///< set the vehicle on time feature (timetable)
 
	CMD_AUTOFILL_TIMETABLE,           ///< autofill the timetable
 
};
 

	
 
/**
 
 * List of flags for a command.
 
 *
 
 * This enums defines some flags which can be used for the commands.
 
 */
 
enum {
 
enum DoCommandFlag {
 
	DC_NONE            = 0x000, ///< no flag is set
 
	DC_EXEC            = 0x001, ///< execute the given command
 
	DC_AUTO            = 0x002, ///< don't allow building on structures
 
	DC_QUERY_COST      = 0x004, ///< query cost only,  don't build.
 
	DC_NO_WATER        = 0x008, ///< don't allow building on water
 
	DC_NO_RAIL_OVERLAP = 0x010, ///< don't allow overlap of rails (used in buildrail)
 
	DC_NO_TOWN_RATING  = 0x020, ///< town rating does not disallow you from building
 
	DC_BANKRUPT        = 0x040, ///< company bankrupts, skip money check, skip vehicle on tile check in some cases
 
	DC_AUTOREPLACE     = 0x080, ///< autoreplace/autorenew is in progress, this shall disable vehicle limits when building, and ignore certain restrictions when undoing things (like vehicle attach callback)
 
	DC_ALL_TILES       = 0x100, ///< allow this command also on MP_VOID tiles
 
};
 
DECLARE_ENUM_AS_BIT_SET(DoCommandFlag);
 

	
 
/**
 
 * Used to combine a StringID with the command.
 
 *
 
 * This macro can be used to add a StringID (the error message to show) on a command-id
 
 * (CMD_xxx). Use the binary or-operator "|" to combine the command with the result from
 
 * this macro.
 
 *
 
 * @param x The StringID to combine with a command-id
 
 */
 
#define CMD_MSG(x) ((x) << 16)
 

	
 
@@ -352,25 +354,25 @@ enum {
 
 * 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, uint32 flags, uint32 p1, uint32 p2, const char *text);
 
typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *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;
 
	byte flags;
 
};
 

	
src/company_cmd.cpp
Show inline comments
 
@@ -559,25 +559,25 @@ void CompaniesYearlyLoop()
 
 * - p2 = minimum amount of money available
 
 * if p1 = 3, then:
 
 * - p1 bits 16-31 = engine group
 
 * - p2 bits  0-15 = old engine type
 
 * - p2 bits 16-31 = new engine type
 
 * if p1 = 4, then:
 
 * - p1 bit     15 = enable engine renewal
 
 * - p1 bits 16-31 = months left before engine expires to replace it
 
 * - p2 bits  0-31 = minimum amount of money available
 
 * if p1 = 5, then
 
 * - p2 = enable renew_keep_length
 
 */
 
CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidCompanyID(_current_company)) return CMD_ERROR;
 

	
 
	Company *c = GetCompany(_current_company);
 
	switch (GB(p1, 0, 3)) {
 
		case 0:
 
			if (c->engine_renew == HasBit(p2, 0)) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				c->engine_renew = HasBit(p2, 0);
 
				if (IsLocalCompany()) {
 
					_settings_client.gui.autorenew = c->engine_renew;
 
@@ -702,25 +702,25 @@ void CompanyNewsInformation::FillData(co
 
 * @param p2 various functionality, dictated by p1
 
 * - p1 = 0 - ClientID of the newly created client
 
 * - p1 = 2 - CompanyID of the that is getting deleted
 
 * - p1 = 3 - #1 p2 = (bit  0-15) - company to merge (p2 & 0xFFFF)
 
 *          - #2 p2 = (bit 16-31) - company to be merged into ((p2>>16)&0xFFFF)
 
 * @todo In the case of p1=0, create new company, the clientID of the new client is in parameter
 
 * p2. This parameter is passed in at function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
 
 * on the server itself. First of all this is unbelievably ugly; second of all, well,
 
 * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
 
 * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
 
 * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
 
 */
 
CommandCost CmdCompanyCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (flags & DC_EXEC) _current_company = OWNER_NONE;
 

	
 
	InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
 

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

	
 
#ifdef ENABLE_NETWORK
 

	
src/dummy_land.cpp
Show inline comments
 
@@ -17,25 +17,25 @@ static void DrawTile_Dummy(TileInfo *ti)
 

	
 

	
 
static uint GetSlopeZ_Dummy(TileIndex tile, uint x, uint y)
 
{
 
	return 0;
 
}
 

	
 
static Foundation GetFoundation_Dummy(TileIndex tile, Slope tileh)
 
{
 
	return FOUNDATION_NONE;
 
}
 

	
 
static CommandCost ClearTile_Dummy(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Dummy(TileIndex tile, DoCommandFlag flags)
 
{
 
	return_cmd_error(STR_0001_OFF_EDGE_OF_MAP);
 
}
 

	
 

	
 
static void GetAcceptedCargo_Dummy(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_Dummy(TileIndex tile, TileDesc *td)
 
{
 
@@ -60,25 +60,25 @@ static bool ClickTile_Dummy(TileIndex ti
 
}
 

	
 
static void ChangeTileOwner_Dummy(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	/* not used */
 
}
 

	
 
static TrackStatus GetTileTrackStatus_Dummy(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 
{
 
	return 0;
 
}
 

	
 
static CommandCost TerraformTile_Dummy(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_Dummy(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	return_cmd_error(STR_0001_OFF_EDGE_OF_MAP);
 
}
 

	
 
extern const TileTypeProcs _tile_type_dummy_procs = {
 
	DrawTile_Dummy,           /* draw_tile_proc */
 
	GetSlopeZ_Dummy,          /* get_slope_z_proc */
 
	ClearTile_Dummy,          /* clear_tile_proc */
 
	GetAcceptedCargo_Dummy,   /* get_accepted_cargo_proc */
 
	GetTileDesc_Dummy,        /* get_tile_desc_proc */
 
	GetTileTrackStatus_Dummy, /* get_tile_track_status_proc */
 
	ClickTile_Dummy,          /* click_tile_proc */
src/economy.cpp
Show inline comments
 
@@ -1847,25 +1847,25 @@ static void DoAcquireCompany(Company *c)
 

	
 
	delete 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
 
 */
 
CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_OTHER);
 

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

	
 
	Company *c = GetCompany((CompanyID)p1);
 

	
 
	/* Protect new companies from hostile takeovers */
 
	if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_PROTECTED);
 

	
 
@@ -1892,25 +1892,25 @@ CommandCost CmdBuyShareInCompany(TileInd
 
		}
 
		InvalidateWindow(WC_COMPANY, p1);
 
	}
 
	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
 
 */
 
CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check if selling shares is allowed (protection against modified clients) */
 
	/* Cannot sell own shares */
 
	if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
 

	
 
	Company *c = GetCompany((CompanyID)p1);
 

	
 
	/* Those lines are here for network-protection (clients can be slow) */
 
	if (GetAmountOwnedBy(c, _current_company) == 0) return CommandCost();
 

	
 
	/* adjust it a little to make it less profitable to sell and buy */
 
	Money cost = CalculateCompanyValue(c) >> 2;
 
@@ -1925,25 +1925,25 @@ CommandCost CmdSellShareInCompany(TileIn
 
	return CommandCost(EXPENSES_OTHER, cost);
 
}
 

	
 
/** 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
 
 */
 
CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CompanyID cid = (CompanyID)p1;
 

	
 
	/* Disable takeovers in multiplayer games */
 
	if (!IsValidCompanyID(cid) || _networking) return CMD_ERROR;
 

	
 
	/* Do not allow companies to take over themselves */
 
	if (cid == _current_company) return CMD_ERROR;
 

	
 
	Company *c = GetCompany(cid);
 

	
 
	if (!c->is_ai) return CMD_ERROR;
src/engine.cpp
Show inline comments
 
@@ -458,25 +458,25 @@ void EnginesDailyLoop()
 
			}
 
		}
 
	}
 
}
 

	
 
/** 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 perfom
 
 * @param p1 engine-prototype offered
 
 * @param p2 unused
 
 */
 
CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Engine *e;
 

	
 
	if (!IsEngineIndex(p1)) return CMD_ERROR;
 
	e = GetEngine(p1);
 
	if (GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
 

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

	
 
	return CommandCost();
 
}
 

	
 
@@ -572,25 +572,25 @@ static bool IsUniqueEngineName(const cha
 
		if (e->name != NULL && strcmp(e->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Rename an engine.
 
 * @param tile unused
 
 * @param flags operation to perfom
 
 * @param p1 engine ID to rename
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsEngineIndex(p1)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueEngineName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Engine *e = GetEngine(p1);
src/group_cmd.cpp
Show inline comments
 
@@ -66,25 +66,25 @@ void InitializeGroup(void)
 
{
 
	_Group_pool.CleanPool();
 
	_Group_pool.AddBlockToPool();
 
}
 

	
 

	
 
/**
 
 * Create a new vehicle group.
 
 * @param tile unused
 
 * @param p1   vehicle type
 
 * @param p2   unused
 
 */
 
CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType vt = (VehicleType)p1;
 
	if (!IsCompanyBuildableVehicleType(vt)) return CMD_ERROR;
 

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

	
 
	if (flags & DC_EXEC) {
 
		Group *g = new Group(_current_company);
 
		g->replace_protection = false;
 
		g->vehicle_type = vt;
 

	
 
		_new_group_id = g->index;
 
@@ -94,25 +94,25 @@ CommandCost CmdCreateGroup(TileIndex til
 

	
 
	return CommandCost();
 
}
 

	
 

	
 
/**
 
 * Add all vehicles in the given group to the default group and then deletes the group.
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *      - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 */
 
CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Vehicle *v;
 

	
 
		/* Add all vehicles belong to the group to the default group */
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->group_id == g->index && v->type == g->vehicle_type) v->group_id = DEFAULT_GROUP;
 
@@ -153,25 +153,25 @@ static bool IsUniqueGroupName(const char
 
	}
 

	
 
	return true;
 
}
 

	
 
/**
 
 * Rename a group
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 * @param p2   unused
 
 */
 
CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueGroupName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 
@@ -188,25 +188,25 @@ CommandCost CmdRenameGroup(TileIndex til
 
	return CommandCost();
 
}
 

	
 

	
 
/**
 
 * Add a vehicle to a group
 
 * @param tile unused
 
 * @param p1   index of array group
 
 *   - p1 bit 0-15 : GroupID
 
 * @param p2   vehicle to add to a group
 
 *   - p2 bit 0-15 : VehicleID
 
 */
 
CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	GroupID new_g = p1;
 

	
 
	if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p2);
 

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

	
 
@@ -235,25 +235,25 @@ CommandCost CmdAddVehicleGroup(TileIndex
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Add all shared vehicles of all vehicles from a group
 
 * @param tile unused
 
 * @param p1   index of group array
 
 *  - p1 bit 0-15 : GroupID
 
 * @param p2   type of vehicles
 
 */
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType type = (VehicleType)p2;
 
	if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Vehicle *v;
 
		VehicleType type = (VehicleType)p2;
 
		GroupID id_g = p1;
 

	
 
		/* 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_ALL_VEHICLES(v) {
 
@@ -272,25 +272,25 @@ CommandCost CmdAddSharedVehicleGroup(Til
 

	
 
	return CommandCost();
 
}
 

	
 

	
 
/**
 
 * Remove all vehicles from a group
 
 * @param tile unused
 
 * @param p1   index of group array
 
 * - p1 bit 0-15 : GroupID
 
 * @param p2   type of vehicles
 
 */
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleType type = (VehicleType)p2;
 
	if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		GroupID old_g = p1;
 
		Vehicle *v;
 

	
 
		/* Find each Vehicle that belongs to the group old_g and add it to the default group */
 
@@ -309,25 +309,25 @@ CommandCost CmdRemoveAllVehiclesGroup(Ti
 
	return CommandCost();
 
}
 

	
 

	
 
/**
 
 * (Un)set global replace protection from a group
 
 * @param tile unused
 
 * @param p1   index of group array
 
 * - p1 bit 0-15 : GroupID
 
 * @param p2
 
 * - p2 bit 0    : 1 to set or 0 to clear protection.
 
 */
 
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidGroupID(p1)) return CMD_ERROR;
 

	
 
	Group *g = GetGroup(p1);
 
	if (g->owner != _current_company) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		g->replace_protection = HasBit(p2, 0);
 

	
 
		InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_company);
 
		InvalidateWindowData(WC_REPLACE_VEHICLE, g->vehicle_type);
 
	}
src/industry_cmd.cpp
Show inline comments
 
@@ -397,25 +397,25 @@ static void GetTileDesc_Industry(TileInd
 
	td->owner[0] = i->owner;
 
	td->str = is->name;
 
	if (!IsIndustryCompleted(tile)) {
 
		SetDParamX(td->dparam, 0, td->str);
 
		td->str = STR_2058_UNDER_CONSTRUCTION;
 
	}
 

	
 
	if (is->grf_prop.grffile != NULL) {
 
		td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->name;
 
	}
 
}
 

	
 
static CommandCost ClearTile_Industry(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags)
 
{
 
	Industry *i = GetIndustryByTile(tile);
 
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 

	
 
	/* water can destroy industries
 
	 * in editor you can bulldoze industries
 
	 * with magic_bulldozer cheat you can destroy industries
 
	 * (area around OILRIG is water, so water shouldn't flood it
 
	 */
 
	if ((_current_company != OWNER_WATER && _game_mode != GM_EDITOR &&
 
			!_cheats.magic_bulldozer.value) ||
 
			((flags & DC_AUTO) != 0) ||
 
@@ -1253,25 +1253,25 @@ static bool CheckIfIndustryTilesAreFree(
 
			}
 

	
 
			if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house
 
					((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house)
 
				if (!IsTileType(cur_tile, MP_HOUSE)) {
 
					_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS;
 
					return false;
 
				}
 

	
 
				/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
 
				CompanyID old_company = _current_company;
 
				_current_company = OWNER_TOWN;
 
				bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR));
 
				bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR));
 
				_current_company = old_company;
 

	
 
				if (not_clearable) return false;
 
			} else {
 
				/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
 
				CompanyID old_company = _current_company;
 
				_current_company = OWNER_TOWN;
 
				bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR));
 
				_current_company = old_company;
 

	
 
				if (not_clearable) return false;
 
			}
 
@@ -1329,25 +1329,25 @@ static bool CheckCanTerraformSurrounding
 
			if (TileX(tile_walk) == 0 || TileY(tile_walk) == 0 || !CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1))
 
				return false;
 
		}
 
	} END_TILE_LOOP(tile_walk, size_x, size_y, tile);
 

	
 
	return true;
 
}
 

	
 
/**
 
 * This function tries to flatten out the land below an industry, without
 
 *  damaging the surroundings too much.
 
 */
 
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const IndustryTileTable *it, int type)
 
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, const IndustryTileTable *it, int type)
 
{
 
	const int MKEND = -0x80;   // used for last element in an IndustryTileTable (see build_industry.h)
 
	int max_x = 0;
 
	int max_y = 0;
 
	TileIndex cur_tile;
 
	uint size_x, size_y;
 
	uint h, curh;
 

	
 
	/* Finds dimensions of largest variant of this industry */
 
	do {
 
		if (it->gfx == 0xFF) continue;  //  FF been a marquer for a check on clear water, skip it
 
		if (it->ti.x > max_x) max_x = it->ti.x;
 
@@ -1588,38 +1588,38 @@ static void DoCreateNewIndustry(Industry
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
 
}
 

	
 
/** Helper function for Build/Fund an industry
 
 * @param tile tile where industry is built
 
 * @param type of industry to build
 
 * @param flags of operations to conduct
 
 * @param indspec pointer to industry specifications
 
 * @param itspec_index the index of the itsepc to build/fund
 
 * @param seed random seed (possibly) used by industries
 
 * @return the pointer of the newly created industry, or NULL if it failed
 
 */
 
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed)
 
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed)
 
{
 
	const IndustryTileTable *it = indspec->table[itspec_index];
 
	bool custom_shape_check = false;
 

	
 
	if (!CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, &custom_shape_check)) return NULL;
 

	
 
	if (HasBit(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) {
 
		if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed)) return NULL;
 
	} else {
 
		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
 
	}
 

	
 
	if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
 
	if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NONE, it, type)) return NULL;
 
	if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL;
 

	
 
	const Town *t = CheckMultipleIndustryInTown(tile, type);
 
	if (t == NULL) return NULL;
 

	
 
	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
 

	
 
	if (!Industry::CanAllocateItem()) return NULL;
 

	
 
	if (flags & DC_EXEC) {
 
		Industry *i = new Industry(tile);
 
		if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
 
@@ -1633,25 +1633,25 @@ static Industry *CreateNewIndustryHelper
 
	return GetIndustry(0);
 
}
 

	
 
/** 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 - 15) - industry type see build_industry.h and see industry.h
 
 * - p1 = (bit 16 - 31) - first layout to try
 
 * @param p2 seed to use for variable 8F
 
 * @return index of the newly create industry, or CMD_ERROR if it failed
 
 */
 
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(GB(p1, 0, 16));
 
	const Industry *ind = NULL;
 

	
 
	/* Check if the to-be built/founded industry is available for this climate. */
 
	if (!indspec->enabled) {
 
		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 && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
 
@@ -2340,25 +2340,25 @@ Money IndustrySpec::GetConstructionCost(
 
	return (_price.build_industry *
 
			(_settings_game.construction.raw_industry_construction == 1 && this->IsRawIndustry() ?
 
					this->raw_industry_cost_multiplier :
 
					this->cost_multiplier
 
			)) >> 8;
 
}
 

	
 
Money IndustrySpec::GetRemovalCost() const
 
{
 
	return (_price.remove_house * this->removal_cost_multiplier) >> 8;
 
}
 

	
 
static CommandCost TerraformTile_Industry(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	if (AutoslopeEnabled()) {
 
		/* We imitate here TTDP's behaviour:
 
		 *  - Both new and old slope must not be steep.
 
		 *  - TileMaxZ must not be changed.
 
		 *  - Allow autoslope by default.
 
		 *  - Disallow autoslope if callback succeeds and returns non-zero.
 
		 */
 
		Slope tileh_old = GetTileSlope(tile, NULL);
 
		/* TileMaxZ must not be changed. Slopes must not be steep. */
 
		if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
 
			const IndustryGfx gfx = GetIndustryGfx(tile);
src/landscape.cpp
Show inline comments
 
@@ -579,36 +579,36 @@ byte HighestSnowLine(void)
 
void ClearSnowLine(void)
 
{
 
	free(_snow_line);
 
	_snow_line = NULL;
 
}
 

	
 
/** Clear a piece of landscape
 
 * @param tile tile to clear
 
 * @param flags of operation to conduct
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
 
}
 

	
 
/** Clear a big piece of landscape
 
 * @param tile end tile of area dragging
 
 * @param p1 start tile of area dragging
 
 * @param flags of operation to conduct
 
 * @param p2 unused
 
 */
 
CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	/* make sure sx,sy are smaller than ex,ey */
 
	int ex = TileX(tile);
 
	int ey = TileY(tile);
 
	int sx = TileX(p1);
 
	int sy = TileY(p1);
 
	if (ex < sx) Swap(ex, sx);
 
	if (ey < sy) Swap(ey, sy);
 

	
 
	Money money = GetAvailableMoneyForCommand();
src/misc_cmd.cpp
Show inline comments
 
@@ -19,46 +19,46 @@
 
#include "company_base.h"
 
#include "company_gui.h"
 
#include "settings_type.h"
 

	
 
#include "table/strings.h"
 

	
 
/** Change the company manager's face.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 face bitmasked
 
 */
 
CommandCost CmdSetCompanyManagerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CompanyManagerFace cmf = (CompanyManagerFace)p2;
 

	
 
	if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		GetCompany(_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 bits 8-9 set in use state or first/second colour
 
 * @param p2 new colour for vehicles, property, etc.
 
 */
 
CommandCost CmdSetCompanyColour(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 >= 16) return CMD_ERROR; // max 16 colours
 

	
 
	Colours colour = (Colours)p2;
 

	
 
	LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
 
	byte state = GB(p1, 8, 2);
 

	
 
	if (scheme >= LS_END || state >= 3) return CMD_ERROR;
 

	
 
	Company *c = GetCompany(_current_company);
 

	
 
@@ -121,25 +121,25 @@ CommandCost CmdSetCompanyColour(TileInde
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Increase the loan of your company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
 
 * @param p2 when 0: loans LOAN_INTERVAL
 
 *           when 1: loans the maximum loan permitting money (press CTRL),
 
 *           when 2: loans the amount specified in p1
 
 */
 
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = GetCompany(_current_company);
 

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

	
 
	Money loan;
 
	switch (p2) {
 
		default: return CMD_ERROR; // Invalid method
 
		case 0: // Take some extra loan
 
@@ -165,25 +165,25 @@ CommandCost CmdIncreaseLoan(TileIndex ti
 

	
 
	return CommandCost(EXPENSES_OTHER);
 
}
 

	
 
/** Decrease the loan of your company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
 
 * @param p2 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
 
 */
 
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = GetCompany(_current_company);
 

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

	
 
	Money loan;
 
	switch (p2) {
 
		default: return CMD_ERROR; // Invalid method
 
		case 0: // Pay back one step
 
			loan = min(c->current_loan, (Money)LOAN_INTERVAL);
 
			break;
 
		case 1: // Pay back as much as possible
 
@@ -217,25 +217,25 @@ static bool IsUniqueCompanyName(const ch
 
		if (c->name != NULL && strcmp(c->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Change the name of the company.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueCompanyName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Company *c = GetCompany(_current_company);
 
		free(c->name);
 
		c->name = reset ? NULL : strdup(text);
 
@@ -253,25 +253,25 @@ static bool IsUniquePresidentName(const 
 
		if (c->president_name != NULL && strcmp(c->president_name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Change the name of the president.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenamePresident(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniquePresidentName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Company *c = GetCompany(_current_company);
 
		free(c->president_name);
 

	
 
@@ -305,25 +305,25 @@ static void AskUnsafeUnpauseCallback(Win
 
	DoCommandP(0, confirmed ? 0 : 1, 0, CMD_PAUSE);
 
}
 

	
 
/** Pause/Unpause the game (server-only).
 
 * Increase or decrease the pause counter. If the counter is zero,
 
 * the game is unpaused. A counter is used instead of a boolean value
 
 * to have more control over the game when saving/loading, etc.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 0 = decrease pause counter; 1 = increase pause counter
 
 * @param p2 unused
 
 */
 
CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (flags & DC_EXEC) {
 
		_pause_game += (p1 == 0) ? -1 : 1;
 

	
 
		switch (_pause_game) {
 
			case -4:
 
			case -1:
 
				_pause_game = 0;
 
				break;
 
			case -3:
 
				ShowQuery(
 
					STR_NEWGRF_UNPAUSE_WARNING_TITLE,
 
@@ -341,42 +341,42 @@ CommandCost CmdPause(TileIndex tile, uin
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Change the financial flow of your company.
 
 * This is normally only enabled in offline mode, but if there is a debug
 
 * build, you can cheat (to test).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the amount of money to receive (if negative), or spend (if positive)
 
 * @param p2 unused
 
 */
 
CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMoneyCheat(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
#ifndef _DEBUG
 
	if (_networking) return CMD_ERROR;
 
#endif
 
	return CommandCost(EXPENSES_OTHER, -(int32)p1);
 
}
 

	
 
/** 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 explicitely, or implicitely
 
 * 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
 
 */
 
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.economy.give_money) return CMD_ERROR;
 

	
 
	const Company *c = GetCompany(_current_company);
 
	CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL));
 

	
 
	/* 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;
 
	if (!_networking || !IsValidCompanyID((CompanyID)p2)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* Add money to company */
src/misc_gui.cpp
Show inline comments
 
@@ -85,25 +85,25 @@ public:
 
		if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
 
			SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
 
			DrawStringMultiCenter(150, y, STR_JUST_RAW_STRING, this->width - 4);
 
		}
 
	}
 

	
 
	LandInfoWindow(TileIndex tile) : Window(&_land_info_desc) {
 
		Company *c = GetCompany(IsValidCompanyID(_local_company) ? _local_company : COMPANY_FIRST);
 
		Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
 

	
 
		Money old_money = c->money;
 
		c->money = INT64_MAX;
 
		CommandCost costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
 
		CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
 
		c->money = old_money;
 

	
 
		/* Because build_date is not set yet in every TileDesc, we make sure it is empty */
 
		TileDesc td;
 
		AcceptedCargo ac;
 

	
 
		td.build_date = INVALID_DATE;
 

	
 
		/* Most tiles have only one owner, but
 
		 *  - drivethrough roadstops can be build on town owned roads (up to 2 owners) and
 
		 *  - roads can have up to four owners (railroad, road, tram, 3rd-roadtype "highway").
 
		 */
src/order_cmd.cpp
Show inline comments
 
@@ -402,25 +402,25 @@ static uint GetOrderDistance(const Order
 
}
 

	
 
/** 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 - 15) - ID of the vehicle
 
 * - p1 = (bit 16 - 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
 
 */
 
CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleID veh   = GB(p1,  0, 16);
 
	VehicleOrderID sel_ord = GB(p1, 16, 16);
 
	Order new_order(p2);
 

	
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	v = GetVehicle(veh);
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
@@ -620,41 +620,41 @@ CommandCost CmdInsertOrder(TileIndex til
 

	
 
		/* Make sure to rebuild the whole list */
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** Declone an order-list
 
 * @param *dst delete the orders of this vehicle
 
 * @param flags execution flags
 
 */
 
static CommandCost DecloneOrder(Vehicle *dst, uint32 flags)
 
static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
 
{
 
	if (flags & DC_EXEC) {
 
		DeleteVehicleOrders(dst);
 
		InvalidateVehicleOrder(dst, -1);
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
 
	}
 
	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)
 
 */
 
CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleID veh_id = p1;
 
	VehicleOrderID sel_ord = p2;
 
	Order *order;
 

	
 
	if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
 

	
 
	v = GetVehicle(veh_id);
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
@@ -704,25 +704,25 @@ CommandCost CmdDeleteOrder(TileIndex til
 
		InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/** 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
 
 */
 
CommandCost CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleID veh_id = p1;
 
	VehicleOrderID sel_ord = p2;
 

	
 
	if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
 

	
 
	v = GetVehicle(veh_id);
 

	
 
	if (!CheckOwnership(v->owner) || sel_ord == v->cur_order_index ||
 
			sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
 

	
 
@@ -744,25 +744,25 @@ CommandCost CmdSkipToOrder(TileIndex til
 
}
 

	
 
/**
 
 * Move an order inside the orderlist
 
 * @param tile unused
 
 * @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
 
 * @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, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleID veh = p1;
 
	VehicleOrderID moving_order = GB(p2,  0, 16);
 
	VehicleOrderID target_order = GB(p2, 16, 16);
 

	
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(veh);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	/* Don't make senseless movements */
 
	if (moving_order >= v->GetNumOrders() || target_order >= v->GetNumOrders() ||
 
@@ -822,25 +822,25 @@ CommandCost CmdMoveOrder(TileIndex tile,
 
/** Modify an order in the orderlist of a vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 - 15) - ID of the vehicle
 
 * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
 
 *                        the order will be inserted before that one
 
 *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
 
 * @param p2 various bitstuffed elements
 
 *  - p2 = (bit 0 -  3) - what data to modify (@see ModifyOrderFlags)
 
 *  - p2 = (bit 4 - 15) - the data to modify
 
 */
 
CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
 
	VehicleID veh          = GB(p1,  0, 16);
 
	ModifyOrderFlags mof   = (ModifyOrderFlags)GB(p2,  0,  4);
 
	uint16 data             = GB(p2, 4, 11);
 

	
 
	if (mof >= MOF_END) return CMD_ERROR;
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(veh);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
@@ -1039,25 +1039,25 @@ CommandCost CmdModifyOrder(TileIndex til
 

	
 
	return CommandCost();
 
}
 

	
 
/** Clone/share/copy an order-list of an other vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0-15) - destination vehicle to clone orders to (p1 & 0xFFFF)
 
 * - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE)
 
 * @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE
 
 */
 
CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *dst;
 
	VehicleID veh_src = GB(p1, 16, 16);
 
	VehicleID veh_dst = GB(p1,  0, 16);
 

	
 
	if (!IsValidVehicleID(veh_dst)) return CMD_ERROR;
 

	
 
	dst = GetVehicle(veh_dst);
 

	
 
	if (!CheckOwnership(dst->owner)) return CMD_ERROR;
 

	
 
	switch (p2) {
 
@@ -1168,25 +1168,25 @@ CommandCost CmdCloneOrder(TileIndex tile
 
	return CommandCost();
 
}
 

	
 
/** 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 8-15 Cargo subtype
 
 *   - bit 16-23 number of order to modify
 
 */
 
CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	const Vehicle *v;
 
	Order *order;
 
	VehicleID veh = GB(p1, 0, 16);
 
	VehicleOrderID order_number  = GB(p2, 16, 8);
 
	CargoID cargo = GB(p2, 0, 8);
 
	byte subtype  = GB(p2, 8, 8);
 

	
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	v = GetVehicle(veh);
 

	
 
@@ -1324,25 +1324,25 @@ void RestoreVehicleOrders(const Vehicle 
 
 * @param flags operation to perform
 
 * @param p1 the ID of the vehicle
 
 * @param p2 various bistuffed elements
 
 * - p2 = (bit  0-15) - current order-index (p2 & 0xFFFF)
 
 * - p2 = (bit 16-31) - service interval (p2 >> 16)
 
 * @todo Unfortunately you cannot safely restore the unitnumber or the old vehicle
 
 * as far as I can see. We can store it in BackuppedOrders, and restore it, but
 
 * but we have no way of seeing it has been tampered with or not, as we have no
 
 * legit way of knowing what that ID was.@n
 
 * If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and
 
 * restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;"
 
 */
 
CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRestoreOrderIndex(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	VehicleOrderID cur_ord = GB(p2,  0, 16);
 
	uint16 serv_int = GB(p2, 16, 16);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	/* Check the vehicle type and ownership, and if the service interval and order are in range */
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->GetNumOrders()) return CMD_ERROR;
src/rail_cmd.cpp
Show inline comments
 
@@ -294,25 +294,25 @@ static CommandCost CheckRailSlope(Slope 
 
	return CommandCost(EXPENSES_CONSTRUCTION, f_new != f_old ? _price.terraform : (Money)0);
 
}
 

	
 
/* Validate functions for rail building */
 
static inline bool ValParamTrackOrientation(Track track) {return IsValidTrack(track);}
 

	
 
/** 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 rail track to build
 
 */
 
CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Slope tileh;
 
	RailType railtype = (RailType)p1;
 
	Track track = (Track)p2;
 
	TrackBits trackbit;
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost ret;
 

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

	
 
	tileh = GetTileSlope(tile, NULL);
 
	trackbit = TrackToTrackBits(track);
 
@@ -433,25 +433,25 @@ CommandCost CmdBuildSingleRail(TileIndex
 
		YapfNotifyTrackLayoutChange(tile, track);
 
	}
 

	
 
	return cost.AddCost(RailBuildCost(railtype));
 
}
 

	
 
/** 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
 
 */
 
CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)p2;
 
	TrackBits trackbit;
 
	CommandCost cost(EXPENSES_CONSTRUCTION, _price.remove_rail );
 
	bool crossing = false;
 

	
 
	if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
 
	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),
 
@@ -659,25 +659,25 @@ static CommandCost ValidateAutoDrag(Trac
 
	return CommandCost();
 
}
 

	
 
/** Build a stretch of railroad tracks.
 
 * @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-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 */
 
static CommandCost CmdRailTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
 
	Track track = (Track)GB(p2, 4, 3);
 
	Trackdir trackdir;
 
	byte mode = HasBit(p2, 7);
 
	RailType railtype = (RailType)GB(p2, 0, 4);
 
	TileIndex end_tile;
 

	
 
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	end_tile = p1;
 
	trackdir = TrackToTrackdir(track);
 
@@ -709,55 +709,55 @@ static CommandCost CmdRailTrackHelper(Ti
 

	
 
/** 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-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 * @see CmdRailTrackHelper
 
 */
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 7), 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-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev)
 
 * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 * @see CmdRailTrackHelper
 
 */
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 7), 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)
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Slope tileh;
 

	
 
	/* check railtype and valid direction for depot (0 through 3), 4 in total */
 
	if (!ValParamRailtype((RailType)p1)) return CMD_ERROR;
 

	
 
	tileh = GetTileSlope(tile, NULL);
 

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

	
 
	/* Prohibit construction if
 
	 * The tile is non-flat AND
 
@@ -803,25 +803,25 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit 0-2) - track-orientation, valid values: 0-5 (Track enum)
 
 * - p1 = (bit 3)   - 1 = override signal/semaphore, or pre/exit/combo signal or (for bit 7) toggle variant (CTRL-toggle)
 
 * - 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
 
 * @param p2 used for CmdBuildManySignals() to copy direction of first signal
 
 * TODO: p2 should be replaced by two bits for "along" and "against" the track.
 
 */
 
CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 
	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 = (SignalType)GB(p1, 5, 3); // the signal type of the new signal
 
	bool convert_signal = HasBit(p1, 8); // convert button pressed
 
	SignalType cycle_start = (SignalType)GB(p1, 9, 3);
 
	SignalType cycle_stop = (SignalType)GB(p1, 12, 3);
 
	CommandCost cost;
 
	uint num_dir_cycle = GB(p1, 15, 2);
 

	
 
	if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
 
@@ -1015,25 +1015,25 @@ static bool CheckSignalAutoFill(TileInde
 
 * @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- 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
 
 */
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
 
	int signal_ctr;
 
	byte signals;
 
	bool error = true;
 
	TileIndex end_tile;
 
	TileIndex start_tile = tile;
 

	
 
	Track track = (Track)GB(p2, 0, 3);
 
	bool mode = HasBit(p2, 3);
 
	bool semaphores = HasBit(p2, 4);
 
	bool remove = HasBit(p2, 5);
 
@@ -1141,39 +1141,39 @@ static CommandCost CmdSignalTrackHelper(
 
 * @param flags operation to perform
 
 * @param p1  end tile of drag
 
 * @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
 
 * @see CmdSignalTrackHelper
 
 */
 
CommandCost CmdBuildSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *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
 
 */
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 

	
 
	if (!ValParamTrackOrientation(track) ||
 
			!IsTileType(tile, MP_RAILWAY) ||
 
			!HasTrack(tile, track) ||
 
			!EnsureNoTrainOnTrack(tile, track) ||
 
			!HasSignalOnTrack(tile, track)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	/* Only water can remove signals from anyone */
 
@@ -1210,50 +1210,50 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
 * @param flags operation to perform
 
 * @param p1  end tile of drag
 
 * @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
 
 * @see CmdSignalTrackHelper
 
 */
 
CommandCost CmdRemoveSignalTrack(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *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 */
 
Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
 
{
 
	/* Similiar checks as in TrainPowerChanged() */
 

	
 
	if (v->type == VEH_TRAIN && !IsArticulatedPart(v)) {
 
		const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
 
		if (GetVehicleProperty(v, 0x0B, rvi->power) != 0) TrainPowerChanged(v->First());
 
	}
 

	
 
	return NULL;
 
}
 

	
 
/** 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 new railtype to convert to
 
 */
 
CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	RailType totype = (RailType)p2;
 

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

	
 
	uint ex = TileX(tile);
 
	uint ey = TileY(tile);
 
	uint sx = TileX(p1);
 
	uint sy = TileY(p1);
 

	
 
@@ -1408,25 +1408,25 @@ CommandCost CmdConvertRail(TileIndex til
 
					break;
 
			}
 

	
 
			for (uint i = 0; i < vehicles_affected.Length(); ++i) {
 
				TryPathReserve(vehicles_affected[i], true);
 
			}
 
		}
 
	}
 

	
 
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
 
}
 

	
 
static CommandCost RemoveTrainDepot(TileIndex tile, uint32 flags)
 
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER)
 
		return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile))
 
		return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* read variables before the depot is removed */
 
		DiagDirection dir = GetRailDepotDirection(tile);
 
		Owner owner = GetTileOwner(tile);
 
		Vehicle *v = NULL;
 
@@ -1437,25 +1437,25 @@ static CommandCost RemoveTrainDepot(Tile
 
		}
 

	
 
		DoClearSquare(tile);
 
		delete GetDepotByTile(tile);
 
		AddSideToSignalBuffer(tile, dir, owner);
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
 
		if (v != NULL) TryPathReserve(v, true);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
 
}
 

	
 
static CommandCost ClearTile_Track(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost ret;
 

	
 
	if (flags & DC_AUTO) {
 
		if (!IsTileOwner(tile, _current_company))
 
			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
 

	
 
		if (IsPlainRailTile(tile)) {
 
			return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
 
		} else {
 
			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 
@@ -2538,25 +2538,25 @@ static CommandCost TestAutoslopeOnRailTi
 
	if (z_old != z_new) return CMD_ERROR;
 

	
 
	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
	/* Make the ground dirty, if surface slope has changed */
 
	if (tileh_old != tileh_new) {
 
		/* If there is flat water on the lower halftile add the cost for clearing it */
 
		if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price.clear_water);
 
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
 
	}
 
	return  cost;
 
}
 

	
 
static CommandCost TerraformTile_Track(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	uint z_old;
 
	Slope tileh_old = GetTileSlope(tile, &z_old);
 
	if (IsPlainRailTile(tile)) {
 
		TrackBits rail_bits = GetTrackBits(tile);
 
		/* Is there flat water on the lower halftile, that must be cleared expensively? */
 
		bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old));
 

	
 
		_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
 

	
 
		/* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */
 
		CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits);
src/road_cmd.cpp
Show inline comments
 
@@ -103,25 +103,25 @@ static const RoadBits _invalid_tileh_slo
 
Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
 

	
 
/**
 
 * Is it allowed to remove the given road bits from the given tile?
 
 * @param tile      the tile to remove the road from
 
 * @param remove    the roadbits that are going to be removed
 
 * @param owner     the actual owner of the roadbits of the tile
 
 * @param rt        the road type to remove the bits from
 
 * @param flags     command flags
 
 * @param town_check Shall the town rating checked/affected
 
 * @return true when it is allowed to remove the road bits
 
 */
 
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, uint32 flags, bool town_check)
 
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check)
 
{
 
	if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return true;
 

	
 
	/* Water can always flood and towns can always remove "normal" road pieces.
 
	 * Towns are not be allowed to remove non "normal" road pieces, like tram
 
	 * tracks as that would result in trams that cannot turn. */
 
	if (_current_company == OWNER_WATER ||
 
			(rt == ROADTYPE_ROAD && !IsValidCompanyID(_current_company))) return true;
 

	
 
	/* Only do the special processing if the road is owned
 
	 * by a town */
 
	if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner);
 
@@ -161,25 +161,25 @@ bool CheckAllowRemoveRoad(TileIndex tile
 

	
 
	return true;
 
}
 

	
 

	
 
/** Delete a piece of road.
 
 * @param tile tile where to remove road from
 
 * @param flags operation to perform
 
 * @param pieces roadbits to remove
 
 * @param rt roadtype to remove
 
 * @param crossing_check should we check if there is a tram track when we are removing road from crossing?
 
 */
 
static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, RoadType rt, bool crossing_check, bool town_check = true)
 
static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadType rt, bool crossing_check, bool town_check = true)
 
{
 
	RoadTypes rts = GetRoadTypes(tile);
 
	/* The tile doesn't have the given road type */
 
	if (!HasBit(rts, rt)) return CMD_ERROR;
 

	
 
	bool town_road_under_stop = false;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_ROAD:
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			break;
 

	
 
@@ -337,25 +337,25 @@ static CommandCost RemoveRoad(TileIndex 
 
			return CMD_ERROR;
 
	}
 
}
 

	
 

	
 
/** Delete a piece of road.
 
 * @param tile tile where to remove road from
 
 * @param flags operation to perform
 
 * @param p1 bit 0..3 road pieces to remove (RoadBits)
 
 *           bit 4..5 road type
 
 * @param p2 unused
 
 */
 
CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	RoadType rt = (RoadType)GB(p1, 4, 2);
 
	if (!IsValidRoadType(rt)) return CMD_ERROR;
 

	
 
	RoadBits pieces = Extract<RoadBits, 0>(p1);
 

	
 
	return RemoveRoad(tile, flags, pieces, rt, true);
 
}
 

	
 
/**
 
 * Calculate the costs for roads on slopes
 
 *  Aside modify the RoadBits to fit on the slopes
 
@@ -431,25 +431,25 @@ static CommandCost CheckRoadSlope(Slope 
 
	}
 
	return CMD_ERROR;
 
}
 

	
 
/** 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..5 road type
 
 *           bit 6..7 disallowed directions to toggle
 
 * @param p2 the town that is building the road (0 if not applicable)
 
 */
 
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	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 ((IsValidCompanyID(_current_company) && p2 != 0) || (_current_company == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
 
	if (_current_company != OWNER_TOWN) {
 
		const Town *town = CalcClosestTownFromTile(tile, UINT_MAX);
 
		p2 = (town != NULL) ? town->index : (TownID)INVALID_TOWN;
 
@@ -674,25 +674,25 @@ do_clear:;
 

	
 
/** Build a long piece of road.
 
 * @param end_tile end tile of drag
 
 * @param flags operation to perform
 
 * @param p1 start 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 + 4) - road type
 
 * - p2 = (bit 5) - set road direction
 
 */
 
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	bool had_bridge = false;
 
	bool had_tunnel = false;
 
	bool had_success = false;
 
	DisallowedRoadDirections drd = DRD_NORTHBOUND;
 

	
 
	_error_message = INVALID_STRING_ID;
 

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

	
 
	TileIndex start_tile = p1;
 
@@ -760,25 +760,25 @@ CommandCost CmdBuildLongRoad(TileIndex e
 
}
 

	
 
/** Remove a long piece of road.
 
 * @param end_tile end tile of drag
 
 * @param flags operation to perform
 
 * @param p1 start 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 + 4) - road type
 
 */
 
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

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

	
 
	TileIndex start_tile = p1;
 
	RoadType rt = (RoadType)GB(p2, 3, 2);
 
	if (!IsValidRoadType(rt)) return CMD_ERROR;
 

	
 
	/* Only drag in X or Y direction dictated by the direction variable */
 
	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
 
	if (HasBit(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
 
@@ -825,25 +825,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..3 road type
 
 * @param p2 unused
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	DiagDirection dir = Extract<DiagDirection, 0>(p1);
 
	RoadType rt = (RoadType)GB(p1, 2, 2);
 

	
 
	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
 

	
 
	Slope tileh = GetTileSlope(tile, NULL);
 
	if (tileh != SLOPE_FLAT && (
 
				!_settings_game.construction.build_on_slopes ||
 
				IsSteepSlope(tileh) ||
 
				!CanBuildDepotByTileh(dir, tileh)
 
			)) {
 
@@ -858,39 +858,39 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *dep = new Depot(tile);
 
		dep->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
 

	
 
		MakeRoadDepot(tile, _current_company, dir, rt, dep->town_index);
 
		MarkTileDirtyByTile(tile);
 
	}
 
	return cost.AddCost(_price.build_road_depot);
 
}
 

	
 
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
 
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile);
 
		delete GetDepotByTile(tile);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road_depot);
 
}
 

	
 
static CommandCost ClearTile_Road(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
 
{
 
	switch (GetRoadTileType(tile)) {
 
		case ROAD_TILE_NORMAL: {
 
			RoadBits b = GetAllRoadBits(tile);
 

	
 
			/* Clear the road if only one piece is on the tile OR we are not using the DC_AUTO flag */
 
			if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) || !(flags & DC_AUTO)) {
 
				RoadTypes rts = GetRoadTypes(tile);
 
				CommandCost ret(EXPENSES_CONSTRUCTION);
 
				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
 
					if (HasBit(rts, rt)) {
 
						CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true);
 
@@ -1579,25 +1579,25 @@ static void ChangeTileOwner_Road(TileInd
 

	
 
	if (IsLevelCrossing(tile)) {
 
		if (GetTileOwner(tile) == old_owner) {
 
			if (new_owner == INVALID_OWNER) {
 
				DoCommand(tile, 0, GetCrossingRailTrack(tile), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
 
			} else {
 
				SetTileOwner(tile, new_owner);
 
			}
 
		}
 
	}
 
}
 

	
 
static CommandCost TerraformTile_Road(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
 
		switch (GetRoadTileType(tile)) {
 
			case ROAD_TILE_CROSSING:
 
				if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
				break;
 

	
 
			case ROAD_TILE_DEPOT:
 
				if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
				break;
 

	
 
			case ROAD_TILE_NORMAL: {
src/road_internal.h
Show inline comments
 
@@ -16,22 +16,22 @@
 
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb);
 

	
 
/**
 
 * Is it allowed to remove the given road bits from the given tile?
 
 * @param tile      the tile to remove the road from
 
 * @param remove    the roadbits that are going to be removed
 
 * @param owner     the actual owner of the roadbits of the tile
 
 * @param rt        the road type to remove the bits from
 
 * @param flags     command flags
 
 * @param town_check Shall the town rating checked/affected
 
 * @return true when it is allowed to remove the road bits
 
 */
 
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, uint32 flags, bool town_check = true);
 
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check = true);
 

	
 
/**
 
 * Draw the catenary for tram road bits
 
 * @param ti   information about the tile (position, slope)
 
 * @param tram the roadbits to draw the catenary for
 
 */
 
void DrawTramCatenary(const TileInfo *ti, RoadBits tram);
 

	
 
#endif /* ROAD_INTERNAL_H */
src/roadveh_cmd.cpp
Show inline comments
 
@@ -149,25 +149,25 @@ void RoadVehUpdateCache(Vehicle *v)
 

	
 
		/* Invalidate the vehicle colour map */
 
		u->colourmap = PAL_NONE;
 
	}
 
}
 

	
 
/** Build a road vehicle.
 
 * @param tile tile of depot where road vehicle is built
 
 * @param flags operation to perform
 
 * @param p1 bus/truck type being built (engine)
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	UnitID unit_num;
 

	
 
	if (!IsEngineBuildable(p1, VEH_ROAD, _current_company)) return_cmd_error(STR_ROAD_VEHICLE_NOT_AVAILABLE);
 

	
 
	const Engine *e = GetEngine(p1);
 
	CommandCost cost(EXPENSES_NEW_VEHICLES, e->GetCost());
 
	if (flags & DC_QUERY_COST) return cost;
 

	
 
	/* The ai_new queries the vehicle cost before building the route,
 
	 * so we must check against cheaters no sooner than now. --pasky */
 
@@ -304,25 +304,25 @@ bool RoadVehicle::IsStoppedInDepot() con
 
	for (const Vehicle *v = this; v != NULL; v = v->Next()) {
 
		if (v->u.road.state != RVSB_IN_DEPOT || v->tile != tile) return false;
 
	}
 
	return true;
 
}
 

	
 
/** Sell a road vehicle.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 */
 
CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
	if (!v->IsStoppedInDepot()) {
 
@@ -409,48 +409,48 @@ bool RoadVehicle::FindClosestDepot(TileI
 

	
 
	return true;
 
}
 

	
 
/** Send a road vehicle to the depot.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
CommandCost CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSendRoadVehToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_ROAD) return CMD_ERROR;
 

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

	
 
/** Turn a roadvehicle around.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to turn
 
 * @param p2 unused
 
 */
 
CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->vehstatus & VS_STOPPED ||
 
			v->vehstatus & VS_CRASHED ||
 
			v->breakdown_ctr != 0 ||
 
@@ -1327,25 +1327,25 @@ static Trackdir FollowPreviousRoadVehicl
 
 * Can a tram track build without destruction on the given tile?
 
 * @param c the company that would be building the tram tracks
 
 * @param t the tile to build on.
 
 * @param r the road bits needed.
 
 * @return true when a track track can be build on 't'
 
 */
 
static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadBits r)
 
{
 
	/* The 'current' company is not necessarily the owner of the vehicle. */
 
	CompanyID original_company = _current_company;
 
	_current_company = c;
 

	
 
	CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, 0, CMD_BUILD_ROAD);
 
	CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, DC_NONE, CMD_BUILD_ROAD);
 

	
 
	_current_company = original_company;
 
	return CmdSucceeded(ret);
 
}
 

	
 
static bool IndividualRoadVehicleController(Vehicle *v, const Vehicle *prev)
 
{
 
	Direction new_dir;
 
	Direction old_dir;
 
	RoadDriveEntry rd;
 
	int x, y;
 
	uint32 r;
 
@@ -1975,25 +1975,25 @@ void RoadVehicle::OnNewDay()
 
}
 

	
 
/** Refit a road vehicle to the specified cargo type
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 Vehicle ID of the vehicle to refit
 
 * @param p2 Bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	CommandCost cost(EXPENSES_ROADVEH_RUN);
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	bool only_this = HasBit(p2, 16);
 
	uint16 capacity = CALLBACK_FAILED;
 
	uint total_capacity = 0;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
src/settings.cpp
Show inline comments
 
@@ -1964,25 +1964,25 @@ static const SettingDesc *GetSettingDesc
 
	if (index >= lengthof(_settings)) return NULL;
 
	return &_settings[index];
 
}
 

	
 
/** 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
 
 * @see _settings
 
 */
 
CommandCost CmdChangeSetting(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	const SettingDesc *sd = GetSettingDescription(p1);
 

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

	
 
	if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return CMD_ERROR;
 
	if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return CMD_ERROR;
 
	if ((sd->desc.flags & SGF_NEWGAME_ONLY) && _game_mode != GM_MENU) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		GameSettings *s = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
src/ship_cmd.cpp
Show inline comments
 
@@ -719,25 +719,25 @@ void Ship::Tick()
 
	if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
 

	
 
	AgeShipCargo(this);
 
	ShipController(this);
 
}
 

	
 
/** Build a ship.
 
 * @param tile tile of depot where ship is built
 
 * @param flags type of operation
 
 * @param p1 ship type being built (engine)
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	UnitID unit_num;
 

	
 
	if (!IsEngineBuildable(p1, VEH_SHIP, _current_company)) return_cmd_error(STR_SHIP_NOT_AVAILABLE);
 

	
 
	const Engine *e = GetEngine(p1);
 
	CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
 

	
 
	if (flags & DC_QUERY_COST) return value;
 

	
 
	/* The ai_new queries the vehicle cost before building the route,
 
	 * so we must check against cheaters no sooner than now. --pasky */
 
@@ -811,25 +811,25 @@ CommandCost CmdBuildShip(TileIndex tile,
 
		GetCompany(_current_company)->num_engines[p1]++;
 
	}
 

	
 
	return value;
 
}
 

	
 
/** Sell a ship.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to be sold
 
 * @param p2 unused
 
 */
 
CommandCost CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
	if (!v->IsStoppedInDepot()) {
 
@@ -856,25 +856,25 @@ bool Ship::FindClosestDepot(TileIndex *l
 

	
 
	return true;
 
}
 

	
 
/** Send a ship to the depot.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
CommandCost CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSendShipToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_SHIP, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_SHIP) return CMD_ERROR;
 
@@ -884,25 +884,25 @@ CommandCost CmdSendShipToDepot(TileIndex
 

	
 

	
 
/** Refits a ship to the specified cargo type.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID of the ship to refit
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle (ignored)
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v;
 
	CommandCost cost(EXPENSES_SHIP_RUN);
 
	CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
 
	byte new_subtype = GB(p2, 8, 8);
 
	uint16 capacity = CALLBACK_FAILED;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR;
src/signs.cpp
Show inline comments
 
@@ -81,25 +81,25 @@ static void MarkSignDirty(Sign *si)
 
		si->sign.top  + ScaleByZoom(12, ZOOM_LVL_MAX));
 
}
 

	
 
/**
 
 * 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
 
 */
 
CommandCost CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Try to locate a new sign */
 
	if (!Sign::CanAllocateItem()) return_cmd_error(STR_2808_TOO_MANY_SIGNS);
 

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

	
 
	/* When we execute, really make the sign */
 
	if (flags & DC_EXEC) {
 
		Sign *si = new Sign(_current_company);
 
		int x = TileX(tile) * TILE_SIZE;
 
		int y = TileY(tile) * TILE_SIZE;
 
@@ -119,25 +119,25 @@ CommandCost CmdPlaceSign(TileIndex tile,
 
	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
 
 * @return 0 if succesfull, otherwise CMD_ERROR
 
 */
 
CommandCost CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidSignID(p1)) return CMD_ERROR;
 

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

	
 
		if (flags & DC_EXEC) {
 
			Sign *si = GetSign(p1);
 

	
 
			/* Delete the old name */
 
			free(si->name);
src/station_cmd.cpp
Show inline comments
 
@@ -687,37 +687,37 @@ static void UpdateStationSignCoord(Stati
 
 * @param st Station
 
 */
 
static void DeleteStationIfEmpty(Station *st)
 
{
 
	if (st->facilities == 0) {
 
		st->delete_ctr = 0;
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
 
	}
 
	/* station remains but it probably lost some parts - station sign should stay in the station boundaries */
 
	UpdateStationSignCoord(st);
 
}
 

	
 
static CommandCost ClearTile_Station(TileIndex tile, byte flags);
 
static CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags);
 

	
 
/** Tries to clear the given area.
 
 * @param tile TileIndex to start check
 
 * @param w width of search area
 
 * @param h height of search area
 
 * @param flags operation to perform
 
 * @param invalid_dirs prohibited directions (set of DiagDirections)
 
 * @param station StationID to be queried and returned if available
 
 * @param check_clear if clearing tile should be performed (in wich case, cost will be added)
 
 * @return the cost in case of success, or an error code if it failed.
 
 */
 
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID *station, bool check_clear = true)
 
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, DoCommandFlag flags, uint invalid_dirs, StationID *station, bool check_clear = true)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	int allowed_z = -1;
 

	
 
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
 
		if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) {
 
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 
		}
 

	
 
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
 

	
 
		uint z;
 
@@ -891,25 +891,25 @@ static void GetStationLayout(byte *layou
 
 * @param flags operation to perform
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0- 3) - railtype (p1 & 0xF)
 
 * - p1 = (bit  4)    - 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 (INVALID_STATION if build new one)
 
 */
 
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Does the authority allow this? */
 
	if (!CheckIfAuthorityAllowsNewStation(tile_org, flags)) return CMD_ERROR;
 
	if (!ValParamRailtype((RailType)(p1 & 0xF))) return CMD_ERROR;
 

	
 
	/* unpack parameters */
 
	Axis axis = Extract<Axis, 4>(p1);
 
	uint numtracks = GB(p1,  8, 8);
 
	uint plat_len  = GB(p1, 16, 8);
 

	
 
	int w_org, h_org;
 
	if (axis == AXIS_X) {
 
@@ -1183,25 +1183,25 @@ restart:
 
	st->trainst_w = w;
 
	st->trainst_h = h;
 
	st->train_tile = tile;
 
}
 

	
 
/** Remove a single tile from a railroad station.
 
 * This allows for custom-built station with holes and weird layouts
 
 * @param tile tile of station piece to remove
 
 * @param flags operation to perform
 
 * @param p1 start_tile
 
 * @param p2 unused
 
 */
 
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TileIndex start = p1 == 0 ? tile : p1;
 

	
 
	/* Count of the number of tiles removed */
 
	int quantity = 0;
 

	
 
	if (tile >= MapSize() || start >= MapSize()) return CMD_ERROR;
 

	
 
	/* make sure sx,sy are smaller than ex,ey */
 
	int ex = TileX(tile);
 
	int ey = TileY(tile);
 
	int sx = TileX(start);
 
@@ -1288,25 +1288,25 @@ CommandCost CmdRemoveFromRailroadStation
 
				DeleteStationIfEmpty(st);
 
			}
 
		}
 
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
 

	
 
	/* If we've not removed any tiles, give an error */
 
	if (quantity == 0) return CMD_ERROR;
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_rail_station * quantity);
 
}
 

	
 

	
 
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
 
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, DoCommandFlag flags)
 
{
 
	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
 
	if (_current_company == OWNER_WATER && _settings_game.station.nonuniform_stations) {
 
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
 
	}
 

	
 
	/* Current company owns the station? */
 
	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
 

	
 
	/* determine width and height of platforms */
 
	tile = st->train_tile;
 
	int w = st->trainst_w;
 
@@ -1386,25 +1386,25 @@ static RoadStop **FindRoadStopSpot(bool 
 
}
 

	
 
/** Build a bus or truck stop
 
 * @param tile tile to build the stop at
 
 * @param flags operation to perform
 
 * @param p1 entrance direction (DiagDirection)
 
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
 
 *           bit 1: 0 for normal, 1 for drive-through
 
 *           bit 2..4: the roadtypes
 
 *           bit 5: allow stations directly adjacent to other stations.
 
 *           bit 16..31: station ID to join (INVALID_STATION if build new one)
 
 */
 
CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool type = HasBit(p2, 0);
 
	bool is_drive_through = HasBit(p2, 1);
 
	bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
 
	bool town_owned_road  = false;
 
	RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
 

	
 
	if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
 
@@ -1535,25 +1535,25 @@ static Vehicle *ClearRoadStopStatusEnum(
 
	if (v->type == VEH_ROAD) ClrBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
 

	
 
	return NULL;
 
}
 

	
 

	
 
/** Remove a bus station
 
 * @param st Station to remove
 
 * @param flags operation to perform
 
 * @param tile TileIndex been queried
 
 * @return cost or failure of operation
 
 */
 
static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
 
static CommandCost RemoveRoadStop(Station *st, DoCommandFlag flags, TileIndex tile)
 
{
 
	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	bool is_truck = IsTruckStop(tile);
 

	
 
	RoadStop **primary_stop;
 
	RoadStop *cur_stop;
 
	if (is_truck) { // truck stop
 
		primary_stop = &st->truck_stops;
 
		cur_stop = GetRoadStopByTile(tile, ROADSTOP_TRUCK);
 
@@ -1608,25 +1608,25 @@ static CommandCost RemoveRoadStop(Statio
 
		DeleteStationIfEmpty(st);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, (is_truck) ? _price.remove_truck_station : _price.remove_bus_station);
 
}
 

	
 
/** Remove a bus or truck stop
 
 * @param tile tile to remove the stop from
 
 * @param flags operation to perform
 
 * @param p1 not used
 
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
 
 */
 
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Make sure the specified tile is a road stop of the correct type */
 
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != GB(p2, 0, 1)) return CMD_ERROR;
 
	Station *st = GetStationByTile(tile);
 
	/* Save the stop info before it is removed */
 
	bool is_drive_through = IsDriveThroughStopTile(tile);
 
	RoadTypes rts = GetRoadTypes(tile);
 
	RoadBits road_bits = IsDriveThroughStopTile(tile) ?
 
			((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) :
 
			DiagDirToRoadBits(GetRoadStopDir(tile));
 
	bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile);
 

	
 
@@ -1838,25 +1838,25 @@ void UpdateAirportsNoise()
 
	}
 
}
 

	
 

	
 
/** Place an Airport.
 
 * @param tile tile where airport will be built
 
 * @param flags operation to perform
 
 * @param p1 airport type, @see airport.h
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit     0) - allow airports directly adjacent to other airports.
 
 * - p2 = (bit 16-31) - station ID to join (INVALID_STATION if build new one)
 
 */
 
CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	bool airport_upgrade = true;
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
 

	
 
	/* Check if a valid, buildable airport was chosen for construction */
 
	if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
 

	
 
	if (!CheckIfAuthorityAllowsNewStation(tile, flags)) {
 
		return CMD_ERROR;
 
@@ -1982,25 +1982,25 @@ CommandCost CmdBuildAirport(TileIndex ti
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
 
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
 

	
 
		if (_settings_game.economy.station_noise_level) {
 
			InvalidateWindow(WC_TOWN_VIEW, st->town->index);
 
		}
 
	}
 

	
 
	return cost;
 
}
 

	
 
static CommandCost RemoveAirport(Station *st, uint32 flags)
 
static CommandCost RemoveAirport(Station *st, DoCommandFlag flags)
 
{
 
	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	TileIndex tile = st->airport_tile;
 

	
 
	const AirportFTAClass *afc = st->Airport();
 
	int w = afc->size_x;
 
	int h = afc->size_y;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport);
 
@@ -2049,25 +2049,25 @@ static CommandCost RemoveAirport(Station
 
		DeleteStationIfEmpty(st);
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** Build a buoy.
 
 * @param tile tile where to place the bouy
 
 * @param flags operation to perform
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 

	
 
	/* allocate and initialize new station */
 
	if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
 

	
 
	if (flags & DC_EXEC) {
 
		Station *st = new Station(tile);
 

	
 
@@ -2111,25 +2111,25 @@ bool HasStationInUse(StationID station, 
 
		if (company == INVALID_COMPANY || v->owner == company) {
 
			const Order *order;
 
			FOR_VEHICLE_ORDERS(v, order) {
 
				if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == station) {
 
					return true;
 
				}
 
			}
 
		}
 
	}
 
	return false;
 
}
 

	
 
static CommandCost RemoveBuoy(Station *st, uint32 flags)
 
static CommandCost RemoveBuoy(Station *st, DoCommandFlag flags)
 
{
 
	/* XXX: strange stuff */
 
	if (!IsValidCompanyID(_current_company)) return_cmd_error(INVALID_STRING_ID);
 

	
 
	TileIndex tile = st->dock_tile;
 

	
 
	if (HasStationInUse(st->index, INVALID_COMPANY)) return_cmd_error(STR_BUOY_IS_IN_USE);
 
	/* remove the buoy if there is a ship on tile when company goes bankrupt... */
 
	if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		st->dock_tile = INVALID_TILE;
 
@@ -2159,25 +2159,25 @@ static const TileIndexDiffC _dock_tileof
 
	{ 0,  0},
 
	{ 0, -1}
 
};
 
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 (INVALID_STATION if build new one)
 
 */
 
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
 

	
 
	DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	direction = ReverseDiagDir(direction);
 

	
 
	/* Docks cannot be placed on rapids */
 
	if (IsWaterTile(tile)) return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
@@ -2260,25 +2260,25 @@ CommandCost CmdBuildDock(TileIndex tile,
 
		MakeDock(tile, st->owner, st->index, direction, wc);
 

	
 
		UpdateStationVirtCoordDirty(st);
 
		UpdateStationAcceptance(st, false);
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
 
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
 
}
 

	
 
static CommandCost RemoveDock(Station *st, uint32 flags)
 
static CommandCost RemoveDock(Station *st, DoCommandFlag flags)
 
{
 
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 

	
 
	TileIndex tile1 = st->dock_tile;
 
	TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
 

	
 
	if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR;
 
	if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile1);
 
		MakeWaterKeepingClass(tile2, st->owner);
 
@@ -2908,25 +2908,25 @@ static bool IsUniqueStationName(const ch
 
		if (st->name != NULL && strcmp(st->name, name) == 0) return false;
 
	}
 

	
 
	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
 
 */
 
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidStationID(p1)) return CMD_ERROR;
 

	
 
	Station *st = GetStation(p1);
 
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueStationName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 
@@ -3165,33 +3165,33 @@ static void ChangeTileOwner_Station(Tile
 
		}
 
	}
 
}
 

	
 
/**
 
 * Check if a drive-through road stop tile can be cleared.
 
 * Road stops built on town-owned roads check the conditions
 
 * that would allow clearing of the original road.
 
 * @param tile road stop tile to check
 
 * @param flags command flags
 
 * @return true if the road can be cleared
 
 */
 
static bool CanRemoveRoadWithStop(TileIndex tile, uint32 flags)
 
static bool CanRemoveRoadWithStop(TileIndex tile, DoCommandFlag flags)
 
{
 
	/* The road can always be cleared if it was not a town-owned road */
 
	if (!GetStopBuiltOnTownRoad(tile)) return true;
 

	
 
	return CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags);
 
}
 

	
 
static CommandCost ClearTile_Station(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (flags & DC_AUTO) {
 
		switch (GetStationType(tile)) {
 
			case STATION_RAIL:    return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD);
 
			case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST);
 
			case STATION_TRUCK:   return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_CARGO_TRAM_STATION : STR_3047_MUST_DEMOLISH_TRUCK_STATION);
 
			case STATION_BUS:     return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_PASSENGER_TRAM_STATION : STR_3046_MUST_DEMOLISH_BUS_STATION);
 
			case STATION_BUOY:    return_cmd_error(STR_306A_BUOY_IN_THE_WAY);
 
			case STATION_DOCK:    return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST);
 
			case STATION_OILRIG:
 
				SetDParam(0, STR_4807_OIL_RIG);
 
				return_cmd_error(STR_4800_IN_THE_WAY);
 
@@ -3223,25 +3223,25 @@ void InitializeStations()
 
{
 
	/* Clean the station pool and create 1 block in it */
 
	_Station_pool.CleanPool();
 
	_Station_pool.AddBlockToPool();
 

	
 
	/* Clean the roadstop pool and create 1 block in it */
 
	_RoadStop_pool.CleanPool();
 
	_RoadStop_pool.AddBlockToPool();
 

	
 
	_station_tick_ctr = 0;
 
}
 

	
 
static CommandCost TerraformTile_Station(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
 
		/* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here.
 
		 *       TTDP does not call it.
 
		 */
 
		if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
 
			switch (GetStationType(tile)) {
 
				case STATION_RAIL: {
 
					DiagDirection direction = AxisToDiagDir(GetRailStationAxis(tile));
 
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
 
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
 
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
src/terraform_cmd.cpp
Show inline comments
 
@@ -219,25 +219,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)
 
 * @return error or cost of terraforming
 
 */
 
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	_terraform_err_tile = INVALID_TILE;
 

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

	
 
	ts.modheight_count = ts.tile_table_count = 0;
 

	
 
	/* 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);
 
@@ -345,25 +345,25 @@ CommandCost CmdTerraformLand(TileIndex t
 
	}
 
	return total_cost;
 
}
 

	
 

	
 
/** 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 height difference; eg raise (+1), lower (-1) or level (0)
 
 * @return  error or cost of terraforming
 
 */
 
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *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 + p2;
 

	
 
	/* Check range of destination height */
src/tile_cmd.h
Show inline comments
 
@@ -57,25 +57,25 @@ struct TileDesc {
 
	StringID station_class; ///< Class of station
 
	StringID station_name;  ///< Type of station within the class
 
	const char *grf;        ///< newGRF used for the tile contents
 
	uint64 dparam[2];       ///< Parameters of the \a str string
 
};
 

	
 
/**
 
 * Tile callback function signature for drawing a tile and its contents to the screen
 
 * @param ti Information about the tile to draw
 
 */
 
typedef void DrawTileProc(TileInfo *ti);
 
typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y);
 
typedef CommandCost ClearTileProc(TileIndex tile, byte flags);
 
typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
 

	
 
/**
 
 * Tile callback function signature for obtaining accepted carog of a tile
 
 * @param tile Tile queried for its accepted cargo
 
 * @param res  Storage destination of the cargo accepted
 
 */
 
typedef void GetAcceptedCargoProc(TileIndex tile, AcceptedCargo res);
 

	
 
/**
 
 * Tile callback function signature for obtaining a tile description
 
 * @param tile Tile being queried
 
 * @param td   Storage pointer for returned tile description
 
@@ -118,25 +118,25 @@ typedef Foundation GetFoundationProc(Til
 
 * The function is called when a tile is affected by a terraforming operation.
 
 * It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype.
 
 * With DC_EXEC in \a flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).
 
 *
 
 * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
 
 *
 
 * @param tile      The involved tile.
 
 * @param flags     Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.).
 
 * @param z_new     TileZ after terraforming.
 
 * @param tileh_new Slope after terraforming.
 
 * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
 
 */
 
typedef CommandCost TerraformTileProc(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new);
 
typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new);
 

	
 
/**
 
 * Set of callback functions for performing tile operations of a given tile type.
 
 * @see TileType */
 
struct TileTypeProcs {
 
	DrawTileProc *draw_tile_proc;                  ///< Called to render the tile and its contents to the screen
 
	GetSlopeZProc *get_slope_z_proc;
 
	ClearTileProc *clear_tile_proc;
 
	GetAcceptedCargoProc *get_accepted_cargo_proc; ///< Return accepted cargo of the tile
 
	GetTileDescProc *get_tile_desc_proc;           ///< Get a description of a tile (for the 'land area information' tool)
 
	GetTileTrackStatusProc *get_tile_track_status_proc; ///< Get available tracks and status of a tile
 
	ClickTileProc *click_tile_proc;                ///< Called when tile is clicked
src/timetable_cmd.cpp
Show inline comments
 
@@ -43,25 +43,25 @@ static void ChangeTimetable(Vehicle *v, 
 
 * @param flags Operation to perform.
 
 * @param p1 Various bitstuffed elements
 
 * - p1 = (bit  0-15) - Vehicle with the orders to change.
 
 * - p1 = (bit 16-23) - Order index to modify.
 
 * - p1 = (bit    24) - Whether to change the waiting time or the travelling
 
 *                      time.
 
 * - p1 = (bit    25) - Whether p2 contains waiting and travelling time.
 
 * @param p2 The amount of time to wait.
 
 * - p2 = (bit  0-15) - Waiting or travelling time as specified by p1 bit 24 if p1 bit 25 is not set,
 
 *                      Travelling time if p1 bit 25 is set.
 
 * - p2 = (bit 16-31) - Waiting time if p1 bit 25 is set
 
 */
 
CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(veh);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	VehicleOrderID order_number = GB(p1, 16, 8);
 
	Order *order = GetVehicleOrder(v, order_number);
 
	if (order == NULL) return CMD_ERROR;
 
@@ -101,25 +101,25 @@ CommandCost CmdChangeTimetable(TileIndex
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * 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-15) - Vehicle with the orders to change.
 
 */
 
CommandCost CmdSetVehicleOnTime(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(veh);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		v->lateness_counter = 0;
 
	}
 
@@ -129,25 +129,25 @@ CommandCost CmdSetVehicleOnTime(TileInde
 

	
 
/**
 
 * 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
 
 */
 
CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 
	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(veh);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (HasBit(p2, 0)) {
 
			/* Start autofilling the timetable, which clears the
src/town.h
Show inline comments
 
@@ -9,24 +9,25 @@
 
#include "core/bitmath_func.hpp"
 
#include "core/random_func.hpp"
 
#include "cargo_type.h"
 
#include "tile_type.h"
 
#include "date_type.h"
 
#include "town_type.h"
 
#include "company_type.h"
 
#include "settings_type.h"
 
#include "strings_type.h"
 
#include "viewport_type.h"
 
#include "economy_type.h"
 
#include "map_type.h"
 
#include "command_type.h"
 

	
 
enum {
 
	HOUSE_NO_CLASS   = 0,
 
	NEW_HOUSE_OFFSET = 110,
 
	HOUSE_MAX        = 512,
 
	INVALID_TOWN     = 0xFFFF,
 
	INVALID_HOUSE_ID = 0xFFFF,
 

	
 
	/* There can only be as many classes as there are new houses, plus one for
 
	 * NO_CLASS, as the original houses don't have classes. */
 
	HOUSE_CLASS_MAX  = HOUSE_MAX - NEW_HOUSE_OFFSET + 1,
 
};
 
@@ -271,25 +272,25 @@ static const byte TOWN_HOUSE_COMPLETED =
 
/** This enum is used in conjonction with town->flags12.
 
 * IT simply states what bit is used for.
 
 * It is pretty unrealistic (IMHO) to only have one church/stadium
 
 * per town, NO MATTER the population of it.
 
 * And there are 5 more bits available on flags12...
 
 */
 
enum {
 
	TOWN_IS_FUNDED      = 0,   ///< Town has received some funds for
 
	TOWN_HAS_CHURCH     = 1,   ///< There can be only one church by town.
 
	TOWN_HAS_STADIUM    = 2    ///< There can be only one stadium by town.
 
};
 

	
 
bool CheckforTownRating(uint32 flags, Town *t, byte type);
 
bool CheckforTownRating(DoCommandFlag flags, Town *t, byte type);
 

	
 
static inline HouseSpec *GetHouseSpecs(HouseID house_id)
 
{
 
	assert(house_id < HOUSE_MAX);
 
	return &_house_specs[house_id];
 
}
 

	
 
TileIndexDiff GetHouseNorthPart(HouseID &house);
 

	
 
/**
 
 * Check if a TownID is valid.
 
 * @param index to inquiry in the pool of town
 
@@ -343,25 +344,25 @@ Town *CalcClosestTownFromTile(TileIndex 
 

	
 
#define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) if (t->IsValid())
 
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
 

	
 
extern Town *_cleared_town;
 
extern int _cleared_town_rating;
 

	
 
void ResetHouses();
 

	
 
void ClearTownHouse(Town *t, TileIndex tile);
 
void UpdateTownMaxPass(Town *t);
 
void UpdateTownRadius(Town *t);
 
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, uint32 flags);
 
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
 
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
 
void ChangeTownRating(Town *t, int add, int max);
 
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
 
void SetTownRatingTestMode(bool mode);
 
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
 
bool GenerateTowns(TownLayout layout);
 

	
 
/**
 
 * Calculate a hash value from a tile position
 
 *
 
 * @param x The X coordinate
 
 * @param y The Y coordinate
src/town_cmd.cpp
Show inline comments
 
@@ -507,25 +507,25 @@ static void TileLoop_Town(TileIndex tile
 
}
 

	
 
/**
 
 * Dummy tile callback function for handling tile clicks in towns
 
 * @param tile unused
 
 */
 
static bool ClickTile_Town(TileIndex tile)
 
{
 
	/* not used */
 
	return false;
 
}
 

	
 
static CommandCost ClearTile_Town(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 
	if (!CanDeleteHouse(tile)) return CMD_ERROR;
 

	
 
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	cost.AddCost(hs->GetRemovalCost());
 

	
 
	int rating = hs->remove_rating_decrease;
 
	_cleared_town_rating += rating;
 
	Town *t = _cleared_town = GetTownByTile(tile);
 
@@ -1501,25 +1501,25 @@ static void DoCreateTown(Town *t, TileIn
 
}
 

	
 
/** Create a new town.
 
 * This obviously only works in the scenario editor. Function not removed
 
 * as it might be possible in the future to fund your own 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)
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Only in the scenario editor */
 
	if (_game_mode != GM_EDITOR) return CMD_ERROR;
 

	
 
	TownSize size = (TownSize)GB(p1, 0, 2);
 
	bool city = HasBit(p1, 2);
 
	TownLayout layout = (TownLayout)GB(p1, 3, 3);
 

	
 
	if (size > TS_RANDOM) return CMD_ERROR;
 
	if (layout > TL_RANDOM) return CMD_ERROR;
 

	
 
	/* Check if too close to the edge of map */
 
@@ -2089,25 +2089,25 @@ static bool IsUniqueTownName(const char 
 
		if (t->name != NULL && strcmp(t->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Rename a town (server-only).
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 town ID to rename
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidTownID(p1)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueTownName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Town *t = GetTown(p1);
 
@@ -2359,25 +2359,25 @@ uint GetMaskOfTownActions(int *nump, Com
 
	if (nump != NULL) *nump = num;
 
	return buttons;
 
}
 

	
 
/** 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
 
 */
 
CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
 

	
 
	Town *t = GetTown(p1);
 

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

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

	
 
	if (flags & DC_EXEC) {
 
		_town_action_proc[p2](t);
 
		InvalidateWindow(WC_TOWN_AUTHORITY, p1);
 
@@ -2488,25 +2488,25 @@ static void UpdateTownUnwanted(Town *t)
 
	const Company *c;
 

	
 
	FOR_ALL_COMPANIES(c) {
 
		if (t->unwanted[c->index] > 0) t->unwanted[c->index]--;
 
	}
 
}
 

	
 
/**
 
 * Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile
 
 * @param tile The tile where the station shall be constructed.
 
 * @param flags Command flags. DC_NO_TOWN_RATING is tested.
 
 */
 
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, uint32 flags)
 
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!IsValidCompanyID(_current_company) || (flags & DC_NO_TOWN_RATING)) return true;
 

	
 
	Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
 
	if (t == NULL) return true;
 

	
 
	if (t->ratings[_current_company] > RATING_VERYPOOR) return true;
 

	
 
	_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
 
	SetDParam(0, t->index);
 

	
 
	return false;
 
@@ -2621,25 +2621,25 @@ void ChangeTownRating(Town *t, int add, 
 
		InvalidateWindow(WC_TOWN_AUTHORITY, t->index);
 
	}
 
}
 

	
 
/* penalty for removing town-owned stuff */
 
static const int _default_rating_settings [3][3] = {
 
	/* ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE */
 
	{  0, 128, 384}, // Permissive
 
	{ 48, 192, 480}, // Neutral
 
	{ 96, 384, 768}, // Hostile
 
};
 

	
 
bool CheckforTownRating(uint32 flags, Town *t, byte type)
 
bool CheckforTownRating(DoCommandFlag flags, Town *t, byte type)
 
{
 
	/* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */
 
	if (t == NULL || !IsValidCompanyID(_current_company) || _cheats.magic_bulldozer.value)
 
		return true;
 

	
 
	/* check if you're allowed to remove the street/bridge/tunnel/industry
 
	 * owned by a town no removal if rating is lower than ... depends now on
 
	 * difficulty setting. Minimum town rating selected by difficulty level
 
	 */
 
	int modemod = _default_rating_settings[_settings_game.difficulty.town_council_tolerance][type];
 

	
 
	if (GetRating(t) < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) {
 
@@ -2683,25 +2683,25 @@ void InitializeTowns()
 
	_Town_pool.AddBlockToPool();
 

	
 
	memset(_subsidies, 0, sizeof(_subsidies));
 
	for (Subsidy *s = _subsidies; s != endof(_subsidies); s++) {
 
		s->cargo_type = CT_INVALID;
 
	}
 

	
 
	_cur_town_ctr = 0;
 
	_cur_town_iter = 0;
 
	_total_towns = 0;
 
}
 

	
 
static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	if (AutoslopeEnabled()) {
 
		HouseID house = GetHouseType(tile);
 
		GetHouseNorthPart(house); // modifies house to the ID of the north tile
 
		const HouseSpec *hs = GetHouseSpecs(house);
 

	
 
		/* Here we differ from TTDP by checking TILE_NOT_SLOPED */
 
		if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
 
			(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
src/train_cmd.cpp
Show inline comments
 
@@ -570,25 +570,25 @@ void DrawTrainEngine(int x, int y, Engin
 
		int yr = y;
 

	
 
		SpriteID spritef = GetRailIcon(engine, false, yf);
 
		SpriteID spriter = GetRailIcon(engine, true, yr);
 
		DrawSprite(spritef, pal, x - 14, yf);
 
		DrawSprite(spriter, pal, x + 15, yr);
 
	} else {
 
		SpriteID sprite = GetRailIcon(engine, false, y);
 
		DrawSprite(sprite, pal, x, y);
 
	}
 
}
 

	
 
static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
 
static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandFlag flags)
 
{
 
	const RailVehicleInfo *rvi = RailVehInfo(engine);
 
	CommandCost value(EXPENSES_NEW_VEHICLES, GetEngine(engine)->GetCost());
 

	
 
	if (flags & DC_QUERY_COST) return value;
 

	
 
	/* Check that the wagon can drive on the track in question */
 
	if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
 

	
 
	uint num_vehicles = 1 + CountArticulatedParts(engine, false);
 

	
 
	/* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
 
@@ -716,25 +716,25 @@ static void AddRearEngineToMultiheadedTr
 
	u->value = v->value;
 
	u->cur_image = 0xAC2;
 
	u->random_bits = VehicleRandomBits();
 
	VehiclePositionChanged(u);
 
}
 

	
 
/** Build a railroad vehicle.
 
 * @param tile tile of the depot where rail-vehicle is built
 
 * @param flags type of operation
 
 * @param p1 engine type id
 
 * @param p2 bit 1 prevents any free cars from being added to the train
 
 */
 
CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check if the engine-type is valid (for the company) */
 
	if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
 

	
 
	const Engine *e = GetEngine(p1);
 
	CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
 

	
 
	if (flags & DC_QUERY_COST) return value;
 

	
 
	/* Check if the train is actually being built in a depot belonging
 
	 * to the company. Doesn't matter if only the cost is queried */
 
	if (!IsRailDepotTile(tile)) return CMD_ERROR;
 
@@ -979,25 +979,25 @@ static void NormaliseTrainConsist(Vehicl
 
	}
 
}
 

	
 
/** 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 - 15) source vehicle index
 
 * - p1 (bit 16 - 31) what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
 
 * @param p2 (bit 0) move all vehicles following the source vehicle
 
 */
 
CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleID s = GB(p1, 0, 16);
 
	VehicleID d = GB(p1, 16, 16);
 

	
 
	if (!IsValidVehicleID(s)) return CMD_ERROR;
 

	
 
	Vehicle *src = GetVehicle(s);
 

	
 
	if (src->type != VEH_TRAIN || !CheckOwnership(src->owner)) return CMD_ERROR;
 

	
 
	/* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */
 
	if (HASBITS(src->vehstatus, VS_CRASHED)) return CMD_ERROR;
 
@@ -1334,25 +1334,25 @@ CommandCost CmdMoveRailVehicle(TileIndex
 
	return CommandCost();
 
}
 

	
 
/** Sell a (single) train wagon/engine.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 the wagon/engine index
 
 * @param p2 the selling mode
 
 * - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
 
 * - p2 = 1: sell the vehicle and all vehicles following it in the chain
 
 *           if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
 
 */
 
CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check if we deleted a vehicle window */
 
	Window *w = NULL;
 

	
 
	if (!IsValidVehicleID(p1) || p2 > 1) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
@@ -1896,25 +1896,25 @@ static void ReverseTrainDirection(Vehicl
 
		/* A train not inside a PBS block can't be stuck. */
 
		ClrBit(v->u.rail.flags, VRF_TRAIN_STUCK);
 
		v->load_unload_time_rem = 0;
 
	}
 
}
 

	
 
/** 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)
 
 */
 
CommandCost CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 

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

	
 
		if (IsMultiheaded(v) || HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) {
 
			return_cmd_error(STR_ONLY_TURN_SINGLE_UNIT);
 
@@ -1946,48 +1946,48 @@ 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
 
 */
 
CommandCost CmdForceTrainProceed(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) v->u.rail.force_proceed = 0x50;
 

	
 
	return CommandCost();
 
}
 

	
 
/** Refits a train to the specified cargo type.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID of the train to refit
 
 * param p2 various bitstuffed elements
 
 * - p2 = (bit 0-7) - the new cargo type to refit to
 
 * - p2 = (bit 8-15) - the new cargo subtype to refit to
 
 * - p2 = (bit 16) - refit only this vehicle
 
 * @return cost of refit or error
 
 */
 
CommandCost CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRefitRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	bool only_this = HasBit(p2, 16);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
 
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE);
 
@@ -2173,25 +2173,25 @@ bool Train::FindClosestDepot(TileIndex *
 

	
 
	return true;
 
}
 

	
 
/** Send a train to a depot
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 train to send to the depot
 
 * @param p2 various bitmasked elements
 
 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h)
 
 * - p2 bit 8-10 - VLW flag (for mass goto depot)
 
 */
 
CommandCost CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSendTrainToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p2 & DEPOT_MASS_SEND) {
 
		/* Mass goto depot requested */
 
		if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
 
		return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
 
	}
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN) return CMD_ERROR;
src/tree_cmd.cpp
Show inline comments
 
@@ -311,25 +311,25 @@ void GenerateTrees()
 

	
 
	for (; i != 0; i--) {
 
		PlaceTreesRandomly();
 
	}
 
}
 

	
 
/** Plant a tree.
 
 * @param tile start tile of area-drag of tree plantation
 
 * @param flags type of operation
 
 * @param p1 tree type, -1 means random.
 
 * @param p2 end tile of area-drag
 
 */
 
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	StringID msg = INVALID_STRING_ID;
 
	CommandCost cost(EXPENSES_OTHER);
 
	int ex;
 
	int ey;
 
	int sx, sy, x, y;
 

	
 
	if (p2 >= MapSize()) return CMD_ERROR;
 
	/* Check the tree type. It can be random or some valid value within the current climate */
 
	if (p1 != UINT_MAX && p1 - _tree_base_by_landscape[_settings_game.game_creation.landscape] >= _tree_count_by_landscape[_settings_game.game_creation.landscape]) return CMD_ERROR;
 

	
 
	// make sure sx,sy are smaller than ex,ey
 
@@ -517,25 +517,25 @@ static uint GetSlopeZ_Trees(TileIndex ti
 
{
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
 

	
 
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
 
}
 

	
 
static Foundation GetFoundation_Trees(TileIndex tile, Slope tileh)
 
{
 
	return FOUNDATION_NONE;
 
}
 

	
 
static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlag flags)
 
{
 
	uint num;
 

	
 
	if (IsValidCompanyID(_current_company)) {
 
		Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
 
		if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
 
	}
 

	
 
	num = GetTreeCount(tile);
 
	if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
 

	
 
	if (flags & DC_EXEC) DoClearSquare(tile);
 
@@ -753,25 +753,25 @@ static TrackStatus GetTileTrackStatus_Tr
 
}
 

	
 
static void ChangeTileOwner_Trees(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	/* not used */
 
}
 

	
 
void InitializeTrees()
 
{
 
	_trees_tick_ctr = 0;
 
}
 

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

	
 

	
 
extern const TileTypeProcs _tile_type_trees_procs = {
 
	DrawTile_Trees,           /* draw_tile_proc */
 
	GetSlopeZ_Trees,          /* get_slope_z_proc */
 
	ClearTile_Trees,          /* clear_tile_proc */
 
	GetAcceptedCargo_Trees,   /* get_accepted_cargo_proc */
 
	GetTileDesc_Trees,        /* get_tile_desc_proc */
 
	GetTileTrackStatus_Trees, /* get_tile_track_status_proc */
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -141,25 +141,25 @@ static CommandCost CheckBridgeSlopeSouth
 
{
 
	Foundation f = GetBridgeFoundation(*tileh, axis);
 
	*z += ApplyFoundationToSlope(f, tileh);
 

	
 
	Slope valid_inclined = (axis == AXIS_X ? SLOPE_SW : SLOPE_SE);
 
	if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR;
 

	
 
	if (f == FOUNDATION_NONE) return CommandCost();
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
}
 

	
 
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len, uint32 flags)
 
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags)
 
{
 
	if (flags & DC_QUERY_COST) {
 
		return bridge_len <= (_settings_game.construction.longbridges ? 100U : 16U);
 
	}
 

	
 
	if (bridge_type >= MAX_BRIDGES) return false;
 

	
 
	const BridgeSpec *b = GetBridgeSpec(bridge_type);
 
	if (b->avail_year > _cur_year) return false;
 

	
 
	uint max = b->max_length;
 
	if (max >= 16 && _settings_game.construction.longbridges) max = 100;
 
@@ -167,25 +167,25 @@ bool CheckBridge_Stuff(BridgeType bridge
 
	return b->min_length <= bridge_len && bridge_len <= max;
 
}
 

	
 
/** 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-14) - rail type or road types.
 
 * - p2 = (bit 15-16) - transport type.
 
 */
 
CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	BridgeType bridge_type;
 
	RailType railtype = INVALID_RAILTYPE;
 
	RoadTypes roadtypes = ROADTYPES_NONE;
 
	uint x;
 
	uint y;
 
	uint sx;
 
	uint sy;
 
	TileIndex tile_start;
 
	TileIndex tile_end;
 
	Slope tileh_start;
 
	Slope tileh_end;
 
@@ -454,25 +454,25 @@ not_valid_below:;
 
	}
 

	
 
	return cost;
 
}
 

	
 

	
 
/** Build Tunnel.
 
 * @param start_tile start tile of tunnel
 
 * @param flags type of operation
 
 * @param p1 railtype or roadtypes. bit 9 set means road tunnel
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TileIndexDiff delta;
 
	TileIndex end_tile;
 
	DiagDirection direction;
 
	Slope start_tileh;
 
	Slope end_tileh;
 
	TransportType transport_type = (TransportType)GB(p1, 9, 1);
 
	uint start_z;
 
	uint end_z;
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost ret;
 

	
 
@@ -581,25 +581,25 @@ CommandCost CmdBuildTunnel(TileIndex sta
 

	
 
static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile)
 
{
 
	/* Floods can remove anything as well as the scenario editor */
 
	if (_current_company == OWNER_WATER || _game_mode == GM_EDITOR) return true;
 
	/* Obviously if the bridge/tunnel belongs to us, or no-one, we can remove it */
 
	if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true;
 
	/* Otherwise we can only remove town-owned stuff with extra settings, or cheat */
 
	if (IsTileOwner(tile, OWNER_TOWN) && (_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
 
	return false;
 
}
 

	
 
static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
 
static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
 
{
 
	Town *t = NULL;
 
	TileIndex endtile;
 

	
 
	if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
 

	
 
	endtile = GetOtherTunnelEnd(tile);
 

	
 
	if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR;
 

	
 
	_build_tunnel_endtile = endtile;
 

	
 
@@ -644,25 +644,25 @@ static CommandCost DoClearTunnel(TileInd
 
			YapfNotifyTrackLayoutChange(endtile, track);
 

	
 
			if (v != NULL) TryPathReserve(v);
 
		} else {
 
			DoClearSquare(tile);
 
			DoClearSquare(endtile);
 
		}
 
	}
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (GetTunnelBridgeLength(tile, endtile) + 2));
 
}
 

	
 

	
 
static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
 
static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
 
{
 
	DiagDirection direction;
 
	TileIndexDiff delta;
 
	TileIndex endtile;
 
	Town *t = NULL;
 

	
 
	if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
 

	
 
	endtile = GetOtherBridgeEnd(tile);
 

	
 
	if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR;
 

	
 
@@ -717,25 +717,25 @@ static CommandCost DoClearBridge(TileInd
 

	
 
			Track track = DiagDirToDiagTrack(direction);
 
			YapfNotifyTrackLayoutChange(tile,    track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 

	
 
			if (v != NULL) TryPathReserve(v, true);
 
		}
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, (GetTunnelBridgeLength(tile, endtile) + 2) * _price.clear_bridge);
 
}
 

	
 
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
 
static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (IsTunnel(tile)) {
 
		if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
 
		return DoClearTunnel(tile, flags);
 
	} else { // IsBridge(tile)
 
		if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 
		return DoClearBridge(tile, flags);
 
	}
 

	
 
	return CMD_ERROR;
 
}
 

	
 
@@ -1453,25 +1453,25 @@ static VehicleEnterTileStatus VehicleEnt
 
						v->u.ship.state = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
 
						return VETSB_ENTERED_WORMHOLE;
 
					}
 
					break;
 

	
 
				default: NOT_REACHED();
 
			}
 
		}
 
	}
 
	return VETSB_CONTINUE;
 
}
 

	
 
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && IsBridge(tile) && GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) {
 
		DiagDirection direction = GetTunnelBridgeDirection(tile);
 
		Axis axis = DiagDirToAxis(direction);
 
		CommandCost res;
 
		uint z_old;
 
		Slope tileh_old = GetTileSlope(tile, &z_old);
 

	
 
		/* Check if new slope is valid for bridges in general (so we can safely call GetBridgeFoundation()) */
 
		if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) {
 
			CheckBridgeSlopeSouth(axis, &tileh_old, &z_old);
 
			res = CheckBridgeSlopeSouth(axis, &tileh_new, &z_new);
src/unmovable_cmd.cpp
Show inline comments
 
@@ -40,25 +40,25 @@ static inline const UnmovableSpec *GetUn
 
{
 
	assert(type < UNMOVABLE_MAX);
 
	return &_original_unmovable[type];
 
}
 

	
 
/** Destroy a HQ.
 
 * During normal gameplay you can only implicitely destroy a HQ when you are
 
 * rebuilding it. Otherwise, only water can destroy it.
 
 * @param cid Company requesting the destruction of his HQ
 
 * @param flags docommand flags of calling function
 
 * @return cost of the operation
 
 */
 
static CommandCost DestroyCompanyHQ(CompanyID cid, uint32 flags)
 
static CommandCost DestroyCompanyHQ(CompanyID cid, DoCommandFlag flags)
 
{
 
	Company *c = GetCompany(cid);
 

	
 
	if (flags & DC_EXEC) {
 
		TileIndex t = c->location_of_HQ;
 

	
 
		DoClearSquare(t);
 
		DoClearSquare(t + TileDiffXY(0, 1));
 
		DoClearSquare(t + TileDiffXY(1, 0));
 
		DoClearSquare(t + TileDiffXY(1, 1));
 
		c->location_of_HQ = INVALID_TILE; // reset HQ position
 
		InvalidateWindow(WC_COMPANY, cid);
 
@@ -80,33 +80,33 @@ void UpdateCompanyHQ(Company *c, uint sc
 
	(val++, score < 520) ||
 
	(val++, score < 720) ||
 
	(val++, true);
 

	
 
	EnlargeCompanyHQ(tile, val);
 

	
 
	MarkTileDirtyByTile(tile);
 
	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
 
	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
 
	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
 
}
 

	
 
extern CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID *station, bool check_clear = true);
 
extern CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, DoCommandFlag flags, uint invalid_dirs, StationID *station, bool check_clear = true);
 

	
 
/** Build or relocate the HQ. This depends if the HQ is already built or not
 
 * @param tile tile where the HQ will be built or relocated to
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = GetCompany(_current_company);
 
	CommandCost cost(EXPENSES_PROPERTY);
 

	
 
	cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
 
	if (CmdFailed(cost)) return cost;
 

	
 
	if (c->location_of_HQ != INVALID_TILE) { // Moving HQ
 
		cost.AddCost(DestroyCompanyHQ(_current_company, flags));
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
@@ -122,25 +122,25 @@ CommandCost CmdBuildCompanyHQ(TileIndex 
 

	
 
	return cost;
 
}
 

	
 
/** Purchase a land area. Actually you only purchase one tile, so
 
 * the name is a bit confusing ;p
 
 * @param tile the tile the company is purchasing
 
 * @param flags for this command type
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return error of cost of operation
 
 */
 
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_company)) {
 
		return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
 
	}
 

	
 
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(cost)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		MakeOwnedLand(tile, _current_company);
 
@@ -149,25 +149,25 @@ CommandCost CmdPurchaseLandArea(TileInde
 

	
 
	return cost.AddCost(GetUnmovableSpec(UNMOVABLE_OWNED_LAND)->GetBuildingCost());
 
}
 

	
 
/** Sell a land area. Actually you only sell one tile, so
 
 * the name is a bit confusing ;p
 
 * @param tile the tile the company is selling
 
 * @param flags for this command type
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return error or cost of operation
 
 */
 
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdSellLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) DoClearSquare(tile);
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, - GetUnmovableSpec(UNMOVABLE_OWNED_LAND)->GetRemovalCost());
 
}
 

	
 
static Foundation GetFoundation_Unmovable(TileIndex tile, Slope tileh);
 
@@ -249,25 +249,25 @@ static uint GetSlopeZ_Unmovable(TileInde
 

	
 
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
 
	} else {
 
		return GetTileMaxZ(tile);
 
	}
 
}
 

	
 
static Foundation GetFoundation_Unmovable(TileIndex tile, Slope tileh)
 
{
 
	return IsOwnedLand(tile) ? FOUNDATION_NONE : FlatteningFoundation(tileh);
 
}
 

	
 
static CommandCost ClearTile_Unmovable(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Unmovable(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (IsCompanyHQ(tile)) {
 
		if (_current_company == OWNER_WATER) {
 
			return DestroyCompanyHQ(GetTileOwner(tile), DC_EXEC);
 
		} else {
 
			return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
 
		}
 
	}
 

	
 
	if (IsOwnedLand(tile)) {
 
		return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
 
	}
 
@@ -477,25 +477,25 @@ static void ChangeTileOwner_Unmovable(Ti
 
			SetBit(t->statues, new_owner);
 
			SetTileOwner(tile, new_owner);
 
		} else {
 
			DoClearSquare(tile);
 
		}
 

	
 
		InvalidateWindow(WC_TOWN_AUTHORITY, town);
 
	} else {
 
		DoClearSquare(tile);
 
	}
 
}
 

	
 
static CommandCost TerraformTile_Unmovable(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
 
static CommandCost TerraformTile_Unmovable(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	/* Owned land remains unsold */
 
	if (IsOwnedLand(tile) && CheckTileOwnership(tile)) return CommandCost();
 

	
 
	if (AutoslopeEnabled() && (IsStatue(tile) || IsCompanyHQ(tile))) {
 
		if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
	}
 

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

	
 
extern const TileTypeProcs _tile_type_unmovable_procs = {
src/vehicle.cpp
Show inline comments
 
@@ -957,25 +957,25 @@ void AgeVehicle(Vehicle *v)
 

	
 
	SetDParam(0, v->index);
 
	AddNewsItem(str, NS_ADVICE, v->index, 0);
 
}
 

	
 
/** Start/Stop a vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle to start/stop
 
 * @param p2 bit 0: Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety)
 
 * @return result of operation.  Nothing if everything went well
 
 */
 
CommandCost CmdStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */
 
	if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

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

	
 
	switch (v->type) {
 
@@ -1030,25 +1030,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 Station/Order/Depot ID (only used for vehicle list windows)
 
 * @param p2 bitmask
 
 *   - bit 0-4 Vehicle type
 
 *   - bit 5 false = start vehicles, true = stop vehicles
 
 *   - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case
 
 *   - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set)
 
 */
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 
	CommandCost return_value = CMD_ERROR;
 
	VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5);
 
	bool start_stop = HasBit(p2, 5);
 
	bool vehicle_list_window = HasBit(p2, 6);
 

	
 
	if (vehicle_list_window) {
 
		uint32 id = p1;
 
		uint16 window_type = p2 & VLW_MASK;
 

	
 
		GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type);
 
@@ -1080,25 +1080,25 @@ CommandCost CmdMassStartStopVehicle(Tile
 
		}
 
	}
 

	
 
	return return_value;
 
}
 

	
 
/** 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
 
 */
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 

	
 
	CommandCost cost(EXPENSES_NEW_VEHICLES);
 
	uint sell_command;
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 

	
 
	switch (vehicle_type) {
 
		case VEH_TRAIN:    sell_command = CMD_SELL_RAIL_WAGON; break;
 
		case VEH_ROAD:     sell_command = CMD_SELL_ROAD_VEH;   break;
 
		case VEH_SHIP:     sell_command = CMD_SELL_SHIP;       break;
 
		case VEH_AIRCRAFT: sell_command = CMD_SELL_AIRCRAFT;   break;
 
@@ -1117,25 +1117,25 @@ CommandCost CmdDepotSellAllVehicles(Tile
 
	return cost;
 
}
 

	
 
/** Autoreplace all vehicles in the depot
 
 * Note: this command can make incorrect cost estimations
 
 * Luckily the final price can only drop, not increase. This is due to the fact that
 
 * estimation can't predict wagon removal so it presumes worst case which is no income from selling wagons.
 
 * @param tile Tile of the depot where the vehicles are
 
 * @param flags type of operation
 
 * @param p1 Type of vehicle
 
 * @param p2 If bit 0 is set, then either replace all or nothing (instead of replacing until money runs out)
 
 */
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	VehicleList list;
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES);
 
	VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8);
 
	bool all_or_nothing = HasBit(p2, 0);
 

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

	
 
	bool did_something = false;
 
@@ -1169,25 +1169,25 @@ CommandCost CmdDepotMassAutoReplace(Tile
 
		cost = CMD_ERROR;
 
	}
 

	
 
	return cost;
 
}
 

	
 
/** 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
 
 */
 
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost total_cost(EXPENSES_NEW_VEHICLES);
 
	uint32 build_argument = 2;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 
	Vehicle *v_front = v;
 
	Vehicle *w = NULL;
 
	Vehicle *w_front = NULL;
 
	Vehicle *w_rear = NULL;
 

	
 
@@ -1337,25 +1337,25 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
	return total_cost;
 
}
 

	
 
/**
 
 * Send all vehicles of type to depots
 
 * @param type type of vehicle
 
 * @param flags the flags used for DoCommand()
 
 * @param service should the vehicles only get service in the depots
 
 * @param owner owner of the vehicles to send
 
 * @param vlw_flag tells what kind of list requested the goto depot
 
 * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
 
 */
 
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, Owner owner, uint16 vlw_flag, uint32 id)
 
CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id)
 
{
 
	VehicleList list;
 

	
 
	GenerateVehicleSortList(&list, type, owner, id, vlw_flag);
 

	
 
	/* Send all the vehicles to a depot */
 
	for (uint i = 0; i < list.Length(); i++) {
 
		const Vehicle *v = list[i];
 
		CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
 

	
 
		/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
 
			* In this case we know that at least one vehicle can be sent to a depot
 
@@ -1519,25 +1519,25 @@ static bool IsUniqueVehicleName(const ch
 
		if (v->name != NULL && strcmp(v->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Give a custom name to your vehicle
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 vehicle ID to name
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR;
 
		if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
 
@@ -1550,25 +1550,25 @@ CommandCost CmdRenameVehicle(TileIndex t
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 

	
 
/** 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 new service interval
 
 */
 
CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
 

	
 
	if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		v->service_interval = serv_int;
 
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
@@ -2042,25 +2042,25 @@ void Vehicle::HandleLoading(bool mode)
 
			break;
 
		}
 

	
 
		case OT_DUMMY: break;
 

	
 
		default: return;
 
	}
 

	
 
	this->cur_order_index++;
 
	InvalidateVehicleOrder(this, 0);
 
}
 

	
 
CommandCost Vehicle::SendToDepot(uint32 flags, DepotCommand command)
 
CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
 
{
 
	if (!CheckOwnership(this->owner)) return CMD_ERROR;
 
	if (this->vehstatus & VS_CRASHED) return CMD_ERROR;
 
	if (this->IsStoppedInDepot()) return CMD_ERROR;
 

	
 
	if (this->current_order.IsType(OT_GOTO_DEPOT)) {
 
		bool halt_in_depot = this->current_order.GetDepotActionType() & ODATFB_HALT;
 
		if (!!(command & DEPOT_SERVICE) == halt_in_depot) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot)          */
 
			if (flags & DC_EXEC) {
src/vehicle_base.h
Show inline comments
 
@@ -585,25 +585,25 @@ public:
 
	 * @param destination what hangar do we go to?
 
	 * @param reverse     should the vehicle be reversed?
 
	 * @return true if a depot could be found.
 
	 */
 
	virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) { return false; }
 

	
 
	/**
 
	 * Send this vehicle to the depot using the given command(s).
 
	 * @param flags   the command flags (like execute and such).
 
	 * @param command the command to execute.
 
	 * @return the cost of the depot action.
 
	 */
 
	CommandCost SendToDepot(uint32 flags, DepotCommand command);
 
	CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command);
 
};
 

	
 
/**
 
 * This class 'wraps' Vehicle; you do not actually instantiate this class.
 
 * You create a Vehicle using AllocateVehicle, so it is added to the pool
 
 * and you reinitialize that to a Train using:
 
 *   v = new (v) Train();
 
 *
 
 * As side-effect the vehicle type is set correctly.
 
 */
 
struct DisasterVehicle : public Vehicle {
 
	/** Initializes the Vehicle to a disaster vehicle */
src/vehicle_func.h
Show inline comments
 
@@ -56,25 +56,25 @@ void AgeVehicle(Vehicle *v);
 
void VehicleEnteredDepotThisTick(Vehicle *v);
 

	
 
void BeginVehicleMove(const Vehicle *v);
 
void EndVehicleMove(const Vehicle *v);
 
void MarkSingleVehicleDirty(const Vehicle *v);
 

	
 
UnitID GetFreeUnitNumber(VehicleType type);
 

	
 
void TrainConsistChanged(Vehicle *v, bool same_length);
 
void TrainPowerChanged(Vehicle *v);
 
Money GetTrainRunningCost(const Vehicle *v);
 

	
 
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
 
CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
 
void VehicleEnterDepot(Vehicle *v);
 

	
 
bool CanBuildVehicleInfrastructure(VehicleType type);
 

	
 
void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
 

	
 
/** Position information of a vehicle after it moved */
 
struct GetNewVehiclePosResult {
 
	int x, y;  ///< x and y position of the vehicle after moving
 
	TileIndex old_tile; ///< Current tile of the vehicle
 
	TileIndex new_tile; ///< Tile of the vehicle after moving
 
};
src/water_cmd.cpp
Show inline comments
 
@@ -90,25 +90,25 @@ static void MarkCanalsAndRiversAroundDir
 
	for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
 
		MarkTileDirtyIfCanalOrRiver(tile + TileOffsByDir(dir));
 
	}
 
}
 

	
 

	
 
/** 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
 
 */
 
CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	TileIndex tile2;
 

	
 
	CommandCost ret;
 

	
 
	Axis axis = Extract<Axis, 0>(p1);
 

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

	
 
	if (!IsWaterTile(tile) || !IsWaterTile(tile2)) {
 
		return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
 
	}
 
@@ -153,25 +153,25 @@ void MakeWaterKeepingClass(TileIndex til
 
	if (GetTileSlope(tile, &z) != SLOPE_FLAT) wc = WATER_CLASS_INVALID;
 

	
 
	if (wc == WATER_CLASS_SEA && z > 0) wc = WATER_CLASS_CANAL;
 

	
 
	switch (wc) {
 
		case WATER_CLASS_SEA:   MakeWater(tile);              break;
 
		case WATER_CLASS_CANAL: MakeCanal(tile, o, Random()); break;
 
		case WATER_CLASS_RIVER: MakeRiver(tile, Random());    break;
 
		default:                DoClearSquare(tile);          break;
 
	}
 
}
 

	
 
static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
 
static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!IsShipDepot(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	TileIndex tile2 = GetOtherShipDepotTile(tile);
 

	
 
	/* do not check for ship on tile when company goes bankrupt */
 
	if (!(flags & DC_BANKRUPT)) {
 
		if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
@@ -179,25 +179,25 @@ static CommandCost RemoveShipDepot(TileI
 
		delete GetDepotByTile(tile2 < tile ? tile2 : tile);
 

	
 
		MakeWaterKeepingClass(tile,  GetTileOwner(tile));
 
		MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
 
		MarkTileDirtyByTile(tile);
 
		MarkTileDirtyByTile(tile2);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_ship_depot);
 
}
 

	
 
/** build a shiplift */
 
static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
 
static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, DoCommandFlag flags)
 
{
 
	CommandCost ret;
 
	int delta;
 

	
 
	/* middle tile */
 
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return CMD_ERROR;
 

	
 
	delta = TileOffsByDiagDir(dir);
 
	/* lower tile */
 
	WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
 

	
 
@@ -225,25 +225,25 @@ static CommandCost DoBuildShiplift(TileI
 
	if (flags & DC_EXEC) {
 
		MakeLock(tile, _current_company, dir, wc_lower, wc_upper);
 
		MarkTileDirtyByTile(tile);
 
		MarkTileDirtyByTile(tile - delta);
 
		MarkTileDirtyByTile(tile + delta);
 
		MarkCanalsAndRiversAroundDirty(tile - delta);
 
		MarkCanalsAndRiversAroundDirty(tile + delta);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3);
 
}
 

	
 
static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
 
static CommandCost RemoveShiplift(TileIndex tile, DoCommandFlag flags)
 
{
 
	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
 

	
 
	if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
 

	
 
	/* make sure no vehicle is on the tile. */
 
	if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile + delta) || !EnsureNoVehicleOnGround(tile - delta))
 
		return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile);
 
		MakeWaterKeepingClass(tile + delta, GetTileOwner(tile));
 
@@ -254,42 +254,42 @@ static CommandCost RemoveShiplift(TileIn
 
		MarkCanalsAndRiversAroundDirty(tile + delta);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2);
 
}
 

	
 
/** Builds a lock (ship-lift)
 
 * @param tile tile where to place the lock
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
 
	if (dir == INVALID_DIAGDIR) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
	/* Disallow building of locks on river rapids */
 
	if (IsWaterTile(tile)) return_cmd_error(STR_0239_SITE_UNSUITABLE);
 

	
 
	return DoBuildShiplift(tile, dir, flags);
 
}
 

	
 
/** 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 specifies canal (0), water (1) or river (2); last two can only be built in scenario editor
 
 */
 
CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	int size_x, size_y;
 
	int x;
 
	int y;
 
	int sx, sy;
 

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

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

	
 
@@ -334,25 +334,25 @@ CommandCost CmdBuildCanal(TileIndex tile
 
		}
 

	
 
		cost.AddCost(_price.clear_water);
 
	} END_TILE_LOOP(tile, size_x, size_y, 0);
 

	
 
	if (cost.GetCost() == 0) {
 
		return_cmd_error(STR_1007_ALREADY_BUILT);
 
	} else {
 
		return cost;
 
	}
 
}
 

	
 
static CommandCost ClearTile_Water(TileIndex tile, byte flags)
 
static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
 
{
 
	switch (GetWaterTileType(tile)) {
 
		case WATER_TILE_CLEAR:
 
			if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
 

	
 
			/* Make sure freeform edges are allowed or it's not an edge tile. */
 
			if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, MapMaxX() - 1) ||
 
					!IsInsideMM(TileY(tile), 1, MapMaxY() - 1))) {
 
				return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
 
			}
 

	
 
			/* Make sure no vehicle is on the tile */
 
@@ -1138,25 +1138,25 @@ static void ChangeTileOwner_Water(TileIn
 
	if (IsShipDepot(tile)) DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 

	
 
	/* Set owner of canals and locks ... and also canal under dock there was before.
 
	 * Check if the new owner after removing depot isn't OWNER_WATER. */
 
	if (IsTileOwner(tile, old_owner)) SetTileOwner(tile, OWNER_NONE);
 
}
 

	
 
static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y)
 
{
 
	return VETSB_CONTINUE;
 
}
 

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

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

	
 

	
 
extern const TileTypeProcs _tile_type_water_procs = {
 
	DrawTile_Water,           /* draw_tile_proc */
 
	GetSlopeZ_Water,          /* get_slope_z_proc */
 
	ClearTile_Water,          /* clear_tile_proc */
src/waypoint.cpp
Show inline comments
 
@@ -147,25 +147,25 @@ static Waypoint *FindDeletedWaypointClos
 
}
 

	
 
/** Convert existing rail to waypoint. Eg build a waypoint station over
 
 * piece of rail
 
 * @param tile tile where waypoint will be built
 
 * @param flags type of operation
 
 * @param p1 graphics for waypoint type, 0 indicates standard graphics
 
 * @param p2 unused
 
 *
 
 * @todo When checking for the tile slope,
 
 * distingush between "Flat land required" and "land sloped in wrong direction"
 
 */
 
CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdBuildTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Waypoint *wp;
 
	Slope tileh;
 
	Axis axis;
 

	
 
	/* if custom gfx are used, make sure it is within bounds */
 
	if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR;
 

	
 
	if (!IsTileType(tile, MP_RAILWAY) ||
 
			GetRailTileType(tile) != RAIL_TILE_NORMAL || (
 
				(axis = AXIS_X, GetTrackBits(tile) != TRACK_BIT_X) &&
 
				(axis = AXIS_Y, GetTrackBits(tile) != TRACK_BIT_Y)
 
@@ -261,25 +261,25 @@ void WaypointsDailyLoop()
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->deleted != 0 && --wp->deleted == 0) delete wp;
 
	}
 
}
 

	
 
/**
 
 * Remove a waypoint
 
 * @param tile from which to remove waypoint
 
 * @param flags type of operation
 
 * @param justremove will indicate if it is removed from rail or if rails are removed too
 
 * @return cost of operation or error
 
 */
 
CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
 
CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags, bool justremove)
 
{
 
	Waypoint *wp;
 

	
 
	/* Make sure it's a waypoint */
 
	if (!IsRailWaypointTile(tile) ||
 
			(!CheckTileOwnership(tile) && _current_company != OWNER_WATER) ||
 
			!EnsureNoVehicleOnGround(tile)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Track track = GetRailWaypointTrack(tile);
 
@@ -309,49 +309,49 @@ CommandCost RemoveTrainWaypoint(TileInde
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
 
}
 

	
 
/**
 
 * Delete a waypoint
 
 * @param tile tile where waypoint is to be deleted
 
 * @param flags type of operation
 
 * @param p1 unused
 
 * @param p2 unused
 
 * @return cost of operation or error
 
 */
 
CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	return RemoveTrainWaypoint(tile, flags, true);
 
}
 

	
 
static bool IsUniqueWaypointName(const char *name)
 
{
 
	const Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->name != NULL && strcmp(wp->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/**
 
 * Rename a waypoint.
 
 * @param tile unused
 
 * @param flags type of operation
 
 * @param p1 id of waypoint
 
 * @param p2 unused
 
 * @return cost of operation or error
 
 */
 
CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
 
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsValidWaypointID(p1)) return CMD_ERROR;
 

	
 
	Waypoint *wp = GetWaypoint(p1);
 
	if (!CheckOwnership(wp->owner)) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_WAYPOINT_NAME_BYTES) return CMD_ERROR;
 
		if (!IsUniqueWaypointName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
	}
src/waypoint.h
Show inline comments
 
@@ -51,19 +51,19 @@ static inline bool IsValidWaypointID(Way
 

	
 
/**
 
 * Fetch a waypoint by tile
 
 * @param tile Tile of waypoint
 
 * @return Waypoint
 
 */
 
static inline Waypoint *GetWaypointByTile(TileIndex tile)
 
{
 
	assert(IsRailWaypointTile(tile));
 
	return GetWaypoint(GetWaypointIndex(tile));
 
}
 

	
 
CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
 
CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags, bool justremove);
 
Station *ComposeWaypointStation(TileIndex tile);
 
void ShowWaypointWindow(const Waypoint *wp);
 
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype);
 
void UpdateAllWaypointSigns();
 

	
 
#endif /* WAYPOINT_H */
0 comments (0 inline, 0 general)