summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js131
1 files changed, 108 insertions, 23 deletions
diff --git a/rules.js b/rules.js
index f9cd8e8..667c7a0 100644
--- a/rules.js
+++ b/rules.js
@@ -189,9 +189,7 @@ function insert_before_active_node(node, engine = game.engine) {
insert_before_or_after_active_node(node, 'before', engine);
}
function next() {
- console.log('next');
const node = get_active_node(game.engine);
- console.log('node', node);
if (node.t === function_node && engine_functions[node.f]) {
const args = node.a;
if (args) {
@@ -241,7 +239,10 @@ function game_view(state, player) {
triggered_track_effects: game.triggered_track_effects,
year: game.year,
};
- if (player !== game.active) {
+ if (game.state === 'game_over') {
+ view.prompt = game.victory;
+ }
+ else if (player !== game.active) {
let inactive = states[game.state].inactive || game.state;
view.prompt = `Waiting for ${game.active} to ${inactive}.`;
}
@@ -275,18 +276,22 @@ function setup(seed, _scenario, _options) {
a: {
value: -2,
contributions: [],
+ status: null,
},
m: {
value: -2,
contributions: [],
+ status: null,
},
n: {
value: -2,
contributions: [],
+ status: null,
},
s: {
value: -2,
contributions: [],
+ status: null,
},
},
glory: [],
@@ -470,13 +475,20 @@ states.attack_front = {
const node = get_active_node();
const front = node.a.t;
view.prompt = 'Attack ' + front_names[front];
+ let targets = [];
if (front === 'd' || front === 'v') {
- const fronts = get_fronts_closest_to(front);
- fronts.forEach((id) => gen_action('front', id));
+ targets = get_fronts_closest_to(front);
+ }
+ else if (game.fronts[front].status === data_1.DEFEAT) {
+ targets = get_fronts_closest_to('d');
+ }
+ else if (game.fronts[front].status === data_1.VICTORY) {
+ targets = get_fronts_to_add_to(data_1.ANY);
}
else {
- gen_action_front(front);
+ targets.push(front);
}
+ targets.forEach((id) => gen_action('front', id));
},
front(f) {
const node = get_active_node();
@@ -579,13 +591,18 @@ states.gain_hero_points = {
},
gain_hp() {
const value = get_active_node_args().v;
- if (game.hero_points.pool > value) {
- game.hero_points.pool -= value;
- game.hero_points[get_active_faction()] += value;
- }
+ gain_hero_points(get_active_faction(), value);
resolve_active_and_proceed();
},
};
+states.game_over = {
+ get inactive() {
+ return game.victory;
+ },
+ prompt() {
+ view.prompt = game.victory;
+ },
+};
states.lose_hero_points = {
inactive: 'choose a Player',
prompt() {
@@ -780,11 +797,35 @@ function end_of_year() {
game.year++;
start_year();
}
+function gain_hero_points_in_player_order(factions, value) {
+ for (const f of get_player_order()) {
+ if (factions.includes(f)) {
+ gain_hero_points(f, value);
+ }
+ }
+}
+function gain_hero_points(faction_id, value) {
+ if (game.hero_points.pool === 0) {
+ return;
+ }
+ const gain = Math.min(game.hero_points.pool, value);
+ game.hero_points.pool -= gain;
+ game.hero_points[faction_id] += gain;
+ logi(`${get_player(faction_id)} +${gain} ${gain === 1 ? 'Hero Point' : 'Hero Points'}`);
+}
+function game_over(result, victory) {
+ insert_after_active_node(create_leaf_node('game_over', 'None'));
+ game.result = result;
+ game.victory = victory;
+ log_br();
+ log(game.victory);
+}
function resolve_fascist_test() {
- console.log('resolve fascist test');
log_h2('Fascist Test', 'fascist');
const test = get_current_event().test;
- const test_passed = game.fronts[test.front].value >= test.value;
+ const status = game.fronts[test.front].status;
+ const test_passed = status === data_1.VICTORY ||
+ (status !== data_1.DEFEAT && game.fronts[test.front].value >= test.value);
if (test_passed) {
log('The Test is passed');
}
@@ -804,7 +845,7 @@ function get_fronts_to_add_to(target) {
return get_fronts_closest_to(target);
}
else if (target === data_1.ANY) {
- return ['a', 'm', 'n', 's'];
+ return data_1.FRONTS.filter((id) => game.fronts[id].status === null);
}
else {
return [target];
@@ -842,21 +883,47 @@ function update_bonus(bonus_id, status) {
game.bonuses[bonus_id] = status;
logi(`${bonus_names[bonus_id]} ${status === data_1.ON ? 'on' : 'off'}`);
}
-function update_front(f, change, faction_id = null) {
- const player_token_on_front = faction_id !== null && game.fronts[f].contributions.includes(faction_id);
+function update_front(front_id, change, faction_id = null) {
+ const player_token_on_front = faction_id !== null &&
+ game.fronts[front_id].contributions.includes(faction_id);
if (game.bonuses[data_1.TEAMWORK_BONUS] === data_1.ON &&
change > 0 &&
faction_id !== null &&
!player_token_on_front &&
- game.fronts[f].contributions.length > 0) {
+ game.fronts[front_id].contributions.length > 0) {
change += 1;
}
- game.fronts[f].value += change;
- logi(`${front_names[f]}: ${change > 0 ? '+' : ''}${change}`);
+ game.fronts[front_id].value += change;
+ logi(`${front_names[front_id]}: ${change > 0 ? '+' : ''}${change}`);
if (faction_id !== null &&
- !game.fronts[f].contributions.includes(faction_id)) {
- game.fronts[f].contributions.push(faction_id);
+ !game.fronts[front_id].contributions.includes(faction_id)) {
+ game.fronts[front_id].contributions.push(faction_id);
}
+ if (game.fronts[front_id].value >= 10) {
+ victory_on_a_front(front_id);
+ }
+ else if (game.fronts[front_id].value <= -10) {
+ defeat_on_a_front(front_id);
+ }
+}
+function defeat_on_a_front(front_id) {
+ game.fronts[front_id].status = data_1.DEFEAT;
+ log('Defeat on ' + get_front_name(front_id));
+ if (front_id === 'm' || get_defeated_front_count() == 2) {
+ game_over('None', 'All players lose the game!');
+ return;
+ }
+ insert_after_active_node(create_effects_node([
+ (0, data_1.create_effect)('bonus', data_1.MORALE_BONUS, data_1.OFF),
+ (0, data_1.create_effect)('track', data_1.COLLECTIVIZATION, -1),
+ (0, data_1.create_effect)('track', data_1.SOVIET_SUPPORT, -1),
+ (0, data_1.create_effect)('track', data_1.FOREIGN_AID, -1),
+ ]));
+}
+function victory_on_a_front(front_id) {
+ game.fronts[front_id].status = data_1.VICTORY;
+ log('Victory on ' + get_front_name(front_id));
+ gain_hero_points_in_player_order(game.fronts[front_id].contributions, 3);
}
function create_effects_node(effects) {
const nodes = effects.reduce((accrued, current) => {
@@ -923,7 +990,12 @@ function lose_hero_point(faction, value) {
}
}
function get_fronts_closest_to(target) {
- const values = Object.values(game.fronts).map((front) => front.value);
+ const values = Object.values(game.fronts).reduce((accrued, current) => {
+ if (current.status === null) {
+ accrued.push(current.value);
+ }
+ return accrued;
+ }, []);
const targetValue = target === 'd' ? Math.min(...values) : Math.max(...values);
return Object.keys(game.fronts).filter((frontId) => game.fronts[frontId].value === targetValue);
}
@@ -966,9 +1038,21 @@ function get_active_faction_id() {
function get_faction_id(player) {
return player_faction_map[player];
}
+function get_front_name(id) {
+ return front_names[id];
+}
function get_current_event() {
return cards[game.current_events[game.current_events.length - 1]];
}
+function get_defeated_front_count() {
+ let count = 0;
+ for (const front_id of data_1.FRONTS) {
+ if (game.fronts[front_id].status === data_1.DEFEAT) {
+ count++;
+ }
+ }
+ return count;
+}
function get_icon_count_in_tableau(icon, faction = get_active_faction_id()) {
let count = 0;
for (const c of game.tableaus[faction]) {
@@ -1059,10 +1143,11 @@ function list_deck(id) {
const deck = [];
const card_list = id === 'fascist' ? fascist_decks[game.year] : faction_cards[id];
card_list.forEach((card) => {
- if (id === 'fascist' && (game.discard.f.includes(card))) {
+ if (id === 'fascist' && game.discard.f.includes(card)) {
return;
}
- else if (id !== 'fascist' && (game.hands[id].includes(card) || game.discard[id].includes(card))) {
+ else if (id !== 'fascist' &&
+ (game.hands[id].includes(card) || game.discard[id].includes(card))) {
return;
}
deck.push(card);