diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-08-21 18:03:49 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-08-21 18:05:35 +0200 |
commit | eb9f45cf055f9f9823eed3aeaefada74f6d07454 (patch) | |
tree | 490aba768d839b554451ac374d79ea4d836edf71 | |
parent | 7cf08432ae2084e7879a1fba0dc34834a6180c86 (diff) | |
download | washingtons-war-eb9f45cf055f9f9823eed3aeaefada74f6d07454.tar.gz |
eslint fixes
-rw-r--r-- | play.js | 3 | ||||
-rw-r--r-- | rules.js | 152 |
2 files changed, 31 insertions, 124 deletions
@@ -440,7 +440,6 @@ function get_army_xy_lerp(s1, s2) { let dx = x2 - x1 let dy = y2 - y1 let n = Math.hypot(dx, dy) - let a = Math.atan2(dy, dx) x = lerp(x1, x2, 1/2) y = lerp(y1, y2, 1/2) @@ -798,7 +797,7 @@ function sub_general(_match, p1) { return `<span class="tip" onclick="on_click_general_tip(${x})" onmouseenter="on_focus_general_tip(${x})" onmouseleave="on_blur_general_tip(${x})">${n}</span>` } -function sub_minus(match, p1) { +function sub_minus(_match, p1) { return "\u2212" + p1 } @@ -12,19 +12,6 @@ const COLONIES = data.colonies const GENERALS = data.generals const Canada = 0 -const NH = 1 -const NY = 2 -const MA = 3 -const CT = 4 -const RI = 5 -const PA = 6 -const NJ = 7 -const MD = 8 -const DE = 9 -const VA = 10 -const NC = 11 -const SC = 12 -const GA = 13 const P_BRITAIN = "Britain" const P_AMERICA = "America" @@ -542,14 +529,6 @@ function has_american_or_french_cu(space) { return count_american_cu(space) > 0 || count_french_cu(space) > 0 } -function has_american_cu(space) { - return count_american_cu(space) > 0 -} - -function has_french_cu(space) { - return count_french_cu(space) > 0 -} - function has_enemy_cu(where) { if (game.active === P_BRITAIN) return has_american_or_french_cu(where) @@ -704,13 +683,6 @@ function has_enemy_general(where) { return has_british_general(where) } -function has_friendly_general(where) { - if (game.active !== P_BRITAIN) - return has_american_or_french_general(where) - else - return has_british_general(where) -} - function count_friendly_generals(where) { let list if (game.active === P_BRITAIN) @@ -1751,10 +1723,10 @@ function place_french_reinforcements(who, where) { move_general(already_there, AMERICAN_REINFORCEMENTS) } if (who !== NOBODY) { - log(`Reinforced ${count} CU and G${who} at S${where}.`) + log(`Reinforced 5 French CU and G${who} at S${where}.`) move_general(who, where) } else { - log(`Reinforced ${count} CU at S${where}.`) + log(`Reinforced 5 French CU at S${where}.`) } move_french_cu(FRENCH_REINFORCEMENTS, where, count_french_cu(FRENCH_REINFORCEMENTS)) move_french_cu(AMERICAN_REINFORCEMENTS, where, count_french_cu(AMERICAN_REINFORCEMENTS)) @@ -2190,6 +2162,7 @@ states.ops_general_move = { resume_moving() } }, + stop() { push_undo() end_move(true) @@ -3012,7 +2985,7 @@ function resolve_battle() { } game.combat.british_losses = apply_british_combat_losses(b_lost_cu) - let american_losses = apply_american_and_french_combat_losses(a_lost_cu) + apply_american_and_french_combat_losses(a_lost_cu) // Special case: winning general with no CU on enemy PC is captured if (victor === P_BRITAIN) { @@ -3196,7 +3169,7 @@ function end_battle() { /* EVENTS */ -events.campaign = function (c, card) { +events.campaign = function (card) { game.state = "campaign" game.campaign = card.count if (game.active === P_BRITAIN) @@ -3207,16 +3180,16 @@ events.campaign = function (c, card) { game.state = "ops_general_who" } -events.the_war_ends = function (c, card) { - game.war_ends = c +events.the_war_ends = function (card) { + game.war_ends = CARDS.indexOf(card) end_strategy_card() } -events.remove_random_british_card = function (c, card) { +events.remove_random_british_card = function () { remove_random_card(game.b_hand) } -events.remove_random_american_card = function (c, card) { +events.remove_random_american_card = function () { remove_random_card(game.a_hand) } @@ -3252,7 +3225,7 @@ function lose_regular_advantage() { } } -events.baron_von_steuben_trains_the_continental_army = function (c, card) { +events.baron_von_steuben_trains_the_continental_army = function () { if (is_general_on_map(WASHINGTON)) game.state = "baron_von_steuben_trains_the_continental_army" else @@ -3275,20 +3248,20 @@ states.baron_von_steuben_trains_the_continental_army = { }, } -events.advance_french_alliance = function (c, card) { +events.advance_french_alliance = function (card) { // TODO: advance alliance manual? // game.state = "advance_french_alliance" advance_french_alliance(card.count) end_strategy_card() } -events.remove_french_navy = function (c, card) { +events.remove_french_navy = function () { // TODO: remove french navy manual? game.french_navy = game.year + 1 end_strategy_card() } -events.remove_british_pc_from = function (c, card) { +events.remove_british_pc_from = function (card) { game.count = card.count game.where = card.where game.state = "remove_british_pc_from" @@ -3318,7 +3291,7 @@ states.remove_british_pc_from = { }, } -events.remove_american_pc = function (c, card) { +events.remove_american_pc = function (card) { game.count = card.count game.state = "remove_american_pc" } @@ -3343,7 +3316,7 @@ states.remove_american_pc = { }, } -events.remove_american_pc_from = function (c, card) { +events.remove_american_pc_from = function (card) { game.count = card.count game.where = card.where game.state = "remove_american_pc_from" @@ -3373,7 +3346,7 @@ states.remove_american_pc_from = { }, } -events.remove_american_pc_from_non_port = function (c, card) { +events.remove_american_pc_from_non_port = function (card) { game.count = card.count game.where = card.where game.state = "remove_american_pc_from_non_port" @@ -3408,7 +3381,7 @@ states.remove_american_pc_from_non_port = { }, } -events.remove_american_pc_within_two_spaces_of_a_british_general = function (c, card) { +events.remove_american_pc_within_two_spaces_of_a_british_general = function (card) { game.count = card.count game.state = "remove_american_pc_within_two_spaces_of_a_british_general" } @@ -3453,7 +3426,7 @@ states.remove_american_pc_within_two_spaces_of_a_british_general = { }, } -events.place_american_pc = function (c, card) { +events.place_american_pc = function (card) { game.count = card.count game.state = "place_american_pc" } @@ -3478,7 +3451,7 @@ states.place_american_pc = { }, } -events.place_american_pc_in = function (c, card) { +events.place_american_pc_in = function (card) { game.where = card.where game.state = "place_american_pc_in" } @@ -3503,7 +3476,7 @@ states.place_american_pc_in = { }, } -events.lord_sandwich_coastal_raids = function (c, card) { +events.lord_sandwich_coastal_raids = function () { game.state = "lord_sandwich_coastal_raids" game.count = 2 delete game.where @@ -3542,7 +3515,7 @@ function gen_lord_sandwich_coastal_raids(first_removed) { } } -events.remove_american_cu = function (c, card) { +events.remove_american_cu = function () { game.state = "remove_american_cu" } @@ -3567,7 +3540,7 @@ states.remove_american_cu = { }, } -events.remove_british_cu = function (c, card) { +events.remove_british_cu = function (card) { game.state = "remove_british_cu" game.count = card.count } @@ -3591,7 +3564,7 @@ states.remove_british_cu = { }, } -events.pennsylvania_and_new_jersey_line_mutinies = function (c, card) { +events.pennsylvania_and_new_jersey_line_mutinies = function () { set_flag(F_MUTINIES) game.state = "pennsylvania_and_new_jersey_line_mutinies" game.count = 2 @@ -3627,7 +3600,7 @@ function gen_pennsylvania_and_new_jersey_line_mutinies(first_removed) { } } -events.john_glovers_marblehead_regiment = function (c, card) { +events.john_glovers_marblehead_regiment = function () { game.state = "john_glovers_marblehead_regiment_who" game.count = 3 // strategy rating for gen_activate_general } @@ -3643,7 +3616,7 @@ states.john_glovers_marblehead_regiment_who = { }, } -events.declaration_of_independence = function (c, card) { +events.declaration_of_independence = function () { game.save = game.active game.active = P_AMERICA game.state = "declaration_of_independence" @@ -3689,7 +3662,7 @@ function do_event(c) { log("Played C" + c + ".") play_card(c) if (card.event in events) - events[card.event](c, card) + events[card.event](card) else throw new Error("Event not implemented yet: " + card.event) } @@ -4451,9 +4424,9 @@ states.european_war = { prompt() { view.prompt = "European War: Remove 2 British CU from any spaces. " + game.count + " left." if (game.count > 0) - for (let space of all_spaces) - if (has_british_cu(space)) - gen_action_space(space) + for (let space of all_spaces) + if (has_british_cu(space)) + gen_action_space(space) view.actions.pass = 1 }, space(where) { @@ -4561,7 +4534,7 @@ exports.scenarios = [ "Standard" ] exports.roles = [ P_BRITAIN, P_AMERICA ] -exports.setup = function (seed, scenario, options) { +exports.setup = function (seed, _scenario, _options) { setup_game(seed) return game } @@ -4733,26 +4706,12 @@ function array_remove(array, index) { array.length = n - 1 } -function array_remove_item(array, item) { - let n = array.length - for (let i = 0; i < n; ++i) - if (array[i] === item) - return array_remove(array, i) -} - function array_insert(array, index, item) { for (let i = array.length; i > index; --i) array[i] = array[i - 1] array[index] = item } -function array_remove_pair(array, index) { - let n = array.length - for (let i = index + 2; i < n; ++i) - array[i - 2] = array[i] - array.length = n - 2 -} - function array_insert_pair(array, index, key, value) { for (let i = array.length; i > index; i -= 2) { array[i] = array[i-2] @@ -4817,46 +4776,12 @@ function set_delete(set, item) { } } -function set_toggle(set, item) { - let a = 0 - let b = set.length - 1 - while (a <= b) { - let m = (a + b) >> 1 - let x = set[m] - if (item < x) - b = m - 1 - else if (item > x) - a = m + 1 - else { - array_remove(set, m) - return - } - } - array_insert(set, a, item) -} - // Map as plain sorted array of key/value pairs function map_clear(map) { map.length = 0 } -function map_has(map, key) { - let a = 0 - let b = (map.length >> 1) - 1 - while (a <= b) { - let m = (a + b) >> 1 - let x = map[m<<1] - if (key < x) - b = m - 1 - else if (key > x) - a = m + 1 - else - return true - } - return false -} - function map_get(map, key, missing) { let a = 0 let b = (map.length >> 1) - 1 @@ -4890,20 +4815,3 @@ function map_set(map, key, value) { } array_insert_pair(map, a<<1, key, value) } - -function map_delete(map, key) { - let a = 0 - let b = (map.length >> 1) - 1 - while (a <= b) { - let m = (a + b) >> 1 - let x = map[m<<1] - if (key < x) - b = m - 1 - else if (key > x) - a = m + 1 - else { - array_remove_pair(map, m<<1) - return - } - } -} |