From 2402a75c307d3926782f7520292f0c9e6cc15be4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 30 Nov 2022 12:26:31 +0100 Subject: locales and call_to_arms --- play.js | 53 ++++++++++--------- rules.js | 182 +++++++++++++++++++++++++++++++-------------------------------- 2 files changed, 116 insertions(+), 119 deletions(-) diff --git a/play.js b/play.js index 5d0bd5f..d9ad807 100644 --- a/play.js +++ b/play.js @@ -215,25 +215,25 @@ function is_p2_locale(loc) { function count_vp1() { let vp = 0 - for (let loc of view.p1_castles) + for (let loc of view.locales.p1_castles) vp += 2 - for (let loc of view.conquered) + for (let loc of view.locales.conquered) if (is_p2_locale(loc)) vp += data.locales[loc].vp << 1 - for (let loc of view.ravaged) + for (let loc of view.locales.ravaged) if (is_p2_locale(loc)) vp += 1 return vp } function count_vp2() { - let vp = view.veche_vp * 2 - for (let loc of view.p2_castles) + let vp = view.call_to_arms.veche_vp * 2 + for (let loc of view.locales.p2_castles) vp += 2 - for (let loc of view.conquered) + for (let loc of view.locales.conquered) if (is_p1_locale(loc)) vp += data.locales[loc].vp << 1 - for (let loc of view.ravaged) + for (let loc of view.locales.ravaged) if (is_p1_locale(loc)) vp += 1 return vp @@ -244,7 +244,7 @@ function is_card_in_use(c) { return true if (set_has(view.capabilities, c)) return true - if (view.lords.cards.includes(c)) + if (view.lords.capabilities.includes(c)) return true if (c === 18 || c === 19 || c === 20) return true @@ -489,10 +489,10 @@ function on_focus_cylinder(evt) { } } - let c = view.lords.cards[(lord<<1)] + let c = view.lords.capabilities[(lord<<1)] if (c >= 0) tip += ` \u2013 ${data.cards[c].capability}` - c = view.lords.cards[(lord<<1) + 1] + c = view.lords.capabilities[(lord<<1) + 1] if (c >= 0) tip += `, ${data.cards[c].capability}` @@ -808,7 +808,7 @@ function update_assets(id, parent, assets) { function update_vassals(ready_parent, mustered_parent, lord_ix) { for (let v of data.lords[lord_ix].vassals) { let e = ui.vassal_service[v] - if (view.vassals[v] === 0) { + if (view.lords.vassals[v] === 0) { e.classList.remove("hide") ready_parent.appendChild(e) } else { @@ -875,15 +875,15 @@ function update_lord(ix) { } function update_legate() { - if (view.legate < 0) { + if (view.call_to_arms.legate < 0) { ui.legate.classList.add("hide") } else { ui.legate.classList.remove("hide") - if (view.legate === 100) { + if (view.call_to_arms.legate === 100) { ui.legate.style.top = "1580px" ui.legate.style.left = "170px" } else { - layout_locale_item(view.legate, ui.legate, 0, -16) + layout_locale_item(view.call_to_arms.legate, ui.legate, 0, -16) } } } @@ -891,7 +891,7 @@ function update_legate() { function update_veche() { ui.veche.replaceChildren() - let n = view.veche_coin + let n = view.call_to_arms.veche_coin while (n >= 3) { add_asset(ui.veche, COIN, 3, VECHE) n -= 3 @@ -905,7 +905,7 @@ function update_veche() { n -= 1 } - for (let i = 0; i < view.veche_vp; ++i) + for (let i = 0; i < view.call_to_arms.veche_vp; ++i) add_veche_vp(ui.veche) } @@ -916,7 +916,7 @@ function update_locale(loc) { ui.locale_markers[loc].replaceChildren() - if (set_has(view.ravaged, loc)) { + if (set_has(view.locales.ravaged, loc)) { let cn if (is_p1_locale(loc)) cn = "marker small ravaged russian" @@ -925,7 +925,7 @@ function update_locale(loc) { ui.locale_markers[loc].appendChild(get_cached_element(cn)) } - if (set_has(view.conquered, loc)) { + if (set_has(view.locales.conquered, loc)) { let cn if (is_p1_locale(loc)) cn = "marker square conquered russian" @@ -935,28 +935,29 @@ function update_locale(loc) { ui.locale_markers[loc].appendChild(get_cached_element(cn)) } - if (set_has(view.p1_castles, loc)) { + if (set_has(view.locales.p1_castles, loc)) { let cn = "marker rectangle castle teutonic" ui.locale_markers[loc].appendChild(get_cached_element(cn)) } - if (set_has(view.p2_castles, loc)) { + if (set_has(view.locales.p2_castles, loc)) { let cn = "marker rectangle castle russian" ui.locale_markers[loc].appendChild(get_cached_element(cn)) } - if (set_has(view.walls, loc)) { + if (set_has(view.locales.walls, loc)) { let cn = "marker square walls" ui.locale_markers[loc].appendChild(get_cached_element(cn)) } - if (view.sieges[loc]) { + let sieges = map_get(view.locales.sieges, loc) + if (sieges > 0) { let cn if (is_p1_locale(loc)) cn = "marker square siege russian" else cn = "marker square siege teutonic" - for (let i = 0; i < view.sieges[loc]; ++i) + for (let i = 0; i < sieges; ++i) ui.locale_markers[loc].appendChild(get_cached_element(cn)) } } @@ -1058,10 +1059,10 @@ function update_cards() { for (let ix = 0; ix < data.lords.length; ++ix) { let side = ix < 6 ? "teutonic" : "russian" ui.lord_capabilities[ix].replaceChildren() - let c = view.lords.cards[(ix << 1) + 0] + let c = view.lords.capabilities[(ix << 1) + 0] if (c >= 0) ui.lord_capabilities[ix].appendChild(ui.cards[c]) - c = view.lords.cards[(ix << 1) + 1] + c = view.lords.capabilities[(ix << 1) + 1] if (c >= 0) ui.lord_capabilities[ix].appendChild(ui.cards[c]) } @@ -1077,7 +1078,7 @@ function on_update() { } for (let ix = 0; ix < data.lords.length; ++ix) { - if (view.lords[ix] === null) { + if (view.lords.locale[ix] < 0) { ui.lord_cylinder[ix].classList.add("hide") ui.lord_service[ix].classList.add("hide") ui.lord_mat[ix].classList.add("hide") diff --git a/rules.js b/rules.js index a0e5285..2d144b1 100644 --- a/rules.js +++ b/rules.js @@ -287,11 +287,11 @@ function get_lord_service(lord) { } function get_lord_capability(lord, n) { - return game.lords.cards[(lord << 1) + n] + return game.lords.capabilities[(lord << 1) + n] } function set_lord_capability(lord, n, x) { - game.lords.cards[(lord << 1) + n] = x + game.lords.capabilities[(lord << 1) + n] = x } function get_lord_assets(lord, n) { @@ -364,12 +364,12 @@ function get_lord_vassal_count(lord) { function get_lord_vassal_service(lord, n) { let v = data.lords[lord].vassals[n] - return game.vassals[v] + return game.lords.vassals[v] } function set_lord_vassal_service(lord, n, x) { let v = data.lords[lord].vassals[n] - game.vassals[v] = x + game.lords.vassals[v] = x } function clear_lords_moved() { @@ -475,7 +475,7 @@ function is_card_in_use(c) { return true if (set_has(game.capabilities, c)) return true - if (game.lords.cards.includes(c)) + if (game.lords.capabilities.includes(c)) return true if (c === 18 || c === 19 || c === 20) return true @@ -512,7 +512,7 @@ function is_lord_ready(lord) { } function is_vassal_ready(vassal) { - return game.vassals[vassal] === 0 + return game.lords.vassals[vassal] === 0 } function is_friendly_lord(lord) { @@ -567,27 +567,27 @@ function is_region(loc) { } function has_conquered_marker(loc) { - return set_has(game.conquered, loc) + return set_has(game.locales.conquered, loc) } function has_ravaged_marker(loc) { - return set_has(game.ravaged, loc) + return set_has(game.locales.ravaged, loc) } function add_ravaged_marker(loc) { - set_add(game.ravaged, loc) + set_add(game.locales.ravaged, loc) } function has_enemy_castle(loc) { if (game.active === P1) - return set_has(game.p2_castles, loc) - return set_has(game.p1_castles, loc) + return set_has(game.locales.p2_castles, loc) + return set_has(game.locales.p1_castles, loc) } function has_friendly_castle(loc) { if (game.active === P1) - return set_has(game.p1_castles, loc) - return set_has(game.p2_castles, loc) + return set_has(game.locales.p1_castles, loc) + return set_has(game.locales.p2_castles, loc) } function has_conquered_stronghold(loc) { @@ -705,13 +705,13 @@ function muster_lord(lord, locale, service) { set_lord_forces(lord, SERFS, info.forces.serfs | 0) for (let v of info.vassals) - game.vassals[v] = 0 + game.lords.vassals[v] = 0 } function muster_vassal(lord, vassal) { let info = data.vassals[vassal] - game.vassals[vassal] = 1 + game.lords.vassals[vassal] = 1 add_lord_forces(lord, KNIGHTS, info.forces.knights | 0) add_lord_forces(lord, SERGEANTS, info.forces.serfs | 0) @@ -735,14 +735,14 @@ exports.setup = function (seed, scenario, options) { state: "setup_lords", stack: [], - turn: 0, - p1_hand: [], p2_hand: [], p1_plan: [], p2_plan: [], - events: [], // this levy/this campaign cards + + turn: 0, capabilities: [], // global capabilities + events: [], // this levy/this campaign cards lords: { locale: Array(lord_count).fill(NOWHERE), @@ -750,29 +750,33 @@ exports.setup = function (seed, scenario, options) { assets: Array(lord_count).fill(0), forces: Array(lord_count).fill(0), routed: Array(lord_count).fill(0), - cards: Array(lord_count << 1).fill(NOTHING), - moved: 0, + capabilities: Array(lord_count << 1).fill(NOTHING), besieged: 0, + moved: 0, lieutenants: [], + vassals: Array(vassal_count).fill(0), }, - vassals: Array(vassal_count).fill(0), - legate: NOWHERE, - veche_vp: 0, - veche_coin: 0, - conquered: [], - ravaged: [], - sieges: [], + locales: { + conquered: [], + ravaged: [], + sieges: [], - p1_castles: [], - p2_castles: [], - walls: [], + p1_castles: [], + p2_castles: [], + walls: [], + }, + + call_to_arms: { + legate: NOWHERE, + veche_vp: 0, + veche_coin: 0, + }, command: NOBODY, who: NOBODY, where: NOWHERE, what: NOTHING, - levy: 0, // lordship used count: 0, } @@ -811,7 +815,7 @@ exports.setup = function (seed, scenario, options) { function setup_pleskau() { game.turn = 1 << 1 - game.veche_vp = 1 + game.call_to_arms.veche_vp = 1 muster_lord(LORD_HERMANN, LOC_DORPAT, 4) muster_lord(LORD_KNUD_ABEL, LOC_REVAL, 3) @@ -826,13 +830,13 @@ function setup_pleskau() { function setup_watland() { game.turn = 4 << 1 - game.veche_vp = 1 - game.veche_coin = 1 + game.call_to_arms.veche_vp = 1 + game.call_to_arms.veche_coin = 1 - set_add(game.conquered, LOC_IZBORSK) - set_add(game.conquered, LOC_PSKOV) - set_add(game.ravaged, LOC_PSKOV) - set_add(game.ravaged, LOC_DUBROVNO) + set_add(game.locales.conquered, LOC_IZBORSK) + set_add(game.locales.conquered, LOC_PSKOV) + set_add(game.locales.ravaged, LOC_PSKOV) + set_add(game.locales.ravaged, LOC_DUBROVNO) muster_lord(LORD_ANDREAS, LOC_FELLIN, 7) muster_lord(LORD_KNUD_ABEL, LOC_WESENBERG, 6) @@ -851,18 +855,18 @@ function setup_watland() { function setup_peipus() { game.turn = 13 << 1 - game.veche_vp = 4 - game.veche_coin = 3 + game.call_to_arms.veche_vp = 4 + game.call_to_arms.veche_coin = 3 - set_add(game.p2_castles, LOC_KOPORYE) - set_add(game.conquered, LOC_IZBORSK) - set_add(game.conquered, LOC_PSKOV) - set_add(game.ravaged, LOC_VOD) - set_add(game.ravaged, LOC_ZHELTSY) - set_add(game.ravaged, LOC_TESOVO) - set_add(game.ravaged, LOC_SABLIA) - set_add(game.ravaged, LOC_PSKOV) - set_add(game.ravaged, LOC_DUBROVNO) + set_add(game.locales.p2_castles, LOC_KOPORYE) + set_add(game.locales.conquered, LOC_IZBORSK) + set_add(game.locales.conquered, LOC_PSKOV) + set_add(game.locales.ravaged, LOC_VOD) + set_add(game.locales.ravaged, LOC_ZHELTSY) + set_add(game.locales.ravaged, LOC_TESOVO) + set_add(game.locales.ravaged, LOC_SABLIA) + set_add(game.locales.ravaged, LOC_PSKOV) + set_add(game.locales.ravaged, LOC_DUBROVNO) muster_lord(LORD_HERMANN, LOC_DORPAT, 16) muster_lord(LORD_YAROSLAV, LOC_PSKOV, 14) @@ -883,20 +887,20 @@ function setup_peipus() { function setup_return_of_the_prince() { game.turn = 9 << 1 - game.veche_vp = 3 - game.veche_coin = 2 - - set_add(game.p1_castles, LOC_KOPORYE) - set_add(game.conquered, LOC_KAIBOLOVO) - set_add(game.conquered, LOC_KOPORYE) - set_add(game.conquered, LOC_IZBORSK) - set_add(game.conquered, LOC_PSKOV) - set_add(game.ravaged, LOC_VOD) - set_add(game.ravaged, LOC_ZHELTSY) - set_add(game.ravaged, LOC_TESOVO) - set_add(game.ravaged, LOC_SABLIA) - set_add(game.ravaged, LOC_PSKOV) - set_add(game.ravaged, LOC_DUBROVNO) + game.call_to_arms.veche_vp = 3 + game.call_to_arms.veche_coin = 2 + + set_add(game.locales.p1_castles, LOC_KOPORYE) + set_add(game.locales.conquered, LOC_KAIBOLOVO) + set_add(game.locales.conquered, LOC_KOPORYE) + set_add(game.locales.conquered, LOC_IZBORSK) + set_add(game.locales.conquered, LOC_PSKOV) + set_add(game.locales.ravaged, LOC_VOD) + set_add(game.locales.ravaged, LOC_ZHELTSY) + set_add(game.locales.ravaged, LOC_TESOVO) + set_add(game.locales.ravaged, LOC_SABLIA) + set_add(game.locales.ravaged, LOC_PSKOV) + set_add(game.locales.ravaged, LOC_DUBROVNO) muster_lord(LORD_ANDREAS, LOC_KOPORYE, 12) muster_lord(LORD_ALEKSANDR, LOC_NOVGOROD, 14) @@ -916,16 +920,16 @@ function setup_return_of_the_prince() { function setup_return_of_the_prince_nicolle() { game.turn = 9 << 1 - game.veche_vp = 3 - game.veche_coin = 2 + game.call_to_arms.veche_vp = 3 + game.call_to_arms.veche_coin = 2 - set_add(game.p1_castles, LOC_KOPORYE) - set_add(game.conquered, LOC_KAIBOLOVO) - set_add(game.conquered, LOC_KOPORYE) - set_add(game.ravaged, LOC_VOD) - set_add(game.ravaged, LOC_ZHELTSY) - set_add(game.ravaged, LOC_TESOVO) - set_add(game.ravaged, LOC_SABLIA) + set_add(game.locales.p1_castles, LOC_KOPORYE) + set_add(game.locales.conquered, LOC_KAIBOLOVO) + set_add(game.locales.conquered, LOC_KOPORYE) + set_add(game.locales.ravaged, LOC_VOD) + set_add(game.locales.ravaged, LOC_ZHELTSY) + set_add(game.locales.ravaged, LOC_TESOVO) + set_add(game.locales.ravaged, LOC_SABLIA) muster_lord(LORD_ANDREAS, LOC_RIGA, 12) muster_lord(LORD_HERMANN, LOC_DORPAT, 12) @@ -945,8 +949,8 @@ function setup_return_of_the_prince_nicolle() { function setup_crusade_on_novgorod() { game.turn = 1 << 1 - game.veche_vp = 1 - game.veche_coin = 0 + game.call_to_arms.veche_vp = 1 + game.call_to_arms.veche_coin = 0 muster_lord(LORD_HERMANN, LOC_DORPAT, 4) muster_lord(LORD_KNUD_ABEL, LOC_REVAL, 3) @@ -989,7 +993,7 @@ function setup_pleskau_quickstart() { set_lord_capability(LORD_YAROSLAV, 0, find_card("T3")) set_add(game.capabilities, find_card("T13")) - game.legate = LOC_DORPAT + game.call_to_arms.legate = LOC_DORPAT set_add(game.capabilities, find_card("R8")) muster_lord(LORD_DOMASH, LOC_NOVGOROD) @@ -1000,7 +1004,7 @@ function setup_pleskau_quickstart() { set_lord_capability(LORD_GAVRILO, 0, find_card("R2")) set_lord_capability(LORD_GAVRILO, 1, find_card("R6")) - game.veche_coin += 1 + game.call_to_arms.veche_coin += 1 goto_campaign_plan() @@ -2079,7 +2083,7 @@ function end_feed() { function can_pay_lord(lord) { if (game.active === RUSSIANS) { - if (game.veche_coin > 0 && !is_lord_besieged(lord)) + if (game.call_to_arms.veche_coin > 0 && !is_lord_besieged(lord)) return true } let loc = get_lord_locale(lord) @@ -2126,10 +2130,12 @@ states.pay = { states.pay_lord = { prompt() { view.prompt = `You may Pay ${lord_name[game.who]} with Coin or Loot.` + if (game.active === RUSSIANS) { - if (game.veche_coin > 0 && !is_lord_besieged(lord)) + if (game.call_to_arms.veche_coin > 0 && !is_lord_besieged(lord)) view.actions.veche_coin = 1 } + let loc = get_lord_locale(game.who) let pay_with_loot = is_friendly_locale(loc) for (let lord = first_friendly_lord; lord <= last_friendly_lord; ++lord) { @@ -2161,7 +2167,7 @@ states.pay_lord = { }, veche_coin() { logi(`Paid L${game.who} with Coin from Veche.`) - game.veche_coin-- + game.call_to_arms.veche_coin-- add_lord_service(game.who, 1) pop_state() }, @@ -2211,7 +2217,7 @@ function disband_lord(lord) { set_lord_moved(lord, 0) for (let v of data.lords[lord].vassals) - game.vassals[v] = 0 + game.lords.vassals[v] = 0 // TODO: check lifted siege } @@ -2390,22 +2396,12 @@ exports.view = function (state, current) { log: game.log, turn: game.turn, - lords: game.lords, - vassals: game.vassals, events: game.events, capabilities: game.capabilities, - conquered: game.conquered, - ravaged: game.ravaged, - sieges: game.sieges, - - p1_castles: game.p1_castles, - p2_castles: game.p2_castles, - walls: game.walls, - - legate: game.legate, - veche_vp: game.veche_vp, - veche_coin: game.veche_coin, + lords: game.lords, + locales: game.locales, + call_to_arms: game.call_to_arms, command: game.command, hand: null, -- cgit v1.2.3