OpenTTD Source  20241124-master-g9399a92a4f
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 More...
 
static debug_inline uint LogX ()
 Logarithm of the map size along the X side. More...
 
static uint LogY ()
 Logarithm of the map size along the y side. More...
 
static debug_inline uint SizeX ()
 Get the size of the map along the X. More...
 
static uint SizeY ()
 Get the size of the map along the Y. More...
 
static debug_inline uint Size ()
 Get the size of the map. More...
 
static debug_inline uint MaxX ()
 Gets the maximum X coordinate within the map, including MP_VOID. More...
 
static uint MaxY ()
 Gets the maximum Y coordinate within the map, including MP_VOID. More...
 
static TileIndex WrapToMap (TileIndex tile)
 'Wraps' the given "tile" so it is within the map. More...
 
static uint ScaleBySize (uint n)
 Scales the given value by the map size, where the given value is for a 256 by 256 map. More...
 
static uint ScaleBySize1D (uint n)
 Scales the given value by the maps circumference, where the given value is for a 256 by 256 map. More...
 
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. More...
 
static IterateWrapper Iterate ()
 Returns an iterable ensemble of all Tiles. More...
 

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 IsInsideMM(), MAX_MAP_SIZE, MIN_MAP_SIZE, size_x, and size_y.

◆ 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()

static IterateWrapper Map::Iterate ( )
inlinestatic

Returns an iterable ensemble of all Tiles.

Returns
an iterable ensemble of all Tiles

Definition at line 363 of file map_func.h.

◆ 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.

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

◆ 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()

static debug_inline uint Map::MaxX ( )
inlinestatic

◆ MaxY()

static uint Map::MaxY ( )
inlinestatic

◆ 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(), 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().

◆ 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.

Referenced by AfterLoadCompanyStats(), CalculateCoverageLine(), OrthogonalTileArea::ClampToMap(), ClickChangeMaxHlCheat(), CmdBuildCanal(), CmdBuildLongRoad(), CmdBuildObjectArea(), CmdClearArea(), CmdConvertRail(), CmdConvertRoad(), CmdLevelLand(), CmdPlantTree(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveFromRoadWaypoint(), CmdRemoveLongRoad(), CmdSignalTrackHelper(), CmdTerraformLand(), DiagonalTileArea::DiagonalTileArea(), CommandHelper< Tcmd, Tret(*)(DoCommandFlag, Targs...), true >::Do(), 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(), MarkDirtyAdjacentLevelCrossingTiles(), MoveWaypointsToBaseStations(), 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(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), UpdateHousesAndTowns(), UpdateLevelCrossing(), UpdateNearestTownForRoadTiles(), and Town::~Town().

◆ SizeX()

static debug_inline uint Map::SizeX ( )
inlinestatic

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

References size_y.

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

◆ 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 RandomTileSeed(), and SetupFarmFieldFence().


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