From eb9f45cf055f9f9823eed3aeaefada74f6d07454 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 21 Aug 2024 18:03:49 +0200 Subject: eslint fixes --- rules.js | 152 +++++++++++++-------------------------------------------------- 1 file changed, 30 insertions(+), 122 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 419060d..117a310 100644 --- a/rules.js +++ b/rules.js @@ -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 - } - } -} -- cgit v1.2.3