OpenTTD Source 20260206-master-g4d4e37dbf1
clear_map.h File Reference

Map accessors for 'clear' tiles. More...

#include "bridge_map.h"
#include "industry_type.h"

Go to the source code of this file.

Enumerations

enum class  ClearGround : uint8_t {
  Grass = 0 , Rough = 1 , Rocks = 2 , Fields = 3 ,
  Desert = 5 , End , MaxSize = 1U << CLEAR_GROUND_BITS
}
 Ground types. More...

Functions

bool IsSnowTile (Tile t)
 Test if a tile is covered with snow.
ClearGround GetClearGround (Tile t)
 Get the type of clear tile.
bool IsClearGround (Tile t, ClearGround ct)
 Set the type of clear tile.
uint GetClearDensity (Tile t)
 Get the density of a non-field clear tile.
void AddClearDensity (Tile t, int d)
 Increment the density of a non-field clear tile.
void SetClearDensity (Tile t, uint d)
 Set the density of a non-field clear tile.
uint GetClearCounter (Tile t)
 Get the counter used to advance to the next clear density/field type.
void AddClearCounter (Tile t, int c)
 Increments the counter used to advance to the next clear density/field type.
void SetClearCounter (Tile t, uint c)
 Sets the counter used to advance to the next clear density/field type.
void SetClearGroundDensity (Tile t, ClearGround type, uint density)
 Sets ground type and density in one go, also sets the counter to 0.
uint GetFieldType (Tile t)
 Get the field type (production stage) of the field.
void SetFieldType (Tile t, uint f)
 Set the field type (production stage) of the field.
IndustryID GetIndustryIndexOfField (Tile t)
 Get the industry (farm) that made the field.
void SetIndustryIndexOfField (Tile t, IndustryID i)
 Set the industry (farm) that made the field.
uint GetFence (Tile t, DiagDirection side)
 Is there a fence at the given border?
void SetFence (Tile t, DiagDirection side, uint h)
 Sets the type of fence (and whether there is one) for the given border.
void MakeClear (Tile t, ClearGround g, uint density)
 Make a clear tile.
void MakeField (Tile t, uint field_type, IndustryID industry)
 Make a (farm) field tile.
void MakeSnow (Tile t, uint density=0)
 Make a snow tile.
void ClearSnow (Tile t)
 Clear the snow from a tile and return it to its previous type.

Variables

static constexpr size_t CLEAR_GROUND_BITS = 3
 How many bits in map array are dedicated for clear ground type.

Detailed Description

Map accessors for 'clear' tiles.

Definition in file clear_map.h.

Enumeration Type Documentation

◆ ClearGround

enum class ClearGround : uint8_t
strong

Ground types.

Valid densities in comments after the enum.

Enumerator
Grass 

Plain grass with dirt transition (0-3).

Rough 

Rough mounds (3).

Rocks 

Rocks with snow transition (0-3).

Fields 

Farm fields (3).

Desert 

Desert with transition (1,3).

End 

End marker.

MaxSize 

The maximum possible number of clear ground types to be stored in map.

Definition at line 21 of file clear_map.h.

Function Documentation

◆ AddClearCounter()

void AddClearCounter ( Tile t,
int c )
inline

Increments the counter used to advance to the next clear density/field type.

Parameters
tthe tile to increment the counter of
cthe amount to increment the counter with
Precondition
IsTileType(t, TileType::Clear)

Definition at line 125 of file clear_map.h.

References Clear, IsTileType(), and Tile::m5().

◆ AddClearDensity()

void AddClearDensity ( Tile t,
int d )
inline

Increment the density of a non-field clear tile.

Parameters
tthe tile to increment the density of
dthe amount to increment the density with
Precondition
IsTileType(t, TileType::Clear)

Definition at line 88 of file clear_map.h.

References Clear, IsTileType(), and Tile::m5().

Referenced by TileLoopClearAlps().

◆ ClearSnow()

void ClearSnow ( Tile t)
inline

Clear the snow from a tile and return it to its previous type.

Parameters
tthe tile to clear of snow
Precondition
IsSnowTile(t)

Definition at line 309 of file clear_map.h.

References ClrBit(), IsSnowTile(), Tile::m3(), and SetClearDensity().

Referenced by TileLoopClearAlps().

◆ GetClearCounter()

uint GetClearCounter ( Tile t)
inline

Get the counter used to advance to the next clear density/field type.

Parameters
tthe tile to get the counter of
Precondition
IsTileType(t, TileType::Clear)
Returns
the value of the counter

Definition at line 113 of file clear_map.h.

References Clear, GB(), IsTileType(), and Tile::m5().

◆ GetClearDensity()

uint GetClearDensity ( Tile t)
inline

Get the density of a non-field clear tile.

Parameters
tthe tile to get the density of
Precondition
IsTileType(t, TileType::Clear)
Returns
the density

Definition at line 76 of file clear_map.h.

References Clear, GB(), IsTileType(), and Tile::m5().

Referenced by AfterLoadGame(), GetSmallMapVegetationPixels(), GetTerrainType(), PlantTreesOnTile(), and TileLoopClearAlps().

◆ GetClearGround()

ClearGround GetClearGround ( Tile t)
inline

Get the type of clear tile.

Parameters
tthe tile to get the clear ground type of
Precondition
IsTileType(t, TileType::Clear)
Returns
the ground type

Definition at line 52 of file clear_map.h.

References Clear, CLEAR_GROUND_BITS, GB(), IsTileType(), and Tile::m5().

Referenced by AfterLoadGame(), CmdPlantTree(), GetFieldType(), GetIndustryIndexOfField(), GetSmallMapVegetationPixels(), IsClearGround(), IsSuitableForFarmField(), MakeSnow(), PlantTreesOnTile(), SetFieldType(), SetIndustryIndexOfField(), and TownCanBePlacedHere().

◆ GetFence()

uint GetFence ( Tile t,
DiagDirection side )
inline

Is there a fence at the given border?

Parameters
tthe tile to check for fences
sidethe border to check
Precondition
IsClearGround(t, ClearGround::Fields)
Returns
0 if there is no fence, otherwise the fence type

Definition at line 214 of file clear_map.h.

References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, Fields, GB(), IsClearGround(), Tile::m3(), Tile::m4(), and Tile::m6().

Referenced by SetupFarmFieldFence().

◆ GetFieldType()

uint GetFieldType ( Tile t)
inline

Get the field type (production stage) of the field.

Parameters
tthe field to get the type of
Precondition
GetClearGround(t) == ClearGround::Fields
Returns
the field type

Definition at line 164 of file clear_map.h.

References Fields, GB(), GetClearGround(), and Tile::m3().

◆ GetIndustryIndexOfField()

IndustryID GetIndustryIndexOfField ( Tile t)
inline

Get the industry (farm) that made the field.

Parameters
tthe field to get creating industry of
Precondition
GetClearGround(t) == ClearGround::Fields
Returns
the industry that made the field

Definition at line 188 of file clear_map.h.

References Fields, GetClearGround(), and Tile::m2().

◆ IsClearGround()

bool IsClearGround ( Tile t,
ClearGround ct )
inline

Set the type of clear tile.

Parameters
tthe tile to set the clear ground type of
ctthe ground type
Precondition
IsTileType(t, TileType::Clear)

Definition at line 64 of file clear_map.h.

References GetClearGround().

Referenced by AfterLoadGame(), CanPlantTreesOnTile(), GetFence(), GetSmallMapVegetationPixels(), SetFence(), and SetupFarmFieldFence().

◆ IsSnowTile()

bool IsSnowTile ( Tile t)
inline

Test if a tile is covered with snow.

Parameters
tthe tile to check
Precondition
IsTileType(t, TileType::Clear)
Returns
whether the tile is covered with snow.

Definition at line 40 of file clear_map.h.

References Clear, HasBit(), IsTileType(), and Tile::m3().

Referenced by ClearSnow(), GetSmallMapVegetationPixels(), GetTerrainType(), IsSuitableForFarmField(), MakeSnow(), PlantTreesOnTile(), and TileLoopClearAlps().

◆ MakeClear()

void MakeClear ( Tile t,
ClearGround g,
uint density )
inline

Make a clear tile.

Parameters
tthe tile to make a clear tile
gthe type of ground
densitythe density of the grass/snow/desert etc

Definition at line 252 of file clear_map.h.

References Clear, Tile::m1(), Tile::m2(), Tile::m3(), Tile::m4(), Tile::m6(), Tile::m7(), Tile::m8(), OWNER_NONE, SetClearGroundDensity(), SetTileOwner(), and SetTileType().

Referenced by AfterLoadGame(), DoDryUp(), FixOwnerOfRailTrack(), FixSlopes(), GenerateRockyArea(), GreyscaleToMapHeights(), and TgenSetTileHeight().

◆ MakeField()

void MakeField ( Tile t,
uint field_type,
IndustryID industry )
inline

Make a (farm) field tile.

Parameters
tthe tile to make a farm field
field_typethe 'growth' level of the field
industrythe industry this tile belongs to

Definition at line 273 of file clear_map.h.

References Clear, Fields, Tile::m1(), Tile::m2(), Tile::m3(), Tile::m4(), Tile::m6(), Tile::m7(), Tile::m8(), OWNER_NONE, SB(), SetClearGroundDensity(), SetTileOwner(), and SetTileType().

◆ MakeSnow()

void MakeSnow ( Tile t,
uint density = 0 )
inline

Make a snow tile.

Parameters
tthe tile to make snowy
densityThe density of snowiness.
Precondition
!IsSnowTile(t)

Definition at line 293 of file clear_map.h.

References Fields, GetClearGround(), Grass, IsSnowTile(), Tile::m3(), SetBit(), SetClearDensity(), and SetClearGroundDensity().

Referenced by TileLoopClearAlps().

◆ SetClearCounter()

void SetClearCounter ( Tile t,
uint c )
inline

Sets the counter used to advance to the next clear density/field type.

Parameters
tthe tile to set the counter of
cthe amount to set the counter to
Precondition
IsTileType(t, TileType::Clear)

Definition at line 137 of file clear_map.h.

References Clear, IsTileType(), Tile::m5(), and SB().

◆ SetClearDensity()

void SetClearDensity ( Tile t,
uint d )
inline

Set the density of a non-field clear tile.

Parameters
tthe tile to set the density of
dthe new density
Precondition
IsTileType(t, TileType::Clear)

Definition at line 100 of file clear_map.h.

References Clear, IsTileType(), Tile::m5(), and SB().

Referenced by ClearSnow(), and MakeSnow().

◆ SetClearGroundDensity()

void SetClearGroundDensity ( Tile t,
ClearGround type,
uint density )
inline

Sets ground type and density in one go, also sets the counter to 0.

Parameters
tthe tile to set the ground type and density for
typethe new ground type of the tile
densitythe density of the ground tile
Precondition
IsTileType(t, TileType::Clear)

Definition at line 151 of file clear_map.h.

References Clear, IsTileType(), Tile::m5(), and to_underlying().

Referenced by AfterLoadGame(), MakeClear(), MakeField(), MakeSnow(), and MakeWetlands().

◆ SetFence()

void SetFence ( Tile t,
DiagDirection side,
uint h )
inline

Sets the type of fence (and whether there is one) for the given border.

Parameters
tthe tile to check for fences
sidethe border to check
h0 if there is no fence, otherwise the fence type
Precondition
IsClearGround(t, ClearGround::Fields)

Definition at line 233 of file clear_map.h.

References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, Fields, IsClearGround(), Tile::m3(), Tile::m4(), Tile::m6(), and SB().

Referenced by AfterLoadGame(), and SetupFarmFieldFence().

◆ SetFieldType()

void SetFieldType ( Tile t,
uint f )
inline

Set the field type (production stage) of the field.

Parameters
tthe field to get the type of
fthe field type
Precondition
GetClearGround(t) == ClearGround::Fields

Definition at line 176 of file clear_map.h.

References Fields, GetClearGround(), Tile::m3(), and SB().

◆ SetIndustryIndexOfField()

void SetIndustryIndexOfField ( Tile t,
IndustryID i )
inline

Set the industry (farm) that made the field.

Parameters
tthe field to get creating industry of
ithe industry that made the field
Precondition
GetClearGround(t) == ClearGround::Fields

Definition at line 200 of file clear_map.h.

References Fields, GetClearGround(), and Tile::m2().

Variable Documentation

◆ CLEAR_GROUND_BITS

size_t CLEAR_GROUND_BITS = 3
staticconstexpr

How many bits in map array are dedicated for clear ground type.

Definition at line 16 of file clear_map.h.

Referenced by GetClearGround().