mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
implement fun isHill() = baseTerrain == Constants.hill (#3128)
fixed isAdjacentToFreshwater - should also check for river on tile use fitsUniqueFilter instead of checking baseTerrain, terrainFeature and some other filters separately changes nothing but makes hill PR a lot more readable
This commit is contained in:
parent
7a7028e3a5
commit
044d04ab28
@ -214,9 +214,9 @@ object GameStarter {
|
||||
for (startBias in civ.nation.startBias) {
|
||||
if (startBias.startsWith("Avoid ")) {
|
||||
val tileToAvoid = startBias.removePrefix("Avoid [").removeSuffix("]")
|
||||
preferredTiles = preferredTiles.filter { it.baseTerrain != tileToAvoid && it.terrainFeature != tileToAvoid }
|
||||
preferredTiles = preferredTiles.filter { !it.fitsUniqueFilter(tileToAvoid) }
|
||||
} else if (startBias == Constants.coast) preferredTiles = preferredTiles.filter { it.isCoastalTile() }
|
||||
else preferredTiles = preferredTiles.filter { it.baseTerrain == startBias || it.terrainFeature == startBias }
|
||||
else preferredTiles = preferredTiles.filter { it.fitsUniqueFilter(startBias) }
|
||||
}
|
||||
|
||||
startingLocation = if (preferredTiles.isNotEmpty()) preferredTiles.random() else freeTiles.random()
|
||||
|
@ -206,10 +206,9 @@ class WorkerAutomation(val unit: MapUnit) {
|
||||
tile.terrainFeature == Constants.jungle -> Constants.tradingPost
|
||||
tile.terrainFeature == "Oasis" -> null
|
||||
tile.terrainFeature == Constants.forest -> "Lumber mill"
|
||||
tile.baseTerrain == Constants.hill -> "Mine"
|
||||
tile.isHill() -> "Mine"
|
||||
tile.baseTerrain in listOf(Constants.grassland,Constants.desert,Constants.plains) -> "Farm"
|
||||
tile.baseTerrain in listOf(Constants.tundra, Constants.snow)
|
||||
&& tile.isAdjacentToFreshwater -> "Farm"
|
||||
tile.isAdjacentToFreshwater -> "Farm"
|
||||
tile.baseTerrain in listOf(Constants.tundra, Constants.snow) -> Constants.tradingPost
|
||||
else -> null
|
||||
}
|
||||
@ -244,7 +243,6 @@ class WorkerAutomation(val unit: MapUnit) {
|
||||
(!isCitadel || tile.neighbors.all { it.getOwner() != civInfo })) ||
|
||||
!isAcceptableTileForFort(tile, civInfo)) return false
|
||||
|
||||
val isHills = tile.getBaseTerrain().name == Constants.hill
|
||||
// if this place is not perfect, let's see if there is a better one
|
||||
val nearestTiles = tile.getTilesInDistance(2).filter{it.owningCity?.civInfo == civInfo}.toList()
|
||||
for (closeTile in nearestTiles) {
|
||||
@ -254,7 +252,7 @@ class WorkerAutomation(val unit: MapUnit) {
|
||||
if (closeTile.improvement == Constants.fort || closeTile.improvement == Constants.citadel
|
||||
|| closeTile.improvementInProgress == Constants.fort) return false
|
||||
// there is another better tile for the fort
|
||||
if (!isHills && tile.getBaseTerrain().name == Constants.hill &&
|
||||
if (!tile.isHill() && closeTile.isHill() &&
|
||||
isAcceptableTileForFort(closeTile, civInfo)) return false
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ object BattleDamage {
|
||||
if (carrierDefenceBonus > 0) modifiers["Armor Plating"] = carrierDefenceBonus
|
||||
|
||||
for(unique in defender.unit.getMatchingUniques("+[]% defence in [] tiles")) {
|
||||
if (tile.baseTerrain == unique.params[1] || tile.terrainFeature == unique.params[1])
|
||||
if (tile.fitsUniqueFilter(unique.params[1]))
|
||||
modifiers["[${unique.params[1]}] defence"] = unique.params[0].toFloat() / 100
|
||||
}
|
||||
|
||||
@ -210,11 +210,11 @@ object BattleDamage {
|
||||
if(!tile.isFriendlyTerritory(unit.getCivInfo()) && unit.unit.hasUnique("+20% bonus outside friendly territory"))
|
||||
modifiers["Foreign Land"] = 0.2f
|
||||
|
||||
// This is to be deprecated and converted to "+[]% combat bonus in []" - keeping it here to that mods with this can still work for now
|
||||
// As of 3.10.6 This is to be deprecated and converted to "+[]% combat bonus in []" - keeping it here to that mods with this can still work for now
|
||||
if (unit.unit.hasUnique("+25% bonus in Snow, Tundra and Hills") &&
|
||||
(tile.baseTerrain == Constants.snow
|
||||
|| tile.baseTerrain == Constants.tundra
|
||||
|| tile.baseTerrain == Constants.hill) &&
|
||||
|| tile.isHill()) &&
|
||||
// except when there is a vegetation
|
||||
(tile.terrainFeature != Constants.forest
|
||||
|| tile.terrainFeature != Constants.jungle))
|
||||
@ -229,17 +229,14 @@ object BattleDamage {
|
||||
.any { it.hasUnique("-10% combat strength for adjacent enemy units") && it.civInfo.isAtWarWith(unit.getCivInfo()) })
|
||||
modifiers["Haka War Dance"] = -0.1f
|
||||
|
||||
// This is to be deprecated and converted to "+[]% combat bonus in []" - keeping it here to that mods with this can still work for now
|
||||
// As of 3.10.6 This is to be deprecated and converted to "+[]% combat bonus in []" - keeping it here to that mods with this can still work for now
|
||||
if(unit.unit.hasUnique("+33% combat bonus in Forest/Jungle")
|
||||
&& (tile.terrainFeature== Constants.forest || tile.terrainFeature==Constants.jungle))
|
||||
modifiers[tile.terrainFeature!!]=0.33f
|
||||
|
||||
for (unique in unit.unit.getUniques().filter { it.placeholderText == "+[]% combat bonus in []" })
|
||||
if (tile.terrainFeature == unique.params[1])
|
||||
modifiers[tile.terrainFeature!!] = unique.params[0].toFloat() / 100
|
||||
else if (tile.baseTerrain == unique.params[1]
|
||||
&& tile.terrainFeature == null)
|
||||
modifiers[tile.baseTerrain] = unique.params[0].toFloat() / 100
|
||||
if (tile.getLastTerrain().name == unique.params[1])
|
||||
modifiers[unique.params[1]] = unique.params[0].toFloat() / 100
|
||||
|
||||
val isRoughTerrain = tile.isRoughTerrain()
|
||||
for (BDM in getBattleDamageModifiersOfUnit(unit.unit)) {
|
||||
|
@ -38,7 +38,7 @@ class CityCombatant(val city: CityInfo) : ICombatant {
|
||||
if(city.isCapital()) strength+=2f
|
||||
strength += (city.population.population/5) * 2 // Each 5 pop gives 2 defence
|
||||
val cityTile = city.getCenterTile()
|
||||
if(cityTile.baseTerrain== Constants.hill) strength+=5
|
||||
if (cityTile.isHill()) strength += 5
|
||||
// as tech progresses so does city strength
|
||||
val techCount = getCivInfo().gameInfo.ruleSet.technologies.count()
|
||||
val techsPercentKnown: Float = if(techCount>0) city.civInfo.tech.techsResearched.count().toFloat() / techCount else 0.5f // for mods with no tech
|
||||
|
@ -49,7 +49,7 @@ class CivInfoStats(val civInfo: CivilizationInfo){
|
||||
for (city in civInfo.cities) {
|
||||
for (tile in city.getTiles()) {
|
||||
if (tile.isCityCenter()) continue
|
||||
if(ignoreHillTiles && tile.baseTerrain==Constants.hill) continue
|
||||
if (ignoreHillTiles && tile.isHill()) continue
|
||||
val tileUpkeep =
|
||||
when (tile.roadStatus) {
|
||||
RoadStatus.Road -> 1
|
||||
|
@ -168,7 +168,7 @@ class MapUnit {
|
||||
if (isEmbarked() && civInfo.hasUnique("+1 Sight when embarked"))
|
||||
visibilityRange += 1
|
||||
val tile = getTile()
|
||||
if (tile.baseTerrain == Constants.hill && type.isLandUnit()) visibilityRange += 1
|
||||
if (tile.isHill() && type.isLandUnit()) visibilityRange += 1
|
||||
|
||||
viewableTiles = tile.getViewableTilesList(visibilityRange)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ open class TileInfo {
|
||||
// This will be called often - farm can be built on Hill and tundra if adjacent to fresh water
|
||||
// and farms on adjacent to fresh water tiles will have +1 additional Food after researching Civil Service
|
||||
@delegate:Transient
|
||||
val isAdjacentToFreshwater: Boolean by lazy { fitsUniqueFilter("Fresh water") || neighbors.any { it.fitsUniqueFilter("Fresh water") } }
|
||||
val isAdjacentToFreshwater: Boolean by lazy { fitsUniqueFilter("River") || fitsUniqueFilter("Fresh water") || neighbors.any { it.fitsUniqueFilter("Fresh water") } }
|
||||
|
||||
var militaryUnit: MapUnit? = null
|
||||
var civilianUnit: MapUnit? = null
|
||||
@ -44,6 +44,8 @@ open class TileInfo {
|
||||
var roadStatus = RoadStatus.None
|
||||
var turnsToImprovement: Int = 0
|
||||
|
||||
fun isHill() = baseTerrain == Constants.hill
|
||||
|
||||
var hasBottomRightRiver = false
|
||||
var hasBottomRiver = false
|
||||
var hasBottomLeftRiver = false
|
||||
@ -129,7 +131,7 @@ open class TileInfo {
|
||||
|
||||
fun getHeight(): Int {
|
||||
if (baseTerrain == Constants.mountain) return 4
|
||||
if (baseTerrain == Constants.hill) return 2
|
||||
if (isHill()) return 2
|
||||
if (terrainFeature == Constants.forest || terrainFeature == Constants.jungle) return 1
|
||||
return 0
|
||||
}
|
||||
@ -188,14 +190,11 @@ open class TileInfo {
|
||||
val civWideUniques = city.civInfo.getMatchingUniques("[] from every []")
|
||||
for (unique in cityWideUniques + civWideUniques) {
|
||||
val tileType = unique.params[1]
|
||||
if (baseTerrain == tileType || terrainFeature == tileType
|
||||
if (fitsUniqueFilter(tileType)
|
||||
|| (resource == tileType && hasViewableResource(observingCiv))
|
||||
|| (tileType == "Water" && isWater)
|
||||
|| (tileType == "Strategic resource" && hasViewableResource(observingCiv) && getTileResource().resourceType == ResourceType.Strategic)
|
||||
|| (tileType == "Water resource" && isWater && hasViewableResource(observingCiv))
|
||||
|| (tileType == "River" && isAdjacentToRiver())
|
||||
)
|
||||
stats.add(Stats.parse(unique.params[0]))
|
||||
) stats.add(Stats.parse(unique.params[0]))
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,8 +271,8 @@ open class TileInfo {
|
||||
if (unique.placeholderText == "[] for each adjacent []") {
|
||||
val adjacent = unique.params[1]
|
||||
val numberOfBonuses = neighbors.count { it.improvement == adjacent
|
||||
|| it.baseTerrain==adjacent || it.terrainFeature==adjacent
|
||||
|| it.roadStatus.name==adjacent}
|
||||
|| it.fitsUniqueFilter(adjacent)
|
||||
|| it.roadStatus.name == adjacent}
|
||||
stats.add(Stats.parse(unique.params[0]).times(numberOfBonuses.toFloat()))
|
||||
}
|
||||
|
||||
@ -309,6 +308,7 @@ open class TileInfo {
|
||||
|
||||
fun fitsUniqueFilter(filter:String): Boolean {
|
||||
return filter == baseTerrain
|
||||
|| filter == Constants.hill && isHill()
|
||||
|| filter == "River" && isAdjacentToRiver()
|
||||
|| filter == terrainFeature
|
||||
|| baseTerrainObject.uniques.contains(filter)
|
||||
|
@ -35,7 +35,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
|
||||
if (unit.doubleMovementInForestAndJungle && (to.terrainFeature == Constants.forest || to.terrainFeature == Constants.jungle))
|
||||
return 1f + extraCost // usually forest and jungle take 2 movements, so here it is 1
|
||||
if (civInfo.nation.ignoreHillMovementCost && to.baseTerrain == Constants.hill)
|
||||
if (civInfo.nation.ignoreHillMovementCost && to.isHill())
|
||||
return 1f + extraCost // usually hills take 2 movements, so here it is 1
|
||||
|
||||
if (unit.roughTerrainPenalty && to.isRoughTerrain())
|
||||
@ -44,7 +44,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
if (unit.doubleMovementInCoast && to.baseTerrain == Constants.coast)
|
||||
return 1 / 2f + extraCost
|
||||
|
||||
if (unit.doubleMovementInSnowTundraAndHills && to.baseTerrain == Constants.hill)
|
||||
if (unit.doubleMovementInSnowTundraAndHills && to.isHill())
|
||||
return 1f + extraCost // usually hills take 2
|
||||
if (unit.doubleMovementInSnowTundraAndHills && (to.baseTerrain == Constants.snow || to.baseTerrain == Constants.tundra))
|
||||
return 1 / 2f + extraCost
|
||||
|
@ -131,6 +131,7 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
for (resource in strategicResources) {
|
||||
// remove the tiles where previous resources have been placed
|
||||
val suitableTiles = candidateTiles
|
||||
.filterNot { it.baseTerrain == Constants.snow && it.isHill() }
|
||||
.filter { it.resource == null
|
||||
&& resource.terrainsCanBeFoundOn.contains(it.getLastTerrain().name) }
|
||||
|
||||
@ -148,6 +149,7 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
val resourcesOfType = ruleset.tileResources.values.filter { it.resourceType == resourceType }
|
||||
|
||||
val suitableTiles = tileMap.values
|
||||
.filterNot { it.baseTerrain == Constants.snow && it.isHill() }
|
||||
.filter { it.resource == null && resourcesOfType.any { r -> r.terrainsCanBeFoundOn.contains(it.getLastTerrain().name) } }
|
||||
val numberOfResources = tileMap.values.count { it.isLand && !it.isImpassible() } *
|
||||
tileMap.mapParameters.resourceRichness
|
||||
@ -234,7 +236,8 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
private fun spawnVegetation(tileMap: TileMap) {
|
||||
val vegetationSeed = randomness.RNG.nextInt().toDouble()
|
||||
val candidateTerrains = Constants.vegetation.flatMap{ ruleset.terrains[it]!!.occursOn!! }
|
||||
for (tile in tileMap.values.asSequence().filter { it.baseTerrain in candidateTerrains && it.terrainFeature == null}) {
|
||||
for (tile in tileMap.values.asSequence().filter { it.baseTerrain in candidateTerrains && it.terrainFeature == null
|
||||
&& (!it.isHill() || Constants.hill in candidateTerrains) }) {
|
||||
val vegetation = (randomness.getPerlinNoise(tile, vegetationSeed, scale = 3.0, nOctaves = 1) + 1.0) / 2.0
|
||||
|
||||
if (vegetation <= tileMap.mapParameters.vegetationRichness)
|
||||
@ -250,7 +253,8 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
}
|
||||
for (tile in tileMap.values.asSequence().filter { it.terrainFeature == null }) {
|
||||
if (randomness.RNG.nextDouble() <= tileMap.mapParameters.rareFeaturesRichness) {
|
||||
val possibleFeatures = rareFeatures.filter { it.occursOn != null && it.occursOn.contains(tile.baseTerrain) }
|
||||
val possibleFeatures = rareFeatures.filter { it.occursOn != null && it.occursOn.contains(tile.baseTerrain)
|
||||
&& (!tile.isHill() || it.occursOn.contains(Constants.hill) )}
|
||||
if (possibleFeatures.any())
|
||||
tile.terrainFeature = possibleFeatures.random(randomness.RNG).name
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
&& wonder.occursOn!!.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
&& it.neighbors.count{ neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 2
|
||||
&& it.neighbors.count{ neighbor -> neighbor.getBaseTerrain().name == Constants.mountain || neighbor.getBaseTerrain().name == Constants.hill } <= 4
|
||||
&& it.neighbors.count{ neighbor -> neighbor.getBaseTerrain().name == Constants.mountain || neighbor.isHill() } <= 4
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -100,7 +100,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.desert }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getLastTerrain().name == Constants.marsh }
|
||||
&& it.neighbors.count{ neighbor -> neighbor.getBaseTerrain().name == Constants.hill } <= 2
|
||||
&& it.neighbors.count{ neighbor -> neighbor.isHill() } <= 2
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -114,7 +114,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
val wonder = ruleset.terrains[Constants.grandMesa]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn!!.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count{ neighbor -> neighbor.getBaseTerrain().name == Constants.hill } >= 2
|
||||
&& it.neighbors.count{ neighbor -> neighbor.isHill() } >= 2
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 2
|
||||
}
|
||||
@ -224,7 +224,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
&& wonder.occursOn!!.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 4
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain ||
|
||||
neighbor.getBaseTerrain().name == Constants.hill
|
||||
neighbor.isHill()
|
||||
} >= 3
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.desert } <= 3
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.tundra } <= 3
|
||||
@ -240,7 +240,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
val wonder = ruleset.terrains[Constants.cerroDePotosi]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn!!.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getBaseTerrain().name == Constants.hill }
|
||||
&& it.neighbors.any { neighbor -> neighbor.isHill() }
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
|
@ -12,7 +12,7 @@ class RiverGenerator(val randomness: MapGenerationRandomness){
|
||||
var optionalTiles = map.values
|
||||
.filter { it.baseTerrain== Constants.mountain && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 }.toMutableList()
|
||||
if(optionalTiles.size < numberOfRivers)
|
||||
optionalTiles.addAll(map.values.filter { it.baseTerrain== Constants.hill && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 })
|
||||
optionalTiles.addAll(map.values.filter { it.isHill() && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 })
|
||||
if(optionalTiles.size < numberOfRivers)
|
||||
optionalTiles = map.values.filter { it.isLand && it.aerialDistanceTo(getClosestWaterTile(it)) > 4 }.toMutableList()
|
||||
|
||||
@ -22,7 +22,7 @@ class RiverGenerator(val randomness: MapGenerationRandomness){
|
||||
|
||||
for(tile in map.values){
|
||||
if(tile.isAdjacentToRiver()){
|
||||
if(tile.baseTerrain== Constants.desert) tile.terrainFeature= Constants.floodPlains
|
||||
if(tile.baseTerrain== Constants.desert && !tile.isHill()) tile.terrainFeature= Constants.floodPlains
|
||||
else if(tile.baseTerrain== Constants.snow) tile.baseTerrain = Constants.tundra
|
||||
else if(tile.baseTerrain== Constants.tundra) tile.baseTerrain = Constants.plains
|
||||
tile.setTerrainTransients()
|
||||
|
Loading…
Reference in New Issue
Block a user