Resolved #10004 - Defensive pact allies *meet* the aggressor civ so they can declare war on them, if they haven't already met

This commit is contained in:
Yair Morgenstern 2023-08-30 23:14:51 +03:00
parent 5585dfa470
commit 96e96cf449

View File

@ -5,8 +5,6 @@ import com.unciv.Constants
import com.unciv.logic.IsPartOfGameInfoSerialization import com.unciv.logic.IsPartOfGameInfoSerialization
import com.unciv.logic.civilization.AlertType import com.unciv.logic.civilization.AlertType
import com.unciv.logic.civilization.Civilization import com.unciv.logic.civilization.Civilization
import com.unciv.logic.civilization.DiplomacyAction
import com.unciv.logic.civilization.LocationAction
import com.unciv.logic.civilization.NotificationCategory import com.unciv.logic.civilization.NotificationCategory
import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.civilization.NotificationIcon
import com.unciv.logic.civilization.PopupAlert import com.unciv.logic.civilization.PopupAlert
@ -384,7 +382,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
return max(0f, increment) * max(0f, modifierPercent).toPercent() return max(0f, increment) * max(0f, modifierPercent).toPercent()
} }
fun canDeclareWar() = turnsToPeaceTreaty() == 0 && diplomaticStatus != DiplomaticStatus.War fun canDeclareWar() = turnsToPeaceTreaty() == 0 && diplomaticStatus != DiplomaticStatus.War
//Used for nuke //Used for nuke
@ -736,7 +734,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
trades.clear() trades.clear()
val civAtWarWith = otherCiv() val civAtWarWith = otherCiv()
// If we attacked, then we need to end all of our defensive pacts acording to Civ 5 // If we attacked, then we need to end all of our defensive pacts acording to Civ 5
if (isOffensiveWar) { if (isOffensiveWar) {
removeDefensivePacts() removeDefensivePacts()
@ -747,13 +745,13 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
if (!isOffensiveWar) callInDefensivePactAllies() if (!isOffensiveWar) callInDefensivePactAllies()
callInCityStateAllies() callInCityStateAllies()
} }
if (civInfo.isCityState() && civInfo.cityStateFunctions.getProtectorCivs().contains(civAtWarWith)) { if (civInfo.isCityState() && civInfo.cityStateFunctions.getProtectorCivs().contains(civAtWarWith)) {
civInfo.cityStateFunctions.removeProtectorCiv(civAtWarWith, forced = true) civInfo.cityStateFunctions.removeProtectorCiv(civAtWarWith, forced = true)
} }
updateHasOpenBorders() updateHasOpenBorders()
removeModifier(DiplomaticModifiers.YearsOfPeace) removeModifier(DiplomaticModifiers.YearsOfPeace)
setFlag(DiplomacyFlags.DeclinedPeace, 10)/// AI won't propose peace for 10 turns setFlag(DiplomacyFlags.DeclinedPeace, 10)/// AI won't propose peace for 10 turns
setFlag(DiplomacyFlags.DeclaredWar, 10) // AI won't agree to trade for 10 turns setFlag(DiplomacyFlags.DeclaredWar, 10) // AI won't agree to trade for 10 turns
@ -803,6 +801,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
&& !ourDipManager.otherCiv().isAtWarWith(civAtWarWith) && !ourDipManager.otherCiv().isAtWarWith(civAtWarWith)
}) { }) {
val ally = ourDefensivePact.otherCiv() val ally = ourDefensivePact.otherCiv()
if (!civAtWarWith.knows(ally)) civAtWarWith.diplomacyFunctions.makeCivilizationsMeet(ally, true)
// Have the aggressor declare war on the ally. // Have the aggressor declare war on the ally.
civAtWarWith.getDiplomacyManager(ally).declareWar(true) civAtWarWith.getDiplomacyManager(ally).declareWar(true)
// Notify the aggressor // Notify the aggressor
@ -810,7 +809,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
NotificationCategory.Diplomacy, ally.civName, NotificationIcon.Diplomacy, civInfo.civName) NotificationCategory.Diplomacy, ally.civName, NotificationIcon.Diplomacy, civInfo.civName)
} }
} }
private fun callInCityStateAllies() { private fun callInCityStateAllies() {
val civAtWarWith = otherCiv() val civAtWarWith = otherCiv()
for (thirdCiv in civInfo.getKnownCivs() for (thirdCiv in civInfo.getKnownCivs()
@ -874,14 +873,14 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
else thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.SharedEnemy, 5f) else thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.SharedEnemy, 5f)
} else thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.WarMongerer, -5f) } else thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.WarMongerer, -5f)
} }
breakTreaties() breakTreaties()
if (otherCiv.isMajorCiv()) if (otherCiv.isMajorCiv())
for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponDeclaringWar)) for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponDeclaringWar))
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)
} }
private fun breakTreaties() { private fun breakTreaties() {
val otherCiv = otherCiv() val otherCiv = otherCiv()
val otherCivDiplomacy = otherCivDiplomacy() val otherCivDiplomacy = otherCivDiplomacy()
@ -1020,11 +1019,11 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
removeModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies) removeModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies)
for (thirdCiv in getCommonKnownCivs() for (thirdCiv in getCommonKnownCivs()
.filter { it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }) { .filter { it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }) {
val relationshipLevel = otherCiv().getDiplomacyManager(thirdCiv).relationshipIgnoreAfraid() val relationshipLevel = otherCiv().getDiplomacyManager(thirdCiv).relationshipIgnoreAfraid()
val modifierType = when (relationshipLevel) { val modifierType = when (relationshipLevel) {
RelationshipLevel.Unforgivable, RelationshipLevel.Enemy -> DiplomaticModifiers.DeclaredFriendshipWithOurEnemies RelationshipLevel.Unforgivable, RelationshipLevel.Enemy -> DiplomaticModifiers.DeclaredFriendshipWithOurEnemies
else -> DiplomaticModifiers.DeclaredFriendshipWithOurAllies else -> DiplomaticModifiers.DeclaredFriendshipWithOurAllies
} }
val modifierValue = when (relationshipLevel) { val modifierValue = when (relationshipLevel) {
RelationshipLevel.Unforgivable -> -15f RelationshipLevel.Unforgivable -> -15f
@ -1045,7 +1044,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
otherCivDiplomacy().setFlag(DiplomacyFlags.DefensivePact, duration) otherCivDiplomacy().setFlag(DiplomacyFlags.DefensivePact, duration)
diplomaticStatus = DiplomaticStatus.DefensivePact diplomaticStatus = DiplomaticStatus.DefensivePact
otherCivDiplomacy().diplomaticStatus = DiplomaticStatus.DefensivePact otherCivDiplomacy().diplomaticStatus = DiplomaticStatus.DefensivePact
for (thirdCiv in getCommonKnownCivs().filter { it.isMajorCiv() }) { for (thirdCiv in getCommonKnownCivs().filter { it.isMajorCiv() }) {
thirdCiv.addNotification("[${civInfo.civName}] and [$otherCivName] have signed the Defensive Pact!", thirdCiv.addNotification("[${civInfo.civName}] and [$otherCivName] have signed the Defensive Pact!",