mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 16:28:40 +07:00
Resolved #610 - map generation assigns a set amount of each Strategic resource, which are spread across the map
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.app"
|
applicationId "com.unciv.app"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 224
|
versionCode 225
|
||||||
versionName "2.14.4"
|
versionName "2.14.5"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Had to add this crap for Travis to build, it wanted to sign the app
|
// Had to add this crap for Travis to build, it wanted to sign the app
|
||||||
|
@ -17,7 +17,7 @@ class UnCivGame(val version: String) : Game() {
|
|||||||
* This exists so that when debugging we can see the entire map.
|
* This exists so that when debugging we can see the entire map.
|
||||||
* Remember to turn this to false before commit and upload!
|
* Remember to turn this to false before commit and upload!
|
||||||
*/
|
*/
|
||||||
val viewEntireMapForDebug = false
|
val viewEntireMapForDebug = true
|
||||||
|
|
||||||
// For when you need to test something in an advanced game and don't have time to faff around
|
// For when you need to test something in an advanced game and don't have time to faff around
|
||||||
val superchargedForDebug = false
|
val superchargedForDebug = false
|
||||||
|
@ -21,6 +21,7 @@ enum class MapType {
|
|||||||
File
|
File
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
||||||
var landProb = 0.55f
|
var landProb = 0.55f
|
||||||
var numSmooth = 4
|
var numSmooth = 4
|
||||||
@ -28,7 +29,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
|||||||
|
|
||||||
constructor(type: MapType): this() {
|
constructor(type: MapType): this() {
|
||||||
mapType = type
|
mapType = type
|
||||||
if (mapType < MapType.Default) {
|
if (mapType != MapType.Default && mapType !=MapType.Pangaea) {
|
||||||
mapType = MapType.Default
|
mapType = MapType.Default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,6 +78,8 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() {
|
|||||||
|
|
||||||
for(tile in mapToReturn.values) randomizeTile(tile,mapToReturn)
|
for(tile in mapToReturn.values) randomizeTile(tile,mapToReturn)
|
||||||
|
|
||||||
|
randomizeStrategicResources(mapToReturn,distance)
|
||||||
|
|
||||||
return mapToReturn
|
return mapToReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,6 +230,8 @@ class PerlinNoiseRandomMapGenerator:SeedRandomMapGenerator(){
|
|||||||
|
|
||||||
for(tile in mapToReturn.values) randomizeTile(tile,mapToReturn)
|
for(tile in mapToReturn.values) randomizeTile(tile,mapToReturn)
|
||||||
|
|
||||||
|
randomizeStrategicResources(mapToReturn,distance)
|
||||||
|
|
||||||
return mapToReturn
|
return mapToReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,6 +338,7 @@ open class SeedRandomMapGenerator : RandomMapGenerator() {
|
|||||||
for (entry in map) randomizeTile(entry.value, mapToReturn)
|
for (entry in map) randomizeTile(entry.value, mapToReturn)
|
||||||
|
|
||||||
setWaterTiles(mapToReturn)
|
setWaterTiles(mapToReturn)
|
||||||
|
randomizeStrategicResources(mapToReturn,distance)
|
||||||
return mapToReturn
|
return mapToReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,15 +363,6 @@ open class SeedRandomMapGenerator : RandomMapGenerator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expandAreas(areas, map)
|
expandAreas(areas, map)
|
||||||
|
|
||||||
// After we've assigned all the tiles, there will be some areas that contain only 1 or 2 tiles.
|
|
||||||
// So, we kill those areas, and have the world expand on and cover them too
|
|
||||||
// for (area in areas.toList()) {
|
|
||||||
// if (area.locations.size < 3) {
|
|
||||||
// areas -= area
|
|
||||||
// for (location in area.locations) map[location]!!.baseTerrain = ""
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
expandAreas(areas, map)
|
expandAreas(areas, map)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +447,7 @@ open class RandomMapGenerator {
|
|||||||
|
|
||||||
var resource: TileResource? = null
|
var resource: TileResource? = null
|
||||||
when {
|
when {
|
||||||
Math.random() < 1 / 5f -> resource = getRandomResource(tileResources, ResourceType.Bonus)
|
Math.random() < 1 / 15f -> resource = getRandomResource(tileResources, ResourceType.Bonus)
|
||||||
Math.random() < 1 / 15f -> resource = getRandomResource(tileResources, ResourceType.Strategic)
|
Math.random() < 1 / 15f -> resource = getRandomResource(tileResources, ResourceType.Strategic)
|
||||||
Math.random() < 1 / 15f -> resource = getRandomResource(tileResources, ResourceType.Luxury)
|
Math.random() < 1 / 15f -> resource = getRandomResource(tileResources, ResourceType.Luxury)
|
||||||
}
|
}
|
||||||
@ -504,4 +501,40 @@ open class RandomMapGenerator {
|
|||||||
addRandomResourceToTile(tileInfo)
|
addRandomResourceToTile(tileInfo)
|
||||||
maybeAddAncientRuins(tileInfo)
|
maybeAddAncientRuins(tileInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun randomizeStrategicResources(mapToReturn: HashMap<String, TileInfo>,distance: Int) {
|
||||||
|
for(tile in mapToReturn.values)
|
||||||
|
if(tile.resource!=null && tile.getTileResource().resourceType==ResourceType.Strategic)
|
||||||
|
tile.resource=null
|
||||||
|
|
||||||
|
for(resource in GameBasics.TileResources.values.filter { it.resourceType==ResourceType.Strategic }){
|
||||||
|
val suitableTiles = mapToReturn.values
|
||||||
|
.filter { it.resource==null && resource.terrainsCanBeFoundOn.contains(it.getLastTerrain().name) }
|
||||||
|
|
||||||
|
val numberOfResources = mapToReturn.count() / 100
|
||||||
|
|
||||||
|
val locations = chooseSpreadOutLocations(numberOfResources,suitableTiles, distance)
|
||||||
|
|
||||||
|
for(location in locations) location.resource = resource.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseSpreadOutLocations(numberOfResources: Int, suitableTiles: List<TileInfo>, initialDistance:Int): ArrayList<TileInfo> {
|
||||||
|
|
||||||
|
for(distanceBetweenResources in initialDistance downTo 1){
|
||||||
|
var availableTiles = suitableTiles.toList()
|
||||||
|
val chosenTiles = ArrayList<TileInfo>()
|
||||||
|
|
||||||
|
for(i in 1..numberOfResources){
|
||||||
|
if(availableTiles.isEmpty()) break
|
||||||
|
val chosenTile = availableTiles.random()
|
||||||
|
availableTiles = availableTiles.filter { it.arialDistanceTo(chosenTile)>distanceBetweenResources }
|
||||||
|
chosenTiles.add(chosenTile)
|
||||||
|
}
|
||||||
|
if(chosenTiles.size == numberOfResources) return chosenTiles
|
||||||
|
}
|
||||||
|
throw Exception("ArgleBargle")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -43,7 +43,6 @@ class TileMap {
|
|||||||
mapValues = CelluarAutomataRandomMapGenerator(newGameParameters.mapType).generateMap(newGameParameters.mapRadius).values
|
mapValues = CelluarAutomataRandomMapGenerator(newGameParameters.mapType).generateMap(newGameParameters.mapRadius).values
|
||||||
|
|
||||||
tileList.addAll(mapValues)
|
tileList.addAll(mapValues)
|
||||||
// tileList.addAll(AlexanderRandomMapGenerator().generateMap(distance,0.8f).values)
|
|
||||||
|
|
||||||
setTransients()
|
setTransients()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user