diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-11-24 18:37:29 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-11-24 22:49:03 +0100 |
commit | 5950d01753f32d4f7d1cc866bcbdda3dc07194b8 (patch) | |
tree | c735e41677b3217fcba2dcd51259afc2edefda7b /rules.js | |
parent | 64ac25a40a2a647a90286d78b7c9e0137fd1da01 (diff) | |
download | maria-5950d01753f32d4f7d1cc866bcbdda3dc07194b8.tar.gz |
validate #2
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 106 |
1 files changed, 82 insertions, 24 deletions
@@ -4305,6 +4305,8 @@ function lose_vp(pow, n) { } function finish_combat() { + clear_undo() + game.selected = -1 if (is_intro()) { @@ -4631,7 +4633,6 @@ function end_place_tc_on_display() { // 25.5 Determine order of influence function goto_determine_order_of_influence() { - log_br() log("Order of influence") @@ -4701,13 +4702,19 @@ function goto_select_political_card() { set_active_to_power(pow) log("=" + game.power) - game.state = "select_political_card" if (is_two_player()) { - if ((game.flags & F_PLAYER_A_PICK) && (game.power === P_FRANCE || game.power === P_PRUSSIA)) + if ((game.flags & F_PLAYER_A_PICK) && (game.power === P_FRANCE || game.power === P_PRUSSIA)) { game.state = "must_save_tc" - if ((game.flags & F_PLAYER_B_PICK) && (game.power === P_PRAGMATIC || game.power === P_AUSTRIA)) + return + } + if ((game.flags & F_PLAYER_B_PICK) && (game.power === P_PRAGMATIC || game.power === P_AUSTRIA)) { game.state = "must_save_tc" + return + } } + + game.state = "select_political_card" + save_checkpoint() } } else { end_politics() @@ -4755,7 +4762,7 @@ states.select_political_card = { }, save() { log(power_name[game.power] + " saved TC.") - goto_select_political_card() + goto_validate_politics() }, } @@ -4885,10 +4892,12 @@ states.political_card_done = { } function end_execute_political_card() { + // Ugly hack to restore the political card executor by peeking at the checkpoint state! + set_active_to_power(game.restart.power) array_remove_item(game.political, game.pc) delete game.pc delete game.pcx - goto_select_political_card() + goto_validate_politics() } const TRACK_NAME = { saxony: "Saxony marker", russia: "Russia marker", italy: "Italy marker" } @@ -6425,11 +6434,11 @@ function goto_propose_deal(save_power, deal) { states.accept_deal_from = { dont_snap: true, - inactive: "negotiate", + inactive: "accept deal", prompt() { let from = game.proposal.deal[DI_A_POWER] let to = game.proposal.deal[DI_B_POWER] - prompt(`Accept ${power_name[from]} - ${power_name[to]} deal?`) + prompt(`Accept deal between ${power_name[from]} and ${power_name[to]}?`) view.actions.accept = 1 view.actions.reject = 1 view.actions.undo = 0 @@ -6446,11 +6455,11 @@ states.accept_deal_from = { states.accept_deal_to = { dont_snap: true, - inactive: "negotiate", + inactive: "accept deal", prompt() { let from = game.proposal.deal[DI_A_POWER] let to = game.proposal.deal[DI_B_POWER] - prompt(`Accept ${power_name[from]} - ${power_name[to]} deal?`) + prompt(`Accept deal between ${power_name[from]} and ${power_name[to]}?`) view.actions.accept = 1 view.actions.reject = 1 view.actions.undo = 0 @@ -6483,7 +6492,7 @@ function next_reject_deal() { states.reject_deal = { dont_snap: true, - inactive: "negotiate", + inactive: "accept deal", prompt() { let from = game.proposal.deal[DI_A_POWER] let to = game.proposal.deal[DI_B_POWER] @@ -6580,7 +6589,7 @@ function resume_validate_promise(state, end) { if (game.proposal & (1 << other)) { game.proposal &= ~(1 << other) game.state = state - set_active_to_power(other) + set_active_to_power_keep_undo(other) return } } @@ -6589,7 +6598,56 @@ function resume_validate_promise(state, end) { end() } -// TODO: validate_political_card +/* VALIDATE: POLITICS */ + +function goto_validate_politics() { + goto_validate_promise(V_POLITICS, resume_validate_politics) +} + +function resume_validate_politics() { + resume_validate_promise("validate_politics", end_validate_politics) +} + +function end_validate_politics() { + clear_checkpoint() + goto_select_political_card() +} + +states.validate_politics = { + dont_snap: true, + inactive: "validate promise", + prompt() { + let other = current_sequence_of_play().power + prompt("Did " + power_name[other] + " keep their politics promise?") + view.actions.yes = 1 + view.actions.no = 1 + }, + yes() { + resume_validate_politics() + }, + no() { + let other = game.power + restore_checkpoint() + game.proposal = other + game.state = "validate_politics_fail" + }, +} + +states.validate_politics_fail = { + dont_snap: true, + inactive: "select a political card", + prompt() { + prompt("Politics promise to " + power_name[game.proposal] + " was not kept.") + view.actions.resume = 1 + view.actions.undo = 0 + }, + resume() { + game.state = "select_political_card" + delete game.proposal + }, +} + +/* VALIDATE: HUSSARS */ function goto_validate_hussars() { game.proposal = 0 @@ -6637,6 +6695,8 @@ states.validate_hussars_fail = { }, } +/* VALIDATE: MOVEMENT */ + function should_validate_movement(power) { for (let other of all_powers) if (should_validate_promise(power, other, V_MOVEMENT)) @@ -6689,15 +6749,14 @@ states.validate_movement_fail = { }, } +/* VALIDATE: RETREAT */ + function goto_validate_retreat() { - // TODO: all powers - let other = piece_power[game.selected[0]] - if (should_validate_promise(game.power, other, V_RETREAT)) { - set_active_to_power_keep_undo(other) - game.state = "validate_retreat" - } else { - finish_combat() - } + goto_validate_promise(V_RETREAT, resume_validate_retreat) +} + +function resume_validate_retreat() { + resume_validate_promise("validate_retreat", finish_combat) } states.validate_retreat = { @@ -6710,8 +6769,7 @@ states.validate_retreat = { view.actions.no = 1 }, yes() { - clear_undo() - finish_combat() + resume_validate_retreat() }, no() { let other = game.power @@ -6725,7 +6783,7 @@ states.validate_retreat_fail = { dont_snap: true, inactive: "retreat defeated general", prompt() { - prompt("Promise to " + power_name[game.proposal] + " was not kept.") + prompt("Retreat promise to " + power_name[game.proposal] + " was not kept.") view.actions.resume = 1 view.actions.undo = 0 }, |