OpenTTD Source: WaterRegion Class Reference

OpenTTD Source 15.3

Public Member Functions | Private Member Functions | Private Attributes
WaterRegion Class Reference

Represents a square section of the map of a fixed size. More...

## Public Member Functions
| WaterRegion (int region_x, int region_y, WaterRegionData &water_region_data)
OrthogonalTileIterator | begin () const
OrthogonalTileIterator | end () const
WaterRegionTraversabilityBits | GetEdgeTraversabilityBits (DiagDirection side) const
| Returns a set of bits indicating whether an edge tile on a particular side is traversable or not.
int | NumberOfPatches () const
bool | HasCrossRegionAqueducts () const
WaterRegionPatchLabel | GetLabel (TileIndex tile) const
| Returns the patch label that was assigned to the tile.
void | ForceUpdate ()
| Performs the connected component labeling and other data gathering.
void | PrintDebugInfo ()

## Private Member Functions
int | GetLocalIndex (TileIndex tile) const
| Returns the local index of the tile within the region.

## Private Attributes
WaterRegionData & | data
const OrthogonalTileArea | tile_area

## Detailed Description

Represents a square section of the map of a fixed size.

Within this square individual unconnected patches of water are identified using a Connected Component Labeling (CCL) algorithm. Note that all information stored in this class applies only to tiles within the square section, there is no knowledge about the rest of the map. This makes it easy to invalidate and update a water region if any changes are made to it, such as construction or terraforming.

Definition at line 63 of file water_regions.cpp.

## Constructor & Destructor Documentation

## ◆ WaterRegion()

WaterRegion::WaterRegion | ( | int | region_x,
|  | int | region_y,
|  | WaterRegionData & | water_region_data
| ) |  |
| inline

Definition at line 81 of file water_regions.cpp.

## Member Function Documentation

## ◆ begin()

OrthogonalTileIterator WaterRegion::begin | ( |  | ) | const
| inline

Definition at line 86 of file water_regions.cpp.

## ◆ end()

OrthogonalTileIterator WaterRegion::end | ( |  | ) | const
| inline

Definition at line 87 of file water_regions.cpp.

## ◆ ForceUpdate()

void WaterRegion::ForceUpdate | ( |  | ) |
| inline

Performs the connected component labeling and other data gathering.

See also
  WaterRegion

Definition at line 127 of file water_regions.cpp.

References AXIS_X, OrthogonalTileArea::Contains(), Debug, DiagdirBetweenTiles(), DiagDirToAxis(), DistanceManhattan(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetLocalIndex(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::is_bridge, CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::new_tile, NumberOfPatches(), SetBit(), OrthogonalTileArea::tile, TileX(), TileY(), TrackBitsToTrackdirBits(), and TRACKDIR_BIT_NONE.

## ◆ GetEdgeTraversabilityBits()

WaterRegionTraversabilityBits WaterRegion::GetEdgeTraversabilityBits | ( | DiagDirection | side | ) | const
| inline

Returns a set of bits indicating whether an edge tile on a particular side is traversable or not.

These values can be used to determine whether a ship can enter/leave the region through a particular edge tile.

See also
  GetLocalIndex() for a description of the coordinate system used.

Parameters

  side | Which side of the region we want to know the edge traversability of.

Returns
  A value holding the edge traversability bits.

Definition at line 96 of file water_regions.cpp.

Referenced by VisitAdjacentWaterRegionPatchNeighbours().

## ◆ GetLabel()

WaterRegionPatchLabel WaterRegion::GetLabel | ( | TileIndex | tile | ) | const
| inline

Returns the patch label that was assigned to the tile.

Parameters

  tile | The tile of which we want to retrieve the label.

Returns
  The label assigned to the tile.

Definition at line 114 of file water_regions.cpp.

References OrthogonalTileArea::Contains(), GetLocalIndex(), and NumberOfPatches().

Referenced by GetWaterRegionPatchInfo(), and VisitAdjacentWaterRegionPatchNeighbours().

## ◆ GetLocalIndex()

int WaterRegion::GetLocalIndex | ( | TileIndex | tile | ) | const
| inlineprivate

Returns the local index of the tile within the region.

The N corner represents 0, the x direction is positive in the SW direction, and Y is positive in the SE direction.

Parameters

  tile | Tile within the water region.

Returns
  The local index.

Definition at line 74 of file water_regions.cpp.

References OrthogonalTileArea::Contains(), OrthogonalTileArea::tile, TileX(), and TileY().

Referenced by ForceUpdate(), and GetLabel().

## ◆ HasCrossRegionAqueducts()

bool WaterRegion::HasCrossRegionAqueducts | ( |  | ) | const
| inline

Returns
  Whether the water region contains aqueducts that cross the region boundaries.

Definition at line 107 of file water_regions.cpp.

Referenced by VisitWaterRegionPatchNeighbours().

## ◆ NumberOfPatches()

int WaterRegion::NumberOfPatches | ( |  | ) | const
| inline

Returns
  The amount of individual water patches present within the water region. A value of 0 means there is no water present in the water region at all.

Definition at line 102 of file water_regions.cpp.

Referenced by ForceUpdate(), GetLabel(), and VisitAdjacentWaterRegionPatchNeighbours().

## ◆ PrintDebugInfo()

void WaterRegion::PrintDebugInfo | ( |  | ) |
| inline

Definition at line 195 of file water_regions.cpp.

## Field Documentation

## ◆ data

WaterRegionData& WaterRegion::data
| private

Definition at line 65 of file water_regions.cpp.

## ◆ tile_area

const OrthogonalTileArea WaterRegion::tile_area
| private

Definition at line 66 of file water_regions.cpp.

The documentation for this class was generated from the following file:

- src/pathfinder/water_regions.cpp