2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file water_regions.h Handles dividing the water in the map into regions to assist pathfinding. */
10 #ifndef WATER_REGIONS_H
11 #define WATER_REGIONS_H
13 #include "tile_type.h"
16 using TWaterRegionPatchLabel
= uint8_t;
17 using TWaterRegionIndex
= uint
;
19 constexpr int WATER_REGION_EDGE_LENGTH
= 16;
20 constexpr int WATER_REGION_NUMBER_OF_TILES
= WATER_REGION_EDGE_LENGTH
* WATER_REGION_EDGE_LENGTH
;
21 constexpr TWaterRegionPatchLabel INVALID_WATER_REGION_PATCH
= 0;
24 * Describes a single interconnected patch of water within a particular water region.
26 struct WaterRegionPatchDesc
28 int x
; ///< The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis
29 int y
; ///< The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis
30 TWaterRegionPatchLabel label
; ///< Unique label identifying the patch within the region
32 bool operator==(const WaterRegionPatchDesc
&other
) const { return x
== other
.x
&& y
== other
.y
&& label
== other
.label
; }
33 bool operator!=(const WaterRegionPatchDesc
&other
) const { return !(*this == other
); }
38 * Describes a single square water region.
40 struct WaterRegionDesc
42 int x
; ///< The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis
43 int y
; ///< The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis
45 WaterRegionDesc(const int x
, const int y
) : x(x
), y(y
) {}
46 WaterRegionDesc(const WaterRegionPatchDesc
&water_region_patch
) : x(water_region_patch
.x
), y(water_region_patch
.y
) {}
48 bool operator==(const WaterRegionDesc
&other
) const { return x
== other
.x
&& y
== other
.y
; }
49 bool operator!=(const WaterRegionDesc
&other
) const { return !(*this == other
); }
52 int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc
&water_region_patch
);
54 TileIndex
GetWaterRegionCenterTile(const WaterRegionDesc
&water_region
);
56 WaterRegionDesc
GetWaterRegionInfo(TileIndex tile
);
57 WaterRegionPatchDesc
GetWaterRegionPatchInfo(TileIndex tile
);
59 void InvalidateWaterRegion(TileIndex tile
);
61 using TVisitWaterRegionPatchCallBack
= std::function
<void(const WaterRegionPatchDesc
&)>;
62 void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc
&water_region_patch
, TVisitWaterRegionPatchCallBack
&callback
);
64 void AllocateWaterRegions();
66 void PrintWaterRegionDebugInfo(TileIndex tile
);
68 #endif /* WATER_REGIONS_H */