From 065ac069ed8109ba67c10ea6874fd442ec0b4ab9 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 1 Nov 2024 20:28:51 +0100 Subject: fix victory pool display (missed elector majority) --- play.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index eaa0869..f8f690c 100644 --- a/play.js +++ b/play.js @@ -1119,35 +1119,60 @@ function layout_retro(s, pow) { ui.markers_element.appendChild(e) } -function layout_victory_pool(pow, max, x, y) { +function elector_majority() { + let elector_france = 0 + let elector_pragmatic = 0 + for (let i = 0; i < 8; i += 2) { + if (view.elector[i+1] === P_FRANCE) + elector_france ++ + else + elector_pragmatic ++ + } + if (elector_france >= 3) + return P_FRANCE + if (elector_pragmatic >= 3) + return P_PRAGMATIC + return -1 +} + +function count_victory_markers(pow) { let n = view.vp[pow] - let m = 0 if (pow === P_PRUSSIA) { - m = view.vp[SET_ASIDE_PRUSSIA] - n += m + n += view.vp[SET_ASIDE_PRUSSIA] if (view.flags & F_SILESIA_ANNEXED) ++n } if (pow === P_FRANCE) { - m = view.vp[SET_ASIDE_FRANCE] - n += m + n += view.vp[SET_ASIDE_FRANCE] if (view.flags & F_ITALY_FRANCE) ++n if (view.flags & F_EMPEROR_FRANCE) ++n + if (elector_majority() === P_FRANCE) ++n } if (pow === P_AUSTRIA) { if (view.flags & F_ITALY_AUSTRIA) ++n if (view.flags & F_EMPEROR_AUSTRIA) ++n } + if (pow === P_PRAGMATIC) { + if (elector_majority() === P_PRAGMATIC) ++n + } for (let i = 0; i < view.victory.length; i += 2) if (view.victory[i+1] === pow) ++n + return n +} +function layout_victory_pool(pow, max, x, y) { + let n = count_victory_markers(pow) + let m = 0 + if (pow === P_PRUSSIA) + m = view.vp[SET_ASIDE_PRUSSIA] + if (pow === P_FRANCE) + m = view.vp[SET_ASIDE_FRANCE] for (let i = 0; i < max - n; ++i) { let e = ui.victory[pow][used_victory[pow]++] e.style.left = (x - 16 + (i%5) * 20) + "px" e.style.top = (y - 16 + (i/5|0) * 20) + "px" ui.markers_element.appendChild(e) } - for (let i = 0; i < m; ++i) { let e = ui.victory[pow][used_victory[pow]++] if (pow === P_FRANCE) { -- cgit v1.2.3