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

OpenTTD Source 15.0-beta1

Data Structures | Typedefs | Functions | Variables
water_regions.h File Reference

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

`#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
int | CalculateWaterRegionPatchHash (const WaterRegionPatchDesc &water_region_patch)
| Calculates a number that uniquely identifies the provided water region patch.
TileIndex | GetWaterRegionCenterTile (const WaterRegionDesc &water_region)
| Returns the center tile of a particular water region.
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.
void | InvalidateWaterRegion (TileIndex tile)
| Marks the water region that tile is part of as invalid.
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.
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.

## Typedef Documentation

## ◆ TVisitWaterRegionPatchCallBack

using TVisitWaterRegionPatchCallBack = std::function<void(const WaterRegionPatchDesc &)>

Definition at line 61 of file water_regions.h.

## ◆ TWaterRegionIndex

using TWaterRegionIndex = uint

Definition at line 17 of file water_regions.h.

## ◆ TWaterRegionPatchLabel

using TWaterRegionPatchLabel = uint8_t

Definition at line 16 of file water_regions.h.

## Function Documentation

## ◆ AllocateWaterRegions()

void AllocateWaterRegions | ( |  | ) |

Allocates the appropriate amount of water regions for the current map size.

Definition at line 409 of file water_regions.cpp.

References Debug.

Referenced by Map::Allocate().

## ◆ CalculateWaterRegionPatchHash()

int CalculateWaterRegionPatchHash | ( | const WaterRegionPatchDesc & | water_region_patch | ) |

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

Parameters

  water_region_patch | The Water region to calculate the hash for.

Definition at line 270 of file water_regions.cpp.

References WaterRegionPatchDesc::label.

## ◆ GetWaterRegionCenterTile()

TileIndex GetWaterRegionCenterTile | ( | const WaterRegionDesc & | water_region | ) |

Returns the center tile of a particular water region.

Parameters

  water_region | The water region to find the center tile for.

Returns
  The center tile of the water region.

Definition at line 280 of file water_regions.cpp.

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

## ◆ GetWaterRegionInfo()

WaterRegionDesc GetWaterRegionInfo | ( | TileIndex | tile | ) |

Returns basic water region information for the provided tile.

Parameters

  tile | The tile for which the information will be calculated.

Definition at line 289 of file water_regions.cpp.

Referenced by CYapfFollowShipT< Types >::PfFollowNode().

## ◆ GetWaterRegionPatchInfo()

WaterRegionPatchDesc GetWaterRegionPatchInfo | ( | TileIndex | tile | ) |

Returns basic water region patch information for the provided tile.

Parameters

  tile | The tile for which the information will be calculated.

Definition at line 298 of file water_regions.cpp.

References WaterRegion::GetLabel().

Referenced by VisitWaterRegionPatchNeighbors().

## ◆ InvalidateWaterRegion()

void InvalidateWaterRegion | ( | TileIndex | tile | ) |

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

Parameters

  tile | Tile within the water region that we wish to invalidate.

Definition at line 308 of file water_regions.cpp.

References AddTileIndexDiffCWrap(), Debug, DIAGDIR_BEGIN, DIAGDIR_END, INVALID_TILE, IsValidTile(), and TileIndexDiffCByDiagDir().

Referenced by BuildObject(), and DoBuildLock().

## ◆ PrintWaterRegionDebugInfo()

void PrintWaterRegionDebugInfo | ( | TileIndex | tile | ) |

Definition at line 423 of file water_regions.cpp.

## ◆ 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_patch | Water patch within the water region to start searching from
  callback | The function that will be called for each accessible water patch that is found

Definition at line 386 of file water_regions.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, GetOtherBridgeEnd(), GetWaterRegionPatchInfo(), WaterRegion::HasCrossRegionAqueducts(), WaterRegionPatchDesc::label, VisitAdjacentWaterRegionPatchNeighbors(), WaterRegionPatchDesc::x, and WaterRegionPatchDesc::y.

## Variable Documentation

## ◆ INVALID_WATER_REGION_PATCH

constexpr TWaterRegionPatchLabel INVALID_WATER_REGION_PATCH = 0
| constexpr

Definition at line 21 of file water_regions.h.

## ◆ WATER_REGION_EDGE_LENGTH

constexpr int WATER_REGION_EDGE_LENGTH = 16
| constexpr

Definition at line 19 of file water_regions.h.

## ◆ WATER_REGION_NUMBER_OF_TILES

constexpr int WATER_REGION_NUMBER_OF_TILES = WATER_REGION_EDGE_LENGTH * WATER_REGION_EDGE_LENGTH
| constexpr

Definition at line 20 of file water_regions.h.