summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-02-21 20:34:57 +0000
committeralberth <alberth@openttd.org>2010-02-21 20:34:57 +0000
commit2b07389fe66471c48d7cd6bdcd96cbe98327e90c (patch)
tree4e6c9259affc393cac484bcdd08b47f2ad3ed52b /src
parent5488a2c1a878a103d138bcda2f225e84d084b41c (diff)
downloadopenttd-2b07389fe66471c48d7cd6bdcd96cbe98327e90c.tar.xz
(svn r19189) -Codechange: CheckTrackCombination() returns a CommandCost.
Diffstat (limited to 'src')
-rw-r--r--src/rail_cmd.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 5679eca24..69e13620c 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -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;
+
+ if (!EnsureNoTrainOnTrack(tile, track)) return CMD_ERROR;
- CommandCost ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
+ ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);