Un-hardcoded some settler checks

This commit is contained in:
Yair Morgenstern 2020-12-20 22:55:36 +02:00
parent 585be1b2be
commit 566a9529ef
4 changed files with 51 additions and 45 deletions

View File

@ -67,8 +67,6 @@ object Constants {
const val disabled = "disabled" const val disabled = "disabled"
const val enabled = "enabled" const val enabled = "enabled"
const val scienceConversionEffect = "Production to science conversion in cities increased by 33%"
const val ancientEra = "Ancient era" const val ancientEra = "Ancient era"
const val classicalEra = "Classical era" const val classicalEra = "Classical era"
const val medievalEra = "Medieval era" const val medievalEra = "Medieval era"

View File

@ -68,10 +68,12 @@ class WorkerAutomation(val unit: MapUnit) {
val targetRoad = unit.civInfo.tech.getBestRoadAvailable() val targetRoad = unit.civInfo.tech.getBestRoadAvailable()
val citiesThatNeedConnecting = unit.civInfo.cities.asSequence() val citiesThatNeedConnecting = unit.civInfo.cities.asSequence()
.filter { it.population.population>3 && !it.isCapital() && !it.isBeingRazed //City being razed should not be connected. .filter {
it.population.population > 3 && !it.isCapital() && !it.isBeingRazed //City being razed should not be connected.
&& !it.cityStats.isConnectedToCapital(targetRoad) && !it.cityStats.isConnectedToCapital(targetRoad)
// Cities that are too far away make the caReach() calculations devastatingly long // Cities that are too far away make the caReach() calculations devastatingly long
&& it.getCenterTile().aerialDistanceTo(unit.getTile()) < 20 } && it.getCenterTile().aerialDistanceTo(unit.getTile()) < 20
}
if (citiesThatNeedConnecting.none()) return false // do nothing. if (citiesThatNeedConnecting.none()) return false // do nothing.
val citiesThatNeedConnectingBfs = citiesThatNeedConnecting val citiesThatNeedConnectingBfs = citiesThatNeedConnecting
@ -217,6 +219,7 @@ class WorkerAutomation(val unit: MapUnit) {
if (improvementString == null) return null if (improvementString == null) return null
return unit.civInfo.gameInfo.ruleSet.tileImprovements[improvementString] // For mods, the tile improvement may not exist, so don't assume. 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 { private fun isImprovementOnFeatureAllowed(tile: TileInfo, civInfo: CivilizationInfo): Boolean {
// routine assumes the caller ensured that terrainFeature and resource are both present // routine assumes the caller ensured that terrainFeature and resource are both present
val resourceImprovementName = tile.getTileResource().improvement val resourceImprovementName = tile.getTileResource().improvement
@ -226,8 +229,7 @@ class WorkerAutomation(val unit: MapUnit) {
return resourceImprovement.resourceTerrainAllow.contains(tile.terrainFeature!!) return resourceImprovement.resourceTerrainAllow.contains(tile.terrainFeature!!)
} }
private fun isAcceptableTileForFort(tile: TileInfo, civInfo: CivilizationInfo): Boolean private fun isAcceptableTileForFort(tile: TileInfo, civInfo: CivilizationInfo): Boolean {
{
if (tile.isCityCenter() // don't build fort in the city if (tile.isCityCenter() // don't build fort in the city
|| !tile.isLand // don't build fort in the water || !tile.isLand // don't build fort in the water
|| tile.improvement == Constants.fort // don't build fort if it is already here || tile.improvement == Constants.fort // don't build fort if it is already here
@ -251,8 +253,9 @@ class WorkerAutomation(val unit: MapUnit) {
// don't build forts too close to the cities // don't build forts too close to the cities
if (closeTile.isCityCenter()) return false if (closeTile.isCityCenter()) return false
// don't build forts too close to other forts // don't build forts too close to other forts
if (closeTile.improvement == Constants.fort || closeTile.improvement == Constants.citadel if (closeTile.improvement != null
|| closeTile.improvementInProgress == Constants.fort) return false && closeTile.getTileImprovement()!!.uniqueObjects.any { it.placeholderText == "Gives a defensive bonus of []%" }
|| closeTile.improvementInProgress != Constants.fort) return false
// there is another better tile for the fort // there is another better tile for the fort
if (!tile.isHill() && closeTile.isHill() && if (!tile.isHill() && closeTile.isHill() &&
isAcceptableTileForFort(closeTile, civInfo)) return false isAcceptableTileForFort(closeTile, civInfo)) return false
@ -273,7 +276,8 @@ class WorkerAutomation(val unit: MapUnit) {
ThreatLevel.Medium -> 10 ThreatLevel.Medium -> 10
ThreatLevel.High -> 15 // they are strong, let's built until they reach us ThreatLevel.High -> 15 // they are strong, let's built until they reach us
ThreatLevel.VeryHigh -> 20 ThreatLevel.VeryHigh -> 20
} } }
}
val enemyCivsIsCloseEnough = enemyCivs.filter { NextTurnAutomation.getMinDistanceBetweenCities(civInfo, it) <= threatMapping(it) } val enemyCivsIsCloseEnough = enemyCivs.filter { NextTurnAutomation.getMinDistanceBetweenCities(civInfo, it) <= threatMapping(it) }
// no threat, let's not build fort // no threat, let's not build fort
if (enemyCivsIsCloseEnough.isEmpty()) return false if (enemyCivsIsCloseEnough.isEmpty()) return false

View File

@ -41,12 +41,14 @@ object UniqueTriggerActivation {
when (unique.placeholderText) { when (unique.placeholderText) {
"Free [] appears" -> { "Free [] appears" -> {
val unitName = unique.params[0] val unitName = unique.params[0]
if (chosenCity != null && (unitName != Constants.settler || !civInfo.isOneCityChallenger())) val unit = civInfo.gameInfo.ruleSet.units[unitName]
if (chosenCity != null && unit != null && (!unit.uniques.contains("Founds a new city") || !civInfo.isOneCityChallenger()))
civInfo.addUnit(unitName, chosenCity) civInfo.addUnit(unitName, chosenCity)
} }
"[] free [] units appear" -> { "[] free [] units appear" -> {
val unitName = unique.params[1] val unitName = unique.params[1]
if (chosenCity!=null && (unitName != Constants.settler || !civInfo.isOneCityChallenger())) val unit = civInfo.gameInfo.ruleSet.units[unitName]
if (chosenCity != null && unit != null && (!unit.uniques.contains("Founds a new city") || !civInfo.isOneCityChallenger()))
for (i in 1..unique.params[0].toInt()) for (i in 1..unique.params[0].toInt())
civInfo.addUnit(unitName, chosenCity) civInfo.addUnit(unitName, chosenCity)
} }
@ -84,9 +86,11 @@ object UniqueTriggerActivation {
val promotion = unique.params[1] val promotion = unique.params[1]
for (unit in civInfo.getCivUnits()) for (unit in civInfo.getCivUnits())
if (unit.matchesFilter(filter) if (unit.matchesFilter(filter)
|| (civInfo.gameInfo.ruleSet.unitPromotions.values.any { it.name == promotion || (civInfo.gameInfo.ruleSet.unitPromotions.values.any {
&& unit.type.name in it.unitTypes })) it.name == promotion && unit.type.name in it.unitTypes
unit.promotions.addPromotion(promotion, isFree = true)} }))
unit.promotions.addPromotion(promotion, isFree = true)
}
} }
} }