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

OpenTTD Source 14.1

Data Structures | Typedefs | Functions | Variables
water_regions.cpp File Reference
`#include "stdafx.h"`
`#include "map_func.h"`
`#include "water_regions.h"`
`#include "tilearea_type.h"`
`#include "track_func.h"`
`#include "transport_type.h"`
`#include "landscape.h"`
`#include "tunnelbridge_map.h"`
`#include "follow_track.hpp"`
`#include "ship.h"`
`#include "debug.h"`

Go to the source code of this file.

## Data Structures
class | WaterRegion
| Represents a square section of the map of a fixed size. More...

## Typedefs
using | TWaterRegionTraversabilityBits = uint16_t
using | TWaterRegionPatchLabelArray = std::array< TWaterRegionPatchLabel, WATER_REGION_NUMBER_OF_TILES >

## Functions
static TrackBits | GetWaterTracks (TileIndex tile)
static bool | IsAqueductTile (TileIndex tile)
static int | GetWaterRegionX (TileIndex tile)
static int | GetWaterRegionY (TileIndex tile)
static int | GetWaterRegionMapSizeX ()
static int | GetWaterRegionMapSizeY ()
static TWaterRegionIndex | GetWaterRegionIndex (int region_x, int region_y)
static TWaterRegionIndex | GetWaterRegionIndex (TileIndex tile)
TileIndex | GetTileIndexFromLocalCoordinate (int region_x, int region_y, int local_x, int local_y)
TileIndex | GetEdgeTileCoordinate (int region_x, int region_y, DiagDirection side, int x_or_y)
WaterRegion & | GetUpdatedWaterRegion (uint16_t region_x, uint16_t region_y)
WaterRegion & | GetUpdatedWaterRegion (TileIndex tile)
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...
static void | VisitAdjacentWaterRegionPatchNeighbors (const WaterRegionPatchDesc &water_region_patch, DiagDirection side, TVisitWaterRegionPatchCallBack &func)
| Calls the provided callback function for all water region patches accessible from one particular side of the starting patch. 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 TWaterRegionPatchLabel | FIRST_REGION_LABEL = 1
std::vector< WaterRegion > | _water_regions

## Detailed Description

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

Definition in file water_regions.cpp.

## Function Documentation

## ◆ 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 278 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_region | The water region to find the center tile for.

Returns
  The center tile of the water region.

Definition at line 288 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_region | The water region to return the index for.

Definition at line 269 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

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

Definition at line 297 of file water_regions.cpp.

## ◆ 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 306 of file water_regions.cpp.

## ◆ 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 316 of file water_regions.cpp.

References GetWaterRegionIndex(), and IsValidTile().

## ◆ VisitAdjacentWaterRegionPatchNeighbors()

static void VisitAdjacentWaterRegionPatchNeighbors | ( | const WaterRegionPatchDesc & | water_region_patch,
|  | DiagDirection | side,
|  | TVisitWaterRegionPatchCallBack & | func
| ) |  |
| inlinestatic

Calls the provided callback function for all water region patches accessible from one particular side of the starting patch.

Parameters

  water_region_patch | Water patch within the water region to start searching from
  side | Side of the water region to look for neigboring patches of water
  callback | The function that will be called for each neighbor that is found

Definition at line 338 of file water_regions.cpp.

References WaterRegionPatchDesc::label.

## ◆ 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 387 of file water_regions.cpp.

References WaterRegionPatchDesc::label.