From 9ca8a214ab0bc45fb295a2da44dfb5deefe6300b Mon Sep 17 00:00:00 2001 From: iainp5 Date: Thu, 26 Sep 2024 15:24:14 +0100 Subject: Removed var from game.pieces --- play.js | 48 ++++---- rules.js | 422 ++++++++++++++++++++++++++++----------------------------------- 2 files changed, 215 insertions(+), 255 deletions(-) diff --git a/play.js b/play.js index 647be0f..a5cd60a 100644 --- a/play.js +++ b/play.js @@ -200,20 +200,9 @@ function is_action(action) { function on_log(text) { // eslint-disable-line no-unused-vars + console.log('on_log called') let p = document.createElement("div") -//Check if adding influence the the same place as the previous influence - - //let last_log_entry = document.getElementById("log").lastElementChild - console.log('view.log', view.log) - let last_log_entry = document.querySelector(`#log div:nth-child(${view.log.length-1})`) - let last_log_entry_text - console.log('last_log_entry', last_log_entry) - if (last_log_entry) { - last_log_entry_text = last_log_entry.innerHTML - console.log('last_log_entry_text', last_log_entry_text) - } - /* let last_text = last_log_entry ? last_log_entry.split(' ') : [] @@ -259,12 +248,12 @@ function on_log(text) { // eslint-disable-line no-unused-vars } //console.log('view.log', view.log) - console.log('new text', text) + /*console.log('new text', text) if (last_log_entry_text) { console.log('log = text', last_log_entry_text === text) } - +*/ p.innerHTML = text return p } @@ -310,19 +299,22 @@ function on_update() { //Check influence values const pieces = view.pieces - pieces.forEach(piece => { + pieces.forEach((piece, index) => { if (!piece) return - const dem_marker = document.getElementById(`${piece.name_unique}_demInfl`); - const dem_number = document.getElementById(`${piece.name_unique}_demInflValue`); - const com_marker = document.getElementById(`${piece.name_unique}_comInfl`); - const com_number = document.getElementById(`${piece.name_unique}_comInflValue`); + const space = spaces[index] + //console.log('piece', piece) + //console.log('space', space) + const dem_marker = document.getElementById(`${space.name_unique}_demInfl`); + const dem_number = document.getElementById(`${space.name_unique}_demInflValue`); + const com_marker = document.getElementById(`${space.name_unique}_comInfl`); + const com_number = document.getElementById(`${space.name_unique}_comInflValue`); dem_number.innerText=piece.demInfl if (piece.demInfl > 0) { dem_marker.style.display = 'block'; dem_number.style.display = 'block'; - - if(piece.demCtrl === 1){ + console.log('piece', piece, 'space', space) + if(check_dem_control(piece, space)){ dem_marker.classList.add('controlled') dem_number.classList.add('outlined_text') dem_marker.classList.remove('uncontrolled') @@ -340,7 +332,7 @@ function on_update() { com_marker.style.display = 'block'; com_number.style.display = 'block'; - if(piece.comCtrl === 1){ + if(check_com_control(piece, space)){ com_marker.classList.add('controlled') com_number.classList.add('controlled') com_marker.classList.remove('uncontrolled') @@ -625,7 +617,6 @@ if (view.persistent_events['the_tyrant_is_gone'] > 0) { action_button("done", "Done") action_button("undo", "Undo") - //console.log('view.log', view.log) } @@ -696,5 +687,16 @@ function toggle_discard() { document.getElementById("discard_panel").classList.toggle("hide") } +function check_dem_control(piece, space) { + if ((piece.demInfl - piece.comInfl) >= space.stability) { + return true + } else{ false} +} + +function check_com_control(piece, space) { + if ((piece.comInfl - piece.demInfl) >= space.stability) { + return true + } else{ false} +} create_ui() diff --git a/rules.js b/rules.js index 7bcc875..8055a7d 100644 --- a/rules.js +++ b/rules.js @@ -143,13 +143,8 @@ function start_game() { spaces.forEach((space, index) => { if(index === 0 ) return game.pieces.push({ - name_unique: space.name_unique, - space_id: space.space_id, demInfl: space.demInfl, comInfl: space.comInfl, - demCtrl: space.demCtrl, - comCtrl: space.comCtrl, - stability: space.stability, adjacent: space.adjacent }); }); @@ -709,10 +704,7 @@ states.finish_add_infl = { // Generate actions for valid spaces for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ gen_action_infl(spaces[space_id].name_unique) - //} } }, infl(space) { @@ -724,7 +716,6 @@ states.finish_add_infl = { } states.finish_support_check_prep = { - inactive: 'do support checks.', prompt () { if (game.available_ops === 0) { @@ -732,13 +723,10 @@ states.finish_support_check_prep = { gen_action('done') //return } else { - view.prompt = `Select a space. ${pluralize(game.available_ops, 'support check')} remaining.` } - + view.prompt = `Select a space. ${pluralize(game.available_ops, 'support check')} remaining.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); */ - if (space_id) { - gen_action_sc(spaces[space_id].name_unique) - } + gen_action_sc(spaces[space_id].name_unique) + } } }, sc(space) { @@ -807,10 +795,7 @@ states.add_influence = { // Generate actions for valid spaces for (let space_id of game.valid_spaces) { - /* const space = spaces.find(s => s && s.space_id === space_id); - if (space) { */ gen_action_infl(spaces[space_id].name_unique); - //} } }, infl(space) { @@ -920,10 +905,7 @@ states.support_check_prep = { view.prompt = `Select a space. ${pluralize(game.available_ops, 'support check')} remaining.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ - gen_action_sc(spaces[space_id].name_unique); - //} + gen_action_sc(spaces[space_id].name_unique) } } }, @@ -1033,8 +1015,8 @@ states.draw_power_cards = { if (game.persistent_events['peasant_parties_revolt']) { let farmer_check - for (let space of game.pieces) { - if (space && spaces[space.space_id].country === game.pwr_struggle_in && spaces[space.space_id].socio === 3 && space.demCtrl === 1) { + for (let space of spaces) { + if (space && space.country === game.pwr_struggle_in && space.socio === 3 && check_dem_control(space.space_id)) { farmer_check = true } } @@ -1451,10 +1433,7 @@ states.support_loss ={ view.prompt = `Support Loss: remove ${game.available_ops} influence.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); Don't think this is needed - if (space) { */ - gen_action_infl(spaces[space_id].name_unique); - //} + gen_action_infl(spaces[space_id].name_unique) } } else if (game.phase === 1 && game.available_ops === 0 ) { view.prompt = 'Support Loss: finished.' @@ -1978,7 +1957,7 @@ states.stasi_end_round = { gen_action_card(card) } } else { - view.prompt = 'Stasi: choose card done.' + view.prompt = 'Stasi. Choose card: done.' gen_action('done') } }, @@ -2105,6 +2084,7 @@ function add_infl(space) { push_undo() console.log('adding infl to', space) const clicked_space = find_space_index(space) + console.log('clicked_space', clicked_space) //console.log('at start, event', game.persistent_events['austria_hungary_border_reopened'], 'ahbr', game.austria_hungary_border_reopened, 'tracker', game.austria_hungary_border_reopened_tracker) log(`Added 1 influence in %${clicked_space}`) @@ -2116,7 +2096,7 @@ function add_infl(space) { if (game.persistent_events['genscher'] && game.active === DEM && spaces[clicked_space].country === 'East_Germany') { game.available_ops-- log(`(-1 op due to C63)`) - } else if (check_control(clicked_space)) { + } else if (check_opp_control(clicked_space)) { game.available_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 if (game.available_ops < 0) { @@ -2153,13 +2133,14 @@ function add_infl(space) { if (game.active === DEM) { if (game.persistent_events['genscher'] || (game.persistent_events['austria_hungary_border_reopened'] && game.austria_hungary_border_reopened_tracker)) { console.log('in gensher subcheck - remove non-East German controlled ') - game.valid_spaces = game.valid_spaces.filter(n => !(game.pieces[n].comCtrl === 1 && spaces[n].country !== 'East_Germany')) + game.valid_spaces = game.valid_spaces.filter(n => !(check_opp_control(n) && spaces[n].country !== 'East_Germany')) } else { console.log('remove all controlled spaces') - game.valid_spaces = game.valid_spaces.filter(n => game.pieces[n].comCtrl !== 1) + game.valid_spaces = game.valid_spaces.filter(n => !check_opp_control(n)) } } else { - game.valid_spaces = game.valid_spaces.filter(n => game.pieces[n].demCtrl !== 1) + console.log('remove all dem controlled spaces') + game.valid_spaces = game.valid_spaces.filter(n => !check_opp_control(n)) } } @@ -2413,18 +2394,20 @@ function do_sc(space) { function valid_spaces_setup() { game.valid_spaces = [] let valid_spaces_set = new Set(); + console.log('in vs setup') + for (let i =1 ; i < game.pieces.length; i++) { + piece = game.pieces[i] + space = spaces[i] - if (game.state === 'com_init') { - for (let space of game.pieces) { - if (space && space.demInfl === 0) { - valid_spaces_set.add(space.space_id); - } - } - } else if (game.state === 'dem_init') { - for (let space of game.pieces) { - if (space && space.comInfl === 0) { + if (game.state === 'com_init') { + + if (piece.demInfl === 0) { valid_spaces_set.add(space.space_id); } + } else if (game.state === 'dem_init') { + if (space && space.comInfl === 0) { + valid_spaces_set.add(space.space_id); + } } } // Convert the set to an array before returning @@ -2434,15 +2417,17 @@ function valid_spaces_setup() { function valid_spaces_sc() { let valid_spaces_set = new Set(); - if (game.active === DEM) { - for (let space of game.pieces) { - if (space && space.comInfl !== 0 ) { + + for (let i = 1 ; i < game.pieces.length; i++) { + piece = game.pieces[i] + space = spaces[i] + + if (game.active === DEM) { + if (piece.comInfl !== 0 ) { valid_spaces_set.add(space.space_id); - } - } - } else { - for (let space of game.pieces) { - if (space && space.demInfl !== 0 ) { + } + } else { + if (piece.demInfl !== 0 ) { if (game.persistent_events['solidarity_legalised']) { if (space.space_id === 14) {continue} } @@ -2455,13 +2440,14 @@ function valid_spaces_sc() { valid_spaces_set.add(space.space_id); } } + console.log('valid spaces', game.valid_spaces) + } - //Check for Foreign Currency Debt Burden - if (game.persistent_events['foreign_currency_debt_burden'] !== '') { - for (let n of valid_spaces_set) { - if (spaces[n].country === game.persistent_events['foreign_currency_debt_burden']) { - valid_spaces_set.delete(n); - } + //Check for Foreign Currency Debt Burden + if (game.persistent_events['foreign_currency_debt_burden'] !== '') { + for (let n of valid_spaces_set) { + if (spaces[n].country === game.persistent_events['foreign_currency_debt_burden']) { + valid_spaces_set.delete(n); } } } @@ -2478,30 +2464,26 @@ function valid_spaces_sc() { function valid_spaces_support_loss() { let valid_spaces_set = new Set(); - if (game.state === 'support_loss') { + for (let i = 1; i < game.pieces.length; i++) { + console.log('game.pieces.length', game.pieces.length, 'i', i) + piece = game.pieces[i] + space = spaces[i] if (game.active === DEM) { - for (let piece of game.pieces) { - if (!piece) continue - let space = spaces.find(s => s && s.space_id === piece.space_id); - if (space && piece.demInfl > 0 && space.country === game.pwr_struggle_in) { - valid_spaces_set.add(space.space_id); - } + if (piece.demInfl > 0 && space.country === game.pwr_struggle_in) { + valid_spaces_set.add(space.space_id); } } else { - for (let piece of game.pieces) { - if (!piece) continue - let space = spaces.find(s => s && s.space_id === piece.space_id); - if (space && piece.comInfl > 0 && space.country === game.pwr_struggle_in) { - valid_spaces_set.add(space.space_id); - } + if (piece.comInfl > 0 && space.country === game.pwr_struggle_in) { + valid_spaces_set.add(space.space_id); } } - } + } + // Convert the set to an array before returning game.valid_spaces = Array.from(valid_spaces_set); return game.valid_spaces; } - +/* function valid_spaces_support_falters() { let valid_spaces_set = new Set(); if (game.active === DEM) { @@ -2525,40 +2507,44 @@ function valid_spaces_support_falters() { game.valid_spaces = Array.from(valid_spaces_set); return game.valid_spaces; } + */ function valid_spaces_infl() { - /*if (game.state.startsWith('vm')) { + if (game.state.startsWith('vm')) { console.log('valid_spaces_infl called from VM') } else { console.log('valid_spaces_infl called not from VM') - }*/ + } // 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 valid_spaces_set = new Set(); // Iterate over all spaces to find the ones with the player's influence - for (let piece of game.pieces) { - if (!piece) continue + for (let i = 1; i < game.pieces.length; i++) { + piece = game.pieces[i] + space = spaces[i] //console.log('checking piece:', piece) - const player_influence = game.active === COM ? piece.comInfl : piece.demInfl; + let player_influence = game.active === COM ? piece.comInfl : piece.demInfl; // If the piece has the player's influence, add it and its adjacent spaces to the set if (player_influence > 0) { //console.log(piece, 'added to set') - valid_spaces_set.add(piece.space_id); + valid_spaces_set.add(space.space_id); // Check adjacency information - for (let adj_space_id of piece.adjacent) { - //console.log('adj_space_id', adj_space_id) + for (let adj_space_id of space.adjacent) { + console.log('adj_space_id', adj_space_id) if (adj_space_id) { - //console.log('checking adjacent space', spaces[adj_space_id].name_unique) - const adj_piece = game.pieces.find(p => p && p.space_id === adj_space_id); - //console.log('adjacent piece', adj_piece) - // Check if the adjacent space is controlled by the opponent - const opponent_control = game.active === COM ? adj_piece.demCtrl : adj_piece.comCtrl; - //console.log('controlled?', opponent_control) - //console.log('genscher?', game.persistent_events['genscher']) - //Check for Genscher. Can always place in East Germany even with 1 op + console.log('checking adjacent space', spaces[adj_space_id].name_unique) + const adj_piece = spaces[adj_space_id]; + console.log('adjacent piece', adj_piece) + + // Check if the adjacent space is controlled by the opponent + const opponent_control = check_opp_control(adj_piece.space_id) + console.log('controlled?', opponent_control) + console.log('genscher?', game.persistent_events['genscher']) + + //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['genscher']){ //console.log('space added with genscher') valid_spaces_set.add(adj_piece.space_id) @@ -2661,10 +2647,42 @@ function count_adj_worker(space_id) { } function check_control(space_id) { - if (game.active === COM && game.pieces[space_id].demCtrl === 1) { + console.log('in check control, space', spaces[space_id].name_unique) + if (game.active === COM && ((game.pieces[space_id].comInfl - game.pieces[space_id].demInfl) >= spaces[space_id].stability)) { return true; - } else if (game.active === DEM && game.pieces[space_id].comCtrl === 1) { + } else if (game.active === DEM && ((game.pieces[space_id].demInfl - game.pieces[space_id].comInfl) >= spaces[space_id].stability)) { + console.log('true') + return true; + } else { + console.log('false') + return false; + } +} + +function check_opp_control(space_id) { + console.log('in check control, space', spaces[space_id].name_unique) + if (game.active === DEM && ((game.pieces[space_id].comInfl - game.pieces[space_id].demInfl) >= spaces[space_id].stability)) { return true; + } else if (game.active === COM && ((game.pieces[space_id].demInfl - game.pieces[space_id].comInfl) >= spaces[space_id].stability)) { + console.log('true') + return true; + } else { + console.log('false') + return false; + } +} + +function check_dem_control(space_id) { + if ((game.pieces[space_id].demInfl - game.pieces[space_id].comInfl) >= spaces[space_id].stability) { + return true; + } else { + return false; + } +} + +function check_com_control(space_id) { + if ((game.pieces[space_id].comInfl - game.pieces[space_id].demInfl) >= spaces[space_id].stability) { + return true; } else { return false; } @@ -2753,26 +2771,26 @@ function check_presence(country) { let com_leaders = {1: false, 4: false, 5: false, 6: false, 7: false}; - for (let space of spaces) { - if (space && space.country === country) { - - let piece = game.pieces.find(p => p && p.space_id === space.space_id); + for (let i = 1; i < spaces.length; i++) { + let space = spaces[i] + let piece = game.pieces[i] + if (space.country === country) { - if (piece.demCtrl === 1) { + if (check_dem_control(i)) { dem_spaces++; if (space.battleground === 1) { dem_battlegrounds++; } - if ([1, 4, 5, 6, 7].includes(space.socio)) { + if (leaders.includes(space.socio)) { dem_leaders[space.socio] = true; } } - if (piece.comCtrl === 1) { + if (check_com_control(i)) { com_spaces++; if (space.battleground === 1) { com_battlegrounds++; } - if ([1, 4, 5, 6, 7].includes(space.socio)) { + if (leaders.includes(space.socio)) { com_leaders[space.socio] = true; } } @@ -2918,6 +2936,8 @@ function score_country(country) { if (presence.com_battlegrounds > 0) { log(`Battlegrounds: -${presence.com_battlegrounds} VP`) com_vp -= presence.com_battlegrounds + } else { + log('No battlegrounds') } log(`Total: ${com_vp} VP`) } else { @@ -2930,6 +2950,8 @@ function score_country(country) { if (presence.dem_battlegrounds > 0) { log(`Battlegrounds: +${presence.dem_battlegrounds} VP`) dem_vp += presence.dem_battlegrounds + } else { + log('No battlegrounds') } log(`Total: +${dem_vp} VP`) } else { @@ -3369,7 +3391,7 @@ function change_player() { } function find_space_index(name_unique) { - return game.pieces.findIndex(piece => piece && piece.name_unique === name_unique); + return spaces.findIndex(space => space && space.name_unique === name_unique) } function draw_deck(deck) { @@ -3551,7 +3573,7 @@ function reset_power() { } function check_control_change(space_id) { - game.pieces[space_id].demCtrl = 0 + /*game.pieces[space_id].demCtrl = 0 game.pieces[space_id].comCtrl = 0 if ((game.pieces[space_id].demInfl - game.pieces[space_id].comInfl) >= game.pieces[space_id].stability) { @@ -3559,10 +3581,10 @@ function check_control_change(space_id) { } if ((game.pieces[space_id].comInfl - game.pieces[space_id].demInfl) >= game.pieces[space_id].stability) { game.pieces[space_id].comCtrl = 1 - } + }*/ // Check if the Tyrant is Gone has been fulfilled - if (game.persistent_events['the_tyrant_is_gone'] > 0 && game.pieces[game.persistent_events['the_tyrant_is_gone']].demCtrl === 1) { + if (game.persistent_events['the_tyrant_is_gone'] > 0 && check_dem_control(game.persistent_events['the_tyrant_is_gone'])) { log('+2 VP from C97') game.vp += 2 game.persistent_events['the_tyrant_is_gone'] = 0 @@ -3955,35 +3977,32 @@ function vm_valid_spaces() { function vm_valid_spaces_opponent () { let valid_spaces = [] - if (game.active === DEM) { - for (let i = 1; i < game.pieces.length; i++) { - let gamePiece = game.pieces[i] - - if (gamePiece.comInfl > 0) { - valid_spaces.push(gamePiece.space_id) + for (let i = 1; i < game.pieces.length; i++) { + let piece = game.pieces[i] + let space = spaces[i] + + if (game.active === DEM) { + if (piece.comInfl > 0) { + valid_spaces.push(space.space_id) } - } - } else { - for (let i = 1; i < game.pieces.length; i++) { - let gamePiece = game.pieces[i] - - if (gamePiece.demInfl > 0) { - valid_spaces.push(gamePiece.space_id) + } else { + if (piece.demInfl > 0) { + valid_spaces.push(space.space_id) } } } game.valid_spaces = valid_spaces + console.log('game.valid_spaces', game.valid_spaces) vm_next() } function vm_valid_spaces_socio () { let valid_spaces = [] for (let i = 1; i < game.pieces.length; i++) { - let gamePiece = game.pieces[i] let space = spaces[i] if (space.socio === vm_operand(1)) { - valid_spaces.push(gamePiece.space_id) + valid_spaces.push(space.space_id) } } game.valid_spaces = valid_spaces @@ -3997,22 +4016,17 @@ function vm_valid_spaces_socio () { function vm_valid_spaces_opponent_socio () { let valid_spaces = [] - if (game.active === DEM) { - for (let i = 1; i < game.pieces.length; i++) { - let gamePiece = game.pieces[i] - let space = spaces[i] - - if (gamePiece.comInfl > 0 && space.socio === vm_operand(1)) { - valid_spaces.push(gamePiece.space_id) + for (let i = 1; i < game.pieces.length; i++) { + let piece = game.pieces[i] + let space = spaces[i] + + if (game.active === DEM) { + if (piece.comInfl > 0 && space.socio === vm_operand(1)) { + valid_spaces.push(space.space_id) } - } - } else { - for (let i = 1; i < game.pieces.length; i++) { - let gamePiece = game.pieces[i] - let space = spaces[i] - - if (gamePiece.demInfl > 0 && space.socio === vm_operand(1)) { - valid_spaces.push(gamePiece.space_id) + } else { + if (piece.demInfl > 0 && space.socio === vm_operand(1)) { + valid_spaces.push(space.space_id) } } } @@ -4141,9 +4155,9 @@ function vm_valid_spaces_region_opp() { function vm_valid_spaces_solidarity_legalised() { let valid_spaces = [] - for (let space of spaces) { - if (!space) continue - let uncontrolled = game.pieces[space.space_id].demCtrl === 0 && game.pieces[space.space_id].comCtrl === 0 + for (let i = 1; i < game.pieces.length; i++) { + let space = spaces[i] + let uncontrolled = (!check_control(i) && !check_opp_control(i)) if ((space.country === 'Poland' && uncontrolled && space.socio === 3) || (space.country === 'Poland' && uncontrolled && space.socio === 4)) { valid_spaces.push(space.space_id); } @@ -4811,11 +4825,10 @@ function vm_foreign_currency_debt_burden() { } function vm_foreign_television() { - for (let piece of game.pieces) { - if (!piece) continue - if (piece.space_id === 12) {continue} /*Does not apply to Dresden*/ + for (let i = 1 ; i < game.pieces.length; i++) { + if (i === 12) {continue} /*Does not apply to Dresden*/ if (piece.comInfl > 0 ) { - game.valid_spaces.push(piece.space_id) + game.valid_spaces.push(i) } } vm_next() @@ -4865,9 +4878,11 @@ function vm_goodbye_lenin() { } function vm_government_resigns() { - for (let space of game.pieces) { - if (space && spaces[space.space_id].socio === 1 && space.comInfl > 0 && space.comCtrl === 0 && space.demCtrl === 0) { - game.valid_spaces.push(space.space_id) + for (let i = 1; i < game.pieces.length; i++) { + let piece = game.pieces[i] + let space = spaces[i] + if (space.socio === 1 && piece.comInfl > 0 && !check_control(i)) { + game.valid_spaces.push(i) } } game.remove_opponent_infl = true @@ -4991,8 +5006,9 @@ function vm_legacy_of_martial_law() { } function vm_legacy_of_1968() { - for (let space of game.pieces) { - if (space && (space.comCtrl === 0 && spaces[space.space_id].country === 'Czechoslovakia')) { + for (let i = 1; i < game.pieces.length; i++) { + let space = spaces[i] + if ((!check_com_control(i) && space.country === 'Czechoslovakia')) { game.valid_spaces.push(space.space_id); } } @@ -5069,7 +5085,7 @@ function vm_perestroika() { function vm_poszgay() { let valid_spaces = [] for (let space of spaces) { - if (space && space.country === 'Hungary' && game.pieces[space.space_id].demCtrl === 0) { + if (space && space.country === 'Hungary' && !check_dem_control(space.space_id)) { valid_spaces.push(space.space_id); } } @@ -5282,8 +5298,10 @@ function vm_the_third_way() { function vm_the_tyrant_is_gone() { game.valid_spaces = [] - for (let space of game.pieces) { - if (space && space.demInfl === 0 && spaces[space.space_id].country === 'Romania') { + for (let i = 1; i < game.pieces.length; i++) { + let piece = game.pieces[i] + let space = spaces[i] + if (piece.demInfl === 0 && space.country === 'Romania') { if (space.space_id === game.persistent_events['systematization']) {continue} game.valid_spaces.push(space.space_id) } @@ -5432,10 +5450,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) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ gen_action_infl(spaces[space_id].name_unique); - //} } } else { view.prompt = `${clean_name(cards[this_card()].name)}. Take control: done.` @@ -5464,10 +5479,7 @@ states.vm_add_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: add ${game.vm_available_ops} influence${event_prompt()}.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ - gen_action_infl(spaces[space_id].name_unique); - //} + gen_action_infl(spaces[space_id].name_unique) } } else { view.prompt = 'Add influence: done.' @@ -5496,10 +5508,7 @@ states.vm_add_infl_free = { view.prompt = `${clean_name(cards[this_card()].name)}: add ${game.vm_available_ops} influence to ${event_prompt()}.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ gen_action_infl(spaces[space_id].name_unique); - //} } } /* else { view.prompt = 'Add influence: done.' @@ -5530,10 +5539,7 @@ states.vm_add_x_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: Add ${game.vm_available_ops} influence to ${event_prompt()}.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ - gen_action_infl(spaces[space_id].name_unique); - //} + gen_action_infl(spaces[space_id].name_unique) } } /*else { view.prompt = 'Add influence: done.' @@ -5564,10 +5570,7 @@ states.vm_add_limited_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: add ${game.vm_available_ops} influence to ${event_prompt()}.` } for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) { */ gen_action_infl(spaces[space_id].name_unique); - //} } } /*else { view.prompt = `${clean_name(cards[this_card()].name)}: done.` @@ -5603,10 +5606,7 @@ states.vm_remove_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: remove ${game.vm_available_ops} SP${event_prompt()}.` } for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) { */ gen_action_infl(spaces[space_id].name_unique); - //} } }, infl(space) { @@ -5637,10 +5637,7 @@ states.vm_remove_x_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: remove ${game.vm_available_ops} SP from ${event_prompt()}.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) { */ gen_action_infl(spaces[space_id].name_unique); - //} } } /*else { view.prompt = 'Remove influence: done.' @@ -5665,10 +5662,7 @@ states.vm_remove_limited_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: remove ${game.vm_available_ops} SP${event_prompt()}, no more than ${game.vm_max_infl} per space.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) { */ gen_action_infl(spaces[space_id].name_unique); - //} } } else if (game.valid_spaces.length === 0) { view.prompt = `${clean_name(cards[this_card()].name)}: no further SP to remove.` @@ -5699,10 +5693,7 @@ states.vm_remove_all_infl = { view.prompt = `${clean_name(cards[this_card()].name)}: remove all SPs from ${event_prompt()}.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ gen_action_infl(spaces[space_id].name_unique); - // } } }, infl(space) { @@ -5865,7 +5856,7 @@ states.vm_adamec = { clear_undo() let roll = Math.floor(Math.random() * 6) + 1 log(`Rolled a ${roll}`) - let worker_spaces = spaces.filter(space => space && space.country === 'Czechoslovakia' && space.socio === 4 && game.pieces[space.space_id].demCtrl === 1).length + let worker_spaces = spaces.filter(space => space && space.country === 'Czechoslovakia' && space.socio === 4 && check_dem_control(space.space_id)).length if (worker_spaces > 0) { log(`-${worker_spaces} from Democrat controlled worker spaces`) roll -= worker_spaces @@ -6624,10 +6615,7 @@ states.vm_switch_infl = { /*if (game.vm_available_ops > 0 ) {*/ view.prompt = `${clean_name(cards[game.played_card].name)}: ${event_prompt()}.` for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) { */ gen_action_infl(spaces[space_id].name_unique); - //} } } /*else { view.prompt = 'Influence replaced.' @@ -6710,7 +6698,7 @@ states.vm_modrow = { roll(){ clear_undo() let roll = Math.floor(Math.random() * 6) + 1 - let dem_spaces = spaces.filter(space => space && space.country === 'East_Germany' && game.pieces[space.space_id].demCtrl === 1).length + let dem_spaces = spaces.filter(space => space && space.country === 'East_Germany' && check_dem_control(space.space_id)).length if (roll > dem_spaces) { log(`Rolled a ${roll}: success`) vm_next() @@ -6808,7 +6796,7 @@ states.vm_nomenklatura = { let space = spaces[i] if (space.socio === 1 && piece.demInfl > 0) { - game.valid_spaces.push(piece.space_id) + game.valid_spaces.push(space.space_id) } } game.vm_available_ops = game.valid_spaces.length @@ -6841,7 +6829,6 @@ states.vm_nomenklatura_remove = { view.prompt = 'Nomenklatura: remove all Democratic influence from Elite spaces.' for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); */ gen_action_infl(spaces[space_id].name_unique); } } @@ -6986,15 +6973,16 @@ states.vm_shock_therapy = { roll() { clear_undo() let roll = Math.floor(Math.random() * 6) + 1 - for (let space of game.pieces) { - if (space && spaces[space.space_id].country === game.vm_active_country && space.comCtrl === 1 && (spaces[space.space_id].socio === 3 || spaces[space.space_id].socio === 4)) { - game.temp++ + let worker_farmer = 0 + for (let space of spaces) { + if (space && space.country === game.vm_active_country && check_com_control(space.space_id) && (space.socio === 3 || space.socio === 4)) { + worker_farmer++ } } log(`Rolled a ${roll}`) - log(`-${game.temp} from Communist controlled Worker and Farmer spaces`) - log(`Modified roll: ${roll - game.temp}`) - if ((roll - game.temp) > 2) { + log(`-${worker_farmer} from Communist controlled Worker and Farmer spaces`) + log(`Modified roll: ${roll - worker_farmer}`) + if ((roll - worker_farmer) > 2) { log('C93 is successful. +3 VP') vm_next() } else { @@ -7218,7 +7206,7 @@ states.vm_the_wall_must_go = { let roll = Math.floor(Math.random() * 6) + 1 log(`Rolled a ${roll}`) if (game.active === DEM) { - let controlled_spaces = spaces.filter(space => space && space.country === 'East_Germany' && game.pieces[space.space_id].demCtrl === 1).length + let controlled_spaces = spaces.filter(space => space && space.country === 'East_Germany' && check_dem_control(space.space_id)).length if (controlled_spaces > 0) { log(`+${controlled_spaces} from controlled spaces in East Germany`) log(`Modified roll: ${roll + controlled_spaces}`) @@ -7226,7 +7214,7 @@ states.vm_the_wall_must_go = { } game.the_wall_must_go['dem_roll'] = roll } else { - let controlled_spaces = spaces.filter(space => space && space.country === 'East_Germany' && game.pieces[space.space_id].comCtrl === 1).length + let controlled_spaces = spaces.filter(space => space && space.country === 'East_Germany' && check_com_control(space.space_id)).length if (controlled_spaces > 0) { log(`+${controlled_spaces} from controlled spaces in East Germany`) log(`Modified roll: ${roll + controlled_spaces}`) @@ -7271,9 +7259,10 @@ states.vm_the_wall_must_go = { if (check_vp()) { return } - for (let space of game.pieces) { - if (space) {console.log('space.space_id', space.space_id)} - if (space && spaces[space.space_id].country === 'East_Germany' && space.comInfl > 0){ + for (let i = 1; i < game.pieces.length; i++) { + let piece = game.pieces[i] + let space = spaces[i] + if (space.country === 'East_Germany' && piece.comInfl > 0){ game.valid_spaces.push(space.space_id) } } @@ -7297,8 +7286,10 @@ states.vm_warsaw_pact_summit = { }, influence(){ push_undo() - for (let space of game.pieces) { - if (space && space.demInfl === 0) { + for (let i = 1; i < game.pieces.length; i++) { + let piece = game.pieces[i] + let space = spaces[i] + if (piece.demInfl === 0) { game.valid_spaces.push(space.space_id); } } @@ -7310,10 +7301,10 @@ states.vm_warsaw_pact_summit = { support_check(){ push_undo() for (let i = 1; i < game.pieces.length; i++) { - let gamePiece = game.pieces[i] + let piece = game.pieces[i] let space = spaces[i] - if (gamePiece.demInfl > 0 && (space.socio === 5 || space.socio === 6)) { - game.valid_spaces.push(gamePiece.space_id) + if (piece.demInfl > 0 && (space.socio === 5 || space.socio === 6)) { + game.valid_spaces.push(space.space_id) } } game.vm_available_ops = 2 @@ -7369,7 +7360,6 @@ states.vm_we_are_the_people_add = { view.prompt = `"We are the People!": you must add the ${game.vm_influence_added[6]} influence to spaces in Germany.` gen_action('done') for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id);*/ gen_action_infl(spaces[space_id].name_unique); } }, @@ -7391,10 +7381,7 @@ states.vm_workers_revolt = { prompt() { view.prompt = 'Workers Revolt: select a Worker Space in a country your opponent has power.' for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ - gen_action_infl(spaces[space_id].name_unique); - //} + gen_action_infl(spaces[space_id].name_unique) } }, infl(space) { @@ -7502,10 +7489,7 @@ states.vm_tst_4 = { view.prompt = 'Tiananmen Square Track award: select a space to remove influence' for (let space_id of game.valid_spaces) { - /*const space = spaces.find(s => s && s.space_id === space_id); - if (space) {*/ gen_action_infl(spaces[space_id].name_unique); - // } } }, infl(space) { @@ -7546,32 +7530,6 @@ states.vm_tst_6 = { } } -/* states.vm_tst_6_prep = { - inactive: 'make their free support check.', - prompt () { - if (game.vm_available_ops === 0) { - view.prompt = 'Tiananmen Square Track award support check: done' - gen_action('done') - return - } else { - view.prompt = `Select a space for the support check.` - for (let space_id of game.valid_spaces) { - if (space_id) { - gen_action_sc(spaces[space_id].name_unique); - } - } - } - }, - sc(space) { - push_undo() - game.selected_space = find_space_index(space) - game.state = 'vm_tst_6_sc' - }, - done () { - vm_next() - } -} */ - states.vm_tst_6_sc = { inactive: 'do support check.', prompt () { -- cgit v1.2.3