summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-12-14 17:21:58 +0100
committerTor Andersson <tor@ccxvii.net>2022-12-14 17:45:06 +0100
commitc1050b3e55e9143950e4f0d5968f8b979881cfe4 (patch)
treee40f24b933e60958164e3b08353c24ed6f14f717
parentba0991afac893f64458ec7e548ffc8946508dda0 (diff)
downloadhammer-of-the-scots-c1050b3e55e9143950e4f0d5968f8b979881cfe4.tar.gz
Stop delaying hits when more hits inflicted than steps.
-rw-r--r--rules.js25
1 files changed, 18 insertions, 7 deletions
diff --git a/rules.js b/rules.js
index c11d22a..1e97949 100644
--- a/rules.js
+++ b/rules.js
@@ -1845,6 +1845,21 @@ function pass_with_block(b) {
resume_battle()
}
+function count_enemy_hp_in_battle() {
+ let is_candidate = (game.active === game.attacker[game.where]) ? is_defender : is_attacker
+ let n = 0
+ for (let b = 0; b < block_count; ++b)
+ if (is_candidate(b))
+ n += game.steps[b]
+ return n
+}
+
+function must_apply_hits() {
+ if (game.delay_hits)
+ return game.hits >= count_enemy_hp_in_battle()
+ return game.hits > 0
+}
+
function fire_with_block(b) {
set_add(game.moved, b)
let steps = game.steps[b]
@@ -1887,13 +1902,9 @@ function fire_with_block(b) {
game.flash += " and scored " + hits + " hits."
}
- if (hits > 0) {
- if (!game.delay_hits) {
- game.active = ENEMY[game.active]
- goto_battle_hits()
- } else {
- resume_battle()
- }
+ if (must_apply_hits()) {
+ game.active = ENEMY[game.active]
+ goto_battle_hits()
} else {
resume_battle()
}