Worker unique is now moddable to other units

This commit is contained in:
Yair Morgenstern 2020-07-17 15:47:49 +03:00
parent c402d63a68
commit 77d741040d
7 changed files with 16 additions and 13 deletions

View file

@ -2,6 +2,7 @@ package com.unciv
object Constants { object Constants {
const val worker = "Worker" const val worker = "Worker"
const val workerUnique = "Can build improvements on tiles"
const val settler = "Settler" const val settler = "Settler"
const val greatGeneral = "Great General" const val greatGeneral = "Great General"

View file

@ -76,7 +76,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
table.add(resumeTable).row() table.add(resumeTable).row()
} }
val quickstartTable = getTableBlock("Quickstart", "OtherIcons/Quickstart") { QuickstartNewGame() } val quickstartTable = getTableBlock("Quickstart", "OtherIcons/Quickstart") { quickstartNewGame() }
table.add(quickstartTable).row() table.add(quickstartTable).row()
val newGameButton = getTableBlock("Start new game", "OtherIcons/New") { 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" }) val newGame = GameStarter.startNewGame(GameSetupInfo().apply { gameParameters.difficulty = "Chieftain" })
game.loadGame(newGame) game.loadGame(newGame)
} }

View file

@ -25,7 +25,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
val civUnits = civInfo.getCivUnits() val civUnits = civInfo.getCivUnits()
val militaryUnits = civUnits.filter { !it.type.isCivilian()}.count() 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 cities = civInfo.cities.size
val canBuildWorkboat = cityInfo.cityConstructions.getConstructableUnits().map { it.name }.contains("Work Boats") val canBuildWorkboat = cityInfo.cityConstructions.getConstructableUnits().map { it.name }.contains("Work Boats")
&& !cityInfo.getTiles().any { it.civilianUnit?.name == "Work Boats" } && !cityInfo.getTiles().any { it.civilianUnit?.name == "Work Boats" }
@ -119,15 +119,17 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
} }
private fun addWorkerChoice() { private fun addWorkerChoice() {
if(!civInfo.gameInfo.ruleSet.units.containsKey(Constants.worker)) return // for mods val workerEquivalents = civInfo.gameInfo.ruleSet.units.values
if(civInfo.getIdleUnits().any { it.name==Constants.worker && it.action== Constants.unitActionAutomation}) .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. 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 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) var modifier = citiesCountedTowardsWorkers / (workers + 0.1f)
if (!cityIsOverAverageProduction) modifier /= 5 // higher production cities will deal with this if (!cityIsOverAverageProduction) modifier /= 5 // higher production cities will deal with this
addChoice(relativeCostEffectiveness, Constants.worker, modifier) addChoice(relativeCostEffectiveness, workerEquivalents.minBy { it.cost }!!.name, modifier)
} }
} }

View file

@ -93,7 +93,7 @@ object UnitAutomation {
if (unit.name == Constants.settler) if (unit.name == Constants.settler)
return SpecificUnitAutomation.automateSettlerActions(unit) return SpecificUnitAutomation.automateSettlerActions(unit)
if (unit.name == Constants.worker) if (unit.hasUnique(Constants.workerUnique))
return WorkerAutomation(unit).automateWorkerAction() return WorkerAutomation(unit).automateWorkerAction()
if (unit.name == "Work Boats") if (unit.name == "Work Boats")

View file

@ -306,7 +306,7 @@ object Battle {
defender.getTile().position, Color.RED) defender.getTile().position, Color.RED)
// Apparently in Civ V, captured settlers are converted to workers. // Apparently in Civ V, captured settlers are converted to workers.
if(capturedUnit.name==Constants.settler){ if(capturedUnit.name==Constants.settler) {
val tile = capturedUnit.getTile() val tile = capturedUnit.getTile()
capturedUnit.destroy() capturedUnit.destroy()
attacker.getCivInfo().placeUnitNearTile(tile.position, Constants.worker) attacker.getCivInfo().placeUnitNearTile(tile.position, Constants.worker)

View file

@ -196,7 +196,7 @@ class MapUnit {
fun isIdle(): Boolean { fun isIdle(): Boolean {
if (currentMovement == 0f) return false 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 (hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") return false
if (isFortified()) return false if (isFortified()) return false
if (action==Constants.unitActionExplore || isSleeping() if (action==Constants.unitActionExplore || isSleeping()
@ -356,7 +356,7 @@ class MapUnit {
} }
private fun doPostTurnAction() { 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(hasUnique("Can construct roads") && currentTile.improvementInProgress=="Road") workOnImprovement()
if(currentMovement == getMaxMovement().toFloat() if(currentMovement == getMaxMovement().toFloat()
&& isFortified()){ && isFortified()){
@ -579,7 +579,7 @@ class MapUnit {
} }
actions.add { 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) .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 if (!(civInfo.isCityState() || civInfo.isOneCityChallenger()) || chosenUnit != Constants.settler) { //City-States and OCC don't get settler from ruins
civInfo.placeUnitNearTile(tile.position, chosenUnit) civInfo.placeUnitNearTile(tile.position, chosenUnit)

View file

@ -391,7 +391,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
displayTutorial(Tutorial.InjuredUnits) { gameInfo.getCurrentPlayerCivilization().getCivUnits().any { it.health < 100 } } 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) { private fun updateDiplomacyButton(civInfo: CivilizationInfo) {