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

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef WATER_REGIONS_H
11#define WATER_REGIONS_H
12
13#include "../core/strong_typedef_type.hpp"
14#include "../tile_type.h"
15#include "../map_func.h"
16
17using WaterRegionIndex = StrongType::Typedef<uint, struct TWaterRegionIndexTag, StrongType::Compare>;
18using WaterRegionPatchLabel = StrongType::Typedef<uint8_t, struct TWaterRegionPatchLabelTag, StrongType::Compare, StrongType::Integer>;
19
20constexpr int WATER_REGION_EDGE_LENGTH = 16;
21constexpr int WATER_REGION_NUMBER_OF_TILES = WATER_REGION_EDGE_LENGTH * WATER_REGION_EDGE_LENGTH;
22constexpr WaterRegionPatchLabel INVALID_WATER_REGION_PATCH{0};
23
27 struct WaterRegionPatchDesc {
28 int x;
29 int y;
30 WaterRegionPatchLabel label;
31
32 bool operator==(const WaterRegionPatchDesc &other) const { return x == other.x && y == other.y && label == other.label; }
33};
34
35
39 struct WaterRegionDesc {
40 int x;
41 int y;
42
43 WaterRegionDesc(const int x, const int y) : x(x), y(y) {}
44 WaterRegionDesc(const WaterRegionPatchDesc &water_region_patch) : x(water_region_patch.x), y(water_region_patch.y) {}
45
46 bool operator==(const WaterRegionDesc &other) const { return x == other.x && y == other.y; }
47};
48
49int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch);
50
51 TileIndex GetWaterRegionCenterTile(const WaterRegionDesc &water_region);
52
53 WaterRegionDesc GetWaterRegionInfo(TileIndex tile);
54 WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile);
55
56void InvalidateWaterRegion(TileIndex tile);
57
58using VisitWaterRegionPatchCallback = std::function<void(const WaterRegionPatchDesc &)>;
59void VisitWaterRegionPatchNeighbours(const WaterRegionPatchDesc &water_region_patch, VisitWaterRegionPatchCallback &callback);
60
61void AllocateWaterRegions();
62
63void PrintWaterRegionDebugInfo(TileIndex tile);
64
65#endif /* WATER_REGIONS_H */
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
WaterRegionDesc
Describes a single square water region.
Definition water_regions.h:39
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:40
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:41
WaterRegionPatchDesc
Describes a single interconnected patch of water within a particular water region.
Definition water_regions.h:27
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:29
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:28
WaterRegionPatchDesc::label
WaterRegionPatchLabel label
Unique label identifying the patch within the region.
Definition water_regions.h:30
AllocateWaterRegions
void AllocateWaterRegions()
Allocates the appropriate amount of water regions for the current map size.
Definition water_regions.cpp:414
GetWaterRegionInfo
WaterRegionDesc GetWaterRegionInfo(TileIndex tile)
Returns basic water region information for the provided tile.
Definition water_regions.cpp:294
GetWaterRegionPatchInfo
WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile)
Returns basic water region patch information for the provided tile.
Definition water_regions.cpp:303
GetWaterRegionCenterTile
TileIndex GetWaterRegionCenterTile(const WaterRegionDesc &water_region)
Returns the center tile of a particular water region.
Definition water_regions.cpp:285
InvalidateWaterRegion
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
Definition water_regions.cpp:313
CalculateWaterRegionPatchHash
int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch)
Calculates a number that uniquely identifies the provided water region patch.
Definition water_regions.cpp:275
VisitWaterRegionPatchNeighbours
void VisitWaterRegionPatchNeighbours(const WaterRegionPatchDesc &water_region_patch, VisitWaterRegionPatchCallback &callback)
Calls the provided callback function on all accessible water region patches in each cardinal directio...
Definition water_regions.cpp:391