summaryrefslogtreecommitdiff
path: root/rules.ts
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@franss-mbp.home>2024-12-15 16:02:52 +0100
committerFrans Bongers <fransbongers@franss-mbp.home>2024-12-15 16:02:52 +0100
commit47b19b5e83850b5fac6e508468b227476d486025 (patch)
tree6a9e5acd80060bfa410a62bbb514fa94343446a3 /rules.ts
parent7517f0e485f63c6c97ee2871ca64373375c504b8 (diff)
downloadland-and-freedom-47b19b5e83850b5fac6e508468b227476d486025.tar.gz
add tokens to fronts and log improvements
Diffstat (limited to 'rules.ts')
-rw-r--r--rules.ts173
1 files changed, 136 insertions, 37 deletions
diff --git a/rules.ts b/rules.ts
index ee9b269..c6f01ab 100644
--- a/rules.ts
+++ b/rules.ts
@@ -214,23 +214,33 @@ function setup_bag_of_glory() {
}
function setup_choose_card() {
- console.log('setup_choose_card');
const player_order = get_player_order();
game.engine = player_order.map((faction_id) =>
create_leaf_node('choose_card', faction_id)
);
game.engine.push(create_function_node('setup_player_turn'));
- resolve_active_and_proceed();
+ next();
}
function setup_player_turn() {
- console.log('setup_player_turn');
const player_order = get_player_order();
game.engine = player_order.map((faction_id) =>
- create_seq_node([create_leaf_node('player_turn', faction_id)])
+ create_seq_node([
+ create_function_node('start_of_player_turn', { f: faction_id }),
+ create_leaf_node('player_turn', faction_id),
+ ])
);
game.engine.push(create_function_node('resolve_fascist_test'));
game.engine.push(create_function_node('setup_bag_of_glory'));
+ next();
+}
+
+function start_of_player_turn() {
+ const args = get_active_node_args();
+ console.log('args', args);
+ console.log('args');
+ const player = faction_player_map[args.f];
+ log_h2(player, player);
resolve_active_and_proceed();
}
@@ -241,6 +251,7 @@ const engine_functions: Record<string, Function> = {
setup_bag_of_glory,
setup_choose_card,
setup_player_turn,
+ start_of_player_turn,
resolve_fascist_test,
};
@@ -300,7 +311,7 @@ function get_active_node(
function get_active_node_args(): any {
const node = get_active_node(game.engine);
- if (node.t === leaf_node) {
+ if (node.t === leaf_node || node.t === function_node) {
return node.a;
}
return null;
@@ -390,11 +401,13 @@ function game_view(state: Game, player: Player) {
glory: game.glory,
hand: game.hands[faction_id],
hero_points: game.hero_points,
+ initiative: game.initiative,
medaillons: game.medaillons,
selected_card: game.chosen_cards[faction_id],
tableaus: game.tableaus,
tracks: game.tracks,
triggered_track_effects: game.triggered_track_effects,
+ year: game.year,
};
if (player !== game.active) {
@@ -432,10 +445,22 @@ export function setup(seed: number, _scenario: string, _options: unknown) {
},
engine: [],
fronts: {
- a: -2,
- m: -2,
- n: -2,
- s: -2,
+ a: {
+ value: -2,
+ contributions: [],
+ },
+ m: {
+ value: -2,
+ contributions: [],
+ },
+ n: {
+ value: -2,
+ contributions: [],
+ },
+ s: {
+ value: -2,
+ contributions: [],
+ },
},
glory: [],
hands: {
@@ -487,9 +512,8 @@ export function setup(seed: number, _scenario: string, _options: unknown) {
function draw_hand_cards() {
role_ids.forEach((role) => {
- const deck = faction_cards[role];
+ const deck = list_deck(role);
for (let i = 0; i < 5; i++) {
- game.hands[role];
game.hands[role].push(draw_card(deck));
}
});
@@ -498,22 +522,21 @@ function draw_hand_cards() {
// #endregion
function start_year() {
- console.log('start year')
- log_h1('Year ' + game.year);
+ // log_h1('Year ' + game.year);
game.current_events = [];
draw_hand_cards();
start_turn();
}
function start_turn() {
- log_h2('Turn ' + game.turn);
+ log_h1(`Year ${game.year} - Turn ${game.turn}`);
- const deck = fascist_decks[game.year];
- const cardId = draw_card(deck);
+ const cardId = draw_card(list_deck('fascist'));
game.current_events.push(cardId);
const card = cards[cardId] as EventCard;
- log_h3('Fascist Event: ' + card.title);
+ log_h2('Fascist Event', 'fascist');
+ log(card.title);
game.engine = card.effects.map((effect) =>
resolve_effect(effect, game.initiative)
@@ -676,10 +699,20 @@ states.choose_area_ap = {
for (const front of fronts) {
gen_action_front(front);
}
+ for (const bonus of bonuses) {
+ if (game.bonuses[bonus] === OFF) {
+ gen_action_bonus(bonus);
+ }
+ }
+ },
+ bonus(b: number) {
+ update_bonus(b, ON);
+ // TODO: insert action in case other bonus is OFF and AP left
+ resolve_active_and_proceed();
},
front(f: string) {
- const s = get_active_node_args().strength;
- update_front(f, s);
+ const s: number = get_active_node_args().strength;
+ update_front(f, s, get_active_faction_id());
resolve_active_and_proceed();
},
standee(track_id: number) {
@@ -723,8 +756,7 @@ states.change_bonus = {
},
bonus(b: number) {
const value = get_active_node_args().v;
- game.bonuses[b] = value;
- log(`${bonus_names[b]} ${value === ON ? 'on' : 'off'}`);
+ update_bonus(b, value);
resolve_active_and_proceed();
},
skip() {
@@ -1009,9 +1041,28 @@ function check_activate_icon() {
resolve_active_and_proceed();
}
+function check_initiative() {
+ let initiative: FactionId;
+ if (game.tracks[LIBERTY] >= 6 && game.tracks[COLLECTIVIZATION] >= 6) {
+ initiative = ANARCHISTS_ID;
+ } else if (game.tracks[GOVERNMENT] <= 5) {
+ initiative = COMMUNISTS_ID;
+ } else {
+ initiative = MODERATES_ID;
+ }
+
+ if (game.initiative === initiative) {
+ return;
+ }
+ game.initiative = initiative;
+ logi(`${faction_player_map[initiative]} claims the Initiative`);
+}
+
function end_of_turn() {
- // REMOVE player tokens from the Fronts;
- log_h2('End of turn');
+ Object.keys(game.fronts).forEach((front_id) => {
+ game.fronts[front_id].contributions = [];
+ });
+ // log_h2('End of turn');
if (game.turn === 4) {
end_of_year();
} else {
@@ -1034,10 +1085,10 @@ function end_of_year() {
function resolve_fascist_test() {
console.log('resolve fascist test');
- log_h2('Fascist test is resolved');
+ log_h2('Fascist Test', 'fascist');
const test = get_current_event().test;
- const test_passed = game.fronts[test.front] >= test.value;
+ const test_passed = game.fronts[test.front].value >= test.value;
if (test_passed) {
log('The Test is passed');
} else {
@@ -1075,7 +1126,10 @@ function move_track(track_id: number, change: number) {
new_value = Math.max(new_value, track_id === GOVERNMENT ? 1 : 0);
new_value = Math.min(new_value, 10);
game.tracks[track_id] = new_value;
- log(`${get_track_name(track_id)} to ${new_value}`);
+ logi(`${get_track_name(track_id)} to ${new_value}`);
+
+ check_initiative();
+
const triggered_spaces =
change > 0
? make_list(current_value + 1, new_value).reverse()
@@ -1098,10 +1152,39 @@ function move_track(track_id: number, change: number) {
});
}
+function update_bonus(bonus_id: number, status: number) {
+ if (game.bonuses[bonus_id] === status) {
+ return;
+ }
+ game.bonuses[bonus_id] = status;
+ logi(`${bonus_names[bonus_id]} ${status === ON ? 'on' : 'off'}`);
+}
+
// TODO: acccount for victory / defeat of front
-function update_front(f: string, change: number) {
- game.fronts[f] += change;
- log(`${front_names[f]}: ${change > 0 ? '+' : ''}${change}`);
+function update_front(
+ f: string,
+ change: number,
+ faction_id: FactionId | null = null
+) {
+ const player_token_on_front =
+ faction_id !== null && game.fronts[f].contributions.includes(faction_id);
+ if (
+ game.bonuses[TEAMWORK_BONUS] === ON &&
+ change > 0 &&
+ faction_id !== null &&
+ !player_token_on_front &&
+ game.fronts[f].contributions.length > 0
+ ) {
+ change += 1;
+ }
+ game.fronts[f].value += change;
+ logi(`${front_names[f]}: ${change > 0 ? '+' : ''}${change}`);
+ if (
+ faction_id !== null &&
+ !game.fronts[f].contributions.includes(faction_id)
+ ) {
+ game.fronts[f].contributions.push(faction_id);
+ }
}
function create_effects_node(effects: Effect[]): EngineNode {
@@ -1276,11 +1359,11 @@ function lose_hero_point(faction: FactionId, value: number) {
// #region FRONTS
function get_fronts_closest_to(target: 'd' | 'v') {
- const values = Object.values(game.fronts);
+ const values = Object.values(game.fronts).map((front) => front.value);
const targetValue =
target === 'd' ? Math.min(...values) : Math.max(...values);
return Object.keys(game.fronts).filter(
- (frontId) => game.fronts[frontId] === targetValue
+ (frontId) => game.fronts[frontId].value === targetValue
);
}
@@ -1305,12 +1388,12 @@ function log(msg: string) {
// game.log.push(`C${cap}.`)
// }
-// function logi(msg: string) {
-// game.log.push('>' + msg);
-// }
+function logi(msg: string) {
+ log('>' + msg);
+}
// function logii(msg: string) {
-// game.log.push('>>' + msg);
+// log('>>' + msg);
// }
function log_h1(msg: string) {
@@ -1319,12 +1402,14 @@ function log_h1(msg: string) {
log_br();
}
-function log_h2(msg: string) {
+function log_h2(msg: string, player?: Player | 'fascist') {
log_br();
- log('.h2 ' + msg);
+ log(`.h2${player ? `.${player}` : ''} ${msg}`);
log_br();
}
+log;
+
// function log_h2_active(msg: string) {
// log_br();
// log('.h2 ' + msg);
@@ -1473,6 +1558,20 @@ function set_delete<T>(set: T[], item: T) {
}
}
+function list_deck(id: FactionId | 'fascist') {
+ 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))) {
+ return
+ } else if (id !== 'fascist' && (game.hands[id].includes(card) || game.discard[id].includes(card))) {
+ return;
+ }
+ deck.push(card)
+ })
+ return deck;
+}
+
// #endregion
// #region ARRAY