mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
chore: More civinfo cleanup
This commit is contained in:
parent
e272a1408d
commit
e4fd6ff069
@ -294,7 +294,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
|
|||||||
TurnManager(player).startTurn()
|
TurnManager(player).startTurn()
|
||||||
|
|
||||||
// Automation done here
|
// Automation done here
|
||||||
player.doTurn()
|
TurnManager(player).automateTurn()
|
||||||
|
|
||||||
// Do we need to break if player won?
|
// Do we need to break if player won?
|
||||||
if (simulateUntilWin && player.victoryManager.hasWon()) {
|
if (simulateUntilWin && player.victoryManager.hasWon()) {
|
||||||
@ -540,7 +540,7 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
|
|||||||
}) {
|
}) {
|
||||||
for (unit in civInfo.getCivUnits())
|
for (unit in civInfo.getCivUnits())
|
||||||
unit.updateVisibleTiles(false) // this needs to be done after all the units are assigned to their civs and all other transients are set
|
unit.updateVisibleTiles(false) // this needs to be done after all the units are assigned to their civs and all other transients are set
|
||||||
civInfo.updateSightAndResources() // only run ONCE and not for each unit - this is a huge performance saver!
|
civInfo.cache.updateSightAndResources() // only run ONCE and not for each unit - this is a huge performance saver!
|
||||||
|
|
||||||
// Since this depends on the cities of ALL civilizations,
|
// Since this depends on the cities of ALL civilizations,
|
||||||
// we need to wait until we've set the transients of all the cities before we can run this.
|
// we need to wait until we've set the transients of all the cities before we can run this.
|
||||||
|
@ -7,9 +7,7 @@ import com.unciv.json.HashMapVector2
|
|||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||||
import com.unciv.logic.UncivShowableException
|
import com.unciv.logic.UncivShowableException
|
||||||
import com.unciv.logic.VictoryData
|
|
||||||
import com.unciv.logic.automation.ai.TacticalAI
|
import com.unciv.logic.automation.ai.TacticalAI
|
||||||
import com.unciv.logic.automation.civilization.NextTurnAutomation
|
|
||||||
import com.unciv.logic.automation.unit.WorkerAutomation
|
import com.unciv.logic.automation.unit.WorkerAutomation
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.civilization.diplomacy.CityStateFunctions
|
import com.unciv.logic.civilization.diplomacy.CityStateFunctions
|
||||||
@ -226,7 +224,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
|
|||||||
val passableImpassables = HashSet<String>() // For Carthage-like uniques
|
val passableImpassables = HashSet<String>() // For Carthage-like uniques
|
||||||
|
|
||||||
// For Aggressor, Warmonger status
|
// For Aggressor, Warmonger status
|
||||||
private var numMinorCivsAttacked = 0
|
internal var numMinorCivsAttacked = 0
|
||||||
|
|
||||||
var totalCultureForContests = 0
|
var totalCultureForContests = 0
|
||||||
var totalFaithForContests = 0
|
var totalFaithForContests = 0
|
||||||
@ -915,41 +913,6 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateSightAndResources() {
|
|
||||||
cache.updateViewableTiles()
|
|
||||||
cache.updateHasActiveEnemyMovementPenalty()
|
|
||||||
cache.updateCivResources()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun changeMinorCivsAttacked(count: Int) {
|
|
||||||
numMinorCivsAttacked += count
|
|
||||||
}
|
|
||||||
|
|
||||||
fun doTurn() {
|
|
||||||
|
|
||||||
// Defeated civs do nothing
|
|
||||||
if (isDefeated())
|
|
||||||
return
|
|
||||||
|
|
||||||
// Do stuff
|
|
||||||
NextTurnAutomation.automateCivMoves(this)
|
|
||||||
|
|
||||||
// Update barbarian camps
|
|
||||||
if (isBarbarian() && !gameInfo.gameParameters.noBarbarians)
|
|
||||||
gameInfo.barbarians.updateEncampments()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateWinningCiv(){
|
|
||||||
if (gameInfo.victoryData == null) {
|
|
||||||
val victoryType = victoryManager.getVictoryTypeAchieved()
|
|
||||||
if (victoryType != null) {
|
|
||||||
gameInfo.victoryData = VictoryData(civName, victoryType, gameInfo.turns)
|
|
||||||
|
|
||||||
for (civInfo in gameInfo.civilizations)
|
|
||||||
civInfo.popupAlerts.add(PopupAlert(AlertType.GameHasBeenWon, civName))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addFlag(flag: String, count: Int) = flagsCountdown.set(flag, count)
|
fun addFlag(flag: String, count: Int) = flagsCountdown.set(flag, count)
|
||||||
fun removeFlag(flag: String) = flagsCountdown.remove(flag)
|
fun removeFlag(flag: String) = flagsCountdown.remove(flag)
|
||||||
|
@ -686,7 +686,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
|
|||||||
|
|
||||||
if (otherCiv.isCityState() && !indirectCityStateAttack) {
|
if (otherCiv.isCityState() && !indirectCityStateAttack) {
|
||||||
otherCivDiplomacy.setInfluence(-60f)
|
otherCivDiplomacy.setInfluence(-60f)
|
||||||
civInfo.changeMinorCivsAttacked(1)
|
civInfo.numMinorCivsAttacked += 1
|
||||||
otherCiv.cityStateFunctions.cityStateAttacked(civInfo)
|
otherCiv.cityStateFunctions.cityStateAttacked(civInfo)
|
||||||
|
|
||||||
// You attacked your own ally, you're a right bastard
|
// You attacked your own ally, you're a right bastard
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package com.unciv.logic.civilization.managers
|
package com.unciv.logic.civilization.managers
|
||||||
|
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.logic.VictoryData
|
||||||
import com.unciv.logic.automation.civilization.NextTurnAutomation
|
import com.unciv.logic.automation.civilization.NextTurnAutomation
|
||||||
|
import com.unciv.logic.civilization.AlertType
|
||||||
import com.unciv.logic.civilization.CivFlags
|
import com.unciv.logic.civilization.CivFlags
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.civilization.NotificationCategory
|
import com.unciv.logic.civilization.NotificationCategory
|
||||||
import com.unciv.logic.civilization.NotificationIcon
|
import com.unciv.logic.civilization.NotificationIcon
|
||||||
import com.unciv.logic.civilization.PlayerType
|
import com.unciv.logic.civilization.PlayerType
|
||||||
|
import com.unciv.logic.civilization.PopupAlert
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.logic.trade.TradeEvaluation
|
import com.unciv.logic.trade.TradeEvaluation
|
||||||
import com.unciv.models.ruleset.ModOptionsConstants
|
import com.unciv.models.ruleset.ModOptionsConstants
|
||||||
@ -66,7 +69,7 @@ class TurnManager(val civInfo: CivilizationInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
civInfo.updateWinningCiv()
|
updateWinningCiv()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +269,33 @@ class TurnManager(val civInfo: CivilizationInfo) {
|
|||||||
|
|
||||||
civInfo.cachedMilitaryMight = -1 // Reset so we don't use a value from a previous turn
|
civInfo.cachedMilitaryMight = -1 // Reset so we don't use a value from a previous turn
|
||||||
|
|
||||||
civInfo.updateWinningCiv() // Maybe we did something this turn to win
|
updateWinningCiv() // Maybe we did something this turn to win
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateWinningCiv(){
|
||||||
|
if (civInfo.gameInfo.victoryData != null) return // Game already won
|
||||||
|
|
||||||
|
val victoryType = civInfo.victoryManager.getVictoryTypeAchieved()
|
||||||
|
if (victoryType != null) {
|
||||||
|
civInfo.gameInfo.victoryData =
|
||||||
|
VictoryData(civInfo.civName, victoryType, civInfo.gameInfo.turns)
|
||||||
|
|
||||||
|
for (civInfo in civInfo.gameInfo.civilizations)
|
||||||
|
civInfo.popupAlerts.add(PopupAlert(AlertType.GameHasBeenWon, civInfo.civName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun automateTurn() {
|
||||||
|
// Defeated civs do nothing
|
||||||
|
if (civInfo.isDefeated())
|
||||||
|
return
|
||||||
|
|
||||||
|
// Do stuff
|
||||||
|
NextTurnAutomation.automateCivMoves(civInfo)
|
||||||
|
|
||||||
|
// Update barbarian camps
|
||||||
|
if (civInfo.isBarbarian() && !civInfo.gameInfo.gameParameters.noBarbarians)
|
||||||
|
civInfo.gameInfo.barbarians.updateEncampments()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,12 @@ import com.unciv.models.ruleset.unique.UniqueType
|
|||||||
/** CivInfo class was getting too crowded */
|
/** CivInfo class was getting too crowded */
|
||||||
class CivInfoTransientCache(val civInfo: CivilizationInfo) {
|
class CivInfoTransientCache(val civInfo: CivilizationInfo) {
|
||||||
|
|
||||||
|
fun updateSightAndResources() {
|
||||||
|
updateViewableTiles()
|
||||||
|
updateHasActiveEnemyMovementPenalty()
|
||||||
|
updateCivResources()
|
||||||
|
}
|
||||||
|
|
||||||
// This is a big performance
|
// This is a big performance
|
||||||
fun updateViewableTiles() {
|
fun updateViewableTiles() {
|
||||||
setNewViewableTiles()
|
setNewViewableTiles()
|
||||||
|
@ -88,7 +88,7 @@ fun debugTab() = Table(BaseScreen.skin).apply {
|
|||||||
curGameInfo.getCurrentPlayerCivilization().popupAlerts.removeLastOrNull()
|
curGameInfo.getCurrentPlayerCivilization().popupAlerts.removeLastOrNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curGameInfo.getCurrentPlayerCivilization().updateSightAndResources()
|
curGameInfo.getCurrentPlayerCivilization().cache.updateSightAndResources()
|
||||||
if (worldScreen != null) worldScreen.shouldUpdate = true
|
if (worldScreen != null) worldScreen.shouldUpdate = true
|
||||||
}
|
}
|
||||||
add(unlockTechsButton).colspan(2).row()
|
add(unlockTechsButton).colspan(2).row()
|
||||||
@ -106,7 +106,7 @@ fun debugTab() = Table(BaseScreen.skin).apply {
|
|||||||
// If this becomes a problem, check if such an improvement exists and otherwise plop down a great improvement or so
|
// If this becomes a problem, check if such an improvement exists and otherwise plop down a great improvement or so
|
||||||
tile.changeImprovement(resource.getImprovements().first())
|
tile.changeImprovement(resource.getImprovements().first())
|
||||||
}
|
}
|
||||||
curGameInfo.getCurrentPlayerCivilization().updateSightAndResources()
|
curGameInfo.getCurrentPlayerCivilization().cache.updateSightAndResources()
|
||||||
if (worldScreen != null) worldScreen.shouldUpdate = true
|
if (worldScreen != null) worldScreen.shouldUpdate = true
|
||||||
}
|
}
|
||||||
add(giveResourcesButton).colspan(2).row()
|
add(giveResourcesButton).colspan(2).row()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user