summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-12-14 17:44:20 +0100
committerTor Andersson <tor@ccxvii.net>2022-12-14 17:44:35 +0100
commit06a45c701b5790349ed2f8dad8255e6205dad231 (patch)
tree3519eb75dabef0c5f968ac859f4a06acd4177149
parent5f23b20f6f9acf40a778912458b889f518ff1aa7 (diff)
downloadcrusader-rex-06a45c701b5790349ed2f8dad8255e6205dad231.tar.gz
Stop delaying hits when more hits inflicted than steps.
-rw-r--r--rules.js41
1 files changed, 37 insertions, 4 deletions
diff --git a/rules.js b/rules.js
index 9543e7c..377204a 100644
--- a/rules.js
+++ b/rules.js
@@ -2738,6 +2738,39 @@ states.siege_attrition = {
// FIELD AND SIEGE BATTLE HELPERS
+function count_enemy_hp_in_field() {
+ let hp = 0
+ for (let b = 0; b <= last_block; ++b)
+ if (block_owner(b) !== game.active && is_field_combatant(b))
+ hp += game.steps[b]
+ return hp
+}
+
+function count_enemy_hp_in_siege() {
+ let hp = 0
+ for (let b = 0; b <= last_block; ++b)
+ if (block_owner(b) !== game.active && is_siege_combatant(b))
+ if (is_block_in_castle(b))
+ hp += game.steps[b] * 2
+ else
+ hp += game.steps[b]
+ if (game.halfhit !== NOBODY && block_owner(game.halfhit) !== game.active)
+ hp -= 1
+ return hp
+}
+
+function must_apply_field_hits() {
+ if (game.delay_hits)
+ return game.hits >= count_enemy_hp_in_field()
+ return game.hits > 0
+}
+
+function must_apply_siege_hits() {
+ if (game.delay_hits)
+ return game.hits >= count_enemy_hp_in_siege()
+ return game.hits > 0
+}
+
function filter_battle_blocks(ci, is_candidate) {
let output = null
for (let b = 0; b <= last_block; ++b) {
@@ -3201,7 +3234,7 @@ function roll_attack(active, b, verb, is_charge) {
function field_fire_with_block(b) {
set_add(game.moved, b)
roll_attack(game.active, b, "fired", 0)
- if (!game.delay_hits && game.hits > 0) {
+ if (must_apply_field_hits()) {
game.active = enemy(game.active)
goto_field_battle_hits()
} else {
@@ -3212,7 +3245,7 @@ function field_fire_with_block(b) {
function siege_fire_with_block(b) {
set_add(game.moved, b)
roll_attack(game.active, b, "fired", 0)
- if (!game.delay_hits && game.hits > 0) {
+ if (must_apply_siege_hits()) {
game.active = enemy(game.active)
goto_siege_battle_hits()
} else {
@@ -3223,7 +3256,7 @@ function siege_fire_with_block(b) {
function charge_with_block(b) {
set_add(game.moved, b)
roll_attack(game.active, b, "charged", 1)
- if (!game.delay_hits && game.hits > 0) {
+ if (must_apply_field_hits()) {
game.active = enemy(game.active)
goto_field_battle_hits()
} else {
@@ -3252,7 +3285,7 @@ function harry_with_block(b) {
game.harry = game.active // remember to retreat after hits have been applied
game.who = b
roll_attack(game.active, b, "harried", 0)
- if (!game.delay_hits && game.hits > 0) {
+ if (must_apply_field_hits()) {
game.active = enemy(game.active)
goto_field_battle_hits()
} else {