From 4e286e95431bf6647eda3b94103d57d5d497512d Mon Sep 17 00:00:00 2001 From: Joël Simoneau Date: Fri, 13 Dec 2024 22:41:06 -0500 Subject: Conspire. --- play.js | 2 ++ rules.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 109 insertions(+), 12 deletions(-) diff --git a/play.js b/play.js index 4dd310c..c5a614c 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("conspire", "Conspire") + action_button("end_conspire", "End Conspire") action_button("demand", "Demand Obedience") action_button("end_demand", "End Demand Obedience") action_button("collect", "Collect Tribute") diff --git a/rules.js b/rules.js index 7e14bad..ce62fdd 100644 --- a/rules.js +++ b/rules.js @@ -329,6 +329,7 @@ function goto_eligible() { end_card() } else { game.state = "eligible" + game.decree = {} game.cmd = { limited: 0, free: 0, @@ -404,6 +405,7 @@ function goto_cavalry(n, next) { function goto_collect() { init_decree("Collect") + game.decree.n = 1 game.state = "collect" } @@ -571,7 +573,7 @@ states.eligible = { command_decree() { push_undo() game.cylinder[game.current] = SOP_COMMAND_DECREE - game.decree = 1 + game.decree.n = 1 game.state = "main_phase" }, event_command() { @@ -595,7 +597,7 @@ states.main_phase = { if (game.cmd && game.cmd.limited === 1) { view.prompt = "Select a limited Command." gen_any_command() - } else if (game.cmd && game.decree === 1) { + } else if (game.cmd && game.decree && game.decree.n === 1) { view.prompt = "Select a Command and a Decree." gen_any_command() gen_any_decree() @@ -606,7 +608,7 @@ states.main_phase = { } else if (game.cmd) { view.prompt = "Select a Command." gen_any_command() - } else if (game.decree === 1) { + } else if (game.decree && game.decree.n === 1) { view.prompt = "Select a Decree." gen_any_decree() } else { @@ -618,6 +620,7 @@ states.main_phase = { build: goto_build, collect: goto_collect, conscript: goto_conscript, + conspire: goto_conspire, demand: goto_demand, govern: goto_govern, march: goto_march, @@ -706,7 +709,7 @@ states.cavalry = { states.collect = { prompt() { - if (game.decree > 0) { + if (game.decree.n > 0) { view.prompt = `Collect Tribute: Collect ${collect_count()} from half the Tributaries prosperity` gen_action_resources(DS) } else { @@ -718,7 +721,7 @@ states.collect = { let c = collect_count() add_resources(DS, c) logi_resources(DS, c) - game.decree = 0 + game.decree.n = 0 goto_cavalry(2, "collect") }, end_collect: end_decree, @@ -1003,7 +1006,7 @@ states.strategic_assistance = { states.tax = { prompt() { - if (game.decree === 1) { + if (game.decree.n === 1) { view.prompt = `Tax: Collect ${tax_count()} from Controlled Prosperity and Temples.` gen_action_resources(VE) } else { @@ -1016,7 +1019,7 @@ states.tax = { let t = tax_count() add_resources(game.current, t) logi_resources(VE, t) - game.decree = 0 + game.decree.n = 0 }, end_tax: end_decree } @@ -1182,7 +1185,7 @@ function end_command() { function end_decree() { log_br() - game.decree = 0 + game.decree = null game.state = "main_phase" } @@ -1191,6 +1194,7 @@ function end_decree() { function init_decree(type) { push_undo() log_h2(faction_name[game.current] + " - " + type) + game.decree = {} } function gen_any_decree() { @@ -1257,7 +1261,7 @@ states.build = { else if (game.current === VE) view.prompt = "Build: Select a Province with a Raja." - if (game.decree === 1) { + if (game.decree.n === 1) { for (let s = first_space; s <= last_space; ++s) { if (can_build_in_space(s)) gen_action_space(s) @@ -1275,11 +1279,91 @@ states.build = { place_piece(p, s) log_space(s, "Build") pop_summary() - game.decree = 0 + game.decree.n = 0 }, end_build: end_decree, } +function can_conspire() { + if (!has_piece(AVAILABLE, BK, ELITE)) + return false + for (let s = first_space; s <= last_province; ++s) + if (can_conspire_in_space(s)) + return true + return false +} + +function can_conspire_in_space(s) { + if (game.inf[BK] < 2) { + if (has_piece_faction(s, BK) && has_piece(s, DS, ELITE)) + return true + } else if ( + (has_piece(s, DS, ELITE) || has_piece(s, VE, ELITE)) && + (has_piece_faction(s, BK) || SPACES[s].adjacent.some(ss => has_piece_faction(ss, BK))) + ) + return true + return false +} + +function goto_conspire() { + init_decree("Conspire") + game.decree.count = 2 + game.state = "conspire" +} + +states.conspire = { + prompt() { + if (game.decree.count === 0 || !can_conspire()) { + view.prompt = "Conspire: Done." + view.actions.end_conspire = 1 + } else { + if (game.decree.count === 1) + view.actions.end_conspire = 1 + + if (game.inf[BK] < 2) + view.prompt = "Conspire: Select a Province with you presence to convert a Governor." + else + view.prompt = "Conspire: Select a Province adjacent presence to convert a Governor or Raja." + + for (let s = first_space; s <= last_province; ++s) + if (can_conspire_in_space(s)) + gen_action_space(s) + } + }, + space(s) { + game.decree.where = s + game.state = "conspire_space" + }, + end_conspire() { + end_decree() + } +} + +states.conspire_space = { + // TODO: Make sure that the rebel status carry over + // TODO: Simply non-choices? + prompt () { + if (game.inf[BK] < 2) { + view.prompt = "Conspire: Select a Governor to convert to an Amir." + gen_piece_in_space(game.decree.where, DS, ELITE) + } else { + view.prompt = "Conspire: Select a Governor or Raja to convert to an Amir." + gen_piece_in_space(game.decree.where, DS, ELITE) + gen_piece_in_space(game.decree.where, VE, ELITE) + } + }, + piece(p) { + log_space(game.decree.where, "Convert") + logi("1 " + piece_name(p)) + log_br() + remove_piece(p) + let amir = find_piece(AVAILABLE, BK, ELITE) + place_piece(amir, game.decree.where) + game.decree.count -= 1 + game.state = "conspire" + } +} + function can_trade() { return trade_count() > 0 } @@ -1298,7 +1382,7 @@ function goto_trade() { states.trade = { prompt() { - if (game.decree === 1) { + if (game.decree.n === 1) { view.prompt = `Trade: Collect ${trade_count()} from Provinces with your presence.` gen_action_resources(BK) } else { @@ -1310,7 +1394,7 @@ states.trade = { let t = trade_count() add_resources(game.current, t) logi_resources(BK, t) - game.decree = 0 + game.decree.n = 0 goto_cavalry(trade_cavalry_count(), "trade") }, end_trade: end_decree, @@ -1509,6 +1593,10 @@ function has_piece(s, faction, type) { return find_piece(s, faction, type) != -1 } +function has_piece_faction(s, faction) { + return count_faction_pieces(s, faction) > 0 +} + function has_unmoved_piece(s, faction) { let unmoved = false for_each_movable(faction, p => { @@ -2234,6 +2322,13 @@ function for_each_piece(faction, type, f) { f(p) } +function gen_piece_in_space(space, faction, type) { + for_each_piece(faction, type, p => { + if (piece_space(p) === space) + gen_action_piece(p) + }) +} + function for_each_movable(faction, f) { if (faction === BK) for_each_piece(BK, ELITE, f) -- cgit v1.2.3