Diplomacy Screen Nation relation indicator (#5032)

This commit is contained in:
SomeTroglodyte 2021-08-30 19:25:13 +02:00 committed by GitHub
parent b0e3aa326b
commit 06c7f049b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 40 deletions

View File

@ -1,5 +1,6 @@
package com.unciv.logic.civilization.diplomacy
import com.badlogic.gdx.graphics.Color
import com.unciv.Constants
import com.unciv.logic.civilization.*
import com.unciv.logic.trade.Trade
@ -12,15 +13,16 @@ import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.min
enum class RelationshipLevel{
Unforgivable,
Afraid,
Enemy,
Competitor,
Neutral,
Favorable,
Friend,
Ally
enum class RelationshipLevel(val color: Color) {
// War is tested separately for the Diplomacy Screen. Colored RED.
Unforgivable(Color.FIREBRICK),
Afraid(Color(0x5300ffff)), // HSV(260,100,100)
Enemy(Color.YELLOW),
Competitor(Color(0x1f998fff)), // HSV(175,80,60)
Neutral(Color(0x1bb371ff)), // HSV(154,85,70)
Favorable(Color(0x14cc3cff)), // HSV(133,90,80)
Friend(Color(0x2ce60bff)), // HSV(111,95,90)
Ally(Color.CHARTREUSE) // HSV(90,100,100)
}
enum class DiplomacyFlags{
@ -72,6 +74,7 @@ class DiplomacyManager() {
const val MINIMUM_INFLUENCE = -60f
}
@Suppress("JoinDeclarationAndAssignment") // incorrect warning - constructor would need to be higher in scope
@Transient
lateinit var civInfo: CivilizationInfo
@ -93,8 +96,8 @@ class DiplomacyManager() {
* As for why it's String and not DiplomaticModifier see FlagsCountdown comment */
var diplomaticModifiers = HashMap<String, Float>()
/** For city-states. Influence is saved in the CITY STATE -> major civ Diplomacy, NOT in the major civ -> cty state diplomacy.
* Won't go below [MINIMUM_INFLUENCE] */
/** For city-states. Influence is saved in the CITY STATE -> major civ Diplomacy, NOT in the major civ -> city state diplomacy.
* Won't go below [MINIMUM_INFLUENCE]. Note this declaration leads to Major Civs getting MINIMUM_INFLUENCE serialized, but that is ignored. */
var influence = 0f
set(value) {
field = max(value, MINIMUM_INFLUENCE)
@ -142,13 +145,13 @@ class DiplomacyManager() {
if (civInfo.isPlayerCivilization())
return otherCiv().getDiplomacyManager(civInfo).relationshipLevel()
if (civInfo.isCityState()) {
if (influence <= -30 || civInfo.isAtWarWith(otherCiv())) return RelationshipLevel.Unforgivable
if (influence < 30 && civInfo.getTributeWillingness(otherCiv()) > 0) return RelationshipLevel.Afraid
if (influence < 0) return RelationshipLevel.Enemy
if (influence >= 60 && civInfo.getAllyCiv() == otherCivName) return RelationshipLevel.Ally
if (influence >= 30) return RelationshipLevel.Friend
return RelationshipLevel.Neutral
if (civInfo.isCityState()) return when {
influence <= -30 || civInfo.isAtWarWith(otherCiv()) -> RelationshipLevel.Unforgivable
influence < 30 && civInfo.getTributeWillingness(otherCiv()) > 0 -> RelationshipLevel.Afraid
influence < 0 -> RelationshipLevel.Enemy
influence >= 60 && civInfo.getAllyCiv() == otherCivName -> RelationshipLevel.Ally
influence >= 30 -> RelationshipLevel.Friend
else -> RelationshipLevel.Neutral
}
// not entirely sure what to do between AI civs, because they probably have different views of each other,
@ -551,7 +554,7 @@ class DiplomacyManager() {
}
}
/** Everything that happens to both sides equally when war is delcared by one side on the other */
/** Everything that happens to both sides equally when war is declared by one side on the other */
private fun onWarDeclared() {
// Cancel all trades.
for (trade in trades)
@ -652,7 +655,7 @@ class DiplomacyManager() {
// Our ally city states make peace with us
if (thirdCiv.getAllyCiv() == civInfo.civName && thirdCiv.isAtWarWith(otherCiv))
thirdCiv.getDiplomacyManager(otherCiv).makePeace()
// Other ccity states that are not our ally don't like the fact that we made peace with their enemy
// Other city states that are not our ally don't like the fact that we made peace with their enemy
if (thirdCiv.getAllyCiv() != civInfo.civName && thirdCiv.isAtWarWith(otherCiv))
thirdCiv.getDiplomacyManager(civInfo).influence -= 10
}

View File

@ -25,6 +25,7 @@ import com.unciv.ui.civilopedia.CivilopediaScreen
import com.unciv.ui.tilegroups.CityButton
import com.unciv.ui.utils.*
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
import java.text.Collator
import kotlin.math.floor
import kotlin.math.roundToInt
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
@ -60,20 +61,34 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
private fun updateLeftSideTable() {
leftSideTable.clear()
for (civ in viewingCiv.gameInfo.civilizations
leftSideTable.add().padBottom(60f).row() // room so the close button does not cover the first
val civsToDisplay = viewingCiv.gameInfo.civilizations.asSequence()
.filterNot {
it.isDefeated() || it == viewingCiv || it.isBarbarian() || it.isSpectator() || !viewingCiv.knows(
it
it.isDefeated() || it == viewingCiv || it.isBarbarian() || it.isSpectator() ||
!viewingCiv.knows(it)
}
.sortedWith(
compareByDescending<CivilizationInfo>{ it.isMajorCiv() }
.thenBy (Collator.getInstance(), { it.civName.tr() })
)
}) {
for (civ in civsToDisplay) {
val civIndicator = ImageGetter.getNationIndicator(civ.nation, 100f)
val relationship = ImageGetter.getCircle()
if (viewingCiv.isAtWarWith(civ)) relationship.color = Color.RED
else relationship.color = Color.GREEN
relationship.setSize(30f, 30f)
civIndicator.addActor(relationship)
val relationLevel = civ.getDiplomacyManager(viewingCiv).relationshipLevel()
val relationshipIcon = if (civ.isCityState() && relationLevel == RelationshipLevel.Ally)
ImageGetter.getImage("OtherIcons/Star")
.surroundWithCircle(size = 30f, color = relationLevel.color).apply {
actor.color = Color.GOLD
}
else
ImageGetter.getCircle().apply {
color = if (viewingCiv.isAtWarWith(civ)) Color.RED else relationLevel.color
setSize(30f, 30f)
}
civIndicator.addActor(relationshipIcon)
if (civ.isCityState() && civ.questManager.haveQuestsFor(viewingCiv)) {
val questIcon = ImageGetter.getImage("OtherIcons/Quest")
@ -336,6 +351,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
"Gift [$giftAmount] gold (+[$influenceAmount] influence)".toTextButton()
giftButton.onClick {
viewingCiv.giveGoldGift(otherCiv, giftAmount)
updateLeftSideTable()
updateRightSide(otherCiv)
}
diplomacyTable.add(giftButton).row()
@ -557,6 +573,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
denounceButton.onClick {
YesNoPopup("Denounce [${otherCiv.civName}]?", {
diplomacyManager.denounce()
updateLeftSideTable()
setRightSideFlavorText(otherCiv, "We will remember this.", "Very well.")
}, this).open()
}