diff options
author | Joël Simoneau <simoneaujoel@gmail.com> | 2024-12-15 21:48:56 -0500 |
---|---|---|
committer | Joël Simoneau <simoneaujoel@gmail.com> | 2024-12-15 21:48:56 -0500 |
commit | e0900575ab7104ffc5204c463aa5b26f38610f80 (patch) | |
tree | 4bc865e21fcda0f66a35cc083194eb1424c698b6 | |
parent | f9f56d9fd4358e3de17ef368ba1afdec281a958c (diff) | |
download | vijayanagara-e0900575ab7104ffc5204c463aa5b26f38610f80.tar.gz |
Migrate.
-rw-r--r-- | play.js | 4 | ||||
-rw-r--r-- | rules.js | 92 |
2 files changed, 89 insertions, 7 deletions
@@ -1041,9 +1041,11 @@ function on_update() { action_button("end_march", "End March") // Command buttons + action_button("migrate", "Migrate") + action_button("end_migrate", "End Migrate") action_button("rally", "Rally") - action_button("rebel", "Rebel") action_button("end_rally", "End Rally") + action_button("rebel", "Rebel") action_button("end_rebel", "End Rebel") // Decree buttons @@ -151,10 +151,6 @@ exports.view = function (state, role) { view.actions.undo = 0 } - // if (game.decree && game.decree.campaign) { - // view.actions.campaign_spaces = game.decree.campaign - // console.log("SPACES ", view.actions.campaign_spaces) - // } } save_game() @@ -600,6 +596,7 @@ states.main_phase = { demand: goto_demand, govern: goto_govern, march: goto_march, + migrate: goto_migrate, rally: goto_rally, rebel: goto_rebel, tax: goto_tax, @@ -862,7 +859,6 @@ states.march_space = { prompt() { view.prompt = "March: Move pieces from adjacent spaces." view.where = game.cmd.where - view.actions.next = 1 for_each_movable(DS, p => { if ( @@ -871,6 +867,10 @@ states.march_space = { ) gen_action_piece(p) }) + + if (game.cmd.pieces.length > 0) + view.actions.next = 1 + }, piece(p) { log_summary_move_from(p) @@ -956,7 +956,7 @@ function gen_any_command() { // 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.migrate = can_migrate() ? 1 : 0 view.actions.rebel = can_rebel() ? 1 : 0 // view.actions.attack = can_attack() ? 1 : 0 } @@ -1058,6 +1058,9 @@ function prompt_end_cmd(cost) { } function end_command() { + if (game.summary && game.summary.length > 0) { + pop_summary() + } log_br() game.cmd = null game.state = "main_phase" @@ -1074,6 +1077,83 @@ function end_decree() { /* REBEL COMMANDS */ +function can_migrate() { + if (count_pieces_on_map(game.current, ELITE) > 0) + return true + return false +} + +function can_migrate_in_space(s) { + for (let ss of SPACES[s].adjacent) + if (has_unmoved_piece(ss, game.current)) + return true + return false +} + +function goto_migrate() { + init_command("Migrate") + game.cmd.pieces = [] + game.state = "migrate" +} + +function goto_migrate_space() { + push_summary() + game.state = "migrate_space" + game.cmd.count = 0 +} + +states.migrate = { + prompt() { + view.prompt = "Migrate: Select a Province as the Migrate destination." + + if (can_select_cmd_space(1) && can_rally()) + for (let s = first_space; s <= last_province; ++s) + if (!is_selected_cmd_space(s) && can_migrate_in_space(s)) + gen_action_space(s) + + if (game.cmd.spaces) + view.actions.end_migrate = 1 + + }, + space(s) { + game.cmd.where = s + select_cmd_space(s, 1) + goto_migrate_space() + }, + end_migrate: end_command +} + +states.migrate_space = { + prompt() { + view.prompt = `Migrate: Move in up to three ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}s.` + view.where = game.cmd.where + + for_each_movable(game.current, p => { + if ( + set_has(SPACES[game.cmd.where].adjacent, piece_space(p)) && + !set_has(game.cmd.pieces, p) && + game.cmd.count < 3 + ) + gen_action_piece(p) + }) + + if (game.cmd.count > 0) + view.actions.next = 1 + + }, + piece(p) { + log_summary_move_from(p) + set_add(game.cmd.pieces, p) + place_piece(p, game.cmd.where) + game.cmd.count += 1 + }, + next() { + log_space(game.cmd.where, "Migrate") + pop_summary() + game.state = "migrate" + } +} + function can_rally() { return has_piece(AVAILABLE, game.current, ELITE) } |