summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-12-14 17:22:40 +0100
committerTor Andersson <tor@ccxvii.net>2023-01-17 11:55:58 +0100
commit6ced7d5c56d6e3f806bf3daf8b13493a676074c0 (patch)
tree3353501f74b64d81ff4aeba95ddc14ac2e3898d2
parentdba911992cd1c177bb75603a53513b2972d20fa7 (diff)
downloadjulius-caesar-6ced7d5c56d6e3f806bf3daf8b13493a676074c0.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 a9ff8bf..bb884cc 100644
--- a/rules.js
+++ b/rules.js
@@ -2018,6 +2018,21 @@ function can_fire_with_block(b) {
return false
}
+function count_enemy_hp_in_battle() {
+ let is_candidate = (game.active === get_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 strength = block_strength(b)
@@ -2057,13 +2072,9 @@ function fire_with_block(b) {
game.flash += " and scored " + hits + " hits."
}
- if (game.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()
}