diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-07-18 14:53:35 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:25 +0100 |
commit | ca8a901cb4ef47356e6e82784aea0a3e8762e7b6 (patch) | |
tree | 440951749346e83a18e53ee3aea0bb9cdf5754fb /play.js | |
parent | ae66c6ac3ed4f2cfff6e41121161cd83a9c5289b (diff) | |
download | rommel-in-the-desert-ca8a901cb4ef47356e6e82784aea0a3e8762e7b6.tar.gz |
state cleanup
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 62 |
1 files changed, 55 insertions, 7 deletions
@@ -73,24 +73,72 @@ let ui = { const AXIS = 'Axis' const ALLIED = 'Allied' +// === UNIT STATE === + +const UNIT_DISRUPTED_SHIFT = 0 +const UNIT_DISRUPTED_MASK = 1 << UNIT_DISRUPTED_SHIFT + +const UNIT_STEPS_SHIFT = 1 +const UNIT_STEPS_MASK = 3 << UNIT_STEPS_SHIFT + +const UNIT_SUPPLY_SHIFT = 3 +const UNIT_SUPPLY_MASK = 7 << UNIT_SUPPLY_SHIFT + +const UNIT_HEX_SHIFT = 6 +const UNIT_HEX_MASK = 255 << UNIT_HEX_SHIFT + +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] >>> 5 + return (view.units[u] & UNIT_HEX_MASK) >> UNIT_HEX_SHIFT } -function unit_lost_steps(u) { - return view.units[u] & 3 +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] & 4) === 4 + return ((view.units[u] & UNIT_SUPPLY_MASK) >> UNIT_SUPPLY_SHIFT) !== 0 } -function is_unit_disrupted(u) { - return (view.units[u] & 8) === 8 +function unit_supply(u) { + let src = (view.units[u] & UNIT_SUPPLY_MASK) >> UNIT_SUPPLY_SHIFT + return hex_from_supply_source[src] +} + +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) +} + +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 units[u].steps - unit_lost_steps(u) +} + +function set_unit_steps(u, n) { + set_unit_lost_steps(u, units[u].steps - n) } function is_unit_moved(u) { - return (view.units[u] & 16) === 16 + return set_has(view.moved, u) } function is_unit_fired(u) { |