summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js106
1 files changed, 95 insertions, 11 deletions
diff --git a/play.js b/play.js
index cef2bdd..0e885e3 100644
--- a/play.js
+++ b/play.js
@@ -43,6 +43,9 @@ const R_LOUIS_XV = "Louis XV"
const R_FREDERICK = "Frederick"
const R_MARIA_THERESA = "Maria Theresa"
+const R_PLAYER_A = "Player A"
+const R_PLAYER_B = "Player B"
+
/* DATA (SHARED) */
const deck_name = [ "red", "green", "blue", "yellow" ]
@@ -80,6 +83,8 @@ const F_SAXONY_TC_ONCE = 128 // only draw TCs once per turn
const F_FRANCE_REDUCED = 256
const F_PRUSSIA_NEUTRAL = 512
const F_MOVE_FLANDERS = 1024
+const F_INTRODUCTORY = 2048
+const F_TWO_PLAYER = 4096
const SPADES = 0
const CLUBS = 1
@@ -265,6 +270,10 @@ function find_city(city) {
return data.cities.name.indexOf(city)
}
+function is_bohemia_space(s) {
+ return s >= 0 && s <= 401
+}
+
const all_electoral_colleges = [
// find_city("England"),
find_city("Prag"),
@@ -276,6 +285,7 @@ const all_electoral_colleges = [
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)
@@ -288,6 +298,30 @@ all_home_country_fortresses[P_AUSTRIA] = set_intersect(all_fortresses, data.coun
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)
+const all_silesian_fortresses = set_intersect(all_fortresses, data.country.Silesia)
+const all_core_austria_fortresses = all_home_country_fortresses[P_AUSTRIA].filter(is_bohemia_space)
+const all_core_austria_and_silesia_fortresses = set_union(
+ all_core_austria_fortresses,
+ all_silesian_fortresses
+)
+
+function is_intro() {
+ return view.flags & F_INTRODUCTORY
+}
+
+function is_two_player() {
+ return view.flags & F_TWO_PLAYER
+}
+
+function count_victory_markers_in_country(pow, country) {
+ let n = 0
+ map_for_each(view.victory, (vspace, vpow) => {
+ if (vpow === pow && set_has(country, vspace))
+ ++n
+ })
+ return n
+}
+
/* SHOW PATHS */
const svgNS = "http://www.w3.org/2000/svg"
@@ -1162,15 +1196,37 @@ function is_saxony_prussian() {
}
function player_from_power(pow) {
+ if (is_two_player()) {
+ switch (pow) {
+ case P_FRANCE:
+ return R_PLAYER_A
+ case P_PRUSSIA:
+ return R_PLAYER_A
+ case P_PRAGMATIC:
+ if (is_intro())
+ return "NONE"
+ return R_PLAYER_B
+ case P_AUSTRIA:
+ return R_PLAYER_B
+ case P_SAXONY:
+ if (is_saxony_prussian())
+ return R_PLAYER_A
+ else
+ return R_PLAYER_B
+ case P_BAVARIA:
+ return R_PLAYER_A
+ }
+ }
+
switch (pow) {
case P_FRANCE:
return R_LOUIS_XV
case P_PRUSSIA:
return R_FREDERICK
case P_PRAGMATIC:
- if (view.pol_deck)
- return R_FREDERICK
- return "NONE"
+ if (is_intro())
+ return "NONE"
+ return R_FREDERICK
case P_AUSTRIA:
return R_MARIA_THERESA
case P_SAXONY:
@@ -1273,9 +1329,14 @@ function on_update() {
ui.header.classList.toggle("pragmatic", view.power === P_PRAGMATIC)
ui.header.classList.toggle("austria", view.power === P_AUSTRIA)
- update_player_power_list(R_MARIA_THERESA)
- update_player_power_list(R_FREDERICK)
- update_player_power_list(R_LOUIS_XV)
+ if (is_two_player()) {
+ update_player_power_list(R_PLAYER_A)
+ update_player_power_list(R_PLAYER_B)
+ } else {
+ update_player_power_list(R_MARIA_THERESA)
+ update_player_power_list(R_FREDERICK)
+ update_player_power_list(R_LOUIS_XV)
+ }
used_victory.fill(0)
used_elector.fill(0)
@@ -1284,7 +1345,7 @@ function on_update() {
back.fill(0)
sort_power_panel(true)
- if (!view.pol_deck) {
+ if (is_intro()) {
ui.power_panel[P_PRAGMATIC].style.display = "none"
ui.power_panel[6].style.display = "none"
}
@@ -1309,6 +1370,18 @@ function on_update() {
banner += " \u2014 Neutral"
if (pow === P_FRANCE && (view.flags & F_WAR_OF_JENKINS_EAR))
banner += " \u2014 receives 1 TC less"
+
+ if (is_intro()) {
+ if (pow === P_FRANCE) {
+ let n = count_victory_markers_in_country(P_FRANCE, all_core_austria_fortresses)
+ banner += ` \u2014 ${n} / 9 fortresses`
+ }
+ if (pow === P_PRUSSIA) {
+ let n = count_victory_markers_in_country(P_PRUSSIA, all_core_austria_and_silesia_fortresses)
+ banner += ` \u2014 ${n} / 12 fortresses`
+ }
+ }
+
ui.power_header[pow].innerHTML = banner
ui.hand[pow].replaceChildren()
@@ -1328,9 +1401,6 @@ function on_update() {
ui.hand[view.power].appendChild(ui.tc[c])
}
- if (view.pol_deck)
- update_political()
-
for (let deck = 0; deck < 4; ++deck) {
ui.discard[deck].replaceChildren()
for (let i = 0; i < view.discard[deck]; ++i)
@@ -1344,7 +1414,9 @@ function on_update() {
for (let i = 0; i < view.retro.length; i += 2)
layout_retro(view.retro[i], view.retro[i+1])
- if (view.pol_deck) {
+ if (!is_intro()) {
+ update_political()
+
for (let i = 0; i < view.elector.length; i += 2)
layout_elector(view.elector[i], view.elector[i+1])
@@ -1418,7 +1490,10 @@ function on_update() {
action_button_with_argument("shift", -1, "\u2b05")
action_button_with_argument("shift", +1, "\u27a1")
action_button_with_argument("shift", +2, "\u27a1\u27a1")
+ action_button_with_argument("shift", +3, "\u27a1\u27a1\u27a1")
action_button_with_argument("shift", +4, "\u27a1\u27a1\u27a1\u27a1")
+ action_button_with_argument("shift", +5, "\u27a1\u27a1\u27a1\u27a1")
+ action_button_with_argument("shift", +6, "\u27a1\u27a1\u27a1\u27a1")
for (let v = 16; v >= 0; --v)
action_button_with_argument("value", v, v)
@@ -1603,6 +1678,15 @@ function set_add_all(set, other) {
set_add(set, item)
}
+function set_union(one, two) {
+ let set = []
+ for (let item of one)
+ set_add(set, item)
+ for (let item of two)
+ set_add(set, item)
+ return set
+}
+
function set_intersect(one, two) {
let set = []
for (let item of one)