diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-06-10 01:25:36 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-08-21 00:28:20 +0200 |
commit | 5a458a5a578445d70356b23c998fe3b8cbe909ec (patch) | |
tree | 5d9293badfcbae3f1dbc7a4a15eab40b5702f038 /rules.js | |
parent | 5eb2975315a50c585eb048479c4fdc765a24a20c (diff) | |
download | washingtons-war-5a458a5a578445d70356b23c998fe3b8cbe909ec.tar.gz |
stuff
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 387 |
1 files changed, 202 insertions, 185 deletions
@@ -10,7 +10,7 @@ const data = require("./data.js") const CARDS = data.cards const SPACES = data.spaces -const COLONIES = data.colony_spaces +const COLONIES = data.colonies const GENERALS = data.generals const Canada = 0 @@ -76,7 +76,7 @@ const WILMINGTON_NC = data.space_index["Wilmington NC"] const CAPTURED_GENERALS = data.space_index["Captured Generals"] const CONTINENTAL_CONGRESS_DISPERSED = data.space_index["Continental Congress Dispersed"] -const BRITISH_REINFORCEMENTS = data.space_index["British Leader Reinforcements"] +const BRITISH_REINFORCEMENTS = data.space_index["British Reinforcement Box"] const AMERICAN_REINFORCEMENTS = data.space_index["American Leader Reinforcements"] const FRENCH_REINFORCEMENTS = data.space_index["French Reinforcements"] const NOWHERE = data.spaces.length @@ -339,16 +339,16 @@ function is_map_space(s) { } function is_port(where) { - return SPACES[where].port + return SPACES[where].port >= 0 } function is_non_blockaded_port(where) { let port = SPACES[where].port - return (port > 0 && port !== game.french_navy) + return (port >= 0 && port !== game.french_navy) } function is_fortified_port(where) { - return SPACES[where].type === "fortified-port" + return SPACES[where].type === "fortified_port" } function is_continental_congress_dispersed() { @@ -360,7 +360,7 @@ function is_winter_quarter_space(where) { if (set_has(SOUTH_OF_WINTER_ATTRITION_LINE, colony)) return true // south of winter attrition line let type = SPACES[where].type - if (type === "winter-quarters" || type === "fortified-port") + if (type === "winter_quarters" || type === "fortified_port") return true return false } @@ -421,9 +421,9 @@ function is_adjacent_to_british_pc(a) { for (let b of SPACES[a].adjacent) if (has_british_pc(b)) return true - if (SPACES[a].port) { + if (is_port(a)) { for (let b of all_spaces) { - if (SPACES[b].port) + if (is_port(b)) if (has_british_pc(b)) return true } @@ -971,7 +971,7 @@ function gen_remove_british_pc_from(list_of_colonies) { for (let colony of list_of_colonies) { for (let space of COLONIES[colony]) { if (has_british_pc(space) && has_no_british_cu(space)) { - gen_action("remove_pc", space) + gen_action_space(space) } } } @@ -980,7 +980,7 @@ function gen_remove_british_pc_from(list_of_colonies) { function gen_remove_american_pc() { for (let space of all_spaces) { if (has_american_pc(space) && has_no_american_unit(space)) { - gen_action("remove_pc", space) + gen_action_space(space) } } } @@ -989,7 +989,7 @@ function gen_remove_american_pc_from(list_of_colonies) { for (let colony of list_of_colonies) { for (let space of COLONIES[colony]) { if (has_american_pc(space) && has_no_american_unit(space)) { - gen_action("remove_pc", space) + gen_action_space(space) } } } @@ -998,9 +998,9 @@ function gen_remove_american_pc_from(list_of_colonies) { function gen_remove_american_pc_from_non_port(list_of_colonies) { for (let colony of list_of_colonies) { for (let space of COLONIES[colony]) { - if (!SPACES[space].port) { + if (!is_port(space)) { if (has_american_pc(space) && has_no_american_unit(space)) { - gen_action("remove_pc", space) + gen_action_space(space) } } } @@ -1023,13 +1023,13 @@ function gen_remove_american_pc_within_two_spaces_of_a_british_general() { } for (let space of candidates) if (has_american_pc(space) && has_no_american_unit(space)) - gen_action("remove_pc", space) + gen_action_space(space) } function gen_place_american_pc() { for (let space of all_spaces) { if (has_no_pc(space) && has_no_british_playing_piece(space)) { - gen_action("place_american_pc", space) + gen_action_space(space) } } } @@ -1038,7 +1038,7 @@ function gen_place_american_pc_in(list_of_colonies) { for (let colony of list_of_colonies) { for (let space of COLONIES[colony]) { if (has_no_pc(space) && has_no_british_playing_piece(space)) { - gen_action("place_american_pc", space) + gen_action_space(space) } } } @@ -1047,7 +1047,7 @@ function gen_place_american_pc_in(list_of_colonies) { /* SETUP PHASE */ function goto_committees_of_correspondence() { - log(".h2.american Committes of Correspondence") + log("=a Committes of Correspondence") logbr() game.active = P_AMERICA game.state = "committees_of_correspondence" @@ -1062,15 +1062,15 @@ states.committees_of_correspondence = { if (game.colonies.length > 0) gen_place_american_pc_in(game.colonies) else - gen_pass() + view.actions.next = 1 }, - place_american_pc(space) { + space(s) { push_undo() - let colony = SPACES[space].colony + let colony = SPACES[s].colony set_delete(game.colonies, colony) - place_american_pc(space) + place_american_pc(s) }, - pass() { + next() { clear_undo() delete game.colonies goto_for_the_king() @@ -1079,7 +1079,7 @@ states.committees_of_correspondence = { function goto_for_the_king() { logbr() - log(".h2.british For the King") + log("=b For the King") logbr() game.active = P_BRITAIN game.state = "for_the_king" @@ -1094,14 +1094,14 @@ states.for_the_king = { if (game.count > 0) gen_british_pc_ops() else - gen_pass() + view.actions.next = 1 }, - place_british_pc(space) { + space(s) { push_undo() - place_british_pc(space) + place_british_pc(s) --game.count }, - pass() { + next() { clear_undo() gen_british_pc_ops_end() goto_start_year() @@ -1139,7 +1139,7 @@ function automatic_victory() { function goto_start_year() { logbr() - log(".h1 Year " + game.year) + log("# Year " + game.year) logbr() // Prisoner exchange @@ -1211,7 +1211,7 @@ states.british_declare_first = { gen_pass() for (let c of CAMPAIGN_CARDS) { if (game.b_hand.includes(c)) { - gen_action("card_campaign", c) + gen_action_card("card_campaign", c) } } }, @@ -1254,9 +1254,9 @@ function goto_strategy_phase(new_active) { game.state = "strategy_phase" logbr() if (game.active === P_AMERICA) - log(".h2.american American Turn") + log("=a America") else - log(".h2.british British Turn") + log("=b Britain") logbr() } @@ -1374,38 +1374,38 @@ function gen_strategy_plays(hand) { let card = CARDS[c] switch (card.type) { case "mandatory-event": - gen_action("card_play_event", c) + gen_action_card("card_play_event", c) break case "campaign": - gen_action("card_campaign", c) + gen_action_card("card_campaign", c) break case "ops": if (can_exchange_for_discard(c)) - gen_action("exchange_for_discard", c) + gen_action_card("exchange_for_discard", c) if (can_activate_general(c)) - gen_action("card_ops_general", c) - gen_action("card_ops_pc", c) + gen_action_card("card_ops_general", c) + gen_action_card("card_ops_pc", c) if (can_play_reinforcements()) - gen_action("card_ops_reinforcements", c) + gen_action_card("card_ops_reinforcements", c) if (card.count < 3) - gen_action("card_ops_queue", c) + gen_action_card("card_ops_queue", c) break case "british-event": case "british-event-or-battle": if (game.active === P_BRITAIN) if (can_play_event(c)) - gen_action("card_play_event", c) - gen_action("card_discard_event", c) + gen_action_card("card_play_event", c) + gen_action_card("card_discard_event", c) break case "american-event": if (game.active === P_AMERICA) if (can_play_event(c)) - gen_action("card_play_event", c) - gen_action("card_discard_event", c) + gen_action_card("card_play_event", c) + gen_action_card("card_discard_event", c) break case "british-battle": case "american-battle": - gen_action("card_discard_event", c) + gen_action_card("card_discard_event", c) break } } @@ -1422,20 +1422,22 @@ states.discard_event_pc_action = { else gen_american_discard_event_pc_action() }, - place_british_pc(space) { - place_british_pc(space) - end_strategy_card() - }, - place_american_pc(space) { - place_american_pc(space) - end_strategy_card() - }, - remove_pc(space) { - remove_pc(space) - end_strategy_card() - }, - flip_pc(space) { - flip_pc(space) + space(s) { + if (game.active === P_BRITAIN) { + if (has_no_pc(s)) + place_british_pc(s) + else if (has_british_army(s)) + flip_pc(s) + else + remove_pc(s) + } else { + if (has_no_pc(s)) + place_american_pc(s) + else if (has_british_army(s)) + flip_pc(s) + else + remove_pc(s) + } end_strategy_card() }, pass() { @@ -1447,11 +1449,11 @@ function gen_british_discard_event_pc_action() { for (let space of all_spaces) { if (is_adjacent_to_british_pc(space)) { if (has_no_pc(space) && has_no_american_unit(space)) - gen_action("place_british_pc", space) + gen_action_space(space) else if (has_american_pc(space) && has_british_army(space)) - gen_action("flip_pc", space) + gen_action_space(space) else if (has_american_pc(space) && has_no_american_unit(space)) - gen_action("remove_pc", space) + gen_action_space(space) } } } @@ -1461,11 +1463,11 @@ function gen_american_discard_event_pc_action() { if (is_adjacent_to_american_pc(space)) { if (has_no_pc(space) && has_no_british_cu(space)) { if (allowed_to_place_american_pc()) - gen_action("place_american_pc", space) + gen_action_space(space) } else if (has_british_pc(space) && has_american_or_french_general(space)) { - gen_action("flip_pc", space) + gen_action_space(space) } else if (has_british_pc(space) && has_no_british_cu(space)) { - gen_action("remove_pc", space) + gen_action_space(space) } } } @@ -1491,19 +1493,19 @@ states.ops_pc = { gen_american_pc_ops() } }, - place_british_pc(space) { - push_undo() - place_british_pc(space) - --game.count - }, - place_american_pc(space) { - push_undo() - place_american_pc(space) - --game.count - }, - flip_pc(space) { + space(s) { push_undo() - flip_pc(space) + if (game.active === P_BRITAIN) { + if (has_american_pc(s)) + flip_pc(s) + else + place_british_pc(s) + } else { + if (has_british_pc(s)) + flip_pc(s) + else + place_american_pc(s) + } --game.count }, pass() { @@ -1525,13 +1527,13 @@ function gen_british_pc_ops_start() { function gen_british_pc_ops() { for (let space of game.british_pc_space_list) - gen_action("place_british_pc", space) + gen_action_space(space) for (let space of all_spaces) { if (has_british_army(space)) { if (has_no_pc(space)) - gen_action("place_british_pc", space) + gen_action_space(space) else if (has_american_pc(space)) - gen_action("flip_pc", space) + gen_action_space(space) } } } @@ -1544,9 +1546,9 @@ function gen_american_pc_ops() { for (let space of all_spaces) { if (has_no_pc(space) && has_no_british_cu(space)) { if (allowed_to_place_american_pc()) - gen_action("place_american_pc", space) + gen_action_space(space) } else if (has_british_pc(space) && has_american_or_french_general(space)) { - gen_action("flip_pc", space) + gen_action_space(space) } } } @@ -1574,6 +1576,7 @@ states.ops_british_reinforcements_who = { prompt() { view.prompt = "Reinforcements: choose an available general or pass to bring only CU." view.prompt += " Carrying " + game.count + " British CU." + view.move = { to: BRITISH_REINFORCEMENTS, who: NOBODY, carry_british: game.count } gen_pass() gen_british_reinforcements_who() }, @@ -1583,7 +1586,7 @@ states.ops_british_reinforcements_who = { pickup_british_cu() { ++game.count }, - select_general(g) { + general(g) { push_undo() game.state = "ops_british_reinforcements_where" game.who = g @@ -1599,6 +1602,7 @@ states.ops_british_reinforcements_where = { prompt() { view.prompt = "Reinforcements: choose a port space." view.prompt += " Carrying " + game.count + " British CU." + view.move = { to: BRITISH_REINFORCEMENTS, who: game.who, carry_british: game.count } gen_british_reinforcements_where() }, drop_british_cu() { @@ -1607,7 +1611,7 @@ states.ops_british_reinforcements_where = { pickup_british_cu() { ++game.count }, - place_reinforcements(space) { + space(space) { place_british_reinforcements(game.who, game.count, space) end_strategy_card() delete game.who @@ -1617,10 +1621,11 @@ states.ops_british_reinforcements_where = { states.ops_american_reinforcements_who = { prompt() { view.prompt = "Reinforcements: choose an available general or pass to bring only CU." + view.move = { to: AMERICAN_REINFORCEMENTS, who: NOBODY, carry_american: game.count } gen_pass() gen_american_reinforcements_who() }, - select_general(g) { + general(g) { push_undo() game.state = "ops_american_reinforcements_where" game.who = g @@ -1635,9 +1640,10 @@ states.ops_american_reinforcements_who = { states.ops_american_reinforcements_where = { prompt() { view.prompt = "Reinforcements: choose a space." + view.move = { to: AMERICAN_REINFORCEMENTS, who: game.who, carry_american: game.count } gen_american_reinforcements_where(game.who) }, - place_reinforcements(space) { + space(space) { if (game.who === ROCHAMBEAU) place_french_reinforcements(game.who, space) else @@ -1650,7 +1656,7 @@ states.ops_american_reinforcements_where = { function gen_british_reinforcements_who() { for (let g of BRITISH_GENERALS) { if (is_general_at_location(g, BRITISH_REINFORCEMENTS)) { - gen_action("select_general", g) + gen_action_general(g) } } if (game.count > 0) @@ -1663,7 +1669,7 @@ function gen_british_reinforcements_where() { for (let space of all_spaces) { if (is_non_blockaded_port(space)) if (!has_american_or_french_cu(space) && !has_american_pc(space)) - gen_action("place_reinforcements", space) + gen_action_space(space) } if (game.count > 0) gen_action("drop_british_cu") @@ -1674,7 +1680,7 @@ function gen_british_reinforcements_where() { function gen_american_reinforcements_who() { for (let g of AMERICAN_GENERALS) { if (is_general_at_location(g, AMERICAN_REINFORCEMENTS)) { - gen_action("select_general", g) + gen_action_general(g) } } } @@ -1683,10 +1689,10 @@ function gen_american_reinforcements_where(general) { for (let space of all_spaces) { if (!has_british_cu(space) && !has_british_pc(space)) { if (general === ROCHAMBEAU) { - if (SPACES[space].port) - gen_action("place_reinforcements", space) + if (is_port(space)) + gen_action_space(space) } else { - gen_action("place_reinforcements", space) + gen_action_space(space) } } } @@ -1729,7 +1735,7 @@ states.ops_general_who = { flip_pc(where) end_strategy_card() }, - select_general(g) { + general(g) { push_undo() goto_ops_general_move(g, false) }, @@ -1761,13 +1767,13 @@ function gen_activate_general() { function gen_activate_british_general() { for (let g of BRITISH_GENERALS) if (is_general_on_map(g) && GENERALS[g].strategy <= game.count && !has_general_moved(g)) - gen_action("select_general", g) + gen_action_general(g) } function gen_activate_american_general() { for (let g of AMERICAN_GENERALS) if (is_general_on_map(g) && GENERALS[g].strategy <= game.count && !has_general_moved(g)) - gen_action("select_general", g) + gen_action_general(g) } function goto_remove_general(where) { @@ -1778,9 +1784,9 @@ function goto_remove_general(where) { states.remove_general = { prompt() { view.prompt = "Remove a general to the reinforcements box." - gen_remove_general() + gen_remove_general(game.where) }, - select_general(g) { + general(g) { if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else @@ -1796,9 +1802,9 @@ function goto_remove_general_after_intercept() { states.remove_general_after_intercept = { prompt() { view.prompt = "Remove a general to the reinforcements box." - gen_remove_general() + gen_remove_general(game.move.to) }, - select_general(g) { + general(g) { if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else @@ -1815,9 +1821,9 @@ function goto_remove_general_after_retreat(where) { states.remove_general_after_retreat = { prompt() { view.prompt = "Remove a general to the reinforcements box." - gen_remove_general() + gen_remove_general(game.where) }, - select_general(g) { + general(g) { if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else @@ -1826,24 +1832,24 @@ states.remove_general_after_retreat = { }, } -function gen_remove_general() { +function gen_remove_general(where) { if (game.active === P_BRITAIN) - return gen_remove_british_general() + return gen_remove_british_general(where) else - return gen_remove_american_general() + return gen_remove_american_general(where) } -function gen_remove_british_general() { +function gen_remove_british_general(where) { for (let g of BRITISH_GENERALS) - if (is_general_at_location(g, game.where)) - gen_action("select_general", g) + if (is_general_at_location(g, where)) + gen_action_general(g) } -function gen_remove_american_general() { +function gen_remove_american_general(where) { for (let g of AMERICAN_GENERALS) if (g !== WASHINGTON) - if (is_general_at_location(g, game.where)) - gen_action("select_general", g) + if (is_general_at_location(g, where)) + gen_action_general(g) } function goto_ops_general_move(g, marblehead) { @@ -1942,7 +1948,7 @@ states.ops_general_move = { mark_moved_french_cu(location_of_general(game.move.who), 1) }, - move(to) { + space(to) { push_undo() set_general_moved(game.move.who) @@ -2011,7 +2017,7 @@ function gen_intercept() { if (has_american_army(space)) { let g = find_american_or_french_general(space) if (g && !has_general_moved(g)) - gen_action("select_general", g) + gen_action_general(g) } } } @@ -2028,7 +2034,7 @@ states.intercept = { gen_pass() gen_intercept() }, - select_general(g) { + general(g) { set_general_moved(g) let die = roll_d6() if (die <= GENERALS[g].agility) { @@ -2145,10 +2151,10 @@ function gen_move_general() { if (game.move.mobility && has_enemy_cu(to)) { if (game.move.count - mp >= 1) - gen_action("move", to) + gen_action_space(to) } else { if (game.move.count - mp >= 0) - gen_action("move", to) + gen_action_space(to) } } if (game.active === P_BRITAIN && game.count === 4) { @@ -2161,7 +2167,7 @@ function gen_move_general() { if (alone && has_enemy_general(to)) continue // TODO: duplicate action if can move by normal road - gen_action("move", to) + gen_action_space(to) } } } @@ -2271,7 +2277,7 @@ states.remove_british_pc_from = { gen_pass() gen_remove_british_pc_from(game.where) }, - remove_pc(where) { + space(where) { remove_pc(where) if (--game.count === 0) { delete game.where @@ -2296,7 +2302,7 @@ states.remove_american_pc = { gen_pass() gen_remove_american_pc() }, - remove_pc(where) { + space(where) { remove_pc(where) if (--game.count === 0) { end_strategy_card() @@ -2320,7 +2326,7 @@ states.remove_american_pc_from = { gen_pass() gen_remove_american_pc_from(game.where) }, - remove_pc(where) { + space(where) { remove_pc(where) if (--game.count === 0) { delete game.where @@ -2347,7 +2353,7 @@ states.remove_american_pc_from_non_port = { gen_pass() gen_remove_american_pc_from_non_port(game.where) }, - remove_pc(where) { + space(where) { remove_pc(where) if (--game.count === 0) { delete game.where @@ -2372,7 +2378,7 @@ states.remove_american_pc_within_two_spaces_of_a_british_general = { gen_pass() gen_remove_american_pc_within_two_spaces_of_a_british_general() }, - remove_pc(where) { + space(where) { remove_pc(where) if (--game.count === 0) { delete game.where @@ -2447,16 +2453,17 @@ states.lord_sandwich_coastal_raids = { gen_pass() gen_lord_sandwich_coastal_raids(game.where) }, - place_british_pc(where) { - place_british_pc(where) + space(where) { + if (has_american_pc(space)) { + game.where = where + remove_pc(where) + if (--game.count === 0) + end_strategy_card() + } else { + place_british_pc(where) + } end_strategy_card() }, - remove_pc(where) { - game.where = where - remove_pc(where) - if (--game.count === 0) - end_strategy_card() - }, pass() { end_strategy_card() }, @@ -2464,11 +2471,11 @@ states.lord_sandwich_coastal_raids = { function gen_lord_sandwich_coastal_raids(first_removed) { for (let space of all_spaces) { - if (SPACES[space].port) + if (is_port(space)) if (has_american_pc(space) && has_no_american_unit(space)) - gen_action("remove_pc", space) + gen_action_space(space) if (space === first_removed) - gen_action("place_british_pc", space) + gen_action_space(space) } } @@ -2578,7 +2585,7 @@ states.john_glovers_marblehead_regiment_who = { view.prompt = "Activate an American general." gen_activate_general() }, - select_general(g) { + general(g) { goto_ops_general_move(g, true) }, } @@ -2638,7 +2645,7 @@ states.george_washington_captured = { gen_pass() gen_remove_american_pc() }, - remove_pc(where) { + space(where) { remove_pc(where) if (--game.count === 0) { end_george_washington_captured() @@ -2706,7 +2713,7 @@ states.retreat_before_battle = { gen_pass() gen_defender_retreat() }, - move(to) { + space(to) { let who = find_american_or_french_general(game.move.to) let agility = GENERALS[who].agility if (GENERALS[who].bonus) @@ -2739,9 +2746,9 @@ function goto_remove_general_after_retreat_before_battle(where) { states.remove_general_after_retreat_before_battle = { prompt() { view.prompt = "Remove a general to the reinforcements box." - gen_remove_general() + gen_remove_general(game.where) }, - select_general(g) { + general(g) { if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else @@ -2786,7 +2793,7 @@ function gen_defender_retreat() { let from = game.move.to for (let to of SPACES[from].adjacent) { if (can_defender_retreat(to)) - gen_action("move", to) + gen_action_space(to) } if (game.active === P_BRITAIN) { let can_sea_retreat = false @@ -2802,7 +2809,7 @@ function gen_defender_retreat() { for (let to of all_spaces) { if (to !== from && is_non_blockaded_port(to)) { if (!has_american_pc(to) && !has_american_or_french_cu(to)) { - gen_action("move", to) + gen_action_space(to) } } } @@ -2812,7 +2819,7 @@ function gen_defender_retreat() { function gen_attacker_retreat() { if (can_attacker_retreat()) - gen_action("move", game.move.from) + gen_action_space(game.move.from) } function end_retreat_before_battle() { @@ -2906,12 +2913,12 @@ function gen_battle_card() { switch (card.type) { case "british-battle": case "british-event-or-battle": - gen_action("card_battle_play", c) + gen_action_card("card_battle_play", c) break case "british-event": case "american-event": case "american-battle": - gen_action("card_battle_discard", c) + gen_action_card("card_battle_discard", c) break } } else { @@ -2920,10 +2927,10 @@ function gen_battle_card() { case "british-event-or-battle": case "british-event": case "american-event": - gen_action("card_battle_discard", c) + gen_action_card("card_battle_discard", c) break case "american-battle": - gen_action("card_battle_play", c) + gen_action_card("card_battle_play", c) break } } @@ -2952,7 +2959,7 @@ function roll_loser_combat_losses(log) { } function roll_winner_combat_losses(log, losing_general) { - let agility = losing_general ? GENERALS[losing_general].agility : 0 + let agility = losing_general !== NOBODY ? GENERALS[losing_general].agility : 0 let roll = roll_d6() log.push("Enemy Agility Rating: " + agility) log.push("Winner Combat Loss Roll: " + roll) @@ -3011,12 +3018,14 @@ function resolve_battle() { let b_br = 0 let a_br = 0 - if (b_g) + if (b_g !== NOBODY) b_log.push("General: " + b_g) - if (a_g) + if (a_g !== NOBODY) a_log.push("General: " + a_g) - if (b_g) { +console.log("GENS", a_g, b_g) + + if (b_g !== NOBODY) { let roll = roll_d6() if (roll <= 3) b_br = Math.min(Math.floor(GENERALS[b_g].battle / 2), b_cu) @@ -3025,7 +3034,7 @@ function resolve_battle() { b_log.push("Actual Battle Rating Roll: " + roll) } - if (a_g) { + if (a_g !== NOBODY) { let roll = roll_d6() if (roll <= 3) a_br = Math.min(Math.floor(GENERALS[a_g].battle / 2), a_cu) @@ -3153,7 +3162,7 @@ states.retreat_after_battle = { else gen_defender_retreat() }, - move(to) { + space(to) { logp("retreated to " + to) if (game.active === P_BRITAIN) retreat_british_army(game.move.to, to) @@ -3283,13 +3292,7 @@ function goto_french_naval_phase() { } function gen_place_french_navy() { - gen_action("place_navy", "Sea1") - gen_action("place_navy", "Sea2") - gen_action("place_navy", "Sea3") - gen_action("place_navy", "Sea4") - gen_action("place_navy", "Sea5") - gen_action("place_navy", "Sea6") - gen_action("place_navy", "Sea7") + view.actions.sea = [ 0, 1, 2, 3, 4, 5, 6 ] } states.place_french_navy_trigger = { @@ -3297,7 +3300,7 @@ states.place_french_navy_trigger = { view.prompt = "Place the French Navy in a blockade zone." gen_place_french_navy() }, - place_navy(zone) { + sea(zone) { logp("placed French Navy.") game.french_navy = zone goto_place_rochambeau() @@ -3329,13 +3332,13 @@ states.place_rochambeau = { for (let space in SPACES) { if (is_port(space)) { if (!has_british_cu(space) && !has_british_pc(space)) { - gen_action("place_reinforcements", space) + gen_action_space(space) can_place = true } } } }, - place_reinforcements(space) { + space(space) { logp("placed Rochambeau .") move_general(ROCHAMBEAU, space) move_cu(FRENCH, FRENCH_REINFORCEMENTS, space, 5) @@ -3354,7 +3357,7 @@ states.place_french_navy = { view.prompt = "Place the French Navy in a blockade zone." gen_place_french_navy() }, - place_navy(zone) { + sea(zone) { logp("placed French Navy.") game.french_navy = zone goto_political_control_phase() @@ -3576,17 +3579,29 @@ states.game_over = { /* CLIENT/SERVER COMMS */ function gen_action(action, argument) { - if (argument === undefined) { - view.actions[action] = 1 - } else { - if (!(action in view.actions)) - view.actions[action] = [] - set_add(view.actions[action], argument) - } + if (!(action in view.actions)) + view.actions[action] = [] + set_add(view.actions[action], argument) +} + +function gen_action_sea(s) { + gen_action("sea", s) +} + +function gen_action_space(s) { + gen_action("space", s) +} + +function gen_action_general(g) { + gen_action("general", g) +} + +function gen_action_card(action, c) { + gen_action(action, c) } function gen_pass() { - gen_action("pass") + view.actions.pass = 1 } exports.scenarios = [ "Standard" ] @@ -3624,33 +3639,35 @@ exports.view = function (state, current) { view = { prompt: null, - log: state.log, - year: state.year, - flags: state.flags, - war_ends: state.war_ends, - reinforcements: state.reinforcements, - french_alliance: state.french_alliance, - congress: state.congress, - french_navy: state.french_navy, + log: game.log, + year: game.year, + flags: game.flags, + war_ends: game.war_ends, + reinforcements: game.reinforcements, + french_alliance: game.french_alliance, + congress: game.congress, + french_navy: game.french_navy, + + loca: game.loca, + cupc: game.cupc, - loca: state.loca, - cupc: state.cupc, + a_cards: game.a_hand.length, + b_cards: game.b_hand.length, + a_queue: game.a_queue, + b_queue: game.b_queue, + last_played: game.last_played, - a_cards: state.a_hand.length, - b_cards: state.b_hand.length, - a_queue: state.a_queue, - b_queue: state.b_queue, - last_played: state.last_played, + move: game.move } if (current === P_AMERICA) - view.hand = state.a_hand + view.hand = game.a_hand else if (current === P_BRITAIN) - view.hand = state.b_hand + view.hand = game.b_hand else view.hand = [] - if (current === state.active) { + if (current === game.active) { view.actions = {} states[game.state].prompt() if (game.undo && game.undo.length > 0) |