diff --git a/core/src/com/unciv/logic/automation/unit/ReligiousUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/ReligiousUnitAutomation.kt index e3bf43b9cd..6eebf17570 100644 --- a/core/src/com/unciv/logic/automation/unit/ReligiousUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/ReligiousUnitAutomation.kt @@ -130,6 +130,7 @@ object ReligiousUnitAutomation { return null val holyCity = unit.civ.religionManager.getHolyCity() + // Our own holy city was taken over! if (holyCity != null && holyCity.religion.getMajorityReligion() != unit.civ.religionManager.religion!!) return holyCity @@ -137,12 +138,22 @@ object ReligiousUnitAutomation { if (blockedHolyCity != null) return blockedHolyCity - return unit.civ.cities.asSequence() - .filter { it.religion.getMajorityReligion() != null } - .filter { it.religion.getMajorityReligion()!! != unit.civ.religionManager.religion } - // Don't go if it takes too long + // Find cities + val relevantCities = unit.civ.gameInfo.getCities() + .filter { it.getCenterTile().isExplored(unit.civ) } // Cities we know about + // Someone else is controlling this city + .filter { + val majorityReligion = it.religion.getMajorityReligion() + majorityReligion != null && majorityReligion != unit.civ.religionManager.religion + } + + val closeCity = relevantCities .filter { it.getCenterTile().aerialDistanceTo(unit.currentTile) <= 20 } - .maxByOrNull { it.religion.getPressureDeficit(unit.civ.religionManager.religion?.name) } + // Find the city that we're the closest to converting + .minByOrNull { it.religion.getPressureDeficit(unit.civ.religionManager.religion?.name) } + if (closeCity != null) return closeCity + + return relevantCities.minByOrNull { it.religion.getPressureDeficit(unit.civ.religionManager.religion?.name) } } diff --git a/core/src/com/unciv/logic/city/managers/CityReligionManager.kt b/core/src/com/unciv/logic/city/managers/CityReligionManager.kt index 11bc61feec..6e6a0a1bf5 100644 --- a/core/src/com/unciv/logic/city/managers/CityReligionManager.kt +++ b/core/src/com/unciv/logic/city/managers/CityReligionManager.kt @@ -330,7 +330,8 @@ class CityReligionManager : IsPartOfGameInfoSerialization { return pressure.toInt() } - /** Calculates how much pressure this religion is lacking compared to the majority religion */ + /** Calculates how much pressure this religion is lacking compared to the majority religion + * That is, if we gain more than this, we'll be the majority */ @Readonly fun getPressureDeficit(otherReligion: String?): Int { val pressures = getPressures()