From 77d741040da7a1c75cdb1e51851812acd5484718 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 17 Jul 2020 15:47:49 +0300 Subject: [PATCH] Worker unique is now moddable to other units --- core/src/com/unciv/Constants.kt | 1 + core/src/com/unciv/MainMenuScreen.kt | 4 ++-- .../unciv/logic/automation/ConstructionAutomation.kt | 12 +++++++----- .../src/com/unciv/logic/automation/UnitAutomation.kt | 2 +- core/src/com/unciv/logic/battle/Battle.kt | 2 +- core/src/com/unciv/logic/map/MapUnit.kt | 6 +++--- core/src/com/unciv/ui/worldscreen/WorldScreen.kt | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt index f198f4ac80..03c629c3ba 100644 --- a/core/src/com/unciv/Constants.kt +++ b/core/src/com/unciv/Constants.kt @@ -2,6 +2,7 @@ package com.unciv object Constants { const val worker = "Worker" + const val workerUnique = "Can build improvements on tiles" const val settler = "Settler" const val greatGeneral = "Great General" diff --git a/core/src/com/unciv/MainMenuScreen.kt b/core/src/com/unciv/MainMenuScreen.kt index 4cda734b07..3a5f1772a1 100644 --- a/core/src/com/unciv/MainMenuScreen.kt +++ b/core/src/com/unciv/MainMenuScreen.kt @@ -76,7 +76,7 @@ class MainMenuScreen: CameraStageBaseScreen() { table.add(resumeTable).row() } - val quickstartTable = getTableBlock("Quickstart", "OtherIcons/Quickstart") { QuickstartNewGame() } + val quickstartTable = getTableBlock("Quickstart", "OtherIcons/Quickstart") { quickstartNewGame() } table.add(quickstartTable).row() val newGameButton = getTableBlock("Start new game", "OtherIcons/New") { @@ -181,7 +181,7 @@ class MainMenuScreen: CameraStageBaseScreen() { } } - private fun QuickstartNewGame() { + private fun quickstartNewGame() { val newGame = GameStarter.startNewGame(GameSetupInfo().apply { gameParameters.difficulty = "Chieftain" }) game.loadGame(newGame) } diff --git a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt index cf0ef2565b..ed36675f06 100644 --- a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt +++ b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt @@ -25,7 +25,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ val civUnits = civInfo.getCivUnits() val militaryUnits = civUnits.filter { !it.type.isCivilian()}.count() - val workers = civUnits.filter { it.name == Constants.worker }.count().toFloat() + val workers = civUnits.filter { it.hasUnique(Constants.workerUnique) }.count().toFloat() val cities = civInfo.cities.size val canBuildWorkboat = cityInfo.cityConstructions.getConstructableUnits().map { it.name }.contains("Work Boats") && !cityInfo.getTiles().any { it.civilianUnit?.name == "Work Boats" } @@ -119,15 +119,17 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ } private fun addWorkerChoice() { - if(!civInfo.gameInfo.ruleSet.units.containsKey(Constants.worker)) return // for mods - if(civInfo.getIdleUnits().any { it.name==Constants.worker && it.action== Constants.unitActionAutomation}) + val workerEquivalents = civInfo.gameInfo.ruleSet.units.values + .filter { it.uniques.contains(Constants.workerUnique) && it.isBuildable(cityConstructions) } + if (workerEquivalents.isEmpty()) return // for mods with no worker units + if (civInfo.getIdleUnits().any { it.action == Constants.unitActionAutomation && it.hasUnique(Constants.workerUnique) }) return // If we have automated workers who have no work to do then it's silly to construct new workers. val citiesCountedTowardsWorkers = min(5, cities) // above 5 cities, extra cities won't make us want more workers - if (workers < citiesCountedTowardsWorkers * 0.6f && civUnits.none { it.name==Constants.worker && it.isIdle() }) { + if (workers < citiesCountedTowardsWorkers * 0.6f && civUnits.none { it.hasUnique(Constants.workerUnique) && it.isIdle() }) { var modifier = citiesCountedTowardsWorkers / (workers + 0.1f) if (!cityIsOverAverageProduction) modifier /= 5 // higher production cities will deal with this - addChoice(relativeCostEffectiveness, Constants.worker, modifier) + addChoice(relativeCostEffectiveness, workerEquivalents.minBy { it.cost }!!.name, modifier) } } diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index a4986cce94..36e1ac0c40 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -93,7 +93,7 @@ object UnitAutomation { if (unit.name == Constants.settler) return SpecificUnitAutomation.automateSettlerActions(unit) - if (unit.name == Constants.worker) + if (unit.hasUnique(Constants.workerUnique)) return WorkerAutomation(unit).automateWorkerAction() if (unit.name == "Work Boats") diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index dd8e647a6b..f72bc7f12d 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -306,7 +306,7 @@ object Battle { defender.getTile().position, Color.RED) // Apparently in Civ V, captured settlers are converted to workers. - if(capturedUnit.name==Constants.settler){ + if(capturedUnit.name==Constants.settler) { val tile = capturedUnit.getTile() capturedUnit.destroy() attacker.getCivInfo().placeUnitNearTile(tile.position, Constants.worker) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index aa6cb7d77d..e057358d9b 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -196,7 +196,7 @@ class MapUnit { fun isIdle(): Boolean { if (currentMovement == 0f) return false - if (name == Constants.worker && getTile().improvementInProgress != null) return false + if (hasUnique(Constants.workerUnique) && getTile().improvementInProgress != null) return false if (hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") return false if (isFortified()) return false if (action==Constants.unitActionExplore || isSleeping() @@ -356,7 +356,7 @@ class MapUnit { } private fun doPostTurnAction() { - if (name == Constants.worker && getTile().improvementInProgress != null) workOnImprovement() + if (hasUnique(Constants.workerUnique) && getTile().improvementInProgress != null) workOnImprovement() if(hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") workOnImprovement() if(currentMovement == getMaxMovement().toFloat() && isFortified()){ @@ -579,7 +579,7 @@ class MapUnit { } actions.add { - val chosenUnit = listOf(Constants.settler, Constants.worker,"Warrior") + val chosenUnit = listOf(Constants.settler, Constants.worker, "Warrior") .filter { civInfo.gameInfo.ruleSet.units.containsKey(it) }.random(tileBasedRandom) if (!(civInfo.isCityState() || civInfo.isOneCityChallenger()) || chosenUnit != Constants.settler) { //City-States and OCC don't get settler from ruins civInfo.placeUnitNearTile(tile.position, chosenUnit) diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 4b1bf9dce2..8af90a7984 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -391,7 +391,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { displayTutorial(Tutorial.InjuredUnits) { gameInfo.getCurrentPlayerCivilization().getCivUnits().any { it.health < 100 } } - displayTutorial(Tutorial.Workers) { gameInfo.getCurrentPlayerCivilization().getCivUnits().any { it.name == Constants.worker } } + displayTutorial(Tutorial.Workers) { gameInfo.getCurrentPlayerCivilization().getCivUnits().any { it.hasUnique(Constants.workerUnique) } } } private fun updateDiplomacyButton(civInfo: CivilizationInfo) {