mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 10:18:26 +07:00
AI: Keep 'don't spread religion' promises better
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
package com.unciv.logic.automation.unit
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.automation.Automation
|
||||
import com.unciv.logic.automation.ThreatLevel
|
||||
import com.unciv.logic.city.City
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.models.UnitActionType
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
@ -17,6 +20,17 @@ object ReligiousUnitAutomation {
|
||||
val ourCitiesWithoutReligion = unit.civ.cities.filter {
|
||||
it.religion.getMajorityReligion() != unit.civ.religionManager.religion
|
||||
}
|
||||
|
||||
fun isValidSpreadReligionTarget(city: City): Boolean {
|
||||
val diplomacyManager = unit.civ.getDiplomacyManager(city.civ)
|
||||
if (diplomacyManager?.hasFlag(DiplomacyFlags.AgreedToNotSpreadReligion) == true){
|
||||
// See NextTurnAutomation - these are the conditions under which AI agrees to religious demands
|
||||
// If they still hold, keep the agreement, otherwise we can renege
|
||||
if (diplomacyManager.relationshipLevel() == RelationshipLevel.Ally) return false
|
||||
if (Automation.threatAssessment(unit.civ, city.civ) >= ThreatLevel.High) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/** Lowest value will be chosen */
|
||||
fun rankCityForReligionSpread(city: City): Int {
|
||||
@ -37,6 +51,7 @@ object ReligiousUnitAutomation {
|
||||
.filter { it.religion.getMajorityReligion() != unit.civ.religionManager.religion }
|
||||
.filter { it.civ.knows(unit.civ) && !it.civ.isAtWarWith(unit.civ) }
|
||||
.filterNot { it.religion.isProtectedByInquisitor(unit.religion) }
|
||||
.filter { isValidSpreadReligionTarget(it) }
|
||||
.minByOrNull { rankCityForReligionSpread(it) }
|
||||
|
||||
if (city == null) return
|
||||
|
Reference in New Issue
Block a user