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