summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-11-26 00:14:53 +0100
committerTor Andersson <tor@ccxvii.net>2024-11-28 23:33:22 +0100
commit41df873b95bd489975cb69f37ba024f2fdb479eb (patch)
treef0d4c0aae5eca31e66755ead6b7f177895253238 /play.js
parent902f03c38dac77a64e1259f04c4f04c2227c3b84 (diff)
downloadmaria-41df873b95bd489975cb69f37ba024f2fdb479eb.tar.gz
separate expiration dates for promises
Diffstat (limited to 'play.js')
-rw-r--r--play.js85
1 files changed, 42 insertions, 43 deletions
diff --git a/play.js b/play.js
index 7824ce3..3df499d 100644
--- a/play.js
+++ b/play.js
@@ -95,11 +95,14 @@ const turn_name = [
"Winter 1744",
]
-const DI_TURN = 0
-const DI_A_POWER = 1
-const DI_B_POWER = 2
-const DI_A_PROMISE = 3
-const DI_B_PROMISE = 4
+const DI_A_POWER = 0
+const DI_B_POWER = 1
+const DI_A_TURN = 2
+const DI_B_TURN = 3
+const DI_A_PHASE = 4
+const DI_B_PHASE = 5
+const DI_A_PROMISE = 6
+const DI_B_PROMISE = 7
const F_EMPEROR_FRANCE = 1
const F_EMPEROR_AUSTRIA = 2
@@ -1843,24 +1846,25 @@ function update_subsidy_list(subs, elt, title) {
}
function update_deal_item(deal) {
- let [ turn, a_power, b_power, a_promise, b_promise, a_phase, b_phase ] = deal
- let str = "<tr>"
+ let [ a_power, b_power, a_turn, b_turn, a_phase, b_phase, a_promise, b_promise ] = deal
+ let str = "<tr class='a'>"
str += "<td width=24>" + power_image[a_power]
str += "<td>" + html_escape(a_promise)
- str += "<td width=80>" + phase_list(a_phase)
- str += "<td width=60>" + turn_name[turn]
- str += "<tr>"
+ str += "<td width=80><i>" + phase_list(a_phase) + "</i>"
+ str += "<td width=60>" + turn_name[a_turn]
+ str += "<tr class='b'>"
str += "<td>" + power_image[b_power]
str += "<td>" + html_escape(b_promise)
- str += "<td>" + phase_list(b_phase)
+ str += "<td><i>" + phase_list(b_phase) + "</i>"
+ str += "<td width=60>" + turn_name[b_turn]
return str
}
function update_deal_list(deals, elt, title) {
if (deals && deals.length > 0) {
+ //let str = "<table><tr><th><th>" + title + "<th>phase<th>until"
let str = "<table><tr><th colspan=4>" + title
- for (let deal of deals)
- str += update_deal_item(deal)
+ str += deals.map(update_deal_item).join("<tr class='sep'><td colspan=4>")
str += "</table>"
elt.innerHTML = str
elt.style.display = "block"
@@ -1882,14 +1886,14 @@ function propose_deal() {
let form = window.propose_deal_form
- form.a_phase_politics.checked = false
- form.b_phase_politics.checked = false
- form.a_phase_hussars.checked = false
- form.b_phase_hussars.checked = false
- form.a_phase_movement.checked = false
- form.b_phase_movement.checked = false
- form.a_phase_retreat.checked = false
- form.b_phase_retreat.checked = false
+ window.a_phase_politics.checked = false
+ window.b_phase_politics.checked = false
+ window.a_phase_hussars.checked = false
+ window.b_phase_hussars.checked = false
+ window.a_phase_movement.checked = false
+ window.b_phase_movement.checked = false
+ window.a_phase_retreat.checked = false
+ window.b_phase_retreat.checked = false
form.a_power.value = view.power
switch (view.power) {
@@ -1906,9 +1910,12 @@ function propose_deal() {
form.b_power.value = P_PRAGMATIC
break
}
- form.turn.value = view.turn
+ form.a_turn.value = view.turn
+ form.b_turn.value = view.turn
- for (let opt of form.turn.options)
+ for (let opt of form.a_turn.options)
+ opt.disabled = (opt.value < view.turn)
+ for (let opt of form.b_turn.options)
opt.disabled = (opt.value < view.turn)
update_deal_options()
@@ -1919,37 +1926,29 @@ function propose_deal() {
function propose_deal_submit(evt) {
evt.preventDefault()
- let data = Object.fromEntries(new FormData(window.propose_deal_form))
-
- data.turn = Number(data.turn)
- 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)
+ let form = new FormData(window.propose_deal_form)
+ let data = {
+ a_power: Number(form.get("a_power")),
+ b_power: Number(form.get("b_power")),
+ a_turn: Number(form.get("a_turn")),
+ b_turn: Number(form.get("b_turn")),
+ a_phase: form.getAll("a_phase").reduce((acc,x)=>acc|x, 0),
+ b_phase: form.getAll("b_phase").reduce((acc,x)=>acc|x, 0),
+ a_promise: form.get("a_promise"),
+ b_promise: form.get("b_promise"),
+ }
if (!data.a_promise || !data.b_promise) {
alert("Each side must promise something!")
return
}
- console.log(data, player_from_power(data.a_power), player_from_power(data.b_power))
if (player_from_power(data.a_power) === player_from_power(data.b_power)) {
alert("Cannot create deals between powers controlled by the same player.")
return
}
- let deal = [ data.turn, data.a_power, data.b_power, data.a_promise, data.b_promise, data.a_phase, data.b_phase ]
+ let deal = [ data.a_power, data.b_power, data.a_turn, data.b_turn, data.a_phase, data.b_phase, data.a_promise, data.b_promise ]
if (view.actions.propose_deal)
send_message("action", [ "propose_deal", deal, game_cookie ])