mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
Intercept damage bonus (from promotions) treated as a unique
This commit is contained in:
parent
588aa7a177
commit
9034729dfd
@ -73,8 +73,6 @@ class MapUnit {
|
|||||||
private const val ANCIENT_RUIN_MAP_REVEAL_OFFSET = 4
|
private const val ANCIENT_RUIN_MAP_REVEAL_OFFSET = 4
|
||||||
private const val ANCIENT_RUIN_MAP_REVEAL_RANGE = 4
|
private const val ANCIENT_RUIN_MAP_REVEAL_RANGE = 4
|
||||||
private const val ANCIENT_RUIN_MAP_REVEAL_CHANCE = 0.8f
|
private const val ANCIENT_RUIN_MAP_REVEAL_CHANCE = 0.8f
|
||||||
const val BONUS_WHEN_INTERCEPTING = "Bonus when intercepting"
|
|
||||||
const val CHANCE_TO_INTERCEPT_AIR_ATTACKS = " chance to intercept air attacks"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//region pure functions
|
//region pure functions
|
||||||
@ -125,14 +123,12 @@ class MapUnit {
|
|||||||
// will not get counted twice!
|
// will not get counted twice!
|
||||||
@Transient var tempUniques= ArrayList<Unique>()
|
@Transient var tempUniques= ArrayList<Unique>()
|
||||||
|
|
||||||
fun getUniques(): ArrayList<Unique> {
|
fun getUniques(): ArrayList<Unique> = tempUniques
|
||||||
return tempUniques
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getMatchingUniques(placeholderText:String): Sequence<Unique>
|
fun getMatchingUniques(placeholderText:String): Sequence<Unique>
|
||||||
= tempUniques.asSequence().filter { it.placeholderText == placeholderText }
|
= tempUniques.asSequence().filter { it.placeholderText == placeholderText }
|
||||||
|
|
||||||
fun updateUniques(){
|
fun updateUniques() {
|
||||||
val uniques = ArrayList<Unique>()
|
val uniques = ArrayList<Unique>()
|
||||||
val baseUnit = baseUnit()
|
val baseUnit = baseUnit()
|
||||||
uniques.addAll(baseUnit.uniqueObjects)
|
uniques.addAll(baseUnit.uniqueObjects)
|
||||||
@ -190,9 +186,7 @@ class MapUnit {
|
|||||||
return action!!.split(" ")[1].toInt()
|
return action!!.split(" ")[1].toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString() = "$name - $owner"
|
||||||
return "$name - $owner"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun isIdle(): Boolean {
|
fun isIdle(): Boolean {
|
||||||
@ -222,7 +216,7 @@ class MapUnit {
|
|||||||
|
|
||||||
|
|
||||||
fun isEmbarked(): Boolean {
|
fun isEmbarked(): Boolean {
|
||||||
if(!type.isLandUnit()) return false
|
if (!type.isLandUnit()) return false
|
||||||
return currentTile.isWater
|
return currentTile.isWater
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,9 +281,7 @@ class MapUnit {
|
|||||||
fun fortifyUntilHealed() { action = "Fortify 0 until healed" }
|
fun fortifyUntilHealed() { action = "Fortify 0 until healed" }
|
||||||
|
|
||||||
fun fortifyIfCan() {
|
fun fortifyIfCan() {
|
||||||
if (canFortify()) {
|
if (canFortify()) fortify()
|
||||||
fortify()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun adjacentHealingBonus():Int{
|
private fun adjacentHealingBonus():Int{
|
||||||
@ -305,9 +297,9 @@ class MapUnit {
|
|||||||
|
|
||||||
//region state-changing functions
|
//region state-changing functions
|
||||||
fun setTransients(ruleset: Ruleset) {
|
fun setTransients(ruleset: Ruleset) {
|
||||||
promotions.unit=this
|
promotions.unit = this
|
||||||
mapUnitAction?.unit = this
|
mapUnitAction?.unit = this
|
||||||
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!")
|
||||||
updateUniques()
|
updateUniques()
|
||||||
}
|
}
|
||||||
@ -436,8 +428,7 @@ class MapUnit {
|
|||||||
|
|
||||||
if (hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.")
|
if (hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.")
|
||||||
&& !isFriendlyTerritory
|
&& !isFriendlyTerritory
|
||||||
// Additional healing from medic is only applied when the unit is able to heal
|
&& healing > 0)// Additional healing from medic is only applied when the unit is able to heal
|
||||||
&& healing > 0)
|
|
||||||
healing += 5
|
healing += 5
|
||||||
|
|
||||||
return healing
|
return healing
|
||||||
@ -568,14 +559,14 @@ class MapUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getAncientRuinBonus(tile: TileInfo) {
|
private fun getAncientRuinBonus(tile: TileInfo) {
|
||||||
tile.improvement=null
|
tile.improvement = null
|
||||||
val tileBasedRandom = Random(tile.position.toString().hashCode())
|
val tileBasedRandom = Random(tile.position.toString().hashCode())
|
||||||
val actions: ArrayList<() -> Unit> = ArrayList()
|
val actions: ArrayList<() -> Unit> = ArrayList()
|
||||||
if(civInfo.cities.isNotEmpty()) actions.add {
|
if (civInfo.cities.isNotEmpty()) actions.add {
|
||||||
val city = civInfo.cities.random(tileBasedRandom)
|
val city = civInfo.cities.random(tileBasedRandom)
|
||||||
city.population.population++
|
city.population.population++
|
||||||
city.population.autoAssignPopulation()
|
city.population.autoAssignPopulation()
|
||||||
civInfo.addNotification("We have found survivors in the ruins - population added to ["+city.name+"]",tile.position, Color.GREEN)
|
civInfo.addNotification("We have found survivors in the ruins - population added to [" + city.name + "]", tile.position, Color.GREEN)
|
||||||
}
|
}
|
||||||
val researchableAncientEraTechs = tile.tileMap.gameInfo.ruleSet.technologies.values
|
val researchableAncientEraTechs = tile.tileMap.gameInfo.ruleSet.technologies.values
|
||||||
.filter {
|
.filter {
|
||||||
@ -583,11 +574,11 @@ class MapUnit {
|
|||||||
&& civInfo.tech.canBeResearched(it.name)
|
&& civInfo.tech.canBeResearched(it.name)
|
||||||
&& it.era() == Constants.ancientEra
|
&& it.era() == Constants.ancientEra
|
||||||
}
|
}
|
||||||
if(researchableAncientEraTechs.isNotEmpty())
|
if (researchableAncientEraTechs.isNotEmpty())
|
||||||
actions.add {
|
actions.add {
|
||||||
val tech = researchableAncientEraTechs.random(tileBasedRandom).name
|
val tech = researchableAncientEraTechs.random(tileBasedRandom).name
|
||||||
civInfo.tech.addTechnology(tech)
|
civInfo.tech.addTechnology(tech)
|
||||||
civInfo.addNotification("We have discovered the lost technology of [$tech] in the ruins!",tile.position, Color.BLUE)
|
civInfo.addNotification("We have discovered the lost technology of [$tech] in the ruins!", tile.position, Color.BLUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.add {
|
actions.add {
|
||||||
@ -599,21 +590,21 @@ class MapUnit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!type.isCivilian())
|
if (!type.isCivilian())
|
||||||
actions.add {
|
actions.add {
|
||||||
promotions.XP+=10
|
promotions.XP += 10
|
||||||
civInfo.addNotification("An ancient tribe trains our [$name] in their ways of combat!",tile.position, Color.RED)
|
civInfo.addNotification("An ancient tribe trains our [$name] in their ways of combat!", tile.position, Color.RED)
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.add {
|
actions.add {
|
||||||
val amount = listOf(25,60,100).random(tileBasedRandom)
|
val amount = listOf(25, 60, 100).random(tileBasedRandom)
|
||||||
civInfo.gold+=amount
|
civInfo.gold += amount
|
||||||
civInfo.addNotification("We have found a stash of [$amount] gold in the ruins!",tile.position, Color.GOLD)
|
civInfo.addNotification("We have found a stash of [$amount] gold in the ruins!", tile.position, Color.GOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.add {
|
actions.add {
|
||||||
civInfo.policies.addCulture(20)
|
civInfo.policies.addCulture(20)
|
||||||
civInfo.addNotification("We have discovered cultural artifacts in the ruins! (+20 Culture)",tile.position, Color.GOLD)
|
civInfo.addNotification("We have discovered cultural artifacts in the ruins! (+20 Culture)", tile.position, Color.GOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map of the surrounding area
|
// Map of the surrounding area
|
||||||
@ -652,12 +643,12 @@ class MapUnit {
|
|||||||
fun isTransportTypeOf(mapUnit: MapUnit): Boolean {
|
fun isTransportTypeOf(mapUnit: MapUnit): Boolean {
|
||||||
val isAircraftCarrier = hasUnique("Can carry 2 aircraft")
|
val isAircraftCarrier = hasUnique("Can carry 2 aircraft")
|
||||||
val isMissileCarrier = hasUnique("Can carry 2 missiles")
|
val isMissileCarrier = hasUnique("Can carry 2 missiles")
|
||||||
if(!isMissileCarrier && !isAircraftCarrier)
|
if (!isMissileCarrier && !isAircraftCarrier)
|
||||||
return false
|
return false
|
||||||
if(!mapUnit.type.isAirUnit()) return false
|
if (!mapUnit.type.isAirUnit()) return false
|
||||||
if(isMissileCarrier && mapUnit.type!=UnitType.Missile)
|
if (isMissileCarrier && mapUnit.type != UnitType.Missile)
|
||||||
return false
|
return false
|
||||||
if(isAircraftCarrier && mapUnit.type==UnitType.Missile)
|
if (isAircraftCarrier && mapUnit.type == UnitType.Missile)
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -669,26 +660,22 @@ class MapUnit {
|
|||||||
var unitCapacity = 2
|
var unitCapacity = 2
|
||||||
unitCapacity += getUniques().count { it.text == "Can carry 1 extra air unit" }
|
unitCapacity += getUniques().count { it.text == "Can carry 1 extra air unit" }
|
||||||
|
|
||||||
if (currentTile.airUnits.filter { it.isTransported }.size >= unitCapacity) return false
|
if (currentTile.airUnits.count { it.isTransported } >= unitCapacity) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun interceptDamagePercentBonus():Int{
|
fun interceptDamagePercentBonus():Int {
|
||||||
var sum=0
|
return getUniques().filter { it.placeholderText == "Bonus when intercepting []%" }
|
||||||
for(unique in getUniques().filter { it.text.startsWith(BONUS_WHEN_INTERCEPTING) }){
|
.sumBy { it.params[0].toInt() }
|
||||||
val percent = Regex("\\d+").find(unique.text)!!.value.toInt()
|
|
||||||
sum += percent
|
|
||||||
}
|
|
||||||
return sum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCitadelDamage() {
|
private fun getCitadelDamage() {
|
||||||
// Check for Citadel damage
|
// Check for Citadel damage
|
||||||
val applyCitadelDamage = currentTile.neighbors
|
val applyCitadelDamage = currentTile.neighbors
|
||||||
.filter{ it.getOwner() != null && civInfo.isAtWarWith(it.getOwner()!!) }
|
.filter { it.getOwner() != null && civInfo.isAtWarWith(it.getOwner()!!) }
|
||||||
.map{ it.getTileImprovement() }
|
.map { it.getTileImprovement() }
|
||||||
.filter{ it != null && it.hasUnique("Deal 30 damage to adjacent enemy units") }
|
.filter { it != null && it.hasUnique("Deal 30 damage to adjacent enemy units") }
|
||||||
.any()
|
.any()
|
||||||
|
|
||||||
if (applyCitadelDamage) {
|
if (applyCitadelDamage) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user