mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-30 14:48:56 +07:00
Possibly fixed a crash accessing gameInfo before it is initialized (#6062)
* Possibly fixed a crash accessing gameInfo before it is initialized * Inlined an otherwise unused variable * Alternative version using an extra constructor instead of weird getters/setters
This commit is contained in:
@ -1367,7 +1367,7 @@ class MapRegions (val ruleset: Ruleset){
|
||||
// Third add some minor deposits to land tiles
|
||||
// Note: In G&K there is a bug where minor deposits are never placed on hills. We're not replicating that.
|
||||
val frequency = (baseMinorDepositFrequency * bonusMultiplier).toInt()
|
||||
val minorDepositsToAdd = (landList.count() / frequency) + 1
|
||||
val minorDepositsToAdd = (landList.count() / frequency) + 1 // I sometimes have division by zero errors on this line
|
||||
var minorDepositsAdded = 0
|
||||
for (tile in landList) {
|
||||
if (tile.resource != null || tileData[tile.position]!!.impacts.containsKey(ImpactType.Strategic))
|
||||
|
@ -8,7 +8,6 @@ import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.models.ruleset.ModOptionsConstants
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.ui.utils.toPercent
|
||||
import com.unciv.ui.victoryscreen.RankingType
|
||||
|
@ -28,8 +28,9 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
|
||||
}
|
||||
|
||||
for (entry in civInfo.getCivResourcesWithOriginsForTrade()
|
||||
.filterNot { it.resource.resourceType == ResourceType.Bonus }
|
||||
.filter { it.origin == "Tradable" } ) {
|
||||
.filterNot { it.resource.resourceType == ResourceType.Bonus }
|
||||
.filter { it.origin == "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))
|
||||
|
@ -6,28 +6,24 @@ import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.Fonts
|
||||
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) {
|
||||
|
||||
init {
|
||||
// Duration needs to be part of the variables defined in the primary constructor,
|
||||
// so that it will be copied over with the automatically generated copy()
|
||||
|
||||
duration =
|
||||
if (type.isImmediate) -1 // -1 for offers that are immediate (e.g. gold transfer)
|
||||
else {
|
||||
// Do *not* access UncivGame.Current.gameInfo in the default constructor!
|
||||
val gameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed
|
||||
when {
|
||||
name == Constants.peaceTreaty -> 10
|
||||
gameSpeed == GameSpeed.Quick -> 25
|
||||
else -> (30 * gameSpeed.modifier).toInt()
|
||||
}
|
||||
}
|
||||
constructor(
|
||||
name: String,
|
||||
type: TradeType,
|
||||
amount: Int = -1,
|
||||
gameSpeed: GameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed
|
||||
) : this(name, type, amount, duration = -1) {
|
||||
duration = when {
|
||||
type.isImmediate -> -1 // -1 for offers that are immediate (e.g. gold transfer)
|
||||
name == Constants.peaceTreaty -> 10
|
||||
gameSpeed == GameSpeed.Quick -> 25
|
||||
else -> (30 * gameSpeed.modifier).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
constructor() : this("", TradeType.Gold) // so that the json deserializer can work
|
||||
|
||||
constructor() : this("", TradeType.Gold, duration = -1) // so that the json deserializer can work
|
||||
|
||||
@Suppress("CovariantEquals") // This is an overload, not an override of the built-in equals(Any?)
|
||||
fun equals(offer: TradeOffer): Boolean {
|
||||
|
Reference in New Issue
Block a user