diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-08-28 11:46:44 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:26 +0100 |
commit | 0ffda67c0726e8906fba200c2a1fb586ed09f0d6 (patch) | |
tree | 8ca054e147c6331c7d1fb444b1bc156e81adf813 /rules.js | |
parent | 58dc4f6e59d5cf463fa3b413caa08690dcfaa490 (diff) | |
download | rommel-in-the-desert-0ffda67c0726e8906fba200c2a1fb586ed09f0d6.tar.gz |
Remember old supply lines during withdrawal regroup moves.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 59 |
1 files changed, 56 insertions, 3 deletions
@@ -1496,6 +1496,16 @@ function tobruk_supply_network() { } function unit_supply_line(who) { + // override with saved supply line during withdrawal regroup moves + if (is_active_player() && game.withdraw && game.withdraw.supply_line) { + switch (unit_supply(who)) { + case SS_BARDIA: return game.withdraw.bardia_line + case SS_BENGHAZI: return game.withdraw.benghazi_line + case SS_TOBRUK: return game.withdraw.tobruk_line + } + return game.withdraw.supply_line + } + switch (unit_supply(who)) { case SS_BARDIA: return bardia_supply_line() case SS_BENGHAZI: return benghazi_supply_line() @@ -1551,6 +1561,12 @@ function friendly_supply_network() { return allied_supply_network() } +function friendly_supply_line() { + if (is_axis_player()) + return axis_supply_line() + return allied_supply_line() +} + function query_friendly_supply_network(src, x, y) { let save_x let save_y @@ -1613,7 +1629,6 @@ function search_move_retreat(start, speed) { } function search_withdraw(who, bonus) { - // TODO: pass remembered supply line let sline = unit_supply_line(who) let sdist = unit_supply_distance(who) let speed = unit_speed[who] + bonus @@ -2708,6 +2723,26 @@ states.final_supply_check_rout = { } } +function save_withdrawal_supply_lines() { + let net = game.withdraw.supply_net = friendly_supply_network().slice() + game.withdraw.supply_line = friendly_supply_line().slice() + + if (!net[BARDIA] && is_fortress_friendly_controlled(BARDIA)) { + game.withdraw.bardia_net = bardia_supply_network().slice() + game.withdraw.bardia_line = bardia_supply_line().slice() + } + + if (!net[BENGHAZI] && is_fortress_friendly_controlled(BENGHAZI)) { + game.withdraw.benghazi_net = benghazi_supply_network().slice() + game.withdraw.benghazi_line = benghazi_supply_line().slice() + } + + if (!net[TOBRUK] && is_fortress_friendly_controlled(TOBRUK)) { + game.withdraw.tobruk_net = tobruk_supply_network().slice() + game.withdraw.tobruk_line = tobruk_supply_line().slice() + } +} + // ==== MOVEMENT PHASE === function init_move_summary() { @@ -2787,8 +2822,10 @@ states.select_moves = { regroup() { push_undo() game.state = 'regroup_move_command_point' - if (game.turn_option === 'pass') + if (game.turn_option === 'pass') { game.withdraw = list_valid_withdrawal_regroup_command_points() + save_withdrawal_supply_lines() + } }, end_turn() { clear_undo() @@ -3024,15 +3061,31 @@ function goto_move() { game.state = 'move' } +function is_withdraw_network_reduced() { + if (game.withdraw.supply_net) { + if (is_network_reduced(game.withdraw.supply_net, friendly_supply_network())) + return true + if (game.withdraw.bardia_net && is_network_reduced(game.withdraw.bardia_net, bardia_supply_network())) + return true + if (game.withdraw.benghazi_net && is_network_reduced(game.withdraw.benghazi_net, benghazi_supply_network())) + return true + if (game.withdraw.tobruk_net && is_network_reduced(game.withdraw.tobruk_net, tobruk_supply_network())) + return true + } + return false +} + function can_end_move() { if (game.turn_option !== 'pass') return true if (game.to1) { - // TODO: regroup move: did we reduce the supply network? + // quick check for (let x of game.withdraw.always) if (!has_friendly_unit(x)) return true + // full check + return is_withdraw_network_reduced() } else { if (!has_friendly_unit(game.from1)) return true |