Allow editor to generate rectangular Deciv redux maps (#6816)

This commit is contained in:
SomeTroglodyte 2022-05-15 14:49:51 +02:00 committed by GitHub
parent 049df797f3
commit 6021dcadb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,16 +95,16 @@ class TileMap {
/** creates a hexagonal map of given radius (filled with grassland) */
constructor(radius: Int, ruleset: Ruleset, worldWrap: Boolean = false) {
startingLocations.clear()
val firstAvailableLandTerrain = ruleset.terrains.values.firstOrNull { it.type==TerrainType.Land }
?: throw Exception("Cannot create map - no land terrains found!")
val firstAvailableLandTerrain = getInitializationTerrain(ruleset)
for (vector in HexMath.getVectorsInDistance(Vector2.Zero, radius, worldWrap))
tileList.add(TileInfo().apply { position = vector; baseTerrain = firstAvailableLandTerrain.name })
tileList.add(TileInfo().apply { position = vector; baseTerrain = firstAvailableLandTerrain })
setTransients(ruleset)
}
/** creates a rectangular map of given width and height (filled with grassland) */
constructor(width: Int, height: Int, ruleset: Ruleset, worldWrap: Boolean = false) {
startingLocations.clear()
val firstAvailableLandTerrain = getInitializationTerrain(ruleset)
// world-wrap maps must always have an even width, so round down
val wrapAdjustedWidth = if (worldWrap && width % 2 != 0) width -1 else width
@ -115,12 +115,16 @@ class TileMap {
for (y in -height / 2 .. (height-1) / 2)
tileList.add(TileInfo().apply {
position = HexMath.evenQ2HexCoords(Vector2(x.toFloat(), y.toFloat()))
baseTerrain = Constants.grassland
baseTerrain = firstAvailableLandTerrain
})
setTransients(ruleset)
}
private fun getInitializationTerrain(ruleset: Ruleset) =
ruleset.terrains.values.firstOrNull { it.type == TerrainType.Land }?.name
?: throw Exception("Cannot create map - no land terrains found!")
//endregion
//region Operators and Standards