From 7cae6b069f2891c8c46dc39c2893047f88373b6b Mon Sep 17 00:00:00 2001 From: Joël Simoneau Date: Sat, 14 Dec 2024 17:57:19 -0500 Subject: WIP Compel --- play.js | 2 ++ rules.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 100 insertions(+), 8 deletions(-) diff --git a/play.js b/play.js index c5a614c..c0cec62 100644 --- a/play.js +++ b/play.js @@ -1046,6 +1046,8 @@ function on_update() { // Decree buttons action_button("build", "Build") action_button("end_build", "End Build") + action_button("compel", "Compel") + action_button("end_compel", "End Compel") action_button("conspire", "Conspire") action_button("end_conspire", "End Conspire") action_button("demand", "Demand Obedience") diff --git a/rules.js b/rules.js index ce62fdd..1b4b91e 100644 --- a/rules.js +++ b/rules.js @@ -615,10 +615,10 @@ states.main_phase = { view.prompt = "End of turn." view.actions.end_of_turn = 1 } - }, build: goto_build, collect: goto_collect, + compel: goto_compel, conscript: goto_conscript, conspire: goto_conspire, demand: goto_demand, @@ -1184,6 +1184,9 @@ function end_command() { } function end_decree() { + if (game.summary && game.summary.length > 0) { + pop_summary() + } log_br() game.decree = null game.state = "main_phase" @@ -1209,7 +1212,7 @@ function gen_any_decree() { } else if (game.current === VE) { view.actions.tax = can_tax() ? 1 : 0 view.actions.build = can_build() ? 1 : 0 - // view.actions.compel = can_compel() ? 1 : 0 + view.actions.compel = can_compel() ? 1 : 0 } } @@ -1284,6 +1287,95 @@ states.build = { end_build: end_decree, } +function can_compel() { + for (let s = first_space; s <= last_province; ++s) + if (can_compel_in_space(s)) + return true + return false +} + +function can_compel_in_space(s) { + if ( + (has_piece_faction(s, VE) || SPACES[s].adjacent.some(ss => has_piece_faction(ss, VE))) && + (has_piece(AVAILABLE, VE, ELITE) || SPACES[s].adjacent.some(ss => has_piece(ss, VE, ELITE))) + ) + return true + return false +} + +function goto_compel() { + init_decree("Compel") + game.decree.count = 2 + game.state = "compel" +} + +states.compel = { + prompt() { + view.prompt = "Compel: Select Province with or adjacent to your presence." + + for (let s = first_space; s <= last_province; ++s) + if (can_compel_in_space(s)) + gen_action_space(s) + }, + space(s) { + log_space(s, "Compel") + push_summary() + game.decree.where = s + game.state = "compel_space" + } +} + +states.compel_space = { + prompt() { + if (game.decree.count > 0) { + view.prompt = "Compel: Move in or add up to two Rajas." + + gen_place_piece(game.current, ELITE) + + for (let s of SPACES[game.decree.where].adjacent) { + gen_piece_in_space(s, VE, ELITE) + } + } else if (game.inf[VE] < 2) { + view.prompt = "Compel: Done." + view.actions.end_compel = 1 + } + + if (game.inf[VE] >= 2 && game.decree.count < 2) { + view.actions.next = 1 + } else if (game.inf[VE] < 2 && game.decree.count < 2) { + view.actions.end_compel = 1 + } + + }, + piece(p) { + if (piece_space(p) === AVAILABLE) + log_summary_place(p) + else + log_summary_move_from(p) + place_piece(p, game.decree.where) + game.decree.count -= 1 + }, + next() { + game.state = "compel_space_influencial" + }, + end_compel: end_decree +} + +states.compel_space_influencial = { + prompt() { + view.prompt = "Compel: Remove one enemy unit in the selected Province." + + gen_piece_in_space(game.decree.where, DS, TROOPS) + gen_piece_in_space(game.decree.where, DS, ELITE) + gen_piece_in_space(game.decree.where, BK, ELITE) + }, + piece(p) { + logi("Removed " + piece_name(p)) + remove_piece(p) + goto_cavalry(1) + } +} + function can_conspire() { if (!has_piece(AVAILABLE, BK, ELITE)) return false @@ -1321,9 +1413,9 @@ states.conspire = { view.actions.end_conspire = 1 if (game.inf[BK] < 2) - view.prompt = "Conspire: Select a Province with you presence to convert a Governor." + view.prompt = "Conspire: Select Province with your presence to convert a Governor." else - view.prompt = "Conspire: Select a Province adjacent presence to convert a Governor or Raja." + view.prompt = "Conspire: Select Province with or adjacent to your presence to convert a Governor or Raja." for (let s = first_space; s <= last_province; ++s) if (can_conspire_in_space(s)) @@ -1331,12 +1423,11 @@ states.conspire = { } }, space(s) { + log_space(s, "Conspire") game.decree.where = s game.state = "conspire_space" }, - end_conspire() { - end_decree() - } + end_conspire: end_decree } states.conspire_space = { @@ -1353,7 +1444,6 @@ states.conspire_space = { } }, piece(p) { - log_space(game.decree.where, "Convert") logi("1 " + piece_name(p)) log_br() remove_piece(p) -- cgit v1.2.3