summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js53
1 files changed, 46 insertions, 7 deletions
diff --git a/rules.js b/rules.js
index bd86bee..2d75589 100644
--- a/rules.js
+++ b/rules.js
@@ -5,6 +5,8 @@
// RULES: can refuse battle from hex with mixed undisrupted and disrupted units?
// assume yes, followed by rout
+// RULES: disrupted units routed again in second enemy turn, will they still recover?
+// assume yes, easy to change (remove from game.recover set if routed)
// unit state: location (8 bits), supply source (3 bits), steps (2 bits), disrupted (1 bit)
@@ -513,6 +515,20 @@ function for_each_hex_and_adjacent_hex(here, fn) {
}
}
+function for_each_friendly_unit(fn) {
+ // TODO: first/last_enemy_unit
+ for (let u = 0; u < units.length; ++u)
+ if (is_friendly_unit(u))
+ fn(u)
+}
+
+function for_each_enemy_unit(fn) {
+ // TODO: first/last_enemy_unit
+ for (let u = 0; u < units.length; ++u)
+ if (is_enemy_unit(u))
+ fn(u)
+}
+
function for_each_friendly_unit_in_hex(x, fn) {
// TODO: first/last_enemy_unit
for (let u = 0; u < units.length; ++u)
@@ -1213,10 +1229,32 @@ function goto_player_turn() {
game.from1 = game.from2 = 0
game.to1 = game.to2 = 0
- goto_supply_check()
+ goto_initial_supply_check()
}
-function goto_supply_check() {
+function goto_initial_supply_check() {
+ update_supply_networks()
+ let snet = game.phasing === AXIS ? game.axis_supply : game.allied_supply
+ let ssrc = game.phasing === AXIS ? EL_AGHEILA : ALEXANDRIA
+
+ for_each_friendly_unit(u => {
+ let x = unit_hex(u)
+ if (snet[x]) {
+ set_unit_supply(u, ssrc)
+ if (is_unit_disrupted(u) && set_has(game.recover, u) && !is_battle_hex(x)) {
+ log(`${unit_name(u)} recovered in ${hex_name[x]}`)
+ set_delete(game.recover, u)
+ clear_unit_disrupted(u)
+ }
+ }
+ })
+
+ set_clear(game.recover)
+ for_each_enemy_unit(u => {
+ if (is_unit_disrupted(u))
+ set_add(game.recover, u)
+ })
+
goto_turn_option()
}
@@ -1270,7 +1308,7 @@ states.turn_option = {
function goto_move_phase() {
game.state = 'select_moves'
- if (game.active === AXIS) {
+ if (game.phasing === AXIS) {
// Automatically select Rommel Move for 1-move turn options
if (game.turn_option !== 'offensive' && game.turn_option !== 'blitz' && game.scenario !== "1940")
game.rommel = 1
@@ -1308,7 +1346,7 @@ states.select_moves = {
}
function gen_rommel_move() {
- if (game.active === AXIS && game.scenario !== "1940")
+ if (game.phasing === AXIS && game.scenario !== "1940")
view.actions.rommel = game.rommel ? 0 : 1
}
@@ -1779,7 +1817,7 @@ states.refuse_battle_who = {
clear_undo()
release_hex_control(game.from1)
game.from1 = 0
- game.state = 'refuse_battle'
+ goto_refuse_battle()
}
}
@@ -2782,6 +2820,9 @@ exports.setup = function (seed, scenario, options) {
allied_hand: [ 0, 0 ],
units: new Array(units.length).fill(0),
+ moved: [],
+ fired: [],
+ recover: [],
axis_minefields: [],
allied_minefields: [],
@@ -2807,7 +2848,6 @@ exports.setup = function (seed, scenario, options) {
// current turn option and selected moves
turn_option: null,
- moved: [],
side_limit: {},
rommel: 0,
from1: 0,
@@ -2826,7 +2866,6 @@ exports.setup = function (seed, scenario, options) {
assault_battles: [],
pursuit: 0,
battle: 0,
- fired: [],
hits: null,
flash: null,
}