summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js400
1 files changed, 201 insertions, 199 deletions
diff --git a/rules.js b/rules.js
index e94f42a..2c90984 100644
--- a/rules.js
+++ b/rules.js
@@ -412,62 +412,11 @@ function goto_compromising_gifts() {
game.state = "compromising_gifts"
}
-function goto_conscript() {
- init_command("Conscript")
- game.state = "conscript"
- }
-
-function goto_conscript_space() {
- push_summary()
-
- if (conscript_count() === 1) {
- let p = find_piece(AVAILABLE, game.current, TROOPS)
- log_summary_place(p)
- place_piece(p, game.cmd.where)
- end_conscript_space()
- } else {
- game.cmd.count = 0
- game.state = "conscript_space"
- }
-}
-
-function end_conscript_space() {
- log_space(game.cmd.where, "Conscript")
- pop_summary()
- game.state = "conscript"
-}
-
function goto_demand() {
init_decree("Demand Obedience")
game.state = "demand"
}
-function goto_govern() {
- init_command("Govern")
- game.state = "govern"
-}
-
-function goto_govern_space() {
- push_summary()
-
- if (count_pieces(game.cmd.where, DS, ELITE) === 0) {
- let p = find_piece(AVAILABLE, DS, ELITE)
- log_summary_place(p)
- place_piece(p, game.cmd.where)
- end_govern_space()
- } else {
- game.cmd.count = [0, 0]
- game.state = "govern_space"
- }
-
-}
-
-function end_govern_space() {
- log_space(game.cmd.where, "Govern")
- pop_summary()
- game.state = "govern"
-}
-
function goto_march() {
init_command("March")
game.cmd.pieces = []
@@ -705,47 +654,6 @@ states.compromising_gifts = {
}
}
-
-states.conscript = {
- prompt() {
- view.prompt = "Conscript: Select Tributaries, Qasbah or Dehli to place troops."
-
- if (can_select_cmd_space(1) && can_conscript()) {
- for (let s = first_space; s <= last_space; ++s) {
- if (!is_selected_cmd_space(s) && can_conscript_in_space(s))
- gen_action_space(s)
- }
- }
-
- view.actions.end_conscript = prompt_end_cmd(1)
- },
- space(s) {
- push_undo()
- select_cmd_space(s, 1)
- goto_conscript_space()
- },
- end_conscript: end_command,
-}
-
-states.conscript_space = {
- prompt() {
- view.prompt = `Conscript: Place up to ${conscript_count()} Troops.`
- view.where = game.cmd.where
- view.actions.next = 1
-
- gen_place_piece(DS, TROOPS)
- },
- piece(p) {
- log_summary_place(p)
- place_piece(p, game.cmd.where)
- if (++game.cmd.count >= conscript_count())
- end_conscript_space()
- },
- next() {
- end_conscript_space()
- }
-}
-
states.demand = {
prompt() {
view.prompt = "Demand Obedience: Select a Controlled province with a Governor"
@@ -768,72 +676,6 @@ states.demand = {
end_demand: end_decree,
}
-states.govern = {
- prompt() {
- view.prompt = "Govern: Select a Tributary, Controlled, Mongol Invader region or Dehli."
-
- if (can_select_cmd_space(1) && can_govern()) {
- for (let s = first_space; s <= last_space; ++s) {
- if (!is_selected_cmd_space(s) && can_govern_in_space(s))
- gen_action_space(s)
- }
- }
-
- view.actions.end_govern = prompt_end_cmd(1)
- },
- space(s) {
- push_undo()
- select_cmd_space(s, 1)
- goto_govern_space()
- },
- end_govern: end_command,
-}
-
-states.govern_space = {
- prompt() {
- view.prompt = "Govern: Place a Governor or place a Qasbah and remove two Obedient Units."
- view.where = game.cmd.where
- view.actions.next = 1
-
- if (has_piece(AVAILABLE, DS, ELITE) && game.cmd.count[0] + game.cmd.count[1] === 0)
- gen_place_piece(DS, ELITE)
-
- if (
- has_piece(AVAILABLE, DS, DISC) &&
- has_piece(game.cmd.where, DS, ELITE) &&
- !has_piece(game.cmd.where, DS, DISC)
- ) {
- gen_place_piece(DS, DISC)
- }
-
- if (has_piece(game.cmd.where, DS, ELITE) && game.cmd.count[1] < 2) {
- gen_action_obedient_in_space(game.cmd.where, BK)
- gen_action_obedient_in_space(game.cmd.where, VE)
- }
- },
- piece(p) {
- let t = piece_type(p)
- let f = piece_faction(p)
-
- if (f === DS) {
- log_summary_place(p)
- place_piece(p, game.cmd.where)
- if (t === ELITE)
- end_govern_space()
- else {
- game.cmd.count[0] += 1
- }
- } else {
- log_summary_remove(p)
- remove_piece(p)
- game.cmd.count[1] += 1
- }
- },
- next() {
- end_govern_space()
- }
-}
-
states.march = {
prompt() {
view.prompt = "March: Select a space to move into."
@@ -953,12 +795,12 @@ function gen_any_command() {
view.actions.conscript = can_conscript() ? 1 : 0
view.actions.govern = can_govern() ? 1 : 0
view.actions.march = can_march() ? 1 : 0
- // view.actions.attack = can_attack() ? 1 : 0
+ view.actions.attack = can_attack() ? 1 : 0
} else if (game.current === BK || game.current === VE) {
view.actions.rally = can_rally() ? 1 : 0
view.actions.migrate = can_migrate() ? 1 : 0
view.actions.rebel = can_rebel() ? 1 : 0
- // view.actions.attack = can_attack() ? 1 : 0
+ view.actions.attack = can_attack() ? 1 : 0
}
}
@@ -977,45 +819,6 @@ function select_cmd_space(s, cost) {
game.cmd.where = s
}
-function can_conscript() {
- return has_piece(AVAILABLE, DS, TROOPS)
-}
-
-function can_conscript_in_space(s) {
- if (s === S_DELHI || has_piece(s, DS, DISC) || is_tributary(s))
- return true
-}
-
-function conscript_count() {
- if (game.cmd.where === S_DELHI)
- return 5
- if (has_piece(game.cmd.where, DS, DISC)) {
- return 2
- }
- return 1
-}
-
-function can_govern() {
- for (let s = first_space; s <= last_space; ++s)
- if (can_govern_in_space(s))
- return true
- return false
-}
-
-function can_govern_in_space(s) {
- let is_space = (is_tributary(s) || s === S_DELHI || s === S_MOUNTAIN_PASSES || s === S_PUNJAB || is_faction_control(s, DS))
- if (!is_space)
- return false
-
- if (has_piece(AVAILABLE, DS, ELITE))
- return true
-
- if (has_piece(s, DS, ELITE) && has_piece(AVAILABLE, DS, DISC))
- return true
-
- return false
-}
-
function can_march() {
for (let s = first_space; s <= last_space; ++s)
if (can_march_in_space(s))
@@ -1075,6 +878,205 @@ function end_decree() {
game.state = "main_phase"
}
+/* SHARED COMMANDS */
+
+function can_attack() {}
+
+function can_attack_in_space(s) {}
+
+function goto_attack() {}
+
+
+/* DELHI SULTANATE COMMANDS */
+
+function can_conscript() {
+ return has_piece(AVAILABLE, DS, TROOPS)
+}
+
+function can_conscript_in_space(s) {
+ if (s === S_DELHI || has_piece(s, DS, DISC) || is_tributary(s))
+ return true
+}
+
+function conscript_count() {
+ if (game.cmd.where === S_DELHI)
+ return 5
+ if (has_piece(game.cmd.where, DS, DISC)) {
+ return 2
+ }
+ return 1
+}
+
+function goto_conscript() {
+ init_command("Conscript")
+ game.state = "conscript"
+ }
+
+function goto_conscript_space() {
+ push_summary()
+
+ if (conscript_count() === 1) {
+ let p = find_piece(AVAILABLE, game.current, TROOPS)
+ log_summary_place(p)
+ place_piece(p, game.cmd.where)
+ end_conscript_space()
+ } else {
+ game.cmd.count = 0
+ game.state = "conscript_space"
+ }
+}
+
+states.conscript = {
+ prompt() {
+ view.prompt = "Conscript: Select Tributaries, Qasbah or Dehli to place troops."
+
+ if (can_select_cmd_space(1) && can_conscript()) {
+ for (let s = first_space; s <= last_space; ++s) {
+ if (!is_selected_cmd_space(s) && can_conscript_in_space(s))
+ gen_action_space(s)
+ }
+ }
+
+ view.actions.end_conscript = prompt_end_cmd(1)
+ },
+ space(s) {
+ push_undo()
+ select_cmd_space(s, 1)
+ goto_conscript_space()
+ },
+ end_conscript: end_command,
+}
+
+states.conscript_space = {
+ prompt() {
+ view.prompt = `Conscript: Place up to ${conscript_count()} Troops.`
+ view.where = game.cmd.where
+ view.actions.next = 1
+
+ gen_place_piece(DS, TROOPS)
+ },
+ piece(p) {
+ log_summary_place(p)
+ place_piece(p, game.cmd.where)
+ if (++game.cmd.count >= conscript_count())
+ end_conscript_space()
+ },
+ next() {
+ end_conscript_space()
+ }
+}
+
+function end_conscript_space() {
+ log_space(game.cmd.where, "Conscript")
+ pop_summary()
+ game.state = "conscript"
+}
+
+function can_govern() {
+ for (let s = first_space; s <= last_space; ++s)
+ if (can_govern_in_space(s))
+ return true
+ return false
+}
+
+function can_govern_in_space(s) {
+ let is_space = (is_tributary(s) || s === S_DELHI || s === S_MOUNTAIN_PASSES || s === S_PUNJAB || is_faction_control(s, DS))
+ if (!is_space)
+ return false
+
+ if (has_piece(AVAILABLE, DS, ELITE))
+ return true
+
+ if (has_piece(s, DS, ELITE) && has_piece(AVAILABLE, DS, DISC))
+ return true
+
+ return false
+}
+
+function goto_govern() {
+ init_command("Govern")
+ game.state = "govern"
+}
+
+function goto_govern_space() {
+ push_summary()
+
+ if (count_pieces(game.cmd.where, DS, ELITE) === 0) {
+ let p = find_piece(AVAILABLE, DS, ELITE)
+ log_summary_place(p)
+ place_piece(p, game.cmd.where)
+ end_govern_space()
+ } else {
+ game.cmd.count = [0, 0]
+ game.state = "govern_space"
+ }
+}
+
+states.govern = {
+ prompt() {
+ view.prompt = "Govern: Select a Tributary, Controlled, Mongol Invader region or Dehli."
+
+ if (can_select_cmd_space(1) && can_govern())
+ for (let s = first_space; s <= last_space; ++s)
+ if (!is_selected_cmd_space(s) && can_govern_in_space(s))
+ gen_action_space(s)
+
+ view.actions.end_govern = prompt_end_cmd(1)
+ },
+ space(s) {
+ push_undo()
+ select_cmd_space(s, 1)
+ goto_govern_space()
+ },
+ end_govern: end_command,
+}
+
+states.govern_space = {
+ prompt() {
+ view.prompt = "Govern: Place a Governor or place a Qasbah and remove two Obedient Units."
+ view.where = game.cmd.where
+ view.actions.next = 1
+
+ if (has_piece(AVAILABLE, DS, ELITE) && game.cmd.count[0] + game.cmd.count[1] === 0)
+ gen_place_piece(DS, ELITE)
+
+ if (
+ has_piece(AVAILABLE, DS, DISC) &&
+ has_piece(game.cmd.where, DS, ELITE) &&
+ !has_piece(game.cmd.where, DS, DISC)
+ ) {
+ gen_place_piece(DS, DISC)
+ }
+
+ if (has_piece(game.cmd.where, DS, ELITE) && game.cmd.count[1] < 2) {
+ gen_action_obedient_in_space(game.cmd.where, BK)
+ gen_action_obedient_in_space(game.cmd.where, VE)
+ }
+ },
+ piece(p) {
+ if (piece_faction(p) === DS) {
+ log_summary_place(p)
+ place_piece(p, game.cmd.where)
+ if (piece_type(p) === ELITE)
+ end_govern_space()
+ else {
+ game.cmd.count[0] += 1
+ }
+ } else {
+ log_summary_remove(p)
+ remove_piece(p)
+ game.cmd.count[1] += 1
+ }
+ },
+ next: end_govern_space
+}
+
+function end_govern_space() {
+ log_space(game.cmd.where, "Govern")
+ pop_summary()
+ game.state = "govern"
+}
+
/* REBEL COMMANDS */
function can_migrate() {