summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.html33
-rw-r--r--play.js67
-rw-r--r--rules.js16
3 files changed, 53 insertions, 63 deletions
diff --git a/play.html b/play.html
index d2b6869..8d84f2b 100644
--- a/play.html
+++ b/play.html
@@ -15,30 +15,17 @@
</head>
<body>
-<table id="battle">
-<tr>
-<th id="battle_header" colspan=4></th>
-<tr class="battle_reserves enemy">
-<td colspan=4><div id="ER"></div></td>
-<tr class="battle_line enemy">
-<td class="battle_a_cell"><div id="EA"></div></td>
-<td class="battle_b_cell"><div id="EB"></div></td>
-<td class="battle_c_cell"><div id="EC"></div></td>
-<td class="battle_d_cell"><div id="ED"></div></td>
-<tr class="battle_separator">
-<td colspan=4>
-<tr class="battle_line friendly">
-<td class="battle_a_cell"><div id="FA"></div></td>
-<td class="battle_b_cell"><div id="FB"></div></td>
-<td class="battle_c_cell"><div id="FC"></div></td>
-<td class="battle_d_cell"><div id="FD"></div></td>
-<tr class="battle_reserves friendly">
-<td colspan=4><div id="FR"></div></td>
-<tr>
-<th id="battle_message" colspan=4></th>
-</table>
+<div id="battle">
+<div id="battle_header"></div>
+<div id="ER"></div>
+<div id="EF"></div>
+<div id="FF"></div>
+<div id="FR"></div>
+<div id="battle_message"></div>
+</div>
<header>
+ <div id="toolbar">
<div class="menu">
<div class="menu_title"><img src="/images/cog.svg"></div>
<div class="menu_popup">
@@ -55,6 +42,7 @@
<div class="icon_button" onclick="toggle_blocks()"><img src="/images/earth-africa-europe.svg"></div>
<div class="icon_button" onclick="toggle_zoom()"><img src="/images/magnifying-glass.svg"></div>
<div class="icon_button" onclick="toggle_log()"><img src="/images/scroll-quill.svg"></div>
+ </div>
<div id="prompt"></div>
<div id="actions"></div>
</header>
@@ -87,7 +75,6 @@
<div id="map">
<svg id="svgmap" viewBox="0 0 1688 1950">
-<image href="map.jpg" x="0" y="0" width="1688" height="1950" />
<g transform="translate(0,1950) scale(0.1,-0.1)">
<path id="area_Scotland" class="area"
d="M3100 19454 c31 -71 27 -146 -11 -219 -17 -33 -40 -67 -50 -75 -17
diff --git a/play.js b/play.js
index 4e3212f..92bab6e 100644
--- a/play.js
+++ b/play.js
@@ -172,19 +172,12 @@ function on_click_map_block(evt) {
send_action('block', b);
}
-function is_battle_reserve(who, list) {
- for (let [b, s, m] of list)
- if (who === b)
- return true;
- return false;
-}
-
function on_focus_battle_block(evt) {
let b = evt.target.block;
let msg = block_name(b);
- if (is_battle_reserve(b, view.battle.LR))
+ if (view.battle.LR.includes(b))
msg = "Lancaster Reserve";
- if (is_battle_reserve(b, view.battle.YR))
+ if (view.battle.YR.includes(b))
msg = "York Reserve";
if (view.actions && view.actions.battle_fire && view.actions.battle_fire.includes(b))
@@ -322,6 +315,7 @@ function build_battle_block(b, block) {
menu.classList.add("battle_menu");
menu.appendChild(element);
menu.appendChild(menu_list);
+ menu.block = b;
ui.battle_menu[b] = menu;
}
@@ -587,6 +581,31 @@ function update_cards() {
document.getElementById("york_card").className = "show card " + CARDS[view.y_card].image;
}
+function compare_blocks(a, b) {
+ let aa = BLOCKS[a].combat;
+ let bb = BLOCKS[b].combat;
+ // Bombard
+ if (aa === "D3" && view.battle.round <= 1) aa = "A3";
+ if (bb === "D3" && view.battle.round <= 1) bb = "A3";
+ if (aa === bb)
+ return (a < b) ? -1 : (a > b) ? 1 : 0;
+ return (aa < bb) ? -1 : (aa > bb) ? 1 : 0;
+}
+
+function sort_battle_row(root) {
+ let swapped;
+ let children = root.children;
+ do {
+ swapped = false;
+ for (let i = 1; i < children.length; ++i) {
+ if (compare_blocks(children[i-1].block, children[i].block) > 0) {
+ children[i].after(children[i-1]);
+ swapped = true;
+ }
+ }
+ } while (swapped);
+}
+
function update_battle() {
function fill_cell(name, list, reserve) {
let cell = window[name];
@@ -596,6 +615,9 @@ function update_battle() {
for (let block of list) {
ui.present.add(block);
+ if (!cell.contains(ui.battle_menu[block]))
+ cell.appendChild(ui.battle_menu[block]);
+
if (block === view.who)
ui.battle_block[block].classList.add("selected");
else
@@ -640,37 +662,24 @@ function update_battle() {
}
for (let b in BLOCKS) {
- if (ui.present.has(b)) {
- if (!cell.contains(ui.battle_menu[b]))
- cell.appendChild(ui.battle_menu[b]);
- } else {
+ if (!ui.present.has(b)) {
if (cell.contains(ui.battle_menu[b]))
cell.removeChild(ui.battle_menu[b]);
}
}
+
+ sort_battle_row(cell);
}
if (player === LANCASTER) {
fill_cell("FR", view.battle.LR, true);
- fill_cell("FA", view.battle.LA, false);
- fill_cell("FB", view.battle.LB, false);
- fill_cell("FC", view.battle.LC, false);
- fill_cell("FD", view.battle.LD, false);
- fill_cell("EA", view.battle.YA, false);
- fill_cell("EB", view.battle.YB, false);
- fill_cell("EC", view.battle.YC, false);
- fill_cell("ED", view.battle.YD, false);
+ fill_cell("FF", view.battle.LF, false);
+ fill_cell("EF", view.battle.YF, false);
fill_cell("ER", view.battle.YR, true);
} else {
fill_cell("ER", view.battle.LR, true);
- fill_cell("EA", view.battle.LA, false);
- fill_cell("EB", view.battle.LB, false);
- fill_cell("EC", view.battle.LC, false);
- fill_cell("ED", view.battle.LD, false);
- fill_cell("FA", view.battle.YA, false);
- fill_cell("FB", view.battle.YB, false);
- fill_cell("FC", view.battle.YC, false);
- fill_cell("FD", view.battle.YD, false);
+ fill_cell("EF", view.battle.LF, false);
+ fill_cell("FF", view.battle.YF, false);
fill_cell("FR", view.battle.YR, true);
}
}
diff --git a/rules.js b/rules.js
index 717ec41..06fcf20 100644
--- a/rules.js
+++ b/rules.js
@@ -3351,8 +3351,9 @@ states.game_over = {
function make_battle_view() {
let battle = {
- LA: [], LB: [], LC: [], LD: [], LR: [],
- YA: [], YB: [], YC: [], YD: [], YR: [],
+ round: game.battle_round,
+ LF: [], LR: [],
+ YF: [], YR: [],
flash: game.flash
};
@@ -3366,16 +3367,9 @@ function make_battle_view() {
}
fill_cell(battle.LR, LANCASTER, b => is_battle_reserve(b));
- fill_cell(battle.LA, LANCASTER, b => !is_battle_reserve(b) && block_initiative(b) === 'A');
- fill_cell(battle.LB, LANCASTER, b => !is_battle_reserve(b) && block_initiative(b) === 'B');
- fill_cell(battle.LC, LANCASTER, b => !is_battle_reserve(b) && block_initiative(b) === 'C');
- fill_cell(battle.LD, LANCASTER, b => !is_battle_reserve(b) && block_initiative(b) === 'D');
-
+ fill_cell(battle.LF, LANCASTER, b => !is_battle_reserve(b));
fill_cell(battle.YR, YORK, b => is_battle_reserve(b));
- fill_cell(battle.YA, YORK, b => !is_battle_reserve(b) && block_initiative(b) === 'A');
- fill_cell(battle.YB, YORK, b => !is_battle_reserve(b) && block_initiative(b) === 'B');
- fill_cell(battle.YC, YORK, b => !is_battle_reserve(b) && block_initiative(b) === 'C');
- fill_cell(battle.YD, YORK, b => !is_battle_reserve(b) && block_initiative(b) === 'D');
+ fill_cell(battle.YF, YORK, b => !is_battle_reserve(b));
return battle;
}