From 547dadf730c28797c25ab566104d3e2c5d4f8f80 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 2 Aug 2024 15:40:44 +0200 Subject: v2: temple --- rules.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/rules.js b/rules.js index 91c3c7e..1343993 100644 --- a/rules.js +++ b/rules.js @@ -1078,6 +1078,14 @@ function count_own_basilicas() { return n } +function count_own_temples() { + let n = 0 + for (let where = 0; where < 12; ++where) + if (is_own_province(where) && has_temple(where)) + ++n + return n +} + function roll_dice(count, target) { let hits = 0 while (count > 0) { @@ -1359,16 +1367,72 @@ function goto_upkeep() { // === CRISIS === function goto_crisis() { + // Temples + if (is_deluxe()) { + game.count = count_own_temples() + } + + roll_crisis() +} + +function roll_crisis() { game.crisis[0] = -1 game.crisis[1] = roll_die() game.crisis[2] = roll_die() game.crisis[3] = 0 game.crisis[4] = 0 - let sum = game.crisis[1] + game.crisis[2] - log("Crisis B" + game.crisis[1] + " W" + game.crisis[2]) + if (is_deluxe()) { + if (game.count > 0) { + game.state = "use_temple" + return + } + } + + resolve_crisis() +} + +states.use_temple = { + inactive: "Temple", + prompt() { + let sum = game.crisis[1] + game.crisis[2] + + let name + if (sum === 2) + name = "Ira Deorum" + else if (sum === 7) + name = "Event" + else if (sum === 12) + name = "Pax Deorum" + else { + if (get_player_count() === 2) + name = BARBARIAN_NAME[CRISIS_TABLE_2P[sum - 2]] + else if (get_player_count() === 3) + name = BARBARIAN_NAME[CRISIS_TABLE_3P[sum - 2]] + else + name = BARBARIAN_NAME[CRISIS_TABLE_4P[sum - 2]] + } + + view.prompt = `Crisis: Rolled ${sum} ${name}. Use Temple to re-roll?` + view.actions.temple = 1 + view.actions.pass = 1 + }, + temple() { + log("Temple re-roll.") + --game.count + roll_crisis() + }, + pass() { + game.count = 0 + resolve_crisis() + }, +} + +function resolve_crisis() { + let sum = game.crisis[1] + game.crisis[2] + if (sum === 2) { logi("Ira Deorum") return goto_ira_deorum() -- cgit v1.2.3