mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-19 12:18:53 +07:00
Send speed for all trade offers, instead of using static - allows for 'next turn' without setting UncivGame.current
This commit is contained in:
@ -60,8 +60,8 @@ object DeclareWarTargetAutomation {
|
||||
|
||||
// Send them an offer
|
||||
val tradeLogic = TradeLogic(civInfo, thirdCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration, speed = civInfo.gameInfo.speed))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration, speed = civInfo.gameInfo.speed))
|
||||
|
||||
thirdCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
|
||||
|
||||
@ -89,7 +89,7 @@ object DeclareWarTargetAutomation {
|
||||
|
||||
// Send them an offer
|
||||
val tradeLogic = TradeLogic(civInfo, thirdCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration, speed = civInfo.gameInfo.speed))
|
||||
// TODO: Maybe add in payment requests in some situations
|
||||
thirdCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
|
||||
|
||||
|
@ -125,8 +125,8 @@ object DiplomacyAutomation {
|
||||
if ((1..10).random() < 7) continue
|
||||
if (wantsToOpenBorders(civInfo, otherCiv)) {
|
||||
val tradeLogic = TradeLogic(civInfo, otherCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement, speed = civInfo.gameInfo.speed))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement, speed = civInfo.gameInfo.speed))
|
||||
|
||||
otherCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
|
||||
} else {
|
||||
@ -168,8 +168,8 @@ object DiplomacyAutomation {
|
||||
if ((1..10).random() <= 5 * civInfo.getPersonality().modifierFocus(PersonalityValue.Science, .3f)) continue
|
||||
val tradeLogic = TradeLogic(civInfo, otherCiv)
|
||||
val cost = civInfo.diplomacyFunctions.getResearchAgreementCost(otherCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, cost))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, cost))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, cost, civInfo.gameInfo.speed))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, cost, civInfo.gameInfo.speed))
|
||||
|
||||
otherCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
|
||||
}
|
||||
@ -192,8 +192,8 @@ object DiplomacyAutomation {
|
||||
if (wantsToSignDefensivePact(civInfo, otherCiv)) {
|
||||
//todo: Add more in depth evaluation here
|
||||
val tradeLogic = TradeLogic(civInfo, otherCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
|
||||
otherCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
|
||||
} else {
|
||||
@ -293,17 +293,19 @@ object DiplomacyAutomation {
|
||||
internal fun offerPeaceTreaty(civInfo: Civilization) {
|
||||
if (!civInfo.isAtWar() || civInfo.cities.isEmpty() || civInfo.diplomacy.isEmpty()) return
|
||||
|
||||
val enemiesCiv = civInfo.diplomacy.filter { it.value.diplomaticStatus == DiplomaticStatus.War }
|
||||
val enemiesCiv = civInfo.diplomacy.asSequence()
|
||||
.filter { it.value.diplomaticStatus == DiplomaticStatus.War }
|
||||
.map { it.value.otherCiv() }
|
||||
.filterNot {
|
||||
it == civInfo || it.isBarbarian || it.cities.isEmpty()
|
||||
|| it.getDiplomacyManager(civInfo)!!.hasFlag(DiplomacyFlags.DeclaredWar)
|
||||
|| civInfo.getDiplomacyManager(it)!!.hasFlag(DiplomacyFlags.DeclaredWar)
|
||||
|| it.getDiplomacyManager(civInfo)!!.hasFlag(DiplomacyFlags.DeclaredWar)
|
||||
|| civInfo.getDiplomacyManager(it)!!.hasFlag(DiplomacyFlags.DeclaredWar)
|
||||
}.filter { !civInfo.getDiplomacyManager(it)!!.hasFlag(DiplomacyFlags.DeclinedPeace) }
|
||||
// Don't allow AIs to offer peace to city states allied with their enemies
|
||||
.filterNot { it.isCityState && it.getAllyCiv() != null && civInfo.isAtWarWith(civInfo.gameInfo.getCivilization(it.getAllyCiv()!!)) }
|
||||
// ignore civs that we have already offered peace this turn as a counteroffer to another civ's peace offer
|
||||
.filter { it.tradeRequests.none { tradeRequest -> tradeRequest.requestingCiv == civInfo.civName && tradeRequest.trade.isPeaceTreaty() } }
|
||||
.toList()
|
||||
|
||||
for (enemy in enemiesCiv) {
|
||||
if (hasAtLeastMotivationToAttack(civInfo, enemy, 10f) >= 10) {
|
||||
@ -319,8 +321,8 @@ object DiplomacyAutomation {
|
||||
// pay for peace
|
||||
val tradeLogic = TradeLogic(civInfo, enemy)
|
||||
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
|
||||
if (enemy.isMajorCiv()) {
|
||||
var moneyWeNeedToPay = -TradeEvaluation().evaluatePeaceCostForThem(civInfo, enemy)
|
||||
@ -330,13 +332,13 @@ object DiplomacyAutomation {
|
||||
moneyWeNeedToPay = civInfo.gold // As much as possible
|
||||
}
|
||||
tradeLogic.currentTrade.ourOffers.add(
|
||||
TradeOffer("Gold".tr(), TradeOfferType.Gold, moneyWeNeedToPay)
|
||||
TradeOffer("Gold".tr(), TradeOfferType.Gold, moneyWeNeedToPay, civInfo.gameInfo.speed)
|
||||
)
|
||||
} else if (moneyWeNeedToPay < -100) {
|
||||
val moneyTheyNeedToPay = abs(moneyWeNeedToPay).coerceAtMost(enemy.gold)
|
||||
if (moneyTheyNeedToPay > 0) {
|
||||
tradeLogic.currentTrade.theirOffers.add(
|
||||
TradeOffer("Gold".tr(), TradeOfferType.Gold, moneyTheyNeedToPay)
|
||||
TradeOffer("Gold".tr(), TradeOfferType.Gold, moneyTheyNeedToPay, civInfo.gameInfo.speed)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -363,7 +365,7 @@ object DiplomacyAutomation {
|
||||
|
||||
val tradeLogic = TradeLogic(civInfo, civToAsk)
|
||||
// TODO: add gold offer here
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(enemyCiv.civName, TradeOfferType.WarDeclaration))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(enemyCiv.civName, TradeOfferType.WarDeclaration, speed = civInfo.gameInfo.speed))
|
||||
civToAsk.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse()))
|
||||
}
|
||||
}
|
||||
|
@ -224,15 +224,15 @@ class CityConquestFunctions(val city: City) {
|
||||
foundingCiv.getDiplomacyManagerOrMeet(conqueringCiv)
|
||||
.addModifier(DiplomaticModifiers.CapturedOurCities, respectForLiberatingOurCity)
|
||||
val openBordersTrade = TradeLogic(foundingCiv, conqueringCiv)
|
||||
openBordersTrade.currentTrade.ourOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement))
|
||||
openBordersTrade.currentTrade.ourOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement, speed = conqueringCiv.gameInfo.speed))
|
||||
openBordersTrade.acceptTrade(false)
|
||||
} else {
|
||||
//Liberating a city state gives a large amount of influence, and peace
|
||||
foundingCiv.getDiplomacyManagerOrMeet(conqueringCiv).setInfluence(90f)
|
||||
if (foundingCiv.isAtWarWith(conqueringCiv)) {
|
||||
val tradeLogic = TradeLogic(foundingCiv, conqueringCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = conqueringCiv.gameInfo.speed))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = conqueringCiv.gameInfo.speed))
|
||||
tradeLogic.acceptTrade(false)
|
||||
}
|
||||
}
|
||||
|
@ -482,8 +482,8 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
|
||||
|
||||
// Make the peace treaty so that the civ can't declare war immedietly
|
||||
val tradeLogic = TradeLogic(thirdCiv, otherCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty))
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
thirdCivDiplo.trades.add(tradeLogic.currentTrade)
|
||||
thirdCivDiplo.otherCivDiplomacy().trades.add(tradeLogic.currentTrade.reverse())
|
||||
}
|
||||
|
@ -21,20 +21,21 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil
|
||||
val offers = TradeOffersList()
|
||||
if (civInfo.isCityState && otherCivilization.isCityState) return offers
|
||||
if (civInfo.isAtWarWith(otherCivilization))
|
||||
offers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty))
|
||||
offers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
|
||||
if (!otherCivilization.getDiplomacyManager(civInfo)!!.hasOpenBorders
|
||||
&& !otherCivilization.isCityState
|
||||
&& civInfo.hasUnique(UniqueType.EnablesOpenBorders)
|
||||
&& otherCivilization.hasUnique(UniqueType.EnablesOpenBorders)) {
|
||||
offers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement))
|
||||
offers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement, speed = civInfo.gameInfo.speed))
|
||||
}
|
||||
|
||||
if (civInfo.diplomacyFunctions.canSignResearchAgreementNoCostWith(otherCivilization))
|
||||
offers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, civInfo.diplomacyFunctions.getResearchAgreementCost(otherCivilization)))
|
||||
offers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty,
|
||||
civInfo.diplomacyFunctions.getResearchAgreementCost(otherCivilization), civInfo.gameInfo.speed))
|
||||
|
||||
if (civInfo.diplomacyFunctions.canSignDefensivePactWith(otherCivilization))
|
||||
offers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty))
|
||||
offers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty, speed = civInfo.gameInfo.speed))
|
||||
|
||||
for (entry in civInfo.getCivResourcesWithOriginsForTrade()
|
||||
.filterNot { it.resource.resourceType == ResourceType.Bonus }
|
||||
@ -42,17 +43,17 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil
|
||||
) {
|
||||
val resourceTradeOfferType = if (entry.resource.resourceType == ResourceType.Luxury) TradeOfferType.Luxury_Resource
|
||||
else TradeOfferType.Strategic_Resource
|
||||
offers.add(TradeOffer(entry.resource.name, resourceTradeOfferType, entry.amount))
|
||||
offers.add(TradeOffer(entry.resource.name, resourceTradeOfferType, entry.amount, speed = civInfo.gameInfo.speed))
|
||||
}
|
||||
|
||||
offers.add(TradeOffer("Gold", TradeOfferType.Gold, civInfo.gold))
|
||||
offers.add(TradeOffer("Gold per turn", TradeOfferType.Gold_Per_Turn, civInfo.stats.statsForNextTurn.gold.toInt()))
|
||||
offers.add(TradeOffer("Gold", TradeOfferType.Gold, civInfo.gold, speed = civInfo.gameInfo.speed))
|
||||
offers.add(TradeOffer("Gold per turn", TradeOfferType.Gold_Per_Turn, civInfo.stats.statsForNextTurn.gold.toInt(), civInfo.gameInfo.speed))
|
||||
|
||||
if (!civInfo.isOneCityChallenger() && !otherCivilization.isOneCityChallenger()
|
||||
&& !civInfo.isCityState && !otherCivilization.isCityState
|
||||
) {
|
||||
for (city in civInfo.cities.filterNot { it.isCapital() || it.isInResistance() })
|
||||
offers.add(TradeOffer(city.id, TradeOfferType.City))
|
||||
offers.add(TradeOffer(city.id, TradeOfferType.City, speed = civInfo.gameInfo.speed))
|
||||
}
|
||||
|
||||
val otherCivsWeKnow = civInfo.getKnownCivs()
|
||||
@ -62,7 +63,7 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil
|
||||
val civsWeKnowAndTheyDont = otherCivsWeKnow
|
||||
.filter { !otherCivilization.diplomacy.containsKey(it.civName) && !it.isDefeated() }
|
||||
for (thirdCiv in civsWeKnowAndTheyDont) {
|
||||
offers.add(TradeOffer(thirdCiv.civName, TradeOfferType.Introduction))
|
||||
offers.add(TradeOffer(thirdCiv.civName, TradeOfferType.Introduction, speed = civInfo.gameInfo.speed))
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +74,7 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil
|
||||
val civsWeArentAtWarWith = civsWeBothKnow
|
||||
.filter { civInfo.getDiplomacyManager(it)!!.canDeclareWar() }
|
||||
for (thirdCiv in civsWeArentAtWarWith) {
|
||||
offers.add(TradeOffer(thirdCiv.civName, TradeOfferType.WarDeclaration))
|
||||
offers.add(TradeOffer(thirdCiv.civName, TradeOfferType.WarDeclaration, speed = civInfo.gameInfo.speed))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ data class TradeOffer(val name: String, val type: TradeOfferType, var amount: In
|
||||
name: String,
|
||||
type: TradeOfferType,
|
||||
amount: Int = 1,
|
||||
speed: Speed = UncivGame.Current.gameInfo!!.speed
|
||||
speed: Speed
|
||||
) : this(name, type, amount, duration = -1) {
|
||||
duration = when {
|
||||
type.isImmediate -> -1 // -1 for offers that are immediate (e.g. gold transfer)
|
||||
|
@ -32,7 +32,6 @@ import com.unciv.ui.components.input.onClick
|
||||
import com.unciv.ui.components.widgets.ColorMarkupLabel
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import com.unciv.ui.popups.ConfirmPopup
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class CityStateDiplomacyTable(private val diplomacyScreen: DiplomacyScreen) {
|
||||
val viewingCiv = diplomacyScreen.viewingCiv
|
||||
@ -250,16 +249,10 @@ class CityStateDiplomacyTable(private val diplomacyScreen: DiplomacyScreen) {
|
||||
) {
|
||||
val tradeLogic = TradeLogic(viewingCiv, otherCiv)
|
||||
tradeLogic.currentTrade.ourOffers.add(
|
||||
TradeOffer(
|
||||
Constants.peaceTreaty,
|
||||
TradeOfferType.Treaty
|
||||
)
|
||||
TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = viewingCiv.gameInfo.speed)
|
||||
)
|
||||
tradeLogic.currentTrade.theirOffers.add(
|
||||
TradeOffer(
|
||||
Constants.peaceTreaty,
|
||||
TradeOfferType.Treaty
|
||||
)
|
||||
TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = viewingCiv.gameInfo.speed)
|
||||
)
|
||||
tradeLogic.acceptTrade()
|
||||
diplomacyScreen.updateLeftSideTable(otherCiv)
|
||||
|
@ -106,7 +106,7 @@ class MajorCivDiplomacyTable(private val diplomacyScreen: DiplomacyScreen) {
|
||||
val negotiatePeaceButton = "Negotiate Peace".toTextButton()
|
||||
negotiatePeaceButton.onClick {
|
||||
val tradeTable = diplomacyScreen.setTrade(otherCiv)
|
||||
val peaceTreaty = TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)
|
||||
val peaceTreaty = TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, speed = viewingCiv.gameInfo.speed)
|
||||
tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty)
|
||||
tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty)
|
||||
tradeTable.offerColumnsTable.update()
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.unciv.ui.screens.worldscreen.status
|
||||
|
||||
import com.unciv.GUI
|
||||
import com.unciv.logic.civilization.managers.TurnManager
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.components.UncivTooltip.Companion.addTooltip
|
||||
@ -14,14 +13,12 @@ import com.unciv.ui.images.IconTextButton
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import com.unciv.ui.popups.hasOpenPopups
|
||||
import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||
import com.unciv.utils.Concurrency
|
||||
|
||||
class NextTurnButton(
|
||||
private val worldScreen: WorldScreen
|
||||
) : IconTextButton("", null, 30) {
|
||||
private var nextTurnAction = NextTurnAction.Default
|
||||
init {
|
||||
// label.setFontSize(30)
|
||||
labelCell.pad(10f)
|
||||
onActivation { nextTurnAction.action(worldScreen) }
|
||||
onRightClick { NextTurnMenu(stage, this, this, worldScreen) }
|
||||
@ -62,5 +59,5 @@ class NextTurnButton(
|
||||
|
||||
private fun getNextTurnAction(worldScreen: WorldScreen) =
|
||||
// Guaranteed to return a non-null NextTurnAction because the last isChoice always returns true
|
||||
NextTurnAction.values().first { it.isChoice(worldScreen) }
|
||||
NextTurnAction.entries.first { it.isChoice(worldScreen) }
|
||||
}
|
||||
|
Reference in New Issue
Block a user