Declaration of Friendship is go!

I'm sure there's stuff I've forgotten but there is just so much that happens in diplomacy that is dependant on these declarations
This commit is contained in:
Yair Morgenstern 2019-05-08 18:48:36 +03:00
parent f8a4f15f33
commit b3a4ed4c4f
3 changed files with 87 additions and 34 deletions

View File

@ -2731,12 +2731,20 @@
French:"Notre relation :" //or l'état de notre relation
}
"Unforgivable!":{
Italian:"Imperdonabile!"
French:"Impardonnable!"
// Friendship declaration flavor texts
"Declare Friendship ([numberOfTurns] turns)":{}
"May our nations forever remain united!":{}
"Indeed!":{}
// Relationship states, from worst (Unforgivable) to best (Ally)
"Unforgivable":{
Italian:"Imperdonabile"
French:"Impardonnable"
}
"Enemy":{ //e.g ?
"Enemy":{
Italian:"Nemico"
French:"Ennemi"
}
@ -2797,6 +2805,8 @@
"You have declared friendship with our enemies!":{}
"You have declared friendship with our allies":{}
"Our open borders have brought us closer together.":{}
////// Overview screen
"Overview":{

View File

@ -24,6 +24,7 @@ enum class RelationshipLevel{
enum class DiplomacyFlags{
DeclinedLuxExchange,
DeclinedPeace,
DeclaredWar,
DeclarationOfFriendship,
BorderConflict
}
@ -37,7 +38,8 @@ enum class DiplomaticModifiers{
YearsOfPeace,
SharedEnemy,
DeclarationOfFriendship,
DeclaredFriendshipWithOurAllies
DeclaredFriendshipWithOurAllies,
OpenBorders
}
class DiplomacyManager() {
@ -70,6 +72,7 @@ class DiplomacyManager() {
toReturn.influence = influence
toReturn.flagsCountdown.putAll(flagsCountdown)
toReturn.hasOpenBorders=hasOpenBorders
toReturn.diplomaticModifiers.putAll(diplomaticModifiers)
return toReturn
}
@ -200,6 +203,12 @@ class DiplomacyManager() {
addModifier(DiplomaticModifiers.YearsOfPeace,0.5f)
else revertToZero(DiplomaticModifiers.YearsOfPeace,-0.5f) // war makes you forget the good ol' days
var openBorders = 0
if(hasOpenBorders) openBorders+=1
if(otherCivDiplomacy().hasOpenBorders) openBorders+=1
if(openBorders>0) addModifier(DiplomaticModifiers.OpenBorders,openBorders/8f) // so if we both have open borders it'll grow by 0.25 per turn
else revertToZero(DiplomaticModifiers.OpenBorders, 1/8f)
revertToZero(DiplomaticModifiers.DeclaredWarOnUs,1/8f) // this disappears real slow - it'll take 160 turns to really forget, this is war declaration we're talking about
revertToZero(DiplomaticModifiers.WarMongerer,0.5f) // warmongering gives a big negative boost when it happens but they're forgotten relatively quickly, like WWII amirite
revertToZero(DiplomaticModifiers.CapturedOurCities,1/4f) // if you captured our cities, though, that's harder to forget
@ -247,6 +256,11 @@ class DiplomacyManager() {
/// AI won't propose peace for 10 turns
setFlag(DiplomacyFlags.DeclinedPeace,10)
otherCiv.getDiplomacyManager(civInfo).setFlag(DiplomacyFlags.DeclinedPeace,10)
// AI won't agree to trade for 10 turns
setFlag(DiplomacyFlags.DeclaredWar,10)
otherCiv.getDiplomacyManager(civInfo).setFlag(DiplomacyFlags.DeclaredWar,10)
otherCivDiplomacy.setModifier(DiplomaticModifiers.DeclaredWarOnUs,-20f)
removeFlag(DiplomacyFlags.BorderConflict)
@ -300,6 +314,8 @@ class DiplomacyManager() {
fun signDeclarationOfFriendship(){
setModifier(DiplomaticModifiers.DeclarationOfFriendship,35f)
otherCivDiplomacy().setModifier(DiplomaticModifiers.DeclarationOfFriendship,35f)
setFlag(DiplomacyFlags.DeclarationOfFriendship,30)
otherCivDiplomacy().setFlag(DiplomacyFlags.DeclarationOfFriendship,30)
for(thirdCiv in civInfo.getKnownCivs().filter { it.isMajorCiv() }){
if(thirdCiv==otherCiv() || !thirdCiv.knows(otherCivName)) continue

View File

@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UnCivGame
import com.unciv.logic.civilization.CityStateType
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
import com.unciv.logic.civilization.diplomacy.DiplomacyManager
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers.*
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
@ -16,7 +17,6 @@ import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeType
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.optionstable.PopupTable
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
class DiplomacyScreen:CameraStageBaseScreen() {
@ -60,13 +60,17 @@ class DiplomacyScreen:CameraStageBaseScreen() {
leftSideTable.add(civIndicator).row()
civIndicator.onClick {
rightSideTable.clear()
if(civ.isCityState()) rightSideTable.add(getCityStateDiplomacyTable(civ))
else rightSideTable.add(getMajorCivDiplomacyTable(civ))
updateRightSide(civ)
}
}
}
fun updateRightSide(civ: CivilizationInfo){
rightSideTable.clear()
if(civ.isCityState()) rightSideTable.add(getCityStateDiplomacyTable(civ))
else rightSideTable.add(getMajorCivDiplomacyTable(civ))
}
fun setTrade(civ: CivilizationInfo): TradeTable {
rightSideTable.clear()
val tradeTable =TradeTable(civ, stage) { updateLeftSideTable() }
@ -128,31 +132,6 @@ class DiplomacyScreen:CameraStageBaseScreen() {
return diplomacyTable
}
private fun getDeclareWarButton(diplomacyManager: DiplomacyManager, otherCiv: CivilizationInfo): TextButton {
val declareWarButton = TextButton("Declare war".tr(), skin)
declareWarButton.color = Color.RED
val turnsToPeaceTreaty = diplomacyManager.turnsToPeaceTreaty()
if (turnsToPeaceTreaty > 0) {
declareWarButton.disable()
declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)")
}
declareWarButton.onClick {
YesNoPopupTable("Declare war on [${otherCiv.civName}]?".tr(), {
diplomacyManager.declareWar()
val responsePopup = PopupTable(this)
responsePopup.add(otherCiv.getTranslatedNation().getLeaderDisplayName().toLabel())
responsePopup.addSeparator()
responsePopup.addGoodSizedLabel(otherCiv.getNation().attacked).row()
responsePopup.addButton("Very well.".tr()) { responsePopup.remove() }
responsePopup.open()
updateLeftSideTable()
}, this)
}
return declareWarButton
}
private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table {
val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization()
val diplomacyTable = Table()
@ -162,11 +141,25 @@ class DiplomacyScreen:CameraStageBaseScreen() {
val tradeButton = TextButton("Trade".tr(), skin)
tradeButton.onClick { setTrade(otherCiv) }
if(otherCiv.getDiplomacyManager(currentPlayerCiv).hasFlag(DiplomacyFlags.DeclaredWar))
tradeButton.disable() // Can't trade for 10 turns after war was declared
diplomacyTable.add(tradeButton).row()
val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv)
if (!currentPlayerCiv.isAtWarWith(otherCiv)) {
if(otherCiv.getDiplomacyManager(currentPlayerCiv).relationshipLevel() > RelationshipLevel.Neutral
&& !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)){
val declareFriendshipButton = TextButton("Declare Friendship ([30] turns)".tr(),skin)
declareFriendshipButton.onClick {
diplomacyManager.signDeclarationOfFriendship()
setRightSideFlavorText(otherCiv,"May our nations forever remain united!".tr(),"Indeed!".tr())
}
diplomacyTable.add(declareFriendshipButton).row()
}
val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv)
diplomacyTable.add(declareWarButton).row()
}
@ -198,6 +191,7 @@ class DiplomacyScreen:CameraStageBaseScreen() {
DeclarationOfFriendship -> "We have signed a public declaration of friendship"
DeclaredFriendshipWithOurEnemies -> "You have declared friendship with our enemies!"
DeclaredFriendshipWithOurAllies -> "You have declared friendship with our allies"
OpenBorders -> "Our open borders have brought us closer together."
}
text = text.tr() + " "
if (modifier.value > 0) text += "+"
@ -210,4 +204,37 @@ class DiplomacyScreen:CameraStageBaseScreen() {
return diplomacyTable
}
private fun getDeclareWarButton(diplomacyManager: DiplomacyManager, otherCiv: CivilizationInfo): TextButton {
val declareWarButton = TextButton("Declare war".tr(), skin)
declareWarButton.color = Color.RED
val turnsToPeaceTreaty = diplomacyManager.turnsToPeaceTreaty()
if (turnsToPeaceTreaty > 0) {
declareWarButton.disable()
declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)")
}
declareWarButton.onClick {
YesNoPopupTable("Declare war on [${otherCiv.civName}]?".tr(), {
diplomacyManager.declareWar()
setRightSideFlavorText(otherCiv,otherCiv.getTranslatedNation().attacked,"Very well.")
updateLeftSideTable()
}, this)
}
return declareWarButton
}
private fun setRightSideFlavorText(otherCiv: CivilizationInfo, flavorText:String, response: String){
val diplomacyTable = Table()
diplomacyTable.defaults().pad(10f)
diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel())
diplomacyTable.addSeparator()
diplomacyTable.add(flavorText.toLabel()).row()
val responseButton = TextButton(response,skin)
responseButton.onClick { updateRightSide(otherCiv) }
diplomacyTable.add(responseButton)
rightSideTable.clear()
rightSideTable.add(diplomacyTable)
}
}