diff --git a/core/src/com/unciv/logic/automation/unit/BattleHelper.kt b/core/src/com/unciv/logic/automation/unit/BattleHelper.kt index d68569fa37..203ce6a292 100644 --- a/core/src/com/unciv/logic/automation/unit/BattleHelper.kt +++ b/core/src/com/unciv/logic/automation/unit/BattleHelper.kt @@ -78,7 +78,7 @@ object BattleHelper { reachableTile, tile, movementLeft, - Battle.getMapCombatantOfTile(tile)!! + Battle.getMapCombatantOfTile(tile) ) else if (tile in tilesWithoutEnemies) continue // avoid checking the same empty tile multiple times else if (tileContainsAttackableEnemy(unit, tile, tilesToCheck)) { @@ -104,7 +104,6 @@ object BattleHelper { if (tile !in (tilesToCheck ?: unit.civ.viewableTiles)) return false val mapCombatant = Battle.getMapCombatantOfTile(tile) - return (!unit.baseUnit.isMelee() || mapCombatant !is MapUnitCombatant || !mapCombatant.unit.isCivilian() || unit.movement.canPassThrough(tile)) } diff --git a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt index 86b8c24e86..7d8423cc71 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTableHelpers.kt @@ -6,11 +6,13 @@ import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.actions.Actions import com.badlogic.gdx.scenes.scene2d.actions.FloatAction +import com.badlogic.gdx.scenes.scene2d.actions.RelativeTemporalAction import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Table import com.unciv.UncivGame import com.unciv.logic.battle.ICombatant +import com.unciv.logic.map.HexMath import com.unciv.ui.images.ImageGetter import com.unciv.ui.screens.worldscreen.WorldScreen @@ -47,15 +49,50 @@ object BattleTableHelpers { actor.color = color.cpy().lerp(Color.RED, percent) } + val actorsToMove = getMapActorsForCombatant(attacker).toList() + + val attackVectorHexCoords = defender.getTile().position.cpy().sub(attacker.getTile().position) + val attackVectorWorldCoords = HexMath.hex2WorldCoords(attackVectorHexCoords) + .nor() // normalize vector to length of "1" + .scl(10f) // we want 10 pixel movement + stage.addAction( Actions.sequence( - object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) { - override fun update(percent: Float) = updateRedPercent(percent) - }, - object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) { - override fun update(percent: Float) = updateRedPercent(1 - percent) - } + object : RelativeTemporalAction(){ + init { + duration = 0.5f + interpolation = Interpolation.sine + } + override fun updateRelative(percentDelta: Float) { + for (actor in actorsToMove){ + actor.moveBy(attackVectorWorldCoords.x * percentDelta, attackVectorWorldCoords.y * percentDelta) + } + } + }, + Actions.parallel( // While the unit is moving back to its normal position, we flash the damages on both units + object : RelativeTemporalAction(){ + init { + duration = 0.5f + interpolation = Interpolation.sine + } + override fun updateRelative(percentDelta: Float) { + for (actor in actorsToMove){ + actor.moveBy(attackVectorWorldCoords.x * -percentDelta, attackVectorWorldCoords.y * -percentDelta) + } + } + }, + Actions.sequence( + object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) { + override fun update(percent: Float) = updateRedPercent(percent) + }, + object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) { + override fun update(percent: Float) = updateRedPercent(1 - percent) + } + ) + ) )) + + } fun getHealthBar(maxHealth: Int, currentHealth: Int, maxRemainingHealth: Int, minRemainingHealth: Int): Table {