adding MapUnitAction, which is compatible to MapUnit.action
This commit is contained in:
parent
86eda6208a
commit
a8c3b3755b
6 changed files with 27 additions and 24 deletions
|
@ -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()
|
||||
}
|
||||
|
|
15
core/src/com/unciv/logic/map/MapUnitAction.kt
Normal file
15
core/src/com/unciv/logic/map/MapUnitAction.kt
Normal file
|
@ -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") {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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())
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue