mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
Merge pull request #661 from ninjatao/maptype_continents
Maptype continents
This commit is contained in:
commit
1840793464
@ -8,14 +8,12 @@ import com.unciv.models.gamebasics.tile.TerrainType
|
|||||||
import com.unciv.models.gamebasics.tile.TileResource
|
import com.unciv.models.gamebasics.tile.TileResource
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
import kotlin.math.abs
|
import kotlin.math.*
|
||||||
import kotlin.math.ceil
|
|
||||||
import kotlin.math.pow
|
|
||||||
import kotlin.math.sin
|
|
||||||
|
|
||||||
enum class MapType {
|
enum class MapType {
|
||||||
Perlin,
|
Perlin,
|
||||||
Default,
|
Default,
|
||||||
|
Continents,
|
||||||
Pangaea,
|
Pangaea,
|
||||||
File
|
File
|
||||||
}
|
}
|
||||||
@ -28,7 +26,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
|||||||
|
|
||||||
constructor(type: MapType): this() {
|
constructor(type: MapType): this() {
|
||||||
mapType = type
|
mapType = type
|
||||||
if (mapType != MapType.Default && mapType !=MapType.Pangaea) {
|
if (mapType != MapType.Default && mapType !=MapType.Pangaea && mapType !=MapType.Continents) {
|
||||||
mapType = MapType.Default
|
mapType = MapType.Default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,6 +57,12 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
|||||||
landscape[vector] = TerrainType.Water
|
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>()
|
val map = HashMap<Vector2, TileInfo>()
|
||||||
@ -82,11 +86,25 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
|||||||
return mapToReturn
|
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 {
|
private fun generateInitTerrain(vector: Vector2, distance: Int): TerrainType {
|
||||||
val type: TerrainType
|
val type: TerrainType
|
||||||
if (mapType == MapType.Pangaea) {
|
if (mapType == MapType.Pangaea) {
|
||||||
val distanceFactor = (HexMath().getDistance(Vector2.Zero, vector) * 1.8 / distance).toFloat()
|
val distanceFactor = (HexMath().getDistance(Vector2.Zero, vector) * 1.8 / distance).toFloat()
|
||||||
type = if (Random().nextDouble() < landProb.pow(distanceFactor)) TerrainType.Land else TerrainType.Water
|
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
|
} else { //default
|
||||||
if (HexMath().getDistance(Vector2.Zero, vector) > 0.9f * distance)
|
if (HexMath().getDistance(Vector2.Zero, vector) > 0.9f * distance)
|
||||||
type = if (Random().nextDouble() < 0.1) TerrainType.Land else TerrainType.Water
|
type = if (Random().nextDouble() < 0.1) TerrainType.Land else TerrainType.Water
|
||||||
|
Loading…
x
Reference in New Issue
Block a user