Unit construction moved to the beginning of the turn, so they won't be generated out in the open and vulnerable to enemy attacks before you can control them - Kudos am-per-sand!

This commit is contained in:
Yair Morgenstern 2019-02-21 20:12:17 +02:00
parent 325ac06e97
commit 563bbaf021
4 changed files with 22 additions and 22 deletions

View File

@ -66,11 +66,6 @@ class CityConstructions {
return result return result
} }
fun getAmountConstructedText(): String =
if (SpecialConstruction.getSpecialConstructions().any { it.name== currentConstruction}) ""
else " (" + getWorkDone(currentConstruction) + "/" +
getCurrentConstruction().getProductionCost(cityInfo.civInfo.policies.adoptedPolicies) + ")"
fun getCurrentConstruction(): IConstruction = getConstruction(currentConstruction) fun getCurrentConstruction(): IConstruction = getConstruction(currentConstruction)
fun isBuilt(buildingName: String): Boolean = builtBuildings.contains(buildingName) fun isBuilt(buildingName: String): Boolean = builtBuildings.contains(buildingName)
@ -120,10 +115,12 @@ class CityConstructions {
builtBuildingObjects = ArrayList(builtBuildings.map { GameBasics.Buildings[it]!! }) builtBuildingObjects = ArrayList(builtBuildings.map { GameBasics.Buildings[it]!! })
} }
fun addProduction(productionToAdd: Int) { fun addProductionPoints(productionToAdd: Int) {
if (!inProgressConstructions.containsKey(currentConstruction)) inProgressConstructions[currentConstruction] = 0 if (!inProgressConstructions.containsKey(currentConstruction)) inProgressConstructions[currentConstruction] = 0
inProgressConstructions[currentConstruction] = inProgressConstructions[currentConstruction]!! + productionToAdd inProgressConstructions[currentConstruction] = inProgressConstructions[currentConstruction]!! + productionToAdd
}
fun constructIfEnough(){
val construction = getConstruction(currentConstruction) val construction = getConstruction(currentConstruction)
val productionCost = construction.getProductionCost(cityInfo.civInfo.policies.adoptedPolicies) val productionCost = construction.getProductionCost(cityInfo.civInfo.policies.adoptedPolicies)
if (inProgressConstructions[currentConstruction]!! >= productionCost) { if (inProgressConstructions[currentConstruction]!! >= productionCost) {
@ -131,7 +128,7 @@ class CityConstructions {
} }
} }
fun nextTurn(cityStats: Stats) { fun endTurn(cityStats: Stats) {
val construction = getConstruction(currentConstruction) val construction = getConstruction(currentConstruction)
if(construction is SpecialConstruction) return if(construction is SpecialConstruction) return
@ -145,7 +142,7 @@ class CityConstructions {
} else } else
currentConstruction = saveCurrentConstruction currentConstruction = saveCurrentConstruction
addProduction(Math.round(cityStats.production)) addProductionPoints(Math.round(cityStats.production))
} }
fun constructionComplete(construction: IConstruction) { fun constructionComplete(construction: IConstruction) {

View File

@ -189,6 +189,9 @@ class CityInfo {
} }
fun startTurn(){ fun startTurn(){
// Construct units at the beginning of the turn,
// so they won't be generated out in the open and vulnerable to enemy attacks before you can control them
cityConstructions.constructIfEnough()
cityStats.update() cityStats.update()
tryUpdateRoadStatus() tryUpdateRoadStatus()
attackedThisTurn = false attackedThisTurn = false
@ -202,7 +205,7 @@ class CityInfo {
stats.food = 0f stats.food = 0f
} }
cityConstructions.nextTurn(stats) cityConstructions.endTurn(stats)
expansion.nextTurn(stats.culture) expansion.nextTurn(stats.culture)
if(isBeingRazed){ if(isBeingRazed){
population.population-- population.population--

View File

@ -336,11 +336,17 @@ class CivilizationInfo {
} }
fun startTurn(){ fun startTurn(){
// Generate great people at the start of the turn,
// so they won't be generated out in the open and vulnerable to enemy attacks before you can control them
if (cities.isNotEmpty()) { //if no city available, addGreatPerson will throw exception
val greatPerson = greatPeople.getNewGreatPerson()
if (greatPerson != null) addGreatPerson(greatPerson)
}
updateViewableTiles() // adds explored tiles so that the units will be able to perform automated actions better updateViewableTiles() // adds explored tiles so that the units will be able to perform automated actions better
setCitiesConnectedToCapitalTransients() setCitiesConnectedToCapitalTransients()
for (city in cities){ for (city in cities) city.startTurn()
city.startTurn()
}
happiness = getHappinessForNextTurn().values.sum().roundToInt() happiness = getHappinessForNextTurn().values.sum().roundToInt()
getCivUnits().toList().forEach { it.startTurn() } getCivUnits().toList().forEach { it.startTurn() }
} }
@ -375,15 +381,6 @@ class CivilizationInfo {
city.endTurn() city.endTurn()
} }
//if no city available, addGreatPerson will throw exception
if (cities.isNotEmpty()) {
val greatPerson = greatPeople.getNewGreatPerson()
if (greatPerson != null) {
addGreatPerson(greatPerson)
}
}
goldenAges.endTurn(happiness) goldenAges.endTurn(happiness)
getCivUnits().forEach { it.endTurn() } getCivUnits().forEach { it.endTurn() }
diplomacy.values.forEach{it.nextTurn()} diplomacy.values.forEach{it.nextTurn()}

View File

@ -181,7 +181,10 @@ class UnitActions {
tile.getCity()!!.cityConstructions.getCurrentConstruction() is Building && tile.getCity()!!.cityConstructions.getCurrentConstruction() is Building &&
(tile.getCity()!!.cityConstructions.getCurrentConstruction() as Building).isWonder (tile.getCity()!!.cityConstructions.getCurrentConstruction() as Building).isWonder
) { ) {
tile.getCity()!!.cityConstructions.addProduction(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) tile.getCity()!!.cityConstructions.apply {
addProductionPoints(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5)
constructIfEnough()
}
unit.destroy() unit.destroy()
}.sound("chimes") }.sound("chimes")
} }