From 06a45c701b5790349ed2f8dad8255e6205dad231 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 14 Dec 2022 17:44:20 +0100 Subject: Stop delaying hits when more hits inflicted than steps. --- rules.js | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'rules.js') 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 { -- cgit v1.2.3