1
0
Fork 0

(svn r19189) -Codechange: CheckTrackCombination() returns a CommandCost.

release/1.1
alberth 2010-02-21 20:34:57 +00:00
parent 5488a2c1a8
commit 2b07389fe6
1 changed files with 18 additions and 15 deletions

View File

@ -172,11 +172,15 @@ static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
return !HasVehicleOnPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc); 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_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
if (!IsPlainRail(tile)) return false;
/* So, we have a tile with tracks on it (and possibly signals). Let's see /* So, we have a tile with tracks on it (and possibly signals). Let's see
* what tracks first */ * what tracks first */
@ -186,19 +190,17 @@ static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags
/* Are we really building something new? */ /* Are we really building something new? */
if (current == future) { if (current == future) {
/* Nothing new is being built */ /* Nothing new is being built */
_error_message = STR_ERROR_ALREADY_BUILT; return_cmd_error(STR_ERROR_ALREADY_BUILT);
return false;
} }
/* Let's see if we may build this */ /* Let's see if we may build this */
if ((flags & DC_NO_RAIL_OVERLAP) || HasSignals(tile)) { if ((flags & DC_NO_RAIL_OVERLAP) || HasSignals(tile)) {
/* If we are not allowed to overlap (flag is on for ai companies or we have /* If we are not allowed to overlap (flag is on for ai companies or we have
* signals on the tile), check that */ * signals on the tile), check that */
return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT; if (future != TRACK_BIT_HORZ && future != TRACK_BIT_VERT) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
} else {
/* Normally, we may overlap and any combination is valid */
return true;
} }
/* 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 (!IsCompatibleRail(GetRailType(tile), railtype)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
if (!CheckTrackCombination(tile, trackbit, flags) || CommandCost ret = CheckTrackCombination(tile, trackbit, flags);
!EnsureNoTrainOnTrack(tile, track)) { ret.SetGlobalErrorMessage();
return CMD_ERROR; 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; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret);