From 9ca7e7ac5b23ba14e22f9abc47b2c444b6b5c60a Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 20 Aug 2020 11:18:53 +0300 Subject: [PATCH] Dealt with some game assumptions about what exists, which may not be true in mods --- .../com/unciv/logic/automation/ConstructionAutomation.kt | 5 +++-- core/src/com/unciv/logic/automation/WorkerAutomation.kt | 2 +- core/src/com/unciv/logic/civilization/TechManager.kt | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt index ed36675f..60896456 100644 --- a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt +++ b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt @@ -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 } diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index ea78e45e..c42bf81c 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -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: diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index c2a2739c..c8a13d01 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -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 }