mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 10:54:19 -04:00
chore(purity): TargetHelper
This commit is contained in:
parent
d828114ede
commit
261e1047ff
@ -611,6 +611,7 @@ object UnitAutomation {
|
||||
return true
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private fun chooseBombardTarget(city: City): ICombatant? {
|
||||
var targets = TargetHelper.getBombardableTiles(city).map { Battle.getMapCombatantOfTile(it)!! }
|
||||
.filterNot { it is MapUnitCombatant &&
|
||||
|
@ -13,6 +13,7 @@ import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.models.ruleset.unique.GameContext
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import yairm210.purity.annotations.Readonly
|
||||
import kotlin.math.min
|
||||
import kotlin.random.Random
|
||||
|
||||
@ -46,8 +47,8 @@ object BattleUnitCapture {
|
||||
return spawnCapturedUnit(defender, attacker)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Readonly
|
||||
private fun unitCapturedPrizeShipsUnique(attacker: MapUnitCombatant, defender: MapUnitCombatant): Boolean {
|
||||
if (attacker.unit.getMatchingUniques(UniqueType.KillUnitCapture)
|
||||
.none { defender.matchesFilter(it.params[0]) }
|
||||
|
@ -7,8 +7,10 @@ import com.unciv.logic.map.mapunit.movement.PathsToTilesWithinTurn
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.models.ruleset.unique.GameContext
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import yairm210.purity.annotations.Readonly
|
||||
|
||||
object TargetHelper {
|
||||
@Readonly
|
||||
fun getAttackableEnemies(
|
||||
unit: MapUnit,
|
||||
unitDistanceToTiles: PathsToTilesWithinTurn,
|
||||
@ -68,6 +70,7 @@ object TargetHelper {
|
||||
return attackableTiles
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private fun getTilesToAttackFromWhenUnitMoves(unitDistanceToTiles: PathsToTilesWithinTurn, unitMustBeSetUp: Boolean, unit: MapUnit) =
|
||||
unitDistanceToTiles.asSequence()
|
||||
.map { (tile, distance) ->
|
||||
@ -86,6 +89,7 @@ object TargetHelper {
|
||||
it.first == unit.getTile() || unit.movement.canMoveTo(it.first)
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private fun tileContainsAttackableEnemy(unit: MapUnit, tile: Tile, tilesToCheck: List<Tile>?): Boolean {
|
||||
if (tile !in (tilesToCheck ?: unit.civ.viewableTiles) || !containsAttackableEnemy(tile, MapUnitCombatant(unit)) )
|
||||
return false
|
||||
@ -94,6 +98,7 @@ object TargetHelper {
|
||||
return (!unit.baseUnit.isMelee() || mapCombatant !is MapUnitCombatant || !mapCombatant.unit.isCivilian() || unit.movement.canPassThrough(tile))
|
||||
}
|
||||
|
||||
@Readonly
|
||||
fun containsAttackableEnemy(tile: Tile, combatant: ICombatant): Boolean {
|
||||
if (combatant is MapUnitCombatant && combatant.unit.isEmbarked() && !combatant.hasUnique(UniqueType.AttackOnSea)) {
|
||||
// Can't attack water units while embarked, only land
|
||||
@ -146,6 +151,7 @@ object TargetHelper {
|
||||
}
|
||||
|
||||
/** Get a list of visible tiles which have something attackable */
|
||||
@Readonly
|
||||
fun getBombardableTiles(city: City): Sequence<Tile> =
|
||||
city.getCenterTile().getTilesInDistance(city.getBombardRange())
|
||||
.filter { it.isVisible(city.civ) && containsAttackableEnemy(it, CityCombatant(city)) }
|
||||
|
@ -189,6 +189,7 @@ open class Stats(
|
||||
|
||||
// function that removes the icon from the Stats object since the circular icons all appear the same
|
||||
// delete this and replace above instances with toString() once the text-coloring-affecting-font-icons bug is fixed (e.g., in notification text)
|
||||
@Readonly
|
||||
fun toStringWithoutIcons(): String {
|
||||
return this.joinToString {
|
||||
it.value.toInt().tr() + " " + it.key.name.tr().substring(startIndex = 1)
|
||||
@ -196,6 +197,7 @@ open class Stats(
|
||||
}
|
||||
|
||||
/** Return a string of just +/- value and Stat symbol*/
|
||||
@Readonly
|
||||
fun toStringOnlyIcons(addPlusSign: Boolean = true): String {
|
||||
return this.joinToString {
|
||||
(if (addPlusSign && it.value > 0) "+" else "") + it.value.toInt() + " " + it.key.character
|
||||
|
@ -38,6 +38,7 @@ import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||
import com.unciv.ui.screens.worldscreen.bottombar.BattleTableHelpers.battleAnimationDeferred
|
||||
import com.unciv.ui.screens.worldscreen.bottombar.BattleTableHelpers.getHealthBar
|
||||
import com.unciv.utils.DebugUtils
|
||||
import yairm210.purity.annotations.Readonly
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@ -97,6 +98,7 @@ class BattleTable(val worldScreen: WorldScreen) : Table() {
|
||||
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private fun tryGetAttacker(): ICombatant? {
|
||||
val unitTable = worldScreen.bottomUnitTable
|
||||
return if (unitTable.selectedUnit != null
|
||||
@ -108,11 +110,13 @@ class BattleTable(val worldScreen: WorldScreen) : Table() {
|
||||
else null // no attacker
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private fun tryGetDefender(): ICombatant? {
|
||||
val selectedTile = worldScreen.mapHolder.selectedTile ?: return null // no selected tile
|
||||
return tryGetDefenderAtTile(selectedTile, false)
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private fun tryGetDefenderAtTile(selectedTile: Tile, includeFriendly: Boolean): ICombatant? {
|
||||
val attackerCiv = worldScreen.viewingCiv
|
||||
val defender: ICombatant? = Battle.getMapCombatantOfTile(selectedTile)
|
||||
|
Loading…
x
Reference in New Issue
Block a user