TileMap

class TileMap

An Unciv map with all properties as produced by the map editor or MapGenerator; or as part of a running game.

Note: Will be Serialized -> Take special care with lateinit and lazy!

Constructors

TileMap
Link copied to clipboard
fun TileMap()

for json parsing, we need to have a default constructor

TileMap
Link copied to clipboard
fun TileMap(radius: Int, ruleset: Ruleset, worldWrap: Boolean = false)

creates a hexagonal map of given radius (filled with grassland)

TileMap
Link copied to clipboard
fun TileMap(width: Int, height: Int, ruleset: Ruleset, worldWrap: Boolean = false)

creates a rectangular map of given width and height (filled with grassland)

Types

AssignContinentsMode
Link copied to clipboard
enum AssignContinentsMode : Enum<TileMap.AssignContinentsMode>

Behaviour of assignContinents

Companion
Link copied to clipboard
object Companion
StartingLocation
Link copied to clipboard
private data class StartingLocation(position: Vector2, nation: String)

Structure geared for simple serialization by Gdx.Json (which is a little blind to kotlin collections, especially HashSet)

Functions

addStartingLocation
Link copied to clipboard
fun addStartingLocation(nationName: String, tile: TileInfo): Boolean

Adds a starting position, maintaining the transients

assignContinents
Link copied to clipboard
fun assignContinents(mode: TileMap.AssignContinentsMode)

Set a continent id for each tile, so we can quickly see which tiles are connected. Can also be called on saved maps.

clearStartingLocations
Link copied to clipboard
fun clearStartingLocations()

Clears starting positions, e.g. after GameStarter is done with them. Does not clear the pseudo-improvements.

clone
Link copied to clipboard
fun clone(): TileMap
contains
Link copied to clipboard
operator fun contains(vector: Vector2): Boolean
fun contains(x: Int, y: Int): Boolean
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
get
Link copied to clipboard
operator fun get(vector: Vector2): TileInfo
operator fun get(x: Int, y: Int): TileInfo
getClockPositionNeighborTile
Link copied to clipboard
fun getClockPositionNeighborTile(tile: TileInfo, clockPosition: Int): TileInfo?

Returns the neighbor tile of tile at clockPosition, if it exists. Takes world wrap into account Returns null if there is no such neighbor tile or if clockPosition is not a valid clock position

getIfTileExistsOrNull
Link copied to clipboard
fun getIfTileExistsOrNull(x: Int, y: Int): TileInfo?
getNeighborTileClockPosition
Link copied to clipboard
fun getNeighborTileClockPosition(tile: TileInfo, otherTile: TileInfo): Int

Returns the clock position of otherTile seen from tile's position Returns -1 if not neighbors

getNeighborTilePositionAsWorldCoords
Link copied to clipboard
fun getNeighborTilePositionAsWorldCoords(tile: TileInfo, otherTile: TileInfo): Vector2

Convert relative direction of otherTile seen from tile's position into a vector in world coordinates of length sqrt(3), so that it can be used to go from tile center to the edge of the hex in that direction (meaning the center of the border between the hexes)

getOrNull
Link copied to clipboard
private fun getOrNull(x: Int, y: Int): TileInfo?
getRulesetIncompatibility
Link copied to clipboard
fun getRulesetIncompatibility(ruleset: Ruleset): HashSet<String>

Build a list of incompatibilities of a map with a ruleset for the new game loader

getTilesAtDistance
Link copied to clipboard
fun getTilesAtDistance(origin: Vector2, distance: Int): Sequence<TileInfo>
getTilesInDistance
Link copied to clipboard
fun getTilesInDistance(origin: Vector2, distance: Int): Sequence<TileInfo>
getTilesInDistanceRange
Link copied to clipboard
fun getTilesInDistanceRange(origin: Vector2, range: IntRange): Sequence<TileInfo>
getTilesInRectangle
Link copied to clipboard
fun getTilesInRectangle(rectangle: Rectangle, evenQ: Boolean = false): Sequence<TileInfo>
getUnWrappedPosition
Link copied to clipboard
fun getUnWrappedPosition(position: Vector2): Vector2

Returns the closest position to (0, 0) outside the map which can be wrapped to the position of the given vector

getViewableTiles
Link copied to clipboard
fun getViewableTiles(position: Vector2, sightDistance: Int): List<TileInfo>
hashCode
Link copied to clipboard
open fun hashCode(): Int
isWaterMap
Link copied to clipboard
fun isWaterMap(): Boolean
placeUnitNearTile
Link copied to clipboard
fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit?

Tries to place the unitName into the TileInfo closest to the given position

removeMissingTerrainModReferences
Link copied to clipboard
fun removeMissingTerrainModReferences(ruleSet: Ruleset)
removeStartingLocation
Link copied to clipboard
fun removeStartingLocation(nationName: String, tile: TileInfo): Boolean

Removes a starting position, maintaining the transients

removeStartingLocations
Link copied to clipboard
fun removeStartingLocations(nationName: String)

Removes all starting positions for nationName, maintaining the transients

setStartingLocationsTransients
Link copied to clipboard
fun setStartingLocationsTransients()

Initialize startingLocations transients, including legacy support (maps saved with placeholder improvements)

setTransients
Link copied to clipboard
fun setTransients(ruleset: Ruleset? = null, setUnitCivTransients: Boolean = true)

Initialize transients - without, most operations, like get from coordinates, will fail.

stripAllUnits
Link copied to clipboard
fun stripAllUnits(): TileMap

Strips all units from TileMap

stripPlayer
Link copied to clipboard
fun stripPlayer(player: Player)

Strips all units and starting locations from TileMap for specified Player Operation in place

switchPlayersNation
Link copied to clipboard
fun switchPlayersNation(player: Player, newNation: Nation)

Finds all units and starting location of Player and changes their Nation Operation in place

toString
Link copied to clipboard
open fun toString(): String
translateStartingLocationsFromMap
Link copied to clipboard
private fun translateStartingLocationsFromMap()

Scan and remove placeholder improvements from map and build startingLocations from them

Properties

bottomY
Link copied to clipboard
var bottomY: Int = 0
continentSizes
Link copied to clipboard
val continentSizes: HashMap<Int, Int>
gameInfo
Link copied to clipboard
lateinit var gameInfo: GameInfo

Attention: lateinit will stay uninitialized while in MapEditorScreen!

leftX
Link copied to clipboard
var leftX: Int = 0
mapParameters
Link copied to clipboard
var mapParameters: MapParameters
maxLatitude
Link copied to clipboard
val maxLatitude: Float
maxLongitude
Link copied to clipboard
val maxLongitude: Float
naturalWonders
Link copied to clipboard
val naturalWonders: List<String>
resources
Link copied to clipboard
val resources: List<String>
ruleset
Link copied to clipboard
var ruleset: Ruleset? = null

Keep a copy of the Ruleset object passed to setTransients, for now only to allow subsequent setTransients without. Copied on clone.

startingLocations
Link copied to clipboard
private val startingLocations: ArrayList<TileMap.StartingLocation>
startingLocationsByNation
Link copied to clipboard
tileList
Link copied to clipboard
private var tileList: ArrayList<TileInfo>
tileMatrix
Link copied to clipboard
var tileMatrix: ArrayList<ArrayList<TileInfo?>>
values
Link copied to clipboard
val values: Collection<TileInfo>

Sources

jvm source
Link copied to clipboard