summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-09-27 01:24:32 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:27 +0100
commitce8910eee718fbba261ba142e45b325db3411283 (patch)
tree6f782142fcae824121e5c4ecf6f3b779dcd638fd
parent8f81eefde0abdd1dac0649ff53c1100b07cb3387 (diff)
downloadrommel-in-the-desert-ce8910eee718fbba261ba142e45b325db3411283.tar.gz
Allow disrupted units to co-exist without creating a battle hex.
Don't create an engagement when retreating. Fix supply lines in co-exist hexes. Fix supply lines in former co-exist hexes when one side recovers.
-rw-r--r--rules.js38
1 files changed, 26 insertions, 12 deletions
diff --git a/rules.js b/rules.js
index 8e67ee2..6d53263 100644
--- a/rules.js
+++ b/rules.js
@@ -661,9 +661,13 @@ function is_allied_hex(x) {
}
function is_battle_hex(x) {
+ // battle hex if both sides present and at least one is undisrupted
+ // disrupted units from both sides can peacefully co-exist
if (presence_invalid)
update_presence()
- return (presence_axis[x] !== 0) && (presence_allied[x] !== 0)
+ let a = presence_axis[x]
+ let b = presence_allied[x]
+ return (a > 1 && b > 0) || (b > 1 && a > 0)
}
function is_enemy_hex(x) {
@@ -1146,9 +1150,11 @@ function is_supply_line_blocked(here, next, side) {
// out of battle hex
// can only cannot trace out through friendly sides
- if (supply_friendly[here] && supply_enemy[here])
- if (!set_has(supply_defender_sides, side))
- return true
+ if (supply_friendly[here] > 0 && supply_enemy[here] > 0) {
+ if (set_has(game.axis_hexes, here) || set_has(game.allied_hexes, here))
+ if (!set_has(supply_defender_sides, side))
+ return true
+ }
return false
}
@@ -1609,16 +1615,16 @@ function search_redeploy(start) {
// Breadth First Search
function search_path_bfs(from, cost, start, road, max_cost, retreat, sline, sdist) {
- let path_enemy, friendly_sides
+ let path_enemy, enemy_sides
if (presence_invalid)
update_presence()
if (is_axis_player()) {
path_enemy = presence_allied
- friendly_sides = game.axis_sides
+ enemy_sides = game.allied_sides
} else {
path_enemy = presence_axis
- friendly_sides = game.allied_sides
+ enemy_sides = game.axis_sides
}
from.fill(0)
@@ -1671,7 +1677,7 @@ function search_path_bfs(from, cost, start, road, max_cost, retreat, sline, sdis
let next_enemy = path_enemy[next]
if (retreat) {
// must cross friendly hex-side to disengage
- if (here === start && !set_has(friendly_sides, side))
+ if (here === start && set_has(enemy_sides, side))
continue
// may only ignore unshielded disrupted units
if (next_enemy & 2) // has undisrupted enemy
@@ -1880,7 +1886,7 @@ function can_unit_disengage_and_withdraw(who) {
let from = unit_hex(who)
for_each_adjacent_hex(from, to => {
let side = to_side_id(from, to)
- if (is_friendly_hexside(side) && !has_enemy_unit(to))
+ if (!is_enemy_hexside(side) && !has_undisrupted_enemy_unit(to))
if (sline[side] && sdist[to] <= sdist[from])
result = true
})
@@ -1893,7 +1899,7 @@ function can_unit_disengage_and_move(who) {
let result = false
for_each_adjacent_hex(from, to => {
let side = to_side_id(from, to)
- if (is_friendly_hexside(side) && !has_enemy_unit(to))
+ if (!is_enemy_hexside(side) && !has_undisrupted_enemy_unit(to))
result = true
})
return result
@@ -2731,7 +2737,7 @@ function goto_initial_supply_check_recover() {
function goto_initial_supply_check_rout() {
let rout = false
for (let x of all_hexes)
- if (is_friendly_rout_hex(x))
+ if (is_enemy_rout_hex(x))
rout = true
if (rout)
game.state = 'initial_supply_check_rout'
@@ -3670,12 +3676,20 @@ function move_via(who, to, speed, move) {
return game.hexside.via.length === 1
}
+function is_engagement_move(to) {
+ if (game.retreat > 0) {
+ // retreating units may co-exist with disrupted enemy units
+ return has_undisrupted_enemy_unit(to)
+ }
+ return has_enemy_unit(to)
+}
+
function move_unit(who, to, speed, move) {
let from = unit_hex(who)
game.used |= move
- if (is_forced_march_move(from, to, speed) || has_enemy_unit(to)) {
+ if (is_forced_march_move(from, to, speed) || is_engagement_move(to)) {
if (move_via(who, to, speed, move)) {
if (game.hexside.forced[0])
forced_march_via(who, game.hexside.via[0], to, move)