From f32d40bd233555f956d58ffe398218aa2c9cf633 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 21 Jun 2023 12:58:29 +0200 Subject: Barbarian invasions. --- rules.js | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 161 insertions(+), 34 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index 8f436cb..7493404 100644 --- a/rules.js +++ b/rules.js @@ -2,6 +2,76 @@ // TODO: barbarian leaders -> barbarian list +/* +TODO +---- + +[x] crisis ira deorum +[x] crisis barbarians +[ ] crisis pax deorum + +[ ] tribute +[ ] foederati +[ ] mobs + +[ ] disperse mob + +[ ] combat victory +[ ] combat retreat out of capital +[ ] combat retreat barbarians to homeland +[ ] combat advance into capital +[ ] combat flanking maneuver + +[ ] quaestor + [ ] place + [ ] remove at start + [ ] remove when replaced + +[ ] castra + [ ] place + [ ] remove at start + [ ] remove when move/attack + [ ] take hits in battle + +[ ] support check + +[ ] gain legacy + [ ] emperor + [ ] provinces + [ ] improvements + +[ ] end turn + [ ] grow mobs + [ ] flip barbarians + +[ ] praetorian guard +[ ] damnatio memoriae + +[ ] pretender + [ ] place + [ ] expand + [ ] scoring effects + [ ] occupation effects + +[ ] game end + +[ ] rival emperors + [ ] emperor turns + [ ] combat + [ ] support check + [ ] combat bonus + [ ] buy/trash bonus + +[ ] barbarian leaders + [ ] invasion + [ ] combat bonus + [ ] combat effect + [ ] buy/trash bonus + +[ ] other events + +*/ + var game var view const states = {} @@ -127,6 +197,7 @@ const GOTHS = 2 const NOMADS = 3 const SASSANIDS = 4 +const TRIBE_COUNT = [ 0, 5, 3, 4, 5 ] const BARBARIAN_COUNT = [ 0, 50, 30, 40, 50 ] const first_barbarian = [ 0, 10, 20, 30, 40 ] const last_barbarian = [ 9, 19, 29, 39, 49 ] @@ -686,12 +757,6 @@ function find_inactive_barbarian_at_home(tribe) { return -1 } -function activate_one_barbarian(tribe) { - let i = find_inactive_barbarian_at_home(tribe) - if (i >= 0) - set_barbarian_active(i) -} - function count_barbarians_in_province(tribe, where) { let n = 0 for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) @@ -879,8 +944,6 @@ function goto_crisis() { let sum = game.dice[0] + game.dice[1] - return goto_take_actions() // XXX - if (sum === 2) return goto_ira_deorum() if (sum === 12) @@ -897,14 +960,36 @@ function goto_crisis() { function goto_ira_deorum() { logi("Ira Deorum") - activate_one_barbarian(ALAMANNI) - activate_one_barbarian(FRANKS) - activate_one_barbarian(GOTHS) - if (game.legacy.length > 3) - activate_one_barbarian(NOMADS) - if (game.legacy.length > 2) - activate_one_barbarian(SASSANIDS) - goto_take_actions() + + game.count = 0 + let tribe_count = BARBARIAN_COUNT[get_player_count()] + for (let tribe = 0; tribe < tribe_count; ++tribe) + if (find_inactive_barbarian_at_home(tribe) >= 0) + game.count |= (1 << tribe) + + game.state = "ira_deorum" + if (game.count === 0) + goto_take_actions() +} + +states.ira_deorum = { + prompt() { + prompt("Ira Deorum: Activate one Barbarian in each tribe's homeland.") + let tribe_count = BARBARIAN_COUNT[get_player_count()] + for (let tribe = 0; tribe < tribe_count; ++tribe) + if (game.count & (1 << tribe)) + gen_action_barbarian(find_inactive_barbarian_at_home(tribe)) + }, + barbarian(id) { + let tribe = get_barbarian_tribe(id) + game.count &= ~(1 << tribe) + + log("Activated " + BARBARIAN_NAME[tribe]) + set_barbarian_active(id) + + if (game.count === 0) + goto_take_actions() + }, } function goto_pax_deorum() { @@ -921,7 +1006,31 @@ function goto_event() { function goto_barbarian_crisis(tribe) { logi(BARBARIAN_NAME[tribe]) - activate_one_barbarian(tribe) + + game.crisis = tribe + + if (find_inactive_barbarian_at_home(tribe) >= 0) + game.state = "barbarian_crisis" + else + roll_barbarian_crisis() +} + +states.barbarian_crisis = { + prompt() { + let tribe = game.crisis + prompt(BARBARIAN_NAME[tribe] + " Crisis!") + gen_action_barbarian(find_inactive_barbarian_at_home(tribe)) + }, + barbarian(id) { + let tribe = game.crisis + log("Activated " + BARBARIAN_NAME[tribe]) + set_barbarian_active(id) + roll_barbarian_crisis() + }, +} + +function roll_barbarian_crisis() { + let tribe = game.crisis let black = game.dice[2] = roll_die() let white = game.dice[3] = roll_die() @@ -929,39 +1038,57 @@ function goto_barbarian_crisis(tribe) { logi(`B${black} W${white}`) if (black <= count_active_barbarians_at_home(tribe)) - goto_barbarian_invasion(tribe, black, white) + goto_barbarian_invasion() else goto_take_actions() } -function invade_with_active_barbarian(tribe, where) { - // TODO: move leaders first - let id = find_active_barbarian_at_home(tribe) - if (id >= 0) - set_barbarian_location(id, where) -} - function goto_barbarian_invasion(tribe, black, white) { logi("Invasion!") + game.count = game.dice[2] + game.state = "barbarian_invasion" +} + +states.barbarian_invasion = { + prompt() { + let tribe = game.crisis + prompt(BARBARIAN_NAME[tribe] + " Invasion!") + gen_action_barbarian(find_active_barbarian_at_home(tribe)) + }, + barbarian(id) { + if (invade_with_barbarian(id) || --game.count === 0) + goto_take_actions() + }, +} + +function invade_with_barbarian(id) { + let tribe = game.crisis + let white = game.dice[3] let path = null for (let list of BARBARIAN_INVASION[tribe]) if (white >= list[0] && white <= list[1]) path = list[2] - let k = 0 - for (let i = 0; i < black;) { - let n = count_barbarians_in_province(tribe, path[k]) + for (let i = 0; i < path.length; ++i) { + let n = count_barbarians_in_province(tribe, path[i]) if (n < 3) { - invade_with_active_barbarian(tribe, path[k]) - ++i - } else { - if (++k > path.length) - break + invade_with_barbarian_counter(id, path, path[i]) + return false } } - goto_take_actions() + return true +} + +function invade_with_barbarian_counter(id, path, where) { + set_barbarian_location(id, where) + for (let loc of path) { + if (has_limes(loc)) + set_barbarian_inactive(id) + if (loc === where) + break + } } // === TAKE ACTIONS === -- cgit v1.2.3