diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-10-05 23:52:44 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-16 19:08:56 +0100 |
commit | 4c807553c0ff72844ba4d29c8ee3e591e6357d40 (patch) | |
tree | bfaf3646886075c7eb8d5d2f2933452831750cd3 | |
parent | 6f327defb9832c0ed2ca99570bba0b91ffd5a36e (diff) | |
download | julius-caesar-4c807553c0ff72844ba4d29c8ee3e591e6357d40.tar.gz |
Add delayed hit assignment option.
-rw-r--r-- | create.html | 16 | ||||
-rw-r--r-- | play.js | 1 | ||||
-rw-r--r-- | rules.js | 78 |
3 files changed, 77 insertions, 18 deletions
diff --git a/create.html b/create.html index 5a7fec9..7fb0407 100644 --- a/create.html +++ b/create.html @@ -35,6 +35,18 @@ House rules: --> <p> -<label><input type="checkbox" name="autohit" value="true"> -Automatically apply combat hits when possible. +<label><input type="checkbox" id="delay_hits" name="delay_hits" value="true"> +Fire with all blocks before assigning hits. </label> + +<br> +<label><input type="checkbox" id="autohit" name="autohit" value="true"> +Automatically assign hits when possible. +</label> + +<script> +let cb1 = document.getElementById("autohit") +let cb2 = document.getElementById("delay_hits") +cb1.onchange = function () { if (cb1.checked) cb2.checked = false } +cb2.onchange = function () { if (cb2.checked) cb1.checked = false } +</script> @@ -750,6 +750,7 @@ function on_update() { document.getElementById("turn_info").textContent = `Turn ${view.turn} of Year ${view.year}` action_button("surprise", "Surprise!") + action_button("assign", "Assign hits") action_button("pass") action_button("undo", "Undo") @@ -1823,6 +1823,7 @@ function count_defenders() { function start_battle() { game.battle_round = 0 game.flash = "" + game.hits = 0 logbr() log(".h4 Battle in #" + game.where) if (game.surprise === game.where) @@ -1948,7 +1949,13 @@ function pump_battle_round() { function battle_step(active, initiative, candidate) { game.battle_list = filter_battle_blocks(initiative, candidate) if (game.battle_list) { - game.active = active + if (game.active !== active) { + game.active = active + if (game.delay_hits && game.hits > 0) { + goto_battle_hits() + return true + } + } return true } return false @@ -1982,6 +1989,11 @@ function pump_battle_round() { if (battle_step(attacker, 'D', is_attacker)) return } + if (game.delay_hits && game.hits > 0) { + game.active = enemy(game.active) + return goto_battle_hits() + } + start_battle_round() } } @@ -2008,33 +2020,50 @@ function can_fire_with_block(b) { function fire_with_block(b) { set_add(game.moved, b) - game.hits = 0 let strength = block_strength(b) let fire = block_fire_power(b) let name = block_name(b) + " " + block_initiative(b) + fire + let rolls = [] + let hits = 0 for (let i = 0; i < strength; ++i) { let die = roll_d6() if (die <= fire) { rolls.push(DIE_HIT[die]) - ++game.hits + ++hits } else { rolls.push(DIE_MISS[die]) } } - game.flash = name + " fired " + rolls.join(" ") + " " - if (game.hits === 0) - game.flash += "and missed." - else if (game.hits === 1) - game.flash += "and scored 1 hit." - else - game.flash += "and scored " + game.hits + " hits." + game.hits += hits log_battle(name + " fired " + rolls.join("") + ".") + if (game.delay_hits) { + game.flash = name + " fired " + rolls.join(" ") + if (game.hits === 0) + game.flash += "." + else if (game.hits === 1) + game.flash += " for a total of 1 hit." + else if (game.hits > 1) + game.flash += " for a total of " + game.hits + " hits." + } else { + game.flash = name + " fired " + rolls.join(" ") + if (hits === 0) + game.flash += " and missed." + else if (hits === 1) + game.flash += " and scored 1 hit." + else + game.flash += " and scored " + hits + " hits." + } + if (game.hits > 0) { - game.active = enemy(game.active) - goto_battle_hits() + if (!game.delay_hits) { + game.active = enemy(game.active) + goto_battle_hits() + } else { + resume_battle() + } } else { resume_battle() } @@ -2108,6 +2137,16 @@ states.battle_round = { if (can_pass) gen_action_battle(view, 'battle_pass', b) gen_action_block(view, b) } + if (game.delay_hits && game.hits > 0) + gen_action(view, 'assign') + }, + assign: function () { + game.active = enemy(game.active) + if (game.hits === 1) + game.flash = `Inflicted 1 hit.` + else + game.flash = `Inflicted ${game.hits} hits.` + goto_battle_hits() }, block: function (who) { if (can_fire_with_block(who)) @@ -2150,10 +2189,12 @@ function goto_battle_hits() { game.flash += ` Assigned ${n}.` } - if (game.battle_list.length === 0) + if (game.battle_list.length === 0) { + game.hits = 0 resume_battle() - else + } else { game.state = 'battle_hits' + } } function list_victims(p) { @@ -2178,10 +2219,12 @@ function apply_hit(who) { resume_battle() else { game.battle_list = list_victims(game.active) - if (game.battle_list.length === 0) + if (game.battle_list.length === 0) { + game.hits = 0 resume_battle() - else + } else { game.flash += " " + game.hits + (game.hits === 1 ? " hit left." : " hits left.") + } } } @@ -2675,6 +2718,9 @@ exports.setup = function (seed, scenario, options) { if (options.autohit) game.autohit = 1 + if (options.delay_hits) + game.delay_hits = 1 + setup_historical_deployment() if (scenario === "Free Deployment") start_free_deployment() |