* Remove signals * @param flags operation to perform * @param tile coordinates where signal is being deleted from * @param track track-orientation * @return the cost of this operation or an error */
| 1456 | * @return the cost of this operation or an error |
| 1457 | */ |
| 1458 | CommandCost CmdRemoveSingleSignal(DoCommandFlags flags, TileIndex tile, Track track) |
| 1459 | { |
| 1460 | if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) { |
| 1461 | return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK); |
| 1462 | } |
| 1463 | if (!HasSignalOnTrack(tile, track)) { |
| 1464 | return CommandCost(STR_ERROR_THERE_ARE_NO_SIGNALS); |
| 1465 | } |
| 1466 | |
| 1467 | /* Only water can remove signals from anyone */ |
| 1468 | if (_current_company != OWNER_WATER) { |
| 1469 | CommandCost ret = CheckTileOwnership(tile); |
| 1470 | if (ret.Failed()) return ret; |
| 1471 | } |
| 1472 | |
| 1473 | /* Do it? */ |
| 1474 | if (flags.Test(DoCommandFlag::Execute)) { |
| 1475 | Train *v = nullptr; |
| 1476 | if (HasReservedTracks(tile, TrackToTrackBits(track))) { |
| 1477 | v = GetTrainForReservation(tile, track); |
| 1478 | } else if (IsPbsSignal(GetSignalType(tile, track))) { |
| 1479 | /* PBS signal, might be the end of a path reservation. */ |
| 1480 | Trackdir td = TrackToTrackdir(track); |
| 1481 | for (int i = 0; v == nullptr && i < 2; i++, td = ReverseTrackdir(td)) { |
| 1482 | /* Only test the active signal side. */ |
| 1483 | if (!HasSignalOnTrackdir(tile, ReverseTrackdir(td))) continue; |
| 1484 | TileIndex next = TileAddByDiagDir(tile, TrackdirToExitdir(td)); |
| 1485 | TrackBits tracks = TrackdirBitsToTrackBits(TrackdirReachesTrackdirs(td)); |
| 1486 | if (HasReservedTracks(next, tracks)) { |
| 1487 | v = GetTrainForReservation(next, TrackBitsToTrack(GetReservedTrackbits(next) & tracks)); |
| 1488 | } |
| 1489 | } |
| 1490 | } |
| 1491 | Company::Get(GetTileOwner(tile))->infrastructure.signal -= CountBits(GetPresentSignals(tile)); |
| 1492 | SetPresentSignals(tile, GetPresentSignals(tile) & ~SignalOnTrack(track)); |
| 1493 | Company::Get(GetTileOwner(tile))->infrastructure.signal += CountBits(GetPresentSignals(tile)); |
| 1494 | DirtyCompanyInfrastructureWindows(GetTileOwner(tile)); |
| 1495 | |
| 1496 | /* removed last signal from tile? */ |
| 1497 | if (GetPresentSignals(tile) == 0) { |
| 1498 | SetSignalStates(tile, 0); |
| 1499 | SetHasSignals(tile, false); |
| 1500 | SetSignalVariant(tile, INVALID_TRACK, SIG_ELECTRIC); // remove any possible semaphores |
| 1501 | } |
| 1502 | |
| 1503 | AddTrackToSignalBuffer(tile, track, GetTileOwner(tile)); |
| 1504 | YapfNotifyTrackLayoutChange(tile, track); |
| 1505 | if (v != nullptr) TryPathReserve(v, false); |
| 1506 | |
| 1507 | MarkTileDirtyByTile(tile); |
| 1508 | } |
| 1509 | |
| 1510 | return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_SIGNALS]); |
| 1511 | } |
| 1512 | |
| 1513 | /** |
| 1514 | * Remove signals on a stretch of track. |
nothing calls this directly
no test coverage detected