OpenTTD Source  20240919-master-gdf0233f4c2
water_regions.h File Reference
#include "tile_type.h"
#include "map_func.h"

Go to the source code of this file.

Data Structures

struct  WaterRegionPatchDesc
 Describes a single interconnected patch of water within a particular water region. More...
 
struct  WaterRegionDesc
 Describes a single square water region. More...
 

Typedefs

using TWaterRegionPatchLabel = uint8_t
 
using TWaterRegionIndex = uint
 
using TVisitWaterRegionPatchCallBack = std::function< void(const WaterRegionPatchDesc &)>
 

Functions

TWaterRegionIndex GetWaterRegionIndex (const WaterRegionDesc &water_region)
 Returns the index of the water region. More...
 
int CalculateWaterRegionPatchHash (const WaterRegionPatchDesc &water_region_patch)
 Calculates a number that uniquely identifies the provided water region patch. More...
 
TileIndex GetWaterRegionCenterTile (const WaterRegionDesc &water_region)
 Returns the center tile of a particular water region. More...
 
WaterRegionDesc GetWaterRegionInfo (TileIndex tile)
 Returns basic water region information for the provided tile. More...
 
WaterRegionPatchDesc GetWaterRegionPatchInfo (TileIndex tile)
 Returns basic water region patch information for the provided tile. More...
 
void InvalidateWaterRegion (TileIndex tile)
 Marks the water region that tile is part of as invalid. More...
 
void VisitWaterRegionPatchNeighbors (const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback)
 Calls the provided callback function on all accessible water region patches in each cardinal direction, plus any others that are reachable via aqueducts. More...
 
void AllocateWaterRegions ()
 Allocates the appropriate amount of water regions for the current map size.
 
void PrintWaterRegionDebugInfo (TileIndex tile)
 

Variables

constexpr int WATER_REGION_EDGE_LENGTH = 16
 
constexpr int WATER_REGION_NUMBER_OF_TILES = WATER_REGION_EDGE_LENGTH * WATER_REGION_EDGE_LENGTH
 
constexpr TWaterRegionPatchLabel INVALID_WATER_REGION_PATCH = 0
 

Detailed Description

Handles dividing the water in the map into regions to assist pathfinding.

Definition in file water_regions.h.

Function Documentation

◆ CalculateWaterRegionPatchHash()

int CalculateWaterRegionPatchHash ( const WaterRegionPatchDesc water_region_patch)

Calculates a number that uniquely identifies the provided water region patch.

Parameters
water_region_patchThe Water region to calculate the hash for.

Definition at line 273 of file water_regions.cpp.

References GetWaterRegionIndex(), and WaterRegionPatchDesc::label.

◆ GetWaterRegionCenterTile()

TileIndex GetWaterRegionCenterTile ( const WaterRegionDesc water_region)

Returns the center tile of a particular water region.

Parameters
water_regionThe water region to find the center tile for.
Returns
The center tile of the water region.

Definition at line 283 of file water_regions.cpp.

References TileXY(), and WaterRegionDesc::x.

◆ GetWaterRegionIndex()

TWaterRegionIndex GetWaterRegionIndex ( const WaterRegionDesc water_region)

Returns the index of the water region.

Parameters
water_regionThe water region to return the index for.

Definition at line 264 of file water_regions.cpp.

References GetWaterRegionIndex(), WaterRegionDesc::x, and WaterRegionDesc::y.

Referenced by CalculateWaterRegionPatchHash(), GetWaterRegionIndex(), and InvalidateWaterRegion().

◆ GetWaterRegionInfo()

WaterRegionDesc GetWaterRegionInfo ( TileIndex  tile)

Returns basic water region information for the provided tile.

Parameters
tileThe tile for which the information will be calculated.

Definition at line 292 of file water_regions.cpp.

◆ GetWaterRegionPatchInfo()

WaterRegionPatchDesc GetWaterRegionPatchInfo ( TileIndex  tile)

Returns basic water region patch information for the provided tile.

Parameters
tileThe tile for which the information will be calculated.

Definition at line 301 of file water_regions.cpp.

◆ InvalidateWaterRegion()

void InvalidateWaterRegion ( TileIndex  tile)

Marks the water region that tile is part of as invalid.

Parameters
tileTile within the water region that we wish to invalidate.

Definition at line 311 of file water_regions.cpp.

References GetWaterRegionIndex(), and IsValidTile().

◆ VisitWaterRegionPatchNeighbors()

void VisitWaterRegionPatchNeighbors ( const WaterRegionPatchDesc water_region_patch,
TVisitWaterRegionPatchCallBack &  callback 
)

Calls the provided callback function on all accessible water region patches in each cardinal direction, plus any others that are reachable via aqueducts.

Parameters
water_region_patchWater patch within the water region to start searching from
callbackThe function that will be called for each accessible water patch that is found

Definition at line 388 of file water_regions.cpp.

References WaterRegionPatchDesc::label.