diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 142 |
1 files changed, 117 insertions, 25 deletions
@@ -22,7 +22,7 @@ const player_faction_map = { const front_names = { a: 'Aragon Front', m: 'Madrid Front', - n: 'Nothern Front', + n: 'Northern Front', s: 'Southern Front', d: 'the Front closest to Defeat', v: 'the Front closest to Victory', @@ -340,17 +340,21 @@ function setup(seed, _scenario, _options) { start_year(); return game; } -function draw_hand_cards() { - role_ids.forEach((role) => { - const deck = list_deck(role); - for (let i = 0; i < 5; i++) { - game.hands[role].push(draw_card(deck)); - } - }); +function draw_hand_cards(faction_id, count) { + const log = count === 1 + ? `${get_player(faction_id)} draws 1 card` + : `${get_player(faction_id)} draws ${count} cards`; + logi(log); + for (let i = 0; i < count; i++) { + const deck = list_deck(faction_id); + game.hands[faction_id].push(draw_card(deck)); + } } function start_year() { game.current_events = []; - draw_hand_cards(); + role_ids.forEach((role) => { + draw_hand_cards(role, 5); + }); start_turn(); } function start_turn() { @@ -377,6 +381,10 @@ states.activate_icon = { } }, add_to_front() { + insert_after_active_node(create_leaf_node('add_to_front', get_active_faction(), { + t: data_1.ANY, + v: get_icon_count_in_tableau('add_to_front'), + })); resolve_active_and_proceed(); }, collectivization() { @@ -404,6 +412,7 @@ states.activate_icon = { resolve_active_and_proceed(); }, draw_card() { + draw_hand_cards(get_active_faction(), get_icon_count_in_tableau('draw_card')); resolve_active_and_proceed(); }, foreign_aid() { @@ -411,10 +420,15 @@ states.activate_icon = { resolve_active_and_proceed(); }, government() { - move_track(data_1.GOVERNMENT, get_icon_count_in_tableau('government')); + const direction = game.active === data_1.COMMUNIST ? -1 : 1; + move_track(data_1.GOVERNMENT, direction * get_icon_count_in_tableau('government')); + resolve_active_and_proceed(); + }, + government_to_center() { + const direction = game.tracks[data_1.GOVERNMENT] >= 6 ? -1 : 1; + move_track(data_1.GOVERNMENT, direction * get_icon_count_in_tableau('government_to_center')); resolve_active_and_proceed(); }, - government_to_center() { }, liberty() { move_track(data_1.LIBERTY, get_icon_count_in_tableau('liberty')); resolve_active_and_proceed(); @@ -465,7 +479,7 @@ states.add_to_front = { }, front(f) { const value = get_active_node_args().v; - update_front(f, value); + update_front(f, value, get_active_faction()); resolve_active_and_proceed(); }, }; @@ -474,7 +488,6 @@ states.attack_front = { prompt() { const node = get_active_node(); const front = node.a.t; - view.prompt = 'Attack ' + front_names[front]; let targets = []; if (front === 'd' || front === 'v') { targets = get_fronts_closest_to(front); @@ -488,6 +501,10 @@ states.attack_front = { else { targets.push(front); } + view.prompt = + targets.length === 1 + ? `Attack ${front_names[targets[0]]}` + : 'Attack a front'; targets.forEach((id) => gen_action('front', id)); }, front(f) { @@ -524,7 +541,6 @@ states.choose_area_ap = { resolve_active_and_proceed(); }, standee(track_id) { - console.log('standee', track_id); insert_after_active_node({ t: leaf_node, p: get_active_faction_id(), @@ -718,11 +734,8 @@ states.player_turn = { resolve_active_and_proceed(); }, spend_hp() { - insert_before_active_node({ - t: leaf_node, - p: get_faction_id(game.active), - s: 'spend_hero_points', - }); + insert_before_active_node(create_leaf_node('spend_hero_points', get_active_faction())); + log('Spends Hero Points'); next(); }, }; @@ -731,17 +744,61 @@ states.spend_hero_points = { prompt() { view.prompt = 'Spend your Hero points'; gen_action('done'); + const hero_points = game.hero_points[get_active_faction()]; + if (hero_points === 0) { + return; + } gen_action('draw_card'); + if (hero_points < 2) { + return; + } + gen_action_standee(data_1.FOREIGN_AID); + gen_action_standee(data_1.SOVIET_SUPPORT); + for (const bonus of bonuses) { + if (game.bonuses[bonus] === data_1.OFF) { + gen_action_bonus(bonus); + } + } + if (hero_points < 3) { + return; + } + gen_action_standee(data_1.COLLECTIVIZATION); + gen_action_standee(data_1.LIBERTY); + if (hero_points < 4) { + return; + } + gen_action_standee(data_1.GOVERNMENT); }, done() { resolve_active_and_proceed(); }, + bonus(b) { + update_bonus(b, data_1.ON); + pay_hero_points(get_active_faction(), 2); + }, draw_card() { - game.hero_points[get_active_faction_id()]--; - log(`${game.active} draws a card`); - if (game.hero_points[get_active_faction_id()] === 0) { - resolve_active_and_proceed(); + const faction = get_active_faction(); + pay_hero_points(faction, 1); + draw_hand_cards(faction, 1); + }, + standee(track_id) { + let amount = 2; + if (track_id === data_1.LIBERTY || track_id === data_1.COLLECTIVIZATION) { + amount = 3; } + else if (track_id === data_1.GOVERNMENT) { + amount = 4; + } + const faction = get_active_faction(); + pay_hero_points(faction, amount); + insert_after_active_node(create_seq_node([ + create_leaf_node('move_track_up_or_down', faction, { + track_id, + strength: 1, + }), + create_leaf_node('spend_hero_points', faction), + ])); + resolve_active_and_proceed(); }, }; function pop_undo() { @@ -851,11 +908,36 @@ function get_fronts_to_add_to(target) { return [target]; } } +function get_max_value_for_track(track_id) { + switch (track_id) { + case data_1.LIBERTY: + return game.tracks[data_1.COLLECTIVIZATION] >= 8 ? 10 : 7; + case data_1.GOVERNMENT: + return game.tracks[data_1.FOREIGN_AID] >= 8 ? 10 : 7; + case data_1.COLLECTIVIZATION: + case data_1.SOVIET_SUPPORT: + case data_1.FOREIGN_AID: + default: + return 10; + } +} +function get_min_value_for_track(track_id) { + switch (track_id) { + case data_1.GOVERNMENT: + return game.tracks[data_1.SOVIET_SUPPORT] >= 8 ? 4 : 1; + case data_1.LIBERTY: + case data_1.COLLECTIVIZATION: + case data_1.SOVIET_SUPPORT: + case data_1.FOREIGN_AID: + default: + return 0; + } +} function move_track(track_id, change) { const current_value = game.tracks[track_id]; let new_value = current_value + change; - new_value = Math.max(new_value, track_id === data_1.GOVERNMENT ? 1 : 0); - new_value = Math.min(new_value, 10); + new_value = Math.max(new_value, get_min_value_for_track(track_id)); + new_value = Math.min(new_value, get_max_value_for_track(track_id)); game.tracks[track_id] = new_value; logi(`${get_track_name(track_id)} to ${new_value}`); check_initiative(); @@ -876,6 +958,10 @@ function move_track(track_id, change) { } }); } +function pay_hero_points(faction, amount) { + game.hero_points[faction] -= amount; + game.hero_points.pool += amount; +} function update_bonus(bonus_id, status) { if (game.bonuses[bonus_id] === status) { return; @@ -893,9 +979,15 @@ function update_front(front_id, change, faction_id = null) { game.fronts[front_id].contributions.length > 0) { change += 1; } + const value_before = game.fronts[front_id].value; game.fronts[front_id].value += change; logi(`${front_names[front_id]}: ${change > 0 ? '+' : ''}${change}`); if (faction_id !== null && + value_before <= 0 && + game.fronts[front_id].value > 0) { + gain_hero_points(faction_id, 1); + } + if (faction_id !== null && !game.fronts[front_id].contributions.includes(faction_id)) { game.fronts[front_id].contributions.push(faction_id); } |