AI Performance improvement (added transient currentTile to unit)

This commit is contained in:
Yair Morgenstern 2018-08-08 08:25:19 +03:00
parent 9d0035a8a6
commit 0ac87fa8c4
3 changed files with 12 additions and 15 deletions

View File

@ -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
}
/**

View File

@ -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
}
}

View File

@ -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
}
}
}