summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.js54
-rw-r--r--rules.js28
2 files changed, 69 insertions, 13 deletions
diff --git a/play.js b/play.js
index 039e1a5..dde9f1e 100644
--- a/play.js
+++ b/play.js
@@ -704,15 +704,26 @@ function on_blur_piece() {
/* UPDATE UI */
function layout_general_offset(g, s) {
- let n = 0
- for (let i = g+1; i < 24; ++i) {
- if (view.pos[i] === s) {
+ // if not selected: number of unselected generals below us
+ // if not selected: (number of unselected generals + 1) + number of selected generals below us
+ if (!set_has(view.selected, g)) {
+ let n = 0
+ for (let i = g+1; i < 24; ++i)
+ if (view.pos[i] === s && !set_has(view.selected, i))
+ ++n
+ return n
+ } else {
+ let n = 0
+ for (let i = 0; i < 24; ++i)
+ if (view.pos[i] === s && !set_has(view.selected, i))
+ ++n
+ if (n > 0)
++n
- if (is_action("piece", i))
+ for (let i = g+1; i < 24; ++i)
+ if (view.pos[i] === s && set_has(view.selected, i))
++n
- }
+ return n
}
- return n
}
function layout_general_count(g, s) {
@@ -952,11 +963,13 @@ function on_update() {
for (let v = 16; v >= 0; --v)
action_button_with_argument("value", v, v)
+ for (let p = 0; p < 24; ++p)
+ action_button_with_argument("detach", p, "Detach " + piece_button_name[p])
+
action_button("take", "Take")
action_button("give", "Give")
action_button("recruit", "Recruit")
action_button("transfer", "Transfer")
- action_button("detach", "Detach")
action_button("stop", "Stop")
action_button("pass", "Pass")
@@ -1036,6 +1049,33 @@ const piece_power = [
P_FRANCE,
]
+const piece_button_name = [
+ "P1",
+ "P2",
+ "P3",
+ "P4",
+ "P5",
+ "P6",
+ "P7",
+ "P8",
+ "H1",
+ "H2",
+ "R1",
+ "R2",
+ "R3",
+ "R4",
+ "S1",
+ "A1",
+ "A2",
+ "A3",
+ "A4",
+ "A5",
+ "IA1",
+ "F1",
+ "F2",
+ "F3",
+]
+
const piece_tooltip_name = [
"P1 Friedrich",
"P2 Winterfeldt",
diff --git a/rules.js b/rules.js
index be51130..90a8ed8 100644
--- a/rules.js
+++ b/rules.js
@@ -1639,17 +1639,26 @@ states.move_general = {
// two options: leave alone, or leave with chevert
// to leave with chevert, detach non-chevert
// to leave alone, detach non-chevert, then detach chevert
- if (game.selected.length === 3)
- for (let p of game.selected)
- if (p !== GEN_CHEVERT)
+ if (game.selected.length === 3) {
+ for (let p of game.selected) {
+ if (p !== GEN_CHEVERT) {
gen_action_piece(p)
- if (game.selected.length === 2)
+ gen_action_detach(p)
+ }
+ }
+ }
+ if (game.selected.length === 2) {
gen_action_piece(GEN_CHEVERT)
+ gen_action_detach(GEN_CHEVERT)
+ }
}
} else {
- if (game.selected.length > 1)
- for (let p of game.selected)
+ if (game.selected.length > 1) {
+ for (let p of game.selected) {
gen_action_piece(p)
+ gen_action_detach(p)
+ }
+ }
}
let s_take = count_stacked_take()
@@ -1692,6 +1701,9 @@ states.move_general = {
give() {
game.state = "move_give"
},
+ detach(p) {
+ set_delete(game.selected, p)
+ },
piece(p) {
if (game.count === 0) {
if (set_has(game.selected, p))
@@ -4388,6 +4400,10 @@ function gen_action_card(c) {
gen_action("card", c)
}
+function gen_action_detach(p) {
+ gen_action("detach", p)
+}
+
function log(msg) {
game.log.push(msg)
}