diff options
author | Tor Andersson <tor@ccxvii.net> | 2025-03-19 23:11:44 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2025-03-19 23:11:44 +0100 |
commit | 7ed5936e81547858673806c9092ff0b370a9e656 (patch) | |
tree | 3f1d400dfcbb230425d7df3652f73f680b60272d | |
parent | 1738326b21f02a1a4cd246b85026bc3f846511df (diff) | |
download | land-and-freedom-7ed5936e81547858673806c9092ff0b370a9e656.tar.gz |
Put pool after factions in medallions and hero_points lists.
-rw-r--r-- | data.js | 4 | ||||
-rw-r--r-- | data.ts | 2 | ||||
-rw-r--r-- | play.js | 116 | ||||
-rw-r--r-- | rules.js | 44 | ||||
-rw-r--r-- | rules.ts | 46 | ||||
-rw-r--r-- | types.d.ts | 10 |
6 files changed, 105 insertions, 117 deletions
@@ -58,10 +58,10 @@ const ANARCHISTS_ID = 0; exports.ANARCHISTS_ID = ANARCHISTS_ID; const COMMUNISTS_ID = 1; exports.COMMUNISTS_ID = COMMUNISTS_ID; -const FASCIST_ID = 3; -exports.FASCIST_ID = FASCIST_ID; const MODERATES_ID = 2; exports.MODERATES_ID = MODERATES_ID; +const FASCIST_ID = 3; +exports.FASCIST_ID = FASCIST_ID; const ANARCHIST = 'Anarchist'; exports.ANARCHIST = ANARCHIST; const COMMUNIST = 'Communist'; @@ -35,8 +35,8 @@ const TRASH = 'trash'; const ANARCHISTS_ID: FactionId = 0; const COMMUNISTS_ID: FactionId = 1; -const FASCIST_ID: FascistId = 3; const MODERATES_ID: FactionId = 2; +const FASCIST_ID: FascistId = 3; const ANARCHIST = 'Anarchist' as Player; const COMMUNIST = 'Communist' as Player; @@ -18,21 +18,21 @@ const ui = { hand: document.getElementById("hand"), player_areas: document.getElementById("player_areas"), - panels: { - a: document.getElementById("player_area_a"), - c: document.getElementById("player_area_c"), - m: document.getElementById("player_area_m"), - }, - tableaus: { - a: document.getElementById("tableau_a"), - c: document.getElementById("tableau_c"), - m: document.getElementById("tableau_m"), - }, - tokens: { - a: document.getElementById("tokens_a"), - c: document.getElementById("tokens_c"), - m: document.getElementById("tokens_m"), - }, + panels: [ + document.getElementById("player_area_a"), + document.getElementById("player_area_c"), + document.getElementById("player_area_m"), + ], + tableaus: [ + document.getElementById("tableau_a"), + document.getElementById("tableau_c"), + document.getElementById("tableau_m"), + ], + tokens: [ + document.getElementById("tokens_a"), + document.getElementById("tokens_c"), + document.getElementById("tokens_m"), + ], bag_of_glory: document.getElementById("bag_of_glory"), // spaces @@ -220,7 +220,7 @@ function build_bonus(b, box_name, cname) { ui.map_container.appendChild(e) } -function build_front(i, action_id, box_name) { +function build_front(i, box_name) { var [x, y, w, h] = boxes[box_name] var e @@ -253,7 +253,7 @@ function build_front(i, action_id, box_name) { e.style.left = Math.round(x-3) + "px" e.style.width = Math.round(w - 6) + "px" e.style.height = Math.round(h - 6) + "px" - register_action(e, "front", action_id) + register_action(e, "front", i) ui.map_container.appendChild(e) } @@ -265,11 +265,11 @@ function on_init() { on_init_once = true ui.roles_list = document.getElementById("roles"), - ui.roles = { - a: document.getElementById("role_Anarchist"), - c: document.getElementById("role_Communist"), - m: document.getElementById("role_Moderate"), - } + ui.roles = [ + document.getElementById("role_Anarchist"), + document.getElementById("role_Communist"), + document.getElementById("role_Moderate"), + ] build_track(0, "tr0", "Liberty", 0, 10) build_track(1, "tr1", "Collectivization", 0, 10) @@ -280,10 +280,10 @@ function on_init() { build_bonus(0, "Bonus1", "bonus_morale") build_bonus(1, "Bonus2", "bonus_teamwork") - build_front(0, "a", "Aragon") - build_front(1, "m", "Madrid") - build_front(2, "n", "Northern") - build_front(3, "s", "Southern") + build_front(0, "Aragon") + build_front(1, "Madrid") + build_front(2, "Northern") + build_front(3, "Southern") ui.medallion_container = [] for (i = 0; i < 5; ++i) { @@ -361,9 +361,9 @@ const faction_class = { "Anarchist": "anarchist", "Communist": "communist", "Moderate": "moderate", - "a": "anarchist", - "c": "communist", - "m": "moderate", + "0": "anarchist", + "1": "communist", + "2": "moderate", } function update_front(status_card, str_container, con_container, front, front_id) { @@ -478,15 +478,15 @@ function on_update() { // eslint-disable-line no-unused-vars ui.hand.replaceChildren() place_cards(ui.hand, view.hand) - ui.tableaus.a.replaceChildren() - ui.tableaus.c.replaceChildren() - ui.tableaus.m.replaceChildren() - ui.tableaus.a.appendChild(ui.cards[117]) - ui.tableaus.c.appendChild(ui.cards[116]) - ui.tableaus.m.appendChild(ui.cards[115]) - place_cards(ui.tableaus.a, view.tableaus.a) - place_cards(ui.tableaus.c, view.tableaus.c) - place_cards(ui.tableaus.m, view.tableaus.m) + ui.tableaus[0].replaceChildren() + ui.tableaus[1].replaceChildren() + ui.tableaus[2].replaceChildren() + ui.tableaus[0].appendChild(ui.cards[117]) + ui.tableaus[1].appendChild(ui.cards[116]) + ui.tableaus[2].appendChild(ui.cards[115]) + place_cards(ui.tableaus[0], view.tableaus[0]) + place_cards(ui.tableaus[1], view.tableaus[1]) + place_cards(ui.tableaus[2], view.tableaus[2]) for (i = 0; i <= 1; ++i) { ui.bonuses[i].classList.toggle("red", !!view.bonuses[i]) @@ -511,28 +511,28 @@ function on_update() { // eslint-disable-line no-unused-vars for (i = 0; i < 5; ++i) { ui.medallion_container[i].replaceChildren() - if (i < view.medallions.pool.length) { - x = view.medallions.pool[i] + if (i < view.medallions[3].length) { + x = view.medallions[3][i] if (x !== null) ui.medallion_container[i].appendChild(ui.medallions[x]) } } - ui.tokens.a.replaceChildren() - ui.tokens.c.replaceChildren() - ui.tokens.m.replaceChildren() + ui.tokens[0].replaceChildren() + ui.tokens[1].replaceChildren() + ui.tokens[2].replaceChildren() ui.tokens[view.initiative].appendChild(ui.initiative) - update_medallions(ui.tokens.a, view.medallions.a) - update_medallions(ui.tokens.c, view.medallions.c) - update_medallions(ui.tokens.m, view.medallions.m) - update_hero_points(ui.tokens.a, view.hero_points.a) - update_hero_points(ui.tokens.c, view.hero_points.c) - update_hero_points(ui.tokens.m, view.hero_points.m) - - update_front(ui.status_fronts[0], ui.str_fronts[0], ui.con_fronts[0], view.fronts.a, "a") - update_front(ui.status_fronts[1], ui.str_fronts[1], ui.con_fronts[1], view.fronts.m, "m") - update_front(ui.status_fronts[2], ui.str_fronts[2], ui.con_fronts[2], view.fronts.n, "n") - update_front(ui.status_fronts[3], ui.str_fronts[3], ui.con_fronts[3], view.fronts.s, "s") + update_medallions(ui.tokens[0], view.medallions[0]) + update_medallions(ui.tokens[1], view.medallions[1]) + update_medallions(ui.tokens[2], view.medallions[2]) + update_hero_points(ui.tokens[0], view.hero_points[0]) + update_hero_points(ui.tokens[1], view.hero_points[1]) + update_hero_points(ui.tokens[2], view.hero_points[2]) + + update_front(ui.status_fronts[0], ui.str_fronts[0], ui.con_fronts[0], view.fronts[0], "a") + update_front(ui.status_fronts[1], ui.str_fronts[1], ui.con_fronts[1], view.fronts[1], "m") + update_front(ui.status_fronts[2], ui.str_fronts[2], ui.con_fronts[2], view.fronts[2], "n") + update_front(ui.status_fronts[3], ui.str_fronts[3], ui.con_fronts[3], view.fronts[3], "s") for (e of ui.raw_glory_container) e.replaceChildren() @@ -610,10 +610,10 @@ function sub_medallion(_match, p1) { function sub_token(match) { switch (match) { - case "Ta": return `<img src="images/icons/player_anarchist.png">` - case "Tc": return `<img src="images/icons/player_communist.png">` - case "Tm": return `<img src="images/icons/player_moderate.png">` - case "Tf": return `<img src="images/icons/player_fascist.png">` + case "T0": return `<img src="images/icons/player_anarchist.png">` + case "T1": return `<img src="images/icons/player_communist.png">` + case "T2": return `<img src="images/icons/player_moderate.png">` + case "T3": return `<img src="images/icons/player_fascist.png">` case "HP": return `<img src="images/icons/hero_point.png">` } return match @@ -9,6 +9,7 @@ const OBSERVER = 'Observer'; const states = {}; let game = {}; var view = {}; +const POOL_ID = 3; const role_ids = [data_1.ANARCHISTS_ID, data_1.COMMUNISTS_ID, data_1.MODERATES_ID]; const faction_player_map = [ data_1.ANARCHIST, @@ -31,11 +32,12 @@ const front_names = [ const bonus_names = ['Morale Bonus', 'Teamwork Bonus']; const { cards, medallions, tracks, } = data_1.default; const bonuses = [data_1.MORALE_BONUS, data_1.TEAMWORK_BONUS]; -const faction_cards = { - [data_1.ANARCHISTS_ID]: make_list(37, 54), - [data_1.COMMUNISTS_ID]: make_list(19, 36), - [data_1.MODERATES_ID]: make_list(1, 18), -}; +const faction_cards = [ + make_list(37, 54), + make_list(19, 36), + make_list(1, 18), +]; +console.log(faction_cards); const fascist_decks = { 1: make_list(55, 72), 2: make_list(73, 90), @@ -439,15 +441,9 @@ function setup(seed, _scenario, options) { [], [], ], - hero_points: { - factions: [2, 2, 0], - pool: 14 - }, + hero_points: [2, 2, 0, 14], initiative: data_1.MODERATES_ID, - medallions: { - factions: [[], [], []], - pool: [], - }, + medallions: [[], [], [], []], played_card: null, player_order: [data_1.MODERATE], selected_cards: [ @@ -1078,10 +1074,10 @@ states.choose_medallion = { prompt() { gen_spend_hero_points(); view.prompt = 'Earn a Medallion.'; - for (let m of game.medallions.pool) { + for (let m of game.medallions[POOL_ID]) { gen_action_medallion(m); } - if (!game.medallions.pool.some((m) => m !== null)) { + if (!game.medallions[POOL_ID].some((m) => m !== null)) { gen_action('skip'); } }, @@ -1092,8 +1088,8 @@ states.choose_medallion = { const faction = get_active_faction(); const medallion = medallions[m]; logp(`earned ${medallion.name}`); - const index = game.medallions.pool.indexOf(m); - game.medallions.pool[index] = null; + const index = game.medallions[POOL_ID].indexOf(m); + game.medallions[POOL_ID][index] = null; switch (m) { case 0: add_glory(faction, 1); @@ -1254,7 +1250,7 @@ states.hero_points = { gen_action('lose_hp'); return; } - if (game.hero_points.pool > 0) { + if (game.hero_points[POOL_ID] > 0) { view.prompt = value > 1 ? `Fascist Test: Gain ${value} Hero points.` : 'Fascist Test: Gain 1 Hero point.'; gen_action('gain_hp'); @@ -2244,7 +2240,7 @@ function gain_hero_points_in_player_order(factions, value) { } } function gain_hero_points(faction_id, value, skip_abilities = false) { - if (game.hero_points.pool === 0) { + if (game.hero_points[POOL_ID] === 0) { return; } if (!skip_abilities && @@ -2259,8 +2255,8 @@ function gain_hero_points(faction_id, value, skip_abilities = false) { value++; game.active_abilities = (game.active_abilities || []).filter((ability) => ability !== data_1.COMMUNIST_EXTRA_HERO_POINT); } - const gain = Math.min(game.hero_points.pool, value); - game.hero_points.pool -= gain; + const gain = Math.min(game.hero_points[POOL_ID], value); + game.hero_points[POOL_ID] -= gain; game.hero_points[faction_id] += gain; logi(`${get_player(faction_id)} +${gain} HP`); } @@ -2472,7 +2468,7 @@ function move_track_to(track_id, new_value) { } function pay_hero_points(faction, amount) { game.hero_points[faction] -= amount; - game.hero_points.pool += amount; + game.hero_points[POOL_ID] += amount; } function can_use_medallion(medallion_id, faction) { faction = faction === undefined ? get_active_faction() : faction; @@ -2725,7 +2721,7 @@ function draw_fascist_card() { } function lose_hero_points(faction, value) { const points_lost = Math.min(game.hero_points[faction], Math.abs(value)); - game.hero_points.pool += points_lost; + game.hero_points[POOL_ID] += points_lost; game.hero_points[faction] -= points_lost; if (points_lost !== 0) logi(`${get_player(faction)} -${points_lost} HP`); @@ -2952,7 +2948,7 @@ function draw_medallions() { let i = random(medallion_ids.length); let r = medallion_ids[i]; set_delete(medallion_ids, r); - game.medallions.pool.push(r); + game.medallions[POOL_ID].push(r); logi("M" + r); } } @@ -77,6 +77,8 @@ const states = {} as States; let game = {} as Game; // = null var view = {} as View; // = null +const POOL_ID = 3; + const role_ids: FactionId[] = [ANARCHISTS_ID, COMMUNISTS_ID, MODERATES_ID]; const faction_player_map: Record<FactionId, Player> = [ @@ -111,11 +113,13 @@ const { const bonuses = [MORALE_BONUS, TEAMWORK_BONUS]; -const faction_cards = { - [ANARCHISTS_ID]: make_list(37, 54) as CardId[], - [COMMUNISTS_ID]: make_list(19, 36) as CardId[], - [MODERATES_ID]: make_list(1, 18) as CardId[], -}; +const faction_cards = [ + make_list(37, 54) as CardId[], + make_list(19, 36) as CardId[], + make_list(1, 18) as CardId[], +]; + +console.log(faction_cards) const fascist_decks = { 1: make_list(55, 72) as CardId[], @@ -625,15 +629,9 @@ export function setup(seed: number, _scenario: string, options: Record<string,bo [], [], ], - hero_points: { - factions: [2, 2, 0], - pool: 14 - }, + hero_points: [2, 2, 0, 14], initiative: MODERATES_ID, - medallions: { - factions: [[],[],[]], - pool: [], - }, + medallions: [[],[],[],[]], played_card: null, player_order: [MODERATE], selected_cards: [ @@ -1363,10 +1361,10 @@ states.choose_medallion = { prompt() { gen_spend_hero_points(); view.prompt = 'Earn a Medallion.'; - for (let m of game.medallions.pool) { + for (let m of game.medallions[POOL_ID]) { gen_action_medallion(m); } - if (!game.medallions.pool.some((m) => m !== null)) { + if (!game.medallions[POOL_ID].some((m) => m !== null)) { gen_action('skip'); } }, @@ -1379,9 +1377,9 @@ states.choose_medallion = { logp(`earned ${medallion.name}`); - const index = game.medallions.pool.indexOf(m); + const index = game.medallions[POOL_ID].indexOf(m); - game.medallions.pool[index] = null; + game.medallions[POOL_ID][index] = null; switch (m) { case 0: @@ -1557,7 +1555,7 @@ states.hero_points = { gen_action('lose_hp'); return; } - if (game.hero_points.pool > 0) { + if (game.hero_points[POOL_ID] > 0) { view.prompt = value > 1 ? `Fascist Test: Gain ${value} Hero points.` : 'Fascist Test: Gain 1 Hero point.'; gen_action('gain_hp'); @@ -2778,7 +2776,7 @@ function gain_hero_points( value: number, skip_abilities = false // Used to prevent gaining of extra hero points when taking them from another player ) { - if (game.hero_points.pool === 0) { + if (game.hero_points[POOL_ID] === 0) { return; } if ( @@ -2802,8 +2800,8 @@ function gain_hero_points( (ability) => ability !== COMMUNIST_EXTRA_HERO_POINT ); } - const gain = Math.min(game.hero_points.pool, value); - game.hero_points.pool -= gain; + const gain = Math.min(game.hero_points[POOL_ID], value); + game.hero_points[POOL_ID] -= gain; game.hero_points[faction_id] += gain; logi(`${get_player(faction_id)} +${gain} HP`); } @@ -3070,7 +3068,7 @@ function move_track_to(track_id: number, new_value: number) { function pay_hero_points(faction: FactionId, amount: number) { game.hero_points[faction] -= amount; - game.hero_points.pool += amount; + game.hero_points[POOL_ID] += amount; } function can_use_medallion(medallion_id: number, faction?: FactionId) { @@ -3412,7 +3410,7 @@ function draw_fascist_card(): CardId { function lose_hero_points(faction: FactionId, value: number) { const points_lost = Math.min(game.hero_points[faction], Math.abs(value)); - game.hero_points.pool += points_lost; + game.hero_points[POOL_ID] += points_lost; game.hero_points[faction] -= points_lost; if (points_lost !== 0) logi(`${get_player(faction)} -${points_lost} HP`); @@ -3701,7 +3699,7 @@ function draw_medallions() { let i = random(medallion_ids.length); let r = medallion_ids[i] as CardId; set_delete(medallion_ids, r); - game.medallions.pool.push(r); + game.medallions[POOL_ID].push(r); logi("M" + r) } } @@ -54,15 +54,9 @@ export interface Game { fronts: Front[]; glory: FactionId[]; hands: CardId[][]; - hero_points: { - factions: number[]; - pool: number; - }; + hero_points: number[]; initiative: FactionId; - medallions: { - factions: number[][] - pool: Array<number | null> - }; + medallions: number[][]; played_card: CardId | null; player_order: Player[]; selected_cards: CardId[][]; |