File diff r26193:4bc7915a2156 → r26194:f7347205838e
src/rail_cmd.cpp
Show inline comments
 
@@ -412,13 +412,13 @@ static CommandCost CheckRailSlope(Slope 
 
	if ((f_new == FOUNDATION_INVALID) ||
 
			((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes))) {
 
		return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
	}
 

	
 
	Foundation f_old = GetRailFoundation(tileh, existing);
 
	return CommandCost(EXPENSES_CONSTRUCTION, f_new != f_old ? _price[PR_BUILD_FOUNDATION] : (Money)0);
 
	return CommandCost(EXPENSES_T_TRAIN_CON, f_new != f_old ? _price[PR_BUILD_FOUNDATION] : (Money)0);
 
}
 

	
 
/* Validate functions for rail building */
 
static inline bool ValParamTrackOrientation(Track track)
 
{
 
	return IsValidTrack(track);
 
@@ -432,13 +432,13 @@ static inline bool ValParamTrackOrientat
 
 * @param track track-orientation
 
 * @param auto_remove_signals false = error on signal in the way, true = auto remove signals when in the way
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType railtype, Track track, bool auto_remove_signals)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost cost(EXPENSES_T_TRAIN_CON);
 

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

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

	
 
@@ -615,13 +615,13 @@ CommandCost CmdBuildSingleRail(DoCommand
 
 * @param tile tile to remove track from
 
 * @param track rail orientation
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost cost(EXPENSES_T_TRAIN_CON);
 
	bool crossing = false;
 

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

	
 
	/* Need to read tile owner now because it may change when the rail is removed
 
@@ -874,13 +874,13 @@ static CommandCost ValidateAutoDrag(Trac
 
 * @param auto_remove_signals false = build up to an obstacle, true = fail if an obstacle is found (used for AIs), only used for building
 
 * @param fail_on_obstacle false = error on signal in the way, true = auto remove signals when in the way, only used for building
 
 * @return the cost of this operation or an error
 
 */
 
static CommandCost CmdRailTrackHelper(DoCommandFlag flags, TileIndex tile, TileIndex end_tile, RailType railtype, Track track, bool remove, bool auto_remove_signals, bool fail_on_obstacle)
 
{
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	CommandCost total_cost(EXPENSES_T_TRAIN_CON);
 

	
 
	if ((!remove && !ValParamRailtype(railtype)) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (end_tile >= MapSize()) return CMD_ERROR;
 

	
 
	Trackdir trackdir = TrackToTrackdir(track);
 

	
 
@@ -1058,23 +1058,23 @@ CommandCost CmdBuildSingleSignal(DoComma
 
	/* you can not convert a signal if no signal is on track */
 
	if (convert_signal && !HasSignalOnTrack(tile, track)) return_cmd_error(STR_ERROR_THERE_ARE_NO_SIGNALS);
 

	
 
	CommandCost cost;
 
	if (!HasSignalOnTrack(tile, track)) {
 
		/* build new signals */
 
		cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_SIGNALS]);
 
		cost = CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_BUILD_SIGNALS]);
 
	} else {
 
		if (signals_copy != 0 && sigvar != GetSignalVariant(tile, track)) {
 
			/* convert signals <-> semaphores */
 
			cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_SIGNALS] + _price[PR_CLEAR_SIGNALS]);
 
			cost = CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_BUILD_SIGNALS] + _price[PR_CLEAR_SIGNALS]);
 

	
 
		} else if (convert_signal) {
 
			/* convert button pressed */
 
			if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) {
 
				/* convert electric <-> semaphore */
 
				cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_SIGNALS] + _price[PR_CLEAR_SIGNALS]);
 
				cost = CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_BUILD_SIGNALS] + _price[PR_CLEAR_SIGNALS]);
 
			} else {
 
				/* it is free to change signal type: normal-pre-exit-combo */
 
				cost = CommandCost();
 
			}
 

	
 
		} else {
 
@@ -1236,13 +1236,13 @@ static bool AdvanceSignalAutoFill(TileIn
 
 * @param minimise_gaps false = keep fixed distance, true = minimise gaps between signals
 
 * @param signal_density user defined signals_density
 
 * @return the cost of this operation or an error
 
 */
 
static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, TileIndex end_tile, Track track, SignalType sigtype, SignalVariant sigvar, bool mode, bool remove, bool autofill, bool minimise_gaps, int signal_density)
 
{
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	CommandCost total_cost(EXPENSES_T_TRAIN_CON);
 

	
 
	if (end_tile >= MapSize() || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
 
	if (!remove && (sigtype > SIGTYPE_LAST || sigvar > SIG_SEMAPHORE)) return CMD_ERROR;
 

	
 
	if (!IsPlainRailTile(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
 
@@ -1489,13 +1489,13 @@ CommandCost CmdRemoveSingleSignal(DoComm
 
		YapfNotifyTrackLayoutChange(tile, track);
 
		if (v != nullptr) TryPathReserve(v, false);
 

	
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_SIGNALS]);
 
	return CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_CLEAR_SIGNALS]);
 
}
 

	
 
/**
 
 * Remove signals on a stretch of track.
 
 * Stub for the unified signal builder/remover
 
 * @param flags operation to perform
 
@@ -1538,13 +1538,13 @@ CommandCost CmdConvertRail(DoCommandFlag
 

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

	
 
	TrainList affected_trains;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost cost(EXPENSES_T_TRAIN_CON);
 
	CommandCost error = CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); // by default, there is no track to convert.
 
	bool found_convertible_track = false; // whether we actually did convert some track (see bug #7633)
 

	
 
	TileIterator *iter = diagonal ? (TileIterator *)new DiagonalTileIterator(area_start, area_end) : new OrthogonalTileIterator(area_start, area_end);
 
	for (; (tile = *iter) != INVALID_TILE; ++(*iter)) {
 
		TileType tt = GetTileType(tile);
 
@@ -1774,18 +1774,18 @@ static CommandCost RemoveTrainDepot(Tile
 
		DoClearSquare(tile);
 
		AddSideToSignalBuffer(tile, dir, owner);
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
 
		if (v != nullptr) TryPathReserve(v, true);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_TRAIN]);
 
	return CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_CLEAR_DEPOT_TRAIN]);
 
}
 

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

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

	
 
@@ -2994,21 +2994,21 @@ static CommandCost TestAutoslopeOnRailTi
 
		case TRACK_BIT_RIGHT: track_corner = CORNER_E; break;
 
		case TRACK_BIT_UPPER: track_corner = CORNER_N; break;
 

	
 
		/* Surface slope must not be changed */
 
		default:
 
			if (z_old != z_new || tileh_old != tileh_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
 
			return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
			return CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_BUILD_FOUNDATION]);
 
	}
 

	
 
	/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
 
	z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner);
 
	z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner);
 
	if (z_old != z_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
 

	
 
	CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
	CommandCost cost = CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_BUILD_FOUNDATION]);
 
	/* 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[PR_CLEAR_WATER]);
 
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
 
	}
 
@@ -3060,16 +3060,16 @@ static CommandCost TerraformTile_Track(T
 
		}
 

	
 
		/* Make the ground dirty */
 
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
 

	
 
		/* allow terraforming */
 
		return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price[PR_CLEAR_WATER] : (Money)0);
 
		return CommandCost(EXPENSES_T_TRAIN_CON, was_water ? _price[PR_CLEAR_WATER] : (Money)0);
 
	} else if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() &&
 
			AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) {
 
		return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
		return CommandCost(EXPENSES_T_TRAIN_CON, _price[PR_BUILD_FOUNDATION]);
 
	}
 
	return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_rail_procs = {