OpenTTD Source 20241224-master-gee860a5c8e
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 debug_inline uint LogX ()
 Logarithm of the map size along the X side.
 
static uint LogY ()
 Logarithm of the map size along the y side.
 
static debug_inline uint SizeX ()
 Get the size of the map along the X.
 
static uint SizeY ()
 Get the size of the map along the Y.
 
static debug_inline uint Size ()
 Get the size of the map.
 
static debug_inline 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 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)
 

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_xthe width of the map along the NE/SW edge
size_ythe 'height' of the map along the SE/NW edge

Definition at line 36 of file map.cpp.

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

Referenced by MAPSChunkHandler::Load().

◆ 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 354 of file map_func.h.

References Tile::base_tiles.

Referenced by CrashLog::WriteSavegame().

◆ Iterate()

◆ LogX()

static debug_inline 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 251 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 261 of file map_func.h.

References log_y.

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

◆ MaxX()

◆ MaxY()

◆ 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
nthe value to scale
Returns
the scaled size

Definition at line 328 of file map_func.h.

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

Referenced by CreateRivers(), DecrementTreeCounter(), IndustryBuildData::EconomyMonthlyLoop(), GenerateLandscape(), GenerateTowns(), GenerateTrees(), 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
nthe value to scale
Returns
the scaled size

Definition at line 341 of file map_func.h.

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

Referenced by ClampSmoothScroll(), and GetScaledIndustryGenerationProbability().

◆ Size()

static debug_inline uint Map::Size ( )
inlinestatic

Get the size of the map.

Returns
the number of tiles of the map

Definition at line 288 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(), DEF_CONSOLE_CMD(), DiagonalTileArea::DiagonalTileArea(), CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Do(), DrawStationCoverageAreaText(), DrawTile_Road(), FindStationsNearby(), 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()

◆ SizeY()

◆ 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
tilethe tile to 'wrap'

Definition at line 317 of file map_func.h.

References tile_mask.

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

Field Documentation

◆ log_x

uint Map::log_x
staticprivate

2^_map_log_x == _map_size_x

Definition at line 236 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 237 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 240 of file map_func.h.

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

◆ size_x

uint Map::size_x
staticprivate

Size of the map along the X.

Definition at line 238 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 239 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 241 of file map_func.h.

Referenced by Allocate(), and WrapToMap().


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