OpenTTD Source 20250529-master-g10c159a79f
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 "../core/strong_typedef_type.hpp"
14#include "../tile_type.h"
15#include "../map_func.h"
16
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
28{
29 int x;
30 int y;
32
33 bool operator==(const WaterRegionPatchDesc &other) const { return x == other.x && y == other.y && label == other.label; }
34};
35
36
41{
42 int x;
43 int y;
44
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) {}
47
48 bool operator==(const WaterRegionDesc &other) const { return x == other.x && y == other.y; }
49};
50
51int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch);
52
54
57
59
60using VisitWaterRegionPatchCallback = std::function<void(const WaterRegionPatchDesc &)>;
61void VisitWaterRegionPatchNeighbours(const WaterRegionPatchDesc &water_region_patch, VisitWaterRegionPatchCallback &callback);
62
64
65void PrintWaterRegionDebugInfo(TileIndex tile);
66
67#endif /* WATER_REGIONS_H */
Templated helper to make a type-safe 'typedef' representing a single POD value.
Describes a single square water region.
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
Describes a single interconnected patch of water within a particular water region.
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
WaterRegionPatchLabel label
Unique label identifying the patch within the region.
void AllocateWaterRegions()
Allocates the appropriate amount of water regions for the current map size.
WaterRegionDesc GetWaterRegionInfo(TileIndex tile)
Returns basic water region information for the provided tile.
WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile)
Returns basic water region patch information for the provided tile.
TileIndex GetWaterRegionCenterTile(const WaterRegionDesc &water_region)
Returns the center tile of a particular water region.
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch)
Calculates a number that uniquely identifies the provided water region patch.
void VisitWaterRegionPatchNeighbours(const WaterRegionPatchDesc &water_region_patch, VisitWaterRegionPatchCallback &callback)
Calls the provided callback function on all accessible water region patches in each cardinal directio...