* Remove a single piece of track * @param flags operation to perform * @param tile tile to remove track from * @param track rail orientation * @return the cost of this operation or an error */
| 610 | * @return the cost of this operation or an error |
| 611 | */ |
| 612 | CommandCost CmdRemoveSingleRail(DoCommandFlags flags, TileIndex tile, Track track) |
| 613 | { |
| 614 | CommandCost cost(EXPENSES_CONSTRUCTION); |
| 615 | bool crossing = false; |
| 616 | |
| 617 | if (!ValParamTrackOrientation(track)) return CMD_ERROR; |
| 618 | TrackBits trackbit = TrackToTrackBits(track); |
| 619 | |
| 620 | /* Need to read tile owner now because it may change when the rail is removed |
| 621 | * Also, in case of floods, _current_company != owner |
| 622 | * There may be invalid tiletype even in exec run (when removing long track), |
| 623 | * so do not call GetTileOwner(tile) in any case here */ |
| 624 | Owner owner = INVALID_OWNER; |
| 625 | |
| 626 | Train *v = nullptr; |
| 627 | |
| 628 | switch (GetTileType(tile)) { |
| 629 | case MP_ROAD: { |
| 630 | if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK); |
| 631 | |
| 632 | if (_current_company != OWNER_WATER) { |
| 633 | CommandCost ret = CheckTileOwnership(tile); |
| 634 | if (ret.Failed()) return ret; |
| 635 | } |
| 636 | |
| 637 | if (!flags.Test(DoCommandFlag::Bankrupt)) { |
| 638 | CommandCost ret = EnsureNoVehicleOnGround(tile); |
| 639 | if (ret.Failed()) return ret; |
| 640 | } |
| 641 | |
| 642 | cost.AddCost(RailClearCost(GetRailType(tile))); |
| 643 | |
| 644 | if (flags.Test(DoCommandFlag::Execute)) { |
| 645 | UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(tile, GetCrossingRoadAxis(tile)); |
| 646 | |
| 647 | if (HasReservedTracks(tile, trackbit)) { |
| 648 | v = GetTrainForReservation(tile, track); |
| 649 | if (v != nullptr) FreeTrainTrackReservation(v); |
| 650 | } |
| 651 | |
| 652 | owner = GetTileOwner(tile); |
| 653 | Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR; |
| 654 | DirtyCompanyInfrastructureWindows(owner); |
| 655 | MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypeRoad(tile), GetRoadTypeTram(tile), GetTownIndex(tile), GetRoadOwner(tile, RTT_ROAD), GetRoadOwner(tile, RTT_TRAM)); |
| 656 | DeleteNewGRFInspectWindow(GSF_RAILTYPES, tile.base()); |
| 657 | } |
| 658 | break; |
| 659 | } |
| 660 | |
| 661 | case MP_RAILWAY: { |
| 662 | TrackBits present; |
| 663 | /* There are no rails present at depots. */ |
| 664 | if (!IsPlainRail(tile)) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK); |
| 665 | |
| 666 | if (_current_company != OWNER_WATER) { |
| 667 | CommandCost ret = CheckTileOwnership(tile); |
| 668 | if (ret.Failed()) return ret; |
| 669 | } |
nothing calls this directly
no test coverage detected