From 21fb502888aa00e5e4536312177e946afb821804 Mon Sep 17 00:00:00 2001 From: iainp5 Date: Fri, 4 Oct 2024 14:04:46 +0100 Subject: Changes to reduce game object --- play.js | 5 ++- rules.js | 150 ++++++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 93 insertions(+), 62 deletions(-) diff --git a/play.js b/play.js index 2b8741c..55efbb4 100644 --- a/play.js +++ b/play.js @@ -413,6 +413,7 @@ for (let c of view.strategy_discard) { } // DISCARD FOR EVENTS +console.log('view.discard',view.discard) if(view.discard) { //document.getElementById("discard").replaceChildren() document.getElementById("discard_panel").classList.remove("hide") @@ -535,7 +536,7 @@ if (view.ceausescu_cards.length > 0 && view.is_pwr_struggle === true) { for (let id of board_events) { let marker = document.getElementById(`event_${id}`) - console.log('event', id, marker) + //console.log('event', id, marker) if (view.persistent_events.includes(id)) { marker.style.display = 'block' } else { @@ -548,7 +549,7 @@ for (let id of board_events) { for (let id of box_events) { let marker = document.getElementById(`event_${id}`) - console.log('event', id, marker) + //console.log('event', id, marker) if (view.persistent_events.includes(id)) { marker.style.display = 'block' } else { diff --git a/rules.js b/rules.js index e454215..f156cc5 100644 --- a/rules.js +++ b/rules.js @@ -43,13 +43,10 @@ exports.setup = function (seed, scenario, options) { vm_event: 0, vm_event_to_do: false, vm_infl_to_do: false, - vm_active_country: 0, vm_influence_added: {}, vm_max_infl: 0, played_card: 0, - stasi_card: 0, - samizdat_card: 0, table_cards: [], austria_hungary_border_reopened_tracker: false, temp: 0, @@ -85,7 +82,6 @@ exports.setup = function (seed, scenario, options) { view_opp_hand: false, strategy_removed: [], persistent_events: [], - prudence: {DEM: 0, COM: 0}, power_struggle_deck: [], power_struggle_discard: [], dem_hand_limit: 8, @@ -436,7 +432,7 @@ states.choose_card = { if (!scoring_cards.includes(card)) { let scoring_cards_count = count_scoring_cards() - if (scoring_cards_count >= (8-game.round)){ + if (game.round !== 8 && scoring_cards_count >= (8-game.round)){ game.temp = card game.state = 'confirm_card' return @@ -1040,6 +1036,7 @@ states.draw_power_cards = { }, draw() { push_undo() + game.power_struggle_deck = all_power_cards console.log('called draw cards, country', game.pwr_struggle_in, 'game.active', game.active, 'game.view_opp_hand', game.view_opp_hand) console.log('test3') let presence = check_presence(game.pwr_struggle_in) @@ -1896,11 +1893,7 @@ states.general_strike = { let roll = Math.floor(Math.random() * 6) + 1 log(`Rolled a ${roll}`) - log(`+${game.available_ops} from C${cards[game.played_card].number}.`) - if (game.prudence.COM !== 0) { - log(`${game.prudence.COM} from C8`) - roll -- - } + log(`+${game.available_ops} from card ops`) let total = roll + game.available_ops log(`Modified total: ${total}`) @@ -2019,7 +2012,8 @@ states.new_years_eve_party = { states.stasi_end_round = { inactive: 'choose next card due to Stasi.', prompt() { - if (game.stasi_card === 0 ) { + console.log('game.stasi_card', game.stasi_card) + if (!game.stasi_card || game.stasi_card === 0 ) { let available_cards = game.democrat_hand if (available_cards.length === 0) { view.prompt = 'Stasi: no cards remaining.' @@ -2289,14 +2283,17 @@ function do_sc(space) { log(`Rolled a ${roll}`) console.log('game.vm_event', game.vm_event) console.log('game.is_pwr_struggle', game.is_pwr_struggle) + /* //Check if support check is being done with game.played_card or a subsequent card (e.g. Common European Home, Dash for the West, etc) if (game.vm_event > 0) { roll+= cards[game.vm_event].ops log(`+${cards[game.vm_event].ops} from card ops`) } + */ // Check for the Crowd Turns Against Ceausescu - else if (game.is_pwr_struggle) { + //else + if (game.is_pwr_struggle) { roll += game.vm_available_ops log(`+${game.vm_available_ops} from Ceausescu`) } @@ -2308,9 +2305,9 @@ function do_sc(space) { log('+2 from Tiananmen Square Track award') } else { - let modifier = 0 - let card_ops = cards[game.played_card].ops - + //let modifier = 0 + let card_ops = get_card_ops(this_card()) +/* // Start with base value of card log(`+${card_ops} from card`) @@ -2326,11 +2323,11 @@ function do_sc(space) { modifier++ } // Check for Prudence - if (game.active === DEM && game.prudence.DEM !== 0) { + if (game.active === DEM && game.prudence && game.prudence.DEM < 0) { log(`${pluralize(game.prudence.DEM, ' op')} from C8`) modifier += game.prudence.DEM } - if (game.active === COM && game.prudence.COM !== 0) { + if (game.active === COM && game.prudence && game.prudence.COM < 0) { log(`${pluralize(game.prudence.COM, ' op')} from C8`) modifier += game.prudence.COM } @@ -2339,8 +2336,9 @@ function do_sc(space) { if ((modified_ops) < 1) { modified_ops = 1 } - roll += modified_ops - //log(`+${card_ops} from card ops`) + */ + roll += card_ops + log(`+${card_ops} from card ops`) } if (game.support_check_modifier > 0) { @@ -2349,33 +2347,34 @@ function do_sc(space) { } // Events which modify SC rolls - + //Tear Gas if (game.active === COM && game.persistent_events.includes(30) && spaces[clicked_space].socio === 6) { roll ++ log('+1 from C30') permanently_remove(30) game.persistent_events = game.persistent_events.filter(n => n !== 30) } + //FRG Embassies if (game.active === DEM && spaces[clicked_space].region === 'Eastern Europe' && game.persistent_events.includes(74)) { roll++ log('+1 from C74') } - /*if (game.warsaw_pact_summit) { - roll += 2 - log('+2 from C76') - }*/ + //GrenzTruppen if (game.active === DEM && spaces[clicked_space].country === 'East_Germany' && game.persistent_events.includes(59)) { roll-- log('-1 from C59') } + //Stand Fast if ((game.active === COM && game.stand_fast === DEM && check_dem_control(clicked_space)) || (game.active === DEM && game.stand_fast === COM && check_com_control(clicked_space))){ roll-- log('-1 from C100') } + //Elena if (game.active === DEM && game.persistent_events.includes(101) && spaces[clicked_space].country === 'Romania') { roll-- log('-1 from C101') } + //Austria Hungary Border Reopened if (game.active === DEM && game.persistent_events.includes(58) && game.austria_hungary_border_reopened_tracker) { roll++ log(`+1 from C58`) @@ -3227,25 +3226,33 @@ function get_events(card){ function get_card_ops(card) { let ops = cards[card].ops if (game.persistent_events.includes(25) && game.active === COM) { - log('+1 op from C25') + if(game.state === 'choose_card' || game.state === 'stasi_play_card') { + log('+1 op from C25') + } ops ++ } if (game.persistent_events.includes(50) && game.active === DEM) { - log('+1 op from C50') + if(game.state === 'choose_card' || game.state === 'stasi_play_card') { + log('+1 op from C50') + } ops ++ } if ((game.active === DEM && game.dem_tst_position >= 2 && game.com_tst_position <= 1 && cards[card].ops === 1) || (game.active === COM && game.com_tst_position >=2 && game.dem_tst_position <= 1 && cards[card].ops === 1)) { - log('+1 op from Tiananmen Square Track') + if(game.state === 'choose_card' || game.state === 'stasi_play_card') { + log('+1 op from Tiananmen Square Track') + } ops ++ } - if ((game.active === DEM && game.prudence.DEM !== 0)) { - if (ops > 2) { - log(`${pluralize(game.prudence.DEM,'op')} from C8`) - } else { - if (ops > 1) { - log(`-1 op from C8`) + if ((game.active === DEM && game.prudence && game.prudence.DEM !== 0)) { + if(game.state === 'choose_card' || game.state === 'stasi_play_card') { + if (ops > 2) { + log(`${pluralize(game.prudence.DEM,'op')} from C8`) + } else { + if (ops > 1) { + log(`-1 op from C8`) + } } } ops += game.prudence.DEM @@ -3254,11 +3261,13 @@ function get_card_ops(card) { } } - if (game.active === COM && game.prudence.COM !== 0) { - if (ops > 2) { - log(`${pluralize(game.prudence.COM,'op')} from C8`) - } else if (ops > 1) { - log(`-1 op from C8`) + if (game.active === COM && game.prudence && game.prudence.COM < 0) { + if(game.state === 'choose_card') { + if (ops > 2) { + log(`${pluralize(game.prudence.COM,'op')} from C8`) + } else if (ops > 1) { + log(`-1 op from C8`) + } } ops += game.prudence.COM if (ops < 1) { @@ -3413,8 +3422,9 @@ function end_round() { return } if (game.round_player === DEM) { + console.log('checking stasi', game.persistent_events.includes(13)) if(game.persistent_events.includes(13)) { - //console.log('stasi sub function') + console.log('stasi sub function') if (game.active !== DEM) { next_player() } @@ -3483,11 +3493,12 @@ function new_turn() { game.tst_8 = false //Remove events that only last one turn - game.persistent_events = game.persistent_events.filter(n => n !== 25) /*Perestroika*/ - game.prudence = {DEM: 0, COM: 0} + game.persistent_events = game.persistent_events.filter(n => n !== 25) /*Perestroika*/ game.persistent_events = game.persistent_events.filter(n => n !== 50) /*Sinatra Doctrine*/ game.persistent_events = game.persistent_events.filter(n => n !== 13) /*Stasi*/ game.persistent_events = game.persistent_events.filter(n => n !== 15) /*Honecker*/ + delete game.prudence + delete game.stasi_card //Austria Hungary Border Reopened if (game.persistent_events.includes(58)) { @@ -3538,7 +3549,7 @@ function new_turn() { if (game.samizdat_card > 0 ) { game.democrat_hand.push(game.samizdat_card) - game.samizdat_card = 0 + delete game.samizdat_card } log_h1("Turn " + game.turn) @@ -3768,7 +3779,7 @@ function add_lateyear() { } function reset_power() { - game.power_struggle_deck = power_cards.filter(card => card !== null && card.number <= 52).map(card => card.number) + game.power_struggle_deck = [] game.dem_pwr_hand = [] game.com_pwr_hand = [] game.phase = 1 @@ -3842,7 +3853,7 @@ function check_common_european_home() { function this_card() { return game.vm_event > 0 ? game.vm_event : game.played_card } - +/* function get_ops(card) { let ops = cards[card].ops if (game.active === COM) { @@ -3854,7 +3865,9 @@ function get_ops(card) { if (game.persistent_events.includes(25)) { ops++ } - ops += game.prudence.COM + if (game.prudence.COM && game.prudence.COM <0) { + ops += game.prudence.COM + } } else { //Check TST op bonus @@ -3865,12 +3878,15 @@ function get_ops(card) { if (game.persistent_events.includes(50)) { ops++ } - ops += game.prudence.DEM + if (game.prudence.DEM && game.prudence.DEM <0) { + ops += game.prudence.DEM + } } //Ops can never be less than one if (ops <1) { ops = 1 } return ops } + */ const pluralize = (count, noun, suffix = 's') => `${count} ${noun}${Math.abs(count) !== 1 ? suffix : ''}` @@ -4223,7 +4239,7 @@ function vm_return() { game.state = "play_card"; } */ console.log('in vm_return, discard:', game.strategy_discard) - game.support_check_modifier = 0 + delete game.support_check_modifier game.vm_event = 0 /*Reset to 0 now that event has been completed. Hopefully this doesn't cause issues! */ if (game.persistent_events.includes(58)) { reset_austria_hungary_border_reopened() @@ -5265,6 +5281,7 @@ function vm_honecker() { game.valid_cards.push(c) } } + game.discard = true game.state = 'vm_honecker' } @@ -5278,13 +5295,13 @@ function vm_inflationary_currency_discard() { next_player() if (game.active === COM) { for (let card of game.communist_hand){ - if (get_ops(card) >= 3) { + if (get_card_ops(card) >= 3) { game.valid_cards.push(card) } } } else { for (let card of game.democrat_hand){ - if (get_ops(card) >= 3) { + if (get_cards_ops(card) >= 3) { game.valid_cards.push(card) } } @@ -5481,6 +5498,9 @@ function vm_presidential_visit() { } function vm_prudence() { + if (!game.prudence) { + game.prudence = {DEM: 0, COM: 0} + } if (game.active === DEM) { game.prudence.COM -- log(`${game.prudence.COM} to Communist ops this turn`) @@ -5825,6 +5845,9 @@ states.vm_take_control = { push_undo() vm_take_control(space) game.vm_available_ops-- + if (game.vm_available_ops === 0) { + vm_next() + } }, done() { vm_next() @@ -5960,6 +5983,14 @@ states.vm_add_limited_infl = { } vm_next() }*/ + if (game.vm_available_ops === 0 || game.valid_spaces.length === 0 ) { + if (game.summary.length > 0) { + pop_summary() + log_br() + } + game.vm_event_done = true + vm_next() + } }, done () { if (game.summary.length > 0) { @@ -6611,9 +6642,13 @@ states.vm_deutsche_marks = { influence() { push_undo() log(`Played C${cards[game.vm_event].number} to place SPs`) - game.vm_available_ops = cards[game.vm_event].ops + game.vm_available_ops = get_card_ops(game.vm_event) + + /*cards[game.vm_event].ops if (game.persistent_events.includes(25)) {game.vm_available_ops++ } - game.vm_available_ops += game.prudence.COM + if (game.prudence.COM && game.prudence.COM < 0 ) { + game.vm_available_ops += game.prudence.COM + }*/ valid_spaces_infl() game.state = 'vm_add_infl' }, @@ -6767,11 +6802,11 @@ states.vm_goodbye_lenin_ops = { }, influence(){ push_undo() - game.vm_available_ops = cards[this_card()].ops - if (game.persistent_events.includes(50)) { + game.vm_available_ops = get_card_ops(this_card()) + /*if (game.persistent_events.includes(50)) { log(`+1 from C50`) game.vm_available_ops++ - } + }*/ console.log('goodbye lenin: influence selected') valid_spaces_infl() @@ -7139,12 +7174,7 @@ states.vm_laszlo_tokes = { }, influence(){ push_undo() - if (game.persistent_events.includes(50)) { - log(`+1 op from C50`) - game.vm_available_ops = 3 - } else { - game.vm_available_ops = 2 - } + game.vm_available_ops = get_card_ops(73) valid_spaces_infl() game.valid_spaces = game.valid_spaces.filter(space_id => spaces[space_id].country === 'Romania') game.phase = 3 -- cgit v1.2.3