Worker automation fixed - ready for big update!

This commit is contained in:
Yair Morgenstern 2018-04-26 21:29:20 +03:00
parent 4d10e11482
commit ace5a6efbf
7 changed files with 20 additions and 14 deletions

View file

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 42
versionName "1.4.9"
versionCode 43
versionName "2.0.0"
}
buildTypes {
release {

View file

@ -168,8 +168,10 @@ class Automation {
val tileMap = unit.civInfo.gameInfo.tileMap
// find best city location within 5 tiles
val bestCityLocation = unit.getTile().getTilesInDistance(7)
.filterNot { it.getTilesInDistance(2).any { tid -> tid.isCityCenter } }
val tilesNearCities = unit.civInfo.gameInfo.civilizations.flatMap { it.cities }
.flatMap { it.getCenterTile().getTilesInDistance(2) }
val bestCityLocation = unit.getTile().getTilesInDistance(5)
.minus(tilesNearCities)
.sortedByDescending { rankTileAsCityCenter(it, unit.civInfo) }
.first()

View file

@ -26,7 +26,7 @@ public class WorkerAutomation(){
}
private fun findTileToWork(currentTile: TileInfo, civInfo: CivilizationInfo): TileInfo {
val selectedTile = currentTile.getTilesInDistance(4)
val workableTiles = currentTile.getTilesInDistance(4)
.filter {
(it.unit == null || it == currentTile)
&& it.improvement == null
@ -35,8 +35,12 @@ public class WorkerAutomation(){
&& UnitMovementAlgorithms(currentTile.tileMap) // the tile is actually reachable - more difficult than it seems!
.getShortestPath(currentTile.position, it.position, 2f, 2, civInfo).isNotEmpty()
}
.maxBy { getPriority(it, civInfo) }
if (selectedTile != null && getPriority(selectedTile, civInfo) > getPriority(currentTile,civInfo)) return selectedTile
val selectedTile = workableTiles.maxBy { getPriority(it, civInfo) }
if (selectedTile != null
&& getPriority(selectedTile, civInfo)>1
&& (!workableTiles.contains(currentTile)
|| getPriority(selectedTile, civInfo) > getPriority(currentTile,civInfo)))
return selectedTile
else return currentTile
}

View file

@ -79,7 +79,7 @@ class MapUnit {
val currentTile = getTile()
val tileMap = currentTile.tileMap
val finalDestinationTile = tileMap.get(destination)
val finalDestinationTile = tileMap[destination]
val distanceToTiles = getDistanceToTiles()
val destinationTileThisTurn:TileInfo

View file

@ -44,7 +44,7 @@ class UnitMovementAlgorithms(val tileMap: TileMap){
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])
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()) {
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
while (currentTile.position != origin) {
path.add(currentTile)

View file

@ -53,8 +53,8 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
open fun update(isViewable: Boolean) {
if (!tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)) {
// hexagon.color = Color.BLACK
// return
hexagon.color = Color.BLACK
return
}
updateTerrainFeatureImage()

View file

@ -47,7 +47,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
override fun update(isViewable: Boolean) {
super.update(isViewable)
//if (!tileInfo.explored) return
if (!tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)) return
if (populationImage != null) removePopulationIcon()
@ -94,7 +94,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
unitImage = null
}
if (tileInfo.unit != null /*&& isViewable*/) { // Tile is visible
if (tileInfo.unit != null && isViewable) { // Tile is visible
val unit = tileInfo.unit!!
unitImage = getUnitImage(unit.name, unit.civInfo.getCivilization().getColor())
addActor(unitImage!!)