diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-08-29 00:29:35 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:26 +0100 |
commit | e29c4c81a0e3d07b26477c92bd3e172750f13500 (patch) | |
tree | c5a52fdb1f13f0c07ff8319993337dccf43b877e /rules.js | |
parent | ce4898ae41817f990013c6bf22d081e87dde1ed7 (diff) | |
download | rommel-in-the-desert-e29c4c81a0e3d07b26477c92bd3e172750f13500.tar.gz |
Clean up hex_supply_source (for non-overlapping supply nets).
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 36 |
1 files changed, 28 insertions, 8 deletions
@@ -1542,6 +1542,26 @@ function unit_supply_source(who) { return ALEXANDRIA } +function hex_supply_source(x) { + // TODO: overlapping fortress supply? + let who = any_friendly_undisrupted_unit_in_hex(x) + return unit_supply_source(who) +} + +function hex_supply_network(x) { + // TODO: overlapping fortress supply? + let who = any_friendly_undisrupted_unit_in_hex(x) + return unit_supply_network(who) +} + +function src_supply_network(src) { + if (src === EL_AGHEILA) return axis_supply_network() + if (src === ALEXANDRIA) return allied_supply_network() + if (src === BARDIA) return bardia_supply_network() + if (src === BENGHAZI) return benghazi_supply_network() + if (src === TOBRUK) return tobruk_supply_network() +} + function friendly_supply_base() { if (is_axis_player()) return EL_AGHEILA @@ -1560,7 +1580,7 @@ function friendly_supply_line() { return allied_supply_line() } -function query_friendly_supply_network(src, x, y) { +function query_friendly_supply_network_from_to(src, x, y) { let save_x let save_y if (is_axis_player()) { @@ -2003,9 +2023,9 @@ function is_valid_withdrawal_group_move_from(x) { // non-retreat withdrawal, check if network is reduced after we leave this hex if (can_all_undisrupted_units_withdraw(x)) { // All units in hex have the same supply source - let who = any_friendly_undisrupted_unit_in_hex(x) - let net = unit_supply_network(who) - let new_net = query_friendly_supply_network(unit_supply_source(who), x, 0) + let src = hex_supply_source(x) + let net = hex_supply_network(x) + let new_net = query_friendly_supply_network_from_to(src, x, 0) if (is_network_reduced(net, new_net)) return true } @@ -2017,7 +2037,7 @@ function is_valid_withdrawal_group_move_to(src, net, from, to) { if (is_battle_hex(from)) { return true } else { - let new_net = query_friendly_supply_network(src, from, to) + let new_net = query_friendly_supply_network_from_to(src, from, to) if (is_network_reduced(net, new_net)) return true } @@ -2042,9 +2062,9 @@ function is_valid_withdrawal_regroup_move_from(x) { } else { // non-retreat withdrawal, check if network is reduced after we leave this hex if (can_all_undisrupted_units_withdraw(x)) { - let who = any_friendly_undisrupted_unit_in_hex(x) - let net = unit_supply_network(who) - let new_net = query_friendly_supply_network(unit_supply_source(who), x, 0) + let src = hex_supply_source(x) + let net = hex_supply_network(x) + let new_net = query_friendly_supply_network_from_to(src, x, 0) if (is_network_reduced(net, new_net)) return 2 // does not reduce network by itself, but maybe in cooperation with other hex withdrawals? |