mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Kotlin 1.5 new warnings - partial (#5121)
This commit is contained in:
parent
1785c1f78e
commit
366ce4b89b
@ -64,7 +64,7 @@ class PopulationManager {
|
||||
var percentOfFoodCarriedOver = cityInfo
|
||||
.getMatchingUniques("[]% of food is carried over [] after population increases")
|
||||
.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
|
||||
if (percentOfFoodCarriedOver > 95) percentOfFoodCarriedOver = 95
|
||||
foodStored += (getFoodToNextPopulation() * percentOfFoodCarriedOver / 100f).toInt()
|
||||
@ -87,10 +87,10 @@ class PopulationManager {
|
||||
} else {
|
||||
autoAssignPopulation()
|
||||
}
|
||||
|
||||
|
||||
cityInfo.religion.updatePressureOnPopulationChange(changedAmount)
|
||||
}
|
||||
|
||||
|
||||
internal fun setPopulation(count: Int) {
|
||||
addPopulation(-population + count)
|
||||
}
|
||||
|
@ -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"
|
||||
val sortedUniques = matchingUniques.groupBy {it.params[0]}
|
||||
for (unique in sortedUniques) {
|
||||
tryAddSpecificBuilding(unique.key, unique.value.sumBy {it.params[1].toInt()})
|
||||
tryAddSpecificBuilding(unique.key, unique.value.sumOf {it.params[1].toInt()})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import com.unciv.ui.utils.randomWeighted
|
||||
import kotlin.math.max
|
||||
import kotlin.random.Random
|
||||
|
||||
@Suppress("NON_EXHAUSTIVE_WHEN") // Many when uses in here are much clearer this way
|
||||
class QuestManager {
|
||||
|
||||
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) {
|
||||
val rewardInfluence = civInfo.gameInfo.ruleSet.quests[assignedQuest.questName]!!.influece
|
||||
val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee)
|
||||
@ -357,6 +358,7 @@ class QuestManager {
|
||||
|
||||
/** Returns the score for the [assignedQuest] */
|
||||
private fun getScoreForQuest(assignedQuest: AssignedQuest): Int {
|
||||
@Suppress("UNUSED_VARIABLE") // This is a work in progress
|
||||
val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee)
|
||||
return when (assignedQuest.questName) {
|
||||
// Waiting for contest quests
|
||||
|
@ -37,10 +37,10 @@ class ReligionManager {
|
||||
// founding a religion would break :(
|
||||
private var foundingCityId: String? = null
|
||||
// Only used for keeping track of the city a prophet was used when founding a religion
|
||||
|
||||
|
||||
private var shouldChoosePantheonBelief: Boolean = false
|
||||
|
||||
|
||||
|
||||
fun clone(): ReligionManager {
|
||||
val clone = ReligionManager()
|
||||
clone.foundingCityId = foundingCityId
|
||||
@ -74,7 +74,7 @@ class ReligionManager {
|
||||
|
||||
fun faithForPantheon(additionalCivs: Int = 0) =
|
||||
10 + (civInfo.gameInfo.civilizations.count { it.isMajorCiv() && it.religionManager.religion != null } + additionalCivs) * 5
|
||||
|
||||
|
||||
fun canFoundPantheon(): Boolean {
|
||||
if (!civInfo.gameInfo.hasReligionEnabled()) return false
|
||||
if (religionState != ReligionState.None) return false
|
||||
@ -102,17 +102,17 @@ class ReligionManager {
|
||||
city.religion.addPressure(belief.name, 200 * city.population.population)
|
||||
religionState = ReligionState.Pantheon
|
||||
}
|
||||
|
||||
|
||||
// https://www.reddit.com/r/civ/comments/2m82wu/can_anyone_detail_the_finer_points_of_great/
|
||||
// Game files (globaldefines.xml)
|
||||
fun faithForNextGreatProphet(): Int {
|
||||
var faithCost =
|
||||
(200 + 100 * greatProphetsEarned * (greatProphetsEarned + 1) / 2f) *
|
||||
civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
||||
|
||||
|
||||
for (unique in civInfo.getMatchingUniques("[]% Faith cost of generating Great Prophet equivalents"))
|
||||
faithCost *= unique.params[0].toPercent()
|
||||
|
||||
|
||||
return faithCost.toInt()
|
||||
}
|
||||
|
||||
@ -141,16 +141,16 @@ class ReligionManager {
|
||||
|
||||
fun mayFoundReligionAtAll(prophet: MapUnit): Boolean {
|
||||
if (religionState >= ReligionState.Religion) return false // Already created a major religion
|
||||
|
||||
|
||||
// Already used its power for other things
|
||||
if (prophet.abilityUsesLeft.any { it.value != prophet.maxAbilityUses[it.key] }) return false
|
||||
|
||||
|
||||
if (!civInfo.isMajorCiv()) return false // Only major civs may use religion
|
||||
|
||||
|
||||
val foundedReligionsCount = civInfo.gameInfo.civilizations.count {
|
||||
it.religionManager.religion != null && it.religionManager.religionState >= ReligionState.Religion
|
||||
}
|
||||
|
||||
|
||||
if (foundedReligionsCount >= civInfo.gameInfo.civilizations.count { it.isMajorCiv() } / 2 + 1)
|
||||
return false // Too bad, too many religions have already been founded
|
||||
|
||||
@ -161,11 +161,11 @@ class ReligionManager {
|
||||
it.type == BeliefType.Follower
|
||||
&& civInfo.gameInfo.religions.values.none { religion -> it in religion.getBeliefs(BeliefType.Follower) }
|
||||
}) return false // Mod maker did not provide enough follower beliefs
|
||||
|
||||
|
||||
// Shortcut as each religion will always have exactly one founder belief
|
||||
if (foundedReligionsCount >= civInfo.gameInfo.ruleSet.beliefs.values.count { it.type == BeliefType.Founder })
|
||||
return false // Mod maker did not provide enough founder beliefs
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@ -183,13 +183,13 @@ class ReligionManager {
|
||||
religionState = ReligionState.FoundingReligion
|
||||
civInfo.religionManager.foundingCityId = prophet.getTile().getCity()!!.id
|
||||
}
|
||||
|
||||
|
||||
fun getBeliefsToChooseAtFounding(): BeliefContainer {
|
||||
if (shouldChoosePantheonBelief)
|
||||
return BeliefContainer(pantheonBeliefCount = 1, founderBeliefCount = 1, followerBeliefCount = 1)
|
||||
return BeliefContainer(founderBeliefCount = 1, followerBeliefCount = 1)
|
||||
}
|
||||
|
||||
|
||||
fun chooseBeliefs(iconName: String?, religionName: String?, beliefs: List<Belief>) {
|
||||
if (religionState == ReligionState.FoundingReligion) {
|
||||
foundReligion(iconName!!, religionName!!, beliefs)
|
||||
@ -198,7 +198,7 @@ class ReligionManager {
|
||||
if (religionState == ReligionState.EnhancingReligion)
|
||||
enhanceReligion(beliefs)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun foundReligion(displayName: String, name: String, beliefs: List<Belief>) {
|
||||
val newReligion = Religion(name, civInfo.gameInfo, civInfo.civName)
|
||||
@ -207,7 +207,7 @@ class ReligionManager {
|
||||
newReligion.followerBeliefs.addAll(religion!!.followerBeliefs)
|
||||
newReligion.founderBeliefs.addAll(religion!!.founderBeliefs)
|
||||
}
|
||||
|
||||
|
||||
newReligion.followerBeliefs.addAll(
|
||||
beliefs
|
||||
.filter { it.type == BeliefType.Pantheon || it.type == BeliefType.Follower }
|
||||
@ -218,7 +218,7 @@ class ReligionManager {
|
||||
.filter { it.type == BeliefType.Founder }
|
||||
.map { it.name }
|
||||
)
|
||||
|
||||
|
||||
religion = newReligion
|
||||
civInfo.gameInfo.religions[name] = newReligion
|
||||
|
||||
@ -230,12 +230,12 @@ class ReligionManager {
|
||||
|
||||
foundingCityId = null
|
||||
shouldChoosePantheonBelief = false
|
||||
|
||||
|
||||
for (unit in civInfo.getCivUnits())
|
||||
if (unit.hasUnique("Religious Unit") && unit.hasUnique("Takes your religion over the one in their birth city"))
|
||||
unit.religion = newReligion.name
|
||||
}
|
||||
|
||||
|
||||
fun mayEnhanceReligionAtAll(prophet: MapUnit): Boolean {
|
||||
if (religion == null) return false // First found a pantheon
|
||||
if (religionState != ReligionState.Religion) return false // First found an actual religion
|
||||
@ -247,12 +247,12 @@ class ReligionManager {
|
||||
it.type == BeliefType.Follower
|
||||
&& civInfo.gameInfo.religions.values.none { religion -> religion.getBeliefs(BeliefType.Follower).contains(it) }
|
||||
}) return false // Mod maker did not provide enough follower beliefs
|
||||
|
||||
|
||||
if (civInfo.gameInfo.ruleSet.beliefs.values.none {
|
||||
it.type == BeliefType.Enhancer
|
||||
&& civInfo.gameInfo.religions.values.none { religion -> religion.getBeliefs(BeliefType.Enhancer).contains(it) }
|
||||
}) return false // Mod maker did not provide enough enhancer beliefs
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@ -270,24 +270,24 @@ class ReligionManager {
|
||||
fun getBeliefsToChooseAtEnhancing(): BeliefContainer {
|
||||
return BeliefContainer(followerBeliefCount = 1, enhancerBeliefCount = 1)
|
||||
}
|
||||
|
||||
|
||||
fun enhanceReligion(beliefs: List<Belief>) {
|
||||
religion!!.followerBeliefs.addAll(beliefs.filter { it.type == BeliefType.Follower}.map { it.name })
|
||||
religion!!.founderBeliefs.addAll(beliefs.filter { it.type == BeliefType.Enhancer}.map { it.name })
|
||||
religionState = ReligionState.EnhancedReligion
|
||||
}
|
||||
|
||||
|
||||
fun numberOfCitiesFollowingThisReligion(): Int {
|
||||
if (religion == null) return 0
|
||||
return civInfo.gameInfo.getCities()
|
||||
.count { it.religion.getMajorityReligion() == religion }
|
||||
}
|
||||
|
||||
|
||||
fun numberOfFollowersFollowingThisReligion(cityFilter: String): Int {
|
||||
if (religion == null) return 0
|
||||
return civInfo.gameInfo.getCities()
|
||||
.filter { it.matchesFilter(cityFilter, civInfo) }
|
||||
.sumBy { it.religion.getFollowersOf(religion!!.name)!! }
|
||||
.sumOf { it.religion.getFollowersOf(religion!!.name)!! }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ enum class RelationshipLevel(val color: Color) {
|
||||
Ally(Color.CHARTREUSE) // HSV(90,100,100)
|
||||
}
|
||||
|
||||
enum class DiplomacyFlags{
|
||||
enum class DiplomacyFlags {
|
||||
DeclinedLuxExchange,
|
||||
DeclinedPeace,
|
||||
DeclinedResearchAgreement,
|
||||
@ -46,7 +46,7 @@ enum class DiplomacyFlags{
|
||||
AngerFreeIntrusion
|
||||
}
|
||||
|
||||
enum class DiplomaticModifiers{
|
||||
enum class DiplomaticModifiers {
|
||||
DeclaredWarOnUs,
|
||||
WarMongerer,
|
||||
CapturedOurCities,
|
||||
@ -199,11 +199,11 @@ class DiplomacyManager() {
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun addInfluence(amount: Float) {
|
||||
setInfluence(influence + amount)
|
||||
}
|
||||
|
||||
|
||||
fun setInfluence(amount: Float) {
|
||||
influence = max(amount, MINIMUM_INFLUENCE)
|
||||
civInfo.updateAllyCivForCityState()
|
||||
@ -743,6 +743,7 @@ class DiplomacyManager() {
|
||||
for (thirdCiv in getCommonKnownCivs()
|
||||
.filter { it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }) {
|
||||
val otherCivRelationshipWithThirdCiv = otherCiv().getDiplomacyManager(thirdCiv).relationshipLevel()
|
||||
@Suppress("NON_EXHAUSTIVE_WHEN") // Better readability
|
||||
when (otherCivRelationshipWithThirdCiv) {
|
||||
RelationshipLevel.Unforgivable -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -15f)
|
||||
RelationshipLevel.Enemy -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -5f)
|
||||
@ -765,6 +766,7 @@ class DiplomacyManager() {
|
||||
thirdCiv.addNotification("[${civInfo.civName}] has denounced [$otherCivName]!", civInfo.civName, NotificationIcon.Diplomacy, otherCivName)
|
||||
val thirdCivRelationshipWithOtherCiv = thirdCiv.getDiplomacyManager(otherCiv()).relationshipLevel()
|
||||
val thirdCivDiplomacyManager = thirdCiv.getDiplomacyManager(civInfo)
|
||||
@Suppress("NON_EXHAUSTIVE_WHEN") // Better readability
|
||||
when (thirdCivRelationshipWithOtherCiv) {
|
||||
RelationshipLevel.Unforgivable -> thirdCivDiplomacyManager.addModifier(DiplomaticModifiers.DenouncedOurEnemies, 15f)
|
||||
RelationshipLevel.Enemy -> thirdCivDiplomacyManager.addModifier(DiplomaticModifiers.DenouncedOurEnemies, 5f)
|
||||
|
Loading…
x
Reference in New Issue
Block a user