mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
Carrier right-click attack fix (#9130)
This commit is contained in:
parent
cb20d91822
commit
93d2ba2af5
@ -127,15 +127,20 @@ object BattleHelper {
|
||||
)
|
||||
return false
|
||||
|
||||
if (combatant is MapUnitCombatant && combatant.hasUnique(UniqueType.CannotAttack))
|
||||
return false
|
||||
|
||||
if (combatant is MapUnitCombatant &&
|
||||
combatant.unit.hasUnique(UniqueType.CanOnlyAttackUnits) &&
|
||||
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackUnits).none { tileCombatant.matchesCategory(it.params[0]) }
|
||||
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackUnits).run {
|
||||
any() && none { tileCombatant.matchesCategory(it.params[0]) }
|
||||
}
|
||||
)
|
||||
return false
|
||||
|
||||
if (combatant is MapUnitCombatant &&
|
||||
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackTiles)
|
||||
.let { unique -> unique.any() && unique.none { tile.matchesFilter(it.params[0]) } }
|
||||
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackTiles).run {
|
||||
any() && none { tile.matchesFilter(it.params[0]) }
|
||||
}
|
||||
)
|
||||
return false
|
||||
|
||||
|
@ -304,6 +304,8 @@ class UnitMovement(val unit: MapUnit) {
|
||||
}
|
||||
}
|
||||
|
||||
class UnreachableDestinationException(msg: String) : Exception(msg)
|
||||
|
||||
fun getTileToMoveToThisTurn(finalDestination: Tile): Tile {
|
||||
|
||||
val currentTile = unit.getTile()
|
||||
@ -314,8 +316,6 @@ class UnitMovement(val unit: MapUnit) {
|
||||
|
||||
val distanceToTiles = getDistanceToTiles()
|
||||
|
||||
class UnreachableDestinationException(msg: String) : Exception(msg)
|
||||
|
||||
// If the tile is far away, we need to build a path how to get there, and then take the first step
|
||||
if (!distanceToTiles.containsKey(finalDestination))
|
||||
return getShortestPath(finalDestination).firstOrNull()
|
||||
@ -329,7 +329,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
val destinationNeighbors = finalDestination.neighbors
|
||||
return when (currentTile) {
|
||||
in destinationNeighbors -> currentTile // We're right nearby anyway, no need to move
|
||||
else -> destinationNeighbors.asSequence()
|
||||
else -> destinationNeighbors
|
||||
.filter { distanceToTiles.containsKey(it) && canMoveTo(it) }
|
||||
.minByOrNull { distanceToTiles.getValue(it).totalDistance } // we can get a little closer
|
||||
?: currentTile // We can't get closer...
|
||||
|
@ -26,6 +26,7 @@ import com.unciv.logic.city.City
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.logic.map.mapunit.UnitMovement
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.models.UncivSound
|
||||
import com.unciv.models.helpers.MapArrowType
|
||||
@ -266,9 +267,12 @@ class WorldMapHolder(
|
||||
try {
|
||||
tileToMoveTo = selectedUnit.movement.getTileToMoveToThisTurn(targetTile)
|
||||
} catch (ex: Exception) {
|
||||
Log.error("Exception in getTileToMoveToThisTurn", ex)
|
||||
return@run
|
||||
} // can't move here
|
||||
// This is normal e.g. when selecting an air unit then right-clicking on an empty tile
|
||||
// Or telling a ship to run onto a coastal land tile.
|
||||
if (ex !is UnitMovement.UnreachableDestinationException)
|
||||
Log.error("Exception in getTileToMoveToThisTurn", ex)
|
||||
return@run // can't move here
|
||||
}
|
||||
|
||||
worldScreen.preActionGameInfo = worldScreen.gameInfo.clone()
|
||||
|
||||
|
@ -90,7 +90,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
||||
val unitTable = worldScreen.bottomUnitTable
|
||||
return if (unitTable.selectedUnit != null
|
||||
&& !unitTable.selectedUnit!!.isCivilian()
|
||||
&& !unitTable.selectedUnit!!.hasUnique(UniqueType.CannotAttack))
|
||||
&& !unitTable.selectedUnit!!.hasUnique(UniqueType.CannotAttack)) // purely cosmetic - hide battle table
|
||||
MapUnitCombatant(unitTable.selectedUnit!!)
|
||||
else if (unitTable.selectedCity != null)
|
||||
CityCombatant(unitTable.selectedCity!!)
|
||||
|
Loading…
Reference in New Issue
Block a user