summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-24 03:22:47 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 18:39:37 +0200
commitcaebd7f985f5c15ad7231a4f230542c4421a44b2 (patch)
treee626ed04cfdc8791d80608f82a8a6f26597fa470
parent667b3711da87ba6b3181f5ebd823d00efd922ce8 (diff)
downloadtime-of-crisis-caebd7f985f5c15ad7231a4f230542c4421a44b2.tar.gz
Streamline Quaestor, Castra, and Foederati.
-rw-r--r--rules.js200
1 files changed, 144 insertions, 56 deletions
diff --git a/rules.js b/rules.js
index 2a56249..6f979df 100644
--- a/rules.js
+++ b/rules.js
@@ -177,10 +177,10 @@ const SHAPUR_BONUS = 1 << 5
const RIVAL_EMPEROR_NAME = [ "Postumus", "Priest King", "Zenobia" ]
const GENERAL_NAME = [
- "Red 0", "Red 1", "Red 2", "Red 3", "Red 4", "Red 5",
- "Blue 0", "Blue 1", "Blue 2", "Blue 3", "Blue 4", "Blue 5",
- "Yellow 0", "Yellow 1", "Yellow 2", "Yellow 3", "Yellow 4", "Yellow 5",
- "Green 0", "Green 1", "Green 2", "Green 3", "Green 4", "Green 5",
+ "Red General", "Red General", "Red General", "Red General", "Red General", "Red General",
+ "Blue General", "Blue General", "Blue General", "Blue General", "Blue General", "Blue General",
+ "Yellow General", "Yellow General", "Yellow General", "Yellow General", "Yellow General", "Yellow General",
+ "Green General", "Green General", "Green General", "Green General", "Green General", "Green General",
]
const BARBARIAN_NAME = [
@@ -1201,7 +1201,7 @@ function goto_crisis() {
else
tribe = CRISIS_TABLE_4P[sum - 2]
- log(msg + " - " + BARBARIAN_NAME[tribe])
+ log(msg)
goto_barbarian_crisis(tribe)
}
@@ -1231,7 +1231,6 @@ states.ira_deorum = {
let tribe = get_barbarian_tribe(id)
game.count &= ~(1 << tribe)
- log("Activated " + BARBARIAN_NAME[tribe])
set_barbarian_active(id)
if (game.count === 0)
@@ -1301,7 +1300,6 @@ states.barbarian_crisis = {
},
barbarian(id) {
let tribe = game.crisis
- log("Activated " + BARBARIAN_NAME[tribe])
set_barbarian_active(id)
roll_barbarian_crisis()
},
@@ -1318,7 +1316,7 @@ function roll_barbarian_crisis() {
if (game.active_event === EVENT_PREPARING_FOR_WAR)
black = Math.min(6, black + 2)
- logi(`B${black} W${white}`)
+ log(BARBARIAN_NAME[tribe] + " B" + black + " W" + white)
if (black <= count_active_barbarians_at_home(tribe))
goto_barbarian_invasion(tribe)
@@ -1327,7 +1325,6 @@ function roll_barbarian_crisis() {
}
function goto_barbarian_invasion(tribe) {
- logi("Invasion!")
game.count = game.dice[2]
// Ardashir: All active Sassanids invade!
@@ -1371,7 +1368,15 @@ function invade_with_barbarian(id) {
return true
}
+function barbarian_name(id) {
+ if (id === CNIVA) return "Cniva"
+ if (id === ARDASHIR) return "Ardashir"
+ if (id === SHAPUR) return "Shapur I"
+ return BARBARIAN_NAME[get_barbarian_tribe(id)]
+}
+
function invade_with_barbarian_counter(id, path, where) {
+ logi(barbarian_name(id) + " to %" + where)
set_barbarian_location(id, where)
for (let loc of path) {
if (has_limes(loc))
@@ -2355,6 +2360,7 @@ function has_praetorian_guard_card() {
}
function can_play_praetorian_guard() {
+ // TODO: select governor after playing praetorian guard?
if (game.selected_governor >= 0 && get_governor_location(game.selected_governor) === AVAILABLE)
return game.ip[MILITARY] >= 1 && !is_emperor_player() && !has_placed_governor(ITALIA)
return false
@@ -2440,39 +2446,74 @@ function move_army_to(who, to) {
// CARD: CASTRA
function can_play_castra() {
- let where = get_selected_region()
- if (game.selected_governor >= 0 && is_province(where))
- return has_lone_militia(where) && !has_militia_castra(where)
- if (game.selected_general >= 0 && is_province(where))
- return !has_general_castra(where)
+ for (let where = 0; where < 12; ++where)
+ if (!has_militia_castra(where) && has_lone_militia(where) && is_own_province(where))
+ return true
+ for (let i = 0; i < 6; ++i) {
+ let id = game.current * 6 + i
+ if (is_region(get_general_location(id)) && !has_general_castra(id))
+ return true
+ }
return false
}
function play_castra() {
- let where = get_selected_region()
- if (game.selected_governor >= 0 && is_province(where)) {
- log("Castra in %" + where)
+ game.state = "castra"
+}
+
+states.castra = {
+ prompt() {
+ prompt("Castra: Select an army you command.")
+ for (let where = 0; where < 12; ++where)
+ if (!has_militia_castra(where) && has_lone_militia(where) && is_own_province(where))
+ gen_action_militia(where)
+ for (let i = 0; i < 6; ++i) {
+ let id = game.current * 6 + i
+ if (is_region(get_general_location(id)) && !has_general_castra(id))
+ gen_action_general(id)
+ }
+ },
+ militia(where) {
+ log("Castra on militia in %" + where)
add_militia_castra(where)
- }
- if (game.selected_general >= 0) {
- log("Castra on " + GENERAL_NAME[game.selected_general])
- add_general_castra(game.selected_general)
- }
+ game.state = "take_actions"
+ },
+ general(id) {
+ push_undo()
+ let where = get_general_location(id)
+ log("Castra on army in %" + where)
+ add_general_castra(id)
+ game.state = "take_actions"
+ },
}
// CARD: QUAESTOR
function can_play_quaestor() {
- let where = get_selected_region()
- if (game.selected_governor >= 0 && is_province(where))
- return !has_quaestor(where) && !is_breakaway(where) && !is_seat_of_power(where)
+ for (let where = 0; where < 12; ++where)
+ if (!has_quaestor(where) && !is_breakaway(where) && !is_seat_of_power(where) && is_own_province(where))
+ return true
return false
}
function play_quaestor() {
- let where = get_selected_region()
- log("Quaestor in %" + where)
- add_quaestor(where)
+ game.state = "quaestor"
+}
+
+states.quaestor = {
+ prompt() {
+ prompt("Quaestor: Select a province you govern.")
+ view.color = POPULACE
+ for (let where = 0; where < 12; ++where)
+ if (!has_quaestor(where) && !is_breakaway(where) && !is_seat_of_power(where) && is_own_province(where))
+ gen_action_region(where)
+ },
+ region(where) {
+ push_undo()
+ log("Quaestor in %" + where)
+ add_quaestor(where)
+ game.state = "take_actions"
+ }
}
// CARD: TRIBUTE
@@ -2501,6 +2542,7 @@ states.tribute = {
}
},
barbarian(target) {
+ push_undo()
let where = get_barbarian_location(target)
let tribe = get_barbarian_tribe(target)
log("Tribute " + BARBARIAN_NAME[tribe] + " in %" + where)
@@ -2513,6 +2555,15 @@ states.tribute = {
// CARD: FOEDERATI
+function can_foederati_from_region_or_adjacent(from) {
+ if (can_foederati_from_region(from))
+ return true
+ for (let to of ADJACENT[from])
+ if (can_foederati_from_region(to))
+ return true
+ return false
+}
+
function can_foederati_from_region(where) {
let tribe_count = get_tribe_count()
for (let tribe = 0; tribe < tribe_count; ++tribe) {
@@ -2539,24 +2590,15 @@ function gen_foederati(where) {
}
}
-function can_foederati_from_region_and_adjacent(from) {
- if (can_foederati_from_region(from))
- return true
- for (let to of ADJACENT[from])
- if (can_foederati_from_region(to))
- return true
- return false
-}
-
function can_play_foederati() {
- let where = get_selected_region()
- if (is_region(where)) {
- if (game.selected_general >= 0)
- if (can_foederati_from_region_and_adjacent(where))
- return true
- if (game.selected_governor >= 0)
- if (has_lone_militia(where) && can_foederati_from_region_and_adjacent(where))
- return true
+ for (let i = 0; i < 6; ++i) {
+ let id = game.current * 6 + i
+ let where = get_general_location(id)
+ if (is_region(where) && can_foederati_from_region_or_adjacent(where))
+ return true
+ where = get_governor_location(id)
+ if (is_province(where) && has_lone_militia(where) && can_foederati_from_region_or_adjacent(where))
+ return true
}
return false
}
@@ -2567,22 +2609,69 @@ function play_foederati() {
states.foederati = {
prompt() {
- prompt("Foederati: Remove or recruit a barbarian.")
- view.selected_general = game.selected_general
- view.selected_governor = game.selected_governor
- let from = get_selected_region()
- gen_foederati(from)
- for (let to of ADJACENT[from])
+ prompt("Foederati: Select an army you command...")
+ for (let i = 0; i < 6; ++i) {
+ let id = game.current * 6 + i
+ let where = get_general_location(id)
+ if (is_region(where) && can_foederati_from_region_or_adjacent(where))
+ gen_action_general(id)
+ where = get_governor_location(id)
+ if (is_province(where) && has_lone_militia(where) && can_foederati_from_region_or_adjacent(where))
+ gen_action_militia(id)
+ }
+ },
+ general(id) {
+ push_undo()
+ game.count = id
+ game.where = get_general_location(id)
+ game.state = "foederati_general"
+ },
+ militia(where) {
+ push_undo()
+ game.count = -1
+ game.where = where
+ game.state = "foederati_militia"
+ },
+}
+
+states.foederati_general = {
+ prompt() {
+ if (count_legions_in_army(game.count) > count_barbarians_in_army(game.count))
+ prompt("Foederati: Recruit a barbarian.")
+ else
+ prompt("Foederati: Remove a barbarian.")
+ view.selected_general = game.count
+ gen_foederati(game.where)
+ for (let to of ADJACENT[game.where])
gen_foederati(to)
},
barbarian(id) {
+ push_undo()
let tribe = get_barbarian_tribe(id)
let from = get_barbarian_location(id)
- log("Foederati " + BARBARIAN_NAME[tribe] + " from %" + from)
- if (game.selected_general >= 0 && count_legions_in_army(game.selected_general) > count_barbarians_in_army(game.selected_general))
- set_barbarian_location(id, ARMY + game.selected_general)
- else
+ log("Foederati " + BARBARIAN_NAME[tribe] + " from %" + from + ".")
+ if (count_legions_in_army(game.count) > count_barbarians_in_army(game.count)) {
+ set_barbarian_location(id, ARMY + game.count)
+ } else {
eliminate_barbarian(id)
+ }
+ game.state = "take_actions"
+ },
+}
+
+states.foederati_militia = {
+ prompt() {
+ prompt("Foederati: Remove a barbarian.")
+ gen_foederati(game.where)
+ for (let to of ADJACENT[game.where])
+ gen_foederati(to)
+ },
+ barbarian(id) {
+ push_undo()
+ let tribe = get_barbarian_tribe(id)
+ let from = get_barbarian_location(id)
+ log("Foederati " + BARBARIAN_NAME[tribe] + " from %" + from + ".")
+ eliminate_barbarian(id)
game.state = "take_actions"
},
}
@@ -3923,7 +4012,6 @@ exports.setup = function (seed, scenario, options) {
update_neutral_italia()
game.first = game.current = random(player_count)
- log("First player " + PLAYER_NAMES[game.first] + ".")
return save_game()
}