OpenTTD Source: Map Struct Reference

OpenTTD Source 15.0-RC2

Data Structures | Static Public Member Functions | Static Private Attributes
Map Struct Reference

Size related data of the map. More...

`#include <map_func.h>`

## Data Structures
struct | IterateWrapper
struct | Iterator
| Iterator to iterate all Tiles. More...

## Static Public Member Functions
static void | Allocate (uint size_x, uint size_y)
| (Re)allocates a map with the given dimension
static void | CountLandTiles ()
static uint | LogX ()
| Logarithm of the map size along the X side.
static uint | LogY ()
| Logarithm of the map size along the y side.
static uint | SizeX ()
| Get the size of the map along the X.
static uint | SizeY ()
| Get the size of the map along the Y.
static uint | Size ()
| Get the size of the map.
static uint | MaxX ()
| Gets the maximum X coordinate within the map, including MP_VOID.
static uint | MaxY ()
| Gets the maximum Y coordinate within the map, including MP_VOID.
static uint | ScaleByLandProportion (uint n)
| Scales the given value by the number of water tiles.
static TileIndex | WrapToMap (TileIndex tile)
| 'Wraps' the given "tile" so it is within the map.
static uint | ScaleBySize (uint n)
| Scales the given value by the map size, where the given value is for a 256 by 256 map.
static uint | ScaleBySize1D (uint n)
| Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
static bool | IsInitialized ()
| Check whether the map has been initialized, as to not try to save the map during crashlog when the map is not there yet.
static IterateWrapper | Iterate ()
| Returns an iterable ensemble of all Tiles.

## Static Private Attributes
static uint | log_x
| 2^_map_log_x == _map_size_x
static uint | log_y
| 2^_map_log_y == _map_size_y
static uint | size_x
| Size of the map along the X.
static uint | size_y
| Size of the map along the Y.
static uint | size
| The number of tiles on the map.
static uint | tile_mask
| _map_size - 1 (to mask the mapsize)
static uint | initial_land_count
| Initial number of land tiles on the map.

## Detailed Description

Size related data of the map.

Definition at line 206 of file map_func.h.

## Member Function Documentation

## ◆ Allocate()

void Map::Allocate | ( | uint | size_x,
|  | uint | size_y
| ) |  |
| static

(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 37 of file map.cpp.

References AllocateWaterRegions(), Tile::base_tiles, Debug, Tile::extended_tiles, FindFirstBit(), IsInsideMM(), log_x, log_y, MAX_MAP_SIZE, MIN_MAP_SIZE, size, size_x, size_y, and tile_mask.

Referenced by MAPSChunkHandler::Load().

## ◆ CountLandTiles()

void Map::CountLandTiles | ( |  | ) |
| static

Definition at line 63 of file map.cpp.

## ◆ IsInitialized()

static bool Map::IsInitialized | ( |  | ) |
| inlinestatic

Check whether the map has been initialized, as to not try to save the map during crashlog when the map is not there yet.

Returns
  true when the map has been allocated/initialized.

Definition at line 366 of file map_func.h.

References Tile::base_tiles.

Referenced by CrashLog::WriteSavegame().

## ◆ Iterate()

static IterateWrapper Map::Iterate | ( |  | ) |
| inlinestatic

Returns an iterable ensemble of all Tiles.

Returns
  an iterable ensemble of all Tiles

Definition at line 375 of file map_func.h.

Referenced by AfterLoadGame(), CalculateCoverageLine(), ChangeOwnershipOfCompanyItems(), ClickChangeMaxHlCheat(), CmdDeleteTown(), ConvertRailTypes(), ConvertRoadTypes(), GetClosestWaterDistance(), MakeHeightmapScreenshot(), MoveWaypointsToBaseStations(), RebuildTownCaches(), SetDefaultRailGui(), UpdateHousesAndTowns(), UpdateNearestTownForRoadTiles(), and Town::~Town().

## ◆ LogX()

static uint Map::LogX | ( |  | ) |
| inlinestatic

Logarithm of the map size along the X side.

Note
  try to avoid using this one

Returns
  2^"return value" == Map::SizeX()

Definition at line 253 of file map_func.h.

References log_x.

Referenced by HeightMapGenerate(), RunTileLoop(), ScaleBySize(), ScaleBySize1D(), StartupIndustryDailyChanges(), TGPGetMaxHeight(), TileVirtXY(), TileXY(), and TileY().

## ◆ LogY()

static uint Map::LogY | ( |  | ) |
| inlinestatic

Logarithm of the map size along the y side.

Note
  try to avoid using this one

Returns
  2^"return value" == Map::SizeY()

Definition at line 263 of file map_func.h.

References log_y.

Referenced by HeightMapGenerate(), RunTileLoop(), ScaleBySize(), ScaleBySize1D(), StartupIndustryDailyChanges(), and TGPGetMaxHeight().

## ◆ MaxX()

static uint Map::MaxX | ( |  | ) |
| inlinestatic

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

Returns
  the maximum X coordinate

Definition at line 299 of file map_func.h.

References SizeX().

Referenced by AfterLoadGame(), CalcRaildirsDrawstyle(), CheckIfCanLevelIndustryPlatform(), CmdBuildLock(), CmdBuildObject(), CmdBuildTunnel(), CreateEffectVehicleAbove(), DisasterTick_Aircraft(), DistanceFromEdgeDir(), SmallMapWindow::DrawSmallMapColumn(), FindStationsAroundSelection(), Station::GetCatchmentRect(), GetClosestWaterDistance(), GetTileHeightBelowAircraft(), GetTileMaxZ(), GetTileSlopeZ(), GetTileZ(), GUIPlaceProcDragXY(), HandleCrashedAircraft(), HeightmapCallback(), InverseRemapCoords2(), IsInnerTile(), IsTileFlat(), IsTunnelInWay(), LoadTownData(), BuildObjectWindow::OnPlaceMouseUp(), TerraformToolbarWindow::OnPlaceMouseUp(), SetAircraftPosition(), SmallMapWindow::SetNewScroll(), SetSelectionTilesDirty(), SetWaterClassDependingOnSurroundings(), TerraformTileHeight(), TileAddWrap(), TileHeightOutsideMap(), TileX(), TryBuildLightHouse(), and DisasterVehicle::UpdatePosition().

## ◆ MaxY()

static uint Map::MaxY | ( |  | ) |
| inlinestatic

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

Returns
  the maximum Y coordinate

Definition at line 308 of file map_func.h.

References SizeY().

Referenced by AfterLoadGame(), CalcRaildirsDrawstyle(), CheckIfCanLevelIndustryPlatform(), CmdBuildLock(), CmdBuildObject(), CreateEffectVehicleAbove(), DistanceFromEdgeDir(), SmallMapWindow::DrawSmallMapColumn(), FindStationsAroundSelection(), Station::GetCatchmentRect(), GetClosestWaterDistance(), GetTileHeightBelowAircraft(), GetTileMaxZ(), GetTileSlopeZ(), GetTileZ(), GUIPlaceProcDragXY(), HandleCrashedAircraft(), InverseRemapCoords2(), IsInnerTile(), IsTileFlat(), IsTunnelInWay(), LoadTownData(), BuildObjectWindow::OnPlaceMouseUp(), TerraformToolbarWindow::OnPlaceMouseUp(), SetAircraftPosition(), SmallMapWindow::SetNewScroll(), SetSelectionTilesDirty(), SetWaterClassDependingOnSurroundings(), TerraformTileHeight(), TileAddWrap(), TileHeightOutsideMap(), TryBuildLightHouse(), and DisasterVehicle::UpdatePosition().

## ◆ ScaleByLandProportion()

static uint Map::ScaleByLandProportion | ( | uint | n | ) |
| inlinestatic

Scales the given value by the number of water tiles.

Parameters

  n | the value to scale

Returns
  the scaled size

Definition at line 318 of file map_func.h.

References initial_land_count, and size.

Referenced by GenerateIndustries(), and GenerateTowns().

## ◆ ScaleBySize()

static uint Map::ScaleBySize | ( | 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 340 of file map_func.h.

References CeilDiv(), LogX(), and LogY().

Referenced by CreateRivers(), DecrementTreeCounter(), IndustryBuildData::EconomyMonthlyLoop(), GenerateLandscape(), GenerateTrees(), GetDefaultTownsForMapSize(), GetNumberOfIndustries(), GetScaledIndustryGenerationProbability(), and PlaceTreesRandomly().

## ◆ ScaleBySize1D()

static uint Map::ScaleBySize1D | ( | 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 353 of file map_func.h.

References CeilDiv(), LogX(), and LogY().

Referenced by ClampSmoothScroll(), and GetScaledIndustryGenerationProbability().

## ◆ Size()

static uint Map::Size | ( |  | ) |
| inlinestatic

Get the size of the map.

Returns
  the number of tiles of the map

Definition at line 290 of file map_func.h.

References size.

Referenced by CalculateCoverageLine(), OrthogonalTileArea::ClampToMap(), CmdBuildCanal(), CmdBuildLongRoad(), CmdBuildObjectArea(), CmdClearArea(), CmdConvertRail(), CmdConvertRoad(), CmdLevelLand(), CmdPlantTree(), CmdRailTrackHelper(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveFromRoadWaypoint(), CmdRemoveLongRoad(), CmdSignalTrackHelper(), CmdTerraformLand(), ConScrollToTile(), DiagonalTileArea::DiagonalTileArea(), CommandHelper< Tcmd, Tret(*)(DoCommandFlags, Targs...), true >::Do(), DrawStationCoverageAreaText(), DrawTile_Road(), 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(), MarkDirtyAdjacentLevelCrossingTiles(), DiagonalTileIterator::operator++(), 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(), SetupScreenshotViewport(), TerraformTileHeight(), TileHeight(), TryBuildLightHouse(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), and UpdateLevelCrossing().

## ◆ SizeX()

static uint Map::SizeX | ( |  | ) |
| inlinestatic

Get the size of the map along the X.

Returns
  the number of tiles along the X of the map

Definition at line 272 of file map_func.h.

References size_x.

Referenced by _GenerateWorld(), AddTileIndexDiffCWrap(), AllocHeightMap(), CheckScaledDistanceFromEdge(), OrthogonalTileArea::ClampToMap(), ConScrollToTile(), Disaster_Small_Ufo_Init(), DisasterTick_Aircraft(), DisasterTick_Big_Ufo_Destroyer(), DistanceFromEdge(), OrthogonalTileArea::Expand(), FixSlopes(), FlatEmptyWorld(), FlowRiver(), ForAllStationsRadius(), GenerateLandscape(), GenerateTerrainPerlin(), GenerateWorld(), GetSlopePixelZOutsideMap(), GreyscaleToMapHeights(), IsMapSurroundedByWater(), AirportSpec::IsWithinMapBounds(), MakeHeightmapScreenshot(), MakeMinimapWorldScreenshot(), MakeScreenshotWithConfirm(), MaxX(), DiagonalTileIterator::operator++(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), MAPSChunkHandler::Save(), ScrollWindowTo(), ServerNetworkAdminSocketHandler::SendWelcome(), SetSelectionTilesDirty(), SpiralTileIterator::SkipOutsideMap(), TileDiffXY(), and ViewportAddLandscape().

## ◆ SizeY()

static uint Map::SizeY | ( |  | ) |
| inlinestatic

Get the size of the map along the Y.

Returns
  the number of tiles along the Y of the map

Definition at line 281 of file map_func.h.

References size_y.

Referenced by _GenerateWorld(), AddTileIndexDiffCWrap(), AllocHeightMap(), CheckScaledDistanceFromEdge(), OrthogonalTileArea::ClampToMap(), ConScrollToTile(), Disaster_Small_Ufo_Init(), DisasterTick_Zeppeliner(), DistanceFromEdge(), OrthogonalTileArea::Expand(), FixSlopes(), FlatEmptyWorld(), FlowRiver(), ForAllStationsRadius(), GenerateLandscape(), GenerateTerrainPerlin(), GenerateWorld(), GetSlopePixelZOutsideMap(), GreyscaleToMapHeights(), IsMapSurroundedByWater(), AirportSpec::IsWithinMapBounds(), MakeHeightmapScreenshot(), MakeMinimapWorldScreenshot(), MakeScreenshotWithConfirm(), MaxY(), DiagonalTileIterator::operator++(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), MAPSChunkHandler::Save(), ScrollWindowTo(), ServerNetworkAdminSocketHandler::SendWelcome(), SetSelectionTilesDirty(), SpiralTileIterator::SkipOutsideMap(), and ViewportAddLandscape().

## ◆ WrapToMap()

static TileIndex Map::WrapToMap | ( | TileIndex | tile | ) |
| inlinestatic

'Wraps' the given "tile" so it is within the map.

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

Parameters

  tile | the tile to 'wrap'

Definition at line 329 of file map_func.h.

References tile_mask.

Referenced by GetNearbyTile(), HouseScopeResolver::GetVariable(), RandomTileSeed(), and SetupFarmFieldFence().

## Field Documentation

## ◆ initial_land_count

uint Map::initial_land_count
| staticprivate

Initial number of land tiles on the map.

Definition at line 242 of file map_func.h.

Referenced by ScaleByLandProportion().

## ◆ log_x

uint Map::log_x
| staticprivate

2^_map_log_x == _map_size_x

Definition at line 235 of file map_func.h.

Referenced by Allocate(), and LogX().

## ◆ log_y

uint Map::log_y
| staticprivate

2^_map_log_y == _map_size_y

Definition at line 236 of file map_func.h.

Referenced by Allocate(), and LogY().

## ◆ size

uint Map::size
| staticprivate

The number of tiles on the map.

Definition at line 239 of file map_func.h.

Referenced by Allocate(), MultiMap< Tkey, Tvalue, Tcompare >::MapSize(), ScaleByLandProportion(), and Size().

## ◆ size_x

uint Map::size_x
| staticprivate

Size of the map along the X.

Definition at line 237 of file map_func.h.

Referenced by Allocate(), and SizeX().

## ◆ size_y

uint Map::size_y
| staticprivate

Size of the map along the Y.

Definition at line 238 of file map_func.h.

Referenced by Allocate(), and SizeY().

## ◆ tile_mask

uint Map::tile_mask
| staticprivate

_map_size - 1 (to mask the mapsize)

Definition at line 240 of file map_func.h.

Referenced by Allocate(), and WrapToMap().

The documentation for this struct was generated from the following files:

- src/map_func.h
- src/map.cpp