From 096e1c2bebb846059061b9fcd6a27e10f2620aa0 Mon Sep 17 00:00:00 2001 From: lyrjie Date: Sat, 8 Feb 2020 21:51:45 +0300 Subject: [PATCH] Tied the unit upkeep scaling to game speed (#1870) * Tied the unit upkeep scaling to game speed * Refactor: Modifier and TurnLimit are now fields * Turn limit will be derived from the GameSpeed.modifier and base game duration --- .../unciv/logic/civilization/CivInfoStats.kt | 5 ++-- .../logic/civilization/CivilizationInfo.kt | 2 +- .../logic/civilization/GoldenAgeManager.kt | 2 +- .../unciv/logic/civilization/PolicyManager.kt | 2 +- .../unciv/logic/civilization/TechManager.kt | 4 ++-- core/src/com/unciv/logic/map/MapUnit.kt | 2 +- .../com/unciv/logic/trade/TradeEvaluation.kt | 2 +- .../com/unciv/models/metadata/GameSpeed.kt | 23 ++++++++----------- core/src/com/unciv/models/ruleset/Building.kt | 2 +- .../models/ruleset/tile/TileImprovement.kt | 2 +- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 2 +- .../unciv/ui/worldscreen/unit/UnitActions.kt | 2 +- 12 files changed, 24 insertions(+), 26 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/CivInfoStats.kt b/core/src/com/unciv/logic/civilization/CivInfoStats.kt index 1c59b2a6c6..d4af9cc4e3 100644 --- a/core/src/com/unciv/logic/civilization/CivInfoStats.kt +++ b/core/src/com/unciv/logic/civilization/CivInfoStats.kt @@ -2,6 +2,7 @@ package com.unciv.logic.civilization import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.map.RoadStatus +import com.unciv.models.metadata.BASE_GAME_DURATION_TURNS import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.stats.Stat import com.unciv.models.stats.StatMap @@ -30,8 +31,8 @@ class CivInfoStats(val civInfo: CivilizationInfo){ numberOfUnitsToPayFor -= 0.25f * numberOfUnitsWithDiscount } - - val gameProgress = civInfo.gameInfo.turns/400f // as game progresses Maintenance cost rises + val turnLimit = BASE_GAME_DURATION_TURNS * civInfo.gameInfo.gameParameters.gameSpeed.modifier + val gameProgress = civInfo.gameInfo.turns / turnLimit // as game progresses Maintenance cost rises var cost = baseUnitCost*numberOfUnitsToPayFor*(1+gameProgress) cost = cost.pow(1+gameProgress/3) // Why 3? To spread 1 to 1.33 if(!civInfo.isPlayerCivilization()) diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 15912a088d..c038f7ea65 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -513,7 +513,7 @@ class CivilizationInfo { TechEra.Information, TechEra.Future -> 400 else -> 0 } - return (basicGoldCostOfSignResearchAgreement * gameInfo.gameParameters.gameSpeed.getModifier()).toInt() + return (basicGoldCostOfSignResearchAgreement * gameInfo.gameParameters.gameSpeed.modifier).toInt() } fun giftMilitaryUnitTo(otherCiv: CivilizationInfo) { diff --git a/core/src/com/unciv/logic/civilization/GoldenAgeManager.kt b/core/src/com/unciv/logic/civilization/GoldenAgeManager.kt index cc674a70f6..37cf7076b9 100644 --- a/core/src/com/unciv/logic/civilization/GoldenAgeManager.kt +++ b/core/src/com/unciv/logic/civilization/GoldenAgeManager.kt @@ -30,7 +30,7 @@ class GoldenAgeManager{ if(civInfo.nation.unique=="Golden Ages last 50% longer. During a Golden Age, units receive +1 Movement and +10% Strength") turnsToGoldenAge*=1.5 if (civInfo.policies.isAdopted("Freedom Complete")) turnsToGoldenAge *= 1.5 - turnsToGoldenAge *= civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + turnsToGoldenAge *= civInfo.gameInfo.gameParameters.gameSpeed.modifier turnsLeftForCurrentGoldenAge += turnsToGoldenAge.toInt() civInfo.addNotification("You have entered a golden age!", null, Color.GOLD) civInfo.popupAlerts.add(PopupAlert(AlertType.GoldenAge,"")) diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index 6562b713dd..d4bfadf076 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -55,7 +55,7 @@ class PolicyManager { policyCultureCost *= 0.9 if (civInfo.isPlayerCivilization()) policyCultureCost *= civInfo.getDifficulty().policyCostModifier - policyCultureCost *= civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + policyCultureCost *= civInfo.gameInfo.gameParameters.gameSpeed.modifier val cost: Int = (policyCultureCost * (1 + cityModifier)).roundToInt() return cost - (cost % 5) } diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index 431e65e044..f1df560346 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -57,7 +57,7 @@ class TechManager { var techCost = getRuleset().technologies[techName]!!.cost.toFloat() if (civInfo.isPlayerCivilization()) techCost *= civInfo.getDifficulty().researchCostModifier - techCost *= civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + techCost *= civInfo.gameInfo.gameParameters.gameSpeed.modifier val techsResearchedKnownCivs = civInfo.getKnownCivs().count { it.isMajorCiv() && it.tech.isResearched(techName) } val undefeatedCivs = UncivGame.Current.gameInfo.civilizations.count { it.isMajorCiv() && !it.isDefeated() } // https://forums.civfanatics.com/threads/the-mechanics-of-overflow-inflation.517970/ @@ -127,7 +127,7 @@ class TechManager { fun getScienceFromGreatScientist(): Int { // https://civilization.fandom.com/wiki/Great_Scientist_(Civ5) - return (scienceOfLast8Turns.sum() * civInfo.gameInfo.gameParameters.gameSpeed.getModifier()).toInt() + return (scienceOfLast8Turns.sum() * civInfo.gameInfo.gameParameters.gameSpeed.modifier).toInt() } fun addCurrentScienceToScienceOfLast8Turns() { diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 56220833ab..585fc09db4 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -507,7 +507,7 @@ class MapUnit { private fun clearEncampment(tile: TileInfo) { tile.improvement = null - var goldGained = civInfo.getDifficulty().clearBarbarianCampReward * civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + var goldGained = civInfo.getDifficulty().clearBarbarianCampReward * civInfo.gameInfo.gameParameters.gameSpeed.modifier if (civInfo.nation.unique == "Receive triple Gold from Barbarian encampments and pillaging Cities. Embarked units can defend themselves.") goldGained *= 3f diff --git a/core/src/com/unciv/logic/trade/TradeEvaluation.kt b/core/src/com/unciv/logic/trade/TradeEvaluation.kt index de7dc2856b..4e95605d31 100644 --- a/core/src/com/unciv/logic/trade/TradeEvaluation.kt +++ b/core/src/com/unciv/logic/trade/TradeEvaluation.kt @@ -121,7 +121,7 @@ class TradeEvaluation{ TradeType.Technology -> return (sqrt(civInfo.gameInfo.ruleSet.technologies[offer.name]!!.cost.toDouble()) - * civInfo.gameInfo.gameParameters.gameSpeed.getModifier()).toInt()*20 + * civInfo.gameInfo.gameParameters.gameSpeed.modifier).toInt()*20 TradeType.Introduction -> return 250 TradeType.WarDeclaration -> { val civToDeclareWarOn = civInfo.gameInfo.getCivilization(offer.name) diff --git a/core/src/com/unciv/models/metadata/GameSpeed.kt b/core/src/com/unciv/models/metadata/GameSpeed.kt index c0c594787b..34ad815f67 100644 --- a/core/src/com/unciv/models/metadata/GameSpeed.kt +++ b/core/src/com/unciv/models/metadata/GameSpeed.kt @@ -1,17 +1,14 @@ package com.unciv.models.metadata -enum class GameSpeed{ - Quick, - Standard, - Epic, - Marathon; +const val BASE_GAME_DURATION_TURNS = 500f - fun getModifier(): Float { - when(this) { - Quick -> return 0.67f - Standard -> return 1f - Epic -> return 1.5f - Marathon -> return 3f - } - } +/** Game speed + * + * @param modifier cost modifier + * */ +enum class GameSpeed(val modifier: Float) { + Quick(0.67f), + Standard(1f), + Epic(1.5f), + Marathon(3f); } \ No newline at end of file diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index 58fe4f4a30..5739c2125a 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -205,7 +205,7 @@ class Building : NamedStats(), IConstruction{ productionCost *= civInfo.gameInfo.getDifficulty().aiBuildingCostModifier } } - productionCost *= civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + productionCost *= civInfo.gameInfo.gameParameters.gameSpeed.modifier return productionCost.toInt() } diff --git a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt index 5afe9bcf3e..ac6e0d72f0 100644 --- a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt +++ b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt @@ -22,7 +22,7 @@ class TileImprovement : NamedStats() { fun getTurnsToBuild(civInfo: CivilizationInfo): Int { - var realTurnsToBuild = turnsToBuild.toFloat() * civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + var realTurnsToBuild = turnsToBuild.toFloat() * civInfo.gameInfo.gameParameters.gameSpeed.modifier if (civInfo.containsBuildingUnique("Worker construction increased 25%")) realTurnsToBuild *= 0.75f if (civInfo.policies.isAdopted("Citizenship")) diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index 3ff76b9a71..c72155c24b 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -97,7 +97,7 @@ class BaseUnit : INamed, IConstruction { productionCost *= civInfo.getDifficulty().unitCostModifier else productionCost *= civInfo.gameInfo.getDifficulty().aiUnitCostModifier - productionCost *= civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + productionCost *= civInfo.gameInfo.gameParameters.gameSpeed.modifier return productionCost.toInt() } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 4674603bbd..96f7519382 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -282,7 +282,7 @@ class UnitActions { uncivSound = UncivSound.Chimes, action = { // http://civilization.wikia.com/wiki/Great_Merchant_(Civ5) - var goldEarned = (350 + 50 * unit.civInfo.getEra().ordinal) * unit.civInfo.gameInfo.gameParameters.gameSpeed.getModifier() + var goldEarned = (350 + 50 * unit.civInfo.getEra().ordinal) * unit.civInfo.gameInfo.gameParameters.gameSpeed.modifier if (unit.civInfo.policies.isAdopted("Commerce Complete")) goldEarned *= 2 unit.civInfo.gold += goldEarned.toInt()