Resolved #1779 - Can now lock worked tiles to prevent them from being unassigned

This commit is contained in:
Yair Morgenstern 2020-03-29 12:42:58 +03:00
parent 9785cafa54
commit 378f56207c
12 changed files with 574 additions and 541 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 892 KiB

After

Width:  |  Height:  |  Size: 893 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 KiB

After

Width:  |  Height:  |  Size: 396 KiB

View file

@ -46,8 +46,12 @@ class CityInfo {
var expansion = CityExpansionManager()
var cityStats = CityStats()
/** All tiles that this city controls */
var tiles = HashSet<Vector2>()
/** Tiles that have population assigned to them */
var workedTiles = HashSet<Vector2>()
/** Tiles that the population in them won't be reassigned */
var lockedTiles = HashSet<Vector2>()
var isBeingRazed = false
var attackedThisTurn = false
var hasSoldBuildingThisTurn = false
@ -114,6 +118,7 @@ class CityInfo {
toReturn.expansion = expansion.clone()
toReturn.tiles = tiles
toReturn.workedTiles = workedTiles
toReturn.lockedTiles = lockedTiles
toReturn.isBeingRazed = isBeingRazed
toReturn.attackedThisTurn = attackedThisTurn
toReturn.resistanceCounter = resistanceCounter

View file

@ -112,7 +112,7 @@ class PopulationManager {
for(tile in cityInfo.workedTiles.map { cityInfo.tileMap[it] }) {
if (tile.getCity() != cityInfo)
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(tile.position)
if(tile.aerialDistanceTo(cityInfo.getCenterTile()) > 3) // AutoAssignPopulation used to assign pop outside of allowed range, fixed as of 2.10.4
if(tile.aerialDistanceTo(cityInfo.getCenterTile()) > 3)
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(tile.position)
}
@ -122,7 +122,8 @@ class PopulationManager {
else {
cityInfo.workedTiles.asSequence()
.map { cityInfo.tileMap[it] }
.minBy { Automation().rankTileForCityWork(it, cityInfo) }!!
.minBy { Automation().rankTileForCityWork(it, cityInfo)
+ (if(it.isLocked()) 10 else 0) }!!
}
val valueWorstTile = if(worstWorkedTile==null) 0f
else Automation().rankTileForCityWork(worstWorkedTile, cityInfo)

View file

@ -140,6 +140,11 @@ open class TileInfo {
return city!=null && city.workedTiles.contains(position)
}
fun isLocked(): Boolean{
val city = getCity()
return city!=null && city.lockedTiles.contains(position)
}
fun getTileStats(observingCiv: CivilizationInfo): Stats = getTileStats(getCity(), observingCiv)
fun getTileStats(city: CityInfo?, observingCiv: CivilizationInfo): Stats {

View file

@ -39,7 +39,7 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
private var cityStatsTable = CityStatsTable(this)
/** Displays tile info, alternate with selectedConstructionTable - sits on BOTTOM RIGHT */
private var tileTable = CityScreenTileTable(city)
private var tileTable = CityScreenTileTable(this)
/** Displays selected construction info, alternate with tileTable - sits on BOTTOM RIGHT */
private var selectedConstructionTable = ConstructionInfoTable(this.city)
@ -164,7 +164,8 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
if (!tileInfo.isWorked() && city.population.getFreePopulation() > 0) {
city.workedTiles.add(tileInfo.position)
game.settings.addCompletedTutorialTask("Reassign worked tiles")
} else if (tileInfo.isWorked()) city.workedTiles.remove(tileInfo.position)
} else if (tileInfo.isWorked() && !tileInfo.isLocked())
city.workedTiles.remove(tileInfo.position)
city.cityStats.update()
}
update()

View file

@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.UncivGame
import com.unciv.logic.city.CityInfo
import com.unciv.logic.map.TileInfo
import com.unciv.models.UncivSound
import com.unciv.models.stats.Stats
@ -12,8 +11,9 @@ import com.unciv.models.translations.tr
import com.unciv.ui.utils.*
import kotlin.math.roundToInt
class CityScreenTileTable(val city: CityInfo): Table(){
class CityScreenTileTable(val cityScreen: CityScreen): Table(){
val innerTable = Table()
val city = cityScreen.city
init{
innerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.5f))
add(innerTable).pad(2f).fill()
@ -58,7 +58,28 @@ class CityScreenTileTable(val city: CityInfo): Table(){
city.expansion.takeOwnership(selectedTile)
UncivGame.Current.setScreen(CityScreen(city))
}
innerTable.add(acquireTileButton)
innerTable.add(acquireTileButton).row()
}
if(city.workedTiles.contains(selectedTile.position)){
if(selectedTile.isLocked()) {
val unlockButton = TextButton("Unlock", CameraStageBaseScreen.skin)
unlockButton.onClick {
city.lockedTiles.remove(selectedTile.position)
update(selectedTile)
cityScreen.update()
}
innerTable.add(unlockButton).row()
}
else {
val lockButton = TextButton("Lock", CameraStageBaseScreen.skin)
lockButton.onClick {
city.lockedTiles.add(selectedTile.position)
update(selectedTile)
cityScreen.update()
}
innerTable.add(lockButton).row()
}
}
innerTable.pack()
pack()

View file

@ -19,8 +19,7 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin
isTransform=false // performance helper - nothing here is rotated or scaled
addActor(yieldGroup)
if (city.location == tileInfo.position) {
icons.populationIcon = ImageGetter.getImage("StatIcons/City_Center_(Civ6)")
addActor(icons.populationIcon)
icons.addPopulationIcon(ImageGetter.getImage("StatIcons/City_Center_(Civ6)"))
}
}
@ -34,7 +33,7 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin
baseLayerGroup.color.a = 0.3f
yieldGroup.isVisible = false
if (city.canAcquireTile(tileInfo))
addAcquirableIcon()
icons.addPopulationIcon(ImageGetter.getStatIcon("Acquire"))
}
tileInfo !in city.tilesInRange -> { // within city but not close enough to be workable
@ -42,7 +41,11 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin
baseLayerGroup.color.a = 0.5f
}
!tileInfo.isCityCenter() && icons.populationIcon==null -> { // workable
tileInfo.isLocked() -> {
icons.addPopulationIcon(ImageGetter.getImage("OtherIcons/Lock"))
}
!tileInfo.isCityCenter() -> { // workable
icons.addPopulationIcon()
isWorkable = true
}
@ -92,16 +95,4 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin
}
}
private fun addAcquirableIcon() {
icons.populationIcon = ImageGetter.getStatIcon("Acquire")
icons.populationIcon!!.run {
color = Color.GREEN.cpy().lerp(Color.BLACK, 0.5f)
setSize(20f, 20f)
center(this@CityTileGroup)
x += 20 // right
}
miscLayerGroup.addActor(icons.populationIcon)
}
}

View file

@ -32,10 +32,11 @@ class TileGroupIcons(val tileGroup: TileGroup){
tileIsViewable && showMilitaryUnit, 20f, viewingCiv)
}
fun addPopulationIcon() {
populationIcon = ImageGetter.getStatIcon("Population")
fun addPopulationIcon(icon: Image = ImageGetter.getStatIcon("Population")
.apply { color = Color.GREEN.cpy().lerp(Color.BLACK, 0.5f) }) {
populationIcon?.remove()
populationIcon = icon
populationIcon!!.run {
color = Color.GREEN.cpy().lerp(Color.BLACK, 0.5f)
setSize(20f, 20f)
center(tileGroup)
x += 20 // right

View file

@ -509,6 +509,7 @@ Unless otherwise specified, all the following are from [the Noun Project](https:
* [short range radar](https://thenounproject.com/search/?q=air%20range&i=2612731) by Vectors Point for Intercept range
* [Puppet](https://thenounproject.com/search/?q=puppet&i=285735) By Ben Davis for puppeted cities
* [City](https://thenounproject.com/search/?q=city&i=1765370) By Muhajir ila Robbi in the Icon center
* [Lock](https://thenounproject.com/search/?q=lock&i=3217613) by Vadim Solomakhin for locked tiles
# Sound credits