Merge branch 'polyline_track_tool' into jgrpp
# Conflicts: # src/rail_cmd.cpp # src/rail_gui.cpp # src/viewport.cpp # src/viewport_func.h
This commit is contained in:
@@ -49,6 +49,7 @@ typedef SmallVector<Train *, 16> TrainList;
|
||||
RailtypeInfo _railtypes[RAILTYPE_END];
|
||||
RailType _sorted_railtypes[RAILTYPE_END];
|
||||
uint8 _sorted_railtypes_size;
|
||||
TileIndex _rail_track_endtile; ///< The end of a rail track; as hidden return from the rail build/remove command for GUI purposes.
|
||||
|
||||
assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
|
||||
|
||||
@@ -442,6 +443,8 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
Track track = Extract<Track, 0, 3>(p2);
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
|
||||
_rail_track_endtile = INVALID_TILE;
|
||||
|
||||
if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
|
||||
|
||||
Slope tileh = GetTileSlope(tile);
|
||||
@@ -458,7 +461,10 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
|
||||
ret = CheckTrackCombination(tile, trackbit, flags);
|
||||
if (ret.Succeeded()) ret = EnsureNoTrainOnTrack(tile, track);
|
||||
if (ret.Failed()) return ret;
|
||||
if (ret.Failed()) {
|
||||
if (ret.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) _rail_track_endtile = tile;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
|
||||
if (ret.Failed()) return ret;
|
||||
@@ -549,6 +555,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
}
|
||||
|
||||
if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
|
||||
_rail_track_endtile = tile;
|
||||
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
@@ -588,6 +595,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
}
|
||||
|
||||
cost.AddCost(RailBuildCost(railtype));
|
||||
_rail_track_endtile = tile;
|
||||
return cost;
|
||||
}
|
||||
|
||||
@@ -606,6 +614,8 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
bool crossing = false;
|
||||
|
||||
_rail_track_endtile = INVALID_TILE;
|
||||
|
||||
if (!ValParamTrackOrientation(track)) return CMD_ERROR;
|
||||
TrackBits trackbit = TrackToTrackBits(track);
|
||||
|
||||
@@ -733,6 +743,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
if (v != NULL) TryPathReserve(v, true);
|
||||
}
|
||||
|
||||
_rail_track_endtile = tile;
|
||||
return cost;
|
||||
}
|
||||
|
||||
@@ -867,6 +878,8 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
|
||||
bool remove = HasBit(p2, 8);
|
||||
bool fail_if_obstacle = HasBit(p2, 9);
|
||||
|
||||
_rail_track_endtile = INVALID_TILE;
|
||||
|
||||
if ((!remove && !ValParamRailtype(railtype)) || !ValParamTrackOrientation(track)) return CMD_ERROR;
|
||||
if (p1 >= MapSize()) return CMD_ERROR;
|
||||
TileIndex end_tile = p1;
|
||||
@@ -878,10 +891,12 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
|
||||
bool had_success = false;
|
||||
CommandCost last_error = CMD_ERROR;
|
||||
for (;;) {
|
||||
TileIndex last_endtile = _rail_track_endtile;
|
||||
CommandCost ret = DoCommand(tile, remove ? 0 : railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
|
||||
|
||||
if (ret.Failed()) {
|
||||
last_error = ret;
|
||||
if (_rail_track_endtile == INVALID_TILE) _rail_track_endtile = last_endtile;
|
||||
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
|
||||
if (fail_if_obstacle) return last_error;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user