diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-10-03 12:54:55 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:27 +0100 |
commit | 39b805a7da253435c5c8c694cb60b49f43adc83e (patch) | |
tree | d33c61538c058751b78b4244677f7613a4bdcb2d | |
parent | d331ad044c3c3be4fc057b1b00494a5c6fdc84f9 (diff) | |
download | rommel-in-the-desert-39b805a7da253435c5c8c694cb60b49f43adc83e.tar.gz |
Verify group and regroup options as valid retreat hexes.
The pass turn option already has strict checks. Add similar disengagement
hexside checks when listing valid group and regroup moves.
-rw-r--r-- | rules.js | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -952,11 +952,11 @@ function for_each_undisrupted_and_unmoved_friendly_unit_in_hex(x, fn) { fn(u) } -function count_hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(here) { +function count_hex_or_adjacent_that_has_any_unit_that_can_move(here) { let n = 0 for_each_hex_and_adjacent_hex(here, x => { - for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) { - if (is_unit_undisrupted(u) && !is_unit_moved(u) && unit_hex(u) === x) { + if (has_undisrupted_and_unmoved_friendly_unit(x)) { + if (!has_enemy_unit(x) || can_any_disengage(x)) { n++ return } @@ -3043,8 +3043,10 @@ states.select_moves = { function list_valid_group_moves() { let result = [] for (let x of all_hexes) { - if (has_undisrupted_and_unmoved_friendly_unit(x)) - set_add(result, x) + if (has_undisrupted_and_unmoved_friendly_unit(x)) { + if (!has_enemy_unit(x) || can_any_disengage(x)) + set_add(result, x) + } } if (has_friendly_unit_in_raw_hex(friendly_queue())) set_add(result, friendly_queue()) @@ -3081,7 +3083,7 @@ function list_valid_regroup_moves() { let result = [] for (let x of all_hexes) { if (!is_enemy_hex(x)) { - let n = count_hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(x) + let n = count_hex_or_adjacent_that_has_any_unit_that_can_move(x) // TODO: allow one-hex regroup moves? (failed forced march abuse) if (n >= 2) set_add(result, x) @@ -3947,13 +3949,20 @@ function can_unit_retreat(who) { return false } +function can_any_disengage(from) { + let result = false + for_each_undisrupted_and_unmoved_friendly_unit_in_hex(from, u => { + if (result === false && can_unit_disengage_and_move(u)) + result = true + }) + return result +} + function can_any_retreat(from) { let result = false for_each_undisrupted_and_unmoved_friendly_unit_in_hex(from, u => { - if (result === false) { - if (can_unit_retreat(u)) - result = true - } + if (result === false && can_unit_retreat(u)) + result = true }) return result } |