Can't trade resources from other trades or city-states (#5252)

* can't trade resources from city-states

* display untradeable sources in trade screen

* Update template.properties

template string

* Update Swedish.properties

* Spelling, better buttons
This commit is contained in:
SimonCeder 2021-09-22 19:21:41 +02:00 committed by GitHub
parent 98f14523ed
commit 0bb565fdc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 9 deletions

View File

@ -246,6 +246,8 @@ Our items = Våra artiklar
Our trade offer = Vårat handelserbjudande Our trade offer = Vårat handelserbjudande
[otherCiv]'s trade offer = [otherCiv]s handelserbjudande [otherCiv]'s trade offer = [otherCiv]s handelserbjudande
[otherCiv]'s items = [otherCiv]s artiklar [otherCiv]'s items = [otherCiv]s artiklar
+[amount] untradable copy = +[amount] ohandelsbar kopia
+[amount] untradable copies = +[amount] ohandelsbara kopior
Pleasure doing business with you! = Angenämt att göra affärer med er! Pleasure doing business with you! = Angenämt att göra affärer med er!
I think not. = Jag skulle inte tro det. I think not. = Jag skulle inte tro det.
That is acceptable. = Det är godtagbart. That is acceptable. = Det är godtagbart.

View File

@ -247,6 +247,8 @@ Our items =
Our trade offer = Our trade offer =
[otherCiv]'s trade offer = [otherCiv]'s trade offer =
[otherCiv]'s items = [otherCiv]'s items =
+[amount] untradable copy =
+[amount] untradable copies =
Pleasure doing business with you! = Pleasure doing business with you! =
I think not. = I think not. =
That is acceptable. = That is acceptable. =

View File

@ -272,8 +272,24 @@ class CivilizationInfo {
fun getCivResources(): ResourceSupplyList { fun getCivResources(): ResourceSupplyList {
val newResourceSupplyList = ResourceSupplyList() val newResourceSupplyList = ResourceSupplyList()
for (resourceSupply in detailedCivResources) for (resourceSupply in detailedCivResources) {
newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, "All") newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, "All")
}
return newResourceSupplyList
}
// Preserves some origins for resources so we can separate them for trades
fun getCivResourcesWithOriginsForTrade(): ResourceSupplyList {
val newResourceSupplyList = ResourceSupplyList()
for (resourceSupply in detailedCivResources) {
// If we got it from another trade or from a CS, preserve the origin
if ((resourceSupply.origin == "City-States" || resourceSupply.origin == "Trade") && resourceSupply.amount > 0) {
newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, resourceSupply.origin)
newResourceSupplyList.add(resourceSupply.resource, 0, "Tradable") // Still add an empty "tradable" entry so it shows up in the list
}
else
newResourceSupplyList.add(resourceSupply.resource, resourceSupply.amount, "Tradable")
}
return newResourceSupplyList return newResourceSupplyList
} }

View File

@ -26,8 +26,9 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
offers.add(TradeOffer(Constants.openBorders, TradeType.Agreement)) offers.add(TradeOffer(Constants.openBorders, TradeType.Agreement))
} }
for (entry in civInfo.getCivResources() for (entry in civInfo.getCivResourcesWithOriginsForTrade()
.filterNot { it.resource.resourceType == ResourceType.Bonus }) { .filterNot { it.resource.resourceType == ResourceType.Bonus }
.filter { it.origin == "Tradable" } ) {
val resourceTradeType = if (entry.resource.resourceType == ResourceType.Luxury) TradeType.Luxury_Resource val resourceTradeType = if (entry.resource.resourceType == ResourceType.Luxury) TradeType.Luxury_Resource
else TradeType.Strategic_Resource else TradeType.Strategic_Resource
offers.add(TradeOffer(entry.resource.name, resourceTradeType, entry.amount)) offers.add(TradeOffer(entry.resource.name, resourceTradeType, entry.amount))

View File

@ -6,6 +6,7 @@ import com.unciv.models.metadata.GameSpeed
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.Fonts import com.unciv.ui.utils.Fonts
import com.unciv.logic.trade.TradeType.TradeTypeNumberType import com.unciv.logic.trade.TradeType.TradeTypeNumberType
import com.unciv.models.ruleset.tile.ResourceSupply
data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, var duration: Int = -1) { data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, var duration: Int = -1) {
@ -35,7 +36,7 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v
&& offer.amount == amount && offer.amount == amount
} }
fun getOfferText(): String { fun getOfferText(untradable: Int = 0): String {
var offerText = when(type){ var offerText = when(type){
TradeType.WarDeclaration -> "Declare war on [$name]" TradeType.WarDeclaration -> "Declare war on [$name]"
TradeType.Introduction -> "Introduction to [$name]" TradeType.Introduction -> "Introduction to [$name]"
@ -48,6 +49,12 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v
if (duration > 0) offerText += "\n" + duration + Fonts.turn if (duration > 0) offerText += "\n" + duration + Fonts.turn
if (untradable == 1) {
offerText += "\n" + "+[${untradable}] untradable copy".tr()
} else if (untradable > 1) {
offerText += "\n" + "+[${untradable}] untradable copies".tr()
}
return offerText return offerText
} }
} }

View File

@ -71,10 +71,12 @@ class OfferColumnsTable(private val tradeLogic: TradeLogic, val screen: Diplomac
fun update() { fun update() {
val ourFilteredOffers = tradeLogic.ourAvailableOffers.without(tradeLogic.currentTrade.ourOffers) val ourFilteredOffers = tradeLogic.ourAvailableOffers.without(tradeLogic.currentTrade.ourOffers)
val theirFilteredOffers = tradeLogic.theirAvailableOffers.without(tradeLogic.currentTrade.theirOffers) val theirFilteredOffers = tradeLogic.theirAvailableOffers.without(tradeLogic.currentTrade.theirOffers)
ourAvailableOffersTable.update(ourFilteredOffers, tradeLogic.theirAvailableOffers) val ourUntradables = tradeLogic.ourCivilization.getCivResourcesWithOriginsForTrade().filterNot { it.origin == "Tradable" }
val theirUntradables = tradeLogic.otherCivilization.getCivResourcesWithOriginsForTrade().filterNot { it.origin == "Tradable" }
ourAvailableOffersTable.update(ourFilteredOffers, tradeLogic.theirAvailableOffers, ourUntradables)
ourOffersTable.update(tradeLogic.currentTrade.ourOffers, tradeLogic.theirAvailableOffers) ourOffersTable.update(tradeLogic.currentTrade.ourOffers, tradeLogic.theirAvailableOffers)
theirOffersTable.update(tradeLogic.currentTrade.theirOffers, tradeLogic.ourAvailableOffers) theirOffersTable.update(tradeLogic.currentTrade.theirOffers, tradeLogic.ourAvailableOffers)
theirAvailableOffersTable.update(theirFilteredOffers, tradeLogic.ourAvailableOffers) theirAvailableOffersTable.update(theirFilteredOffers, tradeLogic.ourAvailableOffers, theirUntradables)
} }
private fun openGoldSelectionPopup(offer: TradeOffer, ourOffers: TradeOffersList, maxGold: Int) { private fun openGoldSelectionPopup(offer: TradeOffer, ourOffers: TradeOffersList, maxGold: Int) {

View File

@ -8,6 +8,7 @@ import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeOffersList import com.unciv.logic.trade.TradeOffersList
import com.unciv.logic.trade.TradeType import com.unciv.logic.trade.TradeType
import com.unciv.logic.trade.TradeType.* import com.unciv.logic.trade.TradeType.*
import com.unciv.models.ruleset.tile.ResourceSupply
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import kotlin.math.min import kotlin.math.min
@ -30,8 +31,9 @@ class OffersListScroll(
/** /**
* @param offersToDisplay The offers which should be displayed as buttons * @param offersToDisplay The offers which should be displayed as buttons
* @param otherOffers The list of other side's offers to compare with whether these offers are unique * @param otherOffers The list of other side's offers to compare with whether these offers are unique
* @param untradableOffers Things we got from sources that we can't trade on, displayed for completeness
*/ */
fun update(offersToDisplay:TradeOffersList, otherOffers: TradeOffersList) { fun update(offersToDisplay:TradeOffersList, otherOffers: TradeOffersList, untradableOffers: List<ResourceSupply> = emptyList()) {
table.clear() table.clear()
expanderTabs.clear() expanderTabs.clear()
@ -64,7 +66,7 @@ class OffersListScroll(
} }
for (offer in offersOfType) { for (offer in offersOfType) {
val tradeButton = offer.getOfferText().toTextButton() val tradeButton = offer.getOfferText(untradableOffers.filter { it.resource.name == offer.name }.sumOf { it.amount }).toTextButton()
val amountPerClick = val amountPerClick =
if (offer.type == Gold) 50 if (offer.type == Gold) 50
else 1 else 1
@ -86,7 +88,8 @@ class OffersListScroll(
if (expanderTabs.containsKey(offerType)) if (expanderTabs.containsKey(offerType))
expanderTabs[offerType]!!.innerTable.add(tradeButton).row() expanderTabs[offerType]!!.innerTable.add(tradeButton).row()
else table.add(tradeButton).row() else
table.add(tradeButton).row()
} }
} }
actor = table actor = table