Dealt with some game assumptions about what exists, which may not be true in mods

This commit is contained in:
Yair Morgenstern 2020-08-20 11:18:53 +03:00
parent 67ce953c62
commit 9ca7e7ac5b
3 changed files with 8 additions and 6 deletions

View file

@ -27,8 +27,9 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
val militaryUnits = civUnits.filter { !it.type.isCivilian()}.count()
val workers = civUnits.filter { it.hasUnique(Constants.workerUnique) }.count().toFloat()
val cities = civInfo.cities.size
val canBuildWorkboat = cityInfo.cityConstructions.getConstructableUnits().map { it.name }.contains("Work Boats")
&& !cityInfo.getTiles().any { it.civilianUnit?.name == "Work Boats" }
val canBuildWorkboat = cityInfo.cityConstructions.getConstructableUnits()
.any { it.uniques.contains("May create improvements on water resources") }
&& !cityInfo.getTiles().any { it.civilianUnit?.hasUnique("May create improvements on water resources")==true }
val needWorkboat = canBuildWorkboat
&& cityInfo.getTiles().any { it.isWater && it.hasViewableResource(civInfo) && it.improvement == null }

View file

@ -211,7 +211,7 @@ class WorkerAutomation(val unit: MapUnit) {
else -> null
}
if (improvementString == null) return null
return unit.civInfo.gameInfo.ruleSet.tileImprovements[improvementString]!!
return unit.civInfo.gameInfo.ruleSet.tileImprovements[improvementString] // For mods, the tile improvement may not exist, so don't assume.
}
private fun isImprovementOnFeatureAllowed(tile: TileInfo, civInfo: CivilizationInfo): Boolean {
// Old hardcoded logic amounts to:

View file

@ -323,10 +323,11 @@ class TechManager {
}
fun getBestRoadAvailable(): RoadStatus {
if (!isResearched(RoadStatus.Road.improvement(getRuleset())!!.techRequired!!)) return RoadStatus.None
val roadImprovement = RoadStatus.Road.improvement(getRuleset()) // May not exist in mods
if (roadImprovement == null || !isResearched(roadImprovement.techRequired!!)) return RoadStatus.None
val techEnablingRailroad = RoadStatus.Railroad.improvement(getRuleset())!!.techRequired!!
val canBuildRailroad = isResearched(techEnablingRailroad)
val railroadImprovement = RoadStatus.Railroad.improvement(getRuleset())
val canBuildRailroad = railroadImprovement!=null && isResearched(railroadImprovement.techRequired!!)
return if (canBuildRailroad) RoadStatus.Railroad else RoadStatus.Road
}