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
|
return false
|
||||||
|
|
||||||
|
if (combatant is MapUnitCombatant && combatant.hasUnique(UniqueType.CannotAttack))
|
||||||
|
return false
|
||||||
|
|
||||||
if (combatant is MapUnitCombatant &&
|
if (combatant is MapUnitCombatant &&
|
||||||
combatant.unit.hasUnique(UniqueType.CanOnlyAttackUnits) &&
|
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackUnits).run {
|
||||||
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackUnits).none { tileCombatant.matchesCategory(it.params[0]) }
|
any() && none { tileCombatant.matchesCategory(it.params[0]) }
|
||||||
|
}
|
||||||
)
|
)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if (combatant is MapUnitCombatant &&
|
if (combatant is MapUnitCombatant &&
|
||||||
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackTiles)
|
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackTiles).run {
|
||||||
.let { unique -> unique.any() && unique.none { tile.matchesFilter(it.params[0]) } }
|
any() && none { tile.matchesFilter(it.params[0]) }
|
||||||
|
}
|
||||||
)
|
)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
@ -304,6 +304,8 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UnreachableDestinationException(msg: String) : Exception(msg)
|
||||||
|
|
||||||
fun getTileToMoveToThisTurn(finalDestination: Tile): Tile {
|
fun getTileToMoveToThisTurn(finalDestination: Tile): Tile {
|
||||||
|
|
||||||
val currentTile = unit.getTile()
|
val currentTile = unit.getTile()
|
||||||
@ -314,8 +316,6 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
|
|
||||||
val distanceToTiles = getDistanceToTiles()
|
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 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))
|
if (!distanceToTiles.containsKey(finalDestination))
|
||||||
return getShortestPath(finalDestination).firstOrNull()
|
return getShortestPath(finalDestination).firstOrNull()
|
||||||
@ -329,7 +329,7 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
val destinationNeighbors = finalDestination.neighbors
|
val destinationNeighbors = finalDestination.neighbors
|
||||||
return when (currentTile) {
|
return when (currentTile) {
|
||||||
in destinationNeighbors -> currentTile // We're right nearby anyway, no need to move
|
in destinationNeighbors -> currentTile // We're right nearby anyway, no need to move
|
||||||
else -> destinationNeighbors.asSequence()
|
else -> destinationNeighbors
|
||||||
.filter { distanceToTiles.containsKey(it) && canMoveTo(it) }
|
.filter { distanceToTiles.containsKey(it) && canMoveTo(it) }
|
||||||
.minByOrNull { distanceToTiles.getValue(it).totalDistance } // we can get a little closer
|
.minByOrNull { distanceToTiles.getValue(it).totalDistance } // we can get a little closer
|
||||||
?: currentTile // We can't get 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.civilization.Civilization
|
||||||
import com.unciv.logic.map.TileMap
|
import com.unciv.logic.map.TileMap
|
||||||
import com.unciv.logic.map.mapunit.MapUnit
|
import com.unciv.logic.map.mapunit.MapUnit
|
||||||
|
import com.unciv.logic.map.mapunit.UnitMovement
|
||||||
import com.unciv.logic.map.tile.Tile
|
import com.unciv.logic.map.tile.Tile
|
||||||
import com.unciv.models.UncivSound
|
import com.unciv.models.UncivSound
|
||||||
import com.unciv.models.helpers.MapArrowType
|
import com.unciv.models.helpers.MapArrowType
|
||||||
@ -266,9 +267,12 @@ class WorldMapHolder(
|
|||||||
try {
|
try {
|
||||||
tileToMoveTo = selectedUnit.movement.getTileToMoveToThisTurn(targetTile)
|
tileToMoveTo = selectedUnit.movement.getTileToMoveToThisTurn(targetTile)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
Log.error("Exception in getTileToMoveToThisTurn", ex)
|
// This is normal e.g. when selecting an air unit then right-clicking on an empty tile
|
||||||
return@run
|
// Or telling a ship to run onto a coastal land tile.
|
||||||
} // can't move here
|
if (ex !is UnitMovement.UnreachableDestinationException)
|
||||||
|
Log.error("Exception in getTileToMoveToThisTurn", ex)
|
||||||
|
return@run // can't move here
|
||||||
|
}
|
||||||
|
|
||||||
worldScreen.preActionGameInfo = worldScreen.gameInfo.clone()
|
worldScreen.preActionGameInfo = worldScreen.gameInfo.clone()
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||||||
val unitTable = worldScreen.bottomUnitTable
|
val unitTable = worldScreen.bottomUnitTable
|
||||||
return if (unitTable.selectedUnit != null
|
return if (unitTable.selectedUnit != null
|
||||||
&& !unitTable.selectedUnit!!.isCivilian()
|
&& !unitTable.selectedUnit!!.isCivilian()
|
||||||
&& !unitTable.selectedUnit!!.hasUnique(UniqueType.CannotAttack))
|
&& !unitTable.selectedUnit!!.hasUnique(UniqueType.CannotAttack)) // purely cosmetic - hide battle table
|
||||||
MapUnitCombatant(unitTable.selectedUnit!!)
|
MapUnitCombatant(unitTable.selectedUnit!!)
|
||||||
else if (unitTable.selectedCity != null)
|
else if (unitTable.selectedCity != null)
|
||||||
CityCombatant(unitTable.selectedCity!!)
|
CityCombatant(unitTable.selectedCity!!)
|
||||||
|
Loading…
Reference in New Issue
Block a user