Skip to content

Commit

Permalink
Fix "ask for help" crash (#11712)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yairm210 authored Jun 9, 2024
1 parent 2f8b8ca commit 2233d3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 10 additions & 2 deletions core/src/com/unciv/models/ruleset/unique/StateForConditionals.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2233d3d

Please sign in to comment.