diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-10-24 01:54:53 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-10-24 01:57:23 +0200 |
commit | fd35bb389dbeebabe9bfee0e89e282df99e8dab5 (patch) | |
tree | 6194bce313d88a8d77073effd3f3137cfa5fc905 /play.js | |
parent | 982dda64511b2f827c2d7fac36e29005834b4fae (diff) | |
download | maria-fd35bb389dbeebabe9bfee0e89e282df99e8dab5.tar.gz |
imperial election
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 121 |
1 files changed, 104 insertions, 17 deletions
@@ -22,21 +22,6 @@ function toggle_shift() { document.body.classList.toggle("shift") } -const last_city = data.cities.name.length - 1 - -const ELIMINATED_TRAIN_X = 340 -const ELIMINATED_TRAIN_Y = 160 -const ELIMINATED_TRAIN_DX = 33 -const ELIMINATED_GENERAL_X = 340 -const ELIMINATED_GENERAL_Y = 110 -const ELIMINATED_GENERAL_DX = 50 - -const HUSSAR_X = 2190 -const HUSSAR_Y = 1630 - -const VICTORY_BOX_X = [ 115, 170, 235 ] -const VICTORY_BOX_Y = [ 235, 290, 345, 401 ] - /* DATA (SHARED) */ const deck_name = [ "red", "green", "blue", "yellow" ] @@ -207,6 +192,54 @@ function to_value(c) { return c & 15 } +/* DATA */ + +const last_city = data.cities.name.length - 1 + +const ELIMINATED_TRAIN_X = 340 +const ELIMINATED_TRAIN_Y = 160 +const ELIMINATED_TRAIN_DX = 33 +const ELIMINATED_GENERAL_X = 340 +const ELIMINATED_GENERAL_Y = 110 +const ELIMINATED_GENERAL_DX = 50 + +const ELECTORAL_COLLEGE_X = 526 +const ELECTORAL_COLLEGE_Y = 1574 +const ELECTORAL_COLLEGE_DX = 52 + +const HUSSAR_X = 2190 +const HUSSAR_Y = 1630 + +const VICTORY_BOX_X = [ 115, 170, 235 ] +const VICTORY_BOX_Y = [ 235, 290, 345, 401 ] + +function find_city(city) { + return data.cities.name.indexOf(city) +} + +const all_electoral_colleges = [ + // find_city("England"), + find_city("Prag"), + find_city("Mainz"), + find_city("Trier"), + find_city("Köln"), + find_city("Mannheim"), + find_city("München"), + find_city("Dresden"), + find_city("Berlin"), +] +const all_fortresses = [] +set_add_all(all_fortresses, data.type.major_fortress) +set_add_all(all_fortresses, data.type.minor_fortress) + +const all_home_country_fortresses = [] +all_home_country_fortresses[P_FRANCE] = set_intersect(all_fortresses, data.country.France) +all_home_country_fortresses[P_PRUSSIA] = set_intersect(all_fortresses, data.country.Prussia) +all_home_country_fortresses[P_PRAGMATIC] = set_intersect(all_fortresses, data.country.Netherlands) +all_home_country_fortresses[P_AUSTRIA] = set_intersect(all_fortresses, data.country.Austria) +all_home_country_fortresses[P_BAVARIA] = set_intersect(all_fortresses, data.country.Bavaria) +all_home_country_fortresses[P_SAXONY] = set_intersect(all_fortresses, data.country.Saxony) + /* SHOW PATHS */ const svgNS = "http://www.w3.org/2000/svg" @@ -587,11 +620,13 @@ function on_init() { } ui.elector = [ [], [], [], [], [], [] ] - for (let i = 0; i < 10; ++i) { + for (let i = 0; i < 30; ++i) { ui.elector[P_FRANCE].push(create_conquest("marker elector_marker_france")) ui.elector[P_PRUSSIA].push(create_conquest("marker elector_marker_prussia")) - ui.elector[P_SAXONY].push(create_conquest("marker elector_marker_saxony")) + ui.elector[P_PRAGMATIC].push(create_conquest("marker elector_marker_austria_pragmatic")) ui.elector[P_AUSTRIA].push(create_conquest("marker elector_marker_austria_pragmatic")) + ui.elector[P_BAVARIA].push(create_conquest("marker elector_marker_france")) + ui.elector[P_SAXONY].push(create_conquest("marker elector_marker_saxony")) } ui.tc = [] @@ -777,6 +812,15 @@ function on_blur_piece() { /* UPDATE UI */ +function is_power_controlled_fortress(pow, s) { + let owner = map_get(view.elector, s, -1) + if (owner < 0) + owner = map_get(view.victory, s, -1) + if (owner < 0) + return set_has(all_home_country_fortresses[pow], s) + return owner === pow +} + function layout_general_offset(who, here) { let other = -1 for (let p = 0; p < 20; ++p) @@ -1009,6 +1053,17 @@ function layout_elector(s, pow) { ui.markers_element.appendChild(e) } +function layout_electoral_college(ix, pow) { + for (let s of all_electoral_colleges) { + let e = ui.elector[pow][used_elector[pow]++] + let x = ELECTORAL_COLLEGE_X + ELECTORAL_COLLEGE_DX * ix + let y = ELECTORAL_COLLEGE_Y + e.style.left = (x - 16) + "px" + e.style.top = (y - 16) + "px" + ui.markers_element.appendChild(e) + } +} + function update_favicon() { let favicon = document.querySelector('link[rel="icon"]') switch (params.role) { @@ -1160,6 +1215,13 @@ function on_update() { for (let i = 0; i < view.retro.length; i += 2) layout_retro(view.retro[i], view.retro[i+1]) + layout_electoral_college(0, P_PRAGMATIC) + for (let i = 0; i < all_electoral_colleges.length; ++i) { + for (let pow of all_powers) + if (is_power_controlled_fortress(pow, all_electoral_colleges[i])) + layout_electoral_college(i+1, pow) + } + layout_victory_pool(P_FRANCE, 11, 83, 1560) layout_victory_pool(P_AUSTRIA, 8, 2334, 1561) layout_victory_pool(P_PRUSSIA, 13, 1927, 76) @@ -1393,3 +1455,28 @@ function set_add_all(set, other) { for (let item of other) set_add(set, item) } + +function set_intersect(one, two) { + let set = [] + for (let item of one) + if (set_has(two, item)) + set_add(set, item) + return set +} + +function map_get(map, key, missing) { + let a = 0 + let b = (map.length >> 1) - 1 + while (a <= b) { + let m = (a + b) >> 1 + let x = map[m<<1] + if (key < x) + b = m - 1 + else if (key > x) + a = m + 1 + else + return map[(m<<1)+1] + } + return missing +} + |