mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -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 @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
|
@Transient lateinit var cityInfo: CityInfo
|
||||||
|
|
||||||
private val statsFromTiles: Stats
|
private fun getStatsFromTiles(): Stats {
|
||||||
get() {
|
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
for (cell in cityInfo.tilesInRange.filter { cityInfo.name == it.workingCity })
|
for (cell in cityInfo.tilesInRange.filter { cityInfo.name == it.workingCity })
|
||||||
stats.add(cell.getTileStats(cityInfo, cityInfo.civInfo))
|
stats.add(cell.getTileStats(cityInfo, cityInfo.civInfo))
|
||||||
@ -22,8 +21,7 @@ class CityStats {
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
val statsFromTradeRoute: Stats
|
fun getStatsFromTradeRoute(): Stats {
|
||||||
get() {
|
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
if (!isCapital && isConnectedToCapital(RoadStatus.Road)) {
|
if (!isCapital && isConnectedToCapital(RoadStatus.Road)) {
|
||||||
val civInfo = cityInfo.civInfo
|
val civInfo = cityInfo.civInfo
|
||||||
@ -36,8 +34,7 @@ class CityStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val statsFromProduction: Stats
|
private fun getStatsFromProduction(): Stats {
|
||||||
get() {
|
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
|
|
||||||
if ("Gold" == cityInfo.cityConstructions.currentConstruction) stats.gold += stats.production / 4
|
if ("Gold" == cityInfo.cityConstructions.currentConstruction) stats.gold += stats.production / 4
|
||||||
@ -51,16 +48,14 @@ class CityStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val statPercentBonusesFromRailroad: Stats
|
private fun getStatPercentBonusesFromRailroad(): Stats {
|
||||||
get() {
|
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
if (cityInfo.civInfo.tech.isResearched("Combustion") && (isCapital || isConnectedToCapital(RoadStatus.Railroad)))
|
if (cityInfo.civInfo.tech.isResearched("Combustion") && (isCapital || isConnectedToCapital(RoadStatus.Railroad)))
|
||||||
stats.production += 25f
|
stats.production += 25f
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
private val statPercentBonusesFromMarble: Stats
|
private fun getStatPercentBonusesFromMarble(): Stats {
|
||||||
get() {
|
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
val construction = cityInfo.cityConstructions.getCurrentConstruction()
|
val construction = cityInfo.cityConstructions.getCurrentConstruction()
|
||||||
|
|
||||||
@ -72,8 +67,7 @@ class CityStats {
|
|||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
private val statPercentBonusesFromComputers: Stats
|
private fun getStatPercentBonusesFromComputers(): Stats {
|
||||||
get() {
|
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
|
|
||||||
if (cityInfo.civInfo.tech.isResearched("Computers")) {
|
if (cityInfo.civInfo.tech.isResearched("Computers")) {
|
||||||
@ -84,8 +78,7 @@ class CityStats {
|
|||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
private val growthBonusFromPolicies: Float
|
private fun getGrowthBonusFromPolicies(): Float {
|
||||||
get() {
|
|
||||||
var bonus = 0f
|
var bonus = 0f
|
||||||
if (cityInfo.civInfo.policies.isAdopted("Landed Elite") && isCapital)
|
if (cityInfo.civInfo.policies.isAdopted("Landed Elite") && isCapital)
|
||||||
bonus += 0.1f
|
bonus += 0.1f
|
||||||
@ -197,22 +190,22 @@ class CityStats {
|
|||||||
stats.science += cityInfo.population.population.toFloat()
|
stats.science += cityInfo.population.population.toFloat()
|
||||||
stats.production += cityInfo.population.freePopulation.toFloat()
|
stats.production += cityInfo.population.freePopulation.toFloat()
|
||||||
|
|
||||||
stats.add(statsFromTiles)
|
stats.add(getStatsFromTiles())
|
||||||
stats.add(getStatsFromSpecialists(cityInfo.population.specialists, civInfo.policies.adoptedPolicies))
|
stats.add(getStatsFromSpecialists(cityInfo.population.specialists, civInfo.policies.adoptedPolicies))
|
||||||
stats.add(statsFromTradeRoute)
|
stats.add(getStatsFromTradeRoute())
|
||||||
stats.add(cityInfo.cityConstructions.getStats())
|
stats.add(cityInfo.cityConstructions.getStats())
|
||||||
stats.add(getStatsFromPolicies(civInfo.policies.adoptedPolicies))
|
stats.add(getStatsFromPolicies(civInfo.policies.adoptedPolicies))
|
||||||
|
|
||||||
val statPercentBonuses = cityInfo.cityConstructions.getStatPercentBonuses()
|
val statPercentBonuses = cityInfo.cityConstructions.getStatPercentBonuses()
|
||||||
statPercentBonuses.add(getStatPercentBonusesFromGoldenAge(cityInfo.civInfo.goldenAges.isGoldenAge()))
|
statPercentBonuses.add(getStatPercentBonusesFromGoldenAge(cityInfo.civInfo.goldenAges.isGoldenAge()))
|
||||||
statPercentBonuses.add(getStatPercentBonusesFromPolicies(civInfo.policies.adoptedPolicies, cityInfo.cityConstructions))
|
statPercentBonuses.add(getStatPercentBonusesFromPolicies(civInfo.policies.adoptedPolicies, cityInfo.cityConstructions))
|
||||||
statPercentBonuses.add(statPercentBonusesFromRailroad)
|
statPercentBonuses.add(getStatPercentBonusesFromRailroad())
|
||||||
statPercentBonuses.add(statPercentBonusesFromMarble)
|
statPercentBonuses.add(getStatPercentBonusesFromMarble())
|
||||||
statPercentBonuses.add(statPercentBonusesFromComputers)
|
statPercentBonuses.add(getStatPercentBonusesFromComputers())
|
||||||
|
|
||||||
stats.production *= 1 + statPercentBonuses.production / 100 // So they get bonuses for production and gold/science
|
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
|
stats.gold *= 1 + statPercentBonuses.gold / 100
|
||||||
@ -226,7 +219,7 @@ class CityStats {
|
|||||||
stats.food += cityInfo.population.numberOfSpecialists.toFloat()
|
stats.food += cityInfo.population.numberOfSpecialists.toFloat()
|
||||||
|
|
||||||
if (isUnhappy) stats.food /= 4f // Reduce excess food to 1/4 per the same
|
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!
|
stats.gold -= cityInfo.cityConstructions.getMaintenanceCosts().toFloat() // this is AFTER the bonus calculation!
|
||||||
this.currentCityStats = stats
|
this.currentCityStats = stats
|
||||||
@ -238,7 +231,7 @@ class CityStats {
|
|||||||
val capitalTile = cityInfo.civInfo.capital.tile
|
val capitalTile = cityInfo.civInfo.capital.tile
|
||||||
val tilesReached = HashSet<TileInfo>()
|
val tilesReached = HashSet<TileInfo>()
|
||||||
var tilesToCheck : List<TileInfo> = listOf(cityInfo.tile)
|
var tilesToCheck : List<TileInfo> = listOf(cityInfo.tile)
|
||||||
while (tilesToCheck.any()) {
|
while (tilesToCheck.isNotEmpty()) {
|
||||||
val newTiles = tilesToCheck
|
val newTiles = tilesToCheck
|
||||||
.flatMap { cityInfo.tileMap.getTilesInDistance(it.position, 1) }.distinct()
|
.flatMap { cityInfo.tileMap.getTilesInDistance(it.position, 1) }.distinct()
|
||||||
.filter{ !tilesReached.contains(it) && !tilesToCheck.contains(it)
|
.filter{ !tilesReached.contains(it) && !tilesToCheck.contains(it)
|
||||||
|
@ -47,7 +47,9 @@ class RandomMapGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getRandomResource(resources: List<TileResource>, resourceType: ResourceType): TileResource? {
|
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