OpenTTD Source: src/pathfinder/water_regions.h Source File

OpenTTD Source 14.0-beta3

water_regions.h
Go to the documentation of this file.
1 /*
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/>.
6 */
7
10 #ifndef WATER_REGIONS_H
11 #define WATER_REGIONS_H
12
13 #include "tile_type.h"
14 #include "map_func.h"
15
16 using TWaterRegionPatchLabel = uint8_t;
17 using TWaterRegionIndex = uint;
18
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
25 struct WaterRegionPatchDesc
26 {
27 int x;
28 int y;
29 TWaterRegionPatchLabel label;
30
31 bool operator==(const WaterRegionPatchDesc &other) const { return x == other.x && y == other.y && label == other.label; }
32 bool operator!=(const WaterRegionPatchDesc &other) const { return !(*this == other); }
33 };
34
35
39 struct WaterRegionDesc
40 {
41 int x;
42 int y;
43
44 WaterRegionDesc(const int x, const int y) : x(x), y(y) {}
45 WaterRegionDesc(const WaterRegionPatchDesc &water_region_patch) : x(water_region_patch.x), y(water_region_patch.y) {}
46
47 bool operator==(const WaterRegionDesc &other) const { return x == other.x && y == other.y; }
48 bool operator!=(const WaterRegionDesc &other) const { return !(*this == other); }
49 };
50
51 TWaterRegionIndex GetWaterRegionIndex(const WaterRegionDesc &water_region);
52
53 int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch);
54
55 TileIndex GetWaterRegionCenterTile(const WaterRegionDesc &water_region);
56
57 WaterRegionDesc GetWaterRegionInfo(TileIndex tile);
58 WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile);
59
60 void InvalidateWaterRegion(TileIndex tile);
61
62 using TVisitWaterRegionPatchCallBack = std::function<void(const WaterRegionPatchDesc &)>;
63 void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback);
64
65 void AllocateWaterRegions();
66
67 void PrintWaterRegionDebugInfo(TileIndex tile);
68
69 #endif /* WATER_REGIONS_H */
WaterRegionPatchDesc
Describes a single interconnected patch of water within a particular water region.
Definition: water_regions.h:25
map_func.h
WaterRegionPatchDesc::y
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
Definition: water_regions.h:28
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetWaterRegionCenterTile
TileIndex GetWaterRegionCenterTile(const WaterRegionDesc &water_region)
Returns the center tile of a particular water region.
Definition: water_regions.cpp:272
GetWaterRegionInfo
WaterRegionDesc GetWaterRegionInfo(TileIndex tile)
Returns basic water region information for the provided tile.
Definition: water_regions.cpp:281
WaterRegionDesc
Describes a single square water region.
Definition: water_regions.h:39
WaterRegionDesc::y
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
Definition: water_regions.h:42
tile_type.h
GetWaterRegionPatchInfo
WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile)
Returns basic water region patch information for the provided tile.
Definition: water_regions.cpp:290
InvalidateWaterRegion
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
Definition: water_regions.cpp:300
WaterRegionPatchDesc::label
TWaterRegionPatchLabel label
Unique label identifying the patch within the region.
Definition: water_regions.h:29
CalculateWaterRegionPatchHash
int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch)
Calculates a number that uniquely identifies the provided water region patch.
Definition: water_regions.cpp:262
WaterRegionDesc::x
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
Definition: water_regions.h:41
AllocateWaterRegions
void AllocateWaterRegions()
Allocates the appropriate amount of water regions for the current map size.
Definition: water_regions.cpp:389
WaterRegionPatchDesc::x
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
Definition: water_regions.h:27
VisitWaterRegionPatchNeighbors
void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback)
Calls the provided callback function on all accessible water region patches in each cardinal directio...
Definition: water_regions.cpp:368
GetWaterRegionIndex
TWaterRegionIndex GetWaterRegionIndex(const WaterRegionDesc &water_region)
Returns the index of the water region.
Definition: water_regions.cpp:253