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

Detailed Description

Map writing/reading functions for tiles.

Definition in file tile_map.h.


Function Documentation

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 228 of file tile_map.h.

References _me, IsTileType(), TileExtended::m7, MP_HOUSE, MP_INDUSTRY, MP_OBJECT, and MP_STATION.

Referenced by AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::AnimateTile(), StationScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), IndustryTileScopeResolver::GetVariable(), IndustriesScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), AirportTileScopeResolver::GetVariable(), and IncreaseAnimationStage().

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 280 of file tile_map.h.

References GetTileMaxZ(), and TILE_HEIGHT.

Referenced by DrawCatenary(), EnsureNoVehicleOnGround(), and SetSelectionTilesDirty().

int GetTileMaxZ ( TileIndex  t  ) 
static Owner GetTileOwner ( TileIndex  tile  )  [inline, static]
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 258 of file tile_map.h.

References GetTileSlope(), and TILE_HEIGHT.

Referenced by GetNearbyTileInformation().

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 270 of file tile_map.h.

References GetTileZ(), and TILE_HEIGHT.

Referenced by DrawCatenaryOnTunnel(), MarkTileDirtyByTile(), and SetSelectionTilesDirty().

Slope GetTileSlope ( TileIndex  tile,
int *  h 
)
static TileType GetTileType ( TileIndex  tile  )  [inline, static]
int GetTileZ ( TileIndex  tile  ) 
static TropicZone GetTropicZone ( TileIndex  tile  )  [inline, static]
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 87 of file tile_map.h.

References _settings_game, GameSettings::construction, ConstructionSettings::freeform_edges, MapSize(), TileX(), and TileY().

Referenced by GetTileSlope(), GrayscaleToMapHeights(), IsTileFlat(), SetTileType(), and TgenSetTileHeight().

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 67 of file tile_map.cpp.

References IsInnerTile(), MapSize(), TileDiffXY(), and TileHeight().

Referenced by AfterLoadGame(), CheckIfIndustryTilesAreFree(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildObject(), CmdBuildShipDepot(), DoBuildLock(), FindFurthestFromWater(), FindSpring(), FlowRiver(), GrowTown(), IsWateredTile(), MakeLake(), SetWaterClassDependingOnSurroundings(), TownCanBePlacedHere(), TryBuildLightHouse(), and TryBuildTransmitter().

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 192 of file tile_map.h.

References GetTileOwner().

Referenced by AfterLoadGame(), BuildObject(), CanEnterTileOwnerCheck(), ChangeOwnershipOfCompanyItems(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildObject(), CmdBuildVehicle(), CmdDeleteTown(), CmdDepotMassAutoReplace(), DoClearBridge(), DoClearTunnel(), DepotWindow::OnPaint(), RoadFindPathToDest(), and Town::~Town().

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 128 of file tile_map.h.

References GetTileType().

Referenced by AddClearCounter(), AddClearDensity(), AddNearbyStation(), AddTreeCount(), AddTreeCounter(), AddTreeGrowth(), AdjustTileh(), AfterLoadGame(), AmbientSoundEffectCallback(), Vehicle::BeginLoading(), CanBuildHouseHere(), CanEnterTile(), CanEnterTileOwnerCheck(), ChangeOwnershipOfCompanyItems(), CheckFlatLandRailStation(), CheckFlatLandRoadStop(), CheckIfIndustryTilesAreFree(), CheckNextTrainTile(), CheckSubsidised(), ClearPathReservation(), CmdBuildCanal(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildObject(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadStop(), CmdBuildSingleRail(), CmdPlantTree(), CmdRemoveRoadStop(), CmdReverseTrainDirection(), CmdTerraformLand(), CmdTurnRoadVeh(), CMSAMine(), CMSATree(), CMSAWater(), Train::Crash(), DecHouseProcessingTime(), DeleteLastWagon(), DisasterTick_Aircraft(), DoClearTownHouseHelper(), DoFloodTile(), DoTriggerIndustryTile(), DrawCatenaryRailway(), ExtendTrainReservation(), FindFurthestFromWater(), FindIndustryToDeliver(), FindNearestEmptyLand(), FindNearIndustryName(), FindRailStationEnd(), FindStationsAroundTiles(), FindStationsNearby(), FixOldVehicles(), FollowReservation(), FollowTrainReservation(), FreeTrainTrackReservation(), GetAnimationFrame(), GetAxisForNewWaypoint(), GetCleanHouseType(), GetCleanIndustryGfx(), GetClearCounter(), GetClearDensity(), GetClosestWaterDistance(), GetDockOffset(), GetEffectiveWaterClass(), GetHouseAge(), GetHouseBuildingStage(), GetHouseConstructionTick(), GetHouseProcessingTime(), GetHouseRandomBits(), GetHouseTriggers(), GetIndustryAnimationLoop(), GetIndustryConstructionCounter(), GetIndustryConstructionStage(), GetIndustryGfx(), GetIndustryIndex(), GetIndustryRandomBits(), GetIndustryTriggers(), GetIndustryType(), GetNearbyAirportTileInformation(), GetNearbyIndustryTileInformation(), GetNearbyObjectTileInformation(), GetNearbyTileInformation(), GetObjectIDAtOffset(), GetObjectIndex(), GetObjectRandomBits(), GetObjectType(), GetOtherTunnelBridgeEnd(), GetRailTileType(), ObjectScopeResolver::GetRandomBits(), IndustryTileScopeResolver::GetRandomBits(), HouseScopeResolver::GetRandomBits(), CanalScopeResolver::GetRandomBits(), GetRawClearGround(), GetRoadOwner(), GetRoadTileType(), GetStationAround(), GetStationGfx(), GetStationIndex(), GetStationTileRandomBits(), GetStationType(), GetTileOwner(), GetTownIndex(), GetTrainForReservation(), GetTreeCount(), GetTreeCounter(), GetTreeDensity(), GetTreeGround(), GetTreeGrowth(), GetTreeType(), IndustryTileScopeResolver::GetTriggers(), HouseScopeResolver::GetTriggers(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), ObjectScopeResolver::GetVariable(), IndustryTileScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), CanalScopeResolver::GetVariable(), GetWaterTileRandomBits(), GetWaterTileType(), GrowTown(), GrowTownAtRoad(), GrowTownInTile(), HasOnewaySignalBlockingTrackdir(), HasPbsSignalOnTrackdir(), HasStationTileRail(), HasTileWaterClass(), HasTunnelBridgeReservation(), HasTunnelBridgeSnowOrDesert(), IncHouseConstructionTick(), IncrementHouseAge(), IsAirportTile(), IsBridge(), IsBridgeTile(), IsBuoyTile(), IsCoastTile(), IsDockTile(), RoadStop::IsDriveThroughRoadStopContinuation(), IsHangar(), IsHangarTile(), IsHouseCompleted(), IsIndustryCompleted(), IsLevelCrossingTile(), IsNormalRoadTile(), IsObjectTypeTile(), IsPlainRailTile(), IsPossibleCrossing(), IsRailDepotTile(), IsRailStationTile(), IsRailWaypointTile(), IsRoadDepotTile(), IsRoadStop(), IsRoadStopTile(), IsSafeWaitingPosition(), IsShipDepotTile(), IsSnowTile(), IsTileForestIndustry(), IsTunnel(), IsTunnelTile(), IsValidTile(), IsValidTileForWaypoint(), IsWaitingPositionFree(), IsWateredTile(), IsWaterTile(), Vehicle::LeaveStation(), LoadUnloadVehicle(), MakeHouseTile(), MakeSingleHouseBigger(), MarkTileDirtyIfCanalOrRiver(), MayHaveBridgeAbove(), MoveBuoysToWaypoints(), MoveWaypointsToBaseStations(), CYapfCostRailT< Types >::PfCalcCost(), ProcessOrders(), RebuildTownCaches(), RemoveRoad(), ResetHouseAge(), ResetIndustryConstructionStage(), ReverseTrainDirection(), RoadFindPathToDest(), StationRect::ScanForStationTiles(), SearchLumberMillTrees(), SearchNearbyHouseClass(), SearchNearbyHouseGRFID(), SearchNearbyHouseID(), SearchTileForStatue(), SetAnimationFrame(), SetClearCounter(), SetClearDensity(), SetClearGroundDensity(), SetDefaultRailGui(), SetHouseCompleted(), SetHouseProcessingTime(), SetHouseRandomBits(), SetHouseTriggers(), SetHouseType(), SetIndustryAnimationLoop(), SetIndustryCompleted(), SetIndustryConstructionCounter(), SetIndustryConstructionStage(), SetIndustryGfx(), SetIndustryRandomBits(), SetIndustryTriggers(), SetRoadTypes(), SetStationGfx(), SetStationTileRandomBits(), SetTileOwner(), SetTownIndex(), SetTreeCounter(), SetTreeGroundDensity(), SetTreeGrowth(), IndustryTileScopeResolver::SetTriggers(), HouseScopeResolver::SetTriggers(), SetTropicZone(), SetTunnelBridgeReservation(), SetTunnelBridgeSnowOrDesert(), SetupFarmFieldFence(), Industry::TileBelongsToIndustry(), TileLoop_Water(), TownCanBePlacedHere(), TrainCanLeaveTile(), TrainController(), TriggerWatchedCargoCallbacks(), TryBuildLightHouse(), TryBuildTransmitter(), UpdateHousesAndTowns(), UpdateNearestTownForRoadTiles(), UpdateStatusAfterSwap(), UpdateTownCargoes(), and WatchedCargoCallback().

static bool IsValidTile ( TileIndex  tile  )  [inline, static]
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 240 of file tile_map.h.

References _me, IsTileType(), TileExtended::m7, MP_HOUSE, MP_INDUSTRY, MP_OBJECT, and MP_STATION.

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

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 47 of file tile_map.h.

References _m, MapSize(), MAX_TILE_HEIGHT, and SB().

Referenced by CmdTerraformLand(), FixSlopes(), FlatEmptyWorld(), GrayscaleToMapHeights(), MakeVoid(), and TgenSetTileHeight().

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 176 of file tile_map.h.

References _m, IsTileType(), IsValidTile(), MP_HOUSE, MP_INDUSTRY, and SB().

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

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 109 of file tile_map.h.

References _m, IsInnerTile(), MapSize(), MP_VOID, and SB().

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

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 203 of file tile_map.h.

References _m, IsTileType(), MapSize(), MP_VOID, SB(), and TROPICZONE_NORMAL.

Referenced by AfterLoadGame(), CmdPlantTree(), GenerateDesertArea(), and RiverModifyDesertZone().

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 293 of file tile_map.h.

Referenced by AfterLoadGame(), Town::InitializeLayout(), River_Hash(), and 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 311 of file tile_map.h.

References GB(), and TileHash().

Referenced by DrawTile_Town(), and HouseScopeResolver::GetVariable().

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.

References _m, GB(), and MapSize().

Referenced by AfterLoadGame(), AmbientSoundEffectCallback(), CalcHeightdiff(), CheckIfCanLevelIndustryPlatform(), CheckNewIndustry_OilRig(), CmdBuildCanal(), CmdLevelLand(), CmdTerraformLand(), CommonRaiseLowerBigLand(), TownViewWindow::DrawWidget(), FixSlopes(), FlowRiver(), TownViewWindow::GetDesiredInfoHeight(), GetSmallMapContoursPixels(), GetSmallMapIndustriesPixels(), GetSmallMapOwnerPixels(), GetTileMaxZ(), GetTileSlope(), GetTileZ(), HeightmapCallback(), IsTileFlat(), MakeLake(), TerraformGetHeightOfTile(), TilePixelHeight(), and UpdateTownGrowRate().

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 62 of file tile_map.h.

References TILE_HEIGHT, and TileHeight().

Referenced by SetupScreenshotViewport().