summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.js121
-rw-r--r--rules.js109
2 files changed, 213 insertions, 17 deletions
diff --git a/play.js b/play.js
index 578156b..efd3935 100644
--- a/play.js
+++ b/play.js
@@ -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
+}
+
diff --git a/rules.js b/rules.js
index 138d5bb..d0b8338 100644
--- a/rules.js
+++ b/rules.js
@@ -310,6 +310,18 @@ const EAST_PRUSSIA = find_city("East Prussia")
const AUSTRIAN_ITALY_BOX = data.sectors.ItalyA[0]
const FRENCH_ITALY_BOX = data.sectors.ItalyF[0]
+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_pieces = [ ...all_power_generals.flat(), ...all_power_trains.flat() ]
const all_trains = [ ...all_power_trains.flat() ]
const all_generals = [ ...all_power_generals.flat() ]
@@ -1125,6 +1137,11 @@ function set_active_to_current_winter_stage() {
}
function goto_end_turn() {
+ if (game.flags & F_IMPERIAL_ELECTION) {
+ goto_imperial_election()
+ return
+ }
+
goto_start_turn()
}
@@ -4717,6 +4734,98 @@ states.france_reduces_military_objectives = {
},
}
+/* IMPERIAL ELECTION */
+
+const POWER_FROM_IMPERIAL_ELECTION_STAGE = [
+ P_AUSTRIA,
+ P_FRANCE,
+ P_PRAGMATIC,
+ P_PRUSSIA
+]
+
+function goto_imperial_election() {
+ log("# Imperial Election")
+ game.count = 0
+
+ game.state = "imperial_election"
+ game.stage = 0
+ set_active_to_power(P_AUSTRIA)
+ log(power_name[game.power])
+}
+
+function next_imperial_election() {
+ if (game.power === P_FRANCE) {
+ set_active_to_power(P_BAVARIA)
+ } else if (coop_major_power(P_SAXONY) === game.power) {
+ set_active_to_power(P_SAXONY)
+ } else {
+ if (++game.stage === 4) {
+ end_imperial_election()
+ return
+ }
+ set_active_to_power(POWER_FROM_IMPERIAL_ELECTION_STAGE[game.stage])
+ }
+ log(power_name[game.power])
+}
+
+states.imperial_election = {
+ inactive: "vote in the imperial election",
+ prompt() {
+ let n = 0
+ if (game.power === P_PRAGMATIC)
+ ++n
+ for (let s of all_electoral_colleges)
+ if (is_power_controlled_fortress(game.power, s))
+ ++n
+ if (n === 0)
+ prompt("Cast no votes in the Imperial Election.")
+ else if (n === 1)
+ prompt("Cast your vote in the Imperial Election.")
+ else
+ prompt("Cast " + n + " votes in the Imperial Election.")
+ if (n === 0)
+ view.actions.pass = 1
+ else {
+ if (game.power === P_AUSTRIA || game.power === P_PRAGMATIC)
+ view.actions.power = [ P_AUSTRIA ]
+ else
+ view.actions.power = [ P_FRANCE, P_AUSTRIA ]
+ }
+ },
+ power(pow) {
+ if (game.power === P_PRAGMATIC) {
+ log(">Hannover for Austria")
+ ++game.count
+ }
+
+ for (let s of all_electoral_colleges) {
+ if (is_power_controlled_fortress(game.power, s)) {
+ log(">S" + s + " for " + power_name[pow])
+ if (pow === P_AUSTRIA)
+ ++game.count
+ }
+ }
+
+ next_imperial_election()
+ },
+ pass() {
+ log(">No votes")
+ next_imperial_election()
+ }
+}
+
+function end_imperial_election() {
+ if (game.count >= 5) {
+ log("Francis Stephen of Lorraine is Emperor.")
+ game.flags |= F_EMPEROR_AUSTRIA
+ } else {
+ log("Charles Albert of Bavaria is Emperor.")
+ game.flags |= F_EMPEROR_FRANCE
+ }
+ game.flags &= ~F_IMPERIAL_ELECTION
+ goto_start_turn()
+}
+
/* SETUP */
const POWER_FROM_SETUP_STAGE = [