From 1e24f04cf9e3ee307a22bda52482476a4378f181 Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Tue, 22 Feb 2022 10:17:22 +0100 Subject: [PATCH] Added mod constants for the distance between two cities (#6211) --- .../logic/automation/SpecificUnitAutomation.kt | 18 ++++++++++-------- core/src/com/unciv/logic/map/TileInfo.kt | 11 ++++++++--- core/src/com/unciv/models/ModConstants.kt | 7 +++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index cdc857860d..19e3369f19 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -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() diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index ef5b3a4cf3..567f0e8806 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -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 } diff --git a/core/src/com/unciv/models/ModConstants.kt b/core/src/com/unciv/models/ModConstants.kt index 9ee89f0afd..9bbd4eb673 100644 --- a/core/src/com/unciv/models/ModConstants.kt +++ b/core/src/com/unciv/models/ModConstants.kt @@ -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 } \ No newline at end of file