|
@@ -738,15 +738,16 @@ CommandCost CheckFlatLand(TileArea tile_
|
|
|
/** Checks if a rail station can be built at the given area.
|
|
|
* @param tile_area Area to check.
|
|
|
* @param flags Operation to perform.
|
|
|
* @param invalid_dirs Prohibited directions (set of #DiagDirection).
|
|
|
* @param station StationID to be queried and returned if available.
|
|
|
* @param rt The rail type to check for (overbuilding rail stations over rail).
|
|
|
* @param affected_vehicles List of trains with PBS reservations on the tiles
|
|
|
* @return The cost in case of success, or an error code if it failed.
|
|
|
*/
|
|
|
static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, StationID *station, RailType rt = INVALID_RAILTYPE)
|
|
|
static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, StationID *station, RailType rt, SmallVector<Train *, 4> &affected_vehicles)
|
|
|
{
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
int allowed_z = -1;
|
|
|
|
|
|
TILE_AREA_LOOP(tile_cur, tile_area) {
|
|
|
CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z);
|
|
@@ -781,12 +782,19 @@ static CommandCost CheckFlatLandRailStat
|
|
|
*/
|
|
|
TrackBits tracks = GetTrackBits(tile_cur);
|
|
|
Track track = RemoveFirstTrack(&tracks);
|
|
|
Track expected_track = HasBit(invalid_dirs, DIAGDIR_NE) ? TRACK_X : TRACK_Y;
|
|
|
|
|
|
if (tracks == TRACK_BIT_NONE && track == expected_track) {
|
|
|
/* Check for trains having a reservation for this tile. */
|
|
|
if (HasBit(GetRailReservationTrackBits(tile_cur), track)) {
|
|
|
Train *v = GetTrainForReservation(tile_cur, track);
|
|
|
if (v != NULL) {
|
|
|
*affected_vehicles.Append() = v;
|
|
|
}
|
|
|
}
|
|
|
CommandCost ret = DoCommand(tile_cur, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
|
|
|
if (ret.Failed()) return ret;
|
|
|
cost.AddCost(ret);
|
|
|
/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
|
|
|
continue;
|
|
|
}
|
|
@@ -1127,14 +1135,15 @@ CommandCost CmdBuildRailStation(TileInde
|
|
|
|
|
|
/* these values are those that will be stored in train_tile and station_platforms */
|
|
|
TileArea new_location(tile_org, w_org, h_org);
|
|
|
|
|
|
/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
|
|
|
StationID est = INVALID_STATION;
|
|
|
SmallVector<Train *, 4> affected_vehicles;
|
|
|
/* Clear the land below the station. */
|
|
|
CommandCost cost = CheckFlatLandRailStation(TileArea(tile_org, w_org, h_org), flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, rt);
|
|
|
CommandCost cost = CheckFlatLandRailStation(TileArea(tile_org, w_org, h_org), flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, rt, affected_vehicles);
|
|
|
if (cost.Failed()) return cost;
|
|
|
/* Add construction expenses. */
|
|
|
cost.AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
|
|
|
|
|
|
Station *st = NULL;
|
|
|
ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
|
|
@@ -1219,13 +1228,12 @@ CommandCost CmdBuildRailStation(TileInde
|
|
|
|
|
|
layout_ptr = AllocaM(byte, numtracks * plat_len);
|
|
|
GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
|
|
|
|
|
|
numtracks_orig = numtracks;
|
|
|
|
|
|
SmallVector<Train*, 4> affected_vehicles;
|
|
|
do {
|
|
|
TileIndex tile = tile_org;
|
|
|
int w = plat_len;
|
|
|
do {
|
|
|
byte layout = *layout_ptr++;
|
|
|
if (IsRailStationTile(tile) && HasStationReservation(tile)) {
|