Remove "Camp" hardcoding and allow mods to do similar things (#2417)

This commit is contained in:
SomeTroglodyte 2020-04-16 09:41:29 +02:00 committed by GitHub
parent 2594777b52
commit 048ce0d3c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 6 deletions

View File

@ -39,6 +39,7 @@
// Resource-specific
{
"name": "Camp",
"resourceTerrainAllow": ["Forest"],
"turnsToBuild": 7,
"techRequired": "Trapping",
"improvingTech": "Economics",

View File

@ -177,10 +177,10 @@ class WorkerAutomation(val unit: MapUnit) {
private fun chooseImprovement(tile: TileInfo, civInfo: CivilizationInfo): TileImprovement? {
val improvementStringForResource : String ?= when {
tile.resource == null || !tile.hasViewableResource(civInfo) -> null
tile.terrainFeature == "Marsh" -> "Remove Marsh"
tile.terrainFeature == "Fallout" -> "Remove Fallout"
tile.terrainFeature == Constants.jungle -> "Remove Jungle"
tile.terrainFeature == Constants.forest && tile.getTileResource().improvement!="Camp" -> "Remove Forest"
tile.terrainFeature == "Marsh" && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Marsh"
tile.terrainFeature == "Fallout" && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Fallout" // for really mad modders
tile.terrainFeature == Constants.jungle && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Jungle"
tile.terrainFeature == Constants.forest && !isImprovementOnFeatureAllowed(tile,civInfo) -> "Remove Forest"
else -> tile.getTileResource().improvement
}
@ -197,7 +197,7 @@ class WorkerAutomation(val unit: MapUnit) {
evaluateFortPlacement(tile,civInfo) -> "Fort"
// I think we can assume that the unique improvement is better
uniqueImprovement!=null && tile.canBuildImprovement(uniqueImprovement,civInfo) -> uniqueImprovement.name
tile.terrainFeature == "Fallout" -> "Remove Fallout"
tile.terrainFeature == "Marsh" -> "Remove Marsh"
tile.terrainFeature == Constants.jungle -> "Trading post"
@ -211,6 +211,17 @@ class WorkerAutomation(val unit: MapUnit) {
if (improvementString == null) return null
return unit.civInfo.gameInfo.ruleSet.tileImprovements[improvementString]!!
}
private fun isImprovementOnFeatureAllowed(tile: TileInfo, civInfo: CivilizationInfo): Boolean {
// Old hardcoded logic amounts to:
//return tile.terrainFeature == Constants.forest && tile.getTileResource().improvement == "Camp"
// routine assumes the caller ensured that terrainFeature and resource are both present
val resourceImprovementName = tile.getTileResource().improvement
?: return false
val resourceImprovement = civInfo.gameInfo.ruleSet.tileImprovements[resourceImprovementName]
?: return false
return resourceImprovement.resourceTerrainAllow.contains(tile.terrainFeature!!)
}
private fun isAcceptableTileForFort(tile: TileInfo, civInfo: CivilizationInfo): Boolean
{

View File

@ -281,7 +281,7 @@ open class TileInfo {
improvement.name == "Remove Road" && this.roadStatus == RoadStatus.Road -> true
improvement.name == "Remove Railroad" && this.roadStatus == RoadStatus.Railroad -> true
improvement.name == Constants.cancelImprovementOrder && this.improvementInProgress != null -> true
topTerrain.unbuildable && !(topTerrain.name == Constants.forest && improvement.name == "Camp") -> false
topTerrain.unbuildable && (topTerrain.name !in improvement.resourceTerrainAllow) -> false
"Can only be built on Coastal tiles" in improvement.uniques && isCoastalTile() -> true
else -> hasViewableResource(civInfo) && getTileResource().improvement == improvement.name
}

View File

@ -11,6 +11,11 @@ import kotlin.math.roundToInt
class TileImprovement : NamedStats() {
var terrainsCanBeBuiltOn: Collection<String> = ArrayList()
// Used only for Camp - but avoid hardcoded comparison and *allow modding*
// Terrain Features that need not be cleared if the improvement enables a resource
var resourceTerrainAllow: Collection<String> = ArrayList()
var techRequired: String? = null
var improvingTech: String? = null