mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-03 13:30:51 +07:00
Unified "improvement on tile" checks
This commit is contained in:
parent
adaee7e7ab
commit
f50a757069
@ -8,7 +8,7 @@ Cannot open multiple gold selection popups in trade table
|
||||
|
||||
"No Maintenance costs for improvements in []" genericified - By givehub99
|
||||
|
||||
Tranlation updates
|
||||
Translation updates
|
||||
|
||||
## 3.10.12
|
||||
|
||||
|
@ -285,17 +285,27 @@ open class TileInfo {
|
||||
|
||||
/** Returns true if the [improvement] can be built on this [TileInfo] */
|
||||
fun canBuildImprovement(improvement: TileImprovement, civInfo: CivilizationInfo): Boolean {
|
||||
val topTerrain = getLastTerrain()
|
||||
return when {
|
||||
isCityCenter() -> false
|
||||
improvement.name == this.improvement -> false
|
||||
improvement.uniqueTo != null && improvement.uniqueTo != civInfo.civName -> false
|
||||
improvement.techRequired?.let { civInfo.tech.isResearched(it) } == false -> false
|
||||
"Cannot be built on bonus resource" in improvement.uniques && resource != null
|
||||
&& getTileResource().resourceType == ResourceType.Bonus -> false
|
||||
getOwner() != null && getOwner() != civInfo &&
|
||||
!improvement.hasUnique("Can be built outside your borders") -> false
|
||||
!canImprovementBeBuiltHere(improvement) -> false
|
||||
else -> getTileResource().improvement == improvement.name && hasViewableResource(civInfo)
|
||||
}
|
||||
}
|
||||
|
||||
/** Without regards to what civinfo it is, a lot of the checks are ust for the improvement on the tile.
|
||||
* Doubles as a check for the map editor.
|
||||
*/
|
||||
fun canImprovementBeBuiltHere(improvement: TileImprovement): Boolean {
|
||||
val topTerrain = getLastTerrain()
|
||||
|
||||
return when {
|
||||
improvement.name == this.improvement -> false
|
||||
isCityCenter() -> false
|
||||
"Cannot be built on bonus resource" in improvement.uniques && resource != null
|
||||
&& getTileResource().resourceType == ResourceType.Bonus -> false
|
||||
improvement.terrainsCanBeBuiltOn.contains(topTerrain.name) -> true
|
||||
improvement.name == "Road" && roadStatus == RoadStatus.None -> true
|
||||
improvement.name == "Railroad" && this.roadStatus != RoadStatus.Railroad -> true
|
||||
@ -306,7 +316,7 @@ open class TileInfo {
|
||||
improvement.hasUnique("Can also be built on tiles adjacent to fresh water")
|
||||
&& isAdjacentToFreshwater -> true
|
||||
"Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile() -> true
|
||||
else -> hasViewableResource(civInfo) && getTileResource().improvement == improvement.name
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -516,35 +516,9 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
|
||||
return
|
||||
}
|
||||
val improvement = tileInfo.getTileImprovement()!!
|
||||
val resource = if (tileInfo.resource!=null) tileInfo.getTileResource() else null
|
||||
when {
|
||||
// Precedence, simplified: terrainsCanBeBuiltOn, then improves-resource, then 'everywhere', default to false
|
||||
// 'everywhere' improvements (city ruins, encampments, ancient ruins, great improvements)
|
||||
// are recognized as without terrainsCanBeBuiltOn and with turnsToBuild == 0
|
||||
"Cannot be built on bonus resource" in improvement.uniques
|
||||
&& tileInfo.resource != null
|
||||
&& resource?.resourceType == ResourceType.Bonus
|
||||
-> tileInfo.improvement = null // forbid if this unique matches
|
||||
tileInfo.isLand // Fishing boats have Coast allowed even though they're meant resource-only
|
||||
&& topTerrain.name in improvement.terrainsCanBeBuiltOn
|
||||
-> Unit // allow where top terrain explicitly named
|
||||
resource?.improvement == improvement.name
|
||||
&& (!topTerrain.unbuildable || topTerrain.name in improvement.resourceTerrainAllow)
|
||||
-> Unit // allow where it improves a resource and feature OK
|
||||
tileInfo.isWater || topTerrain.impassable
|
||||
-> tileInfo.improvement = null // forbid if water or mountains
|
||||
improvement.terrainsCanBeBuiltOn.isEmpty() && improvement.turnsToBuild == 0
|
||||
// Allow Great Improvement but clear unbuildable terrain feature
|
||||
// Allow barbarian camps, ruins and similar without clear
|
||||
-> if (topTerrain.unbuildable && improvement.isGreatImprovement())
|
||||
tileInfo.terrainFeature = null
|
||||
topTerrain.unbuildable -> tileInfo.improvement = null // forbid on unbuildable feature
|
||||
improvement.hasUnique("Can also be built on tiles adjacent to fresh water")
|
||||
&& tileInfo.isAdjacentToFreshwater -> Unit // allow farms on tiles adjacent to fresh water
|
||||
"Can only be built on Coastal tiles" in improvement.uniques && tileInfo.isCoastalTile()
|
||||
-> Unit // allow Moai where appropriate
|
||||
else -> tileInfo.improvement = null
|
||||
}
|
||||
tileInfo.improvement = null // Unset, and check if it can be reset. If so, do it, if not, invalid.
|
||||
if (tileInfo.canImprovementBeBuiltHere(improvement))
|
||||
tileInfo.improvement = improvement.name
|
||||
}
|
||||
|
||||
private fun setCurrentHex(tileInfo: TileInfo, text:String){
|
||||
|
Loading…
Reference in New Issue
Block a user