summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js188
1 files changed, 96 insertions, 92 deletions
diff --git a/rules.js b/rules.js
index 9fbf357..6d33f64 100644
--- a/rules.js
+++ b/rules.js
@@ -513,31 +513,6 @@ function goto_strategic_assistance() {
}
-function goto_rally() {
- init_command("Rally")
- game.state = "rally"
-}
-
-function goto_rally_space() {
- push_summary()
-
- if (rally_count() === 1) {
- let p = find_piece(AVAILABLE, game.current, ELITE)
- log_summary_place(p)
- place_piece(p, game.cmd.where)
- end_rally_space()
- } else {
- game.cmd.count = 0
- game.state = "rally_space"
- }
-}
-
-function end_rally_space() {
- log_space(game.cmd.where, "Rally")
- pop_summary()
- game.state = "rally"
-}
-
function goto_rebel() {
init_command("Rebel")
game.state = "rebel"
@@ -907,49 +882,6 @@ states.march_space = {
}
}
-states.rally = {
- prompt() {
- if (game.current === BK)
- view.prompt = "Rally: Select Maharashtra or a Province with your presence"
- else if (game.current === VE)
- view.prompt = "Rally: Select Karnataka or a Province with your presence"
-
- if (can_select_cmd_space(1) && can_rally()) {
- for (let s = first_space; s <= last_space; ++s) {
- if (!is_selected_cmd_space(s) && can_rally_in_space(s))
- gen_action_space(s)
- }
- }
-
- view.actions.end_rally = prompt_end_cmd(1)
- },
- space(s) {
- push_undo()
- select_cmd_space(s, 1)
- goto_rally_space()
- },
- end_rally: end_command,
-}
-
-states.rally_space = {
- prompt() {
- view.prompt = `Rally: Place up to ${rally_count()} ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}`
- view.where = game.cmd.where
- view.actions.next = 1
-
- gen_place_piece(game.current, ELITE)
- },
- piece(p) {
- log_summary_place(p)
- place_piece(p, game.cmd.where)
- if (++game.cmd.count >= rally_count())
- end_rally_space()
- },
- next() {
- end_rally_space()
- }
-}
-
states.rebel = {
prompt() {
view.prompt = "Rebel: Select a Province where you are in majority."
@@ -1098,30 +1030,6 @@ function can_march_in_space(s) {
return false
}
-function can_rally() {
- return has_piece(AVAILABLE, game.current, ELITE)
-}
-
-function can_rally_in_space(s) {
- if (game.current === BK) {
- return (s === S_MAHARASHTRA || has_piece(s, BK, ELITE) || has_piece(s, BK, DISC))
- } else if (game.current === VE) {
- return (s === S_KARNATAKA || has_piece(s, VE, ELITE) || has_piece(s, VE, DISC))
- }
-}
-
-function rally_count() {
- // TODO : Add rally with control + 1
- let count = 1
- if (game.current === BK) {
- count += (game.cmd.where === S_MAHARASHTRA ? 1 : 0)
- } else if (game.current === VE) {
- count += (game.cmd.where === S_KARNATAKA ? 1 : 0)
- count += (has_piece(game.cmd.where, VE, DISC) ? 1 : 0)
- }
- return count
-}
-
function can_rebel() {
// todo: implement dynasty logic
for (let s = first_space; s <= last_space; ++s) {
@@ -1164,6 +1072,101 @@ function end_decree() {
game.state = "main_phase"
}
+/* REBEL COMMANDS */
+
+function can_rally() {
+ return has_piece(AVAILABLE, game.current, ELITE)
+}
+
+function can_rally_in_space(s) {
+ if (game.current === BK) {
+ return (s === S_MAHARASHTRA || has_piece(s, BK, ELITE) || has_piece(s, BK, DISC))
+ } else if (game.current === VE) {
+ return (s === S_KARNATAKA || has_piece(s, VE, ELITE) || has_piece(s, VE, DISC))
+ }
+}
+
+function rally_count() {
+ let count = 1
+ if (game.current === BK) {
+ count += (game.cmd.where === S_MAHARASHTRA ? 1 : 0)
+ } else if (game.current === VE) {
+ count += (game.cmd.where === S_KARNATAKA ? 1 : 0)
+ count += (has_piece(game.cmd.where, VE, DISC) ? 1 : 0)
+ }
+ count += (is_faction_control(game.cmd.where, game.current) ? 1 : 0)
+ return count
+}
+
+function goto_rally() {
+ init_command("Rally")
+ game.state = "rally"
+}
+
+function goto_rally_space() {
+ push_summary()
+
+ if (rally_count() === 1) {
+ let p = find_piece(AVAILABLE, game.current, ELITE)
+ log_summary_place(p)
+ place_piece(p, game.cmd.where)
+ end_rally_space()
+ } else {
+ game.cmd.count = 0
+ game.state = "rally_space"
+ }
+}
+
+function end_rally_space() {
+ log_space(game.cmd.where, "Rally")
+ pop_summary()
+ game.state = "rally"
+}
+
+states.rally = {
+ prompt() {
+ if (game.current === BK)
+ view.prompt = "Rally: Select Maharashtra or a Province with your presence"
+ else if (game.current === VE)
+ view.prompt = "Rally: Select Karnataka or a Province with your presence"
+
+ if (can_select_cmd_space(1) && can_rally()) {
+ for (let s = first_space; s <= last_space; ++s) {
+ if (!is_selected_cmd_space(s) && can_rally_in_space(s))
+ gen_action_space(s)
+ }
+ }
+
+ view.actions.end_rally = prompt_end_cmd(1)
+ },
+ space(s) {
+ push_undo()
+ select_cmd_space(s, 1)
+ goto_rally_space()
+ },
+ end_rally: end_command,
+}
+
+states.rally_space = {
+ prompt() {
+ view.prompt = `Rally: Place up to ${rally_count()} ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}`
+ view.where = game.cmd.where
+ gen_place_piece(game.current, ELITE)
+
+ if (game.cmd.count > 0)
+ view.actions.next = 1
+ },
+ piece(p) {
+ log_summary_place(p)
+ place_piece(p, game.cmd.where)
+ if (++game.cmd.count >= rally_count())
+ end_rally_space()
+ },
+ next() {
+ end_rally_space()
+ }
+}
+
/* DECREES */
function init_decree(type) {
@@ -1359,6 +1362,7 @@ function can_build_in_space(s) {
function goto_build() {
init_decree("Build")
+ game.decree.n = 1
game.state = "build"
}