From e8ee549f0d30c5caa99b2d931734c5f18332d543 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 30 Jul 2022 14:14:41 +0200 Subject: Fortress and Oasis supply. --- play.js | 69 ++++++++++++++++++++++++++++++----------------------------------- 1 file changed, 32 insertions(+), 37 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 685e280..4410ab9 100644 --- a/play.js +++ b/play.js @@ -1,7 +1,5 @@ "use strict" -// TODO: intermediate regroup moves - // https://www.redblobgames.com/grids/hexagons/ const svgNS = "http://www.w3.org/2000/svg" @@ -16,6 +14,13 @@ const hex_special = [ 48, 49, 102, 127, MALTA ] const unit_count = 94 +const SS_NONE = 0 +const SS_BASE = 1 +const SS_BARDIA = 2 +const SS_BENGHAZI = 3 +const SS_TOBRUK = 4 +const SS_OASIS = 5 + const ARMOR = 0 const INFANTRY = 1 const ANTITANK = 2 @@ -29,9 +34,9 @@ function is_allied_unit(u) { return (u >= 34 && u <= 93) } function is_elite_unit(u) { return unit_elite[u] } function is_armor_unit(u) { return unit_class[u] === ARMOR } -function is_infantry_unit(u) { unit_class[u] === INFANTRY } -function is_antitank_unit(u) { unit_class[u] === ANTITANK } -function is_artillery_unit(u) { unit_class[u] === ARTILLERY } +function is_infantry_unit(u) { return unit_class[u] === INFANTRY } +function is_antitank_unit(u) { return unit_class[u] === ANTITANK } +function is_artillery_unit(u) { return unit_class[u] === ARTILLERY } function is_recon_unit(u) { return unit_speed[u] === 4 } function is_mechanized_unit(u) { return unit_speed[u] === 3 } @@ -103,6 +108,10 @@ let ui = { const AXIS = 'Axis' const ALLIED = 'Allied' +function is_map_hex(x) { + return x < hex_exists.length && hex_exists[x] === 1 +} + // === UNIT STATE === const UNIT_DISRUPTED_SHIFT = 0 @@ -121,56 +130,32 @@ function is_unit_disrupted(u) { return (view.units[u] & UNIT_DISRUPTED_MASK) === UNIT_DISRUPTED_MASK } -function set_unit_disrupted(u) { - view.units[u] |= UNIT_DISRUPTED_MASK -} - -function clear_unit_disrupted(u) { - view.units[u] &= ~UNIT_DISRUPTED_MASK -} - function unit_hex(u) { return (view.units[u] & UNIT_HEX_MASK) >> UNIT_HEX_SHIFT } -function set_unit_hex(u, x) { - view.units[u] = (view.units[u] & ~UNIT_HEX_MASK) | (x << UNIT_HEX_SHIFT) -} - function is_unit_supplied(u) { return ((view.units[u] & UNIT_SUPPLY_MASK) >> UNIT_SUPPLY_SHIFT) !== 0 } function unit_supply(u) { - let src = (view.units[u] & UNIT_SUPPLY_MASK) >> UNIT_SUPPLY_SHIFT - return hex_from_supply_source[src] + return (view.units[u] & UNIT_SUPPLY_MASK) >> UNIT_SUPPLY_SHIFT } function is_unit_unsupplied(u) { - return ((view.units[u] & UNIT_SUPPLY_MASK) >> UNIT_SUPPLY_SHIFT) === 0 -} - -function set_unit_supply(u, hex) { - let src = supply_source_from_hex(hex) - view.units[u] = (view.units[u] & ~UNIT_SUPPLY_MASK) | (src << UNIT_SUPPLY_SHIFT) + if (is_map_hex(unit_hex(u))) + return ((view.units[u] & UNIT_SUPPLY_MASK) >> UNIT_SUPPLY_SHIFT) === 0 + return false } function unit_lost_steps(u) { return (view.units[u] & UNIT_STEPS_MASK) >> UNIT_STEPS_SHIFT } -function set_unit_lost_steps(u, n) { - view.units[u] = (view.units[u] & ~UNIT_STEPS_MASK) | (n << UNIT_STEPS_SHIFT) -} - function unit_steps(u) { return unit_start_steps[u] - unit_lost_steps(u) } -function set_unit_steps(u, n) { - set_unit_lost_steps(u, unit_start_steps[u] - n) -} - function is_unit_moved(u) { return set_has(view.moved, u) } @@ -340,13 +325,23 @@ for (let u = 0; u <= 93; ++u) { function on_focus_unit(evt) { let u = evt.target.unit - let t = "(" + u + ")" - t += " " + unit_description[u] - t += " \"" + unit_name[u] + "\"" + let t = "" + if (is_unit_revealed(u)) { + t += " " + unit_description[u] + t += " \"" + unit_name[u] + "\"" + } else { + t = is_allied_unit(u) ? "Allied unit" : "Axis unit" + } if (is_unit_disrupted(u)) t += " - disrupted" if (is_unit_unsupplied(u)) t += " - unsupplied" + else { + if (unit_supply(u) === SS_BARDIA) t += " - Bardia supply" + if (unit_supply(u) === SS_TOBRUK) t += " - Tobruk supply" + if (unit_supply(u) === SS_BENGHAZI) t += " - Benghazi supply" + if (unit_supply(u) === SS_OASIS) t += " - Oasis supply" + } if (is_unit_moved(u)) t += " - moved" if (is_unit_fired(u)) @@ -663,7 +658,7 @@ function update_map() { e.classList.toggle("selected", !view.battle && is_unit_selected(u)) e.classList.toggle("disrupted", is_unit_disrupted(u)) e.classList.toggle("moved", is_unit_moved(u)) - // e.classList.toggle("unsupplied", is_unit_unsupplied(u)) + e.classList.toggle("unsupplied", is_unit_unsupplied(u)) e.classList.toggle("revealed", is_unit_revealed(u)) } -- cgit v1.2.3