diff options
-rw-r--r-- | play.js | 2 | ||||
-rw-r--r-- | rules.js | 170 |
2 files changed, 152 insertions, 20 deletions
@@ -982,6 +982,8 @@ function on_update() { // DS buttons action_button("conscript", "Conscript") action_button("end_conscript", "End Conscript") + action_button("govern", "Govern") + action_button("end_govern", "End Govern") action_button("march", "March") action_button("end_march", "End March") @@ -383,7 +383,7 @@ function goto_conscript() { game.state = "conscript" } - function goto_conscript_space() { +function goto_conscript_space() { push_summary() if (conscript_count() === 1) { @@ -395,38 +395,64 @@ function goto_conscript() { game.cmd.count = 0 game.state = "conscript_space" } - } +} - function end_conscript_space() { +function end_conscript_space() { log_space(game.cmd.where, "Conscript") pop_summary() game.state = "conscript" - } +} + +function goto_govern() { + init_command("Govern") + game.state = "govern" +} - function goto_march() { +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 = [] game.state = "march" - } +} - function goto_march_space() { +function goto_march_space() { push_summary() game.cmd_count = 0 game.state = "march_space" - } +} - function end_march_space() { +function end_march_space() { log_space(game.cmd.where, "March") pop_summary() game.state = "march" - } +} - function goto_rally() { +function goto_rally() { init_command("Rally") game.state = "rally" - } +} - function goto_rally_space() { +function goto_rally_space() { push_summary() if (rally_count() === 1) { @@ -438,13 +464,13 @@ function goto_conscript() { game.cmd.count = 0 game.state = "rally_space" } - } +} - function end_rally_space() { +function end_rally_space() { log_space(game.cmd.where, "Rally") pop_summary() game.state = "rally" - } +} function goto_rebel() { init_command("Rebel") @@ -513,6 +539,7 @@ states.command_decree = { build: goto_build, collect: goto_collect, conscript: goto_conscript, + govern: goto_govern, march: goto_march, rally: goto_rally, rebel: goto_rebel, @@ -527,6 +554,7 @@ states.event_command = { gen_any_command() }, conscript: goto_conscript, + govern: goto_govern, march: goto_march, rally: goto_rally, rebel: goto_rebel, @@ -539,6 +567,7 @@ states.lim_command = { gen_any_command() }, conscript: goto_conscript, + govern: goto_govern, march: goto_march, rally: goto_rally, rebel: goto_rebel, @@ -628,6 +657,76 @@ states.conscript_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) { + for (let p of iter_faction_pieces(BK, ELITE)) + if (piece_space(p) === game.cmd.where && !is_rebel(p)) + gen_action_piece(p) + for (let p of iter_faction_pieces(VE, ELITE)) + if (piece_space(p) === game.cmd.where && !is_rebel(p)) + gen_action_piece(p) + } + }, + 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." @@ -786,6 +885,7 @@ function init_command(type) { function gen_any_command() { if (game.current === DS) { view.actions.conscript = can_conscript() ? 1 : 0 + view.actions.govern = can_govern() ? 1 : 0 view.actions.march = can_march() ? 1 : 0 } else if (game.current === BK || game.current === VE) { view.actions.rally = can_rally() ? 1 : 0 @@ -831,12 +931,31 @@ function can_collect() { } function collect_count() { - console.log(game.prosperity) let c = Math.floor(game.prosperity[DS]) - console.log("Collect count ", c) return Math.floor(game.prosperity[0] / 2) } +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)) @@ -973,6 +1092,12 @@ function remove_tributary(s) { update_control() } +function is_rebel(p) { + let faction = piece_faction(p) + let piece_index = p - first_piece[faction][ELITE] + return game.rebel[faction] & (1 << piece_index) +} + function to_obedient(p) { let faction = piece_faction(p) let piece_index = p - first_piece[faction][ELITE] @@ -1075,8 +1200,8 @@ function gen_place_piece(faction, type) { if (piece_space(p) === AVAILABLE) { gen_action_piece(p) can_place = true - if (type === DISC) - break + // if (type === DISC) + // break } } return can_place @@ -1095,6 +1220,11 @@ function place_piece(p, s) { update_rebel(p, s) } +function remove_piece(p) { + set_piece_space(p, AVAILABLE) + update_control() +} + function piece_faction(p) { if (p >= first_piece[MI][TROOPS] && p <= last_piece[MI][TROOPS]) return MI |