From d76855a759686208c1f9529cb0233ec519182b56 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 18 Jun 2023 13:06:11 +0200 Subject: Show running victory margin tally in the player list. --- play.css | 2 ++ play.html | 7 +++++++ play.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/play.css b/play.css index 168cbd7..593f5b8 100644 --- a/play.css +++ b/play.css @@ -32,6 +32,8 @@ main { background-color: #777; } .role.active span { text-decoration: underline; } +.role_vp { float: right; } + #card_tip { position: fixed; z-index: 100; diff --git a/play.html b/play.html index 935c069..eb01928 100644 --- a/play.html +++ b/play.html @@ -50,36 +50,43 @@
Government +
-
Government + AUC +
-
FARC +
-
FARC + Cartels +
-
AUC +
-
AUC + Cartels +
-
Cartels +
-
diff --git a/play.js b/play.js index e8ce8b1..fcaf290 100644 --- a/play.js +++ b/play.js @@ -221,6 +221,7 @@ function piece_faction(p) { } const last_city = data.last_city +const first_pop = data.first_pop const last_pop = data.last_pop const first_dept = data.first_dept const last_dept = data.last_dept @@ -253,6 +254,51 @@ function has_capability(bit) { return view.capabilities & (1 << bit) } +function piece_space(p) { + return view.pieces[p] +} + +function calc_support() { + let n = 0 + for (let s = first_pop; s <= last_pop; ++s) + if (view.support[s] > 0) + n += data.spaces[s].pop * view.support[s] + return n +} + +function calc_opposition() { + let n = 0 + for (let s = first_pop; s <= last_pop; ++s) + if (view.support[s] < 0) + n -= data.spaces[s].pop * view.support[s] + return n +} + +function calc_bases(faction) { + let n = 0 + for (let p = first_piece[faction][BASE]; p <= last_piece[faction][BASE]; ++p) + if (piece_space(p) !== AVAILABLE) + n += 1 + return n +} + +function govt_victory_margin() { + return calc_support() - 60 +} + +function farc_victory_margin() { + return calc_opposition() + calc_bases(FARC) - 25 +} + +function auc_victory_margin() { + return calc_bases(AUC) - calc_bases(FARC) +} + +function cartels_victory_margin() { + return Math.min(calc_bases(CARTELS) - 10, view.resources[CARTELS] - 40) +} + + let ui = { map: document.getElementById("map"), favicon: document.getElementById("favicon"), @@ -267,6 +313,15 @@ let ui = { document.getElementById("role_FARC_+_Cartels"), document.getElementById("role_AUC_+_Cartels"), ], + victory: [ + document.querySelector("#role_Government .role_vp"), + document.querySelector("#role_FARC .role_vp"), + document.querySelector("#role_AUC .role_vp"), + document.querySelector("#role_Cartels .role_vp"), + document.querySelector("#role_Government_\\+_AUC .role_vp"), + document.querySelector("#role_FARC_\\+_Cartels .role_vp"), + document.querySelector("#role_AUC_\\+_Cartels .role_vp"), + ], capabilities: [ document.getElementById("cap_first_div"), document.getElementById("cap_ospina"), @@ -1104,6 +1159,19 @@ function on_update() { ui.player[FARC_CARTELS].classList.toggle("active", view.current === FARC || view.current === CARTELS) ui.player[AUC_CARTELS].classList.toggle("active", view.current === AUC || view.current === CARTELS) + let vm_g = govt_victory_margin() + let vm_a = auc_victory_margin() + let vm_f = farc_victory_margin() + let vm_c = cartels_victory_margin() + + ui.victory[GOVT].textContent = vm_g + ui.victory[AUC].textContent = vm_a + ui.victory[CARTELS].textContent = vm_c + ui.victory[FARC].textContent = vm_f + ui.victory[GOVT_AUC].textContent = vm_g + " / " + vm_a + ui.victory[FARC_CARTELS].textContent = vm_f + " / " + vm_c + ui.victory[AUC_CARTELS].textContent = vm_a + " / " + vm_c + ui.tokens.president.style.left = [ 0, "254px", "337px", "420px" ][view.president] ui.tokens.senado_farc.classList.toggle("hide", !has_momentum(MOM_SENADO_FARC)) -- cgit v1.2.3