Merge pull request #661 from ninjatao/maptype_continents

Maptype continents
This commit is contained in:
Yair Morgenstern 2019-04-19 16:45:51 +03:00 committed by GitHub
commit 1840793464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,14 +8,12 @@ import com.unciv.models.gamebasics.tile.TerrainType
import com.unciv.models.gamebasics.tile.TileResource
import java.util.*
import kotlin.collections.HashMap
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.pow
import kotlin.math.sin
import kotlin.math.*
enum class MapType {
Perlin,
Default,
Continents,
Pangaea,
File
}
@ -28,7 +26,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
constructor(type: MapType): this() {
mapType = type
if (mapType != MapType.Default && mapType !=MapType.Pangaea) {
if (mapType != MapType.Default && mapType !=MapType.Pangaea && mapType !=MapType.Continents) {
mapType = MapType.Default
}
}
@ -59,6 +57,12 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
landscape[vector] = TerrainType.Water
}
}
if (mapType == MapType.Continents) { //keep a ocean column in the middle
for (y in -distance..distance) {
landscape[Vector2((y/2).toFloat(), y.toFloat())] = TerrainType.Water
landscape[Vector2((y/2+1).toFloat(), y.toFloat())] = TerrainType.Water
}
}
}
val map = HashMap<Vector2, TileInfo>()
@ -82,11 +86,25 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
return mapToReturn
}
private fun getDistanceWeightForContinents(origin: Vector2, destination: Vector2): Float {
val relative_x = 2*(origin.x-destination.x)
val relative_y = origin.y-destination.y
if (relative_x * relative_y >= 0)
return max(abs(relative_x),abs(relative_y))
else
return (abs(relative_x) + abs(relative_y))
}
private fun generateInitTerrain(vector: Vector2, distance: Int): TerrainType {
val type: TerrainType
if (mapType == MapType.Pangaea) {
val distanceFactor = (HexMath().getDistance(Vector2.Zero, vector) * 1.8 / distance).toFloat()
type = if (Random().nextDouble() < landProb.pow(distanceFactor)) TerrainType.Land else TerrainType.Water
} else if (mapType == MapType.Continents) {
val distanceWeight = min(getDistanceWeightForContinents(Vector2(distance.toFloat()/2, 0f), vector),
getDistanceWeightForContinents(Vector2(-distance.toFloat()/2, 0f), vector))
val distanceFactor = (distanceWeight * 1.8 / distance).toFloat()
type = if (Random().nextDouble() < landProb.pow(distanceFactor)) TerrainType.Land else TerrainType.Water
} else { //default
if (HexMath().getDistance(Vector2.Zero, vector) > 0.9f * distance)
type = if (Random().nextDouble() < 0.1) TerrainType.Land else TerrainType.Water