mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Separate unit automation (#5592)
* Should resolve #5534 and the long-standing request of "move after automate" by separating the automated movement from the actual end of turn * Added translation * Automated units move in a separate thread to avoid UI freezing
This commit is contained in:
parent
72ffeaddce
commit
860e788fb5
@ -653,6 +653,7 @@ Waiting for other players... =
|
|||||||
Waiting for [civName]... =
|
Waiting for [civName]... =
|
||||||
in =
|
in =
|
||||||
Next turn =
|
Next turn =
|
||||||
|
Move automated units =
|
||||||
[currentPlayerCiv] ready? =
|
[currentPlayerCiv] ready? =
|
||||||
1 turn =
|
1 turn =
|
||||||
[numberOfTurns] turns =
|
[numberOfTurns] turns =
|
||||||
|
@ -181,6 +181,8 @@ class CivilizationInfo {
|
|||||||
var totalCultureForContests = 0
|
var totalCultureForContests = 0
|
||||||
var totalFaithForContests = 0
|
var totalFaithForContests = 0
|
||||||
|
|
||||||
|
var hasMovedAutomatedUnits = false
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var hasLongCountDisplayUnique = false
|
var hasLongCountDisplayUnique = false
|
||||||
|
|
||||||
@ -234,6 +236,7 @@ class CivilizationInfo {
|
|||||||
toReturn.numMinorCivsAttacked = numMinorCivsAttacked
|
toReturn.numMinorCivsAttacked = numMinorCivsAttacked
|
||||||
toReturn.totalCultureForContests = totalCultureForContests
|
toReturn.totalCultureForContests = totalCultureForContests
|
||||||
toReturn.totalFaithForContests = totalFaithForContests
|
toReturn.totalFaithForContests = totalFaithForContests
|
||||||
|
toReturn.hasMovedAutomatedUnits = hasMovedAutomatedUnits
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -779,6 +782,7 @@ class CivilizationInfo {
|
|||||||
for (city in cities) city.startTurn() // Most expensive part of startTurn
|
for (city in cities) city.startTurn() // Most expensive part of startTurn
|
||||||
|
|
||||||
for (unit in getCivUnits()) unit.startTurn()
|
for (unit in getCivUnits()) unit.startTurn()
|
||||||
|
hasMovedAutomatedUnits = false
|
||||||
|
|
||||||
for (tradeRequest in tradeRequests.toList()) { // remove trade requests where one of the sides can no longer supply
|
for (tradeRequest in tradeRequests.toList()) { // remove trade requests where one of the sides can no longer supply
|
||||||
val offeringCiv = gameInfo.getCivilization(tradeRequest.requestingCiv)
|
val offeringCiv = gameInfo.getCivilization(tradeRequest.requestingCiv)
|
||||||
|
@ -709,8 +709,6 @@ class MapUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun endTurn() {
|
fun endTurn() {
|
||||||
doAction()
|
|
||||||
|
|
||||||
if (currentMovement > 0 &&
|
if (currentMovement > 0 &&
|
||||||
getTile().improvementInProgress != null
|
getTile().improvementInProgress != null
|
||||||
&& canBuildImprovement(getTile().getTileImprovementInProgress()!!)
|
&& canBuildImprovement(getTile().getTileImprovementInProgress()!!)
|
||||||
|
@ -683,14 +683,20 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
|
|||||||
|
|
||||||
private fun getNextTurnAction(): NextTurnAction {
|
private fun getNextTurnAction(): NextTurnAction {
|
||||||
return when {
|
return when {
|
||||||
!isPlayersTurn && gameInfo.gameParameters.isOnlineMultiplayer -> NextTurnAction("Waiting for [${gameInfo.currentPlayerCiv}]...", Color.GRAY) {}
|
!isPlayersTurn && gameInfo.gameParameters.isOnlineMultiplayer ->
|
||||||
!isPlayersTurn && !gameInfo.gameParameters.isOnlineMultiplayer -> NextTurnAction("Waiting for other players...", Color.GRAY) {}
|
NextTurnAction("Waiting for [${gameInfo.currentPlayerCiv}]...", Color.GRAY) {}
|
||||||
|
!isPlayersTurn && !gameInfo.gameParameters.isOnlineMultiplayer ->
|
||||||
|
NextTurnAction("Waiting for other players...",Color.GRAY) {}
|
||||||
|
|
||||||
viewingCiv.shouldGoToDueUnit() ->
|
viewingCiv.shouldGoToDueUnit() ->
|
||||||
NextTurnAction("Next unit", Color.LIGHT_GRAY) {
|
NextTurnAction("Next unit", Color.LIGHT_GRAY) {
|
||||||
val nextDueUnit = viewingCiv.getNextDueUnit()
|
val nextDueUnit = viewingCiv.getNextDueUnit()
|
||||||
if (nextDueUnit != null) {
|
if (nextDueUnit != null) {
|
||||||
mapHolder.setCenterPosition(nextDueUnit.currentTile.position, immediately = false, selectUnit = false)
|
mapHolder.setCenterPosition(
|
||||||
|
nextDueUnit.currentTile.position,
|
||||||
|
immediately = false,
|
||||||
|
selectUnit = false
|
||||||
|
)
|
||||||
bottomUnitTable.selectUnit(nextDueUnit)
|
bottomUnitTable.selectUnit(nextDueUnit)
|
||||||
shouldUpdate = true
|
shouldUpdate = true
|
||||||
}
|
}
|
||||||
@ -699,13 +705,17 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
|
|||||||
viewingCiv.cities.any { it.cityConstructions.currentConstructionFromQueue == "" } ->
|
viewingCiv.cities.any { it.cityConstructions.currentConstructionFromQueue == "" } ->
|
||||||
NextTurnAction("Pick construction", Color.CORAL) {
|
NextTurnAction("Pick construction", Color.CORAL) {
|
||||||
val cityWithNoProductionSet = viewingCiv.cities
|
val cityWithNoProductionSet = viewingCiv.cities
|
||||||
.firstOrNull { it.cityConstructions.currentConstructionFromQueue == "" }
|
.firstOrNull { it.cityConstructions.currentConstructionFromQueue == "" }
|
||||||
if (cityWithNoProductionSet != null) game.setScreen(CityScreen(cityWithNoProductionSet))
|
if (cityWithNoProductionSet != null) game.setScreen(
|
||||||
|
CityScreen(cityWithNoProductionSet)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewingCiv.shouldOpenTechPicker() ->
|
viewingCiv.shouldOpenTechPicker() ->
|
||||||
NextTurnAction("Pick a tech", Color.SKY) {
|
NextTurnAction("Pick a tech", Color.SKY) {
|
||||||
game.setScreen(TechPickerScreen(viewingCiv, null, viewingCiv.tech.freeTechs != 0))
|
game.setScreen(
|
||||||
|
TechPickerScreen(viewingCiv, null, viewingCiv.tech.freeTechs != 0)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewingCiv.policies.shouldOpenPolicyPicker || (viewingCiv.policies.freePolicies > 0 && viewingCiv.policies.canAdoptPolicy()) ->
|
viewingCiv.policies.shouldOpenPolicyPicker || (viewingCiv.policies.freePolicies > 0 && viewingCiv.policies.canAdoptPolicy()) ->
|
||||||
@ -718,32 +728,53 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
|
|||||||
NextTurnAction("Found Pantheon", Color.WHITE) {
|
NextTurnAction("Found Pantheon", Color.WHITE) {
|
||||||
game.setScreen(PantheonPickerScreen(viewingCiv, gameInfo))
|
game.setScreen(PantheonPickerScreen(viewingCiv, gameInfo))
|
||||||
}
|
}
|
||||||
|
|
||||||
viewingCiv.religionManager.religionState == ReligionState.FoundingReligion ->
|
viewingCiv.religionManager.religionState == ReligionState.FoundingReligion ->
|
||||||
NextTurnAction("Found Religion", Color.WHITE) {
|
NextTurnAction("Found Religion", Color.WHITE) {
|
||||||
game.setScreen(ReligiousBeliefsPickerScreen(
|
game.setScreen(
|
||||||
viewingCiv,
|
ReligiousBeliefsPickerScreen(
|
||||||
gameInfo,
|
viewingCiv,
|
||||||
viewingCiv.religionManager.getBeliefsToChooseAtFounding(),
|
gameInfo,
|
||||||
pickIconAndName = true
|
viewingCiv.religionManager.getBeliefsToChooseAtFounding(),
|
||||||
))
|
pickIconAndName = true
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewingCiv.religionManager.religionState == ReligionState.EnhancingReligion ->
|
viewingCiv.religionManager.religionState == ReligionState.EnhancingReligion ->
|
||||||
NextTurnAction("Enhance Religion", Color.ORANGE) {
|
NextTurnAction("Enhance Religion", Color.ORANGE) {
|
||||||
game.setScreen(ReligiousBeliefsPickerScreen(
|
game.setScreen(
|
||||||
viewingCiv,
|
ReligiousBeliefsPickerScreen(
|
||||||
gameInfo,
|
viewingCiv,
|
||||||
viewingCiv.religionManager.getBeliefsToChooseAtEnhancing(),
|
gameInfo,
|
||||||
pickIconAndName = false
|
viewingCiv.religionManager.getBeliefsToChooseAtEnhancing(),
|
||||||
))
|
pickIconAndName = false
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewingCiv.mayVoteForDiplomaticVictory() ->
|
viewingCiv.mayVoteForDiplomaticVictory() ->
|
||||||
NextTurnAction("Vote for World Leader", Color.RED) {
|
NextTurnAction("Vote for World Leader", Color.RED) {
|
||||||
game.setScreen(DiplomaticVotePickerScreen(viewingCiv))
|
game.setScreen(DiplomaticVotePickerScreen(viewingCiv))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
!viewingCiv.hasMovedAutomatedUnits && viewingCiv.getCivUnits()
|
||||||
|
.any { it.isMoving() || it.isAutomated() || it.isExploring() } ->
|
||||||
|
NextTurnAction("Move automated units", Color.LIGHT_GRAY) {
|
||||||
|
viewingCiv.hasMovedAutomatedUnits = true
|
||||||
|
isPlayersTurn = false // Disable state changes
|
||||||
|
nextTurnButton.disable()
|
||||||
|
thread(name="Move automated units") {
|
||||||
|
for (unit in viewingCiv.getCivUnits())
|
||||||
|
unit.doAction()
|
||||||
|
Gdx.app.postRunnable {
|
||||||
|
shouldUpdate = true
|
||||||
|
isPlayersTurn = true //Re-enable state changes
|
||||||
|
nextTurnButton.enable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
NextTurnAction("${Fonts.turn}{Next turn}", Color.WHITE) {
|
NextTurnAction("${Fonts.turn}{Next turn}", Color.WHITE) {
|
||||||
game.settings.addCompletedTutorialTask("Pass a turn")
|
game.settings.addCompletedTutorialTask("Pass a turn")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user