mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 02:42:16 -04:00
Minor performance enhancements for unit movement
This commit is contained in:
parent
fb1f381f06
commit
6cd78ca926
@ -32,10 +32,18 @@ public class WorkerAutomation(){
|
||||
&& it.improvement == null
|
||||
&& it.canBuildImprovement(chooseImprovement(it), civInfo)
|
||||
&& {val city=it.getCity(); city==null || it.getCity()?.civInfo == civInfo}() // don't work tiles belonging to another civ
|
||||
&& UnitMovementAlgorithms(currentTile.tileMap) // the tile is actually reachable - more difficult than it seems!
|
||||
.getShortestPath(currentTile.position, it.position, 2f, 2, civInfo).isNotEmpty()
|
||||
}
|
||||
val selectedTile = workableTiles.maxBy { getPriority(it, civInfo) }
|
||||
}.sortedByDescending { getPriority(it, civInfo) }.toMutableList()
|
||||
|
||||
// the tile needs to be actually reachable - more difficult than it seems,
|
||||
// which is why we DON'T calculate this for every possible tile in the radius,
|
||||
// but only for the tile that's about to be chosen.
|
||||
while (workableTiles.isNotEmpty()
|
||||
&& UnitMovementAlgorithms(currentTile.tileMap)
|
||||
.getShortestPath(currentTile.position, workableTiles.first().position,2f, 2, civInfo)
|
||||
.isEmpty())
|
||||
workableTiles.removeAt(0)
|
||||
|
||||
val selectedTile = workableTiles.firstOrNull()
|
||||
if (selectedTile != null
|
||||
&& getPriority(selectedTile, civInfo)>1
|
||||
&& (!workableTiles.contains(currentTile)
|
||||
|
@ -81,7 +81,11 @@ class UnitMovementAlgorithms(val tileMap: TileMap){
|
||||
|
||||
if(newTilesToCheck.isEmpty()) return emptyList() // there is NO PATH (eg blocked by enemy units)
|
||||
|
||||
// no need to check tiles that are surrounded by reachable tiles, only need to check the edgemost tiles.
|
||||
// Because anything we can reach from intermediate tiles, can be more easily reached by the edgemost tiles,
|
||||
// since we'll have to pass through an edgemost tile in order to reach the diestination anyway
|
||||
tilesToCheck = newTilesToCheck.filterNot {tile -> tile.neighbors.all{newTilesToCheck.contains(it) || tilesToCheck.contains(it) } }
|
||||
|
||||
distance++
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,12 @@ object ImageGetter {
|
||||
|
||||
private fun getTextureRegion(fileName: String): TextureRegion {
|
||||
try {
|
||||
if (!textureRegionByFileName.containsKey(fileName))
|
||||
textureRegionByFileName[fileName] = TextureRegion(Texture(Gdx.files.internal(fileName)))
|
||||
if (!textureRegionByFileName.containsKey(fileName)) {
|
||||
val texture = Texture(Gdx.files.internal(fileName))
|
||||
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||
textureRegionByFileName[fileName] = TextureRegion(texture)
|
||||
}
|
||||
|
||||
} catch (ex: Exception) {
|
||||
print("File $fileName not found!")
|
||||
throw ex
|
||||
|
@ -51,7 +51,6 @@ class UnitActions {
|
||||
UnitAction("Stop movement", {
|
||||
unitTable.currentlyExecutingAction = null
|
||||
unit.action=null
|
||||
tileMapHolder.updateTiles()
|
||||
},unit.currentMovement != 0f)
|
||||
}
|
||||
|
||||
@ -63,7 +62,6 @@ class UnitActions {
|
||||
unit.civInfo.addCity(tile.position)
|
||||
unitTable.currentlyExecutingAction = null // In case the settler was in the middle of doing something and we then founded a city with it
|
||||
tile.unit = null // Remove settler!
|
||||
worldScreen.update()
|
||||
},
|
||||
unit.currentMovement != 0f &&
|
||||
!tile.getTilesInDistance(2).any { it.isCityCenter() })
|
||||
@ -109,7 +107,6 @@ class UnitActions {
|
||||
{
|
||||
unit.civInfo.goldenAges.enterGoldenAge()
|
||||
tile.unit = null// destroy!
|
||||
worldScreen.update()
|
||||
},unit.currentMovement != 0f
|
||||
)
|
||||
actionList += UnitAction("Construct Landmark",
|
||||
|
Loading…
x
Reference in New Issue
Block a user