From 8a29c80a3b67a480832b5a4828fc1f1b2203b0b1 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 27 Mar 2023 14:05:10 +0200 Subject: Add different highlight for dangerous moves. Make colors clearer. Moves into spaces which will yield to the opponent are highlighted with an extra red inside border. Also change colors to be consistent: Yellow - action for both spaces and units Blue - selected unit White - highlight (both for tooltip and current battle/intercept space) Clearer blue and red colors for supply lines. RED --- rules.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 575a055..fbb1b0e 100644 --- a/rules.js +++ b/rules.js @@ -1,5 +1,7 @@ "use strict" +// TODO: "danger_space" action for moving into interception/battle + // WONTFIX // TODO: select leader for defense instead of automatically picking the best // TODO: remove old 7 command leader(s) immediately as they're drawn, before placing reinforcements @@ -2961,6 +2963,40 @@ function has_friendly_fortifications_or_cultivated(s) { return has_friendly_fortifications(s) || is_originally_friendly(s) } +function add_danger_space(s) { + if (!view.danger) + view.danger = [] + set_add(view.danger, s) +} + +// Check if this move may lead to intercept/battle/other loss of control that prevents undo +function is_danger_move(from, to) { + // Lake Schooner + if (is_enemy_card_available(LAKE_SCHOONER)) + if (has_enemy_fortifications(to) && is_lake_connection(from, to)) + return true + + // Battle (and interception if infiltrating) + if (has_unbesieged_enemy_units(to)) + return true + + // Retreat Lone Leader + if (has_unbesieged_enemy_leader(to)) + return true + + // Interception + if (can_be_intercepted(from, to)) + return true + + return false +} + +function gen_action_move(from, to) { + if (is_danger_move(from, to)) + add_danger_space(to) + gen_action_space(to) +} + function gen_naval_move() { let from = moving_piece_space() if (!piece_can_naval_move_from(moving_piece(), from)) @@ -2968,19 +3004,19 @@ function gen_naval_move() { if (game.active === BRITAIN) { game.amphib.forEach(to => { if (to !== from) - gen_action_space(to) + gen_action_move(from, to) }) ports.forEach(to => { if (to !== from && !set_has(game.amphib, to)) if (is_friendly_controlled_space(to)) - gen_action_space(to) + gen_action_move(from, to) }) } if (game.active === FRANCE) { if (from !== LOUISBOURG && is_friendly_controlled_space(LOUISBOURG)) - gen_action_space(LOUISBOURG) + gen_action_move(from, LOUISBOURG) if (from !== QUEBEC && is_friendly_controlled_space(QUEBEC)) - gen_action_space(QUEBEC) + gen_action_move(from, QUEBEC) } } @@ -3110,14 +3146,14 @@ function gen_regular_move() { switch (game.move.type) { case 'boat-or-land': if (can_move_by_boat_or_land(game.move.used, game.move.did_carry, from, to)) - gen_action_space(to) + gen_action_move(from, to) break case 'boat': if (can_move_by_boat(game.move.used, game.move.did_carry, from, to)) - gen_action_space(to) + gen_action_move(from, to) break case 'land': - gen_action_space(to) + gen_action_move(from, to) break } }) @@ -3572,12 +3608,12 @@ states.amphibious_landing = { view.prompt = `Amphibious Landing: Select a destination for ${piece_name_and_place(who)}.` view.who = who if (from === HALIFAX) { - gen_action_space(LOUISBOURG) + gen_action_move(from, LOUISBOURG) } if (from === LOUISBOURG) { - gen_action_space(BAIE_ST_PAUL) - gen_action_space(RIVIERE_OUELLE) - gen_action_space(ILE_D_ORLEANS) + gen_action_move(from, BAIE_ST_PAUL) + gen_action_move(from, RIVIERE_OUELLE) + gen_action_move(from, ILE_D_ORLEANS) } }, space(to) { @@ -3676,12 +3712,10 @@ function end_move() { // INTERCEPT -function can_be_intercepted() { +function can_be_intercepted(came_from, here) { let result = false let who = moving_piece() - let here = moving_piece_space() - let came_from = moving_piece_came_from() // 6.723 Leaders moving alone can NOT be intercepted if (is_lone_leader(who)) @@ -3779,7 +3813,7 @@ function goto_intercept() { } } - if (can_be_intercepted()) { + if (can_be_intercepted(moving_piece_came_from(), moving_piece_space())) { game.move.intercepting = 0 set_active_enemy() game.state = 'intercept_who' -- cgit v1.2.3