diff options
author | Frans Bongers <fransbongers@franss-mbp.home> | 2025-01-03 20:19:15 +0100 |
---|---|---|
committer | Frans Bongers <fransbongers@franss-mbp.home> | 2025-01-03 20:19:15 +0100 |
commit | 51d3c52ad03931e01a2f0c9e643f7a67286f9044 (patch) | |
tree | 9980e47e93b106ec7b8a9b4dde0f5e6843e3ee37 | |
parent | 1a5bcbc0293208cd2837a95c2cdd573cf461d960 (diff) | |
download | land-and-freedom-51d3c52ad03931e01a2f0c9e643f7a67286f9044.tar.gz |
fix: do not allow players to sabotage their own tracks
-rw-r--r-- | rules.js | 50 | ||||
-rw-r--r-- | rules.ts | 71 |
2 files changed, 113 insertions, 8 deletions
@@ -1140,14 +1140,56 @@ states.move_track = { resolve_active_and_proceed(); }, }; +function can_move_track_up(track_id) { + const faction = get_active_faction(); + return game.faction_turn === data_1.COMMUNISTS_ID && + faction === data_1.COMMUNISTS_ID && + track_id === data_1.GOVERNMENT + ? false + : true; +} +function can_move_track_down(track_id) { + const faction = get_active_faction(); + if (game.faction_turn === data_1.ANARCHISTS_ID && + faction === data_1.ANARCHISTS_ID && + (track_id === data_1.LIBERTY || track_id === data_1.COLLECTIVIZATION)) { + return false; + } + if (game.faction_turn === data_1.COMMUNISTS_ID && + faction === data_1.COMMUNISTS_ID && + track_id === data_1.SOVIET_SUPPORT) { + return false; + } + if (game.faction_turn === data_1.MODERATES_ID && + faction === data_1.MODERATES_ID && + (track_id === data_1.GOVERNMENT || track_id === data_1.FOREIGN_AID)) { + return false; + } + return true; +} states.move_track_up_or_down = { inactive: 'move a track', prompt() { gen_spend_hero_points(); - const node = get_active_node(); - view.prompt = `Move ${get_track_name(node.a.track_id)} up or down`; - gen_action('up'); - gen_action('down'); + const { track_id } = get_active_node_args(); + const can_move_up = can_move_track_up(track_id); + const can_move_down = can_move_track_down(track_id); + const track_name = get_track_name(track_id); + if (can_move_down && can_move_up) { + view.prompt = `Move ${track_name} up or down`; + } + else if (can_move_up) { + view.prompt = `Move ${track_name} up`; + } + else { + view.prompt = `Move ${track_name} down`; + } + if (can_move_up) { + gen_action('up'); + } + if (can_move_down) { + gen_action('down'); + } }, spend_hp() { resolve_spend_hp(); @@ -1406,14 +1406,77 @@ states.move_track = { }, }; +/** + * A player can always move a track up, unless Communist player + * during their turn + */ +function can_move_track_up(track_id: number): boolean { + const faction = get_active_faction(); + return game.faction_turn === COMMUNISTS_ID && + faction === COMMUNISTS_ID && + track_id === GOVERNMENT + ? false + : true; +} + +/** + * Not allowed for: + * - Anarchist and Liberty or Collectivization + * - Communist and Soviet Support + * - Moderate and Forgeign Aid + * Note: all during their turn + */ +function can_move_track_down(track_id): boolean { + const faction = get_active_faction(); + if ( + game.faction_turn === ANARCHISTS_ID && + faction === ANARCHISTS_ID && + (track_id === LIBERTY || track_id === COLLECTIVIZATION) + ) { + return false; + } + + if ( + game.faction_turn === COMMUNISTS_ID && + faction === COMMUNISTS_ID && + track_id === SOVIET_SUPPORT + ) { + return false; + } + + if ( + game.faction_turn === MODERATES_ID && + faction === MODERATES_ID && + (track_id === GOVERNMENT || track_id === FOREIGN_AID) + ) { + return false; + } + + return true; +} + states.move_track_up_or_down = { inactive: 'move a track', prompt() { gen_spend_hero_points(); - const node = get_active_node(); - view.prompt = `Move ${get_track_name(node.a.track_id)} up or down`; - gen_action('up'); - gen_action('down'); + const { track_id } = get_active_node_args(); + const can_move_up = can_move_track_up(track_id); + const can_move_down = can_move_track_down(track_id); + const track_name = get_track_name(track_id); + if (can_move_down && can_move_up) { + view.prompt = `Move ${track_name} up or down`; + } else if (can_move_up) { + view.prompt = `Move ${track_name} up`; + } else { + view.prompt = `Move ${track_name} down`; + } + + if (can_move_up) { + gen_action('up'); + } + if (can_move_down) { + gen_action('down'); + } }, spend_hp() { resolve_spend_hp(); |