Skip to content

Commit

Permalink
3.6.14-patch1
Browse files Browse the repository at this point in the history
Fixed crash when non-resource trades are made
  • Loading branch information
yairm210 committed Mar 31, 2020
1 parent 93e4888 commit 4e365ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ allprojects {
version = '1.0.1'
ext {
appName = "Unciv"
appCodeNumber = 402
appVersion = "3.6.14"
appCodeNumber = 403
appVersion = "3.6.14-patch1"

gdxVersion = '1.9.10'
roboVMVersion = '2.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.unciv.Constants
import com.unciv.UniqueAbility
import com.unciv.logic.civilization.*
import com.unciv.logic.trade.Trade
import com.unciv.logic.trade.TradeOffer
import com.unciv.logic.trade.TradeType
import com.unciv.models.ruleset.tile.ResourceSupplyList
import kotlin.math.ceil
Expand Down Expand Up @@ -211,17 +212,16 @@ 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(resourcesMap[offer.name]!!,-offer.amount,"Trade")
for(offer in trade.theirOffers)
if(offer.type== TradeType.Strategic_Resource || offer.type== TradeType.Luxury_Resource)
counter.add(resourcesMap[offer.name]!!,offer.amount,"Trade")
val isResourceFilter: (TradeOffer) -> Boolean = { it.type == TradeType.Strategic_Resource || it.type == TradeType.Luxury_Resource }
for (trade in trades) {
for (offer in trade.ourOffers.filter(isResourceFilter))
counter.add(resourcesMap[offer.name]!!, -offer.amount, "Trade")
for (offer in trade.theirOffers.filter(isResourceFilter))
counter.add(resourcesMap[offer.name]!!, offer.amount, "Trade")
}

for(trade in otherCiv().tradeRequests.filter { it.requestingCiv==civInfo.civName }){
for(offer in trade.trade.theirOffers)
for (trade in otherCiv().tradeRequests.filter { it.requestingCiv == civInfo.civName }) {
for (offer in trade.trade.theirOffers.filter(isResourceFilter))
counter.add(resourcesMap[offer.name]!!, -offer.amount, "Trade request")
}

Expand Down

2 comments on commit 4e365ac

@JackRainy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! I did not know that it's possible to do such tricks in Kotlin.
Good to know, thank you :)

@yairm210
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the regular .filter{}, .map{} functions work this way - you're basically passing them the filter/map function as a parameter
Kotlin is magical in that its syntax allows you to "hide" this, since for Kotlin doSomething( { function } ) is the same as doSomething{ function }

Please sign in to comment.