diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 52 |
1 files changed, 42 insertions, 10 deletions
@@ -38,6 +38,7 @@ let ui = { hex_y: [], units: [], battle_units: [], + battle: document.getElementById("battle"), battle_hits: [ document.getElementById("hits_armor"), @@ -57,6 +58,14 @@ let ui = { battle_line_2: document.getElementById("battle_line_2"), battle_line_3: document.getElementById("battle_line_3"), battle_line_4: document.getElementById("battle_line_4"), + + pursuit: document.getElementById("pursuit"), + pursuit_hits: document.getElementById("pursuit_hits"), + pursuit_header: document.getElementById("pursuit_header"), + pursuit_message: document.getElementById("pursuit_message"), + pursuit_line_1: document.getElementById("pursuit_line_1"), + pursuit_line_2: document.getElementById("pursuit_line_2"), + onmap: document.getElementById("units"), focus: null, } @@ -446,10 +455,10 @@ function update_map() { } } -function update_battle_line(line, test) { +function update_battle_line(hex, line, test) { for (let u = 0; u < units.length; ++u) { let e = ui.battle_units[u] - if (unit_hex(u) === view.battle && test(u)) { + if (unit_hex(u) === hex && test(u)) { if (!line.contains(e)) line.appendChild(e) @@ -475,15 +484,15 @@ function update_battle() { ui.battle_header.textContent = hex_name[view.battle] ui.battle_message.textContent = view.flash if (player === ALLIED) { - update_battle_line(ui.battle_line_1, u => is_axis_unit(u) && is_artillery_unit(u)) - update_battle_line(ui.battle_line_2, u => is_axis_unit(u) && !is_artillery_unit(u)) - update_battle_line(ui.battle_line_3, u => is_allied_unit(u) && !is_artillery_unit(u)) - update_battle_line(ui.battle_line_4, u => is_allied_unit(u) && is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_1, u => is_axis_unit(u) && is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_2, u => is_axis_unit(u) && !is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_3, u => is_allied_unit(u) && !is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_4, u => is_allied_unit(u) && is_artillery_unit(u)) } else { - update_battle_line(ui.battle_line_1, u => is_allied_unit(u) && is_artillery_unit(u)) - update_battle_line(ui.battle_line_2, u => is_allied_unit(u) && !is_artillery_unit(u)) - update_battle_line(ui.battle_line_3, u => is_axis_unit(u) && !is_artillery_unit(u)) - update_battle_line(ui.battle_line_4, u => is_axis_unit(u) && is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_1, u => is_allied_unit(u) && is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_2, u => is_allied_unit(u) && !is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_3, u => is_axis_unit(u) && !is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_4, u => is_axis_unit(u) && is_artillery_unit(u)) } target_button("armor") target_button("infantry") @@ -493,6 +502,24 @@ function update_battle() { ui.battle_hits[i].textContent = view.hits[i] } +function update_pursuit() { + ui.pursuit.classList.remove("hide") + ui.pursuit_header.textContent = "Pursuit Fire at " + hex_name[view.pursuit] + ui.pursuit_message.textContent = view.flash + if (player === ALLIED) { + let slowest = + update_battle_line(view.pursuit, ui.pursuit_line_1, u => is_axis_unit(u)) + update_battle_line(view.pursuit, ui.pursuit_line_2, u => is_allied_unit(u)) + } else { + update_battle_line(view.pursuit, ui.pursuit_line_1, u => is_allied_unit(u)) + update_battle_line(view.pursuit, ui.pursuit_line_2, u => is_axis_unit(u)) + } + if (view.hits === 1) + ui.pursuit_hits.textContent = view.hits + " hit" + else + ui.pursuit_hits.textContent = view.hits + " hits" +} + function target_button(action) { let button = document.getElementById("target_" + action + "_button") if (view.actions) { @@ -514,6 +541,11 @@ function on_update() { else ui.battle.classList.add("hide") + if (view.pursuit) + update_pursuit() + else + ui.pursuit.classList.add("hide") + action_button("overrun", "Overrun") action_button("rommel", "Rommel") action_button("stop", "Stop") |