From ab5083173ddcf777215ba377489e1c22e6aa82f6 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Wed, 8 Sep 2021 19:48:24 +0200 Subject: [PATCH] Kotlin 1.5 new warnings - partial (#5120) --- core/src/com/unciv/logic/map/MapUnit.kt | 46 +++++++++---------- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 4 +- .../cityscreen/CityScreenCityPickerTable.kt | 1 - .../unciv/ui/civilopedia/CivilopediaScreen.kt | 1 - core/src/com/unciv/ui/utils/AskTextPopup.kt | 3 +- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 3dabb05423..6140aeed2e 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -182,7 +182,7 @@ class MapUnit { if (isEmbarked()) 2 else baseUnit.movement - movement += getMatchingUniques("[] Movement").sumBy { it.params[0].toInt() } + movement += getMatchingUniques("[] Movement").sumOf { it.params[0].toInt() } for (unique in civInfo.getMatchingUniques("+[] Movement for all [] units")) if (matchesFilter(unique.params[1])) @@ -277,7 +277,7 @@ class MapUnit { visibilityRange += unique.params[0].toInt() // TODO: This should be replaced with "Sight" like others, for naming consistency - visibilityRange += getMatchingUniques("[] Visibility Range").sumBy { it.params[0].toInt() } + visibilityRange += getMatchingUniques("[] Visibility Range").sumOf { it.params[0].toInt() } if (hasUnique("Limited Visibility")) visibilityRange -= 1 @@ -344,7 +344,7 @@ class MapUnit { } fun maxAttacksPerTurn(): Int { - var maxAttacksPerTurn = 1 + getMatchingUniques("[] additional attacks per turn").sumBy { it.params[0].toInt() } + var maxAttacksPerTurn = 1 + getMatchingUniques("[] additional attacks per turn").sumOf { it.params[0].toInt() } return maxAttacksPerTurn } @@ -356,7 +356,7 @@ class MapUnit { fun getRange(): Int { if (baseUnit.isMelee()) return 1 var range = baseUnit().range - range += getMatchingUniques("[] Range").sumBy { it.params[0].toInt() } + range += getMatchingUniques("[] Range").sumOf { it.params[0].toInt() } return range } @@ -440,7 +440,7 @@ class MapUnit { } private fun adjacentHealingBonus(): Int { - return getMatchingUniques("All adjacent units heal [] HP when healing").sumBy { it.params[0].toInt() } + return getMatchingUniques("All adjacent units heal [] HP when healing").sumOf { it.params[0].toInt() } } fun canGarrison() = baseUnit.isMilitary() && baseUnit.isLandUnit() @@ -469,7 +469,7 @@ class MapUnit { for (ability in abilityUsedCount) { val maxUsesOfThisAbility = getMatchingUniques("Can [] [] times") .filter { it.params[0] == ability.key } - .sumBy { it.params[1].toInt() } + .sumOf { it.params[1].toInt() } abilityUsesLeft[ability.key] = maxUsesOfThisAbility - ability.value maxAbilityUses[ability.key] = maxUsesOfThisAbility } @@ -595,7 +595,7 @@ class MapUnit { var amountToHealBy = rankTileForHealing(getTile()) if (amountToHealBy == 0 && !(hasUnique("May heal outside of friendly territory") && !getTile().isFriendlyTerritory(civInfo))) return - amountToHealBy += getMatchingUniques("[] HP when healing").sumBy { it.params[0].toInt() } + amountToHealBy += getMatchingUniques("[] HP when healing").sumOf { it.params[0].toInt() } val maxAdjacentHealingBonus = currentTile.getTilesInDistance(1) .flatMap { it.getUnits().asSequence() }.map { it.adjacentHealingBonus() }.maxOrNull() @@ -858,13 +858,13 @@ class MapUnit { fun canIntercept(): Boolean { if (interceptChance() == 0) return false val maxAttacksPerTurn = 1 + - getMatchingUniques("[] extra interceptions may be made per turn").sumBy { it.params[0].toInt() } + getMatchingUniques("[] extra interceptions may be made per turn").sumOf { it.params[0].toInt() } if (attacksThisTurn >= maxAttacksPerTurn) return false return true } fun interceptChance(): Int { - return getMatchingUniques("[]% chance to intercept air attacks").sumBy { it.params[0].toInt() } + return getMatchingUniques("[]% chance to intercept air attacks").sumOf { it.params[0].toInt() } } fun isTransportTypeOf(mapUnit: MapUnit): Boolean { @@ -872,13 +872,12 @@ class MapUnit { if (!mapUnit.baseUnit.movesLikeAirUnits()) return false return getMatchingUniques("Can carry [] [] units").any { mapUnit.matchesFilter(it.params[1]) } } - + private fun carryCapacity(unit: MapUnit): Int { - var capacity = getMatchingUniques("Can carry [] [] units").filter { unit.matchesFilter(it.params[1]) } - .sumBy { it.params[0].toInt() } - capacity += getMatchingUniques("Can carry [] extra [] units").filter { unit.matchesFilter(it.params[1]) } - .sumBy { it.params[0].toInt() } - return capacity + return (getMatchingUniques("Can carry [] [] units") + + getMatchingUniques("Can carry [] extra [] units")) + .filter { unit.matchesFilter(it.params[1]) } + .sumOf { it.params[0].toInt() } } fun canTransport(unit: MapUnit): Boolean { @@ -891,7 +890,7 @@ class MapUnit { fun interceptDamagePercentBonus(): Int { return getUniques().filter { it.placeholderText == "[]% Damage when intercepting"} - .sumBy { it.params[0].toInt() } + .sumOf { it.params[0].toInt() } } fun receivedInterceptDamageFactor(): Float { @@ -999,9 +998,9 @@ class MapUnit { fun getBaseMaxActionUses(action: String): Int { return getMatchingUniques("Can [] [] times") .filter { it.params[0] == action } - .sumBy { it.params[1].toInt() } + .sumOf { it.params[1].toInt() } } - + fun setupAbilityUses(buildCity: CityInfo? = null) { for (action in religiousActionsUnitCanDo()) { val baseAmount = getBaseMaxActionUses(action) @@ -1009,15 +1008,14 @@ class MapUnit { if (buildCity == null) 0 else buildCity.getMatchingUniques("[] units built [] can [] [] extra times") .filter { matchesFilter(it.params[0]) && buildCity.matchesFilter(it.params[1]) && it.params[2] == action } - .sumBy { println("Addition ability found: ${it.params[1]}"); it.params[3].toInt() } - + .sumOf { it.params[3].toInt() } + maxAbilityUses[action] = baseAmount + additional - - abilityUsesLeft[action] = maxAbilityUses[action]!! + abilityUsesLeft[action] = baseAmount + additional } } - - + + fun getPressureAddedFromSpread(): Int { var pressureAdded = baseUnit.religiousStrength.toFloat() for (unique in civInfo.getMatchingUniques("[]% Spread Religion Strength for [] units")) diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index 59eed18876..ca6842889b 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -482,8 +482,8 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText { if (getType().matchesFilter(filter)) return true if ( filter.endsWith(" units") - // "military units" --> "Military" - && matchesFilter(filter.removeSuffix(" units").toLowerCase(Locale.ENGLISH).capitalize(Locale.ENGLISH)) + // "military units" --> "Military", using invariant locale + && matchesFilter(filter.removeSuffix(" units").lowercase().replaceFirstChar { it.uppercaseChar() }) ) return true return uniques.contains(filter) } diff --git a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt index 544e1fdfb1..8ac993e5a3 100644 --- a/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityScreenCityPickerTable.kt @@ -58,7 +58,6 @@ class CityScreenCityPickerTable(private val cityScreen: CityScreen) : Table() { actionOnOk = { text -> city.name = text cityScreen.game.setScreen(CityScreen(city)) - true } ).open() } diff --git a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt index 66ce7022f3..78c0168c37 100644 --- a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt @@ -173,7 +173,6 @@ class CivilopediaScreen( onBackButtonClicked { UncivGame.Current.setWorldScreen() } val hideReligionItems = !game.gameInfo.hasReligionEnabled() - val noCulturalVictory = VictoryType.Cultural !in game.gameInfo.gameParameters.victoryTypes fun shouldBeDisplayed(uniqueObjects: List): Boolean { val uniques = uniqueObjects.map { it.placeholderText } diff --git a/core/src/com/unciv/ui/utils/AskTextPopup.kt b/core/src/com/unciv/ui/utils/AskTextPopup.kt index f1a638fe3f..708acea81b 100644 --- a/core/src/com/unciv/ui/utils/AskTextPopup.kt +++ b/core/src/com/unciv/ui/utils/AskTextPopup.kt @@ -13,8 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField * @param maxLength The maximal amount of characters the user may input * @param validate Function that should return `true` when a valid input is entered, false otherwise * @param actionOnOk Lambda that will be executed after pressing 'OK'. - * Gets the text the user inputted as a parameter. Should return `true` if ready to close, - * `false` if `errorText` is to be displayed + * Gets the text the user inputted as a parameter. */ class AskTextPopup( screen: CameraStageBaseScreen,