summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js29
1 files changed, 19 insertions, 10 deletions
diff --git a/rules.js b/rules.js
index 5dca9fe..adbf7d5 100644
--- a/rules.js
+++ b/rules.js
@@ -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
}