diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 168 |
1 files changed, 95 insertions, 73 deletions
@@ -641,17 +641,87 @@ function build_cards() { build_units() build_cards() -let stack = new Array(map_w * map_h + 21) -for (let i = 0; i < stack.length; ++i) - stack[i] = [] +let stack_list = new Array(map_w * map_h + 21) +for (let i = 0; i < stack_list.length; ++i) + stack_list[i] = [[],[]] + +function layout_stack(stack, hex, start_x, start_y, wrap, xdir) { + for (let i = 0; i < stack.length; ++i) { + let u = stack[i] + let e = ui.units[u] + let x, y, z + + if (is_setup_hex(hex)) { + if (view.month == 8) + wrap = 14 + else + wrap = 12 + x = start_x - 25 + ((i % wrap) | 0) * 56 + y = start_y - 25 + ((i / wrap) | 0) * 56 + z = 201 + } else if (stack === ui.focus) { + if (start_x > 2000) xdir = -1 + if (start_x < 600) xdir = 1 + x = start_x - 25 + xdir * ((i / wrap) | 0) * 56 + y = start_y - 25 + (i % wrap) * 56 + z = 200 + } else { + if (stack.length <= 1) { + x = start_x - 25 + i * 11 + y = start_y - 25 + i * 14 + } else if (stack.length <= 4) { + x = start_x - 30 + i * 11 + y = start_y - 30 + i * 14 + } else if (stack.length <= 8) { + x = start_x - 30 + i * 4 + y = start_y - 30 + i * 4 + } else { + x = start_x - 35 + i * 3 + y = start_y - 35 + i * 3 + } + if (is_unit_revealed(u)) + z = 1 + i + else + z = 1 + i + } + + e.style.top = y + "px" + e.style.left = x + "px" + e.style.zIndex = z + + if (is_unit_revealed(u)) { + let r = unit_lost_steps(u) + e.classList.toggle("r0", r === 0) + e.classList.toggle("r1", r === 1) + e.classList.toggle("r2", r === 2) + e.classList.toggle("r3", r === 3) + e.classList.toggle("revealed", true) + } else { + e.classList.toggle("r0", false) + e.classList.toggle("r1", false) + e.classList.toggle("r2", false) + e.classList.toggle("r3", false) + e.classList.toggle("revealed", false) + } + + e.classList.toggle("action", !view.battle && is_unit_action(u)) + 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)) + } + +} function update_map() { ui.bardia.classList.toggle("axis", (view.fortress & 1) === 0) ui.benghazi.classList.toggle("axis", (view.fortress & 2) === 0) ui.tobruk.classList.toggle("axis", (view.fortress & 4) === 0) - for (let i = 0; i < stack.length; ++i) - stack[i].length = 0 + for (let i = 0; i < stack_list.length; ++i) { + 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) @@ -670,8 +740,13 @@ function update_map() { if (hex) { if (!ui.units_holder.contains(e)) ui.units_holder.appendChild(e) - stack[hex].push(u) - e.stack = stack[hex] + if (is_axis_unit(u)) { + stack_list[hex][0].push(u) + e.stack = stack_list[hex][0] + } else { + stack_list[hex][1].push(u) + e.stack = stack_list[hex][1] + } e.hex = hex } else { e.remove() @@ -680,7 +755,6 @@ function update_map() { 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("show", true) ui.months[i].classList.toggle("now", i === view.month) } @@ -704,7 +778,7 @@ function update_map() { ui.minefields[i].remove() } - for (let hex = 0; hex < stack.length; ++hex) { + for (let hex = 0; hex < stack_list.length; ++hex) { let start_x = ui.hex_x[hex] let start_y = ui.hex_y[hex] let wrap = 6 @@ -714,73 +788,21 @@ function update_map() { start_y = 25 + 8 } - if (stack[hex] === ui.focus) { - let height = Math.min(wrap, stack[hex].length) * 56 - if (start_y + height + 25 > 960) - start_y = 960 - height + 25 - } - - for (let i = 0; i < stack[hex].length; ++i) { - let u = stack[hex][i] - let e = ui.units[u] - let x, y, z - - if (is_setup_hex(hex)) { - if (view.month == 8) - wrap = 14 - else - wrap = 12 - x = start_x - 25 + ((i % wrap) | 0) * 56 - y = start_y - 25 + ((i / wrap) | 0) * 56 - z = 101 - } else if (stack[hex] === ui.focus) { - if (start_x > 2000) - x = start_x - 25 - ((i / wrap) | 0) * 56 - else - x = start_x - 25 + ((i / wrap) | 0) * 56 - y = start_y - 25 + (i % wrap) * 56 - z = 100 - } else { - if (stack[hex].length <= 1) { - x = start_x - 25 + i * 11 - y = start_y - 25 + i * 14 - } else if (stack[hex].length <= 4) { - x = start_x - 30 + i * 11 - y = start_y - 30 + i * 14 - } else if (stack[hex].length <= 8) { - x = start_x - 30 + i * 4 - y = start_y - 30 + i * 4 - } else { - x = start_x - 35 + i * 3 - y = start_y - 35 + i * 3 - } - z = 1 + i + let shared = (stack_list[hex][0].length > 0) && (stack_list[hex][1].length > 0) + for (let aa = 0; aa < 2; ++aa) { + if (stack_list[hex][aa] === ui.focus) { + let height = Math.min(wrap, stack_list[hex][aa].length) * 56 + if (start_y + height + 25 > 960) + start_y = 960 - height + 25 } - - e.style.top = y + "px" - e.style.left = x + "px" - e.style.zIndex = z - - if (is_unit_revealed(u)) { - let r = unit_lost_steps(u) - e.classList.toggle("r0", r === 0) - e.classList.toggle("r1", r === 1) - e.classList.toggle("r2", r === 2) - e.classList.toggle("r3", r === 3) - e.classList.toggle("revealed", true) + if (shared) { + if (aa === 0) + layout_stack(stack_list[hex][aa], hex, start_x - 28, start_y + 2, wrap, -1) + else + layout_stack(stack_list[hex][aa], hex, start_x + 28, start_y - 2, wrap, 1) } else { - e.classList.toggle("r0", false) - e.classList.toggle("r1", false) - e.classList.toggle("r2", false) - e.classList.toggle("r3", false) - e.classList.toggle("revealed", false) + layout_stack(stack_list[hex][aa], hex, start_x, start_y, wrap, 1) } - - e.classList.toggle("action", !view.battle && is_unit_action(u)) - 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)) } if (ui.hexes[hex]) { |