1
0
Fork 0

Fix #12940: Use specific error when overbuilding station on signals (#12943)

pull/13061/head
Tyler Trahan 2024-11-06 14:13:04 -05:00 committed by GitHub
parent c3bb512bd9
commit 4cd46e54aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 25 deletions

View File

@ -916,34 +916,32 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
} }
} }
} else { } else {
/* Rail type is only valid when building a railway station; if station to /* If we are building a station with a valid railtype, we may be able to overbuild an existing rail tile. */
* build isn't a rail station it's INVALID_RAILTYPE. */ if (rt != INVALID_RAILTYPE && IsPlainRailTile(tile_cur)) {
if (rt != INVALID_RAILTYPE && /* Don't overbuild signals. */
IsPlainRailTile(tile_cur) && !HasSignals(tile_cur) && if (HasSignals(tile_cur)) return_cmd_error(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
HasPowerOnRail(GetRailType(tile_cur), rt)) {
/* Allow overbuilding if the tile:
* - has rail, but no signals
* - it has exactly one track
* - the track is in line with the station
* - the current rail type has power on the to-be-built type (e.g. convert normal rail to el rail)
*/
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) { /* The current rail type must have power on the to-be-built type (e.g. convert normal rail to electrified rail). */
/* Check for trains having a reservation for this tile. */ if (HasPowerOnRail(GetRailType(tile_cur), rt)) {
if (HasBit(GetRailReservationTrackBits(tile_cur), track)) { TrackBits tracks = GetTrackBits(tile_cur);
Train *v = GetTrainForReservation(tile_cur, track); Track track = RemoveFirstTrack(&tracks);
if (v != nullptr) { Track expected_track = HasBit(invalid_dirs, DIAGDIR_NE) ? TRACK_X : TRACK_Y;
affected_vehicles.push_back(v);
/* The existing track must align with the desired station axis. */
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 != nullptr) {
affected_vehicles.push_back(v);
}
} }
ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile_cur, track);
if (ret.Failed()) return ret;
cost.AddCost(ret);
/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
return cost;
} }
ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile_cur, track);
if (ret.Failed()) return ret;
cost.AddCost(ret);
/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
return cost;
} }
} }
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur);