summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-07-27 15:22:13 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:26 +0100
commitb4d3f46b6e0497af9836dfd00a0918bc0f95a5db (patch)
tree3825bc5aa2bc4a6c284ef29b59fd20a8b61e886a /rules.js
parent4177faf4cce352fa472de8b8dae503e6dc705941 (diff)
downloadrommel-in-the-desert-b4d3f46b6e0497af9836dfd00a0918bc0f95a5db.tar.gz
Misc fixes.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js91
1 files changed, 59 insertions, 32 deletions
diff --git a/rules.js b/rules.js
index e0f8ae6..20a1ce0 100644
--- a/rules.js
+++ b/rules.js
@@ -1175,6 +1175,7 @@ function search_withdraw(who, bonus) {
let sline = unit_supply_line(who)
let sdist = unit_supply_distance(who)
let speed = unit_speed(who) + bonus
+ let start = unit_hex(who)
search_move_bfs(path_from[0], path_cost[0], start, 0, speed, false, sline, sdist)
search_move_bfs(path_from[1], path_cost[1], start, 1, speed + 1, false, sline, sdist)
@@ -1186,6 +1187,7 @@ function search_withdraw_retreat(who, bonus) {
let sline = unit_supply_line(who)
let sdist = unit_supply_distance(who)
let speed = unit_speed(who) + bonus
+ let start = unit_hex(who)
search_move_bfs(path_from[0], path_cost[0], start, 0, speed, true, sline, sdist)
search_move_bfs(path_from[1], path_cost[1], start, 1, speed + 1, true, sline, sdist)
@@ -1957,8 +1959,6 @@ function apply_move(to) {
push_undo()
- console.log("apply_move", hex_name[to])
-
if (has_enemy_unit(to)) {
// TODO: pick hex-side manually when engaging
}
@@ -2020,7 +2020,7 @@ function is_valid_retreat_hex(from) {
function can_any_retreat(from) {
let result = false
- for_each_undisrupted_friendly_unit_in_hex(from, u => {
+ for_each_undisrupted_and_unmoved_friendly_unit_in_hex(from, u => {
if (result === false) {
if (can_unit_retreat(u))
result = true
@@ -2032,23 +2032,25 @@ function can_any_retreat(from) {
function can_all_retreat(from) {
let result = true
for_each_undisrupted_friendly_unit_in_hex(from, u => {
- if (result === true && !can_unit_retreat(u))
+ if (result === true && !is_unit_moved(u) && !can_unit_retreat(u))
result = false
})
return result
}
function can_unit_retreat(who) {
+ let rommel1 = (game.rommel === 1) ? 1 : 0
+ let rommel2 = (game.rommel === 2) ? 1 : 0
let from = unit_hex(who)
if (!game.to1 && game.from1 === from)
- return can_unit_retreat_group_move(from)
+ return can_unit_retreat_group_move(who)
if (!game.to2 && game.from2 === from)
- return can_unit_retreat_group_move(from)
+ return can_unit_retreat_group_move(who)
if (game.to1 && is_hex_or_adjacent_to(from, game.from1))
- if (can_unit_retreat_regroup_move(u, game.to1, rommel1))
+ if (can_unit_retreat_regroup_move(who, game.to1, rommel1))
return true
if (game.to2 && is_hex_or_adjacent_to(from, game.from2))
- if (can_unit_retreat_regroup_move(u, game.to2, rommel2))
+ if (can_unit_retreat_regroup_move(who, game.to2, rommel2))
return true
return false
}
@@ -2067,6 +2069,12 @@ function can_unit_retreat_regroup_move(who, to, rommel) {
return can_unit_disengage_and_move_to(who, to, rommel)
}
+function is_friendly_hexside(side) {
+ if (is_axis_player())
+ return set_has(game.axis_sides, side)
+ return set_has(game.allied_sides, side)
+}
+
function can_unit_disengage_and_withdraw(who) {
let sline = unit_supply_line(who)
let sdist = unit_supply_distance(who)
@@ -2181,7 +2189,7 @@ states.retreat_who = {
prompt() {
view.prompt = `Retreat: Select units to retreat.`
let full_retreat = true
- for_each_undisrupted_friendly_unit_in_hex(game.retreat, u => {
+ for_each_undisrupted_and_unmoved_friendly_unit_in_hex(game.retreat, u => {
if (!set_has(game.retreat_units, u))
full_retreat = false
if (can_unit_retreat(u))
@@ -2203,7 +2211,7 @@ states.retreat_who = {
set_toggle(game.retreat_units, u)
},
select_all() {
- for_each_undisrupted_friendly_unit_in_hex(game.retreat, u => {
+ for_each_undisrupted_and_unmoved_friendly_unit_in_hex(game.retreat, u => {
if (!set_has(game.retreat_units, u))
if (can_unit_retreat(u))
set_add(game.retreat_units, u)
@@ -2805,18 +2813,29 @@ function apply_battle_fire(tc) {
})
}
if (done) {
- set_enemy_player()
+ goto_hits()
+ }
+}
- // round down half-hits from double defense
- game.hits[0] |= 0
- game.hits[1] |= 0
- game.hits[2] |= 0
- game.hits[3] |= 0
+function goto_hits() {
+ set_enemy_player()
+
+ // round down half-hits from double defense
+ game.hits[0] |= 0
+ game.hits[1] |= 0
+ game.hits[2] |= 0
+ game.hits[3] |= 0
+ if (game.hits[0] + game.hits[1] + game.hits[2] + game.hits[3] > 0) {
if (game.state === 'battle_fire')
game.state = 'battle_hits'
else
game.state = 'probe_hits'
+ } else {
+ if (game.state === 'battle_fire')
+ end_battle_hits()
+ else
+ end_probe_hits()
}
}
@@ -2952,18 +2971,22 @@ states.battle_hits = {
},
next() {
clear_undo()
- if (is_friendly_rout_hex(game.battle)) {
- goto_rout(game.battle, false, end_battle)
- } else if (game.active === game.phasing) {
- // goto offensive fire
- game.state = 'battle_fire'
- game.hits = [ 0, 0, 0, 0 ]
- } else {
- end_battle()
- }
+ end_battle_hits()
},
}
+function end_battle_hits() {
+ if (is_friendly_rout_hex(game.battle)) {
+ goto_rout(game.battle, false, end_battle)
+ } else if (game.active === game.phasing) {
+ // goto offensive fire
+ game.state = 'battle_fire'
+ game.hits = [ 0, 0, 0, 0 ]
+ } else {
+ end_battle()
+ }
+}
+
states.probe_fire = {
prompt() {
if (game.active !== game.phasing)
@@ -3006,16 +3029,20 @@ states.probe_hits = {
},
next() {
clear_undo()
- if (game.active !== game.phasing && has_friendly_units_in_battle()) {
- // goto offensive fire
- game.state = 'probe_fire'
- game.hits = [ 0, 0, 0, 0 ]
- } else {
- end_probe()
- }
+ end_probe_hits()
},
}
+function end_probe_hits() {
+ if (game.active !== game.phasing && has_friendly_units_in_battle()) {
+ // goto offensive fire
+ game.state = 'probe_fire'
+ game.hits = [ 0, 0, 0, 0 ]
+ } else {
+ end_probe()
+ }
+}
+
// === PURSUIT FIRE ===
// Refuse battle