mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(svn r19189) -Codechange: CheckTrackCombination() returns a CommandCost.
This commit is contained in:
parent
5488a2c1a8
commit
2b07389fe6
@ -172,11 +172,15 @@ static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
|
||||
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(TileIndex tile, TrackBits to_build, uint flags
|
||||
/* 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 tile, DoCommandFlag flags, uint32 p1, u
|
||||
|
||||
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 = CheckTrackCombination(tile, trackbit, flags);
|
||||
ret.SetGlobalErrorMessage();
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
CommandCost ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
|
||||
if (!EnsureNoTrainOnTrack(tile, track)) return CMD_ERROR;
|
||||
|
||||
ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user