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

View File

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