summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js74
1 files changed, 68 insertions, 6 deletions
diff --git a/play.js b/play.js
index c8bcaeb..b136ce8 100644
--- a/play.js
+++ b/play.js
@@ -118,6 +118,12 @@ const F_TWO_PLAYER = 8192
const F_PLAYER_A_PICK = 16384 // picked PC card
const F_PLAYER_B_PICK = 32768
+// promise validation phases
+const V_POLITICS = 1
+const V_HUSSARS = 2
+const V_MOVEMENT = 4
+const V_RETREAT = 8
+
const SPADES = 0
const CLUBS = 1
const HEARTS = 2
@@ -1574,6 +1580,7 @@ function on_update() {
"ping",
])
+ update_subsidy_list(view.contracts, window.subsidy_list, "Active Subsidies")
update_deal_list(view.deals, window.active_deal_list, "Active Deals")
if (view.proposed_deal) {
update_deal_list([ view.proposed_deal ], window.proposed_deal_list, "Proposed Deal")
@@ -1620,7 +1627,9 @@ function on_update() {
action_button("reduce", "Reduce")
action_button("peace", "Peace")
action_button("accept", "Accept")
- action_button("refuse", "Refuse")
+ action_button("reject", "Reject")
+ action_button("yes", "Yes")
+ action_button("no", "No")
action_button("re_enter", "Re-enter")
action_button("force_march", "Force march")
@@ -1766,20 +1775,51 @@ function html_escape(str) {
return str.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")
}
+function phase_list(phase) {
+ let list = []
+ if (phase & V_POLITICS) list.push("politics")
+ if (phase & V_HUSSARS) list.push("hussars")
+ if (phase & V_MOVEMENT) list.push("movement")
+ if (phase & V_RETREAT) list.push("retreat")
+ return list.join(" ")
+}
+
+function update_subsidy_list(subs, elt, title) {
+ let show = false
+ let str = "<table><tr><th colspan=3>" + title
+ for (let from of all_major_powers) {
+ map_for_each(subs[from], (to, n) => {
+ show = true
+ str += "<tr><td width=24>" + power_image[from]
+ str += "<td width=24>" + power_image[to]
+ str += "<td>" + n + " TC"
+ })
+ }
+ if (show) {
+ elt.innerHTML = str
+ elt.style.display = "block"
+ } else {
+ elt.style.display = "none"
+ }
+}
+
function update_deal_item(deal) {
- let [ turn, a_power, b_power, a_promise, b_promise ] = deal
+ let [ turn, a_power, b_power, a_promise, b_promise, a_phase, b_phase ] = deal
let str = "<tr>"
str += "<td width=24>" + power_image[a_power]
str += "<td>" + html_escape(a_promise)
- str += "<td width=24>" + power_image[b_power]
- str += "<td>" + html_escape(b_promise)
+ str += "<td width=80>" + phase_list(a_phase)
str += "<td width=60>" + turn_name[turn]
+ str += "<tr>"
+ str += "<td>" + power_image[b_power]
+ str += "<td>" + html_escape(b_promise)
+ str += "<td>" + phase_list(b_phase)
return str
}
function update_deal_list(deals, elt, title) {
if (deals && deals.length > 0) {
- let str = "<table><tr><th colspan=5>" + title
+ let str = "<table><tr><th colspan=4>" + title
for (let deal of deals)
str += update_deal_item(deal)
str += "</table>"
@@ -1790,6 +1830,13 @@ function update_deal_list(deals, elt, title) {
}
}
+function update_deal_options() {
+ let a_power = window.propose_deal_form.elements.a_power.value | 0
+ let b_power = window.propose_deal_form.elements.b_power.value | 0
+ window.a_hussars_label.classList.toggle("hide", a_power !== P_AUSTRIA)
+ window.b_hussars_label.classList.toggle("hide", b_power !== P_AUSTRIA)
+}
+
function propose_deal() {
if (!is_action("propose_deal"))
return
@@ -1816,6 +1863,8 @@ function propose_deal() {
for (let opt of form.turn.options)
opt.disabled = (opt.value < view.turn)
+ update_deal_options()
+
window.propose_deal_dlog.showModal()
}
@@ -1828,6 +1877,19 @@ function propose_deal_submit(evt) {
data.a_power = Number(data.a_power)
data.b_power = Number(data.b_power)
+ data.a_phase = 0
+ data.b_phase = 0
+ data.a_phase |= (data.a_phase_politics ? V_POLITICS : 0)
+ data.b_phase |= (data.b_phase_politics ? V_POLITICS : 0)
+ if (data.a_power === P_AUSTRIA)
+ data.a_phase |= (data.a_phase_hussars ? V_HUSSARS : 0)
+ if (data.b_power === P_AUSTRIA)
+ data.b_phase |= (data.b_phase_hussars ? V_HUSSARS : 0)
+ data.a_phase |= (data.a_phase_movement ? V_MOVEMENT : 0)
+ data.b_phase |= (data.b_phase_movement ? V_MOVEMENT : 0)
+ data.a_phase |= (data.a_phase_retreat ? V_RETREAT : 0)
+ data.b_phase |= (data.b_phase_retreat ? V_RETREAT : 0)
+
if (!data.a_promise || !data.b_promise) {
alert("Each side must promise something!")
return
@@ -1839,7 +1901,7 @@ function propose_deal_submit(evt) {
return
}
- let deal = [ data.turn, data.a_power, data.b_power, data.a_promise, data.b_promise ]
+ let deal = [ data.turn, data.a_power, data.b_power, data.a_promise, data.b_promise, data.a_phase, data.b_phase ]
if (view.actions.propose_deal)
send_message("action", [ "propose_deal", deal, game_cookie ])