mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
AI Performance improvement (added transient currentTile to unit)
This commit is contained in:
parent
9d0035a8a6
commit
0ac87fa8c4
@ -27,9 +27,9 @@ class MapUnit {
|
||||
|
||||
fun getBaseUnit(): BaseUnit = GameBasics.Units[name]!!
|
||||
fun getMovementString(): String = DecimalFormat("0.#").format(currentMovement.toDouble()) + "/" + maxMovement
|
||||
fun getTile(): TileInfo {
|
||||
return civInfo.gameInfo.tileMap.values.first{it.militaryUnit==this || it.civilianUnit==this}
|
||||
}
|
||||
|
||||
@Transient private lateinit var currentTile :TileInfo
|
||||
fun getTile(): TileInfo = currentTile
|
||||
|
||||
fun getDistanceToTiles(): HashMap<TileInfo, Float> {
|
||||
val tile = getTile()
|
||||
@ -187,6 +187,7 @@ class MapUnit {
|
||||
if(getBaseUnit().unitType== UnitType.Civilian)
|
||||
tile.civilianUnit=this
|
||||
else tile.militaryUnit=this
|
||||
currentTile = tile
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,6 +65,8 @@ class TileMap {
|
||||
fun setTransients() {
|
||||
for (tileInfo in values){
|
||||
tileInfo.tileMap = this
|
||||
if(tileInfo.militaryUnit!=null) tileInfo.militaryUnit!!.currentTile = tileInfo
|
||||
if(tileInfo.civilianUnit!=null) tileInfo.civilianUnit!!.currentTile = tileInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,21 +34,15 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){
|
||||
}
|
||||
|
||||
fun update() {
|
||||
if(selectedUnit!=null)
|
||||
{
|
||||
if(selectedUnit!!.civInfo != worldScreen.civInfo) { // The unit that was selected, was captured. It exists but is no longer ours.
|
||||
if(selectedUnit!=null) {
|
||||
if (selectedUnit!!.civInfo != worldScreen.civInfo) { // The unit that was selected, was captured. It exists but is no longer ours.
|
||||
selectedUnit = null
|
||||
currentlyExecutingAction = null
|
||||
selectedUnitHasChanged = true
|
||||
} else if (selectedUnit!! !in selectedUnit!!.getTile().getUnits()) { // The unit that was there no longer exists}
|
||||
selectedUnit = null
|
||||
currentlyExecutingAction = null
|
||||
selectedUnitHasChanged = true
|
||||
}
|
||||
else {
|
||||
try {
|
||||
selectedUnit!!.getTile()
|
||||
} catch (ex: Exception) { // The unit that was there no longer exists}
|
||||
selectedUnit = null
|
||||
currentlyExecutingAction = null
|
||||
selectedUnitHasChanged=true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user