Kotlin 1.5 new warnings - partial (#5121)

This commit is contained in:
SomeTroglodyte 2021-09-08 20:15:32 +02:00 committed by GitHub
parent 1785c1f78e
commit 366ce4b89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 34 deletions

View File

@ -64,7 +64,7 @@ class PopulationManager {
var percentOfFoodCarriedOver = cityInfo var percentOfFoodCarriedOver = cityInfo
.getMatchingUniques("[]% of food is carried over [] after population increases") .getMatchingUniques("[]% of food is carried over [] after population increases")
.filter { cityInfo.matchesFilter(it.params[1]) } .filter { cityInfo.matchesFilter(it.params[1]) }
.sumBy { it.params[0].toInt() } .sumOf { it.params[0].toInt() }
// Try to avoid runaway food gain in mods, just in case // Try to avoid runaway food gain in mods, just in case
if (percentOfFoodCarriedOver > 95) percentOfFoodCarriedOver = 95 if (percentOfFoodCarriedOver > 95) percentOfFoodCarriedOver = 95
foodStored += (getFoodToNextPopulation() * percentOfFoodCarriedOver / 100f).toInt() foodStored += (getFoodToNextPopulation() * percentOfFoodCarriedOver / 100f).toInt()
@ -87,10 +87,10 @@ class PopulationManager {
} else { } else {
autoAssignPopulation() autoAssignPopulation()
} }
cityInfo.religion.updatePressureOnPopulationChange(changedAmount) cityInfo.religion.updatePressureOnPopulationChange(changedAmount)
} }
internal fun setPopulation(count: Int) { internal fun setPopulation(count: Int) {
addPopulation(-population + count) addPopulation(-population + count)
} }

View File

@ -199,7 +199,7 @@ class PolicyManager {
// If we have "create a free aqueduct in first 3 cities" and "create free aqueduct in first 4 cities", we do: "create free aqueduct in first 3+4=7 cities" // If we have "create a free aqueduct in first 3 cities" and "create free aqueduct in first 4 cities", we do: "create free aqueduct in first 3+4=7 cities"
val sortedUniques = matchingUniques.groupBy {it.params[0]} val sortedUniques = matchingUniques.groupBy {it.params[0]}
for (unique in sortedUniques) { for (unique in sortedUniques) {
tryAddSpecificBuilding(unique.key, unique.value.sumBy {it.params[1].toInt()}) tryAddSpecificBuilding(unique.key, unique.value.sumOf {it.params[1].toInt()})
} }
} }

View File

@ -17,6 +17,7 @@ import com.unciv.ui.utils.randomWeighted
import kotlin.math.max import kotlin.math.max
import kotlin.random.Random import kotlin.random.Random
@Suppress("NON_EXHAUSTIVE_WHEN") // Many when uses in here are much clearer this way
class QuestManager { class QuestManager {
companion object { companion object {
@ -338,7 +339,7 @@ class QuestManager {
} }
} }
/** Increments [assignedQuest.assignee] influence on [civInfo] and adds a [Notification] */ /** Increments [assignedQuest.assignee][AssignedQuest.assignee] influence on [civInfo] and adds a [Notification] */
private fun giveReward(assignedQuest: AssignedQuest) { private fun giveReward(assignedQuest: AssignedQuest) {
val rewardInfluence = civInfo.gameInfo.ruleSet.quests[assignedQuest.questName]!!.influece val rewardInfluence = civInfo.gameInfo.ruleSet.quests[assignedQuest.questName]!!.influece
val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee) val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee)
@ -357,6 +358,7 @@ class QuestManager {
/** Returns the score for the [assignedQuest] */ /** Returns the score for the [assignedQuest] */
private fun getScoreForQuest(assignedQuest: AssignedQuest): Int { private fun getScoreForQuest(assignedQuest: AssignedQuest): Int {
@Suppress("UNUSED_VARIABLE") // This is a work in progress
val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee) val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee)
return when (assignedQuest.questName) { return when (assignedQuest.questName) {
// Waiting for contest quests // Waiting for contest quests

View File

@ -37,10 +37,10 @@ class ReligionManager {
// founding a religion would break :( // founding a religion would break :(
private var foundingCityId: String? = null private var foundingCityId: String? = null
// Only used for keeping track of the city a prophet was used when founding a religion // Only used for keeping track of the city a prophet was used when founding a religion
private var shouldChoosePantheonBelief: Boolean = false private var shouldChoosePantheonBelief: Boolean = false
fun clone(): ReligionManager { fun clone(): ReligionManager {
val clone = ReligionManager() val clone = ReligionManager()
clone.foundingCityId = foundingCityId clone.foundingCityId = foundingCityId
@ -74,7 +74,7 @@ class ReligionManager {
fun faithForPantheon(additionalCivs: Int = 0) = fun faithForPantheon(additionalCivs: Int = 0) =
10 + (civInfo.gameInfo.civilizations.count { it.isMajorCiv() && it.religionManager.religion != null } + additionalCivs) * 5 10 + (civInfo.gameInfo.civilizations.count { it.isMajorCiv() && it.religionManager.religion != null } + additionalCivs) * 5
fun canFoundPantheon(): Boolean { fun canFoundPantheon(): Boolean {
if (!civInfo.gameInfo.hasReligionEnabled()) return false if (!civInfo.gameInfo.hasReligionEnabled()) return false
if (religionState != ReligionState.None) return false if (religionState != ReligionState.None) return false
@ -102,17 +102,17 @@ class ReligionManager {
city.religion.addPressure(belief.name, 200 * city.population.population) city.religion.addPressure(belief.name, 200 * city.population.population)
religionState = ReligionState.Pantheon religionState = ReligionState.Pantheon
} }
// https://www.reddit.com/r/civ/comments/2m82wu/can_anyone_detail_the_finer_points_of_great/ // https://www.reddit.com/r/civ/comments/2m82wu/can_anyone_detail_the_finer_points_of_great/
// Game files (globaldefines.xml) // Game files (globaldefines.xml)
fun faithForNextGreatProphet(): Int { fun faithForNextGreatProphet(): Int {
var faithCost = var faithCost =
(200 + 100 * greatProphetsEarned * (greatProphetsEarned + 1) / 2f) * (200 + 100 * greatProphetsEarned * (greatProphetsEarned + 1) / 2f) *
civInfo.gameInfo.gameParameters.gameSpeed.modifier civInfo.gameInfo.gameParameters.gameSpeed.modifier
for (unique in civInfo.getMatchingUniques("[]% Faith cost of generating Great Prophet equivalents")) for (unique in civInfo.getMatchingUniques("[]% Faith cost of generating Great Prophet equivalents"))
faithCost *= unique.params[0].toPercent() faithCost *= unique.params[0].toPercent()
return faithCost.toInt() return faithCost.toInt()
} }
@ -141,16 +141,16 @@ class ReligionManager {
fun mayFoundReligionAtAll(prophet: MapUnit): Boolean { fun mayFoundReligionAtAll(prophet: MapUnit): Boolean {
if (religionState >= ReligionState.Religion) return false // Already created a major religion if (religionState >= ReligionState.Religion) return false // Already created a major religion
// Already used its power for other things // Already used its power for other things
if (prophet.abilityUsesLeft.any { it.value != prophet.maxAbilityUses[it.key] }) return false if (prophet.abilityUsesLeft.any { it.value != prophet.maxAbilityUses[it.key] }) return false
if (!civInfo.isMajorCiv()) return false // Only major civs may use religion if (!civInfo.isMajorCiv()) return false // Only major civs may use religion
val foundedReligionsCount = civInfo.gameInfo.civilizations.count { val foundedReligionsCount = civInfo.gameInfo.civilizations.count {
it.religionManager.religion != null && it.religionManager.religionState >= ReligionState.Religion it.religionManager.religion != null && it.religionManager.religionState >= ReligionState.Religion
} }
if (foundedReligionsCount >= civInfo.gameInfo.civilizations.count { it.isMajorCiv() } / 2 + 1) if (foundedReligionsCount >= civInfo.gameInfo.civilizations.count { it.isMajorCiv() } / 2 + 1)
return false // Too bad, too many religions have already been founded return false // Too bad, too many religions have already been founded
@ -161,11 +161,11 @@ class ReligionManager {
it.type == BeliefType.Follower it.type == BeliefType.Follower
&& civInfo.gameInfo.religions.values.none { religion -> it in religion.getBeliefs(BeliefType.Follower) } && civInfo.gameInfo.religions.values.none { religion -> it in religion.getBeliefs(BeliefType.Follower) }
}) return false // Mod maker did not provide enough follower beliefs }) return false // Mod maker did not provide enough follower beliefs
// Shortcut as each religion will always have exactly one founder belief // Shortcut as each religion will always have exactly one founder belief
if (foundedReligionsCount >= civInfo.gameInfo.ruleSet.beliefs.values.count { it.type == BeliefType.Founder }) if (foundedReligionsCount >= civInfo.gameInfo.ruleSet.beliefs.values.count { it.type == BeliefType.Founder })
return false // Mod maker did not provide enough founder beliefs return false // Mod maker did not provide enough founder beliefs
return true return true
} }
@ -183,13 +183,13 @@ class ReligionManager {
religionState = ReligionState.FoundingReligion religionState = ReligionState.FoundingReligion
civInfo.religionManager.foundingCityId = prophet.getTile().getCity()!!.id civInfo.religionManager.foundingCityId = prophet.getTile().getCity()!!.id
} }
fun getBeliefsToChooseAtFounding(): BeliefContainer { fun getBeliefsToChooseAtFounding(): BeliefContainer {
if (shouldChoosePantheonBelief) if (shouldChoosePantheonBelief)
return BeliefContainer(pantheonBeliefCount = 1, founderBeliefCount = 1, followerBeliefCount = 1) return BeliefContainer(pantheonBeliefCount = 1, founderBeliefCount = 1, followerBeliefCount = 1)
return BeliefContainer(founderBeliefCount = 1, followerBeliefCount = 1) return BeliefContainer(founderBeliefCount = 1, followerBeliefCount = 1)
} }
fun chooseBeliefs(iconName: String?, religionName: String?, beliefs: List<Belief>) { fun chooseBeliefs(iconName: String?, religionName: String?, beliefs: List<Belief>) {
if (religionState == ReligionState.FoundingReligion) { if (religionState == ReligionState.FoundingReligion) {
foundReligion(iconName!!, religionName!!, beliefs) foundReligion(iconName!!, religionName!!, beliefs)
@ -198,7 +198,7 @@ class ReligionManager {
if (religionState == ReligionState.EnhancingReligion) if (religionState == ReligionState.EnhancingReligion)
enhanceReligion(beliefs) enhanceReligion(beliefs)
} }
fun foundReligion(displayName: String, name: String, beliefs: List<Belief>) { fun foundReligion(displayName: String, name: String, beliefs: List<Belief>) {
val newReligion = Religion(name, civInfo.gameInfo, civInfo.civName) val newReligion = Religion(name, civInfo.gameInfo, civInfo.civName)
@ -207,7 +207,7 @@ class ReligionManager {
newReligion.followerBeliefs.addAll(religion!!.followerBeliefs) newReligion.followerBeliefs.addAll(religion!!.followerBeliefs)
newReligion.founderBeliefs.addAll(religion!!.founderBeliefs) newReligion.founderBeliefs.addAll(religion!!.founderBeliefs)
} }
newReligion.followerBeliefs.addAll( newReligion.followerBeliefs.addAll(
beliefs beliefs
.filter { it.type == BeliefType.Pantheon || it.type == BeliefType.Follower } .filter { it.type == BeliefType.Pantheon || it.type == BeliefType.Follower }
@ -218,7 +218,7 @@ class ReligionManager {
.filter { it.type == BeliefType.Founder } .filter { it.type == BeliefType.Founder }
.map { it.name } .map { it.name }
) )
religion = newReligion religion = newReligion
civInfo.gameInfo.religions[name] = newReligion civInfo.gameInfo.religions[name] = newReligion
@ -230,12 +230,12 @@ class ReligionManager {
foundingCityId = null foundingCityId = null
shouldChoosePantheonBelief = false shouldChoosePantheonBelief = false
for (unit in civInfo.getCivUnits()) for (unit in civInfo.getCivUnits())
if (unit.hasUnique("Religious Unit") && unit.hasUnique("Takes your religion over the one in their birth city")) if (unit.hasUnique("Religious Unit") && unit.hasUnique("Takes your religion over the one in their birth city"))
unit.religion = newReligion.name unit.religion = newReligion.name
} }
fun mayEnhanceReligionAtAll(prophet: MapUnit): Boolean { fun mayEnhanceReligionAtAll(prophet: MapUnit): Boolean {
if (religion == null) return false // First found a pantheon if (religion == null) return false // First found a pantheon
if (religionState != ReligionState.Religion) return false // First found an actual religion if (religionState != ReligionState.Religion) return false // First found an actual religion
@ -247,12 +247,12 @@ class ReligionManager {
it.type == BeliefType.Follower it.type == BeliefType.Follower
&& civInfo.gameInfo.religions.values.none { religion -> religion.getBeliefs(BeliefType.Follower).contains(it) } && civInfo.gameInfo.religions.values.none { religion -> religion.getBeliefs(BeliefType.Follower).contains(it) }
}) return false // Mod maker did not provide enough follower beliefs }) return false // Mod maker did not provide enough follower beliefs
if (civInfo.gameInfo.ruleSet.beliefs.values.none { if (civInfo.gameInfo.ruleSet.beliefs.values.none {
it.type == BeliefType.Enhancer it.type == BeliefType.Enhancer
&& civInfo.gameInfo.religions.values.none { religion -> religion.getBeliefs(BeliefType.Enhancer).contains(it) } && civInfo.gameInfo.religions.values.none { religion -> religion.getBeliefs(BeliefType.Enhancer).contains(it) }
}) return false // Mod maker did not provide enough enhancer beliefs }) return false // Mod maker did not provide enough enhancer beliefs
return true return true
} }
@ -270,24 +270,24 @@ class ReligionManager {
fun getBeliefsToChooseAtEnhancing(): BeliefContainer { fun getBeliefsToChooseAtEnhancing(): BeliefContainer {
return BeliefContainer(followerBeliefCount = 1, enhancerBeliefCount = 1) return BeliefContainer(followerBeliefCount = 1, enhancerBeliefCount = 1)
} }
fun enhanceReligion(beliefs: List<Belief>) { fun enhanceReligion(beliefs: List<Belief>) {
religion!!.followerBeliefs.addAll(beliefs.filter { it.type == BeliefType.Follower}.map { it.name }) religion!!.followerBeliefs.addAll(beliefs.filter { it.type == BeliefType.Follower}.map { it.name })
religion!!.founderBeliefs.addAll(beliefs.filter { it.type == BeliefType.Enhancer}.map { it.name }) religion!!.founderBeliefs.addAll(beliefs.filter { it.type == BeliefType.Enhancer}.map { it.name })
religionState = ReligionState.EnhancedReligion religionState = ReligionState.EnhancedReligion
} }
fun numberOfCitiesFollowingThisReligion(): Int { fun numberOfCitiesFollowingThisReligion(): Int {
if (religion == null) return 0 if (religion == null) return 0
return civInfo.gameInfo.getCities() return civInfo.gameInfo.getCities()
.count { it.religion.getMajorityReligion() == religion } .count { it.religion.getMajorityReligion() == religion }
} }
fun numberOfFollowersFollowingThisReligion(cityFilter: String): Int { fun numberOfFollowersFollowingThisReligion(cityFilter: String): Int {
if (religion == null) return 0 if (religion == null) return 0
return civInfo.gameInfo.getCities() return civInfo.gameInfo.getCities()
.filter { it.matchesFilter(cityFilter, civInfo) } .filter { it.matchesFilter(cityFilter, civInfo) }
.sumBy { it.religion.getFollowersOf(religion!!.name)!! } .sumOf { it.religion.getFollowersOf(religion!!.name)!! }
} }
} }

View File

@ -25,7 +25,7 @@ enum class RelationshipLevel(val color: Color) {
Ally(Color.CHARTREUSE) // HSV(90,100,100) Ally(Color.CHARTREUSE) // HSV(90,100,100)
} }
enum class DiplomacyFlags{ enum class DiplomacyFlags {
DeclinedLuxExchange, DeclinedLuxExchange,
DeclinedPeace, DeclinedPeace,
DeclinedResearchAgreement, DeclinedResearchAgreement,
@ -46,7 +46,7 @@ enum class DiplomacyFlags{
AngerFreeIntrusion AngerFreeIntrusion
} }
enum class DiplomaticModifiers{ enum class DiplomaticModifiers {
DeclaredWarOnUs, DeclaredWarOnUs,
WarMongerer, WarMongerer,
CapturedOurCities, CapturedOurCities,
@ -199,11 +199,11 @@ class DiplomacyManager() {
else -> false else -> false
} }
} }
fun addInfluence(amount: Float) { fun addInfluence(amount: Float) {
setInfluence(influence + amount) setInfluence(influence + amount)
} }
fun setInfluence(amount: Float) { fun setInfluence(amount: Float) {
influence = max(amount, MINIMUM_INFLUENCE) influence = max(amount, MINIMUM_INFLUENCE)
civInfo.updateAllyCivForCityState() civInfo.updateAllyCivForCityState()
@ -743,6 +743,7 @@ class DiplomacyManager() {
for (thirdCiv in getCommonKnownCivs() for (thirdCiv in getCommonKnownCivs()
.filter { it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }) { .filter { it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }) {
val otherCivRelationshipWithThirdCiv = otherCiv().getDiplomacyManager(thirdCiv).relationshipLevel() val otherCivRelationshipWithThirdCiv = otherCiv().getDiplomacyManager(thirdCiv).relationshipLevel()
@Suppress("NON_EXHAUSTIVE_WHEN") // Better readability
when (otherCivRelationshipWithThirdCiv) { when (otherCivRelationshipWithThirdCiv) {
RelationshipLevel.Unforgivable -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -15f) RelationshipLevel.Unforgivable -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -15f)
RelationshipLevel.Enemy -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -5f) RelationshipLevel.Enemy -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -5f)
@ -765,6 +766,7 @@ class DiplomacyManager() {
thirdCiv.addNotification("[${civInfo.civName}] has denounced [$otherCivName]!", civInfo.civName, NotificationIcon.Diplomacy, otherCivName) thirdCiv.addNotification("[${civInfo.civName}] has denounced [$otherCivName]!", civInfo.civName, NotificationIcon.Diplomacy, otherCivName)
val thirdCivRelationshipWithOtherCiv = thirdCiv.getDiplomacyManager(otherCiv()).relationshipLevel() val thirdCivRelationshipWithOtherCiv = thirdCiv.getDiplomacyManager(otherCiv()).relationshipLevel()
val thirdCivDiplomacyManager = thirdCiv.getDiplomacyManager(civInfo) val thirdCivDiplomacyManager = thirdCiv.getDiplomacyManager(civInfo)
@Suppress("NON_EXHAUSTIVE_WHEN") // Better readability
when (thirdCivRelationshipWithOtherCiv) { when (thirdCivRelationshipWithOtherCiv) {
RelationshipLevel.Unforgivable -> thirdCivDiplomacyManager.addModifier(DiplomaticModifiers.DenouncedOurEnemies, 15f) RelationshipLevel.Unforgivable -> thirdCivDiplomacyManager.addModifier(DiplomaticModifiers.DenouncedOurEnemies, 15f)
RelationshipLevel.Enemy -> thirdCivDiplomacyManager.addModifier(DiplomaticModifiers.DenouncedOurEnemies, 5f) RelationshipLevel.Enemy -> thirdCivDiplomacyManager.addModifier(DiplomaticModifiers.DenouncedOurEnemies, 5f)