Cancel the chain reaction of defense pact (#12703)

* When calling a defense pact ally to join a war, the ally's defense pact with other civilizations will no longer be chained.

* Update DiplomacyScreen.kt

Simplify the loop and delete dead code

---------

Co-authored-by: czyh2022 <2200013085@stu.pku.edu.cn>
This commit is contained in:
czyh2022 2024-12-26 02:36:47 +08:00 committed by GitHub
parent 81a85856cb
commit 87817dd776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 21 deletions

View File

@ -33,8 +33,8 @@ object DeclareWar {
notifyOfWar(diplomacyManager, declareWarReason)
onWarDeclared(diplomacyManager, true)
onWarDeclared(otherCivDiplomacy, false)
onWarDeclared(diplomacyManager, true, declareWarReason.warType)
onWarDeclared(otherCivDiplomacy, false, declareWarReason.warType)
changeOpinions(diplomacyManager, declareWarReason)
@ -127,7 +127,7 @@ object DeclareWar {
}
/** Everything that happens to both sides equally when war is declared by one side on the other */
private fun onWarDeclared(diplomacyManager: DiplomacyManager, isOffensiveWar: Boolean) {
private fun onWarDeclared(diplomacyManager: DiplomacyManager, isOffensiveWar: Boolean, warType: WarType) {
// Cancel all trades.
for (trade in diplomacyManager.trades)
for (offer in trade.theirOffers.filter { it.duration > 0 && it.name != Constants.defensivePact})
@ -147,10 +147,11 @@ object DeclareWar {
removeDefensivePacts(diplomacyManager)
}
diplomacyManager.diplomaticStatus = DiplomaticStatus.War
// Defensive pact chains are not allowed now
if (diplomacyManager.civInfo.isMajorCiv()) {
if (!isOffensiveWar && !civAtWarWith.isCityState)
callInDefensivePactAllies(diplomacyManager)
if (!isOffensiveWar && warType != WarType.DefensivePactWar && !civAtWarWith.isCityState)
callInDefensivePactAllies(diplomacyManager)
callInCityStateAllies(diplomacyManager)
}

View File

@ -281,22 +281,15 @@ class DiplomacyScreen(
otherCivDiploManager -> otherCivDiploManager.otherCiv() != viewingCiv
&& otherCivDiploManager.diplomaticStatus == DiplomaticStatus.DefensivePact
&& !otherCivDiploManager.otherCiv().isAtWarWith(viewingCiv) }
.map { it.otherCiv() }.toMutableList()
// Go through and find all of the defensive pact chains and add them to the list
var listIndex = 0
while (listIndex < otherCivDefensivePactList.size) {
messageLines += if (viewingCiv.knows(otherCivDefensivePactList[listIndex]))
"[${otherCivDefensivePactList[listIndex].civName}] will also join them in the war"
else "An unknown civilization will also join them in the war"
.map { it.otherCiv() }
// Add their defensive pact allies
otherCivDefensivePactList.addAll(otherCivDefensivePactList[listIndex].diplomacy.values
.filter { diploChain -> diploChain.diplomaticStatus == DiplomaticStatus.DefensivePact
&& !otherCivDefensivePactList.contains(diploChain.otherCiv())
&& diploChain.otherCiv() != viewingCiv && diploChain.otherCiv() != otherCiv
&& !diploChain.otherCiv().isAtWarWith(viewingCiv) }
.map { it.otherCiv() })
listIndex++
// Defensive pact chains are not allowed now
for (civ in otherCivDefensivePactList) {
messageLines += if (viewingCiv.knows(civ)) {
"[${civ.civName}] will also join them in the war"
} else {
"An unknown civilization will also join them in the war"
}
}
// Tell the player that their defensive pacts will be canceled.