using StringAction for string-encoded actions used throughout the app
This commit is contained in:
parent
29647896ce
commit
4330508d2e
3 changed files with 23 additions and 5 deletions
|
@ -7,6 +7,7 @@ import com.unciv.logic.automation.UnitAutomation
|
|||
import com.unciv.logic.automation.WorkerAutomation
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.action.MapUnitAction
|
||||
import com.unciv.logic.map.action.StringAction
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.tech.TechEra
|
||||
import com.unciv.models.gamebasics.tile.TerrainType
|
||||
|
@ -38,8 +39,8 @@ class MapUnit {
|
|||
var mapUnitAction : MapUnitAction? = null
|
||||
var action: String? // work, automation, fortifying, I dunno what.
|
||||
// getter and setter for compatibility: make sure string-based actions still work
|
||||
get() = mapUnitAction?.name
|
||||
set(value) { mapUnitAction = value?.let{ MapUnitAction(this, value) } }
|
||||
get() = (mapUnitAction as? StringAction)?.action ?: mapUnitAction?.let { "" } // null if no action is assigned.
|
||||
set(value) { mapUnitAction = value?.let{ StringAction(this, value) } } // wrap traditional string-encoded actions into StringAction
|
||||
|
||||
var attacksThisTurn = 0
|
||||
var promotions = UnitPromotions()
|
||||
|
|
|
@ -3,13 +3,12 @@ package com.unciv.logic.map.action
|
|||
import com.unciv.logic.map.MapUnit
|
||||
|
||||
open class MapUnitAction(
|
||||
@Transient var unit: MapUnit = MapUnit(),
|
||||
var name: String = ""
|
||||
@Transient var unit: MapUnit = MapUnit()
|
||||
) {
|
||||
/** return true if this action is possible in the given conditions */
|
||||
open fun isAvailable(): Boolean = true
|
||||
open fun doPreTurnAction() {}
|
||||
open fun shouldStopOnEnemyInSight(): Boolean = name.startsWith("moveTo")
|
||||
open fun shouldStopOnEnemyInSight(): Boolean = false
|
||||
}
|
||||
|
||||
|
||||
|
|
18
core/src/com/unciv/logic/map/action/StringAction.kt
Normal file
18
core/src/com/unciv/logic/map/action/StringAction.kt
Normal file
|
@ -0,0 +1,18 @@
|
|||
package com.unciv.logic.map.action
|
||||
|
||||
import com.unciv.logic.map.MapUnit
|
||||
|
||||
/**
|
||||
* this class represents all actions that are identified by string only.
|
||||
* this is the traditional way of handling actions in UnCiv: by coding relevant information
|
||||
* into a string. This class is here to maintain compatibility to that method, preventing from a huge
|
||||
* refactoring going on here.
|
||||
*/
|
||||
class StringAction(
|
||||
unit: MapUnit = MapUnit(),
|
||||
val action: String = "" // traditional string-encoded action like "moveTo x,y"
|
||||
): MapUnitAction(unit) {
|
||||
|
||||
override fun shouldStopOnEnemyInSight(): Boolean = action.startsWith("moveTo")
|
||||
|
||||
}
|
Loading…
Reference in a new issue