Changeset - r14602:8b4037c5395c
[Not reviewed]
master
0 1 0
alberth - 14 years ago 2010-02-21 20:34:57
alberth@openttd.org
(svn r19189) -Codechange: CheckTrackCombination() returns a CommandCost.
1 file changed with 19 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -172,11 +172,15 @@ static bool EnsureNoTrainOnTrack(TileInd
 
	return !HasVehicleOnPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc);
 
}
 

	
 
static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
 
/** Check that the new track bits may be built.
 
 * @param tile %Tile to build on.
 
 * @param to_build New track bits.
 
 * @param flags    Flags of the operation.
 
 * @return Succeeded or failed command.
 
 */
 
static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
 
{
 
	_error_message = STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION;
 

	
 
	if (!IsPlainRail(tile)) return false;
 
	if (!IsPlainRail(tile)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
 

	
 
	/* So, we have a tile with tracks on it (and possibly signals). Let's see
 
	 * what tracks first */
 
@@ -186,19 +190,17 @@ static bool CheckTrackCombination(TileIn
 
	/* Are we really building something new? */
 
	if (current == future) {
 
		/* Nothing new is being built */
 
		_error_message = STR_ERROR_ALREADY_BUILT;
 
		return false;
 
		return_cmd_error(STR_ERROR_ALREADY_BUILT);
 
	}
 

	
 
	/* Let's see if we may build this */
 
	if ((flags & DC_NO_RAIL_OVERLAP) || HasSignals(tile)) {
 
		/* If we are not allowed to overlap (flag is on for ai companies or we have
 
		 * signals on the tile), check that */
 
		return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
 
	} else {
 
		/* Normally, we may overlap and any combination is valid */
 
		return true;
 
		if (future != TRACK_BIT_HORZ && future != TRACK_BIT_VERT) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
 
	}
 
	/* Normally, we may overlap and any combination is valid */
 
	return CommandCost();
 
}
 

	
 

	
 
@@ -382,12 +384,13 @@ CommandCost CmdBuildSingleRail(TileIndex
 

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

	
 
			if (!CheckTrackCombination(tile, trackbit, flags) ||
 
					!EnsureNoTrainOnTrack(tile, track)) {
 
				return CMD_ERROR;
 
			}
 

	
 
			CommandCost ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
 
			CommandCost ret = CheckTrackCombination(tile, trackbit, flags);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			if (!EnsureNoTrainOnTrack(tile, track)) return CMD_ERROR;
 

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

	
0 comments (0 inline, 0 general)