Skip to content

Commit

Permalink
Save associated unique in UnitAction for automation / grouping - see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Nov 3, 2024
1 parent a0bbab1 commit ab15058
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/com/unciv/models/UnitAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.unciv.models

import com.badlogic.gdx.scenes.scene2d.Actor
import com.unciv.Constants
import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.translations.getPlaceholderParameters
import com.unciv.ui.components.fonts.Fonts
Expand All @@ -23,6 +24,7 @@ open class UnitAction(
val title: String = type.value,
val isCurrentAction: Boolean = false,
val uncivSound: UncivSound = type.uncivSound,
val associatedUnique: Unique? = null,
/** Action is Null if this unit *can* execute the action but *not right now* - it's embarked, out of moves, etc */
val action: (() -> Unit)? = null
) {
Expand Down Expand Up @@ -70,7 +72,7 @@ open class UnitAction(

/** Specialized [UnitAction] for upgrades
*
* Transports [unitToUpgradeTo] from [creation][com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsUpgrade.getUpgradeAction]
* Transports [unitToUpgradeTo] from [creation][com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsUpgrade.getUpgradeActions]
* to [UI][com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsTable.update]
*/
class UpgradeUnitAction(
Expand Down Expand Up @@ -196,6 +198,6 @@ enum class UnitActionType(

val binding: KeyboardBinding =
binding ?:
KeyboardBinding.values().firstOrNull { it.name == name } ?:
KeyboardBinding.entries.firstOrNull { it.name == name } ?:
KeyboardBinding.None
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ object UnitActionsFromUniques {
useFrequency = 80f,
title = title,
uncivSound = UncivSound.Chimes,
associatedUnique = unique,
action = {
// check if we would be breaking a promise
val leadersPromisedNotToSettleNear = getLeadersWePromisedNotToSettleNear(unit.civ, tile)
Expand Down Expand Up @@ -242,6 +243,7 @@ object UnitActionsFromUniques {

yield(
UnitAction(UnitActionType.TriggerUnique, 80f, title,
associatedUnique = unique,
action = unitAction.takeIf {
UnitActionModifiers.canActivateSideEffects(unit, unique)
})
Expand Down Expand Up @@ -312,6 +314,7 @@ object UnitActionsFromUniques {
unique,
unit
),
associatedUnique = unique,
action = {
val unitTile = unit.getTile()
unitTile.setImprovement(improvement.name, unit.civ, unit)
Expand Down Expand Up @@ -393,6 +396,7 @@ object UnitActionsFromUniques {

yield(UnitAction(UnitActionType.Transform, 70f,
title = title,
associatedUnique = unique,
action = {
val oldMovement = unit.currentMovement
unit.destroy()
Expand Down

0 comments on commit ab15058

Please sign in to comment.