* Called from water_cmd if a non-flat rail-tile gets flooded and should be converted to shore. * The function floods the lower halftile, if the tile has a halftile foundation. * * @param t The tile to flood. * @return true if something was flooded. */
| 757 | * @return true if something was flooded. |
| 758 | */ |
| 759 | bool FloodHalftile(TileIndex t) |
| 760 | { |
| 761 | assert(IsPlainRailTile(t)); |
| 762 | |
| 763 | bool flooded = false; |
| 764 | if (GetRailGroundType(t) == RailGroundType::HalfTileWater) return flooded; |
| 765 | |
| 766 | Slope tileh = GetTileSlope(t); |
| 767 | TrackBits rail_bits = GetTrackBits(t); |
| 768 | |
| 769 | if (IsSlopeWithOneCornerRaised(tileh)) { |
| 770 | TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh))); |
| 771 | |
| 772 | TrackBits to_remove = lower_track & rail_bits; |
| 773 | if (to_remove != TRACK_BIT_NONE) { |
| 774 | Backup<CompanyID> cur_company(_current_company, OWNER_WATER); |
| 775 | flooded = Command<CMD_REMOVE_SINGLE_RAIL>::Do(DoCommandFlag::Execute, t, FindFirstTrack(to_remove)).Succeeded(); |
| 776 | cur_company.Restore(); |
| 777 | if (!flooded) return flooded; // not yet floodable |
| 778 | rail_bits = rail_bits & ~to_remove; |
| 779 | if (rail_bits == TRACK_BIT_NONE) { |
| 780 | MakeShore(t); |
| 781 | MarkTileDirtyByTile(t); |
| 782 | return flooded; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | if (IsNonContinuousFoundation(GetRailFoundation(tileh, rail_bits))) { |
| 787 | flooded = true; |
| 788 | SetRailGroundType(t, RailGroundType::HalfTileWater); |
| 789 | MarkTileDirtyByTile(t); |
| 790 | } |
| 791 | } else { |
| 792 | /* Make shore on steep slopes and 'three-corners-raised'-slopes. */ |
| 793 | if (ApplyFoundationToSlope(GetRailFoundation(tileh, rail_bits), tileh) == 0) { |
| 794 | if (IsSteepSlope(tileh) || IsSlopeWithThreeCornersRaised(tileh)) { |
| 795 | flooded = true; |
| 796 | SetRailGroundType(t, RailGroundType::HalfTileWater); |
| 797 | MarkTileDirtyByTile(t); |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | return flooded; |
| 802 | } |
| 803 | |
| 804 | static const TileIndexDiffC _trackdelta[] = { |
| 805 | { -1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, 1 }, |
no test coverage detected