summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-18 13:06:11 +0200
committerTor Andersson <tor@ccxvii.net>2023-06-18 20:30:23 +0200
commitd76855a759686208c1f9529cb0233ec519182b56 (patch)
tree6cb6cb917ad2e477002cd1f7bf5795d65ad6b3d9
parente1db7534f6360c7b83131e049e913038d595080e (diff)
downloadandean-abyss-d76855a759686208c1f9529cb0233ec519182b56.tar.gz
Show running victory margin tally in the player list.
-rw-r--r--play.css2
-rw-r--r--play.html7
-rw-r--r--play.js68
3 files changed, 77 insertions, 0 deletions
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 @@
<div id="roles">
<div class="role hide" id="role_Government">
<div class="role_name"><span>Government</span>
+ <div class="role_vp"></div>
<div class="role_user">-</div>
</div>
</div>
<div class="role hide" id="role_Government_+_AUC">
<div class="role_name"><span>Government + AUC</span>
+ <div class="role_vp"></div>
<div class="role_user">-</div>
</div>
</div>
<div class="role hide" id="role_FARC">
<div class="role_name"><span>FARC</span>
+ <div class="role_vp"></div>
<div class="role_user">-</div>
</div>
</div>
<div class="role hide" id="role_FARC_+_Cartels">
<div class="role_name"><span>FARC + Cartels</span>
+ <div class="role_vp"></div>
<div class="role_user">-</div>
</div>
</div>
<div class="role hide" id="role_AUC">
<div class="role_name"><span>AUC</span>
+ <div class="role_vp"></div>
<div class="role_user">-</div>
</div>
</div>
<div class="role hide" id="role_AUC_+_Cartels">
<div class="role_name"><span>AUC + Cartels</span>
+ <div class="role_vp"></div>
<div class="role_user">-</div>
</div>
</div>
<div class="role hide" id="role_Cartels">
<div class="role_name"><span>Cartels</span>
+ <div class="role_vp"></div>
<div class="role_user">-</div>
</div>
</div>
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))