mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-05 15:59:50 +07:00
Resolved #7111 - Peace cooldown with city-states
This commit is contained in:
@ -330,29 +330,10 @@ class DiplomacyScreen(
|
||||
val improveTileButton = getImproveTilesButton(otherCiv, otherCivDiplomacyManager)
|
||||
if (improveTileButton != null) diplomacyTable.add(improveTileButton).row()
|
||||
|
||||
if (otherCivDiplomacyManager.diplomaticStatus == DiplomaticStatus.Protector) {
|
||||
val revokeProtectionButton = "Revoke Protection".toTextButton()
|
||||
revokeProtectionButton.onClick {
|
||||
YesNoPopup("Revoke protection for [${otherCiv.civName}]?", {
|
||||
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()
|
||||
}
|
||||
if (otherCivDiplomacyManager.diplomaticStatus != DiplomaticStatus.Protector)
|
||||
diplomacyTable.add(getPledgeToProtectButton(otherCiv)).row()
|
||||
else
|
||||
diplomacyTable.add(getRevokeProtectionButton(otherCiv)).row()
|
||||
|
||||
val demandTributeButton = "Demand Tribute".toTextButton()
|
||||
demandTributeButton.onClick {
|
||||
@ -364,7 +345,60 @@ class DiplomacyScreen(
|
||||
|
||||
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
|
||||
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()
|
||||
peaceButton.onClick {
|
||||
YesNoPopup("Peace with [${otherCiv.civName}]?", {
|
||||
@ -386,35 +420,18 @@ class DiplomacyScreen(
|
||||
updateRightSide(otherCiv)
|
||||
}, this).open()
|
||||
}
|
||||
diplomacyTable.add(peaceButton).row()
|
||||
val cityStatesAlly = otherCiv.getAllyCiv()
|
||||
val atWarWithItsAlly = viewingCiv.getKnownCivs()
|
||||
.any { it.civName == cityStatesAlly && it.isAtWarWith(viewingCiv) }
|
||||
if (isNotPlayersTurn() || atWarWithItsAlly) peaceButton.disable()
|
||||
} else {
|
||||
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
|
||||
if (isNotPlayersTurn()) declareWarButton.disable()
|
||||
diplomacyTable.add(declareWarButton).row()
|
||||
}
|
||||
|
||||
if (otherCivDiplomacyManager.hasFlag(DiplomacyFlags.DeclaredWar)) {
|
||||
peaceButton.disable() // Can't trade for 10 turns after war was declared
|
||||
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)
|
||||
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
|
||||
return peaceButton
|
||||
}
|
||||
|
||||
private fun getImproveTilesButton(
|
||||
@ -629,6 +646,7 @@ class DiplomacyScreen(
|
||||
return warTable
|
||||
}
|
||||
|
||||
|
||||
private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table {
|
||||
val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(viewingCiv)
|
||||
|
||||
@ -645,104 +663,33 @@ class DiplomacyScreen(
|
||||
val diplomaticRelationshipsCanChange =
|
||||
!viewingCiv.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)
|
||||
|
||||
val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv)
|
||||
|
||||
if (!viewingCiv.isAtWarWith(otherCiv)) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
diplomacyTable.add(tradeButton).row()
|
||||
if (isNotPlayersTurn()) tradeButton.disable()
|
||||
diplomacyTable.add(getTradeButton(otherCiv)).row()
|
||||
|
||||
|
||||
if (!diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship))
|
||||
diplomacyTable.add(getDeclareFriendshipButton(otherCiv)).row()
|
||||
|
||||
|
||||
if (viewingCiv.canSignResearchAgreementsWith(otherCiv))
|
||||
diplomacyTable.add(getResearchAgreementButton(otherCiv)).row()
|
||||
|
||||
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) {
|
||||
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() || 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)
|
||||
}
|
||||
}
|
||||
val negotiatePeaceButton =
|
||||
getNegotiatePeaceMajorCivButton(otherCiv, otherCivDiplomacyManager)
|
||||
|
||||
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()
|
||||
demandsButton.onClick {
|
||||
@ -768,6 +715,99 @@ class DiplomacyScreen(
|
||||
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(
|
||||
diplomacyManager: DiplomacyManager,
|
||||
otherCivDiplomacyManager: DiplomacyManager
|
||||
@ -906,6 +946,7 @@ class DiplomacyScreen(
|
||||
UncivGame.Current.musicController.chooseTrack(otherCiv.civName, MusicMood.War, MusicTrackChooserFlags.setSpecific)
|
||||
}, this).open()
|
||||
}
|
||||
if (isNotPlayersTurn()) declareWarButton.disable()
|
||||
return declareWarButton
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user