mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 10:54:19 -04:00
Worker automation fixed - ready for big update!
This commit is contained in:
parent
4d10e11482
commit
ace5a6efbf
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 42
|
versionCode 43
|
||||||
versionName "1.4.9"
|
versionName "2.0.0"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -168,8 +168,10 @@ class Automation {
|
|||||||
val tileMap = unit.civInfo.gameInfo.tileMap
|
val tileMap = unit.civInfo.gameInfo.tileMap
|
||||||
|
|
||||||
// find best city location within 5 tiles
|
// find best city location within 5 tiles
|
||||||
val bestCityLocation = unit.getTile().getTilesInDistance(7)
|
val tilesNearCities = unit.civInfo.gameInfo.civilizations.flatMap { it.cities }
|
||||||
.filterNot { it.getTilesInDistance(2).any { tid -> tid.isCityCenter } }
|
.flatMap { it.getCenterTile().getTilesInDistance(2) }
|
||||||
|
val bestCityLocation = unit.getTile().getTilesInDistance(5)
|
||||||
|
.minus(tilesNearCities)
|
||||||
.sortedByDescending { rankTileAsCityCenter(it, unit.civInfo) }
|
.sortedByDescending { rankTileAsCityCenter(it, unit.civInfo) }
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class WorkerAutomation(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun findTileToWork(currentTile: TileInfo, civInfo: CivilizationInfo): TileInfo {
|
private fun findTileToWork(currentTile: TileInfo, civInfo: CivilizationInfo): TileInfo {
|
||||||
val selectedTile = currentTile.getTilesInDistance(4)
|
val workableTiles = currentTile.getTilesInDistance(4)
|
||||||
.filter {
|
.filter {
|
||||||
(it.unit == null || it == currentTile)
|
(it.unit == null || it == currentTile)
|
||||||
&& it.improvement == null
|
&& it.improvement == null
|
||||||
@ -35,8 +35,12 @@ public class WorkerAutomation(){
|
|||||||
&& UnitMovementAlgorithms(currentTile.tileMap) // the tile is actually reachable - more difficult than it seems!
|
&& UnitMovementAlgorithms(currentTile.tileMap) // the tile is actually reachable - more difficult than it seems!
|
||||||
.getShortestPath(currentTile.position, it.position, 2f, 2, civInfo).isNotEmpty()
|
.getShortestPath(currentTile.position, it.position, 2f, 2, civInfo).isNotEmpty()
|
||||||
}
|
}
|
||||||
.maxBy { getPriority(it, civInfo) }
|
val selectedTile = workableTiles.maxBy { getPriority(it, civInfo) }
|
||||||
if (selectedTile != null && getPriority(selectedTile, civInfo) > getPriority(currentTile,civInfo)) return selectedTile
|
if (selectedTile != null
|
||||||
|
&& getPriority(selectedTile, civInfo)>1
|
||||||
|
&& (!workableTiles.contains(currentTile)
|
||||||
|
|| getPriority(selectedTile, civInfo) > getPriority(currentTile,civInfo)))
|
||||||
|
return selectedTile
|
||||||
else return currentTile
|
else return currentTile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class MapUnit {
|
|||||||
val currentTile = getTile()
|
val currentTile = getTile()
|
||||||
val tileMap = currentTile.tileMap
|
val tileMap = currentTile.tileMap
|
||||||
|
|
||||||
val finalDestinationTile = tileMap.get(destination)
|
val finalDestinationTile = tileMap[destination]
|
||||||
val distanceToTiles = getDistanceToTiles()
|
val distanceToTiles = getDistanceToTiles()
|
||||||
|
|
||||||
val destinationTileThisTurn:TileInfo
|
val destinationTileThisTurn:TileInfo
|
||||||
|
@ -44,7 +44,7 @@ class UnitMovementAlgorithms(val tileMap: TileMap){
|
|||||||
|
|
||||||
|
|
||||||
fun getShortestPath(origin: Vector2, destination: Vector2, currentMovement: Float, maxMovement: Int, civInfo: CivilizationInfo): List<TileInfo> {
|
fun getShortestPath(origin: Vector2, destination: Vector2, currentMovement: Float, maxMovement: Int, civInfo: CivilizationInfo): List<TileInfo> {
|
||||||
if(origin.equals(destination)) return listOf(tileMap[origin]) // edge case that's needed, so that workers will know that they can reach their own tile. *sigh*
|
if(origin.equals(destination)) return listOf(tileMap[origin]) // edge case that's needed, so that workers will know that they can reach their own tile. *sig
|
||||||
|
|
||||||
var tilesToCheck: List<TileInfo> = listOf(tileMap[origin])
|
var tilesToCheck: List<TileInfo> = listOf(tileMap[origin])
|
||||||
val movementTreeParents = HashMap<TileInfo, TileInfo?>() // contains a map of "you can get from X to Y in that turn"
|
val movementTreeParents = HashMap<TileInfo, TileInfo?>() // contains a map of "you can get from X to Y in that turn"
|
||||||
@ -70,7 +70,7 @@ class UnitMovementAlgorithms(val tileMap: TileMap){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (distanceToDestination.isNotEmpty()) {
|
if (distanceToDestination.isNotEmpty()) {
|
||||||
val path = ArrayList<TileInfo>() // Traverse the tree upwards to get the list of tiles leading to the destination,
|
val path = mutableListOf(tileMap[destination]) // Traverse the tree upwards to get the list of tiles leading to the destination,
|
||||||
var currentTile = distanceToDestination.minBy { it.value }!!.key
|
var currentTile = distanceToDestination.minBy { it.value }!!.key
|
||||||
while (currentTile.position != origin) {
|
while (currentTile.position != origin) {
|
||||||
path.add(currentTile)
|
path.add(currentTile)
|
||||||
|
@ -53,8 +53,8 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||||||
|
|
||||||
open fun update(isViewable: Boolean) {
|
open fun update(isViewable: Boolean) {
|
||||||
if (!tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)) {
|
if (!tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)) {
|
||||||
// hexagon.color = Color.BLACK
|
hexagon.color = Color.BLACK
|
||||||
// return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTerrainFeatureImage()
|
updateTerrainFeatureImage()
|
||||||
|
@ -47,7 +47,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||||||
|
|
||||||
override fun update(isViewable: Boolean) {
|
override fun update(isViewable: Boolean) {
|
||||||
super.update(isViewable)
|
super.update(isViewable)
|
||||||
//if (!tileInfo.explored) return
|
if (!tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)) return
|
||||||
|
|
||||||
if (populationImage != null) removePopulationIcon()
|
if (populationImage != null) removePopulationIcon()
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||||||
unitImage = null
|
unitImage = null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tileInfo.unit != null /*&& isViewable*/) { // Tile is visible
|
if (tileInfo.unit != null && isViewable) { // Tile is visible
|
||||||
val unit = tileInfo.unit!!
|
val unit = tileInfo.unit!!
|
||||||
unitImage = getUnitImage(unit.name, unit.civInfo.getCivilization().getColor())
|
unitImage = getUnitImage(unit.name, unit.civInfo.getCivilization().getColor())
|
||||||
addActor(unitImage!!)
|
addActor(unitImage!!)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user