OpenTTD

Functions
tile_map.h File Reference

Map writing/reading functions for tiles. More...

`#include "slope_type.h"`
`#include "map_func.h"`
`#include "core/bitmath_func.hpp"`
`#include "settings_type.h"`

Go to the source code of this file.

## Functions
static uint | TileHeight (TileIndex tile)
| Returns the height of a tile. More...
uint | TileHeightOutsideMap (int x, int y)
| Returns the tile height for a coordinate outside map. More...
static void | SetTileHeight (TileIndex tile, uint height)
| Sets the height of a tile. More...
static uint | TilePixelHeight (TileIndex tile)
| Returns the height of a tile in pixels. More...
static uint | TilePixelHeightOutsideMap (int x, int y)
| Returns the tile height for a coordinate outside map. More...
static TileType | GetTileType (TileIndex tile)
| Get the tiletype of a given tile. More...
static bool | IsInnerTile (TileIndex tile)
| Check if a tile is within the map (not a border) More...
static void | SetTileType (TileIndex tile, TileType type)
| Set the type of a tile. More...
static bool | IsTileType (TileIndex tile, TileType type)
| Checks if a tile is a give tiletype. More...
static bool | IsValidTile (TileIndex tile)
| Checks if a tile is valid. More...
static Owner | GetTileOwner (TileIndex tile)
| Returns the owner of a tile. More...
static void | SetTileOwner (TileIndex tile, Owner owner)
| Sets the owner of a tile. More...
static bool | IsTileOwner (TileIndex tile, Owner owner)
| Checks if a tile belongs to the given owner. More...
static void | SetTropicZone (TileIndex tile, TropicZone type)
| Set the tropic zone. More...
static TropicZone | GetTropicZone (TileIndex tile)
| Get the tropic zone. More...
static byte | GetAnimationFrame (TileIndex t)
| Get the current animation frame. More...
static void | SetAnimationFrame (TileIndex t, byte frame)
| Set a new animation frame. More...
Slope | GetTileSlope (TileIndex tile, int *h=NULL)
| Return the slope of a given tile inside the map. More...
int | GetTileZ (TileIndex tile)
| Get bottom height of the tile. More...
int | GetTileMaxZ (TileIndex tile)
| Get top height of the tile inside the map. More...
bool | IsTileFlat (TileIndex tile, int *h=NULL)
| Check if a given tile is flat. More...
static Slope | GetTilePixelSlope (TileIndex tile, int *h)
| Return the slope of a given tile. More...
Slope | GetTilePixelSlopeOutsideMap (int x, int y, int *h)
| Return the slope of a given tile outside the map. More...
static int | GetTilePixelZ (TileIndex tile)
| Get bottom height of the tile. More...
int | GetTilePixelZOutsideMap (int x, int y)
| Get bottom height of the tile outside map. More...
static int | GetTileMaxPixelZ (TileIndex tile)
| Get top height of the tile. More...
int | GetTileMaxPixelZOutsideMap (int x, int y)
| Get top height of the tile outside the map. More...
static uint | TileHash (uint x, uint y)
| Calculate a hash value from a tile position. More...
static uint | TileHash2Bit (uint x, uint y)
| Get the last two bits of the TileHash from a tile position. More...

## Detailed Description

Map writing/reading functions for tiles.

Definition in file tile_map.h.

## Function Documentation

## ◆ GetAnimationFrame()

static byte GetAnimationFrame | ( | TileIndex | t | ) |
| inline static

Get the current animation frame.

Parameters

  t | the tile

Precondition
  IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION)

Returns
  frame number

Definition at line 243 of file tile_map.h.

Referenced by IndustryTileScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), and IncreaseAnimationStage().

## ◆ GetTileMaxPixelZ()

static int GetTileMaxPixelZ | ( | TileIndex | tile | ) |
| inline static

Get top height of the tile.

Parameters

  t | Tile to compute height of

Returns
  Maximum height of the tile

Definition at line 299 of file tile_map.h.

References GetTileMaxPixelZOutsideMap(), GetTileMaxZ(), and TILE_HEIGHT.

Referenced by EnsureNoVehicleOnGround().

## ◆ GetTileMaxPixelZOutsideMap()

int GetTileMaxPixelZOutsideMap | ( | int | x,
|  | int | y
| ) |  |

Get top height of the tile outside the map.

See also
  Detailed description in header.

Parameters

  tile | Tile outside to compute height of.

Returns
  Maximum height of the tile.

Definition at line 235 of file tile_map.cpp.

Referenced by GetTileMaxPixelZ().

## ◆ GetTileMaxZ()

int GetTileMaxZ | ( | TileIndex | t | ) |

Get top height of the tile inside the map.

Parameters

  t | Tile to compute height of

Returns
  Maximum height of the tile

Definition at line 215 of file tile_map.cpp.

References MapMaxX(), MapMaxY(), TileDiffXY(), TileHeight(), TileHeightOutsideMap(), TileX(), and TileY().

Referenced by AutoslopeCheckForEntranceEdge(), BuildTownHouse(), CheckBuildHouseSameZ(), FloodVehicleProc(), GetOtherAqueductEnd(), and GetTileMaxPixelZ().

## ◆ GetTileOwner()

static Owner GetTileOwner | ( | TileIndex | tile | ) |
| inline static

Returns the owner of a tile.

This function returns the owner of a tile. This cannot used for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY as no company owned any of these buildings.

Parameters

  tile | The tile to check

Returns
  The owner of the tile

Precondition
  IsValidTile(tile)
  The type of the tile must not be MP_HOUSE and MP_INDUSTRY

Definition at line 171 of file tile_map.h.

Referenced by CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CheckTileOwnership(), CmdConvertRail(), ObjectScopeResolver::GetVariable(), IsTileOwner(), MakeBuoy(), MakeLock(), and RemoveLock().

## ◆ GetTilePixelSlope()

static Slope GetTilePixelSlope | ( | TileIndex | tile,
|  | int * | h
| ) |  |
| inline static

Return the slope of a given tile.

Parameters

  tile | Tile to compute slope of
  h | If not `NULL`, pointer to storage of z height

Returns
  Slope of the tile, except for the HALFTILE part

Definition at line 273 of file tile_map.h.

References GetTilePixelSlopeOutsideMap(), GetTileSlope(), and TILE_HEIGHT.

Referenced by GetNearbyTileInformation().

## ◆ GetTilePixelSlopeOutsideMap()

Slope GetTilePixelSlopeOutsideMap | ( | int | x,
|  | int | y,
|  | int * | h
| ) |  |

Return the slope of a given tile outside the map.

Parameters

  tile | Tile outside the map to compute slope of.
  h | If not `NULL`, pointer to storage of z height.

Returns
  Slope of the tile outside map, except for the HALFTILE part.

Definition at line 141 of file tile_map.cpp.

Referenced by GetTilePixelSlope().

## ◆ GetTilePixelZ()

static int GetTilePixelZ | ( | TileIndex | tile | ) |
| inline static

Get bottom height of the tile.

Parameters

  tile | Tile to compute height of

Returns
  Minimum height of the tile

Definition at line 287 of file tile_map.h.

References GetTilePixelZOutsideMap(), GetTileZ(), and TILE_HEIGHT.

## ◆ GetTilePixelZOutsideMap()

int GetTilePixelZOutsideMap | ( | int | x,
|  | int | y
| ) |  |

Get bottom height of the tile outside map.

Parameters

  tile | Tile outside the map to compute height of.

Returns
  Minimum height of the tile outside the map.

Definition at line 200 of file tile_map.cpp.

Referenced by GetTilePixelZ().

## ◆ GetTileSlope()

Slope GetTileSlope | ( | TileIndex | tile,
|  | int * | h
| ) |  |

Return the slope of a given tile inside the map.

Parameters

  tile | Tile to compute slope of
  h | If not `NULL`, pointer to storage of z height

Returns
  Slope of the tile, except for the HALFTILE part

Definition at line 115 of file tile_map.cpp.

Referenced by BuildTownHouse(), CanBuildHouseHere(), CanPlantTreesOnTile(), CheckBuildableTile(), CheckIfIndustryTilesAreFree(), CmdBuildLock(), CmdBuildRoadDepot(), CmdBuildTrainDepot(), GetBridgeHeight(), GetFloodingBehaviour(), GetFoundationSlope(), GetOtherAqueductEnd(), GetTilePixelSlope(), StationScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), IsRoadAllowedHere(), BuildDocksToolbarWindow::OnPlacePresize(), PerformStationTileSlopeCheck(), SearchTileForStatue(), and CYapfCostBase::stSlopeCost().

## ◆ GetTileType()

static TileType GetTileType | ( | TileIndex | tile | ) |
| inline static

Get the tiletype of a given tile.

Parameters

  tile | The tile to get the TileType

Returns
  The tiletype of the tile

Precondition
  tile < MapSize()

Definition at line 89 of file tile_map.h.

Referenced by CanEnterTileOwnerCheck(), CanFollowRoad(), CanPlantTreesOnTile(), ChangeTileOwner(), CheckIfFarEnoughFromConflictingIndustry(), CleanUpRoadBits(), ClosestTownFromTile(), CmdConvertRail(), DrawRailCatenary(), GetAnyRoadBits(), GetDepotVehicleType(), GetFloodingBehaviour(), GetFoundationSlope(), GetGrfSpecFeature(), GetNearbyTileInformation(), GetRailTrackBitsUniversal(), GetReservedTrackbits(), SmallMapWindow::GetTileColours(), GetTileRailType(), GetTileTrackStatus(), GrowTownWithExtraHouse(), IsCloseToTown(), Depot::IsOfType(), IsSuitableForFarmField(), IsTileType(), IsWateredTile(), CYapfCostRoadT< Types >::OneTileCost(), CYapfCostRailT< Types >::OneTileCost(), RemoveRoad(), and SetWaterClassDependingOnSurroundings().

## ◆ GetTileZ()

int GetTileZ | ( | TileIndex | tile | ) |

Get bottom height of the tile.

Parameters

  tile | Tile to compute height of

Returns
  Minimum height of the tile

Definition at line 182 of file tile_map.cpp.

References MapMaxX(), MapMaxY(), min(), TileDiffXY(), TileHeight(), TileX(), and TileY().

Referenced by CheckNewIndustry_BubbleGen(), GetOtherTunnelEnd(), GetTilePixelZ(), CanalScopeResolver::GetVariable(), IndustriesScopeResolver::GetVariable(), and TileLoopClearAlps().

## ◆ GetTropicZone()

static TropicZone GetTropicZone | ( | TileIndex | tile | ) |
| inline static

Get the tropic zone.

Parameters

  tile | the tile to get the zone of

Precondition
  tile < MapSize()

Returns
  the zone type

Definition at line 231 of file tile_map.h.

Referenced by CheckNewIndustry_Lumbermill(), CheckNewIndustry_Plantation(), CheckNewIndustry_Water(), NeighbourIsDesert(), and RiverModifyDesertZone().

## ◆ IsInnerTile()

static bool IsInnerTile | ( | TileIndex | tile | ) |
| inline static

Check if a tile is within the map (not a border)

Parameters

  tile | The tile to check

Returns
  Whether the tile is in the interior of the map

Precondition
  tile < MapSize()

Definition at line 102 of file tile_map.h.

Referenced by TgenSetTileHeight().

## ◆ IsTileFlat()

bool IsTileFlat | ( | TileIndex | tile,
|  | int * | h
| ) |  |

Check if a given tile is flat.

Parameters

  tile | Tile to check
  h | If not `NULL`, pointer to storage of z height (only if tile is flat)

Returns
  Whether the tile is flat

Definition at line 159 of file tile_map.cpp.

Referenced by CheckIfIndustryTilesAreFree(), CmdBuildBuoy(), CmdBuildShipDepot(), FindFurthestFromWater(), FindSpring(), SetWaterClassDependingOnSurroundings(), TownCanBePlacedHere(), and TryBuildTransmitter().

## ◆ IsTileOwner()

static bool IsTileOwner | ( | TileIndex | tile,
|  | Owner | owner
| ) |  |
| inline static

Checks if a tile belongs to the given owner.

Parameters

  tile | The tile to check
  owner | The owner to check against

Returns
  True if a tile belongs the the given owner

Definition at line 207 of file tile_map.h.

References GetTileOwner().

Referenced by CanEnterTileOwnerCheck(), CmdBuildVehicle(), CmdDepotMassAutoReplace(), DoClearBridge(), DoClearTunnel(), GetOrderCmdFromTile(), and RoadFindPathToDest().

## ◆ IsTileType()

static bool IsTileType | ( | TileIndex | tile,
|  | TileType | type
| ) |  |
| inline static

Checks if a tile is a give tiletype.

This function checks if a tile got the given tiletype.

Parameters

  tile | The tile to check
  type | The type to check against

Returns
  true If the type matches against the type of the tile

Definition at line 143 of file tile_map.h.

References GetTileType().

Referenced by AddNearbyStation(), AdjustTileh(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanEnterTile(), CanEnterTileOwnerCheck(), CheckFlatLandRailStation(), CheckFlatLandRoadStop(), ClearPathReservation(), CmdBuildLongRoad(), CMSAMine(), CMSATree(), CMSAWater(), Train::Crash(), ExtendTrainReservation(), FindFurthestFromWater(), FindIndustryToDeliver(), FindNearestEmptyLand(), FindNearIndustryName(), FindRailStationEnd(), FollowReservation(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::FollowTileExit(), GetAxisForNewWaypoint(), GetEffectiveWaterClass(), GetNearbyAirportTileInformation(), GetNearbyIndustryTileInformation(), GetNearbyObjectTileInformation(), GetNearbyTileInformation(), GetObjectIDAtOffset(), GetOrderCmdFromTile(), CanalScopeResolver::GetRandomBits(), ObjectScopeResolver::GetRandomBits(), CanalScopeResolver::GetVariable(), IndustryTileScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), HasOnewaySignalBlockingTrackdir(), HasPbsSignalOnTrackdir(), HasStationTileRail(), HasTileWaterClass(), IsAirportTile(), IsBridgeTile(), IsBuoyTile(), IsCoastTile(), IsDockTile(), RoadStop::IsDriveThroughRoadStopContinuation(), IsHangarTile(), IsLevelCrossingTile(), IsNormalRoadTile(), IsObjectTypeTile(), IsPlainRailTile(), IsPossibleCrossing(), IsRailDepotTile(), IsRailStationTile(), IsRailWaypointTile(), IsRoadDepotTile(), IsRoadStopTile(), IsSafeWaitingPosition(), IsShipDepotTile(), IsTileForestIndustry(), IsTunnelTile(), IsValidTile(), IsValidTileForWaypoint(), IsWaitingPositionFree(), IsWaterTile(), MarkTileDirtyIfCanalOrRiver(), MayHaveBridgeAbove(), RemoveRoad(), RoadFindPathToDest(), StationRect::ScanForStationTiles(), SearchLumberMillTrees(), SearchNearbyHouseClass(), SearchNearbyHouseGRFID(), SearchNearbyHouseID(), SearchTileForStatue(), SetupFarmFieldFence(), Industry::TileBelongsToIndustry(), TileLoop_Water(), TownCanBePlacedHere(), TrainCanLeaveTile(), TriggerWatchedCargoCallbacks(), TryBuildTransmitter(), UpdateHousesAndTowns(), UpdateStatusAfterSwap(), and UpdateTownCargoes().

## ◆ IsValidTile()

static bool IsValidTile | ( | TileIndex | tile | ) |
| inline static

Checks if a tile is valid.

Parameters

  tile | The tile to check

Returns
  True if the tile is on the map and not one of MP_VOID.

Definition at line 154 of file tile_map.h.

References IsTileType(), MapSize(), and MP_VOID.

Referenced by CanFollowRoad(), CheckIfIndustryTilesAreFree(), CleanUpRoadBits(), CmdBuildBridge(), DisasterTick_Submarine(), DoCommand(), DrawTileSelectionRect(), GetOtherAqueductEnd(), ObjectScopeResolver::GetRandomBits(), ObjectScopeResolver::GetVariable(), GoalListWindow::HandleClick(), IsNeighborRoadTile(), MarkTileDirtyIfCanalOrRiver(), TileLoop_Water(), and VerifyElementContentParameters().

## ◆ SetAnimationFrame()

static void SetAnimationFrame | ( | TileIndex | t,
|  | byte | frame
| ) |  |
| inline static

Set a new animation frame.

Parameters

  t | the tile
  frame | the new frame number

Precondition
  IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION)

Definition at line 255 of file tile_map.h.

Referenced by AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::ChangeAnimationFrame(), and IncreaseAnimationStage().

## ◆ SetTileHeight()

static void SetTileHeight | ( | TileIndex | tile,
|  | uint | height
| ) |  |
| inline static

Sets the height of a tile.

This function sets the height of the northern corner of a tile.

Parameters

  tile | The tile to change the height
  height | The new height value of the tile

Precondition
  tile < MapSize()
  heigth <= MAX_TILE_HEIGHT

Definition at line 49 of file tile_map.h.

Referenced by FlatEmptyWorld(), MakeVoid(), and TgenSetTileHeight().

## ◆ SetTileOwner()

static void SetTileOwner | ( | TileIndex | tile,
|  | Owner | owner
| ) |  |
| inline static

Sets the owner of a tile.

This function sets the owner status of a tile. Note that you cannot set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY.

Parameters

  tile | The tile to change the owner status.
  owner | The new owner.

Precondition
  IsValidTile(tile)
  The type of the tile must not be MP_HOUSE and MP_INDUSTRY

Definition at line 191 of file tile_map.h.

Referenced by MakeBridgeRamp(), MakeClear(), MakeField(), MakeLockTile(), MakeObject(), MakeRailTunnel(), MakeRoadCrossing(), MakeRoadDepot(), MakeRoadNormal(), MakeRoadTunnel(), MakeShipDepot(), MakeShore(), MakeStation(), MakeTree(), and MakeWater().

## ◆ SetTileType()

static void SetTileType | ( | TileIndex | tile,
|  | TileType | type
| ) |  |
| inline static

Set the type of a tile.

This functions sets the type of a tile. If the type MP_VOID is selected the tile must be at the south-west or south-east edges of the map and vice versa.

Parameters

  tile | The tile to save the new type
  type | The type to save

Precondition
  tile < MapSize()
  type MP_VOID <=> tile is on the south-east or south-west edge.

Definition at line 124 of file tile_map.h.

Referenced by MakeBridgeRamp(), MakeClear(), MakeField(), MakeIndustry(), MakeLockTile(), MakeObject(), MakeRailTunnel(), MakeRoadCrossing(), MakeRoadDepot(), MakeRoadNormal(), MakeRoadTunnel(), MakeShipDepot(), MakeShore(), MakeStation(), MakeTree(), MakeVoid(), and MakeWater().

## ◆ SetTropicZone()

static void SetTropicZone | ( | TileIndex | tile,
|  | TropicZone | type
| ) |  |
| inline static

Set the tropic zone.

Parameters

  tile | the tile to set the zone of
  type | the new type

Precondition
  tile < MapSize()

Definition at line 218 of file tile_map.h.

Referenced by RiverModifyDesertZone().

## ◆ TileHash()

static uint TileHash | ( | uint | x,
|  | uint | y
| ) |  |
| inline static

Calculate a hash value from a tile position.

Parameters

  x | The X coordinate
  y | The Y coordinate

Returns
  The hash of the tile

Definition at line 314 of file tile_map.h.

Referenced by Town::InitializeLayout(), and River_Hash().

## ◆ TileHash2Bit()

static uint TileHash2Bit | ( | uint | x,
|  | uint | y
| ) |  |
| inline static

Get the last two bits of the TileHash from a tile position.

See also
  TileHash()

Parameters

  x | The X coordinate
  y | The Y coordinate

Returns
  The last two bits from hash of the tile

Definition at line 332 of file tile_map.h.

Referenced by HouseScopeResolver::GetVariable().

## ◆ TileHeight()

static uint TileHeight | ( | TileIndex | tile | ) |
| inline static

Returns the height of a tile.

This function returns the height of the northern corner of a tile. This is saved in the global map-array. It does not take affect by any slope-data of the tile.

Parameters

  tile | The tile to get the height from

Returns
  the height of the tile

Precondition
  tile < MapSize()

Definition at line 31 of file tile_map.h.

Referenced by CheckIfCanLevelIndustryPlatform(), ClampXYToMap(), ClickChangeMaxHlCheat(), CmdLevelLand(), CmdTerraformLand(), GetTileHeightBelowAircraft(), GetTileMaxZ(), GetTileZ(), MarkBridgeDirty(), TerraformGetHeightOfTile(), and TilePixelHeight().

## ◆ TileHeightOutsideMap()

uint TileHeightOutsideMap | ( | int | x,
|  | int | y
| ) |  |

Returns the tile height for a coordinate outside map.

Such a height is needed for painting the area outside map using completely black tiles. The idea is descending to heightlevel 0 as fast as possible.

Parameters

  x | The X-coordinate (same unit as TileX).
  y | The Y-coordinate (same unit as TileY).

Returns
  The height in the same unit as TileHeight.

Definition at line 25 of file tile_map.cpp.

Referenced by GetTileMaxZ().

## ◆ TilePixelHeight()

static uint TilePixelHeight | ( | TileIndex | tile | ) |
| inline static

Returns the height of a tile in pixels.

This function returns the height of the northern corner of a tile in pixels.

Parameters

  tile | The tile to get the height

Returns
  The height of the tile in pixel

Definition at line 64 of file tile_map.h.

References TILE_HEIGHT, and TileHeight().

Referenced by MarkTileDirtyByTile(), and SetupScreenshotViewport().

## ◆ TilePixelHeightOutsideMap()

static uint TilePixelHeightOutsideMap | ( | int | x,
|  | int | y
| ) |  |
| inline static

Returns the tile height for a coordinate outside map.

Such a height is needed for painting the area outside map using completely black tiles. The idea is descending to heightlevel 0 as fast as possible.

Parameters

  x | The X-coordinate (same unit as TileX).
  y | The Y-coordinate (same unit as TileY).

Returns
  The height in pixels in the same unit as TilePixelHeight.

Definition at line 77 of file tile_map.h.

Referenced by GetViewportY(), and MarkTileDirtyByTileOutsideMap().