summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js36
1 files changed, 28 insertions, 8 deletions
diff --git a/rules.js b/rules.js
index 2a80a34..090918d 100644
--- a/rules.js
+++ b/rules.js
@@ -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?