Skip to content

MapTile

A MapTile is one map tile. Get one with GetMapTile(x, y), GetAllMapTiles() or object:GetCurrentMapTile().

local tile = GetMapTile(40, 52)
if tile and tile:GetTerrain() == Terrain.WATER then
    LogInfo("water at", tile:GetPosition().x, tile:GetPosition().y)
end

Calling a method on something that is not a MapTile raises a Lua error.

Method Returns
GetPosition() Whole-number tile coordinates as a Vector2. Add 0.5 for the centre.
GetTerrain() A Terrain value. -1 when masked or unreadable.
IsForestTerrain() true for forest ground. nil, "terrain-forest-unavailable" if unreadable. Not masked.
GetElevation() Height level, 0 lowest. 0 when masked or unreadable.
GetTileVisibility() A TileVisibility value for the assigned player: VISIBLE, EXPLORED or UNEXPLORED. Not masked.
GetObjectCount() Objects registered on the tile. 0 when masked.
GetObjects() Those objects, including ones in fog. Empty when masked.
IsNavigatable() The engine's terrain navigation test. Not a walkability test: see below. IsWalkable() is the same call.

IsBuildable() exists but is not implemented.

Pitfalls

  • IsNavigatable() and IsWalkable() read false on plain, visible land. To test terrain, use GetPlacementTile(x, y): terrain flag 8 is water and its pathing flags mark blocked tiles. To test reachability, use CanReachPoint or object:GetNativeZoneAt.
  • A large building is registered on every tile it covers, so it counts on each.
  • GetObjects() includes enemies in fog. Check object:IsVisible() when your script must only use what the player can see.

The visibility mask

By default a tile the assigned player has never explored hides its contents: GetTerrain() returns -1, GetElevation() 0, IsNavigatable() false, GetObjectCount() 0 and GetObjects() an empty array. GetPosition(), GetTileVisibility() and IsForestTerrain() are never masked.

The mask is a shared setting. Turn it off only when your script is meant to see the whole map, because it changes every script:

Settings.Module("MapTile"):SetBool("UseVisibilityMask", false)

GetPlacementTile and the placement checks never apply the mask.