OpenTTD Source: src/map_func.h File Reference

OpenTTD Source 12.0-beta1

Macros | Typedefs | Functions | Variables
map_func.h File Reference
`#include "core/math_func.hpp"`
`#include "tile_type.h"`
`#include "map_type.h"`
`#include "direction_func.h"`

Go to the source code of this file.

## Macros
#define | TILE_MASK(x) ((x) & _map_tile_mask)
| 'Wraps' the given tile to it is within the map. More...
#define | TILE_ADD(x, y) ((x) + (y))
| Adds to tiles together. More...
#define | TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y))
| Adds a given offset to a tile. More...
#define | RandomTile() RandomTileSeed(Random())
| Get a valid random tile. More...

## Typedefs
typedef int32 | TileIndexDiff
| An offset value between to tiles. More...
typedef bool | TestTileOnSearchProc(TileIndex tile, void *user_data)
| A callback function type for searching tiles. More...

## Functions
void | AllocateMap (uint size_x, uint size_y)
| (Re)allocates a map with the given dimension More...
static uint | MapLogX ()
| Logarithm of the map size along the X side. More...
static uint | MapLogY ()
| Logarithm of the map size along the y side. More...
static uint | MapSizeX ()
| Get the size of the map along the X. More...
static uint | MapSizeY ()
| Get the size of the map along the Y. More...
static uint | MapSize ()
| Get the size of the map. More...
static uint | MapMaxX ()
| Gets the maximum X coordinate within the map, including MP_VOID. More...
static uint | MapMaxY ()
| Gets the maximum Y coordinate within the map, including MP_VOID. More...
static uint | ScaleByMapSize (uint n)
| Scales the given value by the map size, where the given value is for a 256 by 256 map. More...
static uint | ScaleByMapSize1D (uint n)
| Scales the given value by the maps circumference, where the given value is for a 256 by 256 map. More...
static TileIndex | TileXY (uint x, uint y)
| Returns the TileIndex of a coordinate. More...
static TileIndexDiff | TileDiffXY (int x, int y)
| Calculates an offset for the given coordinate(-offset). More...
static TileIndex | TileVirtXY (uint x, uint y)
| Get a tile from the virtual XY-coordinate. More...
static uint | TileX (TileIndex tile)
| Get the X component of a tile. More...
static uint | TileY (TileIndex tile)
| Get the Y component of a tile. More...
static TileIndexDiff | ToTileIndexDiff (TileIndexDiffC tidc)
| Return the offset between to tiles from a TileIndexDiffC struct. More...
TileIndex | TileAddWrap (TileIndex tile, int addx, int addy)
| This function checks if we add addx/addy to tile, if we do wrap around the edges. More...
static TileIndexDiffC | TileIndexDiffCByDiagDir (DiagDirection dir)
| Returns the TileIndexDiffC offset from a DiagDirection. More...
static TileIndexDiffC | TileIndexDiffCByDir (Direction dir)
| Returns the TileIndexDiffC offset from a Direction. More...
static TileIndex | AddTileIndexDiffCWrap (TileIndex tile, TileIndexDiffC diff)
| Add a TileIndexDiffC to a TileIndex and returns the new one. More...
static TileIndexDiffC | TileIndexToTileIndexDiffC (TileIndex tile_a, TileIndex tile_b)
| Returns the diff between two tiles. More...
uint | DistanceManhattan (TileIndex, TileIndex)
| also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads) More...
uint | DistanceSquare (TileIndex, TileIndex)
| euclidian- or L2-Norm squared More...
uint | DistanceMax (TileIndex, TileIndex)
| also known as L-Infinity-Norm More...
uint | DistanceMaxPlusManhattan (TileIndex, TileIndex)
| Max + Manhattan. More...
uint | DistanceFromEdge (TileIndex)
| shortest distance from any edge of the map More...
uint | DistanceFromEdgeDir (TileIndex, DiagDirection)
| distance from the map edge in given direction More...
static TileIndexDiff | TileOffsByDiagDir (DiagDirection dir)
| Convert a DiagDirection to a TileIndexDiff. More...
static TileIndexDiff | TileOffsByDir (Direction dir)
| Convert a Direction to a TileIndexDiff. More...
static TileIndex | TileAddByDir (TileIndex tile, Direction dir)
| Adds a Direction to a tile. More...
static TileIndex | TileAddByDiagDir (TileIndex tile, DiagDirection dir)
| Adds a DiagDir to a tile. More...
static DiagDirection | DiagdirBetweenTiles (TileIndex tile_from, TileIndex tile_to)
| Determines the DiagDirection to get from one tile to another. More...
bool | CircularTileSearch (TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
| Function performing a search around a center tile and going outward, thus in circle. More...
bool | CircularTileSearch (TileIndex *tile, uint radius, uint w, uint h, TestTileOnSearchProc proc, void *user_data)
| Generalized circular search allowing for rectangles and a hole. More...
static TileIndex | RandomTileSeed (uint32 r)
| Get a random tile out of a given seed. More...
uint | GetClosestWaterDistance (TileIndex tile, bool water)
| Finds the distance for the closest tile with water/land given a tile. More...

## Variables
uint | _map_tile_mask
| _map_size - 1 (to mask the mapsize)
Tile * | _m
| Pointer to the tile-array. More...
TileExtended * | _me
| Pointer to the extended tile-array. More...

## Detailed Description

Functions related to maps.

Definition in file map_func.h.

## Macro Definition Documentation

## ◆ RandomTile

#define RandomTile | ( |  | ) | RandomTileSeed(Random())

Get a valid random tile.

Note
  a define so 'random' gets inserted in the place where it is actually called, thus making the random traces more explicit.

Returns
  a valid tile

Definition at line 435 of file map_func.h.

## ◆ TILE_ADD

#define TILE_ADD | ( |  | x,
|  |  | y
| ) |  | ((x) + (y))

Adds to tiles together.

Parameters

  x | One tile
  y | Another tile to add

Returns
  The resulting tile(index)

Definition at line 244 of file map_func.h.

## ◆ TILE_ADDXY

#define TILE_ADDXY | ( |  | tile,
|  |  | x,
|  |  | y
| ) |  | TILE_ADD(tile, TileDiffXY(x, y))

Adds a given offset to a tile.

Parameters

  tile | The tile to add an offset on it
  x | The x offset to add to the tile
  y | The y offset to add to the tile

Definition at line 258 of file map_func.h.

## ◆ TILE_MASK

#define TILE_MASK | ( |  | x | ) | ((x) & _map_tile_mask)

'Wraps' the given tile to it is within the map.

It does this by masking the 'high' bits of.

Parameters

  x | the tile to 'wrap'

Definition at line 26 of file map_func.h.

## Typedef Documentation

## ◆ TestTileOnSearchProc

typedef bool TestTileOnSearchProc(TileIndex tile, void *user_data)

A callback function type for searching tiles.

Parameters

  tile | The tile to test
  user_data | additional data for the callback function to use

Returns
  A boolean value, depend on the definition of the function.

Definition at line 414 of file map_func.h.

## ◆ TileIndexDiff

typedef int32 TileIndexDiff

An offset value between to tiles.

This value is used for the difference between two tiles. It can be added to a tileindex to get the resulting tileindex of the start tile applied with this saved difference.

See also
  TileDiffXY(int, int)

Definition at line 154 of file map_func.h.

## Function Documentation

## ◆ AddTileIndexDiffCWrap()

static TileIndex AddTileIndexDiffCWrap | ( | TileIndex | tile,
|  | TileIndexDiffC | diff
| ) |  |
| inlinestatic

Add a TileIndexDiffC to a TileIndex and returns the new one.

Returns tile + the diff given in diff. If the result tile would end up outside of the map, INVALID_TILE is returned instead.

Parameters

  tile | The base tile to add the offset on
  diff | The offset to add on the tile

Returns
  The resulting TileIndex

Definition at line 300 of file map_func.h.

Referenced by CalculateCoverageLine().

## ◆ AllocateMap()

void AllocateMap | ( | uint | size_x,
|  | uint | size_y
| ) |  |

(Re)allocates a map with the given dimension

Parameters

  size_x | the width of the map along the NE/SW edge
  size_y | the 'height' of the map along the SE/NW edge

Definition at line 39 of file map.cpp.

References _m, _map_log_x, _map_log_y, _map_size, _map_size_x, _map_size_y, _map_tile_mask, _me, Debug, error(), FindFirstBit(), free(), IsInsideMM(), MAX_MAP_SIZE, and MIN_MAP_SIZE.

## ◆ CircularTileSearch() [1/2]

bool CircularTileSearch | ( | TileIndex * | tile,
|  | uint | radius,
|  | uint | w,
|  | uint | h,
|  | TestTileOnSearchProc | proc,
|  | void * | user_data
| ) |  |

Generalized circular search allowing for rectangles and a hole.

Function performing a search around a center rectangle and going outward. The center rectangle is left out from the search. To do a rectangular search without a hole, set either h or w to zero. Every tile will be tested by means of the callback function proc, which will determine if yes or no the given tile meets criteria of search.

Parameters

  tile | to start the search from. Upon completion, it will return the tile matching the search. This tile should be directly north of the hole (if any).
  radius | How many tiles to search outwards. Note: This is a radius and thus different from the size parameter of the other CircularTileSearch function, which is a diameter.
  w | the width of the inner rectangle
  h | the height of the inner rectangle
  proc | callback testing function pointer.
  user_data | to be passed to the callback function. Depends on the implementation

Returns
  result of the search

Precondition
  proc != nullptr
  radius > 0

Definition at line 296 of file map.cpp.

## ◆ CircularTileSearch() [2/2]

bool CircularTileSearch | ( | TileIndex * | tile,
|  | uint | size,
|  | TestTileOnSearchProc | proc,
|  | void * | user_data
| ) |  |

Function performing a search around a center tile and going outward, thus in circle.

Although it really is a square search... Every tile will be tested by means of the callback function proc, which will determine if yes or no the given tile meets criteria of search.

Parameters

  tile | to start the search from. Upon completion, it will return the tile matching the search
  size | number of tiles per side of the desired search area
  proc | callback testing function pointer.
  user_data | to be passed to the callback function. Depends on the implementation

Returns
  result of the search

Precondition
  proc != nullptr
  size > 0

Definition at line 258 of file map.cpp.

References CircularTileSearch(), DIR_N, and TileAddByDir().

Referenced by ChopLumberMillTrees(), CircularTileSearch(), CreateRivers(), FindNearestGoodCoastalTownSpot(), GetDistanceFromNearbyHouse(), TownActionBuildStatue(), and TryBuildTransmitter().

## ◆ DiagdirBetweenTiles()

static DiagDirection DiagdirBetweenTiles | ( | TileIndex | tile_from,
|  | TileIndex | tile_to
| ) |  |
| inlinestatic

Determines the DiagDirection to get from one tile to another.

The tiles do not necessarily have to be adjacent.

Parameters

  tile_from | Origin tile
  tile_to | Destination tile

Returns
  DiagDirection from tile_from towards tile_to, or INVALID_DIAGDIR if the tiles are not on an axis

Definition at line 394 of file map_func.h.

References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, INVALID_DIAGDIR, TileX(), and TileY().

Referenced by TrainController().

## ◆ DistanceFromEdge()

uint DistanceFromEdge | ( | TileIndex | tile | ) |

shortest distance from any edge of the map

shortest distance from any edge of the map

Parameters

  tile | the tile to get the distance from

Returns
  the distance from the edge in tiles

Definition at line 217 of file map.cpp.

References MapSizeX(), MapSizeY(), TileX(), and TileY().

Referenced by GrowTownWithExtraHouse(), IsRoadAllowedHere(), and TownCanBePlacedHere().

## ◆ DistanceFromEdgeDir()

uint DistanceFromEdgeDir | ( | TileIndex | tile,
|  | DiagDirection | dir
| ) |  |

distance from the map edge in given direction

distance from the map edge in given direction

Parameters

  tile | the tile to get the distance from
  dir | the direction of interest

Returns
  the distance from the edge in tiles

Definition at line 234 of file map.cpp.

References _settings_game, GameSettings::construction, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, ConstructionSettings::freeform_edges, MapMaxX(), MapMaxY(), TileX(), and TileY().

Referenced by CheckScaledDistanceFromEdge(), and GetOtherAqueductEnd().

## ◆ DistanceManhattan()

uint DistanceManhattan | ( | TileIndex | t0,
|  | TileIndex | t1
| ) |  |

also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads)

also known as L1-Norm. Is the shortest distance one could go over diagonal tracks (or roads)

The Manhattan distance is the sum of the delta of both the X and Y component. Also known as L1-Norm

Parameters

  t0 | the start tile
  t1 | the end tile

Returns
  the distance

Definition at line 157 of file map.cpp.

References Delta(), TileX(), and TileY().

Referenced by AirportGetNearestTown(), CheckSubsidyDistance(), DeleteStaleLinks(), FindDeletedWaypointCloseTo(), FlowRiver(), FlowsDown(), GetDistanceFromNearbyHouse(), IndustriesScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), VpSetPresizeRange(), and YapfTrainCheckReverse().

## ◆ DistanceMax()

uint DistanceMax | ( | TileIndex | t0,
|  | TileIndex | t1
| ) |  |

also known as L-Infinity-Norm

also known as L-Infinity-Norm

Also known as L-Infinity-Norm.

Parameters

  t0 | the start tile
  t1 | the end tile

Returns
  the distance

Definition at line 189 of file map.cpp.

References Delta(), TileX(), and TileY().

Referenced by CheckIfFarEnoughFromConflictingIndustry(), and CheckIfIndustryIsAllowed().

## ◆ DistanceMaxPlusManhattan()

uint DistanceMaxPlusManhattan | ( | TileIndex | t0,
|  | TileIndex | t1
| ) |  |

Max + Manhattan.

Max + Manhattan.

two times the biggest distance component and once the smallest component.

Parameters

  t0 | the start tile
  t1 | the end tile

Returns
  the distance

Definition at line 205 of file map.cpp.

References Delta(), TileX(), and TileY().

## ◆ DistanceSquare()

uint DistanceSquare | ( | TileIndex | t0,
|  | TileIndex | t1
| ) |  |

euclidian- or L2-Norm squared

euclidian- or L2-Norm squared

The 'Square' distance is the square of the shortest (straight line) distance between the two tiles. Also known as euclidian- or L2-Norm squared.

Parameters

  t0 | the start tile
  t1 | the end tile

Returns
  the distance

Definition at line 174 of file map.cpp.

References TileX(), and TileY().

Referenced by CmdBuildBridge(), CmdBuildTunnel(), GetTownRadiusGroup(), IndustriesScopeResolver::GetVariable(), and ObjectScopeResolver::GetVariable().

## ◆ GetClosestWaterDistance()

uint GetClosestWaterDistance | ( | TileIndex | tile,
|  | bool | water
| ) |  |

Finds the distance for the closest tile with water/land given a tile.

Parameters

  tile | the tile to find the distance too
  water | whether to find water or land

Returns
  distance to nearest water (max 0x7F) / land (max 0x1FF; 0x200 if there is no land)

Definition at line 340 of file map.cpp.

References HasTileWaterGround().

Referenced by FindFurthestFromWater(), and IndustriesScopeResolver::GetVariable().

## ◆ MapLogX()

static uint MapLogX | ( |  | ) |
| inlinestatic

Logarithm of the map size along the X side.

Note
  try to avoid using this one

Returns
  2^"return value" == MapSizeX()

Definition at line 51 of file map_func.h.

References _map_log_x.

Referenced by HeightMapGenerate(), RunTileLoop(), ScaleByMapSize(), ScaleByMapSize1D(), StartupIndustryDailyChanges(), TGPGetMaxHeight(), TileY(), and ToTileIndexDiff().

## ◆ MapLogY()

static uint MapLogY | ( |  | ) |
| inlinestatic

Logarithm of the map size along the y side.

Note
  try to avoid using this one

Returns
  2^"return value" == MapSizeY()

Definition at line 62 of file map_func.h.

References _map_log_y.

Referenced by HeightMapGenerate(), RunTileLoop(), ScaleByMapSize(), ScaleByMapSize1D(), StartupIndustryDailyChanges(), and TGPGetMaxHeight().

## ◆ MapMaxX()

static uint MapMaxX | ( |  | ) |
| inlinestatic

Gets the maximum X coordinate within the map, including MP_VOID.

Returns
  the maximum X coordinate

Definition at line 102 of file map_func.h.

References MapSizeX().

Referenced by CheckIfCanLevelIndustryPlatform(), DistanceFromEdgeDir(), Station::GetCatchmentRect(), GetTileHeightBelowAircraft(), GetTileMaxZ(), GetTileSlope(), GetTileZ(), GUIPlaceProcDragXY(), IsTileFlat(), IsTunnelInWay(), SetWaterClassDependingOnSurroundings(), TileX(), and TryBuildLightHouse().

## ◆ MapMaxY()

static uint MapMaxY | ( |  | ) |
| inlinestatic

Gets the maximum Y coordinate within the map, including MP_VOID.

Returns
  the maximum Y coordinate

Definition at line 111 of file map_func.h.

References MapSizeY().

Referenced by CheckIfCanLevelIndustryPlatform(), DistanceFromEdgeDir(), Station::GetCatchmentRect(), GetTileHeightBelowAircraft(), GetTileMaxZ(), GetTileSlope(), GetTileZ(), GUIPlaceProcDragXY(), IsTileFlat(), IsTunnelInWay(), SetWaterClassDependingOnSurroundings(), and TryBuildLightHouse().

## ◆ MapSize()

static uint MapSize | ( |  | ) |
| inlinestatic

Get the size of the map.

Returns
  the number of tiles of the map

Definition at line 92 of file map_func.h.

References _map_size.

Referenced by AfterLoadCompanyStats(), AfterLoadGame(), CalculateCoverageLine(), OrthogonalTileArea::ClampToMap(), ClickChangeMaxHlCheat(), CmdBuildCanal(), CmdBuildLongRoad(), CmdClearArea(), CmdConvertRail(), CmdConvertRoad(), CmdLevelLand(), CmdPlantTree(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveLongRoad(), CmdSignalTrackHelper(), CmdTerraformLand(), DEF_CONSOLE_CMD(), DiagonalTileArea::DiagonalTileArea(), DoCommand(), GetTileType(), GetTropicZone(), GrowTownAtRoad(), GrowTownInTile(), IsInnerTile(), IsValidTile(), MAPTChunkHandler::Load(), MAPHChunkHandler::Load(), MAPOChunkHandler::Load(), MAP2ChunkHandler::Load(), M3LOChunkHandler::Load(), M3HIChunkHandler::Load(), MAP5ChunkHandler::Load(), MAPEChunkHandler::Load(), MAP7ChunkHandler::Load(), MAP8ChunkHandler::Load(), MakeHeightmapScreenshot(), OrthogonalTileArea::OrthogonalTileArea(), MAPTChunkHandler::Save(), MAPHChunkHandler::Save(), MAPOChunkHandler::Save(), MAP2ChunkHandler::Save(), M3LOChunkHandler::Save(), M3HIChunkHandler::Save(), MAP5ChunkHandler::Save(), MAPEChunkHandler::Save(), MAP7ChunkHandler::Save(), MAP8ChunkHandler::Save(), SetTileHeight(), SetTileType(), SetTropicZone(), TerraformTileHeight(), TileHeight(), UpdateHousesAndTowns(), UpdateNearestTownForRoadTiles(), and Town::~Town().

## ◆ MapSizeX()

static uint MapSizeX | ( |  | ) |
| inlinestatic

Get the size of the map along the X.

Returns
  the number of tiles along the X of the map

Definition at line 72 of file map_func.h.

References _map_size_x.

Referenced by AllocHeightMap(), CalculateCoverageLine(), CheckScaledDistanceFromEdge(), OrthogonalTileArea::ClampToMap(), DistanceFromEdge(), FillStaticNetworkServerGameInfo(), FixSlopes(), FlatEmptyWorld(), AirportSpec::IsWithinMapBounds(), MakeHeightmapScreenshot(), MakeScreenshotWithConfirm(), MapMaxX(), and ServerNetworkAdminSocketHandler::SendWelcome().

## ◆ MapSizeY()

static uint MapSizeY | ( |  | ) |
| inlinestatic

Get the size of the map along the Y.

Returns
  the number of tiles along the Y of the map

Definition at line 82 of file map_func.h.

References _map_size_y.

Referenced by AllocHeightMap(), CalculateCoverageLine(), CheckScaledDistanceFromEdge(), OrthogonalTileArea::ClampToMap(), DistanceFromEdge(), FillStaticNetworkServerGameInfo(), FixSlopes(), FlatEmptyWorld(), AirportSpec::IsWithinMapBounds(), MakeHeightmapScreenshot(), MakeScreenshotWithConfirm(), MapMaxY(), and ServerNetworkAdminSocketHandler::SendWelcome().

## ◆ RandomTileSeed()

static TileIndex RandomTileSeed | ( | uint32 | r | ) |
| inlinestatic

Get a random tile out of a given seed.

Parameters

  r | the random 'seed'

Returns
  a valid tile

Definition at line 424 of file map_func.h.

References TILE_MASK.

## ◆ ScaleByMapSize()

static uint ScaleByMapSize | ( | uint | n | ) |
| inlinestatic

Scales the given value by the map size, where the given value is for a 256 by 256 map.

Parameters

  n | the value to scale

Returns
  the scaled size

Definition at line 122 of file map_func.h.

References CeilDiv(), MapLogX(), and MapLogY().

Referenced by CreateRivers(), DecrementTreeCounter(), IndustryBuildData::MonthlyLoop(), and PlaceTreesRandomly().

## ◆ ScaleByMapSize1D()

static uint ScaleByMapSize1D | ( | uint | n | ) |
| inlinestatic

Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.

Parameters

  n | the value to scale

Returns
  the scaled size

Definition at line 136 of file map_func.h.

References CeilDiv(), MapLogX(), and MapLogY().

## ◆ TileAddByDiagDir()

static TileIndex TileAddByDiagDir | ( | TileIndex | tile,
|  | DiagDirection | dir
| ) |  |
| inlinestatic

Adds a DiagDir to a tile.

Parameters

  tile | The current tile
  dir | The direction in which we want to step

Returns
  the moved tile

Definition at line 382 of file map_func.h.

References TILE_ADD, and TileOffsByDiagDir().

Referenced by CleanUpRoadBits(), ClearPathReservation(), DrawRoadTypeCatenary(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::FollowTileExit(), GrowTownWithBridge(), GrowTownWithExtraHouse(), GrowTownWithTunnel(), BuildDocksToolbarWindow::OnPlacePresize(), SetWaterClassDependingOnSurroundings(), and TryPathReserve().

## ◆ TileAddByDir()

static TileIndex TileAddByDir | ( | TileIndex | tile,
|  | Direction | dir
| ) |  |
| inlinestatic

Adds a Direction to a tile.

Parameters

  tile | The current tile
  dir | The direction in which we want to step

Returns
  the moved tile

Definition at line 370 of file map_func.h.

References TILE_ADD, and TileOffsByDir().

Referenced by CircularTileSearch().

## ◆ TileAddWrap()

TileIndex TileAddWrap | ( | TileIndex | tile,
|  | int | addx,
|  | int | addy
| ) |  |

This function checks if we add addx/addy to tile, if we do wrap around the edges.

For example, tile = (10,2) and addx = +3 and addy = -4. This function will now return INVALID_TILE, because the y is wrapped. This is needed in for example, farmland. When the tile is not wrapped, the result will be tile + TileDiffXY(addx, addy)

Parameters

  tile | the 'starting' point of the adding
  addx | the amount of tiles in the X direction to add
  addy | the amount of tiles in the Y direction to add

Returns
  translated tile, or INVALID_TILE when it would've wrapped.

Definition at line 114 of file map.cpp.

Referenced by CheckIfIndustryTilesAreFree(), and CountMapSquareAround().

## ◆ TileDiffXY()

static TileIndexDiff TileDiffXY | ( | int | x,
|  | int | y
| ) |  |
| inlinestatic

Calculates an offset for the given coordinate(-offset).

This function calculate an offset value which can be added to an TileIndex. The coordinates can be negative.

Parameters

  x | The offset in x direction
  y | The offset in y direction

Returns
  The resulting offset value of the given coordinate

See also
  ToTileIndexDiff(TileIndexDiffC)

Definition at line 179 of file map_func.h.

Referenced by CheckIfCanLevelIndustryPlatform(), CmdBuildShipDepot(), CmdTerraformLand(), GetOtherShipDepotTile(), Station::GetPlatformLength(), GetReferenceTile(), Airport::GetRotatedTileFromOffset(), GUIPlaceProcDragXY(), Station::MarkTilesDirty(), OrthogonalTileIterator::operator++(), SetupFarmFieldFence(), and TerraformAddDirtyTileAround().

## ◆ TileIndexDiffCByDiagDir()

static TileIndexDiffC TileIndexDiffCByDiagDir | ( | DiagDirection | dir | ) |
| inlinestatic

Returns the TileIndexDiffC offset from a DiagDirection.

Parameters

  dir | The given direction

Returns
  The offset as TileIndexDiffC value

Definition at line 268 of file map_func.h.

References _tileoffs_by_diagdir, DIAGDIR_END, and IsValidDiagDirection().

Referenced by CalculateCoverageLine().

## ◆ TileIndexDiffCByDir()

static TileIndexDiffC TileIndexDiffCByDir | ( | Direction | dir | ) |
| inlinestatic

Returns the TileIndexDiffC offset from a Direction.

Parameters

  dir | The given direction

Returns
  The offset as TileIndexDiffC value

Definition at line 282 of file map_func.h.

References _tileoffs_by_dir, DIR_END, and IsValidDirection().

## ◆ TileIndexToTileIndexDiffC()

static TileIndexDiffC TileIndexToTileIndexDiffC | ( | TileIndex | tile_a,
|  | TileIndex | tile_b
| ) |  |
| inlinestatic

Returns the diff between two tiles.

Parameters

  tile_a | from tile
  tile_b | to tile

Returns
  the difference between tila_a and tile_b

Definition at line 316 of file map_func.h.

References TileX(), TileY(), TileIndexDiffC::x, and TileIndexDiffC::y.

Referenced by DoWatchedCargoCallback(), GetTownRoadGridElement(), TownLayoutAllows2x2HouseHere(), and TownLayoutAllowsHouseHere().

## ◆ TileOffsByDiagDir()

static TileIndexDiff TileOffsByDiagDir | ( | DiagDirection | dir | ) |
| inlinestatic

Convert a DiagDirection to a TileIndexDiff.

Parameters

  dir | The DiagDirection

Returns
  The resulting TileIndexDiff

See also
  TileIndexDiffCByDiagDir

Definition at line 341 of file map_func.h.

References _tileoffs_by_diagdir, DIAGDIR_END, IsValidDiagDirection(), and ToTileIndexDiff().

Referenced by CanConnectToRoad(), CanFollowRoad(), CanRoadContinueIntoNextTile(), CheckForDockingTile(), CheckFree2x2Area(), RoadStop::Entry::CheckIntegrity(), CheckTownBuild2House(), CheckTownBuild2x2House(), ClearDockingTilesCheckingNeighbours(), RoadStop::ClearDriveThrough(), CmdBuildLongRoad(), ConnectRoadToStructure(), DisasterTick_Submarine(), DoBuildLock(), DoClearBridge(), ExtendTrainReservation(), FindDockLandPart(), FixOwnerOfRailTrack(), FollowReservation(), FollowTrainReservation(), GetBridgeEnd(), GetOtherAqueductEnd(), GetOtherTunnelEnd(), Station::GetPlatformLength(), GetTrainForReservation(), GrowTownWithBridge(), GrowTownWithTunnel(), CYapfCostRailT< Types >::IsAnyStationTileReserved(), IsNeighborRoadTile(), IsShipDestinationTile(), IsTunnelInWayDir(), RoadStop::MakeDriveThrough(), MakeLock(), MarkBridgeDirty(), NeighbourIsNormal(), NPFSaveTargetData(), CYapfCostRoadT< Types >::OneTileCost(), RoadStop::Entry::Rebuild(), RemoveDock(), RemoveLock(), CYapfReserveTrack< Types >::ReserveRailStationPlatform(), SetRailStationPlatformReservation(), TestTownOwnsBridge(), TileAddByDiagDir(), TrainApproachingCrossing(), TrainApproachingCrossingTile(), TrainCheckIfLineEnds(), CYapfReserveTrack< Types >::UnreserveSingleTrack(), and UpdateSignalsInBuffer().

## ◆ TileOffsByDir()

static TileIndexDiff TileOffsByDir | ( | Direction | dir | ) |
| inlinestatic

Convert a Direction to a TileIndexDiff.

Parameters

  dir | The direction to convert from

Returns
  The resulting TileIndexDiff

Definition at line 355 of file map_func.h.

References _tileoffs_by_dir, DIR_END, IsValidDirection(), and ToTileIndexDiff().

Referenced by MarkCanalsAndRiversAroundDirty(), TileAddByDir(), and TileLoop_Water().

## ◆ TileVirtXY()

static TileIndex TileVirtXY | ( | uint | x,
|  | uint | y
| ) |  |
| inlinestatic

Get a tile from the virtual XY-coordinate.

Parameters

  x | The virtual x coordinate of the tile.
  y | The virtual y coordinate of the tile.

Returns
  The TileIndex calculated by the coordinate.

Definition at line 194 of file map_func.h.

Referenced by AircraftLandAirplane(), CheckTrainCollision(), CrashAirplane(), DrawStationCoverageAreaText(), FindStationsAroundSelection(), GetTileHeightBelowAircraft(), SignListWindow::OnClick(), SignWindow::OnClick(), VehicleViewWindow::OnClick(), BuildRoadToolbarWindow::OnHotkey(), BuildRailToolbarWindow::OnHotkey(), UpdateStatusAfterSwap(), and YapfTrainCheckReverse().

## ◆ TileX()

static uint TileX | ( | TileIndex | tile | ) |
| inlinestatic

Get the X component of a tile.

Parameters

  tile | the tile to get the X component of

Returns
  the X component

Definition at line 205 of file map_func.h.

References MapMaxX().

Referenced by OrthogonalTileArea::Add(), AyStar::AddStartNode(), AircraftGetEntryPoint(), AirportGetNearestTown(), AlignTileToGrid(), TileMatrix< T, N >::AllocateStorage(), CalcClosestStationTile(), CcBuildIndustry(), CheckIfCanLevelIndustryPlatform(), OrthogonalTileArea::ClampToMap(), CmdBuildLongRoad(), CmdRemoveLongRoad(), OrthogonalTileArea::Contains(), DiagonalTileArea::Contains(), DiagdirBetweenTiles(), DiagonalTileArea::DiagonalTileArea(), DistanceFromEdge(), DistanceFromEdgeDir(), DistanceManhattan(), DistanceMax(), DistanceMaxPlusManhattan(), DistanceSquare(), SmallMapWindow::DrawTowns(), TileMatrix< T, N >::GetAreaForTile(), GetOtherAqueductEnd(), RoadTypeScopeResolver::GetRandomBits(), RailTypeScopeResolver::GetRandomBits(), GetTileMaxZ(), GetTileSlope(), GetTileZ(), GetTLG(), GetTunnelBridgeLength(), HouseScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), GUIPlaceProcDragXY(), Town::InitializeLayout(), OrthogonalTileArea::Intersects(), IsTileAlignedToGrid(), IsTileFlat(), IsTunnelInWay(), AirportSpec::IsWithinMapBounds(), MarkTileDirtyByTile(), NPFDistanceTrack(), NPFHash(), OrthogonalTileArea::OrthogonalTileArea(), CYapfDestinationTileWaterT< Types >::PfCalcEstimate(), CYapfDestinationTileT< Types >::PfCalcEstimate(), CYapfDestinationTileOrStationRailT< Types >::PfCalcEstimate(), CYapfDestinationTileRoadT< Types >::PfCalcEstimate(), River_Hash(), ScrollMainWindowToTile(), ScrollWindowToTile(), SetWaterClassDependingOnSurroundings(), SwapDirection(), TerraformAddDirtyTileAround(), TileIndexToTileIndexDiffC(), TileStr(), Waypoint::UpdateVirtCoord(), Town::UpdateVirtCoord(), and Station::UpdateVirtCoord().

## ◆ TileXY()

static TileIndex TileXY | ( | uint | x,
|  | uint | y
| ) |  |
| inlinestatic

Returns the TileIndex of a coordinate.

Parameters

  x | The x coordinate of the tile
  y | The y coordinate of the tile

Returns
  The TileIndex calculated by the coordinate

Definition at line 163 of file map_func.h.

Referenced by OrthogonalTileArea::Add(), AlignTileToGrid(), FlatEmptyWorld(), GetTileMaxZ(), GetTileSlope(), GetTileZ(), BitmapTileArea::Initialize(), IsTileFlat(), OrthogonalTileArea::OrthogonalTileArea(), Station::RecomputeCatchment(), and StationRect::ScanForStationTiles().

## ◆ TileY()

static uint TileY | ( | TileIndex | tile | ) |
| inlinestatic

Get the Y component of a tile.

Parameters

  tile | the tile to get the Y component of

Returns
  the Y component

Definition at line 215 of file map_func.h.

References MapLogX().

Referenced by OrthogonalTileArea::Add(), AyStar::AddStartNode(), AircraftGetEntryPoint(), AirportGetNearestTown(), AlignTileToGrid(), CalcClosestStationTile(), CcBuildIndustry(), CheckIfCanLevelIndustryPlatform(), OrthogonalTileArea::ClampToMap(), CmdBuildLongRoad(), CmdRemoveLongRoad(), OrthogonalTileArea::Contains(), DiagonalTileArea::Contains(), DiagdirBetweenTiles(), DiagonalTileArea::DiagonalTileArea(), DistanceFromEdge(), DistanceFromEdgeDir(), DistanceManhattan(), DistanceMax(), DistanceMaxPlusManhattan(), DistanceSquare(), SmallMapWindow::DrawTowns(), GetOtherAqueductEnd(), RoadTypeScopeResolver::GetRandomBits(), RailTypeScopeResolver::GetRandomBits(), GetTileMaxZ(), GetTileSlope(), GetTileZ(), GetTLG(), GetTunnelBridgeLength(), HouseScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), GUIPlaceProcDragXY(), Town::InitializeLayout(), OrthogonalTileArea::Intersects(), IsTileAlignedToGrid(), IsTileFlat(), IsTunnelInWay(), AirportSpec::IsWithinMapBounds(), MarkTileDirtyByTile(), NPFDistanceTrack(), OrthogonalTileArea::OrthogonalTileArea(), CYapfDestinationTileWaterT< Types >::PfCalcEstimate(), CYapfDestinationTileT< Types >::PfCalcEstimate(), CYapfDestinationTileOrStationRailT< Types >::PfCalcEstimate(), CYapfDestinationTileRoadT< Types >::PfCalcEstimate(), River_Hash(), ScrollMainWindowToTile(), ScrollWindowToTile(), SetWaterClassDependingOnSurroundings(), SwapDirection(), TerraformAddDirtyTileAround(), TileIndexToTileIndexDiffC(), TileStr(), Waypoint::UpdateVirtCoord(), Town::UpdateVirtCoord(), and Station::UpdateVirtCoord().

## ◆ ToTileIndexDiff()

static TileIndexDiff ToTileIndexDiff | ( | TileIndexDiffC | tidc | ) |
| inlinestatic

Return the offset between to tiles from a TileIndexDiffC struct.

This function works like TileDiffXY(int, int) and returns the difference between two tiles.

Parameters

  tidc | The coordinate of the offset as TileIndexDiffC

Returns
  The difference between two tiles.

See also
  TileDiffXY(int, int)

Definition at line 230 of file map_func.h.

References MapLogX(), TileIndexDiffC::x, and TileIndexDiffC::y.

Referenced by Airport::GetRotatedTileFromOffset(), AirportTileTableIterator::operator++(), RoadTypesAllowHouseHere(), TileOffsByDiagDir(), and TileOffsByDir().

## Variable Documentation

## ◆ _m

Tile* _m

Pointer to the tile-array.

This variable points to the tile-array which contains the tiles of the map.

Pointer to the tile-array.

Definition at line 30 of file map.cpp.

Referenced by AddClearCounter(), AddClearDensity(), AddTreeCount(), AddTreeCounter(), AddTreeGrowth(), AllocateMap(), ClearSingleBridgeMiddle(), ClearSnow(), GetBridgeAxis(), GetCleanHouseType(), GetCleanIndustryGfx(), GetClearCounter(), GetClearDensity(), GetCrossingRoadAxis(), GetCustomStationSpecIndex(), GetDepotIndex(), GetDisallowedRoadDirections(), GetFieldType(), GetHouseAge(), GetHouseConstructionTick(), GetHouseRandomBits(), GetHouseTriggers(), GetIndustryAnimationLoop(), GetIndustryConstructionCounter(), GetIndustryIndex(), GetIndustryIndexOfField(), GetIndustryRandomBits(), GetLockDirection(), GetLockPart(), GetObjectIndex(), GetObjectRandomBits(), GetPresentSignals(), GetRailDepotDirection(), GetRailReservationTrackBits(), GetRailTileType(), GetRawClearGround(), GetRoadDepotDirection(), GetRoadTileType(), GetShipDepotAxis(), GetShipDepotPart(), GetSignalStates(), GetStationGfx(), GetStationIndex(), GetStationTileRandomBits(), GetTileOwner(), GetTileType(), GetTownIndex(), GetTrackBits(), GetTreeCount(), GetTreeCounter(), GetTreeDensity(), GetTreeGround(), GetTreeGrowth(), GetTreeType(), GetTropicZone(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), GetWaterClass(), GetWaterTileRandomBits(), GetWaterTileType(), HasCrossingReservation(), HasDepotReservation(), HasTunnelBridgeReservation(), IncHouseConstructionTick(), IncrementHouseAge(), IsBridge(), IsBridgeAbove(), IsCrossingBarred(), IsCustomStationSpecIndex(), IsDockingTile(), IsHouseCompleted(), IsIndustryCompleted(), IsSnowTile(), IsTunnel(), MakeBridgeRamp(), MakeClear(), MakeField(), MakeHouseTile(), MakeIndustry(), MakeLockTile(), MakeObject(), MakeRailTunnel(), MakeRoadCrossing(), MakeRoadDepot(), MakeRoadNormal(), MakeRoadTunnel(), MakeShipDepot(), MakeShore(), MakeSnow(), MakeStation(), MakeTree(), MakeVoid(), MakeWater(), MoveWaypointsToBaseStations(), ResetHouseAge(), ResetIndustryConstructionStage(), SetBridgeMiddle(), SetClearCounter(), SetClearDensity(), SetClearGroundDensity(), SetCrossingBarred(), SetCrossingReservation(), SetCustomStationSpecIndex(), SetDepotReservation(), SetDisallowedRoadDirections(), SetDockingTile(), SetFieldType(), SetHasSignals(), SetHouseCompleted(), SetHouseRandomBits(), SetHouseTriggers(), SetHouseType(), SetIndustryAnimationLoop(), SetIndustryCompleted(), SetIndustryConstructionCounter(), SetIndustryConstructionStage(), SetIndustryGfx(), SetIndustryIndexOfField(), SetIndustryRandomBits(), SetPresentSignals(), SetSignalStates(), SetStationGfx(), SetStationTileRandomBits(), SetTileHeight(), SetTileOwner(), SetTileType(), SetTownIndex(), SetTrackBits(), SetTrackReservation(), SetTreeCounter(), SetTreeGroundDensity(), SetTreeGrowth(), SetTropicZone(), SetTunnelBridgeReservation(), SetWaterClass(), TileHeight(), and CrashLog::WriteSavegame().

## ◆ _me

TileExtended* _me

Pointer to the extended tile-array.

This variable points to the extended tile-array which contains the tiles of the map.

Pointer to the extended tile-array.

Definition at line 31 of file map.cpp.

Referenced by AllocateMap(), DecHouseProcessingTime(), GetAnimationFrame(), GetBridgeType(), GetCleanIndustryGfx(), GetHouseProcessingTime(), GetIndustryTriggers(), GetLiftDestination(), GetLiftPosition(), GetRailType(), GetRoadside(), GetStationType(), HaltLift(), HasStationReservation(), HasTunnelBridgeSnowOrDesert(), IncreaseRoadWorksCounter(), IsOnSnow(), LiftHasDestination(), MakeBridgeRamp(), MakeClear(), MakeField(), MakeIndustry(), MakeLockTile(), MakeObject(), MakeRailTunnel(), MakeRoadCrossing(), MakeRoadDepot(), MakeRoadNormal(), MakeRoadTunnel(), MakeShipDepot(), MakeShore(), MakeStation(), MakeTree(), MakeVoid(), MakeWater(), MoveBuoysToWaypoints(), SetAnimationFrame(), SetHouseProcessingTime(), SetIndustryGfx(), SetIndustryTriggers(), SetLiftDestination(), SetLiftPosition(), SetRailStationReservation(), SetRailType(), SetRoadside(), SetTunnelBridgeSnowOrDesert(), TerminateRoadWorks(), and ToggleSnow().