Fixed cities built on pillages roads colored red
Some checks failed
Docker / build (push) Failing after 1m50s
Build and test / Check code and run unit tests (push) Failing after 5m39s
Conflict marking / main (push) Failing after 5s
Detekt / detekt (ubuntu-latest) (push) Failing after 45s
Generate mkdocs from docs folder / deploy (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 20s

This commit is contained in:
yairm210 2024-12-11 19:17:01 +02:00
parent f791b70997
commit 8519453d19
6 changed files with 21 additions and 30 deletions

View File

@ -5,7 +5,6 @@ import com.unciv.logic.city.CityConstructions
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
import com.unciv.logic.civilization.diplomacy.DiplomacyManager import com.unciv.logic.civilization.diplomacy.DiplomacyManager
import com.unciv.logic.civilization.managers.TechManager import com.unciv.logic.civilization.managers.TechManager
import com.unciv.logic.map.tile.RoadStatus
import com.unciv.models.ruleset.ModOptions import com.unciv.models.ruleset.ModOptions
import com.unciv.models.ruleset.PerpetualConstruction import com.unciv.models.ruleset.PerpetualConstruction
import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.Ruleset
@ -61,8 +60,7 @@ object BackwardCompatibility {
if (!ruleset.tileImprovements.containsKey(Constants.repair)) if (!ruleset.tileImprovements.containsKey(Constants.repair))
for (tile in tileMap.values) { for (tile in tileMap.values) {
if (tile.roadIsPillaged) { if (tile.roadIsPillaged) {
tile.roadStatus = RoadStatus.None tile.removeRoad()
tile.roadIsPillaged = false
} }
if (tile.improvementIsPillaged) { if (tile.improvementIsPillaged) {
tile.improvement = null tile.improvement = null

View File

@ -91,7 +91,7 @@ class City : IsPartOfGameInfoSerialization, INamed {
civ.gameInfo.getCities().filter { it != this && it.getCenterTile().isExplored(civ) && it.getCenterTile().aerialDistanceTo(getCenterTile()) <= 12 }.toList() civ.gameInfo.getCities().filter { it != this && it.getCenterTile().isExplored(civ) && it.getCenterTile().aerialDistanceTo(getCenterTile()) <= 12 }.toList()
} }
var cityAIFocus: String = CityFocus.NoFocus.name private var cityAIFocus: String = CityFocus.NoFocus.name
fun getCityFocus() = CityFocus.entries.firstOrNull { it.name == cityAIFocus } ?: CityFocus.NoFocus fun getCityFocus() = CityFocus.entries.firstOrNull { it.name == cityAIFocus } ?: CityFocus.NoFocus
fun setCityFocus(cityFocus: CityFocus){ cityAIFocus = cityFocus.name } fun setCityFocus(cityFocus: CityFocus){ cityAIFocus = cityFocus.name }
@ -385,15 +385,12 @@ class City : IsPartOfGameInfoSerialization, INamed {
CityConquestFunctions(this).moveToCiv(newCivInfo) CityConquestFunctions(this).moveToCiv(newCivInfo)
internal fun tryUpdateRoadStatus() { internal fun tryUpdateRoadStatus() {
if (getCenterTile().roadStatus == RoadStatus.None) { val requiredRoad = when{
val roadImprovement = getRuleset().roadImprovement getRuleset().railroadImprovement?.let { it.techRequired == null || it.techRequired in civ.tech.techsResearched } == true -> RoadStatus.Railroad
if (roadImprovement != null && roadImprovement.techRequired in civ.tech.techsResearched) getRuleset().roadImprovement?.let { it.techRequired == null || it.techRequired in civ.tech.techsResearched } == true -> RoadStatus.Road
getCenterTile().roadStatus = RoadStatus.Road else -> RoadStatus.None
} else if (getCenterTile().roadStatus != RoadStatus.Railroad) {
val railroadImprovement = getRuleset().railroadImprovement
if (railroadImprovement != null && railroadImprovement.techRequired in civ.tech.techsResearched)
getCenterTile().roadStatus = RoadStatus.Railroad
} }
getCenterTile().setRoadStatus(requiredRoad, civ)
} }
fun getGoldForSellingBuilding(buildingName: String) = fun getGoldForSellingBuilding(buildingName: String) =

View File

@ -80,6 +80,7 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
private val improvementQueue = ArrayList<ImprovementQueueEntry>(1) private val improvementQueue = ArrayList<ImprovementQueueEntry>(1)
var roadStatus = RoadStatus.None var roadStatus = RoadStatus.None
var roadIsPillaged = false var roadIsPillaged = false
private var roadOwner: String = "" // either who last built the road or last owner of tile private var roadOwner: String = "" // either who last built the road or last owner of tile
@ -885,11 +886,16 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
fun setImprovement(improvementStr: String, civToHandleCompletion: Civilization? = null, unit: MapUnit? = null) = fun setImprovement(improvementStr: String, civToHandleCompletion: Civilization? = null, unit: MapUnit? = null) =
improvementFunctions.setImprovement(improvementStr, civToHandleCompletion, unit) improvementFunctions.setImprovement(improvementStr, civToHandleCompletion, unit)
// function handling when adding a road to the tile // function handling when removing a road from the tile
fun addRoad(roadType: RoadStatus, creatingCivInfo: Civilization?) { fun removeRoad() = setRoadStatus(RoadStatus.None, null)
roadStatus = roadType
fun setRoadStatus(newRoadStatus: RoadStatus, creatingCivInfo: Civilization?) {
roadStatus = newRoadStatus
roadIsPillaged = false roadIsPillaged = false
if (getOwner() != null) {
if (newRoadStatus == RoadStatus.None && owningCity == null)
getRoadOwner()?.neutralRoads?.remove(this.position)
else if (getOwner() != null) {
roadOwner = getOwner()!!.civName roadOwner = getOwner()!!.civName
} else if (creatingCivInfo != null) { } else if (creatingCivInfo != null) {
roadOwner = creatingCivInfo.civName // neutral tile, use building unit roadOwner = creatingCivInfo.civName // neutral tile, use building unit
@ -897,15 +903,6 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
} }
} }
// function handling when removing a road from the tile
fun removeRoad() {
roadIsPillaged = false
if (roadStatus == RoadStatus.None) return
roadStatus = RoadStatus.None
if (owningCity == null)
getRoadOwner()?.neutralRoads?.remove(this.position)
}
fun startWorkingOnImprovement(improvement: TileImprovement, civInfo: Civilization, unit: MapUnit) { fun startWorkingOnImprovement(improvement: TileImprovement, civInfo: Civilization, unit: MapUnit) {
improvementQueue.clear() improvementQueue.clear()
queueImprovement(improvement, civInfo, unit) queueImprovement(improvement, civInfo, unit)

View File

@ -203,8 +203,8 @@ class TileImprovementFunctions(val tile: Tile) {
improvementName?.startsWith(Constants.remove) == true -> { improvementName?.startsWith(Constants.remove) == true -> {
activateRemovalImprovement(improvementName, civToActivateBroaderEffects) activateRemovalImprovement(improvementName, civToActivateBroaderEffects)
} }
improvementName == RoadStatus.Road.name -> tile.addRoad(RoadStatus.Road, civToActivateBroaderEffects) improvementName == RoadStatus.Road.name -> tile.setRoadStatus(RoadStatus.Road, civToActivateBroaderEffects)
improvementName == RoadStatus.Railroad.name -> tile.addRoad(RoadStatus.Railroad, civToActivateBroaderEffects) improvementName == RoadStatus.Railroad.name -> tile.setRoadStatus(RoadStatus.Railroad, civToActivateBroaderEffects)
improvementName == Constants.repair -> tile.setRepaired() improvementName == Constants.repair -> tile.setRepaired()
else -> { else -> {
tile.improvementIsPillaged = false tile.improvementIsPillaged = false

View File

@ -8,7 +8,6 @@ import com.unciv.logic.civilization.NotificationCategory
import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.civilization.NotificationIcon
import com.unciv.logic.map.mapgenerator.RiverGenerator import com.unciv.logic.map.mapgenerator.RiverGenerator
import com.unciv.logic.map.mapgenerator.RiverGenerator.RiverDirections import com.unciv.logic.map.mapgenerator.RiverGenerator.RiverDirections
import com.unciv.logic.map.tile.RoadStatus
import com.unciv.logic.map.tile.Tile import com.unciv.logic.map.tile.Tile
import com.unciv.models.ruleset.tile.Terrain import com.unciv.models.ruleset.tile.Terrain
import com.unciv.models.ruleset.tile.TerrainType import com.unciv.models.ruleset.tile.TerrainType
@ -42,7 +41,7 @@ internal class ConsoleTileCommands: ConsoleCommandNode {
"removeroad" to ConsoleAction("tile removeroad") { console, _ -> "removeroad" to ConsoleAction("tile removeroad") { console, _ ->
val selectedTile = console.getSelectedTile() val selectedTile = console.getSelectedTile()
selectedTile.roadStatus = RoadStatus.None selectedTile.removeRoad()
//todo this covers many cases but not all - do we really need to loop over all civs? //todo this covers many cases but not all - do we really need to loop over all civs?
selectedTile.getOwner()?.cache?.updateCitiesConnectedToCapital() selectedTile.getOwner()?.cache?.updateCitiesConnectedToCapital()
DevConsoleResponse.OK DevConsoleResponse.OK

View File

@ -224,7 +224,7 @@ class MapEditorEditImprovementsTab(
val road = RoadStatus.entries.firstOrNull { r -> r.name == it } val road = RoadStatus.entries.firstOrNull { r -> r.name == it }
if (road != null) if (road != null)
editTab.setBrush(it, "Improvement/$it", handlerType = BrushHandlerType.Road) { tile -> editTab.setBrush(it, "Improvement/$it", handlerType = BrushHandlerType.Road) { tile ->
tile.roadStatus = if (tile.roadStatus == road) RoadStatus.None else road tile.setRoadStatus(if (tile.roadStatus == road) RoadStatus.None else road, null)
} }
else else
editTab.setBrush(it, "Improvement/$it") { tile -> editTab.setBrush(it, "Improvement/$it") { tile ->