OpenTTD Source  14.0-RC2
water_regions.cpp
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 #include "stdafx.h"
11 #include "map_func.h"
12 #include "water_regions.h"
13 #include "map_func.h"
14 #include "tilearea_type.h"
15 #include "track_func.h"
16 #include "transport_type.h"
17 #include "landscape.h"
18 #include "tunnelbridge_map.h"
19 #include "follow_track.hpp"
20 #include "ship.h"
21 #include "debug.h"
22 
23 using TWaterRegionTraversabilityBits = uint16_t;
24 constexpr TWaterRegionPatchLabel FIRST_REGION_LABEL = 1;
25 
26 static_assert(sizeof(TWaterRegionTraversabilityBits) * 8 == WATER_REGION_EDGE_LENGTH);
27 static_assert(sizeof(TWaterRegionPatchLabel) == sizeof(byte)); // Important for the hash calculation.
28 
29 static inline TrackBits GetWaterTracks(TileIndex tile) { return TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)); }
30 static inline bool IsAqueductTile(TileIndex tile) { return IsBridgeTile(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_WATER; }
31 
32 static inline int GetWaterRegionX(TileIndex tile) { return TileX(tile) / WATER_REGION_EDGE_LENGTH; }
33 static inline int GetWaterRegionY(TileIndex tile) { return TileY(tile) / WATER_REGION_EDGE_LENGTH; }
34 
35 static inline int GetWaterRegionMapSizeX() { return Map::SizeX() / WATER_REGION_EDGE_LENGTH; }
36 static inline int GetWaterRegionMapSizeY() { return Map::SizeY() / WATER_REGION_EDGE_LENGTH; }
37 
38 static inline TWaterRegionIndex GetWaterRegionIndex(int region_x, int region_y) { return GetWaterRegionMapSizeX() * region_y + region_x; }
39 static inline TWaterRegionIndex GetWaterRegionIndex(TileIndex tile) { return GetWaterRegionIndex(GetWaterRegionX(tile), GetWaterRegionY(tile)); }
40 
48 {
49 private:
50  std::array<TWaterRegionTraversabilityBits, DIAGDIR_END> edge_traversability_bits{};
51  bool has_cross_region_aqueducts = false;
52  TWaterRegionPatchLabel number_of_patches = 0; // 0 = no water, 1 = one single patch of water, etc...
53  const OrthogonalTileArea tile_area;
54  std::array<TWaterRegionPatchLabel, WATER_REGION_NUMBER_OF_TILES> tile_patch_labels{};
55  bool initialized = false;
56 
63  inline int GetLocalIndex(TileIndex tile) const
64  {
65  assert(this->tile_area.Contains(tile));
66  return (TileX(tile) - TileX(this->tile_area.tile)) + WATER_REGION_EDGE_LENGTH * (TileY(tile) - TileY(this->tile_area.tile));
67  }
68 
69 public:
70  WaterRegion(int region_x, int region_y)
71  : tile_area(TileXY(region_x * WATER_REGION_EDGE_LENGTH, region_y * WATER_REGION_EDGE_LENGTH), WATER_REGION_EDGE_LENGTH, WATER_REGION_EDGE_LENGTH)
72  {}
73 
74  OrthogonalTileIterator begin() const { return this->tile_area.begin(); }
75  OrthogonalTileIterator end() const { return this->tile_area.end(); }
76 
77  bool IsInitialized() const { return this->initialized; }
78 
79  void Invalidate()
80  {
81  if (!IsInitialized()) Debug(map, 3, "Invalidated water region ({},{})", GetWaterRegionX(this->tile_area.tile), GetWaterRegionY(this->tile_area.tile));
82  this->initialized = false;
83  }
84 
92  TWaterRegionTraversabilityBits GetEdgeTraversabilityBits(DiagDirection side) const { return edge_traversability_bits[side]; }
93 
98  int NumberOfPatches() const { return this->number_of_patches; }
99 
103  bool HasCrossRegionAqueducts() const { return this->has_cross_region_aqueducts; }
104 
110  TWaterRegionPatchLabel GetLabel(TileIndex tile) const
111  {
112  assert(this->tile_area.Contains(tile));
113  return this->tile_patch_labels[GetLocalIndex(tile)];
114  }
115 
120  void ForceUpdate()
121  {
122  Debug(map, 3, "Updating water region ({},{})", GetWaterRegionX(this->tile_area.tile), GetWaterRegionY(this->tile_area.tile));
123  this->has_cross_region_aqueducts = false;
124 
125  this->tile_patch_labels.fill(INVALID_WATER_REGION_PATCH);
126  this->edge_traversability_bits.fill(0);
127 
128  TWaterRegionPatchLabel current_label = 1;
129  TWaterRegionPatchLabel highest_assigned_label = 0;
130 
131  /* Perform connected component labeling. This uses a flooding algorithm that expands until no
132  * additional tiles can be added. Only tiles inside the water region are considered. */
133  for (const TileIndex start_tile : tile_area) {
134  static std::vector<TileIndex> tiles_to_check;
135  tiles_to_check.clear();
136  tiles_to_check.push_back(start_tile);
137 
138  bool increase_label = false;
139  while (!tiles_to_check.empty()) {
140  const TileIndex tile = tiles_to_check.back();
141  tiles_to_check.pop_back();
142 
143  const TrackdirBits valid_dirs = TrackBitsToTrackdirBits(GetWaterTracks(tile));
144  if (valid_dirs == TRACKDIR_BIT_NONE) continue;
145 
146  if (this->tile_patch_labels[GetLocalIndex(tile)] != INVALID_WATER_REGION_PATCH) continue;
147 
148  this->tile_patch_labels[GetLocalIndex(tile)] = current_label;
149  highest_assigned_label = current_label;
150  increase_label = true;
151 
152  for (const Trackdir dir : SetTrackdirBitIterator(valid_dirs)) {
153  /* By using a TrackFollower we "play by the same rules" as the actual ship pathfinder */
155  if (ft.Follow(tile, dir)) {
156  if (this->tile_area.Contains(ft.m_new_tile)) {
157  tiles_to_check.push_back(ft.m_new_tile);
158  } else if (!ft.m_is_bridge) {
159  assert(DistanceManhattan(ft.m_new_tile, tile) == 1);
160  const auto side = DiagdirBetweenTiles(tile, ft.m_new_tile);
161  const int local_x_or_y = DiagDirToAxis(side) == AXIS_X ? TileY(tile) - TileY(this->tile_area.tile) : TileX(tile) - TileX(this->tile_area.tile);
162  SetBit(this->edge_traversability_bits[side], local_x_or_y);
163  } else {
164  this->has_cross_region_aqueducts = true;
165  }
166  }
167  }
168  }
169 
170  if (increase_label) current_label++;
171  }
172 
173  this->number_of_patches = highest_assigned_label;
174  this->initialized = true;
175  }
176 
181  {
182  if (!this->initialized) ForceUpdate();
183  }
184 
185  void PrintDebugInfo()
186  {
187  Debug(map, 9, "Water region {},{} labels and edge traversability = ...", GetWaterRegionX(tile_area.tile), GetWaterRegionY(tile_area.tile));
188 
189  const size_t max_element_width = std::to_string(this->number_of_patches).size();
190 
191  std::array<int, 16> traversability_NW{0};
192  for (auto bitIndex : SetBitIterator(edge_traversability_bits[DIAGDIR_NW])) *(traversability_NW.rbegin() + bitIndex) = 1;
193  Debug(map, 9, " {:{}}", fmt::join(traversability_NW, " "), max_element_width);
194  Debug(map, 9, " +{:->{}}+", "", WATER_REGION_EDGE_LENGTH * (max_element_width + 1) + 1);
195 
196  for (int y = 0; y < WATER_REGION_EDGE_LENGTH; ++y) {
197  std::string line{};
198  for (int x = 0; x < WATER_REGION_EDGE_LENGTH; ++x) {
199  const auto label = this->tile_patch_labels[x + y * WATER_REGION_EDGE_LENGTH];
200  const std::string label_str = label == INVALID_WATER_REGION_PATCH ? "." : std::to_string(label);
201  line = fmt::format("{:{}}", label_str, max_element_width) + " " + line;
202  }
203  Debug(map, 9, "{} | {}| {}", GB(this->edge_traversability_bits[DIAGDIR_SW], y, 1), line, GB(this->edge_traversability_bits[DIAGDIR_NE], y, 1));
204  }
205 
206  Debug(map, 9, " +{:->{}}+", "", WATER_REGION_EDGE_LENGTH * (max_element_width + 1) + 1);
207  std::array<int, 16> traversability_SE{0};
208  for (auto bitIndex : SetBitIterator(edge_traversability_bits[DIAGDIR_SE])) *(traversability_SE.rbegin() + bitIndex) = 1;
209  Debug(map, 9, " {:{}}", fmt::join(traversability_SE, " "), max_element_width);
210  }
211 };
212 
213 std::vector<WaterRegion> _water_regions;
214 
215 TileIndex GetTileIndexFromLocalCoordinate(int region_x, int region_y, int local_x, int local_y)
216 {
217  assert(local_x >= 0 && local_x < WATER_REGION_EDGE_LENGTH);
218  assert(local_y >= 0 && local_y < WATER_REGION_EDGE_LENGTH);
219  return TileXY(WATER_REGION_EDGE_LENGTH * region_x + local_x, WATER_REGION_EDGE_LENGTH * region_y + local_y);
220 }
221 
222 TileIndex GetEdgeTileCoordinate(int region_x, int region_y, DiagDirection side, int x_or_y)
223 {
224  assert(x_or_y >= 0 && x_or_y < WATER_REGION_EDGE_LENGTH);
225  switch (side) {
226  case DIAGDIR_NE: return GetTileIndexFromLocalCoordinate(region_x, region_y, 0, x_or_y);
227  case DIAGDIR_SW: return GetTileIndexFromLocalCoordinate(region_x, region_y, WATER_REGION_EDGE_LENGTH - 1, x_or_y);
228  case DIAGDIR_NW: return GetTileIndexFromLocalCoordinate(region_x, region_y, x_or_y, 0);
229  case DIAGDIR_SE: return GetTileIndexFromLocalCoordinate(region_x, region_y, x_or_y, WATER_REGION_EDGE_LENGTH - 1);
230  default: NOT_REACHED();
231  }
232 }
233 
234 WaterRegion &GetUpdatedWaterRegion(uint16_t region_x, uint16_t region_y)
235 {
236  WaterRegion &result = _water_regions[GetWaterRegionIndex(region_x, region_y)];
237  result.UpdateIfNotInitialized();
238  return result;
239 }
240 
241 WaterRegion &GetUpdatedWaterRegion(TileIndex tile)
242 {
243  WaterRegion &result = _water_regions[GetWaterRegionIndex(tile)];
244  result.UpdateIfNotInitialized();
245  return result;
246 }
247 
252 TWaterRegionIndex GetWaterRegionIndex(const WaterRegionDesc &water_region)
253 {
254  return GetWaterRegionIndex(water_region.x, water_region.y);
255 }
256 
262 {
263  return water_region_patch.label | GetWaterRegionIndex(water_region_patch) << 8;
264 }
265 
272 {
273  return TileXY(water_region.x * WATER_REGION_EDGE_LENGTH + (WATER_REGION_EDGE_LENGTH / 2), water_region.y * WATER_REGION_EDGE_LENGTH + (WATER_REGION_EDGE_LENGTH / 2));
274 }
275 
281 {
282  return WaterRegionDesc{ GetWaterRegionX(tile), GetWaterRegionY(tile) };
283 }
284 
290 {
291  WaterRegion &region = GetUpdatedWaterRegion(tile);
292  return WaterRegionPatchDesc{ GetWaterRegionX(tile), GetWaterRegionY(tile), region.GetLabel(tile)};
293 }
294 
300 {
301  if (!IsValidTile(tile)) return;
302  const int water_region_index = GetWaterRegionIndex(tile);
303  _water_regions[water_region_index].Invalidate();
304 
305  /* When updating the water region we look into the first tile of adjacent water regions to determine edge
306  * traversability. This means that if we invalidate any region edge tiles we might also change the traversability
307  * of the adjacent region. This code ensures the adjacent regions also get invalidated in such a case. */
308  for (DiagDirection side = DIAGDIR_BEGIN; side < DIAGDIR_END; side++) {
309  const int adjacent_region_index = GetWaterRegionIndex(TileAddByDiagDir(tile, side));
310  if (adjacent_region_index != water_region_index) _water_regions[adjacent_region_index].Invalidate();
311  }
312 }
313 
321 static inline void VisitAdjacentWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, DiagDirection side, TVisitWaterRegionPatchCallBack &func)
322 {
323  if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return;
324 
325  const WaterRegion &current_region = GetUpdatedWaterRegion(water_region_patch.x, water_region_patch.y);
326 
327  const TileIndexDiffC offset = TileIndexDiffCByDiagDir(side);
328  const int nx = water_region_patch.x + offset.x;
329  const int ny = water_region_patch.y + offset.y;
330 
331  if (nx < 0 || ny < 0 || nx >= GetWaterRegionMapSizeX() || ny >= GetWaterRegionMapSizeY()) return;
332 
333  const WaterRegion &neighboring_region = GetUpdatedWaterRegion(nx, ny);
334  const DiagDirection opposite_side = ReverseDiagDir(side);
335 
336  /* Indicates via which local x or y coordinates (depends on the "side" parameter) we can cross over into the adjacent region. */
337  const TWaterRegionTraversabilityBits traversability_bits = current_region.GetEdgeTraversabilityBits(side)
338  & neighboring_region.GetEdgeTraversabilityBits(opposite_side);
339  if (traversability_bits == 0) return;
340 
341  if (current_region.NumberOfPatches() == 1 && neighboring_region.NumberOfPatches() == 1) {
342  func(WaterRegionPatchDesc{ nx, ny, FIRST_REGION_LABEL }); // No further checks needed because we know there is just one patch for both adjacent regions
343  return;
344  }
345 
346  /* Multiple water patches can be reached from the current patch. Check each edge tile individually. */
347  static std::vector<TWaterRegionPatchLabel> unique_labels; // static and vector-instead-of-map for performance reasons
348  unique_labels.clear();
349  for (int x_or_y = 0; x_or_y < WATER_REGION_EDGE_LENGTH; ++x_or_y) {
350  if (!HasBit(traversability_bits, x_or_y)) continue;
351 
352  const TileIndex current_edge_tile = GetEdgeTileCoordinate(water_region_patch.x, water_region_patch.y, side, x_or_y);
353  const TWaterRegionPatchLabel current_label = current_region.GetLabel(current_edge_tile);
354  if (current_label != water_region_patch.label) continue;
355 
356  const TileIndex neighbor_edge_tile = GetEdgeTileCoordinate(nx, ny, opposite_side, x_or_y);
357  const TWaterRegionPatchLabel neighbor_label = neighboring_region.GetLabel(neighbor_edge_tile);
358  assert(neighbor_label != INVALID_WATER_REGION_PATCH);
359  if (std::find(unique_labels.begin(), unique_labels.end(), neighbor_label) == unique_labels.end()) unique_labels.push_back(neighbor_label);
360  }
361  for (TWaterRegionPatchLabel unique_label : unique_labels) func(WaterRegionPatchDesc{ nx, ny, unique_label });
362 }
363 
370 void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback)
371 {
372  if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return;
373 
374  const WaterRegion &current_region = GetUpdatedWaterRegion(water_region_patch.x, water_region_patch.y);
375 
376  /* Visit adjacent water region patches in each cardinal direction */
377  for (DiagDirection side = DIAGDIR_BEGIN; side < DIAGDIR_END; side++) VisitAdjacentWaterRegionPatchNeighbors(water_region_patch, side, callback);
378 
379  /* Visit neigboring water patches accessible via cross-region aqueducts */
380  if (current_region.HasCrossRegionAqueducts()) {
381  for (const TileIndex tile : current_region) {
382  if (GetWaterRegionPatchInfo(tile) == water_region_patch && IsAqueductTile(tile)) {
383  const TileIndex other_end_tile = GetOtherBridgeEnd(tile);
384  if (GetWaterRegionIndex(tile) != GetWaterRegionIndex(other_end_tile)) callback(GetWaterRegionPatchInfo(other_end_tile));
385  }
386  }
387  }
388 }
389 
394 {
395  _water_regions.clear();
396  _water_regions.reserve(static_cast<size_t>(GetWaterRegionMapSizeX()) * GetWaterRegionMapSizeY());
397 
398  Debug(map, 2, "Allocating {} x {} water regions", GetWaterRegionMapSizeX(), GetWaterRegionMapSizeY());
399 
400  for (int region_y = 0; region_y < GetWaterRegionMapSizeY(); region_y++) {
401  for (int region_x = 0; region_x < GetWaterRegionMapSizeX(); region_x++) {
402  _water_regions.emplace_back(region_x, region_y);
403  }
404  }
405 }
406 
407 void PrintWaterRegionDebugInfo(TileIndex tile)
408 {
409  GetUpdatedWaterRegion(tile).PrintDebugInfo();
410 }
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
TileIndexDiffCByDiagDir
TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
Returns the TileIndexDiffC offset from a DiagDirection.
Definition: map_func.h:490
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:76
transport_type.h
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:59
WaterRegion::ForceUpdate
void ForceUpdate()
Performs the connected component labeling and other data gathering.
Definition: water_regions.cpp:120
WaterRegionPatchDesc
Describes a single interconnected patch of water within a particular water region.
Definition: water_regions.h:26
tunnelbridge_map.h
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
WaterRegion::UpdateIfNotInitialized
void UpdateIfNotInitialized()
Updates the patch labels and other data, but only if the region is not yet initialized.
Definition: water_regions.cpp:180
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:79
map_func.h
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
ship.h
WaterRegionPatchDesc::y
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
Definition: water_regions.h:29
GetWaterRegionCenterTile
TileIndex GetWaterRegionCenterTile(const WaterRegionDesc &water_region)
Returns the center tile of a particular water region.
Definition: water_regions.cpp:271
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:78
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
CFollowTrackT::m_is_bridge
bool m_is_bridge
last turn passed bridge ramp
Definition: follow_track.hpp:47
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:556
OrthogonalTileIterator
Iterator to iterate over a tile area (rectangle) of the map.
Definition: tilearea_type.h:185
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:77
GetWaterRegionPatchInfo
WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile)
Returns basic water region patch information for the provided tile.
Definition: water_regions.cpp:289
GetWaterRegionInfo
WaterRegionDesc GetWaterRegionInfo(TileIndex tile)
Returns basic water region information for the provided tile.
Definition: water_regions.cpp:280
TrackBitsToTrackdirBits
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:319
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:282
WaterRegion
Represents a square section of the map of a fixed size.
Definition: water_regions.cpp:47
WaterRegion::GetLocalIndex
int GetLocalIndex(TileIndex tile) const
Returns the local index of the tile within the region.
Definition: water_regions.cpp:63
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:99
OrthogonalTileArea::begin
OrthogonalTileIterator begin() const
Returns an iterator to the beginning of the tile area.
Definition: tilearea.cpp:153
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
water_regions.h
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
follow_track.hpp
VisitWaterRegionPatchNeighbors
void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback)
Calls the provided callback function on all accessible water region patches in each cardinal directio...
Definition: water_regions.cpp:370
OrthogonalTileArea::end
OrthogonalTileIterator end() const
Returns an iterator to the end of the tile area.
Definition: tilearea.cpp:162
WaterRegion::GetEdgeTraversabilityBits
TWaterRegionTraversabilityBits GetEdgeTraversabilityBits(DiagDirection side) const
Returns a set of bits indicating whether an edge tile on a particular side is traversable or not.
Definition: water_regions.cpp:92
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
TrackStatusToTrackBits
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:363
stdafx.h
WaterRegionDesc
Describes a single square water region.
Definition: water_regions.h:40
landscape.h
CalculateWaterRegionPatchHash
int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch)
Calculates a number that uniquely identifies the provided water region patch.
Definition: water_regions.cpp:261
WaterRegionDesc::y
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
Definition: water_regions.h:43
GetWaterRegionIndex
TWaterRegionIndex GetWaterRegionIndex(const WaterRegionDesc &water_region)
Returns the index of the water region.
Definition: water_regions.cpp:252
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:31
Map::SizeX
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition: map_func.h:270
tilearea_type.h
DiagdirBetweenTiles
DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
Determines the DiagDirection to get from one tile to another.
Definition: map_func.h:616
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
GetTunnelBridgeTransportType
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:39
InvalidateWaterRegion
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
Definition: water_regions.cpp:299
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:74
track_func.h
AllocateWaterRegions
void AllocateWaterRegions()
Allocates the appropriate amount of water regions for the current map size.
Definition: water_regions.cpp:393
CFollowTrackT::m_new_tile
TileIndex m_new_tile
the new tile (the vehicle has entered)
Definition: follow_track.hpp:43
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:117
TileIndexDiffC::y
int16_t y
The y value of the coordinate.
Definition: map_type.h:33
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
WaterRegionPatchDesc::label
TWaterRegionPatchLabel label
Unique label identifying the patch within the region.
Definition: water_regions.h:30
CFollowTrackT::Follow
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
Definition: follow_track.hpp:119
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
WaterRegion::GetLabel
TWaterRegionPatchLabel GetLabel(TileIndex tile) const
Returns the patch label that was assigned to the tile.
Definition: water_regions.cpp:110
WaterRegionDesc::x
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
Definition: water_regions.h:42
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition: track_type.h:98
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
VisitAdjacentWaterRegionPatchNeighbors
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...
Definition: water_regions.cpp:321
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:75
WaterRegion::HasCrossRegionAqueducts
bool HasCrossRegionAqueducts() const
Definition: water_regions.cpp:103
TileAddByDiagDir
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:604
TileIndexDiffC::x
int16_t x
The x value of the coordinate.
Definition: map_type.h:32
WaterRegion::NumberOfPatches
int NumberOfPatches() const
Definition: water_regions.cpp:98
CFollowTrackT
Track follower helper template class (can serve pathfinders and vehicle controllers).
Definition: follow_track.hpp:28
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition: map_func.h:279
OrthogonalTileArea::Contains
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
Definition: tilearea.cpp:104
debug.h
WaterRegionPatchDesc::x
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
Definition: water_regions.h:28
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103