summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoël Simoneau <simoneaujoel@gmail.com>2024-10-26 09:13:10 -0400
committerJoël Simoneau <simoneaujoel@gmail.com>2024-10-26 09:13:10 -0400
commitd242a0adbdc9fbf43e6fbf1d0eaccdc624a6c68a (patch)
tree1254ab611f1f611c194f488c2dee2959b76d083a
parent0355e16c0bb38f34d9317a8ee54f03c8836c1261 (diff)
downloadvijayanagara-d242a0adbdc9fbf43e6fbf1d0eaccdc624a6c68a.tar.gz
Rally.
-rw-r--r--const.js8
-rw-r--r--play.js4
-rw-r--r--rules.js111
3 files changed, 111 insertions, 12 deletions
diff --git a/const.js b/const.js
index 32003b8..2b99fd0 100644
--- a/const.js
+++ b/const.js
@@ -21,10 +21,10 @@ const AVAILABLE = -1
const OUT_OF_PLAY = -2
const ANY_PIECES = [ DISC, ELITE, TROOPS ]
const PIECE_FACTION_TYPE_NAME = [
- [ "Qasbah", "Governors", "Troops" ],
- [ "Fort", "Amirs", null ],
- [ "Temple", "Rajas", null ],
- [ null, null, "Invaders"]
+ [ "Qasbah", "Governor", "Troops" ],
+ [ "Fort", "Amir", null ],
+ [ "Temple", "Raja", null ],
+ [ null, null, "Invader" ]
]
// Sequence of Play options
diff --git a/play.js b/play.js
index f3e654b..9253d0a 100644
--- a/play.js
+++ b/play.js
@@ -980,6 +980,10 @@ function on_update() {
action_button("conscript", "Conscript")
action_button("end_conscript", "End Conscript")
+ // Command buttons
+ action_button("rally", "Rally")
+ action_button("end_rally", "End Rally")
+
action_button("next", "Next")
action_button("undo", "Undo")
diff --git a/rules.js b/rules.js
index b7b4dfb..9937e19 100644
--- a/rules.js
+++ b/rules.js
@@ -384,6 +384,31 @@ function goto_conscript() {
game.state = "conscript"
}
+ 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.op.where)
+ end_rally_space()
+ } else {
+ game.op.count = 0
+ game.state = "rally_space"
+ }
+ }
+
+ function end_rally_space() {
+ log_space(game.op.where, "Rally")
+ pop_summary()
+ game.state = "rally"
+ }
+
/* STATES */
states.eligible = {
@@ -392,8 +417,10 @@ states.eligible = {
prompt() {
if (did_option(SOP_COMMAND_DECREE)) {
view.prompt = `${data.card_title[this_card()]}: Event or Command.`
+ view.actions.event_command = 1
} else if (did_option(SOP_EVENT_OR_COMMAND)) {
view.prompt = `${data.card_title[this_card()]}: Command & Decree.`
+ view.actions.command_decree = 1
} else {
view.prompt = `${data.card_title[this_card()]}: Event or Command & Decree.`
view.actions.command_decree = 1
@@ -429,6 +456,7 @@ states.command_decree = {
gen_any_command()
},
conscript: goto_conscript,
+ rally: goto_rally,
}
states.event_command = {
@@ -438,6 +466,7 @@ states.event_command = {
gen_any_command()
},
conscript: goto_conscript,
+ rally: goto_rally,
}
states.lim_command = {
@@ -447,6 +476,7 @@ states.lim_command = {
gen_any_command()
},
conscript: goto_conscript,
+ rally: goto_rally,
}
states.conscript = {
@@ -489,6 +519,49 @@ states.conscript_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.op.where
+ view.actions.next = 1
+
+ gen_place_piece(game.current, ELITE)
+ },
+ piece(p) {
+ log_summary_place(p)
+ place_piece(p, game.op.where)
+ if (++game.op.count >= rally_count())
+ end_rally_space()
+ },
+ next() {
+ end_rally_space()
+ }
+}
+
/* COMMANDS */
function init_command(type) {
@@ -504,7 +577,7 @@ function gen_any_command() {
if (game.current === DS) {
view.actions.conscript = can_conscript() ? 1 : 0
} else if (game.current === BK || game.current === VE) {
- // view.actions.rally = can_rally() ? 1 : 0
+ view.actions.rally = can_rally() ? 1 : 0
}
}
@@ -524,9 +597,7 @@ function select_cmd_space(s, cost) {
}
function can_conscript() {
- if (!has_piece(AVAILABLE, DS, TROOPS))
- return false
- return true
+ return has_piece(AVAILABLE, DS, TROOPS)
}
function can_conscript_in_space(s) {
@@ -543,6 +614,30 @@ function conscript_count() {
return 1
}
+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.op.where === S_MAHARASHTRA ? 1 : 0)
+ } else if (game.current === VE) {
+ count += (game.op.where === S_KARNATAKA ? 1 : 0)
+ count += (has_piece(game.op.where, VE, DISC) ? 1 : 0)
+ }
+ return count
+}
+
function prompt_end_cmd(cost) {
if (!view.actions.space) {
if (game.op.limited && game.op.spaces && game.op.spaces.length > 0)
@@ -1153,10 +1248,10 @@ const AVAILABLE = -1
const OUT_OF_PLAY = -2
const ANY_PIECES = [ DISC, ELITE, TROOPS ]
const PIECE_FACTION_TYPE_NAME = [
- [ "Qasbah", "Governors", "Troops" ],
- [ "Fort", "Amirs", null ],
- [ "Temple", "Rajas", null ],
- [ null, null, "Invaders"]
+ [ "Qasbah", "Governor", "Troops" ],
+ [ "Fort", "Amir", null ],
+ [ "Temple", "Raja", null ],
+ [ null, null, "Invader" ]
]
// Sequence of Play options