mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 12:05:54 -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.improvement == null
|
||||||
&& it.canBuildImprovement(chooseImprovement(it), civInfo)
|
&& it.canBuildImprovement(chooseImprovement(it), civInfo)
|
||||||
&& {val city=it.getCity(); city==null || it.getCity()?.civInfo == civInfo}() // don't work tiles belonging to another civ
|
&& {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!
|
}.sortedByDescending { getPriority(it, civInfo) }.toMutableList()
|
||||||
.getShortestPath(currentTile.position, it.position, 2f, 2, civInfo).isNotEmpty()
|
|
||||||
}
|
// the tile needs to be actually reachable - more difficult than it seems,
|
||||||
val selectedTile = workableTiles.maxBy { getPriority(it, civInfo) }
|
// 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
|
if (selectedTile != null
|
||||||
&& getPriority(selectedTile, civInfo)>1
|
&& getPriority(selectedTile, civInfo)>1
|
||||||
&& (!workableTiles.contains(currentTile)
|
&& (!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)
|
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) } }
|
tilesToCheck = newTilesToCheck.filterNot {tile -> tile.neighbors.all{newTilesToCheck.contains(it) || tilesToCheck.contains(it) } }
|
||||||
|
|
||||||
distance++
|
distance++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,12 @@ object ImageGetter {
|
|||||||
|
|
||||||
private fun getTextureRegion(fileName: String): TextureRegion {
|
private fun getTextureRegion(fileName: String): TextureRegion {
|
||||||
try {
|
try {
|
||||||
if (!textureRegionByFileName.containsKey(fileName))
|
if (!textureRegionByFileName.containsKey(fileName)) {
|
||||||
textureRegionByFileName[fileName] = TextureRegion(Texture(Gdx.files.internal(fileName)))
|
val texture = Texture(Gdx.files.internal(fileName))
|
||||||
|
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||||
|
textureRegionByFileName[fileName] = TextureRegion(texture)
|
||||||
|
}
|
||||||
|
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
print("File $fileName not found!")
|
print("File $fileName not found!")
|
||||||
throw ex
|
throw ex
|
||||||
|
@ -51,7 +51,6 @@ class UnitActions {
|
|||||||
UnitAction("Stop movement", {
|
UnitAction("Stop movement", {
|
||||||
unitTable.currentlyExecutingAction = null
|
unitTable.currentlyExecutingAction = null
|
||||||
unit.action=null
|
unit.action=null
|
||||||
tileMapHolder.updateTiles()
|
|
||||||
},unit.currentMovement != 0f)
|
},unit.currentMovement != 0f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +62,6 @@ class UnitActions {
|
|||||||
unit.civInfo.addCity(tile.position)
|
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
|
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!
|
tile.unit = null // Remove settler!
|
||||||
worldScreen.update()
|
|
||||||
},
|
},
|
||||||
unit.currentMovement != 0f &&
|
unit.currentMovement != 0f &&
|
||||||
!tile.getTilesInDistance(2).any { it.isCityCenter() })
|
!tile.getTilesInDistance(2).any { it.isCityCenter() })
|
||||||
@ -109,7 +107,6 @@ class UnitActions {
|
|||||||
{
|
{
|
||||||
unit.civInfo.goldenAges.enterGoldenAge()
|
unit.civInfo.goldenAges.enterGoldenAge()
|
||||||
tile.unit = null// destroy!
|
tile.unit = null// destroy!
|
||||||
worldScreen.update()
|
|
||||||
},unit.currentMovement != 0f
|
},unit.currentMovement != 0f
|
||||||
)
|
)
|
||||||
actionList += UnitAction("Construct Landmark",
|
actionList += UnitAction("Construct Landmark",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user