diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 100 |
1 files changed, 51 insertions, 49 deletions
@@ -5,12 +5,14 @@ // TODO: legal pass withdrawal moves (reduce supply net, withdraw from fortress attack) // TODO: fortress combat in pass turns (must withdraw) +// TODO: highlight selected/active battles + // TODO: group move from queue holding box to base // TODO: 1942 malta group (reinforce, reduce supply card draw) +// TODO: multi-select deployment // TODO: log summaries (deploy, rebuild, move, etc) // TODO: put initial deployment stack somewhere more accessible (spread out along the top?) -// TODO: multi-select deployment // RULES: may units redeploying out of battle hex cross enemy controlled hexsides? (yes / doesn't matter) @@ -146,7 +148,7 @@ const SS_OASIS = 5 const region_egypt = regions["Egypt"] const region_egypt_and_libya = regions["Libya"].concat(regions["Egypt"]) const region_libya_and_sidi_omar = regions["Libya"].concat(regions["Sidi Omar"]) -const region_libya_and_sidi_omar_and_sollum = regions["Libya"].concat(regions["Sidi Omar"]).concat(regions["Sollum"]) +const region_libya_and_sidi_omar_and_sollum_except_tobruk = regions["Libya"].concat(regions["Sidi Omar"]).concat(regions["Sollum"]).filter(r => r !== TOBRUK) const region_egypt_and_tobruk = regions["Egypt"].concat(regions["Tobruk"]) const region_libya_except_tobruk = regions["Libya"].filter(r => r !== TOBRUK) @@ -413,8 +415,8 @@ function set_unit_fired(u) { } function eliminate_unit(u) { - set_unit_hex(u, 0) - set_unit_lost_steps(u, 0) + invalidate_caches() + game.units[u] = 0 hide_unit(u) } @@ -912,11 +914,17 @@ function for_each_undisrupted_and_unmoved_friendly_unit_in_hex(x, fn) { fn(u) } -function hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(here) { - for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) - if (!is_unit_disrupted(u) && !is_unit_moved(u) && is_hex_or_adjacent_to(unit_hex(u), here)) - return true - return false +function count_hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(here) { + let n = 0 + for_each_hex_and_adjacent_hex(here, x => { + for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) { + if (!is_unit_disrupted(u) && !is_unit_moved(u) && unit_hex(u) === x) { + n++ + return + } + } + }) + return n } function for_each_enemy_unit_in_hex(x, fn) { @@ -2138,6 +2146,7 @@ function goto_initial_supply_check_recover() { } } + // remember enemy units that can recover on their next turn set_clear(game.recover) for_each_enemy_unit_on_map(u => { if (is_unit_disrupted(u)) @@ -2323,9 +2332,10 @@ states.regroup_move_command_point = { prompt() { view.prompt = `Regroup Move: Designate the command point hex.` gen_rommel_move() - for (let x = first_hex; x <= last_hex; ++x) { + for (let x of all_hexes) { if (!is_enemy_hex(x)) { - if (hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(x)) + let n = count_hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(x) + if (n >= 2) gen_action_hex(x) } } @@ -4055,7 +4065,7 @@ function format_allocate_hits() { if (typeof game.hits === 'number') hits = game.hits else - hits = game.hits[1] + game.hits[2] + game.hits[3] + hits = game.hits[0] + game.hits[1] + game.hits[2] + game.hits[3] if (hits === 0) return `Allocate zero hits` else if (hits === 1) @@ -4484,13 +4494,11 @@ function apply_reinforcements() { for_each_friendly_unit_in_hex(friendly_refit(), u => { set_unit_hex(u, base) - set_unit_supply(u, SS_BASE) refitted++ }) for_each_friendly_unit_in_month(game.month, u => { set_unit_hex(u, base) - set_unit_supply(u, SS_BASE) scheduled++ }) @@ -4498,7 +4506,6 @@ function apply_reinforcements() { for_each_friendly_unit_in_month(game.month + 1, u => { if (roll_die() <= 2) { set_unit_hex(u, base) - set_unit_supply(u, SS_BASE) early++ } }) @@ -4864,8 +4871,8 @@ states.axis_player_initiative = { // === VICTORY CHECK === -const EXIT_EAST_EDGE = [ 99, 123, 148 ] //, 172, 197 ] -const EXIT_EAST = 172 +const EXIT_EAST_EDGE = [ 99, 148, 197 ] +const EXIT_EAST = 47 function check_sudden_death_victory() { // Supplied units that move beyond the map "edge" exit the map. @@ -4935,20 +4942,21 @@ function end_game() { function goto_free_deployment() { game.state = 'free_deployment' + game.selected = [] if (!has_friendly_unit_in_month(current_scenario().start)) end_free_deployment() } -function is_valid_deployment_hex(base, x) { +function is_valid_deployment_hex(base, x, n) { // we've already seen this hex during a previous supplied hex check this go if (supply_temp_network[x] > 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 + return count_friendly_units_in_hex(x) + n <= 5 if (x === JALO_OASIS || x === JARABUB_OASIS || x === SIWA_OASIS) - return count_friendly_units_in_hex(x) < 1 + return count_friendly_units_in_hex(x) + n <= 1 return false } @@ -4958,17 +4966,19 @@ states.free_deployment = { let scenario = current_scenario() let deploy = hexdeploy + scenario.start let axis = (game.active === AXIS) - let done = true view.prompt = `Setup: ${game.active} Deployment.` - view.prompt = `Setup: Deploy units in a supplied location in the setup area.` + // view.prompt = `Setup: Deploy units in a supplied location in the setup area.` - if (game.selected < 0) { - for_each_friendly_unit_in_hex(deploy, u => { - gen_action_unit(u) - done = false - }) - } else { + let done = true + for_each_friendly_unit_in_hex(deploy, u => { + gen_action_unit(u) + done = false + }) + if (done) + gen_action_next() + + if (game.selected.length > 0) { trace_total = 0 let base = friendly_base() @@ -4979,30 +4989,27 @@ states.free_deployment = { let limit = 0 if (scenario.deployment_limit) limit = scenario.deployment_limit[x] | 0 - if (!limit || count_friendly_units_in_hex(x) < limit) { - if (is_valid_deployment_hex(base, x)) + if (!limit || count_friendly_units_in_hex(x) + game.selected.length <= limit) { + if (is_valid_deployment_hex(base, x, game.selected.length)) gen_action_hex(x) } } } - gen_action_unit(game.selected) - done = false console.log("DEPLOYMENT SUPPLY VISITS", trace_total) } - - if (done) - gen_action_next() }, unit(u) { - apply_select(u) + set_toggle(game.selected, u) }, hex(to) { - let who = pop_selected() + let list = game.selected + game.selected = [] push_undo() - log(`Deployed at #${to}.`) - set_unit_hex(who, to) - set_unit_supply(who, SS_BASE) + log(`Deployed ${list.length} at #${to}.`) + for (let who of list) { + set_unit_hex(who, to) + } }, next() { clear_undo() @@ -5013,8 +5020,10 @@ states.free_deployment = { function end_free_deployment() { set_enemy_player() if (has_friendly_unit_in_month(current_scenario().start)) { + game.selected = [] log_h2("Allied Deployment") } else { + game.selected = -1 goto_initial_supply_cards() } } @@ -5113,6 +5122,7 @@ function setup_reinforcements(m) { set_unit_hex(u, MALTA) else set_unit_hex(u, hexdeploy + m) + set_unit_supply(u, SS_BASE) } } } @@ -5163,7 +5173,6 @@ function sort_deployment_for_allied(list) { const SCENARIOS = { "1940": { - year: 1940, start: 1, end: 6, axis_deployment: sort_deployment_for_axis(region_libya_and_sidi_omar), @@ -5172,7 +5181,6 @@ const SCENARIOS = { allied_initial_supply: 3, }, "1941": { - year: 1941, start: 1, end: 10, axis_deployment: [], @@ -5181,16 +5189,14 @@ const SCENARIOS = { allied_initial_supply: 6, }, "Crusader": { - year: 1941, start: 8, end: 10, - axis_deployment: sort_deployment_for_axis(region_libya_and_sidi_omar_and_sollum), + axis_deployment: sort_deployment_for_axis(region_libya_and_sidi_omar_and_sollum_except_tobruk), allied_deployment: sort_deployment_for_allied(region_egypt_and_tobruk), axis_initial_supply: 10, allied_initial_supply: 12, }, "Battleaxe": { - year: 1941, start: 4, end: 10, axis_deployment: sort_deployment_for_axis(region_libya_except_tobruk), @@ -5199,7 +5205,6 @@ const SCENARIOS = { allied_initial_supply: 8, }, "1942": { - year: 1942, start: 11, end: 20, axis_deployment: [ EL_AGHEILA, MERSA_BREGA ], @@ -5212,7 +5217,6 @@ const SCENARIOS = { }, }, "Gazala": { - year: 1942, start: 14, end: 15, axis_deployment: sort_deployment_for_axis(regions["West Line"]), @@ -5224,7 +5228,6 @@ const SCENARIOS = { } }, "Pursuit to Alamein": { - year: 1942, start: 15, end: 20, axis_deployment: sort_deployment_for_axis(regions["Libya"]), @@ -5233,7 +5236,6 @@ const SCENARIOS = { allied_initial_supply: 8, }, "1941-42": { - year: 1941, start: 1, end: 20, axis_deployment: [], |