Changeset - r14772:59c9e3e72143
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2010-03-07 18:29:53
alberth@openttd.org
(svn r19370) -Codechange: EnsureNoTrainOnTrack() returns a CommandCost.
1 file changed with 16 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -147,20 +147,18 @@ static const byte _track_sloped_sprites[
 
/**
 
 * Tests if a vehicle interacts with the specified track.
 
 * All track bits interact except parallel #TRACK_BIT_HORZ or #TRACK_BIT_VERT.
 
 *
 
 * @param tile The tile.
 
 * @param track The track.
 
 * @return \c true if no train that interacts, is found. \c false if a train is found.
 
 * @return Succeeded command (no train found), or a failed command (a train was found).
 
 */
 
static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
 
static CommandCost EnsureNoTrainOnTrack(TileIndex tile, Track track)
 
{
 
	TrackBits rail_bits = TrackToTrackBits(track);
 
	CommandCost ret = EnsureNoTrainOnTrackBits(tile, rail_bits);
 
	ret.SetGlobalErrorMessage();
 
	return ret.Succeeded();
 
	return EnsureNoTrainOnTrackBits(tile, rail_bits);
 
}
 

	
 
/** 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.
 
@@ -372,17 +370,16 @@ CommandCost CmdBuildSingleRail(TileIndex
 

	
 
			if (!IsPlainRail(tile)) return CMD_ERROR;
 

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

	
 
			CommandCost ret = CheckTrackCombination(tile, trackbit, flags);
 
			if (ret.Succeeded()) ret = EnsureNoTrainOnTrack(tile, track);
 
			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);
 

	
 
			/* If the rail types don't match, try to convert only if engines of
 
			 * the new rail type are not powered on the present rail type and engines of
 
@@ -539,17 +536,17 @@ CommandCost CmdRemoveSingleRail(TileInde
 
			break;
 
		}
 

	
 
		case MP_RAILWAY: {
 
			TrackBits present;
 

	
 
			if (!IsPlainRail(tile) ||
 
					(_current_company != OWNER_WATER && !CheckTileOwnership(tile)) ||
 
					!EnsureNoTrainOnTrack(tile, track)) {
 
				return CMD_ERROR;
 
			}
 
			if (!IsPlainRail(tile) || (_current_company != OWNER_WATER && !CheckTileOwnership(tile))) return CMD_ERROR;
 

	
 
			CommandCost ret = EnsureNoTrainOnTrack(tile, track);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			present = GetTrackBits(tile);
 
			if ((present & trackbit) == 0) return CMD_ERROR;
 
			if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
 

	
 
			/* Charge extra to remove signals on the track, if they are there */
 
@@ -896,15 +893,18 @@ CommandCost CmdBuildSingleSignal(TileInd
 
	uint num_dir_cycle = GB(p1, 15, 2);
 

	
 
	if (sigtype > SIGTYPE_LAST) return CMD_ERROR;
 

	
 
	/* You can only build signals on plain rail tiles, and the selected track must exist */
 
	if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) ||
 
			!HasTrack(tile, track) || !EnsureNoTrainOnTrack(tile, track)) {
 
			!HasTrack(tile, track)) {
 
		return CMD_ERROR;
 
	}
 
	CommandCost ret = EnsureNoTrainOnTrack(tile, track);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	/* Protect against invalid signal copying */
 
	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
 

	
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
@@ -1254,16 +1254,18 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
{
 
	Track track = (Track)GB(p1, 0, 3);
 

	
 
	if (!ValParamTrackOrientation(track) ||
 
			!IsPlainRailTile(tile) ||
 
			!HasTrack(tile, track) ||
 
			!EnsureNoTrainOnTrack(tile, track) ||
 
			!HasSignalOnTrack(tile, track)) {
 
		return CMD_ERROR;
 
	}
 
	CommandCost ret = EnsureNoTrainOnTrack(tile, track);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	/* Only water can remove signals from anyone */
 
	if (_current_company != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	/* Do it? */
 
	if (flags & DC_EXEC) {
0 comments (0 inline, 0 general)