mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
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:
parent
81a85856cb
commit
87817dd776
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user