diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-09-04 14:43:11 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:27 +0100 |
commit | 6d25e8e0f4e5b4c9e831350856aaf1ea6a61a18c (patch) | |
tree | a1b44eacadc2f21f1837f590b93ce611f0400d80 | |
parent | 90f1aa26dc17af43dcedba91160c4ff620d9b352 (diff) | |
download | rommel-in-the-desert-6d25e8e0f4e5b4c9e831350856aaf1ea6a61a18c.tar.gz |
Group units by status in stacks.
-rw-r--r-- | play.js | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -139,6 +139,10 @@ function is_unit_disrupted(u) { return (view.units[u] & UNIT_DISRUPTED_MASK) === UNIT_DISRUPTED_MASK } +function is_unit_undisrupted(u) { + return !is_unit_disrupted(u) +} + function unit_hex(u) { return (view.units[u] & UNIT_HEX_MASK) >> UNIT_HEX_SHIFT } @@ -713,6 +717,20 @@ function layout_stack(stack, hex, start_x, start_y, wrap, xdir) { } +function cmp_unit_stack(a, b) { + let as = a + let bs = b + as += is_unit_revealed(a) ? 800 : 0 + bs += is_unit_revealed(b) ? 800 : 0 + as += is_unit_undisrupted(a) ? 400 : 0 + bs += is_unit_undisrupted(b) ? 400 : 0 + as += is_unit_supplied(a) ? 200 : 0 + bs += is_unit_supplied(b) ? 200 : 0 + as += (is_unit_moved(a) && !is_unit_revealed(a)) ? 0 : 100 + bs += (is_unit_moved(b) && !is_unit_revealed(a)) ? 0 : 100 + return as - bs +} + function update_map() { ui.bardia.classList.toggle("axis", (view.fortress & 1) === 0) ui.benghazi.classList.toggle("axis", (view.fortress & 2) === 0) @@ -722,6 +740,7 @@ function update_map() { stack_list[i][0].length = 0 stack_list[i][1].length = 0 } + for (let u = 0; u < unit_count; ++u) { let e = ui.units[u] let hex = unit_hex(u) @@ -753,6 +772,11 @@ function update_map() { } } + for (let i = 0; i < stack_list.length; ++i) { + stack_list[i][0].sort(cmp_unit_stack) + stack_list[i][1].sort(cmp_unit_stack) + } + for (let i = 1; i <= 20; ++i) { ui.months[i].classList.toggle("show", (i >= view.start && i <= view.end) && (i < view.month + 10)) ui.months[i].classList.toggle("now", i === view.month) |