diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index e491d0c6cf..8f52ef37c8 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -16,6 +16,7 @@ import java.util.* import kotlin.collections.ArrayList class MapUnit { + @Transient lateinit var civInfo: CivilizationInfo @Transient lateinit var baseUnit: BaseUnit @Transient internal lateinit var currentTile :TileInfo @@ -32,7 +33,13 @@ class MapUnit { lateinit var name: String var currentMovement: Float = 0f var health:Int = 100 - var action: String? = null // work, automation, fortifying, I dunno what. + + 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) } } + var attacksThisTurn = 0 var promotions = UnitPromotions() var due: Boolean = true @@ -275,6 +282,7 @@ class MapUnit { //region state-changing functions fun setTransients(){ promotions.unit=this + mapUnitAction?.unit = this baseUnit=GameBasics.Units[name]!! updateUniques() } diff --git a/core/src/com/unciv/logic/map/MapUnitAction.kt b/core/src/com/unciv/logic/map/MapUnitAction.kt new file mode 100644 index 0000000000..8d7d7dfc07 --- /dev/null +++ b/core/src/com/unciv/logic/map/MapUnitAction.kt @@ -0,0 +1,15 @@ +package com.unciv.logic.map + +open class MapUnitAction( + @Transient var unit: MapUnit = MapUnit(), + var name: String = "" +) + + +class BuildLongRoadAction( + mapUnit: MapUnit = MapUnit() +) : MapUnitAction(mapUnit, "Build Long Road") { + + + +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 5e69d56717..6da39d4a20 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -246,8 +246,6 @@ class WorldScreen : CameraStageBaseScreen() { return@onClick } - bottomBar.unitTable.currentlyExecutingAction = null - Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked! nextTurnButton.disable() nextTurnButton.setText("Working...".tr()) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 4ab1721f8c..80aad0f255 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -34,7 +34,6 @@ class UnitActions { if(unit.action!=null && unit.action!!.startsWith("moveTo")) { actionList += UnitAction("Stop movement", true) { - unitTable.currentlyExecutingAction = null unit.action = null } } @@ -146,7 +145,6 @@ class UnitActions { unit.civInfo.addCity(tile.position) tile.improvement = null - unitTable.currentlyExecutingAction = null // In case the settler was in the middle of doing something and we then founded a city with it unit.destroy() }.sound("chimes") } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitContextMenu.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitContextMenu.kt index 94da057ad4..87d10c0619 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitContextMenu.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitContextMenu.kt @@ -10,6 +10,7 @@ import com.unciv.ui.utils.ImageGetter import com.unciv.ui.utils.Sounds import com.unciv.ui.utils.onClick import com.unciv.ui.worldscreen.TileMapHolder +import com.unciv.logic.map.BuildLongRoadAction import kotlin.concurrent.thread class UnitContextMenu(val tileMapHolder: TileMapHolder, val selectedUnit: MapUnit, val targetTile: TileInfo) : VerticalGroup() { @@ -67,6 +68,6 @@ class UnitContextMenu(val tileMapHolder: TileMapHolder, val selectedUnit: MapUni } private fun onConstructRoadButtonClick() { - // TODO + selectedUnit.mapUnitAction = BuildLongRoadAction() } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index 4d7a689cff..dbeac8e6d0 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -22,8 +22,6 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ private val unitDescriptionTable = Table(CameraStageBaseScreen.skin) var selectedUnit : MapUnit? = null var selectedCity : CityInfo? = null - var currentlyExecutingAction : String? = null - var lastSelectedCityButton : Boolean = false val deselectUnitButton = Table() val helpUnitButton = Table() @@ -88,12 +86,10 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ if (selectedUnit!!.civInfo != worldScreen.currentPlayerCiv) { // The unit that was selected, was captured. It exists but is no longer ours. selectedUnit = null selectedCity = null - currentlyExecutingAction = null selectedUnitHasChanged = true } else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists} selectedUnit = null selectedCity = null - currentlyExecutingAction = null selectedUnitHasChanged = true } } @@ -190,20 +186,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ fun tileSelected(selectedTile: TileInfo) { val previouslySelectedUnit = selectedUnit - if(currentlyExecutingAction=="moveTo"){ - if(selectedUnit!!.movementAlgs() - .getShortestPath(selectedTile).isEmpty()) - return // can't reach there with the selected unit, watcha want me to do? - - val reachedTile = selectedUnit!!.movementAlgs().headTowards(selectedTile) - - selectedUnit!!.action=null // Disable any prior action (automation, fortification...) - if(reachedTile!=selectedTile) // Didn't get all the way there - selectedUnit!!.action = "moveTo " + selectedTile.position.x.toInt() + "," + selectedTile.position.y.toInt() - currentlyExecutingAction = null - } - - else if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.currentPlayerCiv + if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.currentPlayerCiv && selectedUnit!=selectedTile.militaryUnit && (selectedTile.civilianUnit==null || selectedUnit!=selectedTile.civilianUnit)){ selectedUnit = selectedTile.militaryUnit