diff options
-rw-r--r-- | play.js | 39 | ||||
-rw-r--r-- | rules.js | 56 | ||||
-rw-r--r-- | tools/gendata.js | 4 |
3 files changed, 53 insertions, 46 deletions
@@ -24,6 +24,8 @@ const SS_BENGHAZI = 3 const SS_TOBRUK = 4 const SS_OASIS = 5 +const DEPLOY = 1 + const ARMOR = 0 const INFANTRY = 1 const ANTITANK = 2 @@ -159,7 +161,7 @@ function unit_lost_steps(u) { } function unit_steps(u) { - return unit_start_steps[u] - unit_lost_steps(u) + return unit_max_steps[u] - unit_lost_steps(u) } function is_unit_moved(u) { @@ -240,12 +242,16 @@ function is_hex_selected(hex) { return set_has(view.selected_hexes, hex) } -function focus_stack(stack) { +function is_setup_hex(hex) { + return hex === DEPLOY +} + +function focus_stack(stack, hex) { if (ui.focus !== stack) { - console.log("FOCUS STACK", stack) + console.log("FOCUS STACK", stack, hex) ui.focus = stack update_map() - return stack.length <= 1 + return stack.length <= 1 || hex === hexdeploy + view.month } return true } @@ -284,7 +290,7 @@ function on_click_unit(evt) { if (evt.button === 0) { hide_supply() evt.stopPropagation() - if (focus_stack(evt.target.stack)) + if (focus_stack(evt.target.stack, evt.target.hex)) send_action('unit', evt.target.unit) } } @@ -615,6 +621,12 @@ function update_map() { let hex = unit_hex(u) if (hex >= hexdeploy + view.month + 10) hex = 0 + if (hex === hexdeploy + view.month) { + if (player === "Axis" && !is_axis_unit(u)) + hex = 0 + if (player === "Allied" && !is_allied_unit(u)) + hex = 0 + } if (view.month <= 10 && hex === MALTA) hex = 0 if (hex) { @@ -622,6 +634,7 @@ function update_map() { ui.units_holder.appendChild(e) stack[hex].push(u) e.stack = stack[hex] + e.hex = hex } else { e.remove() } @@ -629,6 +642,7 @@ function update_map() { for (let i = 1; i <= 20; ++i) { ui.months[i].classList.toggle("show", (i >= view.start && i <= view.end) && (i < view.month + 10)) + //ui.months[i].classList.toggle("show", true) ui.months[i].classList.toggle("now", i === view.month) } @@ -657,6 +671,11 @@ function update_map() { let start_y = ui.hex_y[hex] let wrap = 6 + if (hex === hexdeploy + view.month) { + start_x = 1095 + start_y = 25 + 8 + } + if (stack[hex] === ui.focus) { let height = Math.min(wrap, stack[hex].length) * 56 if (start_y + height + 25 > 960) @@ -668,7 +687,15 @@ function update_map() { let e = ui.units[u] let x, y, z - if (stack[hex] === ui.focus) { + if (hex === hexdeploy + view.month) { + if (view.month == 8) + wrap = 14 + else + wrap = 12 + x = start_x - 25 + ((i % wrap) | 0) * 56 + y = start_y - 25 + ((i / wrap) | 0) * 56 + z = 101 + } else if (stack[hex] === ui.focus) { if (start_x > 2000) x = start_x - 25 - ((i / wrap) | 0) * 56 else @@ -1,23 +1,5 @@ "use strict" -// TODO: remember withdrawal supply lines for regroup pass moves -// TODO: withdrawal pass regroup moves where 2+ moves combine to reduce supply network - -// TODO: clean up withdraw calculations and search_withdraw (pass supply source directly, not sample unit) -// TODO: log summaries (deploy, rebuild, move, etc) -// TODO: put initial deployment stack somewhere more accessible (spread out along the top?) - -// UI: skip clicking destination if only one regroup move selected? - -// UI: flash message cleanup during battles -// UI: separate colors for secret and visible minefields -// UI: basic turn - skip move - direct to combat - -// TODO: undo push/clear - -// ERRATA: forbid single-group regroup moves or convert to group moves after the fact, -// to prevent forced march abuse. - const max = Math.max const min = Math.min const abs = Math.abs @@ -30,7 +12,7 @@ var after_rout_table = {} const { all_hexes, hex_exists, hex_road, side_road, side_limit, hex_name, regions, - unit_name, unit_appearance, unit_elite, unit_class, unit_speed, unit_start_steps, + unit_name, unit_appearance, unit_elite, unit_class, unit_speed, unit_max_steps, } = require("./data") function debug_hexes3(n, list) { @@ -147,6 +129,9 @@ const ALLIED_REFIT = 48 const AXIS_QUEUE = 127 const ALLIED_QUEUE = 49 +// Free deployment holding box +const DEPLOY = 1 + // Off board optional 1942 Malta reinforcements const MALTA = 4 @@ -424,11 +409,11 @@ function set_unit_lost_steps(u, n) { } function unit_steps(u) { - return unit_start_steps[u] - unit_lost_steps(u) + return unit_max_steps[u] - unit_lost_steps(u) } function set_unit_steps(u, n) { - set_unit_lost_steps(u, unit_start_steps[u] - n) + set_unit_lost_steps(u, unit_max_steps[u] - n) } function is_unit_moved(u) { @@ -593,10 +578,6 @@ function has_friendly_unit_in_raw_hex(x) { return false } -function has_friendly_unit_in_month(month) { - return has_friendly_unit_in_raw_hex(hexdeploy + month) -} - function for_each_friendly_unit_in_month(month, fn) { for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) if (unit_hex(u) === hexdeploy + month) @@ -6003,7 +5984,7 @@ function end_game() { function goto_free_deployment() { game.state = 'free_deployment' game.selected = [] - if (!has_friendly_unit_in_month(current_scenario().start)) + if (!has_friendly_unit_in_raw_hex(DEPLOY)) end_free_deployment() } @@ -6024,14 +6005,13 @@ states.free_deployment = { inactive: "free deployment", prompt() { let scenario = current_scenario() - let deploy = hexdeploy + scenario.start let axis = (game.active === AXIS) view.prompt = `Setup: ${game.active} Deployment.` // view.prompt = `Setup: Deploy units in a supplied location in the setup area.` let done = true - for_each_friendly_unit_in_hex(deploy, u => { + for_each_friendly_unit_in_hex(DEPLOY, u => { gen_action_unit(u) done = false }) @@ -6079,7 +6059,7 @@ states.free_deployment = { function end_free_deployment() { set_enemy_player() - if (has_friendly_unit_in_month(current_scenario().start)) { + if (has_friendly_unit_in_raw_hex(DEPLOY)) { game.selected = [] log_h2("Allied Deployment") } else { @@ -6197,7 +6177,7 @@ function setup_units(where, steps, list) { u = find_unit(u) set_unit_hex(u, where) if (steps < 0) - set_unit_steps(u, unit_start_steps[u] + steps) + set_unit_steps(u, unit_max_steps[u] + steps) else if (steps > 0) set_unit_steps(u, steps) set_unit_supply(u, SS_BASE) @@ -6308,7 +6288,7 @@ const SCENARIOS = { } const SETUP = { - "1940" (DEPLOY) { + "1940" () { setup_units(DEPLOY, 0, [ "Pav", "Bre", "Tre", "Bol", "Sav", "Sab", "Fas", "Ita" ]) setup_units(-3, 0, [ "Ari", "Pis"]) setup_units(-5, 0, [ "Lit", "Cen"]) @@ -6318,7 +6298,7 @@ const SETUP = { setup_units(-4, 0, [ "Matilda/A", "7/4", "4IN/7m", "/Tob" ]) }, - "1941" (DEPLOY) { + "1941" () { setup_units(EL_AGHEILA, 0, find_axis_units('S')) setup_reinforcements(3) setup_reinforcements(5) @@ -6333,7 +6313,7 @@ const SETUP = { setup_reinforcements(10) }, - "Crusader" (DEPLOY) { + "Crusader" () { setup_units(DEPLOY, 0, find_axis_units('S')) setup_units(DEPLOY, 0, find_axis_units(3)) setup_units(DEPLOY, 0, find_axis_units(5)) @@ -6349,7 +6329,7 @@ const SETUP = { setup_reinforcements(10) }, - "Battleaxe" (DEPLOY) { + "Battleaxe" () { setup_units(DEPLOY, 0, [ "21/5", "21/3", "15/33", "90/155", "15/115", "88mm/A" ]) setup_units(DEPLOY, -1, [ "21/104" ]) setup_units(DEPLOY, 0, [ "Ari", "Lit", "Pav", "Bre", "Tre", "Bol", "Ita" ]) @@ -6365,7 +6345,7 @@ const SETUP = { setup_reinforcements(10) }, - "1942" (DEPLOY) { + "1942" () { setup_units(DEPLOY, 0, [ "21/3", "15/33", @@ -6422,7 +6402,7 @@ const SETUP = { setup_reinforcements(20) }, - "Gazala" (DEPLOY) { + "Gazala" () { setup_units(DEPLOY, -1, [ "21/5", "15/8", @@ -6491,7 +6471,7 @@ const SETUP = { ]) }, - "Pursuit to Alamein" (DEPLOY) { + "Pursuit to Alamein" () { setup_units(DEPLOY, 0, [ "21/3", "15/33", @@ -6566,7 +6546,7 @@ const SETUP = { setup_reinforcements(20) }, - "1941-42" (DEPLOY) { + "1941-42" () { SETUP["1941"](-1) setup_reinforcements(11) diff --git a/tools/gendata.js b/tools/gendata.js index ba78d95..8de889d 100644 --- a/tools/gendata.js +++ b/tools/gendata.js @@ -658,14 +658,14 @@ data += "const regions = " + JSON.stringify(regions) + "\n" gen_array("unit_name", u => JSON.stringify(u.name)) gen_array("unit_appearance", u => JSON.stringify(u.appearance)) -gen_array("unit_start_steps", u => u.steps) +gen_array("unit_max_steps", u => u.steps) gen_array("unit_elite", u => u.elite) gen_array("unit_class", u => u.class) gen_array("unit_speed", u => u.speed) data += "if (typeof module !== 'undefined')\n\tmodule.exports = {\n" data += "\t\tall_hexes, hex_exists, hex_name, hex_road, side_road, side_limit, regions,\n" -data += "\t\tunit_name, unit_appearance, unit_start_steps, unit_elite, unit_class, unit_speed,\n" +data += "\t\tunit_name, unit_appearance, unit_max_steps, unit_elite, unit_class, unit_speed,\n" data += "\t}\n" fs.writeFileSync("data.js", data) |