summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js102
1 files changed, 76 insertions, 26 deletions
diff --git a/rules.js b/rules.js
index 4a22e36..b462c2a 100644
--- a/rules.js
+++ b/rules.js
@@ -6,6 +6,7 @@
// TODO: RAIDERS
// TODO: MINEFIELDS
// TODO: legal pass withdrawal moves (reduce supply net, withdraw from fortress attack)
+// TODO: fortress combat in pass turns (must withdraw)
// TODO: group move from queue holding box to base
// TODO: 1942 malta group (reinforce, reduce supply card draw)
@@ -238,6 +239,18 @@ var supply_allied_invalid = true
var supply_allied_network = new Array(hexcount).fill(0)
var supply_allied_line = new Array(sidecount).fill(0)
+var supply_bardia_invalid = true
+var supply_bardia_network = new Array(hexcount).fill(0)
+var supply_bardia_line = new Array(sidecount).fill(0)
+
+var supply_benghazi_invalid = true
+var supply_benghazi_network = new Array(hexcount).fill(0)
+var supply_benghazi_line = new Array(sidecount).fill(0)
+
+var supply_tobruk_invalid = true
+var supply_tobruk_network = new Array(hexcount).fill(0)
+var supply_tobruk_line = new Array(sidecount).fill(0)
+
var supply_temp_network = new Array(hexcount).fill(0)
var supply_temp_line = new Array(sidecount).fill(0)
@@ -294,12 +307,19 @@ function update_aliases() {
}
}
+function invalidate_caches() {
+ presence_invalid = true
+ supply_axis_invalid = true
+ supply_allied_invalid = true
+ supply_tobruk_invalid = true
+ supply_bardia_invalid = true
+ supply_benghazi_invalid = true
+}
+
function load_state(state) {
if (game !== state) {
game = state
- presence_invalid = true
- supply_axis_invalid = true
- supply_allied_invalid = true
+ invalidate_caches()
update_aliases()
}
}
@@ -338,16 +358,11 @@ function is_unit_disrupted(u) {
}
function set_unit_disrupted(u) {
- presence_invalid = true
- supply_axis_invalid = true
- supply_allied_invalid = true
game.units[u] |= UNIT_DISRUPTED_MASK
}
function clear_unit_disrupted(u) {
- presence_invalid = true
- supply_axis_invalid = true
- supply_allied_invalid = true
+ invalidate_caches()
game.units[u] &= ~UNIT_DISRUPTED_MASK
}
@@ -356,9 +371,7 @@ function unit_hex(u) {
}
function set_unit_hex(u, x) {
- presence_invalid = true
- supply_axis_invalid = true
- supply_allied_invalid = true
+ invalidate_caches()
game.units[u] = (game.units[u] & ~UNIT_HEX_MASK) | (x << UNIT_HEX_SHIFT)
}
@@ -737,8 +750,7 @@ function claim_hex_control_for_defender(a) {
function capture_fortress(fortress, capacity) {
if (!is_fortress_friendly_controlled(fortress)) {
if (has_undisrupted_friendly_unit(fortress) && !has_enemy_unit(fortress)) {
- supply_axis_invalid = true
- supply_allied_invalid = true
+ invalidate_caches()
log(`Captured #${fortress}!`)
@@ -1232,28 +1244,27 @@ function trace_supply_network(start) {
//debug_hexes("SN", supply_net)
}
-// For repeated supplied hex checks during deployment
-function init_trace_supply_to_base() {
+// For repeated supplied hex checks during deployment and fortress assignment
+function init_trace_supply_to_base_or_fortress(net, line) {
if (presence_invalid)
update_presence()
- supply_net = supply_temp_network
- supply_line = supply_temp_line
- supply_defender = null
- supply_defender_sides = null
+ supply_net = net
+ supply_line = line
if (is_axis_player()) {
+ supply_defender = game.axis_hexes
+ supply_defender_sides = game.axis_sides
supply_friendly = presence_axis
supply_enemy = presence_allied
} else {
+ supply_defender = game.allied_hexes
+ supply_defender_sides = game.allied_sides
supply_friendly = presence_allied
supply_enemy = presence_axis
}
supply_net.fill(0)
}
-function can_trace_supply_to_base(base, from) {
- // we've already seen this hex during a previous supplied hex check this go
- if (supply_net[from] > 0)
- return true
+function can_trace_supply_to_base_or_fortress(base, from) {
supply_visited.fill(0)
supply_src.fill(0)
supply_src[base] = 1
@@ -1321,6 +1332,42 @@ function allied_supply_network() {
return supply_allied_network
}
+function bardia_supply_line() {
+ if (supply_bardia_invalid)
+ update_bardia_supply()
+ return supply_bardia_line
+}
+
+function bardia_supply_network() {
+ if (supply_bardia_invalid)
+ update_bardia_supply()
+ return supply_bardia_network
+}
+
+function benghazi_supply_line() {
+ if (supply_benghazi_invalid)
+ update_benghazi_supply()
+ return supply_benghazi_line
+}
+
+function benghazi_supply_network() {
+ if (supply_benghazi_invalid)
+ update_benghazi_supply()
+ return supply_benghazi_network
+}
+
+function tobruk_supply_line() {
+ if (supply_tobruk_invalid)
+ update_tobruk_supply()
+ return supply_tobruk_line
+}
+
+function tobruk_supply_network() {
+ if (supply_tobruk_invalid)
+ update_tobruk_supply()
+ return supply_tobruk_network
+}
+
function unit_supply_line(who) {
// TODO: fortress supply
if (is_axis_unit(who))
@@ -4559,7 +4606,10 @@ function goto_free_deployment() {
}
function is_valid_deployment_hex(base, x) {
- if (can_trace_supply_to_base(base, x))
+ // we've already seen this hex during a previous supplied hex check this go
+ if (supply_net[from] > 0)
+ return true
+ if (can_trace_supply_to_base_or_fortress(base, x))
return true
if (x === TOBRUK)
return count_friendly_units_in_hex(x) < 5
@@ -4588,7 +4638,7 @@ states.free_deployment = {
trace_total = 0
let base = friendly_base()
- init_trace_supply_to_base()
+ init_trace_supply_to_base_or_fortress()
for (let x of (axis ? scenario.axis_deployment : scenario.allied_deployment)) {
if (!is_enemy_hex(x)) {