diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-11-26 00:14:53 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-11-28 23:33:22 +0100 |
commit | 41df873b95bd489975cb69f37ba024f2fdb479eb (patch) | |
tree | f0d4c0aae5eca31e66755ead6b7f177895253238 | |
parent | 902f03c38dac77a64e1259f04c4f04c2227c3b84 (diff) | |
download | maria-41df873b95bd489975cb69f37ba024f2fdb479eb.tar.gz |
separate expiration dates for promises
-rw-r--r-- | play.css | 28 | ||||
-rw-r--r-- | play.html | 54 | ||||
-rw-r--r-- | play.js | 85 | ||||
-rw-r--r-- | rules.js | 21 |
4 files changed, 108 insertions, 80 deletions
@@ -172,12 +172,17 @@ header.your_turn.austria { background-color: var(--color-light-austria); } dialog { background-color: #f3ebd4; + user-select: none; } dialog button { margin-left: 8px; } +dialog p { + margin: 6px 0; +} + /* PANELS */ .panel { @@ -336,24 +341,33 @@ button:not(.hide):has(img) { width: 879px; background-color: var(--color-light-political); border: 1px solid #0008; + border-collapse: collapse; } -#pd_deals td { - border: 1px solid #0004; - padding: 4px; - vertical-align: top; -} - -#pd_deals td img { +#pd_deals img { display: block; border: 1px solid black; } #pd_deals th { + border-bottom: 1px solid #0008; +} + +#pd_deals th { font-weight: normal; background-color: #0002; } +#pd_deals td { + padding: 4px; + vertical-align: top; +} + +#pd_deals tr.sep td { + border: 1px solid #000; + background-color: #0002; +} + #pd_deals .deal { margin-top: 8px; } @@ -166,15 +166,32 @@ <option value="4">Bavaria</option> <option value="5">Saxony</option> </select> - <br> - <label><input type="checkbox" name="a_phase_politics">Politics</label> - <label><input type="checkbox" name="a_phase_movement">Movement</label> - <label><input type="checkbox" name="a_phase_retreat">Retreat</label> - <label id="a_hussars_label"><input type="checkbox" name="a_phase_hussars">Hussars</label> - <br> + <select name="a_turn"> + <option value="1">Turn 1</option> + <option value="2">Turn 2</option> + <option value="3">Turn 3</option> + <option value="5">Turn 4</option> + <option value="6">Turn 5</option> + <option value="7">Turn 6</option> + <option value="9">Turn 7</option> + <option value="10">Turn 8</option> + <option value="11">Turn 9</option> + <option value="13">Turn 10</option> + <option value="14">Turn 11</option> + <option value="15">Turn 12</option> + </select> + <p> + <label><input type="checkbox" name="a_phase" value="1" id="a_phase_politics">Politics</label> + <label><input type="checkbox" name="a_phase" value="4" id="a_phase_movement">Movement</label> + <label><input type="checkbox" name="a_phase" value="8" id="a_phase_retreat">Retreat</label> + <label id="a_hussars_label"><input type="checkbox" name="a_phase" value="2" id="a_phase_hussars">Hussars</label> + <p> <textarea name="a_promise" placeholder="Promise..." rows=3 cols=40></textarea> - <br><br> + <p style="text-align:center"> + - ❦ - + + <p> <select name="b_power" onchange="update_deal_options()"> <option value="0">France</option> <option value="1">Prussia</option> @@ -183,18 +200,7 @@ <option value="4">Bavaria</option> <option value="5">Saxony</option> </select> - <br> - <label><input type="checkbox" name="b_phase_politics">Politics</label> - <label><input type="checkbox" name="b_phase_movement">Movement</label> - <label><input type="checkbox" name="b_phase_retreat">Retreat</label> - <label id="b_hussars_label"><input type="checkbox" name="b_phase_hussars">Hussars</label> - <br> - <textarea name="b_promise" placeholder="Promise..." rows=3 cols=40></textarea> - <br><br> - - Last until: - <br> - <select name="turn"> + <select name="b_turn"> <option value="1">Turn 1</option> <option value="2">Turn 2</option> <option value="3">Turn 3</option> @@ -208,8 +214,16 @@ <option value="14">Turn 11</option> <option value="15">Turn 12</option> </select> - <br><br> + <p> + <label><input type="checkbox" name="b_phase" value="1" id="b_phase_politics">Politics</label> + <label><input type="checkbox" name="b_phase" value="4" id="b_phase_movement">Movement</label> + <label><input type="checkbox" name="b_phase" value="8" id="b_phase_retreat">Retreat</label> + <label id="b_hussars_label"><input type="checkbox" name="b_phase" value="2" id="b_phase_hussars">Hussars</label> + <p> + <textarea name="b_promise" placeholder="Promise..." rows=3 cols=40></textarea> + <br> + <br> <div style="text-align:right"> <button onclick="propose_deal_cancel(event)">Cancel</button> <button onclick="propose_deal_submit(event)">Submit</button> @@ -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 ]) @@ -83,13 +83,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_PHASE = 5 -const DI_B_PHASE = 6 +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 @@ -1405,7 +1406,7 @@ function goto_start_turn() { } // remove expired deals - game.deals = game.deals.filter(deal => deal[DI_TURN] >= game.turn) + game.deals = game.deals.filter(deal => deal[DI_A_TURN] >= game.turn || deal[DI_B_TURN] >= game.turn) } function goto_end_turn() { @@ -6617,9 +6618,9 @@ states.pong = { function should_validate_promise(me, you, phase) { for (let deal of game.deals) { - if (deal[DI_A_POWER] === me && deal[DI_B_POWER] === you && (deal[DI_A_PHASE] & phase)) + if (deal[DI_A_POWER] === me && deal[DI_B_POWER] === you && (deal[DI_A_PHASE] & phase) && game.turn <= deal[DI_A_TURN]) return true - if (deal[DI_B_POWER] === me && deal[DI_A_POWER] === you && (deal[DI_B_PHASE] & phase)) + if (deal[DI_B_POWER] === me && deal[DI_A_POWER] === you && (deal[DI_B_PHASE] & phase) && game.turn <= deal[DI_B_TURN]) return true } return false |