diff options
-rw-r--r-- | play.js | 33 | ||||
-rw-r--r-- | rules.js | 738 |
2 files changed, 395 insertions, 376 deletions
@@ -555,14 +555,18 @@ function layout_tst_marker(e, v, top) { function layout_vp_marker() { let x, y - if (view.vp > 21) { view.vp = 21 } - if (view.vp < -21) { view.vp = -21 } + if (view.vp > 21) { + view.vp = 21 + } + if (view.vp < -21) { + view.vp = -21 + } if (view.vp === 0) { y = 2425 + 25 x = 843 + 28 } else if (view.vp === -21) { y = 2424 + 25 - x = 803 + 28 - 651 + x = 803 + 28 - 651 } else if (view.vp === 21) { y = 2424 + 25 x = 883 + 28 + 651 @@ -606,8 +610,7 @@ function layout_inf_markers(cn, one, two, three, v, ctl) { one.className = cn + " v" + 8 two.className = cn + " v" + 8 three.className = cn + " v" + (v - 16) - } - else if (v > 8) { + } else if (v > 8) { one.className = cn + " v" + 8 two.className = cn + " v" + (v - 8) three.className = "hide" @@ -687,8 +690,22 @@ function on_update() { for (let s = 0; s <= last_space; ++s) { const demInfl = view.demInfl[s] const comInfl = view.comInfl[s] - layout_inf_markers("marker demInfl", ui.dem_inf[s], ui.dem_inf2[s], ui.dem_inf3[s], demInfl, demInfl - comInfl >= spaces[s].stability) - layout_inf_markers("marker comInfl", ui.com_inf[s], ui.com_inf2[s], ui.com_inf3[s], comInfl, comInfl - demInfl >= spaces[s].stability) + layout_inf_markers( + "marker demInfl", + ui.dem_inf[s], + ui.dem_inf2[s], + ui.dem_inf3[s], + demInfl, + demInfl - comInfl >= spaces[s].stability + ) + layout_inf_markers( + "marker comInfl", + ui.com_inf[s], + ui.com_inf2[s], + ui.com_inf3[s], + comInfl, + comInfl - demInfl >= spaces[s].stability + ) } // UPDATE COUNTRY MARKERS @@ -734,7 +751,7 @@ function on_update() { ui.discard.replaceChildren() for (let c of view.strategy_discard) ui.discard.appendChild(ui.cards[c]) - if (view.discard) + if (view.discard) document.getElementById("discard_panel").classList.remove("hide") else document.getElementById("discard_panel").classList.add("hide") @@ -218,7 +218,7 @@ const support_loss_roll = [0, 0, 1, 1, 2, 2, 3, 4] const vp_roll = [0, 0, 1, 1, 2, 2, 3, 4] const countries = ['Poland', 'Hungary', 'East_Germany', 'Bulgaria', 'Czechoslovakia', 'Romania'] const elite_spaces = [11, 14, 26, 42, 50, 68] -const all_power_cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52 ] +const all_power_cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52 ] const numberless_cards = [1, 2, 3, 4, 5, 6, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52 ] const auto_resolve_events = [5, 8, 9, 13, 17, 25, 26, 30, 35, 50, 53, 54, 58, 59, 62, 63, 65, 70, 72, 74, 86, 99, 102, 108] const switch_events = [6, 20, 71] @@ -243,7 +243,7 @@ exports.scenarios = [ "Standard", "Democrat +1 SP", "Democrat +2 SP" - ] +] exports.roles = [ DEM, COM ] @@ -293,7 +293,7 @@ exports.setup = function (seed, scenario, options) { dem_hand_limit: 8, com_hand_limit: 8, democrat_hand: [], - communist_hand: [], + communist_hand: [], is_pwr_struggle: false, dem_pwr_hand_limit: 0, @@ -301,7 +301,7 @@ exports.setup = function (seed, scenario, options) { dem_pwr_hand: [], com_pwr_hand: [], times_held: [0, 0, 0, 0, 0, 0], - revolutions: [false, false, false, false, false, false], + revolutions: [false, false, false, false, false, false], } log_h1("1989 Dawn of Freedom") @@ -322,13 +322,13 @@ function start_game() { // Draw cards game.strategy_deck = draw_deck() - //Set starting influence + // Set starting influence spaces.forEach((space, index) => { - game.demInfl[index] = space.demInfl - game.comInfl[index] = space.comInfl - }) + game.demInfl[index] = space.demInfl + game.comInfl[index] = space.comInfl + }) - //Set starting placement ops + // Set starting placement ops game.temp = 0 @@ -385,7 +385,7 @@ exports.view = function(state, player) { strategy_deck: game.strategy_deck.length, strategy_removed: game.strategy_removed, discard: game.discard, - show_opp_hand: game.view_opp_hand, /* Is this still needed?*/ + show_opp_hand: game.view_opp_hand /* Is this still needed?*/, democrat_hand: game.democrat_hand.length, communist_hand: game.communist_hand.length, @@ -477,15 +477,15 @@ function gen_action(action, argument) { } } -function gen_action_space(space){ +function gen_action_space(space) { gen_action("space", space) } -function gen_action_card(card){ +function gen_action_card(card) { gen_action("card", card) } -function gen_action_power_card(card){ +function gen_action_power_card(card) { gen_action("power_card", card) } @@ -509,18 +509,18 @@ states.place_starting_infl = { prompt() { if (game.temp === (game.starting_infl.length - 1) && game.available_ops === 0 ) { view.prompt = 'Place starting SPs: done. Start Turn 1.' - gen_action("start") + gen_action("start") } else if (game.available_ops === 0) { view.prompt = 'Place starting SPs: done.' - gen_action("done") - return + gen_action("done") + return } else if ((game.starting_infl.length === 5 && game.temp > 2) || game.temp > 3) { view.prompt = `Place your last ${pluralize(game.available_ops,'starting SP')}.` } else { view.prompt = `Place ${pluralize(game.available_ops,'starting SP')}.` } - for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + for (let space_id of game.valid_spaces) { + gen_action_space(space_id) } }, space(space) { @@ -543,7 +543,7 @@ states.place_starting_infl = { } states.choose_card = { - inactive: 'choose a card.', + inactive: 'choose a card.', prompt() { if ((game.active===DEM && game.democrat_hand.length === 0) || game.active === COM && game.communist_hand.length === 0) { view.prompt = 'No cards remaining: you must pass.' @@ -564,7 +564,7 @@ states.choose_card = { card(card) { push_undo() - //Check if player is at risk of losing game due to held scoring card + // Check if player is at risk of losing game due to held scoring card if (!scoring_cards.includes(card)) { let scoring_cards_count = count_scoring_cards() @@ -583,7 +583,7 @@ states.choose_card = { } states.confirm_card = { - inactive: 'choose a card.', + inactive: 'choose a card.', prompt() { let scoring_cards_count = count_scoring_cards() view.prompt = `${pluralize(scoring_cards_count,'scoring card')} in hand with ${pluralize(8-game.round,'Action Round')} remaining. Scoring cards may not be held. Continue?` @@ -594,7 +594,7 @@ states.confirm_card = { } } -states.play_card ={ +states.play_card = { get inactive() { return `play ${clean_name(cards[game.played_card].name)}.` }, @@ -616,16 +616,16 @@ states.play_card ={ } } - //Check for events + // Check for events if (event_is_playable(game.played_card)) { - if ((game.active === DEM && cards[game.played_card].side === 'C' && game.dem_tst_position >= 7 && game.com_tst_position < 7 && !game.tst_7) || (game.active === COM && cards[game.played_card].side === 'D' && game.com_tst_position >= 7 && game.dem_tst_position < 7 && !game.tst_7)){ + if ((game.active === DEM && cards[game.played_card].side === 'C' && game.dem_tst_position >= 7 && game.com_tst_position < 7 && !game.tst_7) || (game.active === COM && cards[game.played_card].side === 'D' && game.com_tst_position >= 7 && game.dem_tst_position < 7 && !game.tst_7)){ gen_action('tst_7') } - if ((game.active === DEM && cards[game.played_card].side !== 'C' && game.dem_tst_position >= 8 && game.com_tst_position < 8 && !game.tst_8) || (game.active === COM && cards[game.played_card].side !== 'D' && game.com_tst_position >= 8 && game.dem_tst_position < 8 && !game.tst_8)){ + if ((game.active === DEM && cards[game.played_card].side !== 'C' && game.dem_tst_position >= 8 && game.com_tst_position < 8 && !game.tst_8) || (game.active === COM && cards[game.played_card].side !== 'D' && game.com_tst_position >= 8 && game.dem_tst_position < 8 && !game.tst_8)){ gen_action('tst_8') } - //Continue with normal logic + // Continue with normal logic get_events(game.played_card) } @@ -874,11 +874,11 @@ states.tiananmen_square_attempt_done = { states.tst_goddess = { inactive: 'choose whether to discard a card.', prompt() { - view.prompt = 'Tiananmen Square Track award: you may discard a non-Power Struggle Card and draw a replacement.' - for (let card of game.valid_cards) { - gen_action_card(card) - } - gen_action('pass') + view.prompt = 'Tiananmen Square Track award: you may discard a non-Power Struggle Card and draw a replacement.' + for (let card of game.valid_cards) { + gen_action_card(card) + } + gen_action('pass') }, card(card) { push_undo() @@ -925,7 +925,7 @@ states.support_check_prep = { } else if (game.available_ops > 0) { view.prompt = `Select a space. ${pluralize(game.available_ops, 'support check')} remaining.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } }, @@ -980,8 +980,8 @@ states.do_support_check = { if (check_vp()) { return } else { - game.state = 'support_check_prep' - return + game.state = 'support_check_prep' + return } } } @@ -1067,7 +1067,7 @@ states.draw_power_cards = { permanently_remove(C_NATIONAL_SALVATION_FRONT) } - //Draw Power Cards + // Draw Power Cards game.is_pwr_struggle = true draw_cards(game.power_struggle_deck, game.dem_pwr_hand, game.com_pwr_hand, game.dem_pwr_hand_limit, game.com_pwr_hand_limit) if (game.active === DEM) { @@ -1079,7 +1079,7 @@ states.draw_power_cards = { log(`Communist: ${game.com_pwr_hand.length} cards`) log(`Democrat: ${game.dem_pwr_hand.length} cards`) - //Check if The Crowd Turns Against Ceausescu occurs + // Check if The Crowd Turns Against Ceausescu occurs if (game.persistent_events.includes(C_THE_CROWD_TURNS_AGAINST_CEAUSESCU) && !game.persistent_events.includes(THE_CROWD_TURNS_AGAINST_CEAUSESCU_OCCURRED) && game.pwr_struggle_in === 'Romania') { if (game.active === COM) { game.return = COM @@ -1143,10 +1143,10 @@ states.the_crowd_turns_against_ceausescu_infl = { inactive: 'add SPs.', prompt () { if (game.vm_available_ops === 0) - { + { view.prompt = 'Place SPs: done.' - gen_action("done") - return + gen_action("done") + return } view.prompt = `Add SPs: ${game.vm_available_ops} remaining` @@ -1175,15 +1175,15 @@ states.raise_stakes_1 = { gen_action('pass') } else if (game.raised_stakes_discard === 3) { - view.prompt = 'Raise the stakes: done.' + view.prompt = 'Raise the stakes: done.' gen_action('done') } else { - view.prompt = `Discard ${3-game.raised_stakes_discard} cards to raise the stakes.` + view.prompt = `Discard ${3-game.raised_stakes_discard} cards to raise the stakes.` if (game.raised_stakes_discard === 0) { gen_action('pass') } for (let card of game.valid_cards) { - gen_action_power_card(card) + gen_action_power_card(card) } } }, @@ -1235,10 +1235,10 @@ states.raise_stakes_2 = { return } if (game.raised_stakes_discard === 3) { - view.prompt = 'Raise the stakes: done.' + view.prompt = 'Raise the stakes: done.' gen_action('done') } else { - view.prompt = `Discard ${3-game.raised_stakes_discard} cards to raise the stakes.` + view.prompt = `Discard ${3-game.raised_stakes_discard} cards to raise the stakes.` if (game.raised_stakes_discard === 0) { gen_action('pass') } @@ -1439,7 +1439,7 @@ states.power_struggle = { } } -states.support_loss ={ +states.support_loss = { inactive: 'do Support Loss.', prompt () { let ps_state = game.persistent_events.includes(111) ? "New Year's Eve Party" : "Power Struggle" @@ -1450,7 +1450,7 @@ states.support_loss ={ view.prompt = `${ps_state} - ${country_name(game.pwr_struggle_in)}. Support Loss: remove ${pluralize(game.available_ops,'SP')}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } else if (game.phase === 1 && game.available_ops === 0 ) { view.prompt = `${ps_state} - ${country_name(game.pwr_struggle_in)}. Support Loss: finished.` @@ -1562,7 +1562,7 @@ states.choose_power = { } } -states.the_tyrant_is_gone ={ +states.the_tyrant_is_gone = { inactive: 'resolve The Tyrant is Gone.', prompt() { view.prompt = 'Play The Tyrant is Gone for the event.' @@ -1578,7 +1578,7 @@ states.the_tyrant_is_gone ={ } } -states.finish_scoring ={ +states.finish_scoring = { inactive: 'finish scoring.', prompt() { view.prompt = 'End power struggle.' @@ -1629,7 +1629,7 @@ states.end_turn_4_5_4 = { else if (game.persistent_events.includes(C_NEW_YEARS_EVE_PARTY)) { log_h1(`New Year's Eve Party`) game.vm_event = 104 - //Check if the Communist receives VP from The Tyrant is Gone + // Check if the Communist receives VP from The Tyrant is Gone if (game.the_tyrant_is_gone && game.the_tyrant_is_gone > 0) { game.vp -= 2 log(`Communist receives 2 VP from C97`) @@ -1644,7 +1644,7 @@ states.end_turn_4_5_4 = { clear_undo() log_h2('Final Scoring') - //Check if the Communist receives VP from The Tyrant is Gone + // Check if the Communist receives VP from The Tyrant is Gone if (game.the_tyrant_is_gone && game.the_tyrant_is_gone > 0) { game.vp -= 2 log(`Communist receives 2 VP from C97`) @@ -1667,7 +1667,7 @@ states.final_scoring_held = { push_undo() const held_countries = game.revolutions.filter(value => value === false).length let vp_gain = 4*held_countries - log(`Communist holds power in ${pluralize(held_countries, 'country', 's')}: -${vp_gain} VP`) + log(`Communist holds power in ${pluralize(held_countries, 'country', 's')}: -${vp_gain} VP`) game.vp -= 4*held_countries game.temp = {'East_Germany': false, 'Poland': false, 'Czechoslovakia': false, 'Hungary': false, 'Romania': false, 'Bulgaria': false} game.state = 'final_scoring' @@ -1786,7 +1786,7 @@ states.general_strike = { }, } -states.honecker ={ +states.honecker = { inactive: 'resolve Honecker.', prompt() { view.prompt = 'Honecker: you may take an extra action round.' @@ -1924,7 +1924,7 @@ states.stasi_end_round = { } states.stasi_confirm_scoring_card = { - inactive: 'choose a card.', + inactive: 'choose a card.', prompt() { view.prompt = `${pluralize(count_scoring_cards(),'scoring card')} in hand with ${pluralize(7-game.round,'Action Round')} remaining. Scoring cards may not be held. Continue?` gen_action('continue') @@ -2017,13 +2017,13 @@ states.stasi_resolve_common_european_home = { } } -// ==================== SUPPORTING STATE FUNCTIONS ============================= +// ==================== SUPPORTING STATE FUNCTIONS ============================= function add_infl(space, ops) { push_undo() log_summary(`Added £ SP in %${space}`) - //If AHBR - check AHBR conditions + // If AHBR - check AHBR conditions if (game.persistent_events.includes(58)) { if (spaces[space].country !== 'East_Germany'){ game.austria_hungary_border_reopened_tracker = false @@ -2036,7 +2036,7 @@ function add_infl(space, ops) { log_summary(`(-1 op due to C${C_GENSCHER})`) } else if (check_opp_control(space)) { game[ops] -= 2 - //Check if Austria Hungary Border Reopened was used to place last SP in a controlled space in East Germany. If so, game.available_op will be negative + // Check if Austria Hungary Border Reopened was used to place last SP in a controlled space in East Germany. If so, game.available_op will be negative if (game[ops] < 0) { log_summary(`(Used +1 op from C${C_AUSTRIA_HUNGARY_BORDER_REOPENED})`) } @@ -2062,21 +2062,21 @@ function add_infl(space, ops) { // If only 1 IP remaining, may not place in opponent controlled spaces - // Check for Genscher & Austria Hungary Border Reopened + // Check for Genscher & Austria Hungary Border Reopened - if (game[ops] === 1) { - if (game.active === DEM) { - if (game.persistent_events.includes(63) || (game.persistent_events.includes(58) && game.austria_hungary_border_reopened_tracker)) { - game.valid_spaces = game.valid_spaces.filter(n => !(check_opp_control(n) && spaces[n].country !== 'East_Germany')) - } else { - game.valid_spaces = game.valid_spaces.filter(n => !check_opp_control(n)) - } + if (game[ops] === 1) { + if (game.active === DEM) { + if (game.persistent_events.includes(63) || (game.persistent_events.includes(58) && game.austria_hungary_border_reopened_tracker)) { + game.valid_spaces = game.valid_spaces.filter(n => !(check_opp_control(n) && spaces[n].country !== 'East_Germany')) } else { game.valid_spaces = game.valid_spaces.filter(n => !check_opp_control(n)) } + } else { + game.valid_spaces = game.valid_spaces.filter(n => !check_opp_control(n)) } + } - //Clear valid spaces if no IP remaining. + // Clear valid spaces if no IP remaining. if (game[ops] <= 0 ) { game.valid_spaces = [] } @@ -2148,7 +2148,7 @@ function do_sc(space) { roll += 2 logi('+2 TST award') } - else { + else { let card_ops = get_card_ops(this_card()) roll += card_ops logi(`+${card_ops} from card ops`) @@ -2189,7 +2189,7 @@ function do_sc(space) { // Continue with logic - check for adjacency - // Events which affect adjacency - The Wall + // Events which affect adjacency - The Wall const adj = count_adj(space) if (game.active === COM && game.persistent_events.includes(C_THE_WALL) && spaces[space].country === 'East_Germany') { @@ -2259,7 +2259,7 @@ function do_sc(space) { } else { log_msg_gap('Change influence: 0 SP') } - //Check VP awards + // Check VP awards if (game.active === COM && game.persistent_events.includes(C_HELSINKI_FINAL_ACT) && (spaces[space].socio === 5 || spaces[space].socio === 6) ) { log('+1 VP from C26') game.vp ++ @@ -2269,7 +2269,7 @@ function do_sc(space) { game.vp++ } - //Check if Tear Gas or The Wall used + // Check if Tear Gas or The Wall used let tear_gas_end = game.persistent_events.includes(C_TEAR_GAS) let the_wall_end = game.persistent_events.includes(C_THE_WALL) if (tear_gas_start && !tear_gas_end) { @@ -2289,21 +2289,21 @@ function do_sc(space) { } function valid_spaces_setup() { - for (let i =0 ; i < spaces.length ; i++) { + for (let i = 0; i < spaces.length; i++) { let space = spaces[i] - if (game.active === COM) { + if (game.active === COM) { let infl = game.demInfl[i] - if (infl === 0) { - game.valid_spaces.push(space.space_id) - } + if (infl === 0) { + game.valid_spaces.push(space.space_id) + } } else { let infl = game.comInfl[i] if (infl === 0) { game.valid_spaces.push(space.space_id) } - } + } } } @@ -2332,7 +2332,7 @@ function valid_spaces_sc() { } game.valid_spaces = Array.from(valid_spaces_set) - //Check for the Crown Turns Against Ceausescu + // Check for the Crown Turns Against Ceausescu if (game.is_pwr_struggle && game.pwr_struggle_in === 'Romania' && game.persistent_events.includes(C_THE_CROWD_TURNS_AGAINST_CEAUSESCU)) { game.valid_spaces = game.valid_spaces.filter(n => spaces[n].country === 'Romania') } @@ -2361,38 +2361,42 @@ function valid_spaces_support_loss() { function valid_spaces_infl() { // Check if function is called from the VM or not, take relevant ops variable - let ops = game.state.startsWith('vm') ? game.vm_available_ops : game.available_ops + let ops = game.state.startsWith("vm") ? game.vm_available_ops : game.available_ops let valid_spaces_set = new Set() for (let i = 0; i < game.demInfl.length; i++) { let space = spaces[i] - let player_influence = game.active === COM ? game.comInfl[i] : game.demInfl[i] + let player_influence = game.active === COM ? game.comInfl[i] : game.demInfl[i] // If the piece has the player's influence, add it and its adjacent spaces to the set - if (player_influence > 0) { - valid_spaces_set.add(space.space_id) + if (player_influence > 0) { + valid_spaces_set.add(space.space_id) let adjacent_spaces = get_adjusted_adjacency(space.space_id) - for (let adj_space_id of adjacent_spaces) { - if (adj_space_id >= 0) { - const adj_piece = spaces[adj_space_id] + for (let adj_space_id of adjacent_spaces) { + if (adj_space_id >= 0) { + const adj_piece = spaces[adj_space_id] // Check if the adjacent space is controlled by the opponent - const opponent_control = check_opp_control(adj_piece.space_id) - - //Check for Genscher. Can always place in East Germany even with 1 op - if (game.active === DEM && adj_piece.country === 'East_Germany' && game.persistent_events.includes(C_GENSCHER)){ + const opponent_control = check_opp_control(adj_piece.space_id) + + // Check for Genscher. Can always place in East Germany even with 1 op + if ( + game.active === DEM && + adj_piece.country === "East_Germany" && + game.persistent_events.includes(C_GENSCHER) + ) { valid_spaces_set.add(adj_piece.space_id) } // Otherwise, only add the adjacent space if the available_ops >= 2 or the space is not controlled by the opponent if (ops >= 2 || !opponent_control) { - valid_spaces_set.add(adj_piece.space_id) - } - } - } - } - } + valid_spaces_set.add(adj_piece.space_id) + } + } + } + } + } game.valid_spaces = Array.from(valid_spaces_set) return game.valid_spaces } @@ -2461,52 +2465,52 @@ function count_adj(space_id) { } function check_control(space_id) { - if ( (game.comInfl[space_id] - game.demInfl[space_id]) >= spaces[space_id].stability) { - return true - } else if ((game.demInfl[space_id] - game.comInfl[space_id]) >= spaces[space_id].stability) { + if ( (game.comInfl[space_id] - game.demInfl[space_id]) >= spaces[space_id].stability) { + return true + } else if ((game.demInfl[space_id] - game.comInfl[space_id]) >= spaces[space_id].stability) { return true - } else { - return false - } + } else { + return false + } } function check_opp_control(space_id) { - if (game.active === DEM && ((game.comInfl[space_id] - game.demInfl[space_id]) >= spaces[space_id].stability)) { + if (game.active === DEM && ((game.comInfl[space_id] - game.demInfl[space_id]) >= spaces[space_id].stability)) { return true - } else if (game.active === COM && ((game.demInfl[space_id] - game.comInfl[space_id]) >= spaces[space_id].stability)) { + } else if (game.active === COM && ((game.demInfl[space_id] - game.comInfl[space_id]) >= spaces[space_id].stability)) { return true - } else { - return false - } + } else { + return false + } } function check_dem_control(space_id) { if ((game.demInfl[space_id] - game.comInfl[space_id]) >= spaces[space_id].stability) { return true - } else { - return false - } + } else { + return false + } } function check_com_control(space_id) { if ((game.comInfl[space_id] - game.demInfl[space_id]) >= spaces[space_id].stability) { return true - } else { - return false - } + } else { + return false + } } function do_tst_attempt() { let roll = roll_d6() - log(`Roll: D${roll}`) + log(`Roll: D${roll}`) roll += game.available_ops logi(`+${game.available_ops} from card ops`) // TIANANMEN SQUARE MODIFIERS - if (game.active === DEM && game.dem_tst_attempted === 1 || game.active === COM && game.com_tst_attempted === 1) { - roll ++ + if (game.active === DEM && game.dem_tst_attempted === 1 || game.active === COM && game.com_tst_attempted === 1) { + roll ++ logi('+1 from previous TST attempts') } if (game.active === DEM && game.dem_tst_position >= 1 && game.com_tst_position === 0) { @@ -2517,10 +2521,10 @@ function do_tst_attempt() { roll ++ logi('+1 from TST award') } - if ((game.active === DEM && cards[game.played_card].side === 'D') || (game.active === COM && cards[game.played_card].side === 'C')) { - roll ++ - logi('+1 for playing own card') - } + if ((game.active === DEM && cards[game.played_card].side === 'D') || (game.active === COM && cards[game.played_card].side === 'C')) { + roll ++ + logi('+1 for playing own card') + } if (game.active === COM && game.persistent_events.includes(53)) { roll ++ logi('+1 from C53') @@ -2537,7 +2541,7 @@ function do_tst_attempt() { game.dem_tst_position++ game.dem_tst_attempted = 0 - //Check if they have reached box 7 or 8 first + // Check if they have reached box 7 or 8 first if (game.dem_tst_position === 7 && game.com_tst_position < 7) { game.tst_7 = false } @@ -2545,7 +2549,7 @@ function do_tst_attempt() { game.tst_8 = false } - //Check if they have caught up to box 7 or 8 + // Check if they have caught up to box 7 or 8 if (game.dem_tst_position >= 7 && game.com_tst_position >= 7) { delete game.tst_7 } @@ -2553,7 +2557,7 @@ function do_tst_attempt() { delete game.tst_8 } - //Check if TST events occur + // Check if TST events occur if (game.dem_tst_position === 3 && game.com_tst_position < 3) {game.vm_event = 203} else if (game.dem_tst_position === 4 && game.com_tst_position < 4) {game.vm_event = 204} game.state = 'tiananmen_square_attempt_success' @@ -2569,7 +2573,7 @@ function do_tst_attempt() { game.com_tst_position++ game.com_tst_attempted = 0 - //Check if they have reached box 7 or 8 first + // Check if they have reached box 7 or 8 first if (game.com_tst_position === 7 && game.dem_tst_position < 7) { game.tst_7 = false } @@ -2577,7 +2581,7 @@ function do_tst_attempt() { game.tst_8 = false } - //Check if they have caught up to box 7 or 8 + // Check if they have caught up to box 7 or 8 if (game.com_tst_position >= 7 && game.dem_tst_position >= 7) { delete game.tst_7 } @@ -2585,7 +2589,7 @@ function do_tst_attempt() { delete game.tst_8 } - //Check if TST events occur + // Check if TST events occur if (game.com_tst_position === 3 && game.dem_tst_position < 3) {game.vm_event = 203} else if (game.com_tst_position === 4 && game.dem_tst_position < 4) {game.vm_event = 204} game.state = 'tiananmen_square_attempt_success' @@ -2599,71 +2603,71 @@ function do_tst_attempt() { function check_presence(country) { - let dem_spaces = 0 - let com_spaces = 0 - let dem_battlegrounds = 0 - let com_battlegrounds = 0 + let dem_spaces = 0 + let com_spaces = 0 + let dem_battlegrounds = 0 + let com_battlegrounds = 0 let dem_leaders = {1: false, 4: false, 5: false, 6: false, 7: false} - let com_leaders = {1: false, 4: false, 5: false, 6: false, 7: false} + let com_leaders = {1: false, 4: false, 5: false, 6: false, 7: false} - for (let i = 0; i < spaces.length; i++) { + for (let i = 0; i < spaces.length; i++) { let space = spaces[i] - if (space.country === country) { + if (space.country === country) { - if (check_dem_control(i)) { - dem_spaces++ - if (space.battleground === 1) { - dem_battlegrounds++ - } + if (check_dem_control(i)) { + dem_spaces++ + if (space.battleground === 1) { + dem_battlegrounds++ + } if (leaders.includes(space.socio)) { - dem_leaders[space.socio] = true - } - } - if (check_com_control(i)) { - com_spaces++ - if (space.battleground === 1) { - com_battlegrounds++ - } + dem_leaders[space.socio] = true + } + } + if (check_com_control(i)) { + com_spaces++ + if (space.battleground === 1) { + com_battlegrounds++ + } if (leaders.includes(space.socio)) { - com_leaders[space.socio] = true - } - } - } - } - - // Determine domination - let dem_domination = dem_battlegrounds > com_battlegrounds && dem_spaces > com_spaces && dem_spaces - dem_battlegrounds > 0 - let com_domination = com_battlegrounds > dem_battlegrounds && com_spaces > dem_spaces && com_spaces - com_battlegrounds > 0 - - // Determine control - let total_battlegrounds = battlegrounds(country) - let dem_control = dem_battlegrounds === total_battlegrounds && dem_spaces > com_spaces - let com_control = com_battlegrounds === total_battlegrounds && com_spaces > dem_spaces - - return { - dem_spaces: dem_spaces, - com_spaces: com_spaces, - dem_battlegrounds: dem_battlegrounds, - com_battlegrounds: com_battlegrounds, - dem_domination: dem_domination, - com_domination: com_domination, + com_leaders[space.socio] = true + } + } + } + } + + // Determine domination + let dem_domination = dem_battlegrounds > com_battlegrounds && dem_spaces > com_spaces && dem_spaces - dem_battlegrounds > 0 + let com_domination = com_battlegrounds > dem_battlegrounds && com_spaces > dem_spaces && com_spaces - com_battlegrounds > 0 + + // Determine control + let total_battlegrounds = battlegrounds(country) + let dem_control = dem_battlegrounds === total_battlegrounds && dem_spaces > com_spaces + let com_control = com_battlegrounds === total_battlegrounds && com_spaces > dem_spaces + + return { + dem_spaces: dem_spaces, + com_spaces: com_spaces, + dem_battlegrounds: dem_battlegrounds, + com_battlegrounds: com_battlegrounds, + dem_domination: dem_domination, + com_domination: com_domination, dem_control: dem_control, - com_control: com_control, + com_control: com_control, dem_leaders: dem_leaders, com_leaders: com_leaders - } + } } function battlegrounds(country) { - let battlegrounds = 0 - if (country === "Hungary") { + let battlegrounds = 0 + if (country === "Hungary") { battlegrounds = 4 } else if (country === "Bulgaria") { battlegrounds = 5 } else { battlegrounds = 6 } - return battlegrounds + return battlegrounds } function take_power(country) { @@ -2683,7 +2687,7 @@ function retain_power(country){ function score_country(country) { log_h3(`Scoring: ${country}`) -//Get scoring values + // Get scoring values let value_presence = get_value(country) let value_domination = value_presence*2 let value_control @@ -2695,10 +2699,10 @@ function score_country(country) { let dem_vp = 0 let com_vp = 0 - //Check for presence + // Check for presence let presence = check_presence(country) - //If one side has domination or control + // If one side has domination or control if (presence.dem_control || presence.dem_domination) { log(`Democrat:`) if (presence.dem_control) { @@ -2754,7 +2758,7 @@ function score_country(country) { } } - //Otherwise, presence and battlegrounds + // Otherwise, presence and battlegrounds else { log("No domination or control") log_gap(`Communist:`) @@ -2762,7 +2766,7 @@ function score_country(country) { logi(`Presence: -${value_presence} VP`) com_vp -= value_presence if (presence.com_battlegrounds > 0) { - logi(`Battlegrounds: -${presence.com_battlegrounds} VP`) + logi(`Battlegrounds: -${presence.com_battlegrounds} VP`) com_vp -= presence.com_battlegrounds } else { logi('No battlegrounds') @@ -2787,7 +2791,7 @@ function score_country(country) { } } -//Calculate change VP + // Calculate change VP let change_vp = dem_vp + com_vp game.vp += change_vp if (change_vp > 0 ) { @@ -3163,24 +3167,24 @@ function get_events(card){ } function event_is_playable(card) { - //Reformer never playable here + // Reformer never playable here if (card === C_REFORMER_REHABILITATED) { return false } - //Check for Common European Home under Stasi + // Check for Common European Home under Stasi else if (game.stasi_card === C_COMMON_EUROPEAN_HOME && card === C_COMMON_EUROPEAN_HOME && game.active === DEM) { return false } - //Check for The Chinese Solution + // Check for The Chinese Solution else if (game.com_tst_position >= 7 && card === C_THE_CHINESE_SOLUTION) { return true } - //Check for Gorbachev Charms the West after Breakaway Baltic Republics + // Check for Gorbachev Charms the West after Breakaway Baltic Republics else if (card === C_GORBACHEV_CHARMS_THE_WEST && !game.playable_cards.includes(C_GORBACHEV_CHARMS_THE_WEST)) { return false } - //Then check normally + // Then check normally else if (game.playable_cards.includes(card)) { return true } else if (cards[card].playable) { @@ -3343,17 +3347,17 @@ function finish_we_are_the_people() { // =========== MOVING THROUGH TURNS ============ function end_round() { - //Check if the game is over! WHY IS THIS NEEDED? + // Check if the game is over! WHY IS THIS NEEDED? if (game.state === 'game_over') { return} - //Check if the card needs to be discarded. + // Check if the card needs to be discarded. let discard_check = [...game.strategy_removed, ...game.persistent_events] if (!discard_check.includes(game.played_card) && game.played_card > 0) { game.strategy_discard.push(game.played_card) } - //Reset + // Reset game.played_card = 0 delete game.temp delete game.vm_event @@ -3381,7 +3385,7 @@ function end_round() { } card_check = card_check.filter(card => card <= last_strategy_card) function check_duplicates(array) { - return new Set(array).size !== array.length + return new Set(array).size !== array.length } function find_duplicates(array) { @@ -3413,7 +3417,7 @@ function end_round() { throw new Error(`Wrong number of cards: ${card_check.length}`) } - //Check if the Reformer is playable + // Check if the Reformer is playable check_reformer() // Check if last round and if so resolve end turn events @@ -3425,25 +3429,25 @@ function end_round() { game.state = 'honecker' return } - else if (game.dem_tst_position >= 6 && game.com_tst_position <= 5) { - if (game.active !== DEM) { - next_player() - } - game.return = game.active - clear_undo() - game.return_state = 'end_turn_4_5_4' - goto_vm(206) - return - } else if (game.com_tst_position >= 6 && game.dem_tst_position <= 5) { - if (game.active !== COM) { - next_player() + else if (game.dem_tst_position >= 6 && game.com_tst_position <= 5) { + if (game.active !== DEM) { + next_player() + } + game.return = game.active + clear_undo() + game.return_state = 'end_turn_4_5_4' + goto_vm(206) + return + } else if (game.com_tst_position >= 6 && game.dem_tst_position <= 5) { + if (game.active !== COM) { + next_player() + } + game.return = game.active + clear_undo() + game.return_state = 'end_turn_4_5_4' + goto_vm(206) + return } - game.return = game.active - clear_undo() - game.return_state = 'end_turn_4_5_4' - goto_vm(206) - return - } else { clear_undo() game.state = 'end_turn_4_5_4' @@ -3452,15 +3456,15 @@ function end_round() { } // Resolve end action round - //Stasi check + // Stasi check if(game.round_player === COM && game.persistent_events.includes(C_STASI)) { - //If in Honecker, turn ends + // If in Honecker, turn ends if (game.round === 8) { clear_undo() game.state = 'end_turn_4_5_4' return } - //Otherwise go to Stasi + // Otherwise go to Stasi game.round_player = DEM if (game.active !== DEM) { next_player() @@ -3476,13 +3480,13 @@ function end_round() { } return } - //Check if in extra Action Round + // Check if in extra Action Round else if (game.round_player === COM && game.round === 8) { clear_undo() game.state = 'end_turn_4_5_4' return } - //Normal round end + // Normal round end else if (game.round_player===COM) { game.round_player = DEM if (game.active !== DEM) { @@ -3537,7 +3541,7 @@ function new_turn() { if (game.tst_8) {game.tst_8 = false} delete game.selected_space - //Remove events that only last one turn + // Remove events that only last one turn for (let e of one_turn_events) { if (game.persistent_events.includes(e)) { @@ -3577,19 +3581,19 @@ function new_turn() { game.com_hand_limit = 8 } - //Check if TST effects need to be resolved + // Check if TST effects need to be resolved if ((game.dem_tst_position >=5 && game.com_tst_position <= 4) || (game.com_tst_position >= 5 && game.dem_tst_position <= 4)) { log_h2('Tiananmen Square Track Award') if ((game.dem_tst_position >= 5 && game.com_tst_position <= 4 && game.active !== DEM) || (game.com_tst_position >= 5 && game.dem_tst_position <= 4 && game.active !== COM)) { - next_player() + next_player() } let hand = game.dem_tst_position >=5 ? game.democrat_hand : game.communist_hand - for (let card of hand) { - if (scoring_cards.includes(card)) continue - game.valid_cards.push(card) - } - game.state = 'tst_goddess' + for (let card of hand) { + if (scoring_cards.includes(card)) continue + game.valid_cards.push(card) + } + game.state = 'tst_goddess' } else { log_h2("Action Round " + game.round) log_side() @@ -3647,27 +3651,25 @@ function draw_deck() { } function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_hand_limit) { - //Start with the communist player - let turn = 'communist' - while (democrat_hand.length < dem_hand_limit || communist_hand.length < com_hand_limit) { + // Start with the communist player + let turn = "communist" + while (democrat_hand.length < dem_hand_limit || communist_hand.length < com_hand_limit) { if (deck.length === 0) { - log_h3('--- Reshuffle ---') + log_h3("--- Reshuffle ---") deck.push(...game.strategy_discard) game.strategy_discard = [] - } else if (turn === 'communist' && communist_hand.length < com_hand_limit) { + } else if (turn === "communist" && communist_hand.length < com_hand_limit) { communist_hand.push(draw_card(deck)) - turn = 'democrat' - } else if(turn === 'communist' && communist_hand.length === com_hand_limit) { - turn = 'democrat' - } - else if (turn === 'democrat' && democrat_hand.length < dem_hand_limit) { - democrat_hand.push(draw_card(deck)) - turn = 'communist' - } - else if (turn === 'democrat' && democrat_hand.length === dem_hand_limit) { - turn = 'communist' - } - } + turn = "democrat" + } else if (turn === "communist" && communist_hand.length === com_hand_limit) { + turn = "democrat" + } else if (turn === "democrat" && democrat_hand.length < dem_hand_limit) { + democrat_hand.push(draw_card(deck)) + turn = "communist" + } else if (turn === "democrat" && democrat_hand.length === dem_hand_limit) { + turn = "communist" + } + } clear_undo() } @@ -3677,7 +3679,7 @@ function draw_card(deck) { deck.push(...game.strategy_discard) game.strategy_discard = [] } - const randomIndex = Math.floor(random(deck.length)) + const randomIndex = Math.floor(random(deck.length)) return deck.splice(randomIndex, 1)[0] } @@ -3817,7 +3819,7 @@ function resolve_tyrant() { } } -function check_systematization() { /* Check for Systematization - may not use this space */ +function check_systematization() { /* Check for Systematization - may not use this space */ if (game.systematization > 0) { game.valid_spaces = game.valid_spaces.filter(n => n !== game.systematization) } @@ -3838,18 +3840,18 @@ const pluralize = (count, noun, suffix = 's') => { return `${count} ${noun}` } else { if (noun.endsWith('y') && !/[aeiou]y$/.test(noun)) { - noun = noun.slice(0, -1) + 'ie' + noun = noun.slice(0, -1) + 'ie' } - return `${count} ${noun}${suffix}` - } + return `${count} ${noun}${suffix}` + } } function clean_name(str) { if (str && str.slice(-1) === '*') { - return str.slice(0, -1) - } else { - return str - } + return str.slice(0, -1) + } else { + return str + } } function country_name(country) { @@ -4030,33 +4032,33 @@ function object_copy(original) { /* =================== VM FUNCTIONS ========================== */ function goto_vm(proc) { - let old_vm = game.vm + let old_vm = game.vm - game.state = "vm" - game.vm = { - prompt: 0, - fp: proc, - ip: 0, - } + game.state = "vm" + game.vm = { + prompt: 0, + fp: proc, + ip: 0, + } - if (old_vm) { - game.vm.return_vm = old_vm - } + if (old_vm) { + game.vm.return_vm = old_vm + } - vm_exec() + vm_exec() } function vm_exec() { - vm_inst(0)() + vm_inst(0)() } function vm_inst(a) { - return CODE[game.vm.fp][game.vm.ip][a] + return CODE[game.vm.fp][game.vm.ip][a] } function vm_next() { - game.vm.ip++ - vm_exec() + game.vm.ip++ + vm_exec() } function vm_logi(){ @@ -4104,15 +4106,15 @@ function vm_endif() { } function vm_goto_step(step) { - for (let i = game.vm.ip; i < CODE[game.vm.fp].length; i++) { - if (CODE[game.vm.fp][i][0] === step) { - game.vm.ip = i - vm_exec() - return - } - } + for (let i = game.vm.ip; i < CODE[game.vm.fp].length; i++) { + if (CODE[game.vm.fp][i][0] === step) { + game.vm.ip = i + vm_exec() + return + } + } - console.log("ERROR: Target operation not found in the current procedure.") + console.log("ERROR: Target operation not found in the current procedure.") } function vm_goto(op, nop, dir, step) { @@ -4149,7 +4151,7 @@ function vm_prompt() { } function vm_return() { - //Remove temporary vm variables + // Remove temporary vm variables delete game.support_check_modifier delete game.vm_max_infl delete game.vm_influence_added @@ -4159,11 +4161,11 @@ function vm_return() { reset_austria_hungary_border_reopened() } - //Check if end event state is needed + // Check if end event state is needed if (game.is_pwr_struggle || game.state === 'vm_tst_6' || game.return_state === 'tiananmen_square_attempt_done') { vm_end_event() } - //Check if auto-resolve opponent event + // Check if auto-resolve opponent event else if (is_auto_resolve(game.played_card) && ((cards[game.played_card].side === 'C' && game.active === DEM) || (cards[game.played_card].side === 'D' && game.active === COM) )) { vm_end_event() } @@ -4445,29 +4447,29 @@ function vm_add_limited_infl() { } function vm_do_add_limited_infl(space, max_infl) { - push_undo() + push_undo() log_summary(`Added £ SP in %${space}`) - game.vm_available_ops -- + game.vm_available_ops -- - if (!game.vm_influence_added) { - game.vm_influence_added = {} - } + if (!game.vm_influence_added) { + game.vm_influence_added = {} + } - if (!game.vm_influence_added[space]) { - game.vm_influence_added[space] = 0 - } + if (!game.vm_influence_added[space]) { + game.vm_influence_added[space] = 0 + } - if (game.active === COM) { - game.comInfl[space] ++ - } else { - game.demInfl[space] ++ - } + if (game.active === COM) { + game.comInfl[space] ++ + } else { + game.demInfl[space] ++ + } - game.vm_influence_added[space] ++ + game.vm_influence_added[space] ++ - if (game.vm_influence_added[space] === max_infl) { - game.valid_spaces = game.valid_spaces.filter(id => id !== space) - } + if (game.vm_influence_added[space] === max_infl) { + game.valid_spaces = game.valid_spaces.filter(id => id !== space) + } check_tyrant() if (game.vm_available_ops === 0) {game.valid_spaces = [] } } @@ -4546,33 +4548,33 @@ function vm_remove_limited_opp_infl() { function vm_do_remove_limited_infl(space, max_infl) { push_undo() log_summary(`Removed £ SP from %${space}`) - game.vm_available_ops -- + game.vm_available_ops -- - if (!game.vm_influence_added) { - game.vm_influence_added = {} - } + if (!game.vm_influence_added) { + game.vm_influence_added = {} + } - if (!game.vm_influence_added[space]) { - game.vm_influence_added[space] = 0 - } + if (!game.vm_influence_added[space]) { + game.vm_influence_added[space] = 0 + } - if (game.active === COM) { - game.demInfl[space] -- + if (game.active === COM) { + game.demInfl[space] -- if (game.demInfl[space] === 0) { game.valid_spaces = game.valid_spaces.filter(id => id !== space) } } else { - game.comInfl[space] -- + game.comInfl[space] -- if (game.comInfl[space] === 0) { game.valid_spaces = game.valid_spaces.filter(id => id !== space) } - } + } - game.vm_influence_added[space] ++ + game.vm_influence_added[space] ++ - if (game.vm_influence_added[space] === max_infl) { - game.valid_spaces = game.valid_spaces.filter(id => id !== space) - } + if (game.vm_influence_added[space] === max_infl) { + game.valid_spaces = game.valid_spaces.filter(id => id !== space) + } check_tyrant() if (game.vm_available_ops === 0) {game.valid_spaces = []} @@ -4864,18 +4866,18 @@ function vm_eliminate(space_id) { // Eliminate the democrat influence and move t } function get_adjusted_adjacency(space_id) { - let adjacent_spaces = spaces[space_id].adjacent + let adjacent_spaces = spaces[space_id].adjacent if (adjacent_spaces.includes(game.systematization)) { - let eliminated_space_id = game.systematization - adjacent_spaces = adjacent_spaces.map(adj_space_id => { - if (adj_space_id === eliminated_space_id) { - return spaces[eliminated_space_id].adjacent - } - return adj_space_id - }).flat(); // Flatten in case the eliminated space has multiple adjacencies - } + let eliminated_space_id = game.systematization + adjacent_spaces = adjacent_spaces.map(adj_space_id => { + if (adj_space_id === eliminated_space_id) { + return spaces[eliminated_space_id].adjacent + } + return adj_space_id + }).flat() // Flatten in case the eliminated space has multiple adjacencies + } adjacent_spaces = adjacent_spaces.filter(s => s !== space_id) - return adjacent_spaces + return adjacent_spaces } function vm_exit_visas() { @@ -4928,7 +4930,7 @@ function vm_goodbye_lenin() { game.communist_hand_red.push(card) } } - //Check if these cards are playable + // Check if these cards are playable for (let card of game.communist_hand_red) { if (cards[card].playable || game.playable_cards.includes(card)) { game.valid_cards.push(card) @@ -5175,7 +5177,7 @@ function vm_power_struggle() { game.pwr_struggle_in = countries[scoring_cards.indexOf(game.vm_event)] log_h2(`C${game.vm_event}`) - //Check for Securitate + // Check for Securitate if (game.pwr_struggle_in === 'Romania' && game.persistent_events.includes(C_SECURITATE)) { log(`C${C_SECURITATE}: Democrat reveals Power Struggle cards`) game.opp_power_hand = true @@ -5450,8 +5452,8 @@ function vm_we_are_the_people() { add_to_persistent_events(C_WE_ARE_THE_PEOPLE) logi(`The Communist may no longer make Support Checks in Leipzig`) if (!game.vm_influence_added) { - game.vm_influence_added = {} - } + game.vm_influence_added = {} + } game.vm_influence_added[S_LUTHERAN_CHURCH] = 0 game.vm_available_ops = 4 game.state = 'vm_we_are_the_people_remove' @@ -5489,8 +5491,8 @@ function vm_permanently_remove () { } if (cards[game.played_card].remove && !game.strategy_removed.includes(game.played_card)) { permanently_remove(game.played_card) - } /*This means the card that called the event being played is also removed if relevant. Think this makes sense */ - vm_next() + } /*This means the card that called the event being played is also removed if relevant. Think this makes sense */ + vm_next() } function discarded_card() { @@ -5513,7 +5515,7 @@ function vm_tst_4() { function vm_tst_6() { log_h3('Tiananmen Square Track Award') game.vm_available_ops = 1 - game.temp = 1 //Set temp to 1, so that Card 1 is called during the support check, which has 2 ops + game.temp = 1 // Set temp to 1, so that Card 1 is called during the support check, which has 2 ops game.state = 'vm_tst_6' } @@ -5584,7 +5586,7 @@ states.vm_take_control = { } else if (game.vm_available_ops > 0 ) { view.prompt = `${clean_name(cards[this_card()].name)}: take control of ${event_prompt()}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } else { view.prompt = `${clean_name(cards[this_card()].name)}. Take control: done.` @@ -5625,7 +5627,7 @@ states.vm_add_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: add ${pluralize(game.vm_available_ops,'SP')}${event_prompt()}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } else { get_end_infl_prompt() @@ -5666,9 +5668,9 @@ states.vm_add_infl_free = { view.prompt = `${clean_name(cards[this_card()].name)}: add ${game.vm_available_ops} SPs to ${event_prompt()}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } - } else { + } else { get_end_infl_prompt() } }, @@ -5710,7 +5712,7 @@ states.vm_add_x_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: Add ${game.vm_available_ops} SPs to ${event_prompt()}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } }, @@ -5742,13 +5744,13 @@ states.vm_add_limited_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: add ${pluralize(game.vm_available_ops,'SP')} to ${event_prompt()}.` } for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } }, space(space) { vm_do_add_limited_infl(space, game.vm_max_infl) - if (game.vm_available_ops === 0 || game.valid_spaces.length === 0) { + if (game.vm_available_ops === 0 || game.valid_spaces.length === 0) { game.valid_spaces = [] do_log_summary() game.vm_event_done = true @@ -5767,9 +5769,9 @@ states.vm_remove_infl = { return } if (game.vm_available_ops === 0 ) { - view.prompt = `${clean_name(cards[this_card()].name)}. Remove SPs: done.` - gen_action('done') - return + view.prompt = `${clean_name(cards[this_card()].name)}. Remove SPs: done.` + gen_action('done') + return } if (game.remove_opponent_infl) { view.prompt = `${clean_name(cards[this_card()].name)}: remove ${pluralize(game.vm_available_ops, 'opponent SP')}${event_prompt()}.` @@ -5778,7 +5780,7 @@ states.vm_remove_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: remove ${pluralize(game.vm_available_ops,'SP')}${event_prompt()}.` } for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } }, space(space) { @@ -5815,7 +5817,7 @@ states.vm_remove_x_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: remove ${pluralize(game.vm_available_ops,'SP')} from ${event_prompt()}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } }, @@ -5835,11 +5837,11 @@ states.vm_remove_x_infl = { states.vm_remove_limited_infl = { inactive: 'remove SP.', prompt () { - if (game.vm_available_ops > 0 && game.valid_spaces.length > 0) { + if (game.vm_available_ops > 0 && game.valid_spaces.length > 0) { view.prompt = `${clean_name(cards[this_card()].name)}: remove ${pluralize(game.vm_available_ops,'SP')}${event_prompt()}, no more than ${game.vm_max_infl} per space.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } else if (game.valid_spaces.length === 0 && game.vm_available_ops > 0) { view.prompt = `${clean_name(cards[this_card()].name)}: no further SP to remove.` @@ -5890,7 +5892,7 @@ states.vm_remove_all_infl = { states.vm_support_check_prep = { inactive: 'do support checks.', prompt () { - if (game.valid_spaces.length === 0) { + if (game.valid_spaces.length === 0) { view.prompt = `${clean_name(cards[this_card()].name)}: no valid targets for support check.` gen_action('done') } else { @@ -5908,16 +5910,16 @@ states.vm_support_check_prep = { push_undo() game.selected_space = space - // Check for Austria-Hungary Border Reopened - check on first support check only - //First check for Monday Demonstrations - support checks will always be in East Germany + // Check for Austria-Hungary Border Reopened - check on first support check only + // First check for Monday Demonstrations - support checks will always be in East Germany if (game.vm_event === C_THE_MONDAY_DEMONSTRATIONS && game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) { game.austria_hungary_border_reopened_tracker = true game.state = 'vm_do_support_check' return } - //Then check Austria-Hungary Border Reopened normally - if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) { + // Then check Austria-Hungary Border Reopened normally + if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) { if (game.active === DEM && game.vm_available_ops > 1) { if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED) && game.active === DEM) { game.state = 'vm_austria_hungary_border_reopened_check' @@ -5941,7 +5943,7 @@ states.vm_ceh_support_check_prep = { view.prompt = `Select a space. ${pluralize(game.vm_available_ops, 'support check')} remaining.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } }, @@ -5949,7 +5951,7 @@ states.vm_ceh_support_check_prep = { push_undo() game.selected_space = space - //Then check Austria-Hungary Border Reopened normally + // Then check Austria-Hungary Border Reopened normally if (game.persistent_events.includes(C_AUSTRIA_HUNGARY_BORDER_REOPENED)) { if (game.active === DEM && game.vm_available_ops > 1) { if (spaces[game.selected_space].country === 'East_Germany' && game.persistent_events.includes(58) && game.active === DEM) { @@ -6092,7 +6094,7 @@ states.vm_adamec = { states.vm_brought_in_for_questioning = { inactive: 'discard a card.', prompt() { - if (game.democrat_hand.length === 0) { + if (game.democrat_hand.length === 0) { view.prompt = 'Brought in for Questioning. No cards to discard.' gen_action('pass') } else { @@ -6164,7 +6166,7 @@ states.vm_central_committee_reshuffle = { }, czechoslovakia() { push_undo() - game.vm_active_country = "Czechoslovakia" + game.vm_active_country = "Czechoslovakia" log(`Chose ${country_name(game.vm_active_country)}`) game.valid_spaces = [...S_CZECHOSLOVAKIA] vm_next() @@ -6331,7 +6333,7 @@ states.vm_deutsche_marks_prep = { for (let card of game.valid_cards) { gen_action_card(card) } - } + } }, card(card) { push_undo() @@ -6589,12 +6591,12 @@ states.vm_honecker = { view.prompt = 'Honecker: no valid cards to choose.' gen_action('pass') } else - if (game.temp === 0) {view.prompt = 'Honecker: choose a card to add to your hand.' - for (let card of game.valid_cards) { - gen_action_card(card) - gen_action('pass') + if (game.temp === 0) {view.prompt = 'Honecker: choose a card to add to your hand.' + for (let card of game.valid_cards) { + gen_action_card(card) + gen_action('pass') + } } - } }, card(card) { push_undo() @@ -6737,7 +6739,7 @@ states.vm_kiss_of_death = { clear_undo() log(`C${C_KISS_OF_DEATH}:`) game.vm_event = discard_card(game.communist_hand) - //Change player before checking if event is playable. Common European Home is not playable here + // Change player before checking if event is playable. Common European Home is not playable here change_player() // Special check for the Reformer Rehabilitated if (game.vm_event === C_REFORMER_REHABILITATED && game.dem_tst_position > game.com_tst_position) { @@ -6859,10 +6861,10 @@ states.vm_kremlin_coup_take_control = { view.prompt = `Kremlin Coup! Take control of the Elite space in ${country_name(game.vm_active_country)}.` for (let space_id of game.valid_spaces) { gen_action_space(space_id) - } - } - }, - space(space) { + } + } + }, + space(space) { push_undo() vm_take_control(space) if (game.vm_active_country === 'East_Germany') {game.selected_space = S_BERLIN } @@ -6872,7 +6874,7 @@ states.vm_kremlin_coup_take_control = { if (game.vm_active_country === 'Romania') {game.selected_space = S_BUCURESTI} if (game.vm_active_country === 'Bulgaria') {game.selected_space = S_SOFIA} game.state = 'vm_kremlin_coup_sc_prep' - }, + }, done() { push_undo() if (game.vm_active_country === 'East_Germany') {game.selected_space = S_BERLIN } @@ -6949,11 +6951,11 @@ states.vm_switch_infl = { prompt() { if (game.valid_spaces.length === 0) { view.prompt = `${clean_name(cards[this_card()].name)}: No SPs to remove.` - gen_action('pass') + gen_action("pass") } else { view.prompt = `${clean_name(cards[game.played_card].name)}: ${event_prompt()}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } }, @@ -6970,7 +6972,7 @@ states.vm_switch_infl = { }, pass() { vm_next() - } + }, } states.vm_malta_summit = { @@ -6980,7 +6982,7 @@ states.vm_malta_summit = { prompt() { view.prompt = 'Malta Summit: roll a die.' gen_action('roll') -}, + }, roll() { clear_undo() let roll = roll_d6() @@ -7144,7 +7146,7 @@ states.vm_nomenklatura_remove = { view.prompt = 'Nomenklatura: remove all Democratic SPs from Elite spaces.' for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } } }, @@ -7239,7 +7241,7 @@ states.vm_shock_therapy = { if (game.revolutions[4]) {gen_action('czechoslovakia')} if (game.revolutions[5]) {gen_action('romania')} } - else { + else { view.prompt = 'Shock Therapy: roll a die.' gen_action('roll') } @@ -7581,10 +7583,10 @@ states.vm_warsaw_pact_summit = { push_undo() for (let i = 0; i < spaces.length; i++) { let space = spaces[i] - if (game.demInfl[i] === 0) { - game.valid_spaces.push(space.space_id) - } - } + if (game.demInfl[i] === 0) { + game.valid_spaces.push(space.space_id) + } + } game.vm_available_ops = 4 game.phase = 3 vm_next() @@ -7670,7 +7672,7 @@ states.vm_workers_revolt = { } view.prompt = 'Workers Revolt: select a Worker Space in a country your opponent has power.' for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } }, pass() { @@ -7761,7 +7763,7 @@ states.vm_tst_3 = { states.vm_tst_4 = { inactive: 'remove SPs', prompt () { - if (game.vm_available_ops === 0 || game.valid_spaces.length === 0) { + if (game.vm_available_ops === 0 || game.valid_spaces.length === 0) { view.prompt = 'Tiananmen Square Track award. Remove SPs: done.' gen_action('done') return @@ -7769,7 +7771,7 @@ states.vm_tst_4 = { view.prompt = `Tiananmen Square Track award: remove ${pluralize(game.vm_available_ops,'SP')}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } }, space(space) { @@ -7916,7 +7918,7 @@ states.vm_scare_tactics = { } view.prompt = `${clean_name(cards[this_card()].name)}: remove ${pluralize(game.vm_available_ops, 'opponent SP')}${event_prompt()}.` for (let space_id of game.valid_spaces) { - gen_action_space(space_id) + gen_action_space(space_id) } }, space(space) { @@ -7961,7 +7963,7 @@ states.vm_support_surges_2 = { } else { view.prompt = `Support Surges: you drew a ${power_cards[game.temp].name} ${power_cards[game.temp].value}. Draw a second card.` } - gen_action('draw') + gen_action('draw') }, draw() { if (game.active === DEM) { |