mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 14:57:58 +07:00
standardized automate action
This commit is contained in:
@ -55,6 +55,8 @@ object UnitActions {
|
|||||||
UnitActionType.AddInCapital to UnitActionsFromUniques::getAddInCapitalActions
|
UnitActionType.AddInCapital to UnitActionsFromUniques::getAddInCapitalActions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun shouldAutomationBePrimaryAction(unit:MapUnit) = unit.cache.hasUniqueToBuildImprovements || unit.hasUnique(UniqueType.AutomationPrimaryAction)
|
||||||
|
|
||||||
private fun getNormalActions(unit: MapUnit): List<UnitAction> {
|
private fun getNormalActions(unit: MapUnit): List<UnitAction> {
|
||||||
val tile = unit.getTile()
|
val tile = unit.getTile()
|
||||||
val actionList = ArrayList<UnitAction>()
|
val actionList = ArrayList<UnitAction>()
|
||||||
@ -63,7 +65,9 @@ object UnitActions {
|
|||||||
actionList.addAll(getActionsFunction(unit, tile))
|
actionList.addAll(getActionsFunction(unit, tile))
|
||||||
|
|
||||||
// General actions
|
// General actions
|
||||||
addAutomateAction(unit, actionList, true)
|
|
||||||
|
if (shouldAutomationBePrimaryAction(unit))
|
||||||
|
actionList += getAutomateActions(unit, unit.currentTile)
|
||||||
if (unit.isMoving()) {
|
if (unit.isMoving()) {
|
||||||
actionList += UnitAction(UnitActionType.StopMovement) { unit.action = null }
|
actionList += UnitAction(UnitActionType.StopMovement) { unit.action = null }
|
||||||
}
|
}
|
||||||
@ -102,7 +106,8 @@ object UnitActions {
|
|||||||
}
|
}
|
||||||
addSleepActions(actionList, unit, true)
|
addSleepActions(actionList, unit, true)
|
||||||
addFortifyActions(actionList, unit, true)
|
addFortifyActions(actionList, unit, true)
|
||||||
addAutomateAction(unit, actionList, false)
|
if (!shouldAutomationBePrimaryAction(unit))
|
||||||
|
actionList += getAutomateActions(unit, unit.currentTile)
|
||||||
|
|
||||||
addSwapAction(unit, actionList)
|
addSwapAction(unit, actionList)
|
||||||
addDisbandAction(actionList, unit)
|
addDisbandAction(actionList, unit)
|
||||||
@ -289,17 +294,13 @@ object UnitActions {
|
|||||||
return UnitAction(UnitActionType.GiftUnit, action = giftAction)
|
return UnitAction(UnitActionType.GiftUnit, action = giftAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addAutomateAction(
|
private fun getAutomateActions(
|
||||||
unit: MapUnit,
|
unit: MapUnit,
|
||||||
actionList: ArrayList<UnitAction>,
|
tile: Tile
|
||||||
showingPrimaryActions: Boolean
|
): List<UnitAction> {
|
||||||
) {
|
|
||||||
val shouldAutomationBePrimaryAction = unit.cache.hasUniqueToBuildImprovements || unit.hasUnique(UniqueType.AutomationPrimaryAction)
|
|
||||||
if (shouldAutomationBePrimaryAction != showingPrimaryActions)
|
|
||||||
return
|
|
||||||
|
|
||||||
if (unit.isAutomated()) return
|
if (unit.isAutomated()) return listOf()
|
||||||
actionList += UnitAction(UnitActionType.Automate,
|
return listOf(UnitAction(UnitActionType.Automate,
|
||||||
isCurrentAction = unit.isAutomated(),
|
isCurrentAction = unit.isAutomated(),
|
||||||
action = {
|
action = {
|
||||||
// Temporary, for compatibility - we want games serialized *moving through old versions* to come out the other end with units still automated
|
// Temporary, for compatibility - we want games serialized *moving through old versions* to come out the other end with units still automated
|
||||||
@ -307,7 +308,7 @@ object UnitActions {
|
|||||||
unit.automated = true
|
unit.automated = true
|
||||||
UnitAutomation.automateUnitMoves(unit)
|
UnitAutomation.automateUnitMoves(unit)
|
||||||
}.takeIf { unit.currentMovement > 0 }
|
}.takeIf { unit.currentMovement > 0 }
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addWaitAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
private fun addWaitAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
|
||||||
|
Reference in New Issue
Block a user