From cdfdbb40b85b2eb6f6a3ab0d6f17767af1fb48d9 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 3 May 2019 16:59:46 +0300 Subject: [PATCH] More massive performance boosts --- android/build.gradle | 2 +- core/src/com/unciv/Constants.kt | 10 +++++++ core/src/com/unciv/GameStarter.kt | 2 +- .../com/unciv/logic/automation/Automation.kt | 5 ++-- .../logic/automation/NextTurnAutomation.kt | 7 +++-- .../unciv/logic/automation/UnitAutomation.kt | 7 +++-- core/src/com/unciv/logic/battle/Battle.kt | 3 +- .../com/unciv/logic/city/CityConstructions.kt | 8 ++--- core/src/com/unciv/logic/city/CityInfo.kt | 5 ++-- core/src/com/unciv/logic/city/CityStats.kt | 3 +- .../logic/civilization/CivilizationInfo.kt | 3 +- .../unciv/logic/civilization/PolicyManager.kt | 5 ++-- .../unciv/logic/civilization/TechManager.kt | 4 ++- core/src/com/unciv/logic/map/BFS.kt | 5 ++-- core/src/com/unciv/logic/map/MapUnit.kt | 17 ++++++----- .../com/unciv/logic/map/RandomMapGenerator.kt | 29 ++++++++++--------- core/src/com/unciv/logic/map/TileInfo.kt | 9 ++++-- core/src/com/unciv/logic/map/TileMap.kt | 1 - .../unciv/logic/map/UnitMovementAlgorithms.kt | 2 +- core/src/com/unciv/models/Counter.kt | 1 + .../com/unciv/models/gamebasics/Building.kt | 5 ++-- .../unciv/models/gamebasics/unit/BaseUnit.kt | 3 +- .../com/unciv/ui/worldscreen/WorldScreen.kt | 3 +- .../ui/worldscreen/unit/UnitActionsTable.kt | 5 ++-- 24 files changed, 84 insertions(+), 60 deletions(-) create mode 100644 core/src/com/unciv/Constants.kt diff --git a/android/build.gradle b/android/build.gradle index aeddacc770..1cd7933e4f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -22,7 +22,7 @@ android { minSdkVersion 14 targetSdkVersion 28 versionCode 236 - versionName "2.16.0" + versionName "2.16.0-patch1" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt new file mode 100644 index 0000000000..3da3929cc1 --- /dev/null +++ b/core/src/com/unciv/Constants.kt @@ -0,0 +1,10 @@ +package com.unciv + +class Constants{ + companion object { + const val worker="Worker" + const val settler="Settler" + const val ocean="Ocean" + const val mountain="Mountain" + } +} \ No newline at end of file diff --git a/core/src/com/unciv/GameStarter.kt b/core/src/com/unciv/GameStarter.kt index d0ff73964a..bcb68af8f0 100644 --- a/core/src/com/unciv/GameStarter.kt +++ b/core/src/com/unciv/GameStarter.kt @@ -74,7 +74,7 @@ class GameStarter{ for (civ in gameInfo.civilizations.filter { !it.isBarbarianCivilization() }) { val startingLocation = startingLocations.pop()!! - civ.placeUnitNearTile(startingLocation.position, "Settler") + civ.placeUnitNearTile(startingLocation.position, Constants.settler) civ.placeUnitNearTile(startingLocation.position, "Warrior") civ.placeUnitNearTile(startingLocation.position, "Scout") } diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index ada8c055d4..1189724771 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -1,6 +1,7 @@ package com.unciv.logic.automation import com.badlogic.gdx.graphics.Color +import com.unciv.Constants import com.unciv.logic.battle.CityCombatant import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.CityInfo @@ -76,7 +77,7 @@ class Automation { val civUnits = cityInfo.civInfo.getCivUnits() val militaryUnits = civUnits.filter { !it.type.isCivilian()}.size - val workers = civUnits.filter { it.name == CityConstructions.Worker }.size.toFloat() + val workers = civUnits.filter { it.name == Constants.worker }.size.toFloat() val cities = cityInfo.civInfo.cities.size val canBuildWorkboat = cityInfo.cityConstructions.getConstructableUnits().map { it.name }.contains("Work Boats") && !cityInfo.getTiles().any { it.civilianUnit?.name == "Work Boats" } @@ -159,7 +160,7 @@ class Automation { //worker if (workers < cities * 0.6f) { - relativeCostEffectiveness.add(ConstructionChoice(CityConstructions.Worker,cities.toFloat()/(workers+0.1f))) + relativeCostEffectiveness.add(ConstructionChoice(Constants.worker,cities.toFloat()/(workers+0.1f))) } //Work boat diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index 63b5d101b5..6edd092783 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -8,6 +8,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomaticStatus import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.map.MapUnit import com.unciv.logic.trade.* +import com.unciv.Constants import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tech.Technology import com.unciv.models.gamebasics.tr @@ -316,12 +317,12 @@ class NextTurnAutomation{ if(civInfo.isAtWar()) return // don't train settlers when you could be training troops. if (civInfo.cities.any() && civInfo.happiness > civInfo.cities.size + 5 - && civInfo.getCivUnits().none { it.name == "Settler" } - && civInfo.cities.none { it.cityConstructions.currentConstruction == "Settler" }) { + && civInfo.getCivUnits().none { it.name == Constants.settler } + && civInfo.cities.none { it.cityConstructions.currentConstruction == Constants.settler }) { val bestCity = civInfo.cities.maxBy { it.cityStats.currentCityStats.production }!! if (bestCity.cityConstructions.builtBuildings.size > 1) // 2 buildings or more, otherwise focus on self first - bestCity.cityConstructions.currentConstruction = "Settler" + bestCity.cityConstructions.currentConstruction = Constants.settler } } diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 571657ac74..3f7f3226a7 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -1,5 +1,6 @@ package com.unciv.logic.automation +import com.unciv.Constants import com.unciv.UnCivGame import com.unciv.logic.battle.* import com.unciv.logic.city.CityInfo @@ -15,11 +16,11 @@ class UnitAutomation{ fun automateUnitMoves(unit: MapUnit) { - if (unit.name == "Settler") { + if (unit.name == Constants.settler) { return SpecificUnitAutomation().automateSettlerActions(unit) } - if (unit.name == "Worker") { + if (unit.name == Constants.worker) { return WorkerAutomation(unit).automateWorkerAction() } @@ -201,7 +202,7 @@ class UnitAutomation{ private fun tryAccompanySettlerOrGreatPerson(unit: MapUnit): Boolean { val settlerOrGreatPersonToAccompany = unit.civInfo.getCivUnits() .firstOrNull { val tile = it.currentTile - (it.name=="Settler" || it.name.startsWith("Great") && it.type.isCivilian()) + (it.name== Constants.settler || it.name.startsWith("Great") && it.type.isCivilian()) && tile.militaryUnit==null && unit.canMoveTo(tile) && unit.movementAlgs().canReach(tile) } if(settlerOrGreatPersonToAccompany==null) return false unit.movementAlgs().headTowards(settlerOrGreatPersonToAccompany.currentTile) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 267b3258c7..ea2457c245 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -8,6 +8,7 @@ import com.unciv.logic.civilization.AlertType import com.unciv.logic.civilization.PopupAlert import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers import com.unciv.logic.map.TileInfo +import com.unciv.Constants import com.unciv.models.gamebasics.unit.UnitType import java.util.* import kotlin.math.max @@ -238,7 +239,7 @@ class Battle(val gameInfo:GameInfo) { defender.takeDamage(100) return } // barbarians don't capture civilians! - if (attacker.getCivInfo().isCityState() && defender.getName() == "Settler") { + if (attacker.getCivInfo().isCityState() && defender.getName() == Constants.settler) { defender.takeDamage(100) return } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index b54414a172..a641d914e0 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -2,6 +2,7 @@ package com.unciv.logic.city import com.badlogic.gdx.graphics.Color import com.unciv.logic.automation.Automation +import com.unciv.Constants import com.unciv.models.gamebasics.Building import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tr @@ -125,7 +126,7 @@ class CityConstructions { cityInfo.cityStats.update() var production = Math.round(cityStatsForConstruction.production) - if (constructionName == Settler) production += cityStatsForConstruction.food.toInt() + if (constructionName == Constants.settler) production += cityStatsForConstruction.food.toInt() return Math.ceil((workLeft / production.toDouble())).toInt() } @@ -222,9 +223,4 @@ class CityConstructions { } //endregion - companion object { - internal const val Worker = "Worker" - internal const val Settler = "Settler" - } - } // for json parsing, we need to have a default constructor \ No newline at end of file diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 09d4fe5baa..2a24a31b94 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -6,6 +6,7 @@ import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileMap +import com.unciv.Constants import com.unciv.models.Counter import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.ResourceType @@ -62,7 +63,7 @@ class CityInfo { if (civInfo.policies.isAdopted("Legalism") && civInfo.cities.size <= 4) cityConstructions.addCultureBuilding() if (civInfo.cities.size == 1) { cityConstructions.addBuilding("Palace") - cityConstructions.currentConstruction = "Worker" // Default for first city only! + cityConstructions.currentConstruction = Constants.worker // Default for first city only! } expansion.reset() @@ -205,7 +206,7 @@ class CityInfo { fun endTurn() { val stats = cityStats.currentCityStats - if (cityConstructions.currentConstruction == CityConstructions.Settler && stats.food > 0) { + if (cityConstructions.currentConstruction == Constants.settler && stats.food > 0) { stats.production += stats.food stats.food = 0f } diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index 6ecef72323..5171e93d78 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -3,6 +3,7 @@ package com.unciv.logic.city import com.unciv.UnCivGame import com.unciv.logic.map.BFS import com.unciv.logic.map.RoadStatus +import com.unciv.Constants import com.unciv.models.gamebasics.Building import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.unit.BaseUnit @@ -269,7 +270,7 @@ class CityStats { val currentConstruction = cityConstructions.getCurrentConstruction() if (policies.contains("Collective Rule") && cityInfo.isCapital() - && currentConstruction.name == "Settler") + && currentConstruction.name == Constants.settler) stats.production += 50f if (policies.contains("Republic") && currentConstruction is Building) stats.production += 5f diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 660f005930..423bf38e11 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -3,6 +3,7 @@ package com.unciv.logic.civilization import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.math.Vector2 +import com.unciv.Constants import com.unciv.UnCivGame import com.unciv.logic.GameInfo import com.unciv.logic.city.CityInfo @@ -331,7 +332,7 @@ class CivilizationInfo { override fun toString(): String {return civName} // for debug - fun isDefeated()= cities.isEmpty() && (citiesCreated > 0 || !getCivUnits().any{it.name=="Settler"}) + fun isDefeated()= cities.isEmpty() && (citiesCreated > 0 || !getCivUnits().any{it.name== Constants.settler}) fun getEra(): TechEra { val maxEraOfTech = tech.researchedTechnologies diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index 308147844d..a9b2ae9295 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -1,5 +1,6 @@ package com.unciv.logic.civilization +import com.unciv.Constants import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.Policy @@ -64,8 +65,8 @@ class PolicyManager { val hasCapital = civInfo.cities.any{it.isCapital()} when (policy.name) { - "Collective Rule" -> if(hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, "Settler") - "Citizenship" -> if(hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, "Worker") + "Collective Rule" -> if(hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.settler) + "Citizenship" -> if(hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.worker) "Representation", "Reformation" -> civInfo.goldenAges.enterGoldenAge() "Scientific Revolution" -> civInfo.tech.freeTechs += 2 "Legalism" -> diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index 85fdb663a6..3b7e10e1e8 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -19,6 +19,8 @@ class TechManager { @Transient var unitsCanEmbark=false @Transient var embarkedUnitsCanEnterOcean=false + // UnitMovementAlgorithms.getMovementCostBetweenAdjacentTiles is a close second =) + @Transient var movementSpeedOnRoadsImproved=false var freeTechs = 0 var techsResearched = HashSet() @@ -188,6 +190,6 @@ class TechManager { fun updateTransientBooleans(){ if(researchedTechUniques.contains("Enables embarkation for land units")) unitsCanEmbark=true if(researchedTechUniques.contains("Enables embarked units to enter ocean tiles")) embarkedUnitsCanEnterOcean=true - + if(researchedTechUniques.contains("Improves movement speed on roads")) movementSpeedOnRoadsImproved = true } } \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/BFS.kt b/core/src/com/unciv/logic/map/BFS.kt index da1fb70102..c3b2309776 100644 --- a/core/src/com/unciv/logic/map/BFS.kt +++ b/core/src/com/unciv/logic/map/BFS.kt @@ -28,9 +28,8 @@ class BFS(val startingPoint: TileInfo, val predicate : (TileInfo) -> Boolean){ for(tileInfo in tilesToCheck){ val fitNeighbors = tileInfo.neighbors.asSequence() .filter(predicate) - .filter{!tilesReached.containsKey(it)}.toList() - fitNeighbors.forEach { tilesReached[it] = tileInfo } - newTilesToCheck.addAll(fitNeighbors) + .filter{!tilesReached.containsKey(it)} + fitNeighbors.forEach { tilesReached[it] = tileInfo; newTilesToCheck.add(it) } } tilesToCheck = newTilesToCheck } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index f95b33055d..922adfb61e 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -2,6 +2,7 @@ package com.unciv.logic.map import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.math.Vector2 +import com.unciv.Constants import com.unciv.logic.automation.UnitAutomation import com.unciv.logic.automation.WorkerAutomation import com.unciv.logic.civilization.CivilizationInfo @@ -136,14 +137,13 @@ class MapUnit { if(tile.isLand && type.isWaterUnit() && !tile.isCityCenter()) return false - val isOcean = tile.baseTerrain == "Ocean" if(tile.isWater && type.isLandUnit()){ if(!civInfo.tech.unitsCanEmbark) return false - if(isOcean && !civInfo.tech.embarkedUnitsCanEnterOcean) + if(tile.isOcean && !civInfo.tech.embarkedUnitsCanEnterOcean) return false } - if(isOcean && baseUnit.uniques.contains("Cannot enter ocean tiles")) return false - if(isOcean && baseUnit.uniques.contains("Cannot enter ocean tiles until Astronomy") + if(tile.isOcean && baseUnit.uniques.contains("Cannot enter ocean tiles")) return false + if(tile.isOcean && baseUnit.uniques.contains("Cannot enter ocean tiles until Astronomy") && !civInfo.tech.isResearched("Astronomy")) return false @@ -174,7 +174,7 @@ class MapUnit { fun isIdle(): Boolean { if (currentMovement == 0f) return false - if (name == "Worker" && getTile().improvementInProgress != null) return false + if (name == Constants.worker && getTile().improvementInProgress != null) return false if (hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") return false if (isFortified()) return false if (action=="Sleep") return false @@ -271,6 +271,7 @@ class MapUnit { } fun doPreTurnAction() { + if(action==null) return val currentTile = getTile() if (currentMovement == 0f) return // We've already done stuff this turn, and can't do any more stuff @@ -300,7 +301,7 @@ class MapUnit { } private fun doPostTurnAction() { - if (name == "Worker" && getTile().improvementInProgress != null) workOnImprovement() + if (name == Constants.worker && getTile().improvementInProgress != null) workOnImprovement() if(hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") workOnImprovement() if(currentMovement== getMaxMovement().toFloat() && isFortified()){ @@ -437,8 +438,8 @@ class MapUnit { } actions.add { - val chosenUnit = listOf("Settler","Worker","Warrior").random() - if (!civInfo.isCityState() || chosenUnit != "Settler") { //City states don't get settler from ruins + val chosenUnit = listOf(Constants.settler, Constants.worker,"Warrior").random() + if (!civInfo.isCityState() || chosenUnit != Constants.settler) { //City states don't get settler from ruins civInfo.placeUnitNearTile(currentTile.position, chosenUnit) civInfo.addNotification("A [$chosenUnit] has joined us!", currentTile.position, Color.BROWN) } diff --git a/core/src/com/unciv/logic/map/RandomMapGenerator.kt b/core/src/com/unciv/logic/map/RandomMapGenerator.kt index aeeeb05c96..3d0ca9b0c7 100644 --- a/core/src/com/unciv/logic/map/RandomMapGenerator.kt +++ b/core/src/com/unciv/logic/map/RandomMapGenerator.kt @@ -1,6 +1,8 @@ package com.unciv.logic.map import com.badlogic.gdx.math.Vector2 +import com.unciv.Constants.Companion.mountain +import com.unciv.Constants.Companion.ocean import com.unciv.logic.HexMath import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.ResourceType @@ -120,7 +122,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() { val tile=TileInfo() tile.position=vector if (type == TerrainType.Land) tile.baseTerrain = "" - else tile.baseTerrain = "Ocean" + else tile.baseTerrain = ocean return tile } @@ -157,7 +159,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() { } //Coasts - for (tile in map.values.filter { it.baseTerrain == "Ocean" }) { + for (tile in map.values.filter { it.baseTerrain == ocean }) { if (HexMath().getVectorsInDistance(tile.position,2).any { hasLandTile(map,it) }) { tile.baseTerrain = "Coast" tile.setTransients() @@ -167,7 +169,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() { override fun randomizeTile(tileInfo: TileInfo, map: HashMap){ if(tileInfo.getBaseTerrain().type==TerrainType.Land && Math.random()<0.05f){ - tileInfo.baseTerrain = "Mountain" + tileInfo.baseTerrain = mountain tileInfo.setTransients() } addRandomTerrainFeature(tileInfo) @@ -183,7 +185,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() { val areas = ArrayList() val terrains = GameBasics.Terrains.values.filter { it.type === TerrainType.Land && it.name != "Lakes" - && it.name != "Mountain"} + && it.name != mountain} while(map.values.any { it.baseTerrain=="" }) // the world could be split into lots off tiny islands, and every island deserves land types { @@ -193,7 +195,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() { for (i in 0 until numberOfSeeds) { var terrain = if (Math.random() > waterPercent) terrains.random().name - else "Ocean" + else ocean val tile = emptyTiles.random() //change grassland to desert or tundra based on y @@ -201,7 +203,7 @@ class CelluarAutomataRandomMapGenerator(): SeedRandomMapGenerator() { if (terrain == "Grassland" || terrain == "Tundra") terrain = "Desert" } else if (abs(getLatitude(tile.position)) > maxLatitude * 0.7) { - if (terrain == "Grassland" || terrain == "Plains" || terrain == "Desert" || terrain == "Ocean") { + if (terrain == "Grassland" || terrain == "Plains" || terrain == "Desert" || terrain == ocean) { terrain = "Tundra" } } else { @@ -260,9 +262,9 @@ class PerlinNoiseRandomMapGenerator:SeedRandomMapGenerator(){ + Perlin.noise(vector.x*ratio*2,vector.y*ratio*2,mapRandomSeed)/2 + Perlin.noise(vector.x*ratio*4,vector.y*ratio*4,mapRandomSeed)/4 when { - height>0.8 -> tile.baseTerrain = "Mountain" + height>0.8 -> tile.baseTerrain = mountain height>0 -> tile.baseTerrain = "" // we'll leave this to the area division - else -> tile.baseTerrain = "Ocean" + else -> tile.baseTerrain = ocean } return tile } @@ -281,7 +283,6 @@ class AlexanderRandomMapGenerator:RandomMapGenerator(){ val sparkList = ArrayList() val grassland = "Grassland" - val ocean = "Ocean" for(i in 0..distance*distance/6){ val location = map.filter { it.value==null }.map { it.key }.random() map[location] = TileInfo().apply { baseTerrain= grassland} @@ -362,7 +363,7 @@ open class SeedRandomMapGenerator : RandomMapGenerator() { open fun divideIntoAreas(averageTilesPerArea: Int, waterPercent: Float, map: HashMap) { val areas = ArrayList() - val terrains = GameBasics.Terrains.values.filter { it.type === TerrainType.Land && it.name != "Lakes" && it.name != "Mountain" } + val terrains = GameBasics.Terrains.values.filter { it.type === TerrainType.Land && it.name != "Lakes" && it.name != mountain } while(map.values.any { it.baseTerrain=="" }) // the world could be split into lots off tiny islands, and every island deserves land types { @@ -371,7 +372,7 @@ open class SeedRandomMapGenerator : RandomMapGenerator() { for (i in 0 until numberOfSeeds) { val terrain = if (Math.random() > waterPercent) terrains.random().name - else "Ocean" + else ocean val area = Area(terrain) val tile = emptyTiles.random() emptyTiles -= tile @@ -384,7 +385,7 @@ open class SeedRandomMapGenerator : RandomMapGenerator() { } - for (area in areas.filter { it.terrain == "Ocean" && it.locations.size <= 10 }) { + for (area in areas.filter { it.terrain == ocean && it.locations.size <= 10 }) { // areas with 10 or less tiles are lakes. for (location in area.locations) map[location]!!.baseTerrain = "Lakes" @@ -496,7 +497,7 @@ open class RandomMapGenerator { } open fun setWaterTiles(map: HashMap) { - for (tile in map.values.filter { it.baseTerrain == "Ocean" }) { + for (tile in map.values.filter { it.baseTerrain == ocean }) { if (HexMath().getVectorsInDistance(tile.position,2).any { hasLandTile(map,it) }) { tile.baseTerrain = "Coast" tile.setTransients() @@ -506,7 +507,7 @@ open class RandomMapGenerator { open fun randomizeTile(tileInfo: TileInfo, map: HashMap){ if(tileInfo.getBaseTerrain().type==TerrainType.Land && Math.random()<0.05f){ - tileInfo.baseTerrain = "Mountain" + tileInfo.baseTerrain = mountain tileInfo.setTransients() } if(tileInfo.getBaseTerrain().type==TerrainType.Land && Math.random()<0.05f diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index d030930406..d3c9320e97 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -1,6 +1,7 @@ package com.unciv.logic.map import com.badlogic.gdx.math.Vector2 +import com.unciv.Constants import com.unciv.UnCivGame import com.unciv.logic.city.CityInfo import com.unciv.logic.civilization.CivilizationInfo @@ -18,6 +19,7 @@ open class TileInfo { // These are for performance - checked with every tile movement and "canEnter" check, which makes them performance-critical @Transient var isLand = false @Transient var isWater = false + @Transient var isOcean = false var militaryUnit:MapUnit?=null var civilianUnit:MapUnit?=null @@ -91,9 +93,9 @@ open class TileInfo { } fun getHeight(): Int { - if (baseTerrain=="Mountain") return 4 + if (baseTerrain==Constants.mountain) return 4 if (baseTerrain == "Hill") return 2 - if (listOf("Forest", "Jungle").contains(terrainFeature)) return 1 + if (baseTerrain=="Forest" || baseTerrain=="Jungle") return 1 return 0 } @@ -121,7 +123,7 @@ open class TileInfo { fun getTileStats(city: CityInfo?, observingCiv: CivilizationInfo): Stats { var stats = getBaseTerrain().clone() - if((baseTerrain=="Ocean"||baseTerrain=="Coast") && city!=null + if((baseTerrain== Constants.ocean||baseTerrain=="Coast") && city!=null && city.getBuildingUniques().contains("+1 food from Ocean and Coast tiles")) stats.food += 1 @@ -282,6 +284,7 @@ open class TileInfo { baseTerrainObject = GameBasics.Terrains[baseTerrain]!! isWater = getBaseTerrain().type==TerrainType.Water isLand = getBaseTerrain().type==TerrainType.Land + isOcean = baseTerrain == Constants.ocean if(militaryUnit!=null) militaryUnit!!.currentTile = this if(civilianUnit!=null) civilianUnit!!.currentTile = this diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 4201994223..bbeb5231bc 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -70,7 +70,6 @@ class TileMap { fun getTilesAtDistance(origin: Vector2, distance: Int): List { return HexMath().getVectorsAtDistance(origin, distance).asSequence() .filter {contains(it)}.map { get(it) }.toList() - } fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit { diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index b4b72cc8b3..20b81f9e62 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -25,7 +25,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { if (from.roadStatus !== RoadStatus.None && to.roadStatus !== RoadStatus.None) //Road { - if (unit.civInfo.tech.getTechUniques().contains("Improves movement speed on roads")) return 1 / 3f + if (unit.civInfo.tech.movementSpeedOnRoadsImproved) return 1 / 3f else return 1 / 2f } if (unit.ignoresTerrainCost) return 1f diff --git a/core/src/com/unciv/models/Counter.kt b/core/src/com/unciv/models/Counter.kt index c4c6b20e80..5cd9473d4b 100644 --- a/core/src/com/unciv/models/Counter.kt +++ b/core/src/com/unciv/models/Counter.kt @@ -36,3 +36,4 @@ class Counter : LinkedHashMap() { return newCounter } } + diff --git a/core/src/com/unciv/models/gamebasics/Building.kt b/core/src/com/unciv/models/gamebasics/Building.kt index 8a36d368aa..31f4cad6ad 100644 --- a/core/src/com/unciv/models/gamebasics/Building.kt +++ b/core/src/com/unciv/models/gamebasics/Building.kt @@ -3,6 +3,7 @@ package com.unciv.models.gamebasics import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.IConstruction import com.unciv.logic.civilization.CivilizationInfo +import com.unciv.Constants import com.unciv.models.gamebasics.tech.Technology import com.unciv.models.stats.NamedStats import com.unciv.models.stats.* @@ -295,8 +296,8 @@ class Building : NamedStats(), IConstruction{ civInfo.addGreatPerson("Great Scientist", construction.cityInfo) } "Provides 2 free workers" in uniques -> { - civInfo.placeUnitNearTile(construction.cityInfo.location, "Worker") - civInfo.placeUnitNearTile(construction.cityInfo.location, "Worker") + civInfo.placeUnitNearTile(construction.cityInfo.location, Constants.worker) + civInfo.placeUnitNearTile(construction.cityInfo.location, Constants.worker) } "Free Social Policy" in uniques -> civInfo.policies.freePolicies++ "Free Great Person" in uniques -> { diff --git a/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt b/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt index c47e53d125..fd4b82ab08 100644 --- a/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt @@ -4,6 +4,7 @@ import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.IConstruction import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.map.MapUnit +import com.unciv.Constants import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.ICivilopedia import com.unciv.models.gamebasics.Translations @@ -131,7 +132,7 @@ class BaseUnit : INamed, IConstruction, ICivilopedia { if (uniqueTo!=null && uniqueTo!=civInfo.civName) return "Unique to $uniqueTo" if (GameBasics.Units.values.any { it.uniqueTo==civInfo.civName && it.replaces==name }) return "Our unique unit replaces this" if (requiredResource!=null && !civInfo.hasResource(requiredResource!!)) return "Requires $requiredResource" - if (name == "Settler" && civInfo.isCityState()) return "No settler for city state" + if (name == Constants.settler && civInfo.isCityState()) return "No settler for city state" return "" } diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 717d263742..9ce91cb399 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -10,6 +10,7 @@ import com.unciv.UnCivGame import com.unciv.logic.GameSaver import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.diplomacy.DiplomaticStatus +import com.unciv.Constants import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.models.gamebasics.tr @@ -137,7 +138,7 @@ class WorldScreen : CameraStageBaseScreen() { if(gameClone.getCurrentPlayerCivilization().getCivUnits().any { it.health<100 }) displayTutorials("InjuredUnits") - if(gameClone.getCurrentPlayerCivilization().getCivUnits().any { it.name=="Worker" }) + if(gameClone.getCurrentPlayerCivilization().getCivUnits().any { it.name== Constants.worker }) displayTutorials("WorkerTrained") updateTechButton(cloneCivilization) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt index eaae676f38..49e3dc80cc 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt @@ -7,6 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.unciv.UnCivGame import com.unciv.logic.map.MapUnit +import com.unciv.Constants import com.unciv.models.gamebasics.tr import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.WorldScreen @@ -25,10 +26,10 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table(){ "Stop movement"-> return ImageGetter.getStatIcon("Movement").apply { color= Color.RED } "Fortify" -> return ImageGetter.getImage("OtherIcons/Shield").apply { color= Color.BLACK } "Promote" -> return ImageGetter.getImage("OtherIcons/Star").apply { color= Color.GOLD } - "Construct improvement" -> return ImageGetter.getUnitIcon("Worker") + "Construct improvement" -> return ImageGetter.getUnitIcon(Constants.worker) "Automate" -> return ImageGetter.getUnitIcon("Great Engineer") "Stop automation" -> return ImageGetter.getImage("OtherIcons/Stop") - "Found city" -> return ImageGetter.getUnitIcon("Settler") + "Found city" -> return ImageGetter.getUnitIcon(Constants.settler) "Discover Technology" -> return ImageGetter.getUnitIcon("Great Scientist") "Construct Academy" -> return ImageGetter.getImprovementIcon("Academy") "Start Golden Age" -> return ImageGetter.getUnitIcon("Great Artist")