From 22b3f563f3259e469a7dfc6fe8db9654b8824735 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 5 Dec 2020 22:54:16 +0200 Subject: [PATCH] Crash reports contain the game version for easy filtering Added helper function cityInfo.isWorked(tile) --- .../com/unciv/app/CrashReportSenderAndroid.kt | 2 +- .../unciv/logic/city/CityExpansionManager.kt | 2 +- core/src/com/unciv/logic/city/CityInfo.kt | 1 + core/src/com/unciv/logic/city/CityStats.kt | 2 +- .../com/unciv/logic/city/PopulationManager.kt | 22 +++++++++---------- core/src/com/unciv/logic/map/TileInfo.kt | 2 +- .../ui/cityscreen/CityScreenTileTable.kt | 4 ++-- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/android/src/com/unciv/app/CrashReportSenderAndroid.kt b/android/src/com/unciv/app/CrashReportSenderAndroid.kt index 89d13e261d..7c1b722f51 100644 --- a/android/src/com/unciv/app/CrashReportSenderAndroid.kt +++ b/android/src/com/unciv/app/CrashReportSenderAndroid.kt @@ -36,7 +36,7 @@ class CrashReportSenderAndroid(private val activity: Activity) : CrashReportSend private fun prepareIntent(report: CrashReport) = Intent(Intent.ACTION_SEND).apply { type = "message/rfc822" putExtra(Intent.EXTRA_EMAIL, arrayOf(EMAIL_TO)) - putExtra(Intent.EXTRA_SUBJECT, EMAIL_TITLE) + putExtra(Intent.EXTRA_SUBJECT, "$EMAIL_TITLE - ${report.version}") putExtra(Intent.EXTRA_TEXT, buildEmailBody(report)) addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } diff --git a/core/src/com/unciv/logic/city/CityExpansionManager.kt b/core/src/com/unciv/logic/city/CityExpansionManager.kt index ae03390a78..7c987d1ee0 100644 --- a/core/src/com/unciv/logic/city/CityExpansionManager.kt +++ b/core/src/com/unciv/logic/city/CityExpansionManager.kt @@ -109,7 +109,7 @@ class CityExpansionManager { fun relinquishOwnership(tileInfo: TileInfo) { cityInfo.tiles = cityInfo.tiles.withoutItem(tileInfo.position) for (city in cityInfo.civInfo.cities) { - if (city.workedTiles.contains(tileInfo.position)) { + if (city.isWorked(tileInfo)) { city.workedTiles = city.workedTiles.withoutItem(tileInfo.position) city.population.autoAssignPopulation() } diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 65cd4745e8..68f74d8dec 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -158,6 +158,7 @@ class CityInfo { fun getCenterTile(): TileInfo = centerTileInfo fun getTiles(): Sequence = tiles.asSequence().map { tileMap[it] } fun getWorkableTiles() = tilesInRange.asSequence().filter { it.getOwner() == civInfo } + fun isWorked(tileInfo: TileInfo) = workedTiles.contains(tileInfo.position) fun isCapital(): Boolean = cityConstructions.builtBuildings.contains(capitalCityIndicator()) fun capitalCityIndicator(): String = getRuleset().buildings.values.first { it.uniques.contains("Indicates the capital city") }.name diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index e95c5feb9e..b043e4cbe8 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -39,7 +39,7 @@ class CityStats { private fun getStatsFromTiles(): Stats { val stats = Stats() for (cell in cityInfo.tilesInRange - .filter { cityInfo.location == it.position || cityInfo.workedTiles.contains(it.position) }) + .filter { cityInfo.location == it.position || cityInfo.isWorked(it) }) stats.add(cell.getTileStats(cityInfo, cityInfo.civInfo)) return stats } diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index 9d741e21e0..1d8d0c3642 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -19,6 +19,7 @@ class PopulationManager { @Deprecated("As of 3.10.14, changed to Counter to accommodate dynamic specialist types. Use specialistAllocations instead.") val specialists = Stats() + // In favor of this bad boy val specialistAllocations = Counter() @@ -43,8 +44,8 @@ class PopulationManager { fun getFoodToNextPopulation(): Int { // civ v math, civilization.wikia - var foodRequired = 15 + 6 * (population - 1) + floor((population - 1).toDouble().pow(1.8)) - if(!cityInfo.civInfo.isPlayerCivilization()) + var foodRequired = 15 + 6 * (population - 1) + floor((population - 1).toDouble().pow(1.8)) + if (!cityInfo.civInfo.isPlayerCivilization()) foodRequired *= cityInfo.civInfo.gameInfo.getDifficulty().aiCityGrowthModifier return foodRequired.toInt() } @@ -54,7 +55,7 @@ class PopulationManager { fun nextTurn(food: Int) { foodStored += food if (food < 0) - cityInfo.civInfo.addNotification("[" + cityInfo.name + "] is starving!", cityInfo.location, Color.RED) + cityInfo.civInfo.addNotification("[${cityInfo.name}] is starving!", cityInfo.location, Color.RED) if (foodStored < 0) { // starvation! if (population > 1) population-- foodStored = 0 @@ -67,11 +68,11 @@ class PopulationManager { foodStored += (getFoodToNextPopulation() * percentOfFoodCarriedOver / 100f).toInt() population++ autoAssignPopulation() - cityInfo.civInfo.addNotification("[" + cityInfo.name + "] has grown!", cityInfo.location, Color.GREEN) + cityInfo.civInfo.addNotification("[${cityInfo.name}] has grown!", cityInfo.location, Color.GREEN) } } - internal fun getStatsOfSpecialist(name:String) = cityInfo.cityStats.getStatsOfSpecialist(name) + private fun getStatsOfSpecialist(name: String) = cityInfo.cityStats.getStatsOfSpecialist(name) // todo - change tile choice according to city! @@ -89,7 +90,7 @@ class PopulationManager { else Automation.rankTileForCityWork(bestTile, cityInfo, foodWeight) val bestJob: String? = getMaxSpecialists() - .filter { specialistAllocations[it.key]!! 3) + if (tile.getOwner() != cityInfo.civInfo || tile.getWorkingCity() != cityInfo + || tile.aerialDistanceTo(cityInfo.getCenterTile()) > 3) cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(tile.position) } @@ -120,7 +120,7 @@ class PopulationManager { val specialistsHashmap = specialistAllocations for ((specialistName, amount) in maxSpecialists) if (specialistsHashmap[specialistName]!! > amount) - specialistAllocations[specialistName]=amount + specialistAllocations[specialistName] = amount @@ -146,7 +146,6 @@ class PopulationManager { valueWorstSpecialist = Automation.rankSpecialist(getStatsOfSpecialist(worstJob), cityInfo) - //un-assign population if ((worstWorkedTile != null && valueWorstTile < valueWorstSpecialist) || worstJob == null) { @@ -162,5 +161,4 @@ class PopulationManager { counter.add(building.newSpecialists()) return counter } - } \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 19a494927e..09ca5d0f5f 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -164,7 +164,7 @@ open class TileInfo { fun getWorkingCity(): CityInfo? { val civInfo = getOwner() if (civInfo == null) return null - return civInfo.cities.firstOrNull { it.workedTiles.contains(position) } + return civInfo.cities.firstOrNull { it.isWorked(this) } } fun isWorked(): Boolean { diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt index 3ace4db95e..c71b8f9491 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenTileTable.kt @@ -54,11 +54,11 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table(){ } if(city.civInfo.cities.filterNot { it==city } - .any { it.workedTiles.contains(selectedTile.position) }) { + .any { it.isWorked(selectedTile) }) { innerTable.add("Worked by [${selectedTile.getWorkingCity()!!.name}]".toLabel()).row() } - if(city.workedTiles.contains(selectedTile.position)){ + if(city.isWorked(selectedTile)){ if(selectedTile.isLocked()) { val unlockButton = "Unlock".toTextButton() unlockButton.onClick {