mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
Fixed crash when starting new game
This commit is contained in:
parent
7f8e1707be
commit
414025dbbe
@ -12,8 +12,7 @@ class CityStats {
|
||||
@Transient @JvmField var currentCityStats: Stats = Stats() // This is so we won't have to calculate this multiple times - takes a lot of time, especially on phones
|
||||
@Transient lateinit var cityInfo: CityInfo
|
||||
|
||||
private val statsFromTiles: Stats
|
||||
get() {
|
||||
private fun getStatsFromTiles(): Stats {
|
||||
val stats = Stats()
|
||||
for (cell in cityInfo.tilesInRange.filter { cityInfo.name == it.workingCity })
|
||||
stats.add(cell.getTileStats(cityInfo, cityInfo.civInfo))
|
||||
@ -22,8 +21,7 @@ class CityStats {
|
||||
|
||||
private
|
||||
|
||||
val statsFromTradeRoute: Stats
|
||||
get() {
|
||||
fun getStatsFromTradeRoute(): Stats {
|
||||
val stats = Stats()
|
||||
if (!isCapital && isConnectedToCapital(RoadStatus.Road)) {
|
||||
val civInfo = cityInfo.civInfo
|
||||
@ -36,8 +34,7 @@ class CityStats {
|
||||
}
|
||||
|
||||
|
||||
private val statsFromProduction: Stats
|
||||
get() {
|
||||
private fun getStatsFromProduction(): Stats {
|
||||
val stats = Stats()
|
||||
|
||||
if ("Gold" == cityInfo.cityConstructions.currentConstruction) stats.gold += stats.production / 4
|
||||
@ -51,16 +48,14 @@ class CityStats {
|
||||
}
|
||||
|
||||
|
||||
private val statPercentBonusesFromRailroad: Stats
|
||||
get() {
|
||||
private fun getStatPercentBonusesFromRailroad(): Stats {
|
||||
val stats = Stats()
|
||||
if (cityInfo.civInfo.tech.isResearched("Combustion") && (isCapital || isConnectedToCapital(RoadStatus.Railroad)))
|
||||
stats.production += 25f
|
||||
return stats
|
||||
}
|
||||
|
||||
private val statPercentBonusesFromMarble: Stats
|
||||
get() {
|
||||
private fun getStatPercentBonusesFromMarble(): Stats {
|
||||
val stats = Stats()
|
||||
val construction = cityInfo.cityConstructions.getCurrentConstruction()
|
||||
|
||||
@ -72,8 +67,7 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private val statPercentBonusesFromComputers: Stats
|
||||
get() {
|
||||
private fun getStatPercentBonusesFromComputers(): Stats {
|
||||
val stats = Stats()
|
||||
|
||||
if (cityInfo.civInfo.tech.isResearched("Computers")) {
|
||||
@ -84,8 +78,7 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private val growthBonusFromPolicies: Float
|
||||
get() {
|
||||
private fun getGrowthBonusFromPolicies(): Float {
|
||||
var bonus = 0f
|
||||
if (cityInfo.civInfo.policies.isAdopted("Landed Elite") && isCapital)
|
||||
bonus += 0.1f
|
||||
@ -197,22 +190,22 @@ class CityStats {
|
||||
stats.science += cityInfo.population.population.toFloat()
|
||||
stats.production += cityInfo.population.freePopulation.toFloat()
|
||||
|
||||
stats.add(statsFromTiles)
|
||||
stats.add(getStatsFromTiles())
|
||||
stats.add(getStatsFromSpecialists(cityInfo.population.specialists, civInfo.policies.adoptedPolicies))
|
||||
stats.add(statsFromTradeRoute)
|
||||
stats.add(getStatsFromTradeRoute())
|
||||
stats.add(cityInfo.cityConstructions.getStats())
|
||||
stats.add(getStatsFromPolicies(civInfo.policies.adoptedPolicies))
|
||||
|
||||
val statPercentBonuses = cityInfo.cityConstructions.getStatPercentBonuses()
|
||||
statPercentBonuses.add(getStatPercentBonusesFromGoldenAge(cityInfo.civInfo.goldenAges.isGoldenAge()))
|
||||
statPercentBonuses.add(getStatPercentBonusesFromPolicies(civInfo.policies.adoptedPolicies, cityInfo.cityConstructions))
|
||||
statPercentBonuses.add(statPercentBonusesFromRailroad)
|
||||
statPercentBonuses.add(statPercentBonusesFromMarble)
|
||||
statPercentBonuses.add(statPercentBonusesFromComputers)
|
||||
statPercentBonuses.add(getStatPercentBonusesFromRailroad())
|
||||
statPercentBonuses.add(getStatPercentBonusesFromMarble())
|
||||
statPercentBonuses.add(getStatPercentBonusesFromComputers())
|
||||
|
||||
stats.production *= 1 + statPercentBonuses.production / 100 // So they get bonuses for production and gold/science
|
||||
|
||||
stats.add(statsFromProduction)
|
||||
stats.add(getStatsFromProduction())
|
||||
|
||||
|
||||
stats.gold *= 1 + statPercentBonuses.gold / 100
|
||||
@ -226,7 +219,7 @@ class CityStats {
|
||||
stats.food += cityInfo.population.numberOfSpecialists.toFloat()
|
||||
|
||||
if (isUnhappy) stats.food /= 4f // Reduce excess food to 1/4 per the same
|
||||
stats.food *= 1 + growthBonusFromPolicies
|
||||
stats.food *= 1 + getGrowthBonusFromPolicies()
|
||||
|
||||
stats.gold -= cityInfo.cityConstructions.getMaintenanceCosts().toFloat() // this is AFTER the bonus calculation!
|
||||
this.currentCityStats = stats
|
||||
@ -238,7 +231,7 @@ class CityStats {
|
||||
val capitalTile = cityInfo.civInfo.capital.tile
|
||||
val tilesReached = HashSet<TileInfo>()
|
||||
var tilesToCheck : List<TileInfo> = listOf(cityInfo.tile)
|
||||
while (tilesToCheck.any()) {
|
||||
while (tilesToCheck.isNotEmpty()) {
|
||||
val newTiles = tilesToCheck
|
||||
.flatMap { cityInfo.tileMap.getTilesInDistance(it.position, 1) }.distinct()
|
||||
.filter{ !tilesReached.contains(it) && !tilesToCheck.contains(it)
|
||||
|
@ -47,7 +47,9 @@ class RandomMapGenerator {
|
||||
}
|
||||
|
||||
private fun getRandomResource(resources: List<TileResource>, resourceType: ResourceType): TileResource? {
|
||||
return resources.filter { it.resourceType == resourceType }.getRandom()
|
||||
val filtered = resources.filter { it.resourceType == resourceType }
|
||||
if (filtered.isEmpty()) return null
|
||||
else return filtered.getRandom()
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user