Resolved #2175 - Can no queue multiple perpetual builds

This commit is contained in:
Yair Morgenstern 2020-03-21 21:39:07 +02:00
parent 0da8cbd607
commit b43e543f23
6 changed files with 23 additions and 22 deletions

View file

@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.Color
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.city.CityConstructions
import com.unciv.logic.city.SpecialConstruction
import com.unciv.logic.city.PerpetualConstruction
import com.unciv.logic.civilization.CityAction
import com.unciv.logic.civilization.PlayerType
import com.unciv.models.ruleset.Building
@ -50,7 +50,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
if (!UncivGame.Current.settings.autoAssignCityProduction
&& civInfo.playerType== PlayerType.Human && !cityInfo.isPuppet)
return
if (cityConstructions.getCurrentConstruction() !is SpecialConstruction) return // don't want to be stuck on these forever
if (cityConstructions.getCurrentConstruction() !is PerpetualConstruction) return // don't want to be stuck on these forever
addFoodBuildingChoice()
addProductionBuildingChoice()
@ -75,9 +75,9 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
val theChosenOne: String
if (relativeCostEffectiveness.isEmpty()) { // choose one of the special constructions instead
// add science!
if (SpecialConstruction.science.isBuildable(cityConstructions))
if (PerpetualConstruction.science.isBuildable(cityConstructions))
theChosenOne = "Science"
else if (SpecialConstruction.gold.isBuildable(cityConstructions))
else if (PerpetualConstruction.gold.isBuildable(cityConstructions))
theChosenOne = "Gold"
else theChosenOne = "Nothing"
} else if (relativeCostEffectiveness.any { it.remainingWork < production * 30 }) {

View file

@ -92,7 +92,7 @@ class CityConstructions {
val currentConstructionSnapshot = currentConstruction // See below
var result = currentConstructionSnapshot.tr()
if (currentConstructionSnapshot != "") {
val construction = SpecialConstruction.specialConstructionsMap[currentConstructionSnapshot]
val construction = PerpetualConstruction.perpetualConstructionsMap[currentConstructionSnapshot]
if (construction == null) {
val turnsLeft = turnsToConstruction(currentConstructionSnapshot)
result += ("\r\n" + "Cost".tr() + " " + getConstruction(currentConstruction).getProductionCost(cityInfo.civInfo).toString()).tr()
@ -110,7 +110,7 @@ class CityConstructions {
val currentConstructionSnapshot = currentConstruction
var result = currentConstructionSnapshot.tr()
if (currentConstructionSnapshot!=""
&& !SpecialConstruction.specialConstructionsMap.containsKey(currentConstructionSnapshot)) {
&& !PerpetualConstruction.perpetualConstructionsMap.containsKey(currentConstructionSnapshot)) {
val turnsLeft = turnsToConstruction(currentConstructionSnapshot)
result += ConstructionInfoTable.turnOrTurns(turnsLeft)
}
@ -152,7 +152,7 @@ class CityConstructions {
gameBasics.units.containsKey(constructionName) -> return gameBasics.units[constructionName]!!
constructionName=="" -> return getConstruction("Nothing")
else -> {
val special = SpecialConstruction.specialConstructionsMap[constructionName]
val special = PerpetualConstruction.perpetualConstructionsMap[constructionName]
if(special!=null) return special
}
}
@ -174,7 +174,7 @@ class CityConstructions {
fun getRemainingWork(constructionName: String, useStoredProduction: Boolean = true): Int {
val constr = getConstruction(constructionName)
return when {
constr is SpecialConstruction -> 0
constr is PerpetualConstruction -> 0
useStoredProduction -> constr.getProductionCost(cityInfo.civInfo) - getWorkDone(constructionName)
else -> constr.getProductionCost(cityInfo.civInfo)
}
@ -222,7 +222,7 @@ class CityConstructions {
stopUnbuildableConstruction()
val construction = getConstruction(currentConstruction)
if(construction is SpecialConstruction) chooseNextConstruction() // check every turn if we could be doing something better, because this doesn't end by itself
if(construction is PerpetualConstruction) chooseNextConstruction() // check every turn if we could be doing something better, because this doesn't end by itself
else {
val productionCost = construction.getProductionCost(cityInfo.civInfo)
if (inProgressConstructions.containsKey(currentConstruction)
@ -237,7 +237,7 @@ class CityConstructions {
stopUnbuildableConstruction()
validateConstructionQueue()
if(getConstruction(currentConstruction) !is SpecialConstruction)
if(getConstruction(currentConstruction) !is PerpetualConstruction)
addProductionPoints(cityStats.production.roundToInt())
}

View file

@ -16,7 +16,7 @@ interface IConstruction : INamed {
open class SpecialConstruction(override var name: String, val description: String) : IConstruction{
open class PerpetualConstruction(override var name: String, val description: String) : IConstruction{
override fun shouldBeDisplayed(construction: CityConstructions): Boolean {
return isBuildable(construction)
}
@ -25,23 +25,23 @@ open class SpecialConstruction(override var name: String, val description: Strin
companion object {
const val CONVERSION_RATE: Int = 4
val science = object : SpecialConstruction("Science", "Convert production to science at a rate of $CONVERSION_RATE to 1") {
val science = object : PerpetualConstruction("Science", "Convert production to science at a rate of $CONVERSION_RATE to 1") {
override fun isBuildable(construction: CityConstructions): Boolean {
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to science")
}
}
val gold = object : SpecialConstruction("Gold", "Convert production to gold at a rate of $CONVERSION_RATE to 1") {
val gold = object : PerpetualConstruction("Gold", "Convert production to gold at a rate of $CONVERSION_RATE to 1") {
override fun isBuildable(construction: CityConstructions): Boolean {
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to gold")
}
}
val idle = object : SpecialConstruction("Nothing", "The city will not produce anything.") {
val idle = object : PerpetualConstruction("Nothing", "The city will not produce anything.") {
override fun isBuildable(construction: CityConstructions): Boolean = true
override fun getProductionTooltip(cityInfo: CityInfo): String = ""
}
val specialConstructionsMap: Map<String, SpecialConstruction>
val perpetualConstructionsMap: Map<String, PerpetualConstruction>
= mapOf(science.name to science, gold.name to gold, idle.name to idle)
}

View file

@ -5,7 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.unciv.logic.city.CityInfo
import com.unciv.logic.city.IConstruction
import com.unciv.logic.city.SpecialConstruction
import com.unciv.logic.city.PerpetualConstruction
import com.unciv.ui.utils.ImageGetter
import com.unciv.models.ruleset.Building
import com.unciv.models.ruleset.unit.BaseUnit
@ -48,7 +48,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() {
var buildingText = construction.name.tr()
val specialConstruction = SpecialConstruction.specialConstructionsMap[construction.name]
val specialConstruction = PerpetualConstruction.perpetualConstructionsMap[construction.name]
if (specialConstruction == null) {
val turnsToComplete = cityConstructions.turnsToConstruction(construction.name)
buildingText += ("\r\n" + "Cost".tr() + " " + construction.getProductionCost(city.civInfo).toString()).tr()
@ -65,7 +65,7 @@ class ConstructionInfoTable(val city: CityInfo): Table() {
description = construction.getDescription(true)
else if (construction is Building)
description = construction.getDescription(true, city.civInfo, city.civInfo.gameInfo.ruleSet)
else if(construction is SpecialConstruction)
else if(construction is PerpetualConstruction)
description = construction.description.tr()
else description="" // Should never happen

View file

@ -9,7 +9,7 @@ import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame
import com.unciv.logic.city.CityInfo
import com.unciv.logic.city.IConstruction
import com.unciv.logic.city.SpecialConstruction
import com.unciv.logic.city.PerpetualConstruction
import com.unciv.models.UncivSound
import com.unciv.models.stats.Stat
import com.unciv.models.translations.tr
@ -150,7 +150,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
else buildableBuildings += productionTextButton
}
for (specialConstruction in SpecialConstruction.specialConstructionsMap.values
for (specialConstruction in PerpetualConstruction.perpetualConstructionsMap.values
.filter { it.shouldBeDisplayed(cityConstructions) }) {
specialConstructions += getProductionButton(specialConstruction.name,
"Produce [${specialConstruction.name}]".tr()
@ -253,6 +253,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|| cityConstructions.isQueueFull()
|| !cityConstructions.getConstruction(construction.name).isBuildable(cityConstructions)
|| !UncivGame.Current.worldScreen.isPlayersTurn
|| construction is PerpetualConstruction && cityConstructions.isBeingConstructedOrEnqueued(construction.name)
|| city.isPuppet) {
button.disable()
} else {

View file

@ -12,7 +12,7 @@ import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame
import com.unciv.logic.city.CityConstructions
import com.unciv.logic.city.CityInfo
import com.unciv.logic.city.SpecialConstruction
import com.unciv.logic.city.PerpetualConstruction
import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.trade.DiplomacyScreen
import com.unciv.ui.utils.*
@ -259,7 +259,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
val secondaryColor = cityConstructions.cityInfo.civInfo.nation.getInnerColor()
val cityCurrentConstruction = cityConstructions.getCurrentConstruction()
if(cityCurrentConstruction !is SpecialConstruction) {
if(cityCurrentConstruction !is PerpetualConstruction) {
val turnsToConstruction = cityConstructions.turnsToConstruction(cityCurrentConstruction.name)
val label = turnsToConstruction.toString().toLabel(secondaryColor,14)
label.pack()