mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 10:18:26 +07:00
adding MapUnitAction, which is compatible to MapUnit.action
This commit is contained in:
@ -16,6 +16,7 @@ import java.util.*
|
|||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class MapUnit {
|
class MapUnit {
|
||||||
|
|
||||||
@Transient lateinit var civInfo: CivilizationInfo
|
@Transient lateinit var civInfo: CivilizationInfo
|
||||||
@Transient lateinit var baseUnit: BaseUnit
|
@Transient lateinit var baseUnit: BaseUnit
|
||||||
@Transient internal lateinit var currentTile :TileInfo
|
@Transient internal lateinit var currentTile :TileInfo
|
||||||
@ -32,7 +33,13 @@ class MapUnit {
|
|||||||
lateinit var name: String
|
lateinit var name: String
|
||||||
var currentMovement: Float = 0f
|
var currentMovement: Float = 0f
|
||||||
var health:Int = 100
|
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 attacksThisTurn = 0
|
||||||
var promotions = UnitPromotions()
|
var promotions = UnitPromotions()
|
||||||
var due: Boolean = true
|
var due: Boolean = true
|
||||||
@ -275,6 +282,7 @@ class MapUnit {
|
|||||||
//region state-changing functions
|
//region state-changing functions
|
||||||
fun setTransients(){
|
fun setTransients(){
|
||||||
promotions.unit=this
|
promotions.unit=this
|
||||||
|
mapUnitAction?.unit = this
|
||||||
baseUnit=GameBasics.Units[name]!!
|
baseUnit=GameBasics.Units[name]!!
|
||||||
updateUniques()
|
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
|
return@onClick
|
||||||
}
|
}
|
||||||
|
|
||||||
bottomBar.unitTable.currentlyExecutingAction = null
|
|
||||||
|
|
||||||
Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked!
|
Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked!
|
||||||
nextTurnButton.disable()
|
nextTurnButton.disable()
|
||||||
nextTurnButton.setText("Working...".tr())
|
nextTurnButton.setText("Working...".tr())
|
||||||
|
@ -34,7 +34,6 @@ class UnitActions {
|
|||||||
if(unit.action!=null && unit.action!!.startsWith("moveTo")) {
|
if(unit.action!=null && unit.action!!.startsWith("moveTo")) {
|
||||||
actionList +=
|
actionList +=
|
||||||
UnitAction("Stop movement", true) {
|
UnitAction("Stop movement", true) {
|
||||||
unitTable.currentlyExecutingAction = null
|
|
||||||
unit.action = null
|
unit.action = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +145,6 @@ class UnitActions {
|
|||||||
|
|
||||||
unit.civInfo.addCity(tile.position)
|
unit.civInfo.addCity(tile.position)
|
||||||
tile.improvement = null
|
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()
|
unit.destroy()
|
||||||
}.sound("chimes")
|
}.sound("chimes")
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.unciv.ui.utils.ImageGetter
|
|||||||
import com.unciv.ui.utils.Sounds
|
import com.unciv.ui.utils.Sounds
|
||||||
import com.unciv.ui.utils.onClick
|
import com.unciv.ui.utils.onClick
|
||||||
import com.unciv.ui.worldscreen.TileMapHolder
|
import com.unciv.ui.worldscreen.TileMapHolder
|
||||||
|
import com.unciv.logic.map.BuildLongRoadAction
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class UnitContextMenu(val tileMapHolder: TileMapHolder, val selectedUnit: MapUnit, val targetTile: TileInfo) : VerticalGroup() {
|
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() {
|
private fun onConstructRoadButtonClick() {
|
||||||
// TODO
|
selectedUnit.mapUnitAction = BuildLongRoadAction()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,8 +22,6 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
private val unitDescriptionTable = Table(CameraStageBaseScreen.skin)
|
private val unitDescriptionTable = Table(CameraStageBaseScreen.skin)
|
||||||
var selectedUnit : MapUnit? = null
|
var selectedUnit : MapUnit? = null
|
||||||
var selectedCity : CityInfo? = null
|
var selectedCity : CityInfo? = null
|
||||||
var currentlyExecutingAction : String? = null
|
|
||||||
var lastSelectedCityButton : Boolean = false
|
|
||||||
val deselectUnitButton = Table()
|
val deselectUnitButton = Table()
|
||||||
val helpUnitButton = 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.
|
if (selectedUnit!!.civInfo != worldScreen.currentPlayerCiv) { // The unit that was selected, was captured. It exists but is no longer ours.
|
||||||
selectedUnit = null
|
selectedUnit = null
|
||||||
selectedCity = null
|
selectedCity = null
|
||||||
currentlyExecutingAction = null
|
|
||||||
selectedUnitHasChanged = true
|
selectedUnitHasChanged = true
|
||||||
} else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists}
|
} else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists}
|
||||||
selectedUnit = null
|
selectedUnit = null
|
||||||
selectedCity = null
|
selectedCity = null
|
||||||
currentlyExecutingAction = null
|
|
||||||
selectedUnitHasChanged = true
|
selectedUnitHasChanged = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,20 +186,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
|||||||
fun tileSelected(selectedTile: TileInfo) {
|
fun tileSelected(selectedTile: TileInfo) {
|
||||||
|
|
||||||
val previouslySelectedUnit = selectedUnit
|
val previouslySelectedUnit = selectedUnit
|
||||||
if(currentlyExecutingAction=="moveTo"){
|
if(selectedTile.militaryUnit!=null && selectedTile.militaryUnit!!.civInfo == worldScreen.currentPlayerCiv
|
||||||
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
|
|
||||||
&& selectedUnit!=selectedTile.militaryUnit
|
&& selectedUnit!=selectedTile.militaryUnit
|
||||||
&& (selectedTile.civilianUnit==null || selectedUnit!=selectedTile.civilianUnit)){
|
&& (selectedTile.civilianUnit==null || selectedUnit!=selectedTile.civilianUnit)){
|
||||||
selectedUnit = selectedTile.militaryUnit
|
selectedUnit = selectedTile.militaryUnit
|
||||||
|
Reference in New Issue
Block a user