Fixed crash when mod game had religion enabled but had no great prophet unit

Also slight deprecation
This commit is contained in:
yairm210 2021-09-11 23:05:07 +03:00
parent d59fe45f51
commit 619dfc5e09
3 changed files with 7 additions and 42 deletions

View File

@ -12,22 +12,15 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo) {
val newViewableInvisibleTiles = HashSet<TileInfo>() val newViewableInvisibleTiles = HashSet<TileInfo>()
newViewableInvisibleTiles.addAll(civInfo.getCivUnits() newViewableInvisibleTiles.addAll(civInfo.getCivUnits()
// "Can attack submarines" unique deprecated since 3.16.9 .filter { attacker -> attacker.hasUnique("Can see invisible [] units") }
.filter { attacker -> attacker.hasUnique("Can see invisible [] units") || attacker.hasUnique("Can attack submarines") }
.flatMap { attacker -> .flatMap { attacker ->
attacker.viewableTiles attacker.viewableTiles
.asSequence() .asSequence()
.filter { tile -> .filter { tile ->
( tile.militaryUnit != null tile.militaryUnit != null
&& attacker.getMatchingUniques("Can see invisible [] units") && attacker.getMatchingUniques("Can see invisible [] units")
.any { unique -> tile.militaryUnit!!.matchesFilter(unique.params[0]) } .any { unique -> tile.militaryUnit!!.matchesFilter(unique.params[0]) }
) || ( }
tile.militaryUnit != null
// "Can attack submarines" unique deprecated since 3.16.9
&& attacker.hasUnique("Can attack submarines")
&& tile.militaryUnit!!.matchesFilter("Submarine")
)
}
} }
) )
civInfo.viewableInvisibleUnitsTiles = newViewableInvisibleTiles civInfo.viewableInvisibleUnitsTiles = newViewableInvisibleTiles

View File

@ -134,11 +134,6 @@ class MapUnit {
var due: Boolean = true var due: Boolean = true
var isTransported: Boolean = false var isTransported: Boolean = false
// Deprecated since 3.16.11
@Deprecated("Deprecated since 3.16.11", replaceWith = ReplaceWith("abilityUsesLeft"))
var abilityUsedCount: HashMap<String, Int> = hashMapOf()
//
var abilityUsesLeft: HashMap<String, Int> = hashMapOf() var abilityUsesLeft: HashMap<String, Int> = hashMapOf()
var maxAbilityUses: HashMap<String, Int> = hashMapOf() var maxAbilityUses: HashMap<String, Int> = hashMapOf()
@ -159,9 +154,6 @@ class MapUnit {
toReturn.attacksThisTurn = attacksThisTurn toReturn.attacksThisTurn = attacksThisTurn
toReturn.promotions = promotions.clone() toReturn.promotions = promotions.clone()
toReturn.isTransported = isTransported toReturn.isTransported = isTransported
// Deprecated since 3.16.11
toReturn.abilityUsedCount.putAll(abilityUsedCount)
//
toReturn.abilityUsesLeft.putAll(abilityUsesLeft) toReturn.abilityUsesLeft.putAll(abilityUsesLeft)
toReturn.maxAbilityUses.putAll(maxAbilityUses) toReturn.maxAbilityUses.putAll(maxAbilityUses)
toReturn.religion = religion toReturn.religion = religion
@ -458,28 +450,7 @@ class MapUnit {
baseUnit = ruleset.units[name] baseUnit = ruleset.units[name]
?: throw java.lang.Exception("Unit $name is not found!") ?: throw java.lang.Exception("Unit $name is not found!")
// "Religion Spread" ability deprecated since 3.16.7, replaced with "Spread Religion"
if ("Religion Spread" in abilityUsedCount) {
abilityUsedCount[Constants.spreadReligionAbilityCount] = abilityUsedCount["Religion Spread"]!!
abilityUsedCount.remove("Religion Spread")
}
//
updateUniques() updateUniques()
// abilityUsedCount deprecated since 3.16.11, this is replacement code
if (abilityUsedCount.isNotEmpty()) {
for (ability in abilityUsedCount) {
val maxUsesOfThisAbility = getMatchingUniques("Can [] [] times")
.filter { it.params[0] == ability.key }
.sumOf { it.params[1].toInt() }
abilityUsesLeft[ability.key] = maxUsesOfThisAbility - ability.value
maxAbilityUses[ability.key] = maxUsesOfThisAbility
}
abilityUsedCount.clear()
}
//
} }
fun useMovementPoints(amount: Float) { fun useMovementPoints(amount: Float) {

View File

@ -381,6 +381,7 @@ object UniqueTriggerActivation {
return true return true
} }
"Gain enough Faith for []% of a Great Prophet" -> { "Gain enough Faith for []% of a Great Prophet" -> {
if (civInfo.religionManager.getGreatProphetEquivalent() == null) return false
val gainedFaith = val gainedFaith =
(civInfo.religionManager.faithForNextGreatProphet() * (unique.params[0].toFloat() / 100f)).toInt() (civInfo.religionManager.faithForNextGreatProphet() * (unique.params[0].toFloat() / 100f)).toInt()
if (gainedFaith == 0) return false if (gainedFaith == 0) return false