Added mod constants for the distance between two cities (#6211)

This commit is contained in:
Xander Lenstra 2022-02-22 10:17:22 +01:00 committed by GitHub
parent 246d11bfc7
commit 1e24f04cf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 11 deletions

View File

@ -151,6 +151,7 @@ object SpecificUnitAutomation {
}
fun automateSettlerActions(unit: MapUnit) {
val modConstants = unit.civInfo.gameInfo.ruleSet.modOptions.constants
if (unit.getTile().militaryUnit == null // Don't move until you're accompanied by a military unit
&& !unit.civInfo.isCityState() // ..unless you're a city state that was unable to settle its city on turn 1
&& unit.getDamageFromTerrain() < unit.health) return // Also make sure we won't die waiting
@ -159,17 +160,18 @@ object SpecificUnitAutomation {
for (city in unit.civInfo.gameInfo.getCities()) {
val center = city.getCenterTile()
if (unit.civInfo.knows(city.civInfo) &&
// If the CITY OWNER knows that the UNIT OWNER agreed not to settle near them
city.civInfo.getDiplomacyManager(unit.civInfo).hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs)
) {
// If the CITY OWNER knows that the UNIT OWNER agreed not to settle near them
city.civInfo.getDiplomacyManager(unit.civInfo).hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs)
) {
yieldAll(center.getTilesInDistance(6))
continue
}
for (tile in center.getTilesAtDistance(3)) {
if (tile.getContinent() == center.getContinent())
yield(tile)
}
yieldAll(center.getTilesInDistance(2))
yieldAll(center.getTilesInDistance(modConstants.minimalCityDistance)
.filter { it.getContinent() == center.getContinent() }
)
yieldAll(center.getTilesInDistance(modConstants.minimalCityDistanceOnDifferentContinents)
.filter { it.getContinent() != center.getContinent() }
)
}
}.toSet()

View File

@ -637,11 +637,16 @@ open class TileInfo {
}
fun canBeSettled(): Boolean {
val modConstants = tileMap.gameInfo.ruleSet.modOptions.constants
if (isWater || isImpassible())
return false
if (getTilesInDistance(2).any { it.isCityCenter() } ||
getTilesAtDistance(3).any { it.isCityCenter() && it.getContinent() == getContinent() })
return false
if (getTilesInDistance(modConstants.minimalCityDistanceOnDifferentContinents)
.any { it.isCityCenter() && it.getContinent() != getContinent() }
|| getTilesInDistance(modConstants.minimalCityDistance)
.any { it.isCityCenter() && it.getContinent() == getContinent() }
) {
return false
}
return true
}

View File

@ -25,4 +25,11 @@ class ModConstants {
// unitSupplyBase and unitSupplyPerCity can be found in difficulties.json
// unitSupplyBase, unitSupplyPerCity and unitSupplyPerPopulation can also be increased through uniques
val unitSupplyPerPopulation = 0.5
// The minimal distance that must be between any two cities, not counting the tiles cities are on
// The number is the amount of tiles between two cities, not counting the tiles the cities are on.
// e.g. "C__C", where "C" is a tile with a city and "_" is a tile without a city, has a distance of 2.
// First constant is for cities on the same landmass, the second is for cities on different continents.
val minimalCityDistance = 3
val minimalCityDistanceOnDifferentContinents = 2
}