From 7936c87962339a07bb79961e5215a3b7d789ee4f Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:23:13 +0100 Subject: [PATCH] Linting --- core/src/com/unciv/logic/GameStarter.kt | 44 +++++++++++++------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/core/src/com/unciv/logic/GameStarter.kt b/core/src/com/unciv/logic/GameStarter.kt index 241e105dd9..1b8d9ebbf7 100644 --- a/core/src/com/unciv/logic/GameStarter.kt +++ b/core/src/com/unciv/logic/GameStarter.kt @@ -166,39 +166,41 @@ object GameStarter { } private fun addCivTechs(gameInfo: GameInfo, ruleset: Ruleset, gameSetupInfo: GameSetupInfo) { - for (civInfo in gameInfo.civilizations.filter { !it.isBarbarian() }) { + fun Civilization.addTechSilently(name: String) { + // check if the technology is in the ruleset and not already researched + if (!ruleset.technologies.containsKey(name)) return + if (tech.isResearched(name)) return + tech.addTechnology(name, false) + } - for(tech in ruleset.technologies.values.filter { it.hasUnique(UniqueType.StartingTech) }) - { - civInfo.tech.addTechnology(tech.name, false) - } + for (civInfo in gameInfo.civilizations) { + if (civInfo.isBarbarian()) continue + + for (tech in ruleset.technologies.values.filter { it.hasUnique(UniqueType.StartingTech) }) + civInfo.addTechSilently(tech.name) if (!civInfo.isHuman()) for (tech in gameInfo.getDifficulty().aiFreeTechs) - civInfo.tech.addTechnology(tech, false) + civInfo.addTechSilently(tech) // generic start with technology unique - for (unique in civInfo.getMatchingUniques(UniqueType.StartsWithTech)) { - // get the parameter from the unique - val techName = unique.params[0] - - // check if the technology is in the ruleset and not already researched - if (ruleset.technologies.containsKey(techName) && !civInfo.tech.isResearched(techName)) - civInfo.tech.addTechnology(techName, false) - } + for (unique in civInfo.getMatchingUniques(UniqueType.StartsWithTech)) + civInfo.addTechSilently(unique.params[0]) // add all techs to spectators if (civInfo.isSpectator()) for (tech in ruleset.technologies.values) - if (!civInfo.tech.isResearched(tech.name)) - civInfo.tech.addTechnology(tech.name, false) + civInfo.addTechSilently(tech.name) - for (tech in ruleset.technologies.values - .filter { ruleset.eras[it.era()]!!.eraNumber < ruleset.eras[gameSetupInfo.gameParameters.startingEra]!!.eraNumber }) - if (!civInfo.tech.isResearched(tech.name)) - civInfo.tech.addTechnology(tech.name, false) + // Add techs for advanced starting era + val startingEraNumber = ruleset.eras[gameSetupInfo.gameParameters.startingEra]!!.eraNumber + for (tech in ruleset.technologies.values) { + if (ruleset.eras[tech.era()]!!.eraNumber >= startingEraNumber) continue + civInfo.addTechSilently(tech.name) + } - civInfo.popupAlerts.clear() // Since adding technologies generates popups... + // Since adding technologies generates popups (addTechnology parameter showNotification only suppresses Notifications) + civInfo.popupAlerts.clear() } }