From 7e9697412c3c4b0593b4f35915072f4de84af816 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 9 Sep 2022 01:21:12 +0200 Subject: Fix lint issues. --- rules.js | 159 +++------------------------------------------------------------ 1 file changed, 6 insertions(+), 153 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index d12eae2..6556386 100644 --- a/rules.js +++ b/rules.js @@ -109,8 +109,6 @@ const INFANTRY = 1 const ANTITANK = 2 const ARTILLERY = 3 -const TRAIL = 1 -const TRACK = 2 const HIGHWAY = 4 const SUPPLY_RANGE = [ 1, 2, 3, 0, 3 ] @@ -484,10 +482,6 @@ function find_unit(name) { throw new Error("cannot find named block: " + name + unit_name) } -function is_allied_unit(u) { - return u >= first_allied_unit && u <= last_allied_unit -} - function is_axis_unit(u) { return u >= first_axis_unit && u <= last_axis_unit } @@ -656,18 +650,6 @@ function is_battle_hex(x) { return (presence_axis[x] !== 0) && (presence_allied[x] !== 0) } -function is_empty_hex(x) { - if (presence_invalid) - update_presence() - return (presence_axis[x] === 0) && (presence_allied[x] === 0) -} - -function is_friendly_hex(x) { - if (game.active === AXIS) - return is_axis_hex(x) - return is_allied_hex(x) -} - function is_enemy_hex(x) { if (game.active === ALLIED) return is_axis_hex(x) @@ -698,12 +680,6 @@ function has_enemy_unit(x) { return has_allied_unit(x) } -function has_disrupted_enemy_unit(x) { - if (game.active === ALLIED) - return has_disrupted_axis_unit(x) - return has_disrupted_allied_unit(x) -} - function has_undisrupted_enemy_unit(x) { if (game.active === ALLIED) return has_undisrupted_axis_unit(x) @@ -813,13 +789,6 @@ function fortress_bit(fortress) { return 0 } -function fortress_src(fortress) { - if (fortress === BARDIA) return SS_BARDIA - if (fortress === BENGHAZI) return SS_BENGHAZI - if (fortress === TOBRUK) return SS_TOBRUK - return SS_OASIS -} - function is_fortress_allied_controlled(fortress) { return (game.fortress & fortress_bit(fortress)) !== 0 } @@ -897,12 +866,6 @@ function for_each_hex_and_adjacent_hex(here, fn) { } } -function for_each_unit_on_map(fn) { - for (let u = 0; u < unit_count; ++u) - if (is_map_hex(unit_hex(u))) - fn(u) -} - function for_each_axis_unit(fn) { for (let u = first_axis_unit; u <= last_axis_unit; ++u) fn(u) @@ -914,33 +877,18 @@ function for_each_axis_unit_on_map(fn) { fn(u) } -function for_each_allied_unit(fn) { - for (let u = first_allied_unit; u <= last_allied_unit; ++u) - fn(u) -} - function for_each_allied_unit_on_map(fn) { for (let u = first_allied_unit; u <= last_allied_unit; ++u) if (is_map_hex(unit_hex(u))) fn(u) } -function for_each_friendly_unit(fn) { - for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) - fn(u) -} - function for_each_friendly_unit_on_map(fn) { for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) if (is_map_hex(unit_hex(u))) fn(u) } -function for_each_enemy_unit(fn) { - for (let u = first_enemy_unit; u <= last_enemy_unit; ++u) - fn(u) -} - function for_each_enemy_unit_on_map(fn) { for (let u = first_enemy_unit; u <= last_enemy_unit; ++u) if (is_map_hex(unit_hex(u))) @@ -1144,7 +1092,7 @@ function shuffle_cards() { // === SUPPLY NETWORK === -var supply_defender, supply_defender_sides, supply_friendly, supply_enemy, supply_net, supply_line, supply_fortress_enemy +var supply_defender, supply_defender_sides, supply_friendly, supply_enemy, supply_net, supply_line var supply_visited = new Array(hexcount).fill(0) var supply_src = new Array(hexcount).fill(0) @@ -1352,13 +1300,11 @@ function init_trace_supply(net, line, friendly) { supply_net = net supply_line = line if (friendly === AXIS) { - supply_fortress_enemy = is_fortress_allied_controlled supply_defender = game.axis_hexes supply_defender_sides = game.axis_sides supply_friendly = presence_axis supply_enemy = presence_allied } else { - supply_fortress_enemy = is_fortress_axis_controlled supply_defender = game.allied_hexes supply_defender_sides = game.allied_sides supply_friendly = presence_allied @@ -1545,12 +1491,6 @@ function src_supply_network(src) { if (src === TOBRUK) return tobruk_supply_network() } -function friendly_supply_base() { - if (is_axis_player()) - return EL_AGHEILA - return ALEXANDRIA -} - function friendly_supply_network() { if (is_axis_player()) return axis_supply_network() @@ -1603,25 +1543,6 @@ const path_from = [ new Array(hexcount), new Array(hexcount), new Array(hexcount const path_cost = [ new Array(hexcount), new Array(hexcount), new Array(hexcount), null, new Array(hexcount) ] const path_valid = new Array(hexcount) -function print_path(who, from, to, road) { - let p = [ hex_name[to] ] - while (to && to !== from) { - to = path_from[road][to] - p.unshift(hex_name[to]) - } - log(">" + p.join(" - ") + ".") -} - -function show_path(from, to, p, speed) { - let road = can_move_road(to, speed) - p.push(to) - while (to && to !== from) { - to = path_from[road][to] - p.push(to) - } - return p -} - // normal move: may not leave battle hex. may engage any enemy. may move freely. // normal withdrawal: may not leave battle hex. may engage disrupted enemy. must follow supply lines. // retreat move: must leave battle hex via friendly side. may ignore disrupted enemy. may move freely. @@ -1846,18 +1767,6 @@ function search_path_redeploy_bfs(cost, start, road) { } } -function can_move_road(to, speed) { - if (path_cost[4][to] <= speed + 4) - return 4 - if (path_cost[2][to] <= speed + 2) - return 2 - if (path_cost[1][to] <= speed + 1) - return 1 - if (path_cost[0][to] <= speed) - return 0 - return -1 -} - function can_move_to(to, speed) { if (path_cost[4][to] <= speed + 4) return true @@ -2585,7 +2494,6 @@ function list_fortress_supply_candidates(fortress) { } function auto_assign_fortress_supply(list, fortress, ss, ix) { - let total = 0 let dist = distance_to[fortress] while (list.length > 0 && game.capacity[ix] > 0) { let d0 = dist[unit_hex(list[0])] @@ -2599,7 +2507,6 @@ function auto_assign_fortress_supply(list, fortress, ss, ix) { if (dist[unit_hex(u)] === d0) set_unit_supply(u, ss) game.capacity[ix] -= n - total += n list = list.slice(n) } else { return true @@ -2616,11 +2523,9 @@ function assign_fortress_supply() { // Isolated friendly fortress with capacity! if (!base_net[fortress] && is_fortress_friendly_controlled(fortress) && game.capacity[ix] > 0) { - let dist = distance_to[fortress] let list = list_fortress_supply_candidates(fortress) - if (auto_assign_fortress_supply(list, fortress, ss, ix)) { + if (auto_assign_fortress_supply(list, fortress, ss, ix)) return true - } } return false @@ -2630,7 +2535,6 @@ const xxx_fortress_supply = { inactive: "supply check", prompt() { let ix = game.assign - let ss = FORTRESS_SRC_LIST[ix] let fortress = FORTRESS_HEX_LIST[ix] view.prompt = `Supply Check: Assign fortress supply to ${hex_name[fortress]} (${game.capacity[ix]} capacity left).` if (game.capacity[ix] > 0) { @@ -2648,7 +2552,6 @@ const xxx_fortress_supply = { unit(who) { let ix = game.assign let ss = FORTRESS_SRC_LIST[ix] - let fortress = FORTRESS_HEX_LIST[ix] push_undo() game.capacity[ix]-- game.summary[ix] ++ @@ -3458,10 +3361,8 @@ function goto_overrun(where) { function do_gen_move_to(from, to, speed) { if (can_move_to(to, speed)) { gen_action_hex(to) - // view.path[to] = show_path(from, to, [], speed) } else if (can_move_to(to, speed + 1)) { gen_action_forced_march(to) - // view.path[to] = show_path(from, to, [], speed + 1) } } @@ -3509,10 +3410,8 @@ function gen_withdraw() { if (to != from) { if (can_move_to(to, speed + rommel1) && set_has(game.withdraw, to)) { gen_action_hex(to) - // view.path[to] = show_path(from, to, [], speed + rommel1) } else if (can_move_to(to, speed + 1 + rommel1) && set_has(game.withdraw, to)) { gen_action_forced_march(to) - // view.path[to] = show_path(from, to, [], speed + 1 + rommel1) } } } @@ -3522,10 +3421,8 @@ function gen_withdraw() { if (game.to1) { if (can_move_to(game.to1, speed + rommel1)) { gen_action_hex(game.to1) - // view.path[game.to1] = show_path(from, game.to1, [], speed + rommel1) } else if (can_move_to(game.to1, speed + 1 + rommel1)) { gen_action_forced_march(game.to1) - // view.path[game.to1] = show_path(from, game.to1, [], speed + 1 + rommel1) } } } @@ -3689,7 +3586,6 @@ states.forced_march_via = { for (let x of game.hexside.via) { gen_action_hex(x) - // view.path[x] = show_path(from, x, [ game.hexside.to ], speed + rommel) } }, hex(via) { @@ -3726,7 +3622,6 @@ states.engage_via = { gen_action_forced_march(x) else gen_action_hex(x) - // view.path[x] = show_path(from, x, [ game.hexside.to ], speed + rommel) } }, forced_march(via) { @@ -3842,7 +3737,7 @@ states.forced_marches = { inactive: "forced marches", prompt() { view.prompt = `Forced Marches!` - for (let [who, to] of game.forced) + for (let [who] of game.forced) gen_action_unit(who) }, unit(who) { @@ -3879,7 +3774,7 @@ function end_forced_marches() { function goto_forced_marches_rout() { let friend_count = 0, friend_where = 0 - let enemy_count = 0, we = 0 + let enemy_count = 0, enemy_where = 0 for (let x of all_hexes) { if (is_friendly_rout_hex(x)) { friend_where = x @@ -3912,7 +3807,7 @@ states.forced_marches_rout = { } }, hex(where) { - goto_rout(where, is_enemy_rout_hex(x), goto_forced_marches_rout) + goto_rout(where, is_enemy_rout_hex(where), goto_forced_marches_rout) } } @@ -4766,20 +4661,6 @@ function apply_battle_fire(tc) { // clamp to available hit points game.hits[tc] = min(game.hits[tc], hp[tc]) - - if (false) { - // end when no more units to fire or all targets destroyed - let done = true - if (game.hits[0] < hp[0] || game.hits[1] < hp[1] || game.hits[2] < hp[2] || game.hits[3] < hp[3]) { - for_each_undisrupted_friendly_unit_in_hex(game.battle, u => { - if (!is_unit_fired(u) && !is_unit_retreating(u)) - done = false - }) - } - if (done) { - goto_hits() - } - } } function goto_hits() { @@ -4865,8 +4746,7 @@ function gen_battle_target() { // only artillery may target artillery if other units are alive if (hp[ARTILLERY] > 0) { - if (fc === ARTILLERY || - (hp[ARMOR] <= 0 && hp[INFANTRY] <= 0 && hp[ANTITANK] <= 0)) + if (fc === ARTILLERY || (hp[ARMOR] <= 0 && hp[INFANTRY] <= 0 && hp[ANTITANK] <= 0)) gen_action('artillery') } } @@ -5125,16 +5005,6 @@ function slowest_undisrupted_enemy_unit_speed(where) { return r } -function slowest_undisrupted_friendly_unit_speed(where) { - let r = 4 - for_each_undisrupted_friendly_unit_in_hex(where, u => { - let s = unit_speed[u] - if (s < r) - r = s - }) - return r -} - function slowest_undisrupted_friendly_unit(where) { let who = -1 let r = 4 @@ -5282,13 +5152,11 @@ states.pursuit_fire = { show_pursuit: true, prompt() { view.prompt = `Pursuit Fire.` - let done = true if (game.hits < count_hp_in_pursuit()) { let slowest = slowest_undisrupted_enemy_unit_speed(game.pursuit) for_each_undisrupted_friendly_unit_in_hex(game.pursuit, u => { if (unit_speed[u] >= slowest && !is_unit_fired(u)) { gen_action_unit(u) - done = false } }) } @@ -5309,13 +5177,11 @@ states.rout_fire = { show_pursuit: true, prompt() { view.prompt = `Pursuit Fire (Rout).` - let done = true if (game.hits < count_hp_in_rout()) { let slowest = slowest_enemy_unit_speed(game.pursuit) for_each_undisrupted_friendly_unit_in_hex(game.pursuit, u => { if (unit_speed[u] >= slowest && !is_unit_fired(u)) { gen_action_unit(u) - done = false } }) } @@ -6469,13 +6335,6 @@ function current_scenario() { return SCENARIOS[game.scenario] } -function bring_to_front(list, hex) { - if (list.includes(hex)) { - remove_from_array(list, hex) - list.unshift(hex) - } -} - function sort_deployment_for_axis(list) { list = list.slice() list.sort((a,b) => distance_to[EL_AGHEILA][b] - distance_to[EL_AGHEILA][a]) @@ -7154,12 +7013,6 @@ function set_toggle(set, item) { set_add(set, item) } -function remove_from_array(array, item) { - let i = array.indexOf(item) - if (i >= 0) - array.splice(i, 1) -} - function deep_copy(original) { if (Array.isArray(original)) { let n = original.length -- cgit v1.2.3