diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-10-27 10:20:58 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-10-27 16:23:20 +0100 |
commit | 0e7691d3bb2d01e4795473e28b14cfa0420dd2bb (patch) | |
tree | 2f8c4345e9c558c445588f358ad243686acc25c5 /rules.js | |
parent | ac994f2e4e8e1db0faa0a189683030fa390a40aa (diff) | |
download | 1989-dawn-of-freedom-0e7691d3bb2d01e4795473e28b14cfa0420dd2bb.tar.gz |
Use card numbers directly.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 146 |
1 files changed, 80 insertions, 66 deletions
@@ -208,7 +208,6 @@ const C_MALTA_SUMMIT = 110 const dem_tst_req = [5, 5, 6, 6, 7, 8, 9, 10] const com_tst_req = [6, 6, 7, 7, 8, 7, 6, 5] const scoring_cards = [22, 23, 42, 43, 55, 95] -const C_TACTICS_FAILS = 52 const leader_cards = [37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48] const rallies = [1, 2, 3, 4, 5, 6] const petitions = [31, 32, 33, 34, 35, 36] @@ -224,6 +223,8 @@ const numberless_cards = [1, 2, 3, 4, 5, 6, 37, 38, 39, 40, 41, 42, 43, 44, 45, 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] +const PC_TACTICS_FAILS = 52 + // COUNTRY CONSTANTS const S_EAST_GERMANY = [0,1,2,3,4,5,6,7,8,9,10,11] @@ -319,7 +320,7 @@ function start_game() { //console.log('start game') - game.strategy_deck = draw_deck(cards) + game.strategy_deck = draw_deck() reset_power() //Set starting influence @@ -714,7 +715,7 @@ states.play_card ={ }, event() { push_undo() - log_gap(`Played C${cards[game.played_card].number} for the event`) + log_gap(`Played C${game.played_card} for the event`) game.vm_infl_to_do = false if (scoring_cards.includes(game.played_card)) {game.phase = 0} else {game.phase = 1} @@ -725,7 +726,7 @@ states.play_card ={ }, opp_event() { push_undo() - log_gap(`Played C${cards[game.played_card].number} for the event`) + log_gap(`Played C${game.played_card} for the event`) game.phase = 1 /*Do I still need this?*/ game.vm_infl_to_do = true game.return = game.active @@ -740,7 +741,7 @@ states.play_card ={ }, influence() { push_undo() - log_gap(`Played C${cards[game.played_card].number} to place SPs`) + log_gap(`Played C${game.played_card} to place SPs`) // Check if Common European Home played for influence @@ -776,12 +777,12 @@ states.play_card ={ }, tst() { push_undo() - log_gap(`Played C${cards[game.played_card].number} to the Tiananmen Square Track`) + log_gap(`Played C${game.played_card} to the Tiananmen Square Track`) game.state='tiananmen_square_attempt' }, support_check() { push_undo() - log_gap(`Played C${cards[game.played_card].number} for support checks`) + log_gap(`Played C${game.played_card} for support checks`) // Check if card is opponent card with event that needs to be resolved @@ -1599,7 +1600,7 @@ states.power_struggle = { game.return_state = 'power_struggle' if (game.phase === 0) {delete game.proxy_power_card} if (card === 52) { - log_gap(`Played P52: P${power_cards[game.played_power_card].number} no longer playable`) + log_gap(`Played P52: P${game.played_power_card} no longer playable`) } else { if (game.phase === 0 && leader_cards.includes(card)) {} /* Log nothing. Probably a better way to do this */ @@ -1675,28 +1676,28 @@ states.power_struggle = { game.state = 'support_loss' }, strike () { - log(`Played: P${power_cards[game.played_power_card].number} as a Strike`) + log(`Played: P${game.played_power_card} as a Strike`) game.proxy_power_card = 'Strike' game.phase = 1 next_player() do_valid_cards() }, march () { - log(`Played: P${power_cards[game.played_power_card].number} as a March`) + log(`Played: P${game.played_power_card} as a March`) game.proxy_power_card = 'March' game.phase = 1 next_player() do_valid_cards() }, rally () { - log(`Played: P${power_cards[game.played_power_card].number} as a Rally in the Square`) + log(`Played: P${game.played_power_card} as a Rally in the Square`) game.proxy_power_card = 'Rally in the Square' game.phase = 1 next_player() do_valid_cards() }, petition () { - log(`Played: P${power_cards[game.played_power_card].number} as a Petition`) + log(`Played: P${game.played_power_card} as a Petition`) game.proxy_power_card = 'Petition' game.phase = 1 next_player() @@ -2169,7 +2170,7 @@ states.general_strike = { game.return_state = 'general_strike' goto_vm(game.vm_event) } else { - log(`Discarded C${cards[card].number}`) + log(`Discarded C${card}`) } }, roll() { @@ -2310,7 +2311,7 @@ states.stasi_end_round = { }, card(card) { push_undo() - log_gap(`Democrat selected C${cards[card].number} as next card.`) + log_gap(`Democrat selected C${card} as next card.`) game.stasi_card = card game.state = 'stasi_finish' }, @@ -2835,34 +2836,41 @@ function valid_spaces_infl() { } function valid_cards(player_hand, presence) { - const valid_cards_set= new Set(); + const valid_cards_set = new Set() if (game.phase === 0) { - for (let c of player_hand) { - let card = power_cards.find(card => card && card.number === c); - if (card.number === C_TACTICS_FAILS) {continue} // Never add tactics fails - if (card.name === game.tactics_fails) {continue} //Cannot play the suit of Tactics Fails - if (card.socio === 0) { - valid_cards_set.add(card.number); - } else if (leaders.includes(card.socio) && presence[card.socio]) { - valid_cards_set.add(card.number); - } - } + for (let c of player_hand) { + let card = power_cards[c] + if (c === PC_TACTICS_FAILS) { + continue + } + // Never add tactics fails + if (card.name === game.tactics_fails) { + continue + } + // Cannot play the suit of Tactics Fails + if (card.socio === 0) { + valid_cards_set.add(c) + } else if (leaders.includes(card.socio) && presence[card.socio]) { + valid_cards_set.add(c) + } + } } else if (game.phase === 1) { - for (let c of player_hand) { - let card = power_cards.find(card => card && card.number === c); - console.log('card', card, ) - if (card.name === power_cards[game.played_power_card].name) { - valid_cards_set.add(card.number); - } else if (card.name === game.proxy_power_card) { - valid_cards_set.add(card.number) - } - else if (leaders.includes(card.socio) && presence[card.socio]) { - valid_cards_set.add(card.number); - } else if (card.number === 52) {valid_cards_set.add(card.number)} - } - } - game.valid_cards = Array.from(valid_cards_set); - return game.valid_cards; + for (let c of player_hand) { + let card = power_cards[c] + console.log("card", card) + if (card.name === power_cards[game.played_power_card].name) { + valid_cards_set.add(c) + } else if (card.name === game.proxy_power_card) { + valid_cards_set.add(c) + } else if (leaders.includes(card.socio) && presence[card.socio]) { + valid_cards_set.add(c) + } else if (c === PC_TACTICS_FAILS) { + valid_cards_set.add(c) + } + } + } + game.valid_cards = Array.from(valid_cards_set) + return game.valid_cards } function do_valid_cards() { @@ -3900,8 +3908,12 @@ function find_country_index(country) { return countries.indexOf(country) } -function draw_deck(deck) { - return deck.filter(card => card && card.period === 1).map(card => card.number) +function draw_deck() { + let hand = [] + for (let c = first_strategy_card; c <= last_strategy_card; ++c) + if (cards[c].period === 1) + hand.push(c) + return c } function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_hand_limit) { @@ -3957,7 +3969,7 @@ function discard(card) { } if (!game.strategy_discard.includes(card)) { game.strategy_discard.push(card) - log(`Discarded C${cards[card].number}`) + log(`Discarded C${card}`) } } else if (game.is_pwr_struggle) { if (game.active === COM) { @@ -4013,7 +4025,7 @@ function discard_card(hand) { log_gap(`Discarded: P${discarded_card} V${power_cards[discarded_card].value}`) } } else { - log(`Discarded C${cards[discarded_card].number}`) + log(`Discarded C${discarded_card}`) game.strategy_discard.push(discarded_card) } return discarded_card @@ -4027,15 +4039,17 @@ function discard_from_table(card) { function add_midyear() { - const mid_year = cards.filter(card => card && card.period === 2).map(card => card.number); - game.strategy_deck.push(...mid_year); + for (let c = first_strategy_card; c <= last_strategy_card; ++c) + if (cards[c].period === 2) + game.strategy_deck.push(c) log_h3('Mid-year cards added to draw deck') } function add_lateyear() { - const late_year = cards.filter(card => card && card.period === 3).map(card => card.number) - game.strategy_deck.push(...late_year) + for (let c = first_strategy_card; c <= last_strategy_card; ++c) + if (cards[c].period === 3) + game.strategy_deck.push(c) log_h3('Late-year cards added to draw deck') } @@ -5183,20 +5197,20 @@ function vm_civic_forum() { } function vm_common_european_home() { - let valid_cards = []; - for (let c of cards) { + let valid_cards = [] + for (let c = first_strategy_card; c <= last_strategy_card; ++c) { if (game.active === DEM) { - if (c && c.side === 'C') { - valid_cards.push(c.number) - } + if (cards[c].side === 'C') { + valid_cards.push(c) + } } else { - if (c && c.side === 'D') { - valid_cards.push(c.number) + if (cards[c].side === 'D') { + valid_cards.push(c) } } } game.valid_cards = valid_cards - game.state = 'vm_common_european_home_choose' + game.state = "vm_common_european_home_choose" } function vm_dash_for_the_west() { @@ -6624,7 +6638,7 @@ states.vm_common_european_home_play = { }, influence(){ push_undo() - log_gap(`Played C${cards[game.vm_event].number} to place SPs`) + log_gap(`Played C${game.vm_event} to place SPs`) game.vm_available_ops = cards[game.vm_event].ops valid_spaces_infl() // If ABHR - Set AHBR tracker to true @@ -6635,14 +6649,14 @@ states.vm_common_european_home_play = { }, support_check() { push_undo() - log_gap(`Played C${cards[game.vm_event].number} for support checks`) + log_gap(`Played C${game.vm_event} for support checks`) game.vm_available_ops = 2 game.state = 'vm_ceh_support_check_prep' valid_spaces_sc() }, tst() { push_undo() - log_gap(`Played C${cards[game.vm_event].number} to the Tiananmen Square Track`) + log_gap(`Played C${game.vm_event} to the Tiananmen Square Track`) game.state = 'vm_tiananmen_square_attempt' } } @@ -6695,7 +6709,7 @@ states.vm_play_event_from_discard = { }, card(card) { push_undo() - log(`Chose C${cards[card].number}`) + log(`Chose C${card}`) game.vm_event = card game.vm_available_ops = cards[card].ops game.discard = false @@ -6728,7 +6742,7 @@ states.vm_deutsche_marks_prep = { }, card(card) { push_undo() - log(`Gave C${cards[card].number}`) + log(`Gave C${card}`) game.valid_cards = [] silent_discard(card) game.state = 'vm_deutsche_marks_confirm' @@ -6777,7 +6791,7 @@ states.vm_deutsche_marks = { }, event() { push_undo() - log(`Played C${cards[game.vm_event].number} for the event`) + log(`Played C${game.vm_event} for the event`) if (!game.vm_infl_to_do) { game.return = game.active } @@ -6785,21 +6799,21 @@ states.vm_deutsche_marks = { }, influence() { push_undo() - log(`Played C${cards[game.vm_event].number} to place SPs`) + log(`Played C${game.vm_event} to place SPs`) game.vm_available_ops = get_card_ops(game.vm_event) valid_spaces_infl() game.state = 'vm_add_infl' }, support_check() { push_undo() - log_gap(`Played C${cards[game.vm_event].number} for support checks`) + log_gap(`Played C${game.vm_event} for support checks`) game.vm_available_ops = 2 game.state='vm_support_check_prep' valid_spaces_sc() }, tst() { push_undo() - log_gap(`Played C${cards[game.vm_event].number} to the Tiananmen Square Track`) + log_gap(`Played C${game.vm_event} to the Tiananmen Square Track`) game.state='vm_tiananmen_square_attempt' } } @@ -6986,7 +7000,7 @@ states.vm_honecker = { card(card) { push_undo() game.valid_cards = [] - log(`Took C${cards[card].number} into hand`) + log(`Took C${card} into hand`) game.temp = card let card_index = game.strategy_discard.indexOf(card) game.strategy_discard.splice(card_index, 1) |