From dbbe5ae68ffc6210241bbbb6eb86f9e4d0f16956 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 18 Oct 2024 23:15:45 +0200 Subject: Mixed stack supreme commander when equal ranks. --- rules.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 19 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 390494b..f4491a5 100644 --- a/rules.js +++ b/rules.js @@ -5,7 +5,6 @@ /* TODO victory check -supreme commander in mixed stacks supply phase hussar payment re-entering supply trains during movement (10.2) @@ -188,6 +187,15 @@ const piece_power = [ P_AUSTRIA, P_AUSTRIA ] +const piece_rank = [ + 1, 2, 3, 4, 5, + 1, + 1, 2, 3, 4, + 1, + 1, 2, 3, + 1, 2, 3, 4, 5, 6, +] + const piece_name = [ "Moritz", "Belle-Isle", @@ -219,6 +227,7 @@ const piece_name = [ ] const all_pieces = [ ...all_power_generals.flat(), ...all_power_trains.flat() ] +const all_trains = [ ...all_power_trains.flat() ] const all_generals = [ ...all_power_generals.flat() ] const all_france_bavaria_generals = [ @@ -634,16 +643,18 @@ function current_player() { } function get_top_piece(s) { - for (let p of all_pieces) + for (let p of all_trains) if (game.pos[p] === s) return p - return -1 + return get_supreme_commander(s) } function get_supreme_commander(s) { - // TODO: promoted minor power (check who is actually on top!) for (let p of all_generals) - if (game.pos[p] === s) + if ((game.supreme & (1<P" + p + " eliminated") else log("P" + p + " eliminated.") + game.supreme &= ~(1 << p) game.pos[p] = ELIMINATED game.troops[p] = 0 set_in_supply(p) @@ -1207,8 +1222,10 @@ states.movement = { game.move_path = [ here ] if (is_supply_train(p)) game.state = "move_supply_train" - else + else { + game.supreme &= ~(1 << p) game.state = "move_general" + } }, confirm_end_movement() { this.end_movement() @@ -1224,7 +1241,6 @@ states.movement = { log_conquest(game.move_conq) delete game.move_conq - // MARIA: recruit during winter goto_recruit() goto_combat() }, } @@ -1545,14 +1561,7 @@ states.move_give = { function end_move_piece() { let here = game.pos[game.selected] - // uniting stacks: flag all as moved - if (is_general(game.selected)) { - for (let p of all_coop_generals(game.power)) - if (game.pos[p] === here) - set_add(game.moved, p) - } else { - set_add(game.moved, game.selected) - } + set_add(game.moved, game.selected) log_move_path() @@ -1563,10 +1572,52 @@ function end_move_piece() { } delete game.move_path - game.selected = -1 - game.state = "movement" - set_active_to_current_action_step() + // uniting stacks: flag all as moved + let supreme = false + if (is_general(game.selected)) { + for (let p of all_coop_generals(game.power)) { + if (game.pos[p] === here && p !== game.selected) { + if (piece_rank[p] === piece_rank[game.selected]) + supreme = true + set_add(game.moved, p) + } + } + } + + if (supreme) { + game.state = "move_supreme" + } else { + game.selected = -1 + game.state = "movement" + set_active_to_current_action_step() + } +} + +states.move_supreme = { + inactive: "move", + prompt() { + prompt("Choose supreme commander for mixed stack.") + let here = game.pos[game.selected] + for (let p of all_coop_generals(game.power)) { + if (game.pos[p] === here) { + gen_action("supreme", p) + gen_action_piece(p) + } + } + }, + supreme(p) { + let here = game.pos[game.selected] + for (let p of all_coop_generals(game.power)) + if (game.pos[p] === here) + game.supreme &= ~(1<