From c9bcf10f2a5733d555e1c2936f523ed6d0777ecb Mon Sep 17 00:00:00 2001 From: yairm210 Date: Thu, 27 Jun 2024 23:18:16 +0300 Subject: [PATCH] naming: TradeType -> TradeOfferType --- .../DeclareWarTargetAutomation.kt | 8 +- .../civilization/DiplomacyAutomation.kt | 24 +++--- .../civilization/TradeAutomation.kt | 22 ++--- .../city/managers/CityConquestFunctions.kt | 8 +- .../diplomacy/DiplomacyManager.kt | 12 +-- .../diplomacy/DiplomacyTurnManager.kt | 10 +-- core/src/com/unciv/logic/trade/Trade.kt | 10 +-- .../com/unciv/logic/trade/TradeEvaluation.kt | 80 +++++++++---------- core/src/com/unciv/logic/trade/TradeLogic.kt | 46 +++++------ core/src/com/unciv/logic/trade/TradeOffer.kt | 14 ++-- .../trade/{TradeType.kt => TradeOfferType.kt} | 2 +- .../CityStateDiplomacyTable.kt | 6 +- .../diplomacyscreen/MajorCivDiplomacyTable.kt | 4 +- .../diplomacyscreen/OfferColumnsTable.kt | 10 +-- .../diplomacyscreen/OffersListScroll.kt | 26 +++--- .../ui/screens/diplomacyscreen/TradeTable.kt | 10 +-- .../overviewscreen/ResourcesOverviewTab.kt | 4 +- .../ui/screens/worldscreen/TradePopup.kt | 4 +- .../diplomacy/GoldGiftingTests.kt | 10 +-- 19 files changed, 155 insertions(+), 155 deletions(-) rename core/src/com/unciv/logic/trade/{TradeType.kt => TradeOfferType.kt} (92%) diff --git a/core/src/com/unciv/logic/automation/civilization/DeclareWarTargetAutomation.kt b/core/src/com/unciv/logic/automation/civilization/DeclareWarTargetAutomation.kt index 45e2157289..7e07f8961c 100644 --- a/core/src/com/unciv/logic/automation/civilization/DeclareWarTargetAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/DeclareWarTargetAutomation.kt @@ -6,7 +6,7 @@ import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeRequest -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.ui.screens.victoryscreen.RankingType object DeclareWarTargetAutomation { @@ -60,8 +60,8 @@ object DeclareWarTargetAutomation { // Send them an offer val tradeLogic = TradeLogic(civInfo, thirdCiv) - tradeLogic.currentTrade.ourOffers.add(TradeOffer(target.civName, TradeType.WarDeclaration)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer(target.civName, TradeType.WarDeclaration)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration)) 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, TradeType.WarDeclaration)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(target.civName, TradeOfferType.WarDeclaration)) // TODO: Maybe add in payment requests in some situations thirdCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse())) diff --git a/core/src/com/unciv/logic/automation/civilization/DiplomacyAutomation.kt b/core/src/com/unciv/logic/automation/civilization/DiplomacyAutomation.kt index 2b1049bc06..38f511356b 100644 --- a/core/src/com/unciv/logic/automation/civilization/DiplomacyAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/DiplomacyAutomation.kt @@ -15,7 +15,7 @@ import com.unciv.logic.trade.TradeEvaluation import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeRequest -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.nation.PersonalityValue import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.translations.tr @@ -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, TradeType.Agreement)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.openBorders, TradeType.Agreement)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement)) 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, TradeType.Treaty, cost)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, cost)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, cost)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, cost)) 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, TradeType.Treaty)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.defensivePact, TradeType.Treaty)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty)) otherCiv.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse())) } else { @@ -319,8 +319,8 @@ object DiplomacyAutomation { // pay for peace val tradeLogic = TradeLogic(civInfo, enemy) - tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)) if (enemy.isMajorCiv()) { var moneyWeNeedToPay = -TradeEvaluation().evaluatePeaceCostForThem(civInfo, enemy) @@ -330,13 +330,13 @@ object DiplomacyAutomation { moneyWeNeedToPay = civInfo.gold // As much as possible } tradeLogic.currentTrade.ourOffers.add( - TradeOffer("Gold".tr(), TradeType.Gold, moneyWeNeedToPay) + TradeOffer("Gold".tr(), TradeOfferType.Gold, moneyWeNeedToPay) ) } else if (moneyWeNeedToPay < -100) { val moneyTheyNeedToPay = abs(moneyWeNeedToPay).coerceAtMost(enemy.gold) if (moneyTheyNeedToPay > 0) { tradeLogic.currentTrade.theirOffers.add( - TradeOffer("Gold".tr(), TradeType.Gold, moneyTheyNeedToPay) + TradeOffer("Gold".tr(), TradeOfferType.Gold, moneyTheyNeedToPay) ) } } @@ -362,7 +362,7 @@ object DiplomacyAutomation { val tradeLogic = TradeLogic(civInfo, civToAsk) // TODO: add gold offer here - tradeLogic.currentTrade.theirOffers.add(TradeOffer(enemyCiv.civName, TradeType.WarDeclaration)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(enemyCiv.civName, TradeOfferType.WarDeclaration)) civToAsk.tradeRequests.add(TradeRequest(civInfo.civName, tradeLogic.currentTrade.reverse())) } } diff --git a/core/src/com/unciv/logic/automation/civilization/TradeAutomation.kt b/core/src/com/unciv/logic/automation/civilization/TradeAutomation.kt index a1510c1d2e..68dbaa1d51 100644 --- a/core/src/com/unciv/logic/automation/civilization/TradeAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/TradeAutomation.kt @@ -11,7 +11,7 @@ import com.unciv.logic.trade.TradeEvaluation import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeRequest -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import kotlin.math.min object TradeAutomation { @@ -67,17 +67,17 @@ object TradeAutomation { val counterofferGifts = ArrayList() for (offer in tradeLogic.theirAvailableOffers) { - if ((offer.type == TradeType.Gold || offer.type == TradeType.Gold_Per_Turn) + if ((offer.type == TradeOfferType.Gold || offer.type == TradeOfferType.Gold_Per_Turn) && tradeRequest.trade.ourOffers.any { it.type == offer.type }) continue // Don't want to counteroffer straight gold for gold, that's silly if (!offer.isTradable()) continue // For example resources gained by trade or CS - if (offer.type == TradeType.City) + if (offer.type == TradeOfferType.City) continue // Players generally don't want to give up their cities, and they might misclick if (tradeLogic.currentTrade.theirOffers.any { it.type == offer.type && it.name == offer.name }) continue // So you don't get double offers of open borders declarations of war etc. - if (offer.type == TradeType.Treaty) + if (offer.type == TradeOfferType.Treaty) continue // Don't try to counter with a defensive pact or research pact val value = evaluation.evaluateBuyCostWithInflation(offer, civInfo, otherCiv, tradeRequest.trade) @@ -105,7 +105,7 @@ object TradeAutomation { } // Only ask for enough of each resource to get maximum price - for (ask in counterofferAsks.keys.filter { it.type == TradeType.Luxury_Resource || it.type == TradeType.Strategic_Resource }) { + for (ask in counterofferAsks.keys.filter { it.type == TradeOfferType.Luxury_Resource || it.type == TradeOfferType.Strategic_Resource }) { // Remove 1 amount as long as doing so does not change the price val originalValue = counterofferAsks[ask]!! while (ask.amount > 1 @@ -119,7 +119,7 @@ object TradeAutomation { // Adjust any gold asked for val toRemove = ArrayList() for (goldAsk in counterofferAsks.keys - .filter { it.type == TradeType.Gold_Per_Turn || it.type == TradeType.Gold } + .filter { it.type == TradeOfferType.Gold_Per_Turn || it.type == TradeOfferType.Gold } .sortedByDescending { it.type.ordinal }) { // Do GPT first val valueOfOne = evaluation.evaluateBuyCostWithInflation(TradeOffer(goldAsk.name, goldAsk.type, 1, goldAsk.duration), civInfo, otherCiv, tradeRequest.trade) val amountCanBeRemoved = deltaInOurFavor / valueOfOne @@ -137,7 +137,7 @@ object TradeAutomation { deltaInOurFavor = (deltaInOurFavor * 2) / 3 // Only compensate some of it though, they're the ones asking us // First give some GPT, then lump sum - but only if they're not already offering the same for (ourGold in tradeLogic.ourAvailableOffers - .filter { it.isTradable() && (it.type == TradeType.Gold || it.type == TradeType.Gold_Per_Turn) } + .filter { it.isTradable() && (it.type == TradeOfferType.Gold || it.type == TradeOfferType.Gold_Per_Turn) } .sortedByDescending { it.type.ordinal }) { if (tradeLogic.currentTrade.theirOffers.none { it.type == ourGold.type } && counterofferAsks.keys.none { it.type == ourGold.type } ) { @@ -196,18 +196,18 @@ object TradeAutomation { private fun potentialLuxuryTrades(civInfo: Civilization, otherCivInfo: Civilization): ArrayList { val tradeLogic = TradeLogic(civInfo, otherCivInfo) val ourTradableLuxuryResources = tradeLogic.ourAvailableOffers - .filter { it.type == TradeType.Luxury_Resource && it.amount > 1 } + .filter { it.type == TradeOfferType.Luxury_Resource && it.amount > 1 } val theirTradableLuxuryResources = tradeLogic.theirAvailableOffers - .filter { it.type == TradeType.Luxury_Resource && it.amount > 1 } + .filter { it.type == TradeOfferType.Luxury_Resource && it.amount > 1 } val weHaveTheyDont = ourTradableLuxuryResources .filter { resource -> tradeLogic.theirAvailableOffers - .none { it.name == resource.name && it.type == TradeType.Luxury_Resource } + .none { it.name == resource.name && it.type == TradeOfferType.Luxury_Resource } } val theyHaveWeDont = theirTradableLuxuryResources .filter { resource -> tradeLogic.ourAvailableOffers - .none { it.name == resource.name && it.type == TradeType.Luxury_Resource } + .none { it.name == resource.name && it.type == TradeOfferType.Luxury_Resource } }.sortedBy { civInfo.cities.count { city -> city.demandedResource == it.name } } // Prioritize resources that get WLTKD val trades = ArrayList() for (i in 0..min(weHaveTheyDont.lastIndex, theyHaveWeDont.lastIndex)) { diff --git a/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt b/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt index 5fcf4b09e4..5c1be21045 100644 --- a/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt +++ b/core/src/com/unciv/logic/city/managers/CityConquestFunctions.kt @@ -12,7 +12,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers import com.unciv.logic.civilization.diplomacy.DiplomaticStatus import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.unique.UniqueType import kotlin.math.max import kotlin.math.min @@ -222,15 +222,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, TradeType.Agreement)) + openBordersTrade.currentTrade.ourOffers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement)) 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, TradeType.Treaty)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)) tradeLogic.acceptTrade(false) } } diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 362aa210ce..d7b3497d79 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -10,7 +10,7 @@ import com.unciv.logic.trade.Trade import com.unciv.logic.trade.TradeEvaluation import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.tile.ResourceSupplyList import com.unciv.models.ruleset.unique.StateForConditionals import com.unciv.models.ruleset.unique.UniqueTriggerActivation @@ -401,9 +401,9 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization { fun goldPerTurn(): Int { var goldPerTurnForUs = 0 for (trade in trades) { - for (offer in trade.ourOffers.filter { it.type == TradeType.Gold_Per_Turn }) + for (offer in trade.ourOffers.filter { it.type == TradeOfferType.Gold_Per_Turn }) goldPerTurnForUs -= offer.amount - for (offer in trade.theirOffers.filter { it.type == TradeType.Gold_Per_Turn }) + for (offer in trade.theirOffers.filter { it.type == TradeOfferType.Gold_Per_Turn }) goldPerTurnForUs += offer.amount } return goldPerTurnForUs @@ -414,7 +414,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization { val newResourceSupplyList = ResourceSupplyList() val resourcesMap = civInfo.gameInfo.ruleset.tileResources val isResourceFilter: (TradeOffer) -> Boolean = { - (it.type == TradeType.Strategic_Resource || it.type == TradeType.Luxury_Resource) + (it.type == TradeOfferType.Strategic_Resource || it.type == TradeOfferType.Luxury_Resource) && resourcesMap.containsKey(it.name) && !resourcesMap[it.name]!!.isStockpiled() } @@ -478,8 +478,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, TradeType.Treaty)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)) thirdCivDiplo.trades.add(tradeLogic.currentTrade) thirdCivDiplo.otherCivDiplomacy().trades.add(tradeLogic.currentTrade.reverse()) } diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyTurnManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyTurnManager.kt index b2f4345d95..fc0f3d3d46 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyTurnManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyTurnManager.kt @@ -6,7 +6,7 @@ import com.unciv.logic.civilization.NotificationCategory import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.trade.Trade import com.unciv.logic.trade.TradeOffer -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.unique.UniqueType import com.unciv.ui.components.extensions.toPercent import kotlin.math.absoluteValue @@ -34,7 +34,7 @@ object DiplomacyTurnManager { .filter { it.amount < 0 && !it.resource.isStockpiled() }.map { it.resource.name } for (offer in trade.ourOffers) { - if (offer.type in listOf(TradeType.Luxury_Resource, TradeType.Strategic_Resource) + if (offer.type in listOf(TradeOfferType.Luxury_Resource, TradeOfferType.Strategic_Resource) && (offer.name in negativeCivResources || !civInfo.gameInfo.ruleset.tileResources.containsKey(offer.name)) ) { @@ -64,10 +64,10 @@ object DiplomacyTurnManager { private fun DiplomacyManager.remakePeaceTreaty(durationLeft: Int) { val treaty = Trade() treaty.ourOffers.add( - TradeOffer(Constants.peaceTreaty, TradeType.Treaty, duration = durationLeft) + TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, duration = durationLeft) ) treaty.theirOffers.add( - TradeOffer(Constants.peaceTreaty, TradeType.Treaty, duration = durationLeft) + TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty, duration = durationLeft) ) trades.add(treaty) otherCiv().getDiplomacyManager(civInfo)!!.trades.add(treaty) @@ -242,7 +242,7 @@ object DiplomacyTurnManager { civInfo.updateStatsForNextTurn() // if they were bringing us gold per turn if (trade.theirOffers.union(trade.ourOffers) // if resources were involved - .any { it.type == TradeType.Luxury_Resource || it.type == TradeType.Strategic_Resource }) + .any { it.type == TradeOfferType.Luxury_Resource || it.type == TradeOfferType.Strategic_Resource }) civInfo.cache.updateCivResources() } } diff --git a/core/src/com/unciv/logic/trade/Trade.kt b/core/src/com/unciv/logic/trade/Trade.kt index 7594fe47b2..501754d1c3 100644 --- a/core/src/com/unciv/logic/trade/Trade.kt +++ b/core/src/com/unciv/logic/trade/Trade.kt @@ -47,7 +47,7 @@ class Trade : IsPartOfGameInfoSerialization { theirOffers.addAll(trade.theirOffers) } - fun isPeaceTreaty() = ourOffers.any { it.type == TradeType.Treaty && it.name == Constants.peaceTreaty } + fun isPeaceTreaty() = ourOffers.any { it.type == TradeOfferType.Treaty && it.name == Constants.peaceTreaty } } @@ -56,8 +56,8 @@ class TradeRequest : IsPartOfGameInfoSerialization { val requestingCivInfo = decliningCiv.gameInfo.getCivilization(requestingCiv) val requestingCivDiploManager = requestingCivInfo.getDiplomacyManager(decliningCiv)!! // the numbers of the flags (20,5) are the amount of turns to wait until offering again - if (trade.ourOffers.all { it.type == TradeType.Luxury_Resource } - && trade.theirOffers.all { it.type == TradeType.Luxury_Resource }) + if (trade.ourOffers.all { it.type == TradeOfferType.Luxury_Resource } + && trade.theirOffers.all { it.type == TradeOfferType.Luxury_Resource }) requestingCivDiploManager.setFlag(DiplomacyFlags.DeclinedLuxExchange,5 - (requestingCivInfo.getPersonality()[PersonalityValue.Commerce] / 2).toInt()) if (trade.ourOffers.any { it.name == Constants.researchAgreement }) requestingCivDiploManager.setFlag(DiplomacyFlags.DeclinedResearchAgreement,15 - requestingCivInfo.getPersonality()[PersonalityValue.Science].toInt()) @@ -65,9 +65,9 @@ class TradeRequest : IsPartOfGameInfoSerialization { requestingCivDiploManager.setFlag(DiplomacyFlags.DeclinedDefensivePact,10) if (trade.ourOffers.any { it.name == Constants.openBorders }) requestingCivDiploManager.setFlag(DiplomacyFlags.DeclinedOpenBorders, if (decliningCiv.isAI()) 5 else 10) - if (trade.theirOffers.any { it.type == TradeType.WarDeclaration }) + if (trade.theirOffers.any { it.type == TradeOfferType.WarDeclaration }) requestingCivDiploManager.setFlag(DiplomacyFlags.DeclinedJoinWarOffer, if (decliningCiv.isAI()) 5 else 10) - if (trade.ourOffers.any { it.type == TradeType.WarDeclaration }) + if (trade.ourOffers.any { it.type == TradeOfferType.WarDeclaration }) requestingCivDiploManager.otherCivDiplomacy().setFlag(DiplomacyFlags.DeclinedJoinWarOffer, if (decliningCiv.isAI()) 5 else 10) if (trade.isPeaceTreaty()) requestingCivDiploManager.setFlag(DiplomacyFlags.DeclinedPeace, 3) diff --git a/core/src/com/unciv/logic/trade/TradeEvaluation.kt b/core/src/com/unciv/logic/trade/TradeEvaluation.kt index aca6979fb5..9a6da13a56 100644 --- a/core/src/com/unciv/logic/trade/TradeEvaluation.kt +++ b/core/src/com/unciv/logic/trade/TradeEvaluation.kt @@ -25,8 +25,8 @@ class TradeEvaluation { // Edge case time! Guess what happens if you offer a peace agreement to the AI for all their cities except for the capital, // and then capture their capital THAT SAME TURN? It can agree, leading to the civilization getting instantly destroyed! - if (trade.ourOffers.count { it.type == TradeType.City } == offerer.cities.size - || trade.theirOffers.count { it.type == TradeType.City } == tradePartner.cities.size) + if (trade.ourOffers.count { it.type == TradeOfferType.City } == offerer.cities.size + || trade.theirOffers.count { it.type == TradeOfferType.City } == tradePartner.cities.size) return false for (offer in trade.ourOffers) @@ -46,16 +46,16 @@ class TradeEvaluation { } return when (tradeOffer.type) { - TradeType.Gold -> true // even if they go negative it's okay - TradeType.Gold_Per_Turn -> true // even if they go negative it's okay - TradeType.Treaty -> true - TradeType.Agreement -> true - TradeType.Luxury_Resource -> hasResource(tradeOffer) - TradeType.Strategic_Resource -> hasResource(tradeOffer) - TradeType.Technology -> true - TradeType.Introduction -> !tradePartner.knows(tradeOffer.name) // You can't introduce them to someone they already know! - TradeType.WarDeclaration -> offerer.getDiplomacyManager(tradeOffer.name)!!.canDeclareWar() - TradeType.City -> offerer.cities.any { it.id == tradeOffer.name } + TradeOfferType.Gold -> true // even if they go negative it's okay + TradeOfferType.Gold_Per_Turn -> true // even if they go negative it's okay + TradeOfferType.Treaty -> true + TradeOfferType.Agreement -> true + TradeOfferType.Luxury_Resource -> hasResource(tradeOffer) + TradeOfferType.Strategic_Resource -> hasResource(tradeOffer) + TradeOfferType.Technology -> true + TradeOfferType.Introduction -> !tradePartner.knows(tradeOffer.name) // You can't introduce them to someone they already know! + TradeOfferType.WarDeclaration -> offerer.getDiplomacyManager(tradeOffer.name)!!.canDeclareWar() + TradeOfferType.City -> offerer.cities.any { it.id == tradeOffer.name } } } @@ -64,14 +64,14 @@ class TradeEvaluation { } fun getTradeAcceptability(trade: Trade, evaluator: Civilization, tradePartner: Civilization, includeDiplomaticGifts:Boolean = false): Int { - val citiesAskedToSurrender = trade.ourOffers.count { it.type == TradeType.City } + val citiesAskedToSurrender = trade.ourOffers.count { it.type == TradeOfferType.City } val maxCitiesToSurrender = ceil(evaluator.cities.size.toFloat() / 5).toInt() if (citiesAskedToSurrender > maxCitiesToSurrender) { return Int.MIN_VALUE } val sumOfTheirOffers = trade.theirOffers.asSequence() - .filter { it.type != TradeType.Treaty } // since treaties should only be evaluated once for 2 sides + .filter { it.type != TradeOfferType.Treaty } // since treaties should only be evaluated once for 2 sides .map { evaluateBuyCostWithInflation(it, evaluator, tradePartner, trade) }.sum() var sumOfOurOffers = trade.ourOffers.sumOf { evaluateSellCostWithInflation(it, evaluator, tradePartner, trade) } @@ -95,7 +95,7 @@ class TradeEvaluation { } fun evaluateBuyCostWithInflation(offer: TradeOffer, civInfo: Civilization, tradePartner: Civilization, trade: Trade): Int { - if (offer.type != TradeType.Gold && offer.type != TradeType.Gold_Per_Turn) + if (offer.type != TradeOfferType.Gold && offer.type != TradeOfferType.Gold_Per_Turn) return (evaluateBuyCost(offer, civInfo, tradePartner, trade) / getGoldInflation(civInfo)).toInt() return evaluateBuyCost(offer, civInfo, tradePartner, trade) } @@ -105,10 +105,10 @@ class TradeEvaluation { */ private fun evaluateBuyCost(offer: TradeOffer, civInfo: Civilization, tradePartner: Civilization, trade: Trade): Int { when (offer.type) { - TradeType.Gold -> return offer.amount + TradeOfferType.Gold -> return offer.amount // GPT loses 1% of value for each 'future' turn, meaning: gold now is more valuable than gold in the future - TradeType.Gold_Per_Turn -> return (1..offer.duration).sumOf { offer.amount * 0.99.pow(it) }.toInt() - TradeType.Treaty -> { + TradeOfferType.Gold_Per_Turn -> return (1..offer.duration).sumOf { offer.amount * 0.99.pow(it) }.toInt() + TradeOfferType.Treaty -> { return when (offer.name) { // Since it will be evaluated twice, once when they evaluate our offer and once when they evaluate theirs Constants.peaceTreaty -> evaluatePeaceCostForThem(civInfo, tradePartner) @@ -118,7 +118,7 @@ class TradeEvaluation { } } - TradeType.Luxury_Resource -> { + TradeOfferType.Luxury_Resource -> { if (civInfo.getDiplomacyManager(tradePartner)!!.hasFlag(DiplomacyFlags.ResourceTradesCutShort)) return 0 // We don't trust you for resources @@ -132,7 +132,7 @@ class TradeEvaluation { } else 0 } - TradeType.Strategic_Resource -> { + TradeOfferType.Strategic_Resource -> { if (civInfo.getDiplomacyManager(tradePartner)!!.hasFlag(DiplomacyFlags.ResourceTradesCutShort)) return 0 // We don't trust you for resources @@ -151,14 +151,14 @@ class TradeEvaluation { return 50 * amountToBuyInOffer } - TradeType.Technology -> // Currently unused + TradeOfferType.Technology -> // Currently unused return (sqrt(civInfo.gameInfo.ruleset.technologies[offer.name]!!.cost.toDouble()) * civInfo.gameInfo.speed.scienceCostModifier).toInt() * 20 - TradeType.Introduction -> return introductionValue(civInfo.gameInfo.ruleset) - TradeType.WarDeclaration -> { + TradeOfferType.Introduction -> return introductionValue(civInfo.gameInfo.ruleset) + TradeOfferType.WarDeclaration -> { val civToDeclareWarOn = civInfo.gameInfo.getCivilization(offer.name) - if (trade.theirOffers.any { it.type == TradeType.WarDeclaration && it.name == offer.name } - && trade.ourOffers.any {it.type == TradeType.WarDeclaration && it.name == offer.name}) { + if (trade.theirOffers.any { it.type == TradeOfferType.WarDeclaration && it.name == offer.name } + && trade.ourOffers.any {it.type == TradeOfferType.WarDeclaration && it.name == offer.name}) { // Team war is handled in the selling method return 0 } else if (civInfo.isAtWarWith(civToDeclareWarOn)) { @@ -169,7 +169,7 @@ class TradeEvaluation { return 0 } } - TradeType.City -> { + TradeOfferType.City -> { val city = tradePartner.cities.firstOrNull { it.id == offer.name } ?: throw Exception("Got an offer for city id "+offer.name+" which does't seem to exist for this civ!") val stats = city.cityStats.currentCityStats @@ -179,7 +179,7 @@ class TradeEvaluation { val sumOfStats = stats.culture + stats.gold + stats.science + stats.production + stats.happiness + stats.food + surrounded return sumOfStats.toInt() * 100 } - TradeType.Agreement -> { + TradeOfferType.Agreement -> { if (offer.name == Constants.openBorders) return 100 throw Exception("Invalid agreement type!") } @@ -213,16 +213,16 @@ class TradeEvaluation { fun evaluateSellCostWithInflation(offer: TradeOffer, civInfo: Civilization, tradePartner: Civilization, trade: Trade): Int { - if (offer.type != TradeType.Gold && offer.type != TradeType.Gold_Per_Turn) + if (offer.type != TradeOfferType.Gold && offer.type != TradeOfferType.Gold_Per_Turn) return (evaluateSellCost(offer, civInfo, tradePartner, trade) / getGoldInflation(civInfo)).toInt() return evaluateSellCost(offer, civInfo, tradePartner, trade) } private fun evaluateSellCost(offer: TradeOffer, civInfo: Civilization, tradePartner: Civilization, trade: Trade): Int { when (offer.type) { - TradeType.Gold -> return offer.amount - TradeType.Gold_Per_Turn -> return offer.amount * offer.duration - TradeType.Treaty -> { + TradeOfferType.Gold -> return offer.amount + TradeOfferType.Gold_Per_Turn -> return offer.amount * offer.duration + TradeOfferType.Treaty -> { return when (offer.name) { // Since it will be evaluated twice, once when they evaluate our offer and once when they evaluate theirs Constants.peaceTreaty -> evaluatePeaceCostForThem(civInfo, tradePartner) @@ -233,7 +233,7 @@ class TradeEvaluation { //Todo:AddDefensiveTreatyHere } } - TradeType.Luxury_Resource -> { + TradeOfferType.Luxury_Resource -> { return when { civInfo.getResourceAmount(offer.name) > 1 -> 250 // fair price civInfo.hasUnique(UniqueType.RetainHappinessFromLuxury) -> // If we retain 50% happiness, value at 375 @@ -242,7 +242,7 @@ class TradeEvaluation { else -> 500 // you want to take away our last lux of this type?! } } - TradeType.Strategic_Resource -> { + TradeOfferType.Strategic_Resource -> { if (civInfo.gameInfo.spaceResources.contains(offer.name) && (civInfo.hasUnique(UniqueType.EnablesConstructionOfSpaceshipParts) || tradePartner.hasUnique(UniqueType.EnablesConstructionOfSpaceshipParts)) @@ -273,12 +273,12 @@ class TradeEvaluation { } return totalCost } - TradeType.Technology -> return sqrt(civInfo.gameInfo.ruleset.technologies[offer.name]!!.cost.toDouble()).toInt() * 20 - TradeType.Introduction -> return introductionValue(civInfo.gameInfo.ruleset) - TradeType.WarDeclaration -> { + TradeOfferType.Technology -> return sqrt(civInfo.gameInfo.ruleset.technologies[offer.name]!!.cost.toDouble()).toInt() * 20 + TradeOfferType.Introduction -> return introductionValue(civInfo.gameInfo.ruleset) + TradeOfferType.WarDeclaration -> { val civToDeclareWarOn = civInfo.gameInfo.getCivilization(offer.name) - if (trade.theirOffers.any { it.type == TradeType.WarDeclaration && it.name == offer.name } - && trade.ourOffers.any {it.type == TradeType.WarDeclaration && it.name == offer.name}) { + if (trade.theirOffers.any { it.type == TradeOfferType.WarDeclaration && it.name == offer.name } + && trade.ourOffers.any {it.type == TradeOfferType.WarDeclaration && it.name == offer.name}) { // Only accept if the war will benefit us, or if they pay us enough // We shouldn't want to pay them for us to declare war (no negative values) return (-20 * DeclareWarPlanEvaluator.evaluateTeamWarPlan(civInfo, civToDeclareWarOn, tradePartner, null)).toInt().coerceAtLeast(0) @@ -291,7 +291,7 @@ class TradeEvaluation { } } - TradeType.City -> { + TradeOfferType.City -> { val city = civInfo.cities.firstOrNull { it.id == offer.name } ?: throw Exception("Got an offer to sell city id " + offer.name + " which does't seem to exist for this civ!") @@ -301,7 +301,7 @@ class TradeEvaluation { stats.culture + stats.gold + stats.science + stats.production + stats.happiness + stats.food + distanceBonus return (sumOfStats.toInt() * 100).coerceAtLeast(1000) } - TradeType.Agreement -> { + TradeOfferType.Agreement -> { if (offer.name == Constants.openBorders) { return when (civInfo.getDiplomacyManager(tradePartner)!!.relationshipIgnoreAfraid()) { RelationshipLevel.Unforgivable -> 10000 diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 3ae30e4fa2..f76157b3d7 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -21,37 +21,37 @@ 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, TradeType.Treaty)) + offers.add(TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty)) if (!otherCivilization.getDiplomacyManager(civInfo)!!.hasOpenBorders && !otherCivilization.isCityState() && civInfo.hasUnique(UniqueType.EnablesOpenBorders) && otherCivilization.hasUnique(UniqueType.EnablesOpenBorders)) { - offers.add(TradeOffer(Constants.openBorders, TradeType.Agreement)) + offers.add(TradeOffer(Constants.openBorders, TradeOfferType.Agreement)) } if (civInfo.diplomacyFunctions.canSignResearchAgreementNoCostWith(otherCivilization)) - offers.add(TradeOffer(Constants.researchAgreement, TradeType.Treaty, civInfo.diplomacyFunctions.getResearchAgreementCost(otherCivilization))) + offers.add(TradeOffer(Constants.researchAgreement, TradeOfferType.Treaty, civInfo.diplomacyFunctions.getResearchAgreementCost(otherCivilization))) if (civInfo.diplomacyFunctions.canSignDefensivePactWith(otherCivilization)) - offers.add(TradeOffer(Constants.defensivePact, TradeType.Treaty)) + offers.add(TradeOffer(Constants.defensivePact, TradeOfferType.Treaty)) for (entry in civInfo.getCivResourcesWithOriginsForTrade() .filterNot { it.resource.resourceType == ResourceType.Bonus } .filter { it.origin == Constants.tradable } ) { - val resourceTradeType = if (entry.resource.resourceType == ResourceType.Luxury) TradeType.Luxury_Resource - else TradeType.Strategic_Resource - offers.add(TradeOffer(entry.resource.name, resourceTradeType, entry.amount)) + 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("Gold", TradeType.Gold, civInfo.gold)) - offers.add(TradeOffer("Gold per turn", TradeType.Gold_Per_Turn, civInfo.stats.statsForNextTurn.gold.toInt())) + offers.add(TradeOffer("Gold", TradeOfferType.Gold, civInfo.gold)) + offers.add(TradeOffer("Gold per turn", TradeOfferType.Gold_Per_Turn, civInfo.stats.statsForNextTurn.gold.toInt())) if (!civInfo.isOneCityChallenger() && !otherCivilization.isOneCityChallenger() && !civInfo.isCityState() && !otherCivilization.isCityState()) { for (city in civInfo.cities.filterNot { it.isCapital() || it.isInResistance() }) - offers.add(TradeOffer(city.id, TradeType.City)) + offers.add(TradeOffer(city.id, TradeOfferType.City)) } val otherCivsWeKnow = civInfo.getKnownCivs() @@ -61,7 +61,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, TradeType.Introduction)) + offers.add(TradeOffer(thirdCiv.civName, TradeOfferType.Introduction)) } } @@ -72,7 +72,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, TradeType.WarDeclaration)) + offers.add(TradeOffer(thirdCiv.civName, TradeOfferType.WarDeclaration)) } } @@ -95,14 +95,14 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil // instant transfers fun transferTrade(from: Civilization, to: Civilization, offer: TradeOffer) { when (offer.type) { - TradeType.Gold -> { + TradeOfferType.Gold -> { to.addGold(offer.amount) from.addGold(-offer.amount) } - TradeType.Technology -> { + TradeOfferType.Technology -> { to.tech.addTechnology(offer.name) } - TradeType.City -> { + TradeOfferType.City -> { val city = from.cities.first { it.id == offer.name } city.moveToCiv(to) city.getCenterTile().getUnits().toList() @@ -124,7 +124,7 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil ) // can't liberate if it's our city to.popupAlerts.add(PopupAlert(AlertType.CityTraded, city.id)) } - TradeType.Treaty -> { + TradeOfferType.Treaty -> { // Note: Treaties are not transfered from both sides due to notifications and double signing if (offer.name == Constants.peaceTreaty) to.getDiplomacyManager(from)!!.makePeace() if (offer.name == Constants.researchAgreement) { @@ -137,11 +137,11 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil } if (offer.name == Constants.defensivePact) to.getDiplomacyManager(from)!!.signDefensivePact(offer.duration) } - TradeType.Introduction -> to.diplomacyFunctions.makeCivilizationsMeet(to.gameInfo.getCivilization(offer.name)) - TradeType.WarDeclaration -> { + TradeOfferType.Introduction -> to.diplomacyFunctions.makeCivilizationsMeet(to.gameInfo.getCivilization(offer.name)) + TradeOfferType.WarDeclaration -> { val nameOfCivToDeclareWarOn = offer.name - val warType = if (currentTrade.theirOffers.any { it.type == TradeType.WarDeclaration && it.name == nameOfCivToDeclareWarOn } - && currentTrade.ourOffers.any {it.type == TradeType.WarDeclaration && it.name == nameOfCivToDeclareWarOn}) + val warType = if (currentTrade.theirOffers.any { it.type == TradeOfferType.WarDeclaration && it.name == nameOfCivToDeclareWarOn } + && currentTrade.ourOffers.any {it.type == TradeOfferType.WarDeclaration && it.name == nameOfCivToDeclareWarOn}) WarType.TeamWar else WarType.JoinWar @@ -165,13 +165,13 @@ class TradeLogic(val ourCivilization: Civilization, val otherCivilization: Civil } // Transfer of cities needs to happen before peace treaty, to avoid our units teleporting out of areas that soon will be ours - for (offer in currentTrade.theirOffers.filterNot { it.type == TradeType.Treaty }) + for (offer in currentTrade.theirOffers.filterNot { it.type == TradeOfferType.Treaty }) transferTrade(otherCivilization, ourCivilization, offer) - for (offer in currentTrade.ourOffers.filterNot { it.type == TradeType.Treaty }) + for (offer in currentTrade.ourOffers.filterNot { it.type == TradeOfferType.Treaty }) transferTrade(ourCivilization, otherCivilization, offer) // Transfter of treaties should only be done from one side to avoid double signing and notifying - for (offer in currentTrade.theirOffers.filter { it.type == TradeType.Treaty }) + for (offer in currentTrade.theirOffers.filter { it.type == TradeOfferType.Treaty }) transferTrade(otherCivilization, ourCivilization, offer) ourCivilization.cache.updateCivResources() diff --git a/core/src/com/unciv/logic/trade/TradeOffer.kt b/core/src/com/unciv/logic/trade/TradeOffer.kt index 2e7535ebf9..2d1e478179 100644 --- a/core/src/com/unciv/logic/trade/TradeOffer.kt +++ b/core/src/com/unciv/logic/trade/TradeOffer.kt @@ -3,16 +3,16 @@ package com.unciv.logic.trade import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.IsPartOfGameInfoSerialization -import com.unciv.logic.trade.TradeType.TradeTypeNumberType +import com.unciv.logic.trade.TradeOfferType.TradeTypeNumberType import com.unciv.models.ruleset.Speed import com.unciv.models.translations.tr import com.unciv.ui.components.fonts.Fonts -data class TradeOffer(val name: String, val type: TradeType, var amount: Int = 1, var duration: Int) : IsPartOfGameInfoSerialization { +data class TradeOffer(val name: String, val type: TradeOfferType, var amount: Int = 1, var duration: Int) : IsPartOfGameInfoSerialization { constructor( name: String, - type: TradeType, + type: TradeOfferType, amount: Int = 1, speed: Speed = UncivGame.Current.gameInfo!!.speed ) : this(name, type, amount, duration = -1) { @@ -23,7 +23,7 @@ data class TradeOffer(val name: String, val type: TradeType, var amount: Int = 1 } } - constructor() : this("", TradeType.Gold, duration = -1) // so that the json deserializer can work + constructor() : this("", TradeOfferType.Gold, duration = -1) // so that the json deserializer can work @Suppress("CovariantEquals", "WrongEqualsTypeParameter") // This is an overload, not an override of the built-in equals(Any?) fun equals(offer: TradeOffer): Boolean { @@ -36,9 +36,9 @@ data class TradeOffer(val name: String, val type: TradeType, var amount: Int = 1 fun getOfferText(untradable: Int = 0): String { var offerText = when(type) { - TradeType.WarDeclaration -> "Declare war on [$name]" - TradeType.Introduction -> "Introduction to [$name]" - TradeType.City -> { + TradeOfferType.WarDeclaration -> "Declare war on [$name]" + TradeOfferType.Introduction -> "Introduction to [$name]" + TradeOfferType.City -> { val city = UncivGame.Current.gameInfo!!.getCities().firstOrNull { it.id == name } city?.run { "{$name} (${population.population})" } ?: "Non-existent city" diff --git a/core/src/com/unciv/logic/trade/TradeType.kt b/core/src/com/unciv/logic/trade/TradeOfferType.kt similarity index 92% rename from core/src/com/unciv/logic/trade/TradeType.kt rename to core/src/com/unciv/logic/trade/TradeOfferType.kt index 8edde1b09b..188a992e50 100644 --- a/core/src/com/unciv/logic/trade/TradeType.kt +++ b/core/src/com/unciv/logic/trade/TradeOfferType.kt @@ -5,7 +5,7 @@ package com.unciv.logic.trade * @param isImmediate Trade is a one-time effect without duration */ @Suppress("EnumEntryName") // We do want the underscores in our names -enum class TradeType(val numberType: TradeTypeNumberType, val isImmediate: Boolean) { +enum class TradeOfferType(val numberType: TradeTypeNumberType, val isImmediate: Boolean) { Gold (TradeTypeNumberType.Gold, true), Gold_Per_Turn (TradeTypeNumberType.Gold, false), /** Treaties are shared by both sides - like peace treaty and defensive pact */ diff --git a/core/src/com/unciv/ui/screens/diplomacyscreen/CityStateDiplomacyTable.kt b/core/src/com/unciv/ui/screens/diplomacyscreen/CityStateDiplomacyTable.kt index 6c5823226f..369395dac6 100644 --- a/core/src/com/unciv/ui/screens/diplomacyscreen/CityStateDiplomacyTable.kt +++ b/core/src/com/unciv/ui/screens/diplomacyscreen/CityStateDiplomacyTable.kt @@ -17,7 +17,7 @@ import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.civilization.managers.AssignedQuest import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.Quest import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.unique.UniqueType @@ -251,13 +251,13 @@ class CityStateDiplomacyTable(private val diplomacyScreen: DiplomacyScreen) { tradeLogic.currentTrade.ourOffers.add( TradeOffer( Constants.peaceTreaty, - TradeType.Treaty + TradeOfferType.Treaty ) ) tradeLogic.currentTrade.theirOffers.add( TradeOffer( Constants.peaceTreaty, - TradeType.Treaty + TradeOfferType.Treaty ) ) tradeLogic.acceptTrade() diff --git a/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt b/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt index f7644be1fc..7a3fb7c314 100644 --- a/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt +++ b/core/src/com/unciv/ui/screens/diplomacyscreen/MajorCivDiplomacyTable.kt @@ -13,7 +13,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomacyManager import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.trade.TradeOffer -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.addSeparator @@ -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, TradeType.Treaty) + val peaceTreaty = TradeOffer(Constants.peaceTreaty, TradeOfferType.Treaty) tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty) tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty) tradeTable.offerColumnsTable.update() diff --git a/core/src/com/unciv/ui/screens/diplomacyscreen/OfferColumnsTable.kt b/core/src/com/unciv/ui/screens/diplomacyscreen/OfferColumnsTable.kt index 45f80d539b..9e1dcf3709 100644 --- a/core/src/com/unciv/ui/screens/diplomacyscreen/OfferColumnsTable.kt +++ b/core/src/com/unciv/ui/screens/diplomacyscreen/OfferColumnsTable.kt @@ -6,7 +6,7 @@ import com.unciv.logic.civilization.Civilization import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeOffersList -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.addSeparator import com.unciv.ui.components.extensions.surroundWithCircle @@ -25,7 +25,7 @@ class OfferColumnsTable( fun addOffer(offer: TradeOffer, offerList: TradeOffersList, correspondingOfferList: TradeOffersList) { offerList.add(offer.copy()) - if (offer.type == TradeType.Treaty) correspondingOfferList.add(offer.copy()) + if (offer.type == TradeOfferType.Treaty) correspondingOfferList.add(offer.copy()) onChange() } @@ -37,8 +37,8 @@ class OfferColumnsTable( civ: Civilization ) { when (offer.type) { - TradeType.Gold -> openGoldSelectionPopup(offer, list, civ.gold) - TradeType.Gold_Per_Turn -> openGoldSelectionPopup(offer, list, civ.stats.statsForNextTurn.gold.toInt()) + TradeOfferType.Gold -> openGoldSelectionPopup(offer, list, civ.gold) + TradeOfferType.Gold_Per_Turn -> openGoldSelectionPopup(offer, list, civ.stats.statsForNextTurn.gold.toInt()) else -> addOffer(if (invert) offer.copy(amount = -offer.amount) else offer, list, counterList) } } @@ -122,7 +122,7 @@ class OfferColumnsTable( icon = ImageGetter.getStatIcon("Gold").surroundWithCircle(80f), defaultValue = offer.amount.toString(), amountButtons = - if (offer.type == TradeType.Gold) listOf(50, 500) + if (offer.type == TradeOfferType.Gold) listOf(50, 500) else listOf(5, 15), bounds = IntRange(0, maxGold), actionOnOk = { userInput -> diff --git a/core/src/com/unciv/ui/screens/diplomacyscreen/OffersListScroll.kt b/core/src/com/unciv/ui/screens/diplomacyscreen/OffersListScroll.kt index 438ad5a65b..1c48173040 100644 --- a/core/src/com/unciv/ui/screens/diplomacyscreen/OffersListScroll.kt +++ b/core/src/com/unciv/ui/screens/diplomacyscreen/OffersListScroll.kt @@ -8,18 +8,18 @@ import com.unciv.UncivGame import com.unciv.logic.civilization.Civilization import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeOffersList -import com.unciv.logic.trade.TradeType -import com.unciv.logic.trade.TradeType.Agreement -import com.unciv.logic.trade.TradeType.City -import com.unciv.logic.trade.TradeType.Gold -import com.unciv.logic.trade.TradeType.Gold_Per_Turn -import com.unciv.logic.trade.TradeType.Introduction -import com.unciv.logic.trade.TradeType.Luxury_Resource -import com.unciv.logic.trade.TradeType.Strategic_Resource -import com.unciv.logic.trade.TradeType.Technology -import com.unciv.logic.trade.TradeType.Treaty -import com.unciv.logic.trade.TradeType.WarDeclaration -import com.unciv.logic.trade.TradeType.values +import com.unciv.logic.trade.TradeOfferType +import com.unciv.logic.trade.TradeOfferType.Agreement +import com.unciv.logic.trade.TradeOfferType.City +import com.unciv.logic.trade.TradeOfferType.Gold +import com.unciv.logic.trade.TradeOfferType.Gold_Per_Turn +import com.unciv.logic.trade.TradeOfferType.Introduction +import com.unciv.logic.trade.TradeOfferType.Luxury_Resource +import com.unciv.logic.trade.TradeOfferType.Strategic_Resource +import com.unciv.logic.trade.TradeOfferType.Technology +import com.unciv.logic.trade.TradeOfferType.Treaty +import com.unciv.logic.trade.TradeOfferType.WarDeclaration +import com.unciv.logic.trade.TradeOfferType.values import com.unciv.models.ruleset.tile.ResourceSupplyList import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.disable @@ -43,7 +43,7 @@ class OffersListScroll( val table = Table(BaseScreen.skin).apply { defaults().pad(5f) } - private val expanderTabs = HashMap() + private val expanderTabs = HashMap() init { fadeScrollBars=false diff --git a/core/src/com/unciv/ui/screens/diplomacyscreen/TradeTable.kt b/core/src/com/unciv/ui/screens/diplomacyscreen/TradeTable.kt index 47c35f0928..ee9fd07fd1 100644 --- a/core/src/com/unciv/ui/screens/diplomacyscreen/TradeTable.kt +++ b/core/src/com/unciv/ui/screens/diplomacyscreen/TradeTable.kt @@ -5,7 +5,7 @@ import com.unciv.Constants import com.unciv.logic.civilization.Civilization import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeRequest -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.isEnabled import com.unciv.ui.components.extensions.toTextButton @@ -58,18 +58,18 @@ class TradeTable( // There must be enough gold to add to the offer to satisfy this, otherwise the research agreement button would be disabled if (tradeLogic.currentTrade.ourOffers.any { it.name == Constants.researchAgreement}) { val researchCost = civ.diplomacyFunctions.getResearchAgreementCost(otherCivilization) - val currentPlayerOfferedGold = tradeLogic.currentTrade.ourOffers.firstOrNull { it.type == TradeType.Gold }?.amount ?: 0 - val otherCivOfferedGold = tradeLogic.currentTrade.theirOffers.firstOrNull { it.type == TradeType.Gold }?.amount ?: 0 + val currentPlayerOfferedGold = tradeLogic.currentTrade.ourOffers.firstOrNull { it.type == TradeOfferType.Gold }?.amount ?: 0 + val otherCivOfferedGold = tradeLogic.currentTrade.theirOffers.firstOrNull { it.type == TradeOfferType.Gold }?.amount ?: 0 val newCurrentPlayerGold = civ.gold + otherCivOfferedGold - researchCost val newOtherCivGold = otherCivilization.gold + currentPlayerOfferedGold - researchCost // Check if we require more gold from them if (newCurrentPlayerGold < 0) { - offerColumnsTable.addOffer( tradeLogic.theirAvailableOffers.first { it.type == TradeType.Gold } + offerColumnsTable.addOffer( tradeLogic.theirAvailableOffers.first { it.type == TradeOfferType.Gold } .copy(amount = -newCurrentPlayerGold), tradeLogic.currentTrade.theirOffers, tradeLogic.currentTrade.ourOffers) } // Check if they require more gold from us if (newOtherCivGold < 0) { - offerColumnsTable.addOffer( tradeLogic.ourAvailableOffers.first { it.type == TradeType.Gold } + offerColumnsTable.addOffer( tradeLogic.ourAvailableOffers.first { it.type == TradeOfferType.Gold } .copy(amount = -newOtherCivGold), tradeLogic.currentTrade.ourOffers, tradeLogic.currentTrade.theirOffers) } } diff --git a/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTab.kt b/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTab.kt index f12ddb5752..0eaf6289eb 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTab.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/ResourcesOverviewTab.kt @@ -8,7 +8,7 @@ import com.unciv.UncivGame import com.unciv.logic.city.City import com.unciv.logic.civilization.Civilization import com.unciv.logic.map.tile.Tile -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.ruleset.tile.ResourceSupplyList import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.TileResource @@ -271,7 +271,7 @@ class ResourcesOverviewTab( for (otherCiv in viewingPlayer.getKnownCivs()) { // Show resources received through trade for (trade in otherCiv.tradeRequests.filter { it.requestingCiv == viewingPlayer.civName }) - for (offer in trade.trade.theirOffers.filter { it.type == TradeType.Strategic_Resource || it.type == TradeType.Luxury_Resource }) + for (offer in trade.trade.theirOffers.filter { it.type == TradeOfferType.Strategic_Resource || it.type == TradeOfferType.Luxury_Resource }) newResourceSupplyList.add(gameInfo.ruleset.tileResources[offer.name]!!, ExtraInfoOrigin.TradeOffer.name, offer.amount) // Show resources your city-state allies have left unimproved diff --git a/core/src/com/unciv/ui/screens/worldscreen/TradePopup.kt b/core/src/com/unciv/ui/screens/worldscreen/TradePopup.kt index 0ec5324dd2..3ba7174894 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/TradePopup.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/TradePopup.kt @@ -7,7 +7,7 @@ import com.unciv.logic.civilization.NotificationCategory import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.pad import com.unciv.ui.components.extensions.toLabel @@ -57,7 +57,7 @@ class TradePopup(worldScreen: WorldScreen) : Popup(worldScreen) { fun getOfferText(offer:TradeOffer): String { var tradeText = offer.getOfferText() - if (offer.type == TradeType.Luxury_Resource || offer.type == TradeType.Strategic_Resource) + if (offer.type == TradeOfferType.Luxury_Resource || offer.type == TradeOfferType.Strategic_Resource) tradeText += "\n" + "Owned by you: [${ourResources[offer.name]}]".tr() return tradeText } diff --git a/tests/src/com/unciv/logic/civilization/diplomacy/GoldGiftingTests.kt b/tests/src/com/unciv/logic/civilization/diplomacy/GoldGiftingTests.kt index 94ccba7e7b..8f97693791 100644 --- a/tests/src/com/unciv/logic/civilization/diplomacy/GoldGiftingTests.kt +++ b/tests/src/com/unciv/logic/civilization/diplomacy/GoldGiftingTests.kt @@ -4,7 +4,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomacyTurnManager.nextTurn import com.unciv.logic.trade.TradeEvaluation import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer -import com.unciv.logic.trade.TradeType +import com.unciv.logic.trade.TradeOfferType import com.unciv.testing.GdxTestRunner import com.unciv.testing.TestGame import org.junit.Assert.assertEquals @@ -100,7 +100,7 @@ class GoldGiftingTests { a.addGold(1000) assertEquals(0, bDiplomacy.getGoldGifts()) val tradeOffer = TradeLogic(a,b) - tradeOffer.currentTrade.ourOffers.add(tradeOffer.ourAvailableOffers.first { it.type == TradeType.Gold }) + tradeOffer.currentTrade.ourOffers.add(tradeOffer.ourAvailableOffers.first { it.type == TradeOfferType.Gold }) assertTrue(TradeEvaluation().getTradeAcceptability(tradeOffer.currentTrade.reverse(), b,a,false) > 0) tradeOffer.acceptTrade() assertEquals(0, aDiplomacy.getGoldGifts()) @@ -113,11 +113,11 @@ class GoldGiftingTests { // Therefore we only test for 90% a.addGold(1000) val tradeOffer = TradeLogic(a,b) - tradeOffer.currentTrade.ourOffers.add(tradeOffer.ourAvailableOffers.first { it.type == TradeType.Gold }) + tradeOffer.currentTrade.ourOffers.add(tradeOffer.ourAvailableOffers.first { it.type == TradeOfferType.Gold }) tradeOffer.acceptTrade() bDiplomacy.nextTurn() val tradeOffer2 = TradeLogic(a,b) - tradeOffer2.currentTrade.theirOffers.add(TradeOffer("Gold", TradeType.Gold, 900)) + tradeOffer2.currentTrade.theirOffers.add(TradeOffer("Gold", TradeOfferType.Gold, 900)) assertTrue(TradeEvaluation().getTradeAcceptability(tradeOffer.currentTrade.reverse(), b,a,false) > 0) tradeOffer2.acceptTrade() assertTrue(bDiplomacy.getGoldGifts() >= 0) // Must not be negative @@ -127,7 +127,7 @@ class GoldGiftingTests { fun `Gold gifted impact trade acceptability`() { a.addGold(1000) val tradeOffer = TradeLogic(a,b) - tradeOffer.currentTrade.ourOffers.add(tradeOffer.ourAvailableOffers.first { it.type == TradeType.Gold }) + tradeOffer.currentTrade.ourOffers.add(tradeOffer.ourAvailableOffers.first { it.type == TradeOfferType.Gold }) assertTrue(TradeEvaluation().getTradeAcceptability(tradeOffer.currentTrade, b,a,true) < 0) tradeOffer.acceptTrade() val tradeOffer2 = TradeLogic(a,b)