summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js163
1 files changed, 157 insertions, 6 deletions
diff --git a/rules.js b/rules.js
index 2abc607..15b79ab 100644
--- a/rules.js
+++ b/rules.js
@@ -191,6 +191,30 @@ const ADJACENT = [
/* PONTUS_EUXINUS */ [ ASIA, THRACIA, GALATIA, GOTHS_HOMELAND, SASSANIDS_HOMELAND ],
]
+const PRETENDER_ADJACENT = [
+ /* ITALIA */ [ GALLIA, PANNONIA, MARE_OCCIDENTALE ],
+ /* ASIA */ [ THRACIA, GALATIA, MARE_ORIENTALE, PONTUS_EUXINUS ],
+ /* GALLIA */ [ ITALIA, PANNONIA, HISPANIA, BRITANNIA, FRANKS_HOMELAND, MARE_OCCIDENTALE, OCEANUS_ATLANTICUS ],
+ /* MACEDONIA */ [ PANNONIA, THRACIA, MARE_OCCIDENTALE, MARE_ORIENTALE ],
+ /* PANNONIA */ [ ITALIA, GALLIA, MACEDONIA, THRACIA, ALAMANNI_HOMELAND, FRANKS_HOMELAND, MARE_OCCIDENTALE ],
+ /* THRACIA */ [ ASIA, MACEDONIA, PANNONIA, ALAMANNI_HOMELAND, GOTHS_HOMELAND, MARE_ORIENTALE, PONTUS_EUXINUS ],
+ /* AEGYPTUS */ [ AFRICA, SYRIA, NOMADS_HOMELAND, MARE_ORIENTALE ],
+ /* AFRICA */ [ AEGYPTUS, HISPANIA, NOMADS_HOMELAND, MARE_OCCIDENTALE, MARE_ORIENTALE, OCEANUS_ATLANTICUS ],
+ /* HISPANIA */ [ GALLIA, AFRICA, MARE_OCCIDENTALE, OCEANUS_ATLANTICUS ],
+ /* BRITANNIA */ [ GALLIA, OCEANUS_ATLANTICUS ],
+ /* GALATIA */ [ ASIA, SYRIA, SASSANIDS_HOMELAND, MARE_ORIENTALE, PONTUS_EUXINUS ],
+ /* SYRIA */ [ AEGYPTUS, GALATIA, SASSANIDS_HOMELAND, MARE_ORIENTALE ],
+ /* ALAMANNI_HOMELAND */ [ PANNONIA, THRACIA, FRANKS_HOMELAND, GOTHS_HOMELAND ],
+ /* FRANKS_HOMELAND */ [ GALLIA, PANNONIA, ALAMANNI_HOMELAND ],
+ /* GOTHS_HOMELAND */ [ THRACIA, ALAMANNI_HOMELAND, PONTUS_EUXINUS ],
+ /* NOMADS_HOMELAND */ [ AEGYPTUS, AFRICA, OCEANUS_ATLANTICUS ],
+ /* SASSANIDS_HOMELAND */ [ GALATIA, SYRIA, PONTUS_EUXINUS ],
+ /* MARE_OCCIDENTALE */ [ ITALIA, GALLIA, MACEDONIA, PANNONIA, AFRICA, HISPANIA, MARE_ORIENTALE, OCEANUS_ATLANTICUS ],
+ /* MARE_ORIENTALE */ [ ASIA, MACEDONIA, THRACIA, AEGYPTUS, AFRICA, GALATIA, SYRIA, MARE_OCCIDENTALE ],
+ /* OCEANUS_ATLANTICUS */ [ GALLIA, AFRICA, HISPANIA, BRITANNIA, NOMADS_HOMELAND, MARE_OCCIDENTALE ],
+ /* PONTUS_EUXINUS */ [ ASIA, THRACIA, GALATIA, GOTHS_HOMELAND, SASSANIDS_HOMELAND ],
+]
+
// BARBARIANS
const ALAMANNI = 0
@@ -701,6 +725,13 @@ function get_province_governor(where) {
return find_governor((id, loc) => loc === where)
}
+function get_province_player(where) {
+ let gov = find_governor((id, loc) => loc === where)
+ if (gov >= 0)
+ return gov / 6 | 0
+ return -1
+}
+
function get_capital_general(where) {
return find_general((id, loc, cap) => loc === where && cap)
}
@@ -785,6 +816,13 @@ function has_enemy_army_in_province(where) {
return false
}
+function has_available_governor() {
+ for (let i = 0; i < 6; ++i)
+ if (get_governor_location(game.current * 6 + i) === AVAILABLE)
+ return true
+ return false
+}
+
function spend_ip(type, n) {
game.ip[type] -= n
}
@@ -1013,7 +1051,7 @@ function find_seat_of_power() {
function is_possible_seat_of_power(from) {
if (is_own_province(from) && get_support(from) >= 3)
- for (let to of ADJACENT[from])
+ for (let to of PRETENDER_ADJACENT[from])
if (is_own_province(to) && get_support(to) >= 3)
return true
return false
@@ -1021,7 +1059,7 @@ function is_possible_seat_of_power(from) {
function is_expand_pretender_province(from) {
if (get_support(from) >= 3 && !is_pretender_province(from) && is_own_province(from))
- for (let to of ADJACENT[from])
+ for (let to of PRETENDER_ADJACENT[from])
if (is_pretender_province(to) && is_own_province(to))
return true
return false
@@ -1665,8 +1703,105 @@ states.take_actions = {
// FREE ACTION: ENTER PROVINCIAL CAPITAL
function enter_capital() {
+ let where = get_general_location(game.selected_general)
+
set_general_inside_capital(game.selected_general)
- // TODO: seat of power / breakaway
+
+ if (is_pretender_province(where) && is_enemy_province(where)) {
+ game.count = get_province_governor(where) / 6 | 0
+ game.where = where
+ if (is_seat_of_power(where))
+ game.state = "occupy_seat_of_power_1"
+ else
+ game.state = "occupy_breakaway"
+ }
+}
+
+function resume_occupy_seat_of_power() {
+ for (let where = 1; where < 12; ++where) {
+ if (is_breakaway(where) && (get_province_governor(where) / 6 | 0) === game.count) {
+ game.state = "occupy_seat_of_power_2"
+ return
+ }
+ }
+ goto_replace_pretender()
+}
+
+states.occupy_seat_of_power_1 = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: Remove Seat of Power and pretender.")
+ view.color = POPULACE
+ gen_action_region(game.where)
+ },
+ region(where) {
+ push_undo()
+ log("Removed Seat of Power in S" + where)
+ remove_seat_of_power(where)
+ remove_governor(where)
+ resume_occupy_seat_of_power()
+ },
+}
+
+states.occupy_seat_of_power_2 = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: Remove Breakaway markers.")
+ view.color = POPULACE
+ for (let where = 1; where < 12; ++where)
+ if (is_breakaway(where) && (get_province_governor(where) / 6 | 0) === game.count)
+ gen_action_region(where)
+ },
+ region(where) {
+ push_undo()
+ log("Removed Breakaway in S" + where)
+ remove_breakaway(where)
+ resume_occupy_seat_of_power()
+ },
+}
+
+states.occupy_breakaway = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: Remove Breakaway marker.")
+ view.color = POPULACE
+ gen_action_region(game.where)
+ },
+ region(where) {
+ push_undo()
+ log("Removed Breakaway in S" + where)
+ remove_breakaway(where)
+ remove_governor(where)
+ goto_replace_pretender()
+ },
+}
+
+function goto_replace_pretender() {
+ if (has_available_governor())
+ game.state = "replace_pretender_governor"
+ else
+ game.state = "take_actions"
+}
+
+states.replace_pretender_governor = {
+ prompt() {
+ prompt("Occupy Pretender Provincial Capital: You may place an available Governor.")
+ view.selected_region = game.where
+ view.color = SENATE
+ for (let i = 0; i < 6; ++i) {
+ let id = game.current * 6 + i
+ if (get_governor_location(id) === AVAILABLE)
+ gen_action_governor(id)
+ }
+ view.actions.pass = 1
+ },
+ governor(id) {
+ push_undo()
+ log("Placed Governor in S" + game.where)
+ set_governor_location(id, game.where)
+ game.state = "take_actions"
+ },
+ pass() {
+ push_undo()
+ game.state = "take_actions"
+ },
}
// ACTION: IMPROVE SUPPORT
@@ -1687,7 +1822,6 @@ function recall_governor() {
spend_ip(SENATE, 2)
set_placed_governor(where)
remove_governor(where)
- update_neutral_italia()
}
// ACTION: PLACE GOVERNOR
@@ -1719,6 +1853,11 @@ function remove_governor(where) {
remove_all_mobs(where)
remove_quaestor(where)
+ // TODO: manual?
+ if (is_seat_of_power(where))
+ auto_remove_pretender_empire(where)
+ remove_breakaway(where)
+
let old_governor = get_province_governor(where)
if (old_governor >= 0) {
set_governor_location(old_governor, AVAILABLE)
@@ -2136,6 +2275,18 @@ states.mob = {
// CARD: PRETENDER
+function auto_remove_pretender_empire(seat) {
+ let pretender = get_province_governor(seat) / 6 | 0
+ log("Removed Seat of Power in S" + seat)
+ remove_seat_of_power(seat)
+ for (let where = 1; where < 12; ++where) {
+ if (is_breakaway(where) && (get_province_governor(where) / 6 | 0) === pretender) {
+ log("Removed Breakaway in S" + where)
+ remove_breakaway(where)
+ }
+ }
+}
+
function can_play_pretender() {
if (is_emperor_player())
return false
@@ -2171,7 +2322,7 @@ states.pretender_seat_of_power = {
function goto_pretender_breakaway() {
let seat = find_seat_of_power()
- for (let where of ADJACENT[seat]) {
+ for (let where of PRETENDER_ADJACENT[seat]) {
if (get_support(where) >= 3 && !is_breakaway(where) && is_own_province(where)) {
game.state = "pretender_breakaway"
return
@@ -2185,7 +2336,7 @@ states.pretender_breakaway = {
prompt("Pretender: Place Breakaway markers.")
view.color = POPULACE
let seat = find_seat_of_power()
- for (let where of ADJACENT[seat])
+ for (let where of PRETENDER_ADJACENT[seat])
if (get_support(where) >= 3 && !is_breakaway(where) && is_own_province(where))
gen_action_region(where)
},