Fix "ask for help" crash (#11712)

* Solved combat resource conditionals vs cities being checked against the target's resources

* Crash fix - Don't attempt to ask civs you don't know for help
This commit is contained in:
Yair Morgenstern
2024-06-09 11:20:10 +03:00
committed by GitHub
parent 2f8b8ca974
commit 2233d3df99
2 changed files with 13 additions and 3 deletions

View File

@ -337,7 +337,9 @@ object DiplomacyAutomation {
for (enemyCiv in civInfo.getCivsAtWarWith().sortedByDescending { it.getStatForRanking(RankingType.Force) }) {
val potentialAllies = enemyCiv.threatManager.getNeighboringCivilizations()
.filter { !it.isAtWarWith(enemyCiv) && civInfo.getDiplomacyManager(it).isRelationshipLevelGE(RelationshipLevel.Friend)
.filter {
civInfo.knows(it) && !it.isAtWarWith(enemyCiv)
&& civInfo.getDiplomacyManager(it).isRelationshipLevelGE(RelationshipLevel.Friend)
&& !it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.DeclinedJoinWarOffer) }
.sortedByDescending { it.getStatForRanking(RankingType.Force) }
val civToAsk = potentialAllies.firstOrNull {

View File

@ -54,8 +54,16 @@ data class StateForConditionals(
}
val relevantCity by lazy {
city
?: relevantTile?.getCity()
if (city != null) return@lazy city
// Edge case: If we attack a city, the "relevant tile" becomes the attacked tile -
// but we DO NOT want that city to become the relevant city because then *our* conditionals get checked against
// the *other civ's* cities, leading to e.g. resource amounts being defined as the *other civ's* resource amounts
val relevantTileForCity = tile ?: relevantUnit?.run { if (hasTile()) getTile() else null }
val cityForRelevantTile = relevantTileForCity?.getCity()
if (cityForRelevantTile != null &&
// ...and we can't use the relevantCiv here either, because that'll cause a loop
(cityForRelevantTile.civ == civInfo || cityForRelevantTile.civ == relevantUnit?.civ)) return@lazy cityForRelevantTile
else return@lazy null
}
val relevantCiv by lazy {