MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ClearTile_Track

Function ClearTile_Track

src/rail_cmd.cpp:1792–1845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1790}
1791
1792static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlags flags)
1793{
1794 CommandCost cost(EXPENSES_CONSTRUCTION);
1795
1796 if (flags.Test(DoCommandFlag::Auto)) {
1797 if (!IsTileOwner(tile, _current_company)) {
1798 return CommandCost(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
1799 }
1800
1801 if (IsPlainRail(tile)) {
1802 return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
1803 } else {
1804 return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
1805 }
1806 }
1807
1808 switch (GetRailTileType(tile)) {
1809 case RailTileType::Signals:
1810 case RailTileType::Normal: {
1811 Slope tileh = GetTileSlope(tile);
1812 /* Is there flat water on the lower halftile that gets cleared expensively? */
1813 bool water_ground = (GetRailGroundType(tile) == RailGroundType::HalfTileWater && IsSlopeWithOneCornerRaised(tileh));
1814
1815 TrackBits tracks = GetTrackBits(tile);
1816 while (tracks != TRACK_BIT_NONE) {
1817 Track track = RemoveFirstTrack(&tracks);
1818 CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, track);
1819 if (ret.Failed()) return ret;
1820 cost.AddCost(ret.GetCost());
1821 }
1822
1823 /* When bankrupting, don't make water dirty, there could be a ship on lower halftile.
1824 * Same holds for non-companies clearing the tile, e.g. disasters. */
1825 if (water_ground && !flags.Test(DoCommandFlag::Bankrupt) && Company::IsValidID(_current_company)) {
1826 CommandCost ret = EnsureNoVehicleOnGround(tile);
1827 if (ret.Failed()) return ret;
1828
1829 /* The track was removed, and left a coast tile. Now also clear the water. */
1830 if (flags.Test(DoCommandFlag::Execute)) {
1831 DoClearSquare(tile);
1832 }
1833 cost.AddCost(_price[PR_CLEAR_WATER]);
1834 }
1835
1836 return cost;
1837 }
1838
1839 case RailTileType::Depot:
1840 return RemoveTrainDepot(tile, flags);
1841
1842 default:
1843 return CMD_ERROR;
1844 }
1845}
1846
1847/**
1848 * Get surface height in point (x,y)

Callers

nothing calls this directly

Calls 15

IsTileOwnerFunction · 0.85
CommandCostClass · 0.85
IsPlainRailFunction · 0.85
GetRailTileTypeFunction · 0.85
GetTileSlopeFunction · 0.85
GetRailGroundTypeFunction · 0.85
GetTrackBitsFunction · 0.85
RemoveFirstTrackFunction · 0.85
EnsureNoVehicleOnGroundFunction · 0.85
DoClearSquareFunction · 0.85
RemoveTrainDepotFunction · 0.85

Tested by

no test coverage detected