From c708ebd7f0ebab5abe44658f01d715da4a8b2249 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Tue, 19 Oct 2021 21:25:43 +0300 Subject: [PATCH] Solved edge case where automated prophet couldn't head towards the city --- .../unciv/logic/automation/SpecificUnitAutomation.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index 45cdab852b..4a3a08ee10 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -378,14 +378,18 @@ object SpecificUnitAutomation { } fun foundReligion(unit: MapUnit) { - val cityToFoundReligionAt = unit.civInfo.cities.first { !it.isHolyCity() } + val cityToFoundReligionAt = unit.civInfo.cities.firstOrNull { + !it.isHolyCity() + && unit.movement.canMoveTo(it.getCenterTile()) + && unit.movement.canReach(it.getCenterTile()) + } + if (cityToFoundReligionAt == null) return if (unit.getTile() != cityToFoundReligionAt.getCenterTile()) { unit.movement.headTowards(cityToFoundReligionAt.getCenterTile()) - return + return } - + UnitActions.getFoundReligionAction(unit)() - } fun enhanceReligion(unit: MapUnit) {