Recalculate attack phase initiative when it is necessary to do so
authorTheSaminator <TheSaminator@users.noreply.github.com>
Sat, 28 May 2022 16:40:11 +0000 (12:40 -0400)
committerTheSaminator <TheSaminator@users.noreply.github.com>
Sat, 28 May 2022 16:40:11 +0000 (12:40 -0400)
src/commonMain/kotlin/starshipfights/game/game_initiative.kt
src/commonMain/kotlin/starshipfights/game/ship_weapons.kt

index 25fd6fd68ca9e6a0e505d8b4c3f281d3b96ea7b1..b8cab0032d922586785fbbda88c980848c06639f 100644 (file)
@@ -45,8 +45,11 @@ fun GameState.calculateAttackPhaseInitiative(): InitiativePair = InitiativePair(
                                .sumOf { ship ->
                                        val allWeapons = ship.armaments.weaponInstances
                                                .filterValues { weaponInstance ->
-                                                       ships.values.any { target ->
-                                                               target.position.location in ship.getWeaponPickRequest(weaponInstance.weapon).boundary
+                                                       when (val weapon = weaponInstance.weapon) {
+                                                               is AreaWeapon -> true
+                                                               else -> ships.values.any { target ->
+                                                                       target.position.location in ship.getWeaponPickRequest(weapon).boundary
+                                                               }
                                                        }
                                                }
                                        val usableWeapons = allWeapons - ship.usedArmaments
index 464dfd0927a77db114928872b5192f4f1c7fc384..7fa00122bee665e202f580b2d0433920b471e7d1 100644 (file)
@@ -683,6 +683,7 @@ fun GameState.useWeaponPickResponse(attacker: ShipInstance, weaponId: Id<ShipWea
                        
                        GameEvent.StateChange(
                                copy(ships = newShips, destroyedShips = newWrecks, chatBox = newChatMessages)
+                                       .withRecalculatedInitiative { calculateAttackPhaseInitiative() }
                        )
                }
                else -> {
@@ -706,6 +707,7 @@ fun GameState.useWeaponPickResponse(attacker: ShipInstance, weaponId: Id<ShipWea
                        
                        GameEvent.StateChange(
                                copy(ships = newShips, destroyedShips = newWrecks, chatBox = newChatMessages)
+                                       .withRecalculatedInitiative { calculateAttackPhaseInitiative() }
                        )
                }
        }