summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js221
1 files changed, 124 insertions, 97 deletions
diff --git a/rules.js b/rules.js
index d3d7456..c18d137 100644
--- a/rules.js
+++ b/rules.js
@@ -1076,8 +1076,7 @@ states.take_actions_governor = {
// Place Governor
if (where === AVAILABLE) {
- if (sip >= 1)
- view.actions.place = 1
+ gen_place_governor()
}
if (is_province(where)) {
@@ -1113,11 +1112,8 @@ states.take_actions_governor = {
// Initiate Battle with Militia not stacked with General
if (!has_militia_battled(where)) {
- if (has_militia(where) && !is_own_general(get_capital_general(where))) {
- if (has_enemy_army_in_province(where))
- if (mip >= 1)
- view.actions.initiate_battle = 1
- }
+ if (has_militia(where) && !is_own_general(get_capital_general(where)))
+ gen_initiate_battle(where)
}
}
},
@@ -1125,7 +1121,12 @@ states.take_actions_governor = {
end_actions: action_take_actions_end_actions,
card: action_take_actions_card,
governor: action_take_actions_governor,
- general: action_take_actions_general,
+ general(id) {
+ if (is_own_general(id))
+ action_take_actions_general(id)
+ else
+ goto_battle_vs_general(get_governor_location(game.who), -1, id)
+ },
recruit() {
push_undo()
@@ -1181,6 +1182,19 @@ states.take_actions_governor = {
game.misc = { attacker: -1, where: get_governor_location(game.who) }
set_militia_battled(get_governor_location(game.who))
},
+ region(where) {
+ push_undo()
+ spend_ip(SENATE, 1)
+ game.misc = { spend: 1, where: where }
+ game.state = "place_governor_spend"
+ },
+
+ barbarian(id) {
+ goto_battle_vs_barbarian(get_governor_location(game.who), -1, id)
+ },
+ rival_emperor(id) {
+ goto_battle_vs_rival_emperor(get_governor_location(game.who), -1, id)
+ },
}
states.take_actions_general = {
@@ -1224,19 +1238,10 @@ states.take_actions_general = {
if (!has_general_battled(game.who)) {
// Move Army
- if (mip >= 1) {
- for (let to of ADJACENT[where]) {
- if (!is_sea(to))
- gen_move_to_region(to)
- else if (mip >= 2)
- gen_move_to_region(to)
- }
- }
+ gen_move_army()
// Initiate Battle
- if (has_enemy_army_in_province(where))
- if (mip >= 1)
- view.actions.initiate_battle = 1
+ gen_initiate_battle(where)
// Free Action: Enter/Leave Capital
if (is_province(where)) {
@@ -1255,8 +1260,12 @@ states.take_actions_general = {
end_actions: action_take_actions_end_actions,
card: action_take_actions_card,
governor: action_take_actions_governor,
- general: action_take_actions_general,
-
+ general(id) {
+ if (is_own_general(id))
+ action_take_actions_general(id)
+ else
+ goto_battle_vs_general(get_general_location(game.who), game.who, id)
+ },
recruit() {
push_undo()
log("Recruited General " + (game.who % 6) + ".")
@@ -1300,17 +1309,30 @@ states.take_actions_general = {
push_undo()
set_general_outside_capital(game.who)
},
+
initiate_battle() {
push_undo()
spend_ip(MILITARY, 1)
game.state = "initiate_battle"
game.misc = { attacker: game.who, where: get_general_location(game.who) }
- set_general_battled(game.who)
},
+
+ barbarian(id) { goto_battle_vs_barbarian(get_general_location(game.who), game.who, id) },
+ rival_emperor(id) { goto_battle_vs_rival_emperor(get_general_location(game.who), game.who, id) },
+ militia(where) { goto_battle_vs_militia(get_general_location(game.who), game.who) },
}
// ACTION: PLACE GOVERNOR
+function gen_place_governor() {
+ let sip = game.ip[SENATE]
+ if (sip >= 1) {
+ for (let where = 0; where < 12; ++where)
+ if (can_place_governor(where))
+ gen_action_region(where)
+ }
+}
+
function reduce_support(where) {
if (game.support[where] === 1)
remove_governor(where)
@@ -1404,13 +1426,19 @@ states.place_governor_spend = {
prompt() {
let [ mip, sip, pip ] = game.ip
let need = calc_needed_votes(game.misc.where)
+ let votes = game.misc.spend
+ if (game.misc.where === ITALIA)
+ votes += count_own_basilicas()
view.selected_governor = game.who
view.selected_region = game.misc.where
- prompt("Place Governor: " + game.misc.spend + " IP spent; " + need + " votes needed.")
+
+ prompt(`Place Governor: ${sip} Senate. Rolling ${votes} dice. ${need} votes needed.`)
+
if (sip >= 1)
view.actions.spend = 1
else
view.actions.spend = 0
+
view.actions.roll = 1
},
spend() {
@@ -1505,6 +1533,19 @@ states.create_army = {
// ACTION: MOVE ARMY
+function gen_move_army() {
+ let mip = game.ip[MILITARY]
+ let from = get_general_location(game.who)
+ if (mip >= 1) {
+ for (let to of ADJACENT[from]) {
+ if (!is_sea(to))
+ gen_move_to_region(to)
+ else if (mip >= 2)
+ gen_move_to_region(to)
+ }
+ }
+}
+
function gen_move_to_region(to) {
if (is_province(to) && can_enter_capital(to))
gen_action_capital(to)
@@ -1516,15 +1557,7 @@ states.move_army_at_sea = {
let [ mip, sip, pip ] = game.ip
prompt("Move Army.")
view.selected_general = game.who
- let from = get_general_location(game.who)
- for (let to of ADJACENT[from]) {
- if (is_sea(to)) {
- if (mip >= 2)
- gen_move_to_region(to)
- } else {
- gen_move_to_region(to)
- }
- }
+ gen_move_army()
},
region(to) {
push_undo()
@@ -1552,54 +1585,55 @@ function move_army_to(who, to, go_inside) {
// === ACTION: INITIATE BATTLE ===
-states.initiate_battle = {
- prompt() {
- prompt("Initiate Battle in " + REGION_NAME[game.misc.where] + "!")
+function goto_battle_vs_general(where, attacker, target) {
+ push_undo()
+ log("Initiate Battle vs " + GENERAL_NAME[target] + " in S" + where)
+ goto_battle("general", where, attacker, target)
+}
+
+function goto_battle_vs_barbarian(where, attacker, target) {
+ push_undo()
+ log("Initiate Battle vs " + BARBARIAN_NAME[target] + " in S" + where)
+ goto_battle("barbarians", where, attacker, get_barbarian_tribe(target))
+}
+
+function goto_battle_vs_rival_emperor(where, attacker, target) {
+ push_undo()
+ log("Initiate Battle vs Rival Emperor in S" + where)
+ goto_battle("rival_emperor", where, attacker, target)
+}
+
+function goto_battle_vs_militia(where, attacker) {
+ push_undo()
+ log("Initiate Battle vs Militia in S" + where)
+ goto_battle("militia", where, attacker, -1)
+}
+function goto_battle(type, where, attacker, target) {
+ spend_ip(MILITARY, 1)
+ game.misc = { type, where, attacker, target }
+ game.state = "battle"
+ if (attacker >= 0)
+ set_general_battled(attacker)
+ else
+ set_militia_battled(where)
+}
+
+function gen_initiate_battle(where) {
+ if (game.ip[MILITARY] >= 1) {
for_each_general((id, loc) => {
- if (loc === game.misc.where && is_enemy_general(id))
+ if (loc === where && is_enemy_general(id))
gen_action_general(id)
})
-
for_each_barbarian((id, loc) => {
- if (loc === game.misc.where)
+ if (loc === where)
gen_action_barbarian(id)
})
-
- if (is_enemy_province(game.misc.where)) {
- if (has_militia(game.misc.where) && get_capital_general(game.misc.where) < 0)
- gen_action_militia(game.misc.where)
+ if (is_enemy_province(where)) {
+ if (has_militia(where) && get_capital_general(where) < 0)
+ gen_action_militia(where)
}
- },
- general(id) {
- push_undo()
- log("Initiate Battle vs " + GENERAL_NAME[id] + " in S" + game.misc.where)
- game.misc.type = "general"
- game.misc.target = id
- game.state = "battle"
- },
- barbarian(id) {
- push_undo()
- let tribe = get_barbarian_tribe(id)
- log("Initiate Battle vs " + BARBARIAN_NAME[id] + " in S" + game.misc.where)
- game.misc.type = "barbarian"
- game.misc.target = tribe
- game.state = "battle"
- },
- rival_emperor(id) {
- push_undo()
- log("Initiate Battle vs Rival Emperor in S" + game.misc.where)
- game.misc.type = "rival_emperor"
- game.misc.target = id
- game.state = "battle"
- },
- militia(where) {
- push_undo()
- log("Initiate Battle vs Militia in S" + game.misc.where)
- game.misc.type = "militia"
- game.misc.target = -1
- game.state = "battle"
- },
+ }
}
states.battle = {
@@ -1730,48 +1764,41 @@ function gen_hits_barbarians(tribe) {
gen_action_barbarian(id)
}
+// TODO: auto-end if all possible hits assigned
+
function gen_hits_general(general) {
let army = ARMY + general
- let done = true
// TODO: castra
- if (!done) {
- if (is_general_inside_capital(general) && has_militia(game.misc.where)) {
- gen_action_militia(game.misc.where)
- done = true
- }
+ if (is_general_inside_capital(general) && has_militia(game.misc.where)) {
+ gen_action_militia(game.misc.where)
+ return false
}
- if (!done) {
- for (let id = 0; id < game.barbarians.length; ++id) {
- if (get_barbarian_location(id) === army) {
- gen_action_barbarian(id)
- done = true
- }
+ for (let id = 0; id < game.barbarians.length; ++id) {
+ if (get_barbarian_location(id) === army) {
+ gen_action_barbarian(id)
+ return false
}
}
// NOTE: reduce all legions before eliminating any
- if (!done) {
- for (let id = 0; id < 33; ++id) {
- if (get_legion_location(id) === army && !is_legion_reduced(id)) {
- gen_action_legion(id)
- done = true
- }
+ for (let id = 0; id < 33; ++id) {
+ if (get_legion_location(id) === army && !is_legion_reduced(id)) {
+ gen_action_legion(id)
+ return false
}
}
- if (!done) {
- for (let id = 0; id < 33; ++id) {
- if (get_legion_location(id) === army && is_legion_reduced(id)) {
- gen_action_legion(id)
- done = true
- }
+ for (let id = 0; id < 33; ++id) {
+ if (get_legion_location(id) === army && is_legion_reduced(id)) {
+ gen_action_legion(id)
+ return false
}
}
- return done
+ return true
}
states.assign_hits_on_attacker = {