Added TileInfo.providsYield() - this will help us later

This commit is contained in:
Yair Morgenstern 2021-03-17 22:47:21 +02:00
parent cdc7739784
commit 755586eecd
6 changed files with 28 additions and 24 deletions

View File

@ -169,7 +169,7 @@ class WorkerAutomation(val unit: MapUnit) {
var priority = 0
if (tileInfo.getOwner() == civInfo) {
priority += 2
if (tileInfo.isWorked()) priority += 3
if (tileInfo.providesYield()) priority += 3
}
// give a minor priority to tiles that we could expand onto
else if (tileInfo.getOwner() == null && tileInfo.neighbors.any { it.getOwner() == civInfo })

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color
import com.unciv.logic.automation.Automation
import com.unciv.logic.map.TileInfo
import com.unciv.models.Counter
import com.unciv.models.stats.Stats
import com.unciv.ui.utils.withItem
import com.unciv.ui.utils.withoutItem
import kotlin.math.floor
@ -80,15 +79,15 @@ class PopulationManager {
//evaluate tiles
val bestTile: TileInfo? = cityInfo.getTiles()
.filter { it.aerialDistanceTo(cityInfo.getCenterTile()) <= 3 }
.filterNot { it.isWorked() || cityInfo.location == it.position }
.maxBy { Automation.rankTileForCityWork(it, cityInfo, foodWeight) }
.filterNot { it.providesYield() }
.maxByOrNull { Automation.rankTileForCityWork(it, cityInfo, foodWeight) }
val valueBestTile = if (bestTile == null) 0f
else Automation.rankTileForCityWork(bestTile, cityInfo, foodWeight)
val bestJob: String? = getMaxSpecialists()
.filter { specialistAllocations[it.key]!! < it.value }
.map { it.key }
.maxBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
.maxByOrNull { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
var valueBestSpecialist = 0f
@ -127,7 +126,7 @@ class PopulationManager {
else {
cityInfo.workedTiles.asSequence()
.map { cityInfo.tileMap[it] }
.minBy {
.minByOrNull {
Automation.rankTileForCityWork(it, cityInfo)
+(if (it.isLocked()) 10 else 0)
}!!
@ -137,7 +136,7 @@ class PopulationManager {
//evaluate specialists
val worstJob: String? = specialistAllocations.keys
.minBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
.minByOrNull { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
var valueWorstSpecialist = 0f
if (worstJob != null)
valueWorstSpecialist = Automation.rankSpecialist(getStatsOfSpecialist(worstJob), cityInfo)

View File

@ -21,8 +21,10 @@ class MapUnit {
@Transient
lateinit var civInfo: CivilizationInfo
@Transient
lateinit var baseUnit: BaseUnit
@Transient
internal lateinit var currentTile: TileInfo
@ -40,22 +42,31 @@ class MapUnit {
// which in turn is a component of getShortestPath and canReach
@Transient
var ignoresTerrainCost = false
@Transient
var allTilesCosts1 = false
@Transient
var canPassThroughImpassableTiles = false
@Transient
var roughTerrainPenalty = false
@Transient
var doubleMovementInCoast = false
@Transient
var doubleMovementInForestAndJungle = false
@Transient
var doubleMovementInSnowTundraAndHills = false
@Transient
var canEnterIceTiles = false
@Transient
var cannotEnterOceanTiles = false
@Transient
var cannotEnterOceanTilesUntilAstronomy = false
@ -75,12 +86,8 @@ class MapUnit {
* Name which should be displayed in UI
*/
fun displayName(): String {
return if(instanceName == null) {
name
}
else {
"$instanceName ({$name})"
}
return if (instanceName == null) name
else "$instanceName ({$name})"
}
var currentMovement: Float = 0f
@ -362,7 +369,7 @@ class MapUnit {
val destination = action!!.replace("moveTo ", "").split(",").dropLastWhile { it.isEmpty() }.toTypedArray()
val destinationVector = Vector2(destination[0].toFloat(), destination[1].toFloat())
val destinationTile = currentTile.tileMap[destinationVector]
if (!movement.canReach(destinationTile)){ // That tile that we were moving towards is now unreachable -
if (!movement.canReach(destinationTile)) { // That tile that we were moving towards is now unreachable -
// for instance we headed towards an unknown tile and it's apparently unreachable
action = null
return
@ -419,7 +426,7 @@ class MapUnit {
private fun tryProvideProductionToClosestCity() {
val tile = getTile()
val closestCity = civInfo.cities.minBy { it.getCenterTile().aerialDistanceTo(tile) }
val closestCity = civInfo.cities.minByOrNull { it.getCenterTile().aerialDistanceTo(tile) }
if (closestCity == null) return
val distance = closestCity.getCenterTile().aerialDistanceTo(tile)
var productionPointsToAdd = if (distance == 1) 20 else 20 - (distance - 2) * 5
@ -438,7 +445,7 @@ class MapUnit {
if (hasUnique("+10 HP when healing")) amountToHealBy += 10
val maxAdjacentHealingBonus = currentTile.getTilesInDistance(1)
.flatMap { it.getUnits().asSequence() }.map { it.adjacentHealingBonus() }.max()
.flatMap { it.getUnits().asSequence() }.map { it.adjacentHealingBonus() }.maxOrNull()
if (maxAdjacentHealingBonus != null)
amountToHealBy += maxAdjacentHealingBonus
if (hasUnique("All healing effects doubled"))

View File

@ -219,6 +219,7 @@ open class TileInfo {
}
fun isWorked(): Boolean = getWorkingCity() != null
fun providesYield() = getCity() != null && (isCityCenter() || isWorked())
fun isLocked(): Boolean {
val workingCity = getWorkingCity()

View File

@ -203,7 +203,7 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
selectedTile = tileInfo
selectedConstruction = null
if (tileGroup.isWorkable && canChangeState) {
if (!tileInfo.isWorked() && city.population.getFreePopulation() > 0) {
if (!tileInfo.providesYield() && city.population.getFreePopulation() > 0) {
city.workedTiles.add(tileInfo.position)
game.settings.addCompletedTutorialTask("Reassign worked tiles")
} else if (tileInfo.isWorked() && !tileInfo.isLocked())

View File

@ -74,11 +74,8 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin
yieldGroup.centerX(this)
yieldGroup.y = height * 0.25f - yieldGroup.height / 2
if (tileInfo.isWorked()) {
yieldGroup.color = Color.WHITE
} else if (!tileInfo.isCityCenter()) {
yieldGroup.color = Color.GRAY.cpy().apply { a = 0.5f }
}
if (tileInfo.providesYield()) yieldGroup.color = Color.WHITE
else yieldGroup.color = Color.GRAY.cpy().apply { a = 0.5f }
}
private fun updatePopulationIcon() {
@ -88,8 +85,8 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin
populationIcon.setPosition(width / 2 - populationIcon.width / 2,
height * 0.85f - populationIcon.height / 2)
if (tileInfo.isWorked()) populationIcon.color = Color.WHITE
else if (!tileInfo.isCityCenter()) populationIcon.color = Color.GRAY.cpy()
if (tileInfo.providesYield()) populationIcon.color = Color.WHITE
else populationIcon.color = Color.GRAY.cpy()
populationIcon.toFront()
}