diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index b24eda44..93053cab 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -210,14 +210,21 @@ class DiplomacyManager() { fun resourcesFromTrade(): ResourceSupplyList { val counter = ResourceSupplyList() + val resourcesMap = civInfo.gameInfo.ruleSet.tileResources for(trade in trades){ for(offer in trade.ourOffers) if(offer.type== TradeType.Strategic_Resource || offer.type== TradeType.Luxury_Resource) - counter.add(civInfo.gameInfo.ruleSet.tileResources[offer.name]!!,-offer.amount,"Trade") + counter.add(resourcesMap[offer.name]!!,-offer.amount,"Trade") for(offer in trade.theirOffers) if(offer.type== TradeType.Strategic_Resource || offer.type== TradeType.Luxury_Resource) - counter.add(civInfo.gameInfo.ruleSet.tileResources[offer.name]!!,offer.amount,"Trade") + counter.add(resourcesMap[offer.name]!!,offer.amount,"Trade") } + + for(trade in otherCiv().tradeRequests.filter { it.requestingCiv==civInfo.civName }){ + for(offer in trade.trade.theirOffers) + counter.add(resourcesMap[offer.name]!!, -offer.amount, "Trade request") + } + return counter } @@ -325,18 +332,18 @@ class DiplomacyManager() { for (trade in trades.toList()) { for (offer in trade.ourOffers.union(trade.theirOffers).filter { it.duration > 0 }) { offer.duration-- - if (offer.duration == 0) { - if(offer in trade.theirOffers) - civInfo.addNotification("[" + offer.name + "] from [$otherCivName] has ended", null, Color.GOLD) - else civInfo.addNotification("[" + offer.name + "] to [$otherCivName] has ended", null, Color.GOLD) - - civInfo.updateStatsForNextTurn() // if they were bringing us gold per turn - civInfo.updateDetailedCivResources() // if they were giving us resources - } } if (trade.ourOffers.all { it.duration <= 0 } && trade.theirOffers.all { it.duration <= 0 }) { trades.remove(trade) + for (offer in trade.ourOffers.union(trade.theirOffers).filter { it.duration == 0 }) { // this was a timed trade + if (offer in trade.theirOffers) + civInfo.addNotification("[${offer.name}] from [$otherCivName] has ended", null, Color.GOLD) + else civInfo.addNotification("[${offer.name}] to [$otherCivName] has ended", null, Color.GOLD) + + civInfo.updateStatsForNextTurn() // if they were bringing us gold per turn + civInfo.updateDetailedCivResources() // if they were giving us resources + } } } } diff --git a/core/src/com/unciv/logic/trade/TradeOffer.kt b/core/src/com/unciv/logic/trade/TradeOffer.kt index 60e35f06..b68c7a7a 100644 --- a/core/src/com/unciv/logic/trade/TradeOffer.kt +++ b/core/src/com/unciv/logic/trade/TradeOffer.kt @@ -5,12 +5,12 @@ import com.unciv.UncivGame import com.unciv.models.metadata.GameSpeed import com.unciv.models.translations.tr -data class TradeOffer(var name:String, var type: TradeType, var amount:Int=1, var duration:Int=0) { +data class TradeOffer(var name:String, var type: TradeType, var amount:Int=1, var duration:Int=-1) { init { // Duration needs to be part of the variables defined at the top, so that it will be copied over with copy() duration = when(type){ - TradeType.Gold, TradeType.Technology, TradeType.Introduction, TradeType.WarDeclaration, TradeType.City -> 0 /** 0 for offers that are immediate (e.g. gold transfer) */ + TradeType.Gold, TradeType.Technology, TradeType.Introduction, TradeType.WarDeclaration, TradeType.City -> -1 /** -1 for offers that are immediate (e.g. gold transfer) */ else -> when(UncivGame.Current.gameInfo.gameParameters.gameSpeed){ GameSpeed.Quick -> if (name==Constants.peaceTreaty) 10 else 25 else -> ((if (name==Constants.peaceTreaty) 10 else 30) * UncivGame.Current.gameInfo.gameParameters.gameSpeed.modifier).toInt() diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index 68bcf671..af5eec43 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -18,7 +18,6 @@ import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeType -import com.unciv.models.metadata.GameSpeed import com.unciv.models.translations.tr import com.unciv.ui.utils.* import kotlin.math.roundToInt @@ -81,7 +80,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { fun setTrade(civ: CivilizationInfo): TradeTable { rightSideTable.clear() - val tradeTable =TradeTable(civ, stage) { updateLeftSideTable() } + val tradeTable =TradeTable(civ, stage) rightSideTable.add(tradeTable) return tradeTable } diff --git a/core/src/com/unciv/ui/trade/TradeTable.kt b/core/src/com/unciv/ui/trade/TradeTable.kt index e436edbf..2c7677d0 100644 --- a/core/src/com/unciv/ui/trade/TradeTable.kt +++ b/core/src/com/unciv/ui/trade/TradeTable.kt @@ -12,7 +12,7 @@ import com.unciv.ui.utils.disable import com.unciv.ui.utils.enable import com.unciv.ui.utils.onClick -class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeComplete: () -> Unit): Table(CameraStageBaseScreen.skin){ +class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage): Table(CameraStageBaseScreen.skin){ val currentPlayerCiv = otherCivilization.gameInfo.getCurrentPlayerCivilization() var tradeLogic = TradeLogic(currentPlayerCiv,otherCivilization) var offerColumnsTable = OfferColumnsTable(tradeLogic, stage) { onChange() } @@ -23,6 +23,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeC fun retractOffer(){ otherCivilization.tradeRequests.removeAll { it.requestingCiv==currentPlayerCiv.civName } + currentPlayerCiv.updateDetailedCivResources() offerButton.setText("Offer trade".tr()) } @@ -48,6 +49,7 @@ class TradeTable(val otherCivilization: CivilizationInfo, stage: Stage, onTradeC } otherCivilization.tradeRequests.add(TradeRequest(currentPlayerCiv.civName,tradeLogic.currentTrade.reverse())) + currentPlayerCiv.updateDetailedCivResources() offerButton.setText("Retract offer".tr()) }