Resolved #7111 - Peace cooldown with city-states

This commit is contained in:
Yair Morgenstern 2022-06-09 19:51:08 +03:00
parent 538b7b8e7d
commit 5cd992a076

View File

@ -330,29 +330,10 @@ class DiplomacyScreen(
val improveTileButton = getImproveTilesButton(otherCiv, otherCivDiplomacyManager) val improveTileButton = getImproveTilesButton(otherCiv, otherCivDiplomacyManager)
if (improveTileButton != null) diplomacyTable.add(improveTileButton).row() if (improveTileButton != null) diplomacyTable.add(improveTileButton).row()
if (otherCivDiplomacyManager.diplomaticStatus == DiplomaticStatus.Protector) { if (otherCivDiplomacyManager.diplomaticStatus != DiplomaticStatus.Protector)
val revokeProtectionButton = "Revoke Protection".toTextButton() diplomacyTable.add(getPledgeToProtectButton(otherCiv)).row()
revokeProtectionButton.onClick { else
YesNoPopup("Revoke protection for [${otherCiv.civName}]?", { diplomacyTable.add(getRevokeProtectionButton(otherCiv)).row()
otherCiv.removeProtectorCiv(viewingCiv)
updateLeftSideTable(otherCiv)
updateRightSide(otherCiv)
}, this).open()
}
diplomacyTable.add(revokeProtectionButton).row()
if (isNotPlayersTurn() || !otherCiv.otherCivCanWithdrawProtection(viewingCiv)) revokeProtectionButton.disable()
} else {
val protectionButton = "Pledge to protect".toTextButton()
protectionButton.onClick {
YesNoPopup("Declare Protection of [${otherCiv.civName}]?", {
otherCiv.addProtectorCiv(viewingCiv)
updateLeftSideTable(otherCiv)
updateRightSide(otherCiv)
}, this).open()
}
diplomacyTable.add(protectionButton).row()
if (isNotPlayersTurn() || !otherCiv.otherCivCanPledgeProtection(viewingCiv)) protectionButton.disable()
}
val demandTributeButton = "Demand Tribute".toTextButton() val demandTributeButton = "Demand Tribute".toTextButton()
demandTributeButton.onClick { demandTributeButton.onClick {
@ -364,7 +345,60 @@ class DiplomacyScreen(
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv) val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
if (!viewingCiv.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) { if (!viewingCiv.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) {
if (viewingCiv.isAtWarWith(otherCiv)) { if (viewingCiv.isAtWarWith(otherCiv))
diplomacyTable.add(getNegotiatePeaceCityStateButton(otherCiv, diplomacyManager)).row()
else diplomacyTable.add(getDeclareWarButton(diplomacyManager, otherCiv)).row()
}
if (otherCiv.cities.isNotEmpty() && otherCiv.getCapital() != null && otherCiv.getCapital()!!.location in viewingCiv.exploredTiles)
diplomacyTable.add(getGoToOnMapButton(otherCiv)).row()
val diplomaticMarriageButton = getDiplomaticMarriageButton(otherCiv)
if (diplomaticMarriageButton != null) diplomacyTable.add(diplomaticMarriageButton).row()
for (assignedQuest in otherCiv.questManager.assignedQuests.filter { it.assignee == viewingCiv.civName }) {
diplomacyTable.addSeparator()
diplomacyTable.add(getQuestTable(assignedQuest)).row()
}
for (target in otherCiv.getKnownCivs().filter { otherCiv.questManager.warWithMajorActive(it) }) {
diplomacyTable.addSeparator()
diplomacyTable.add(getWarWithMajorTable(target, otherCiv)).row()
}
return diplomacyTable
}
private fun getRevokeProtectionButton(otherCiv: CivilizationInfo): TextButton {
val revokeProtectionButton = "Revoke Protection".toTextButton()
revokeProtectionButton.onClick {
YesNoPopup("Revoke protection for [${otherCiv.civName}]?", {
otherCiv.removeProtectorCiv(viewingCiv)
updateLeftSideTable(otherCiv)
updateRightSide(otherCiv)
}, this).open()
}
if (isNotPlayersTurn() || !otherCiv.otherCivCanWithdrawProtection(viewingCiv)) revokeProtectionButton.disable()
return revokeProtectionButton
}
private fun getPledgeToProtectButton(otherCiv: CivilizationInfo): TextButton {
val protectionButton = "Pledge to protect".toTextButton()
protectionButton.onClick {
YesNoPopup("Declare Protection of [${otherCiv.civName}]?", {
otherCiv.addProtectorCiv(viewingCiv)
updateLeftSideTable(otherCiv)
updateRightSide(otherCiv)
}, this).open()
}
if (isNotPlayersTurn() || !otherCiv.otherCivCanPledgeProtection(viewingCiv)) protectionButton.disable()
return protectionButton
}
private fun getNegotiatePeaceCityStateButton(
otherCiv: CivilizationInfo,
otherCivDiplomacyManager: DiplomacyManager
): TextButton {
val peaceButton = "Negotiate Peace".toTextButton() val peaceButton = "Negotiate Peace".toTextButton()
peaceButton.onClick { peaceButton.onClick {
YesNoPopup("Peace with [${otherCiv.civName}]?", { YesNoPopup("Peace with [${otherCiv.civName}]?", {
@ -386,35 +420,18 @@ class DiplomacyScreen(
updateRightSide(otherCiv) updateRightSide(otherCiv)
}, this).open() }, this).open()
} }
diplomacyTable.add(peaceButton).row()
val cityStatesAlly = otherCiv.getAllyCiv() val cityStatesAlly = otherCiv.getAllyCiv()
val atWarWithItsAlly = viewingCiv.getKnownCivs() val atWarWithItsAlly = viewingCiv.getKnownCivs()
.any { it.civName == cityStatesAlly && it.isAtWarWith(viewingCiv) } .any { it.civName == cityStatesAlly && it.isAtWarWith(viewingCiv) }
if (isNotPlayersTurn() || atWarWithItsAlly) peaceButton.disable() if (isNotPlayersTurn() || atWarWithItsAlly) peaceButton.disable()
} else {
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv) if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.DeclaredWar)) {
if (isNotPlayersTurn()) declareWarButton.disable() peaceButton.disable() // Can't trade for 10 turns after war was declared
diplomacyTable.add(declareWarButton).row() val turnsLeft = otherCivDiplomacyManager.getFlag(DiplomacyFlags.DeclaredWar)
} peaceButton.setText(peaceButton.text.toString() + "\n$turnsLeft" + Fonts.turn)
} }
if (otherCiv.cities.isNotEmpty() && otherCiv.getCapital() != null && otherCiv.getCapital()!!.location in viewingCiv.exploredTiles) return peaceButton
diplomacyTable.add(getGoToOnMapButton(otherCiv)).row()
val diplomaticMarriageButton = getDiplomaticMarriageButton(otherCiv)
if (diplomaticMarriageButton != null) diplomacyTable.add(diplomaticMarriageButton).row()
for (assignedQuest in otherCiv.questManager.assignedQuests.filter { it.assignee == viewingCiv.civName }) {
diplomacyTable.addSeparator()
diplomacyTable.add(getQuestTable(assignedQuest)).row()
}
for (target in otherCiv.getKnownCivs().filter { otherCiv.questManager.warWithMajorActive(it) }) {
diplomacyTable.addSeparator()
diplomacyTable.add(getWarWithMajorTable(target, otherCiv)).row()
}
return diplomacyTable
} }
private fun getImproveTilesButton( private fun getImproveTilesButton(
@ -629,6 +646,7 @@ class DiplomacyScreen(
return warTable return warTable
} }
private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table { private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table {
val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(viewingCiv) val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(viewingCiv)
@ -645,104 +663,33 @@ class DiplomacyScreen(
val diplomaticRelationshipsCanChange = val diplomaticRelationshipsCanChange =
!viewingCiv.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange) !viewingCiv.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
if (!viewingCiv.isAtWarWith(otherCiv)) { if (!viewingCiv.isAtWarWith(otherCiv)) {
val tradeButton = "Trade".toTextButton() diplomacyTable.add(getTradeButton(otherCiv)).row()
tradeButton.onClick {
setTrade(otherCiv).apply {
tradeLogic.ourAvailableOffers.apply { remove(firstOrNull { it.type == TradeType.Treaty }) } if (!diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship))
tradeLogic.theirAvailableOffers.apply { remove(firstOrNull { it.type == TradeType.Treaty }) } diplomacyTable.add(getDeclareFriendshipButton(otherCiv)).row()
offerColumnsTable.update()
}
} if (viewingCiv.canSignResearchAgreementsWith(otherCiv))
diplomacyTable.add(tradeButton).row() diplomacyTable.add(getResearchAgreementButton(otherCiv)).row()
if (isNotPlayersTurn()) tradeButton.disable()
if (!diplomacyManager.hasFlag(DiplomacyFlags.Denunciation)
&& !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)
) diplomacyTable.add(getDenounceButton(otherCiv, diplomacyManager)).row()
if (diplomaticRelationshipsCanChange)
diplomacyTable.add(getDeclareWarButton(diplomacyManager, otherCiv)).row()
} else if (diplomaticRelationshipsCanChange) { } else if (diplomaticRelationshipsCanChange) {
val negotiatePeaceButton = "Negotiate Peace".toTextButton() val negotiatePeaceButton =
negotiatePeaceButton.onClick { getNegotiatePeaceMajorCivButton(otherCiv, otherCivDiplomacyManager)
val tradeTable = setTrade(otherCiv)
val peaceTreaty = TradeOffer(Constants.peaceTreaty, TradeType.Treaty)
tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty)
tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty)
tradeTable.offerColumnsTable.update()
}
if (isNotPlayersTurn() || otherCivDiplomacyManager.hasFlag(DiplomacyFlags.DeclaredWar)) {
negotiatePeaceButton.disable() // Can't trade for 10 turns after war was declared
if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.DeclaredWar)) {
val turnsLeft = otherCivDiplomacyManager.getFlag(DiplomacyFlags.DeclaredWar)
negotiatePeaceButton.setText(negotiatePeaceButton.text.toString() + "\n$turnsLeft" + Fonts.turn)
}
}
diplomacyTable.add(negotiatePeaceButton).row() diplomacyTable.add(negotiatePeaceButton).row()
} }
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
if (!viewingCiv.isAtWarWith(otherCiv)) {
if (!diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)) {
val declareFriendshipButton =
"Offer Declaration of Friendship ([30] turns)".toTextButton()
declareFriendshipButton.onClick {
otherCiv.popupAlerts.add(
PopupAlert(
AlertType.DeclarationOfFriendship,
viewingCiv.civName
)
)
declareFriendshipButton.disable()
}
diplomacyTable.add(declareFriendshipButton).row()
if (isNotPlayersTurn() || otherCiv.popupAlerts
.any { it.type == AlertType.DeclarationOfFriendship && it.value == viewingCiv.civName }
)
declareFriendshipButton.disable()
}
if (viewingCiv.canSignResearchAgreementsWith(otherCiv)) {
val researchAgreementButton = "Research Agreement".toTextButton()
val requiredGold = viewingCiv.getResearchAgreementCost()
researchAgreementButton.onClick {
val tradeTable = setTrade(otherCiv)
val researchAgreement =
TradeOffer(Constants.researchAgreement, TradeType.Treaty, requiredGold)
val goldCostOfSignResearchAgreement =
TradeOffer("Gold".tr(), TradeType.Gold, -requiredGold)
tradeTable.tradeLogic.currentTrade.theirOffers.add(researchAgreement)
tradeTable.tradeLogic.ourAvailableOffers.add(researchAgreement)
tradeTable.tradeLogic.ourAvailableOffers.add(goldCostOfSignResearchAgreement)
tradeTable.tradeLogic.currentTrade.ourOffers.add(researchAgreement)
tradeTable.tradeLogic.theirAvailableOffers.add(researchAgreement)
tradeTable.tradeLogic.theirAvailableOffers.add(goldCostOfSignResearchAgreement)
tradeTable.offerColumnsTable.update()
}
if (isNotPlayersTurn()) researchAgreementButton.disable()
diplomacyTable.add(researchAgreementButton).row()
}
if (!diplomacyManager.hasFlag(DiplomacyFlags.Denunciation)
&& !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)
) {
val denounceButton = "Denounce ([30] turns)".toTextButton()
denounceButton.onClick {
YesNoPopup("Denounce [${otherCiv.civName}]?", {
diplomacyManager.denounce()
updateLeftSideTable(otherCiv)
setRightSideFlavorText(otherCiv, "We will remember this.", "Very well.")
}, this).open()
}
diplomacyTable.add(denounceButton).row()
if (isNotPlayersTurn()) denounceButton.disable()
}
if (diplomaticRelationshipsCanChange) {
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
diplomacyTable.add(declareWarButton).row()
if (isNotPlayersTurn()) declareWarButton.disable()
}
}
val demandsButton = "Demands".toTextButton() val demandsButton = "Demands".toTextButton()
demandsButton.onClick { demandsButton.onClick {
@ -768,6 +715,99 @@ class DiplomacyScreen(
return diplomacyTable return diplomacyTable
} }
private fun getNegotiatePeaceMajorCivButton(
otherCiv: CivilizationInfo,
otherCivDiplomacyManager: DiplomacyManager
): TextButton {
val negotiatePeaceButton = "Negotiate Peace".toTextButton()
negotiatePeaceButton.onClick {
val tradeTable = setTrade(otherCiv)
val peaceTreaty = TradeOffer(Constants.peaceTreaty, TradeType.Treaty)
tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty)
tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty)
tradeTable.offerColumnsTable.update()
}
if (isNotPlayersTurn()) negotiatePeaceButton.disable()
if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.DeclaredWar)) {
negotiatePeaceButton.disable() // Can't trade for 10 turns after war was declared
val turnsLeft = otherCivDiplomacyManager.getFlag(DiplomacyFlags.DeclaredWar)
negotiatePeaceButton.setText(negotiatePeaceButton.text.toString() + "\n$turnsLeft" + Fonts.turn)
}
return negotiatePeaceButton
}
private fun getDenounceButton(
otherCiv: CivilizationInfo,
diplomacyManager: DiplomacyManager
): TextButton {
val denounceButton = "Denounce ([30] turns)".toTextButton()
denounceButton.onClick {
YesNoPopup("Denounce [${otherCiv.civName}]?", {
diplomacyManager.denounce()
updateLeftSideTable(otherCiv)
setRightSideFlavorText(otherCiv, "We will remember this.", "Very well.")
}, this).open()
}
if (isNotPlayersTurn()) denounceButton.disable()
return denounceButton
}
private fun getResearchAgreementButton(otherCiv: CivilizationInfo): TextButton {
val researchAgreementButton = "Research Agreement".toTextButton()
val requiredGold = viewingCiv.getResearchAgreementCost()
researchAgreementButton.onClick {
val tradeTable = setTrade(otherCiv)
val researchAgreement =
TradeOffer(Constants.researchAgreement, TradeType.Treaty, requiredGold)
val goldCostOfSignResearchAgreement =
TradeOffer("Gold".tr(), TradeType.Gold, -requiredGold)
tradeTable.tradeLogic.currentTrade.theirOffers.add(researchAgreement)
tradeTable.tradeLogic.ourAvailableOffers.add(researchAgreement)
tradeTable.tradeLogic.ourAvailableOffers.add(goldCostOfSignResearchAgreement)
tradeTable.tradeLogic.currentTrade.ourOffers.add(researchAgreement)
tradeTable.tradeLogic.theirAvailableOffers.add(researchAgreement)
tradeTable.tradeLogic.theirAvailableOffers.add(goldCostOfSignResearchAgreement)
tradeTable.offerColumnsTable.update()
}
if (isNotPlayersTurn()) researchAgreementButton.disable()
return researchAgreementButton
}
private fun getDeclareFriendshipButton(otherCiv: CivilizationInfo): TextButton {
val declareFriendshipButton =
"Offer Declaration of Friendship ([30] turns)".toTextButton()
declareFriendshipButton.onClick {
otherCiv.popupAlerts.add(
PopupAlert(
AlertType.DeclarationOfFriendship,
viewingCiv.civName
)
)
declareFriendshipButton.disable()
}
if (isNotPlayersTurn() || otherCiv.popupAlerts
.any { it.type == AlertType.DeclarationOfFriendship && it.value == viewingCiv.civName }
)
declareFriendshipButton.disable()
return declareFriendshipButton
}
private fun getTradeButton(otherCiv: CivilizationInfo): TextButton {
val tradeButton = "Trade".toTextButton()
tradeButton.onClick {
setTrade(otherCiv).apply {
tradeLogic.ourAvailableOffers.apply { remove(firstOrNull { it.type == TradeType.Treaty }) }
tradeLogic.theirAvailableOffers.apply { remove(firstOrNull { it.type == TradeType.Treaty }) }
offerColumnsTable.update()
}
}
if (isNotPlayersTurn()) tradeButton.disable()
return tradeButton
}
private fun getPromisesTable( private fun getPromisesTable(
diplomacyManager: DiplomacyManager, diplomacyManager: DiplomacyManager,
otherCivDiplomacyManager: DiplomacyManager otherCivDiplomacyManager: DiplomacyManager
@ -906,6 +946,7 @@ class DiplomacyScreen(
UncivGame.Current.musicController.chooseTrack(otherCiv.civName, MusicMood.War, MusicTrackChooserFlags.setSpecific) UncivGame.Current.musicController.chooseTrack(otherCiv.civName, MusicMood.War, MusicTrackChooserFlags.setSpecific)
}, this).open() }, this).open()
} }
if (isNotPlayersTurn()) declareWarButton.disable()
return declareWarButton return declareWarButton
} }