diff options
author | Joël Simoneau <simoneaujoel@gmail.com> | 2025-03-20 12:55:14 -0400 |
---|---|---|
committer | Joël Simoneau <simoneaujoel@gmail.com> | 2025-03-20 12:55:14 -0400 |
commit | 9cc11d54a7f0ef5b6f33b5eb14f4ad15ff8fd414 (patch) | |
tree | a3fb09d467e6087ed9d7e82ebdb6b7521a321d1c | |
parent | 6b3319a0b88c234a7a0c5ed72954c381ec1ec327 (diff) | |
download | vijayanagara-9cc11d54a7f0ef5b6f33b5eb14f4ad15ff8fd414.tar.gz |
Better flow
-rw-r--r-- | play.js | 32 | ||||
-rw-r--r-- | rules.js | 62 |
2 files changed, 53 insertions, 41 deletions
@@ -1170,42 +1170,44 @@ function on_update() { action_button("lim_command", "Limited Command") action_button("pass", "Pass") - // DS buttons - action_button("campaign", "Campaign") - action_button("end_campaign", "End Campaign") + // DS commands 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") + action_button("govern", "Govern") + action_button("end_govern", "End Govern") // Command buttons - action_button("attack", "Attack") - action_button("end_attack", "End Attack") - action_button("migrate", "Migrate") - action_button("end_migrate", "End Migrate") action_button("rally", "Rally") action_button("end_rally", "End Rally") + action_button("migrate", "Migrate") + action_button("end_migrate", "End Migrate") action_button("rebel", "Rebel") action_button("end_rebel", "End Rebel") + action_button("attack", "Attack") + action_button("end_attack", "End Attack") action_button("roll", "Roll") // Decree buttons + action_button("tax", "Tax") + action_button("end_tax", "End Tax") + action_button("trade", "Trade") + action_button("end_trade", "End Trade") action_button("build", "Build") action_button("end_build", "End Build") action_button("compel", "Compel") action_button("end_compel", "End Compel") action_button("conspire", "Conspire") action_button("end_conspire", "End Conspire") - action_button("demand", "Demand Obedience") - action_button("end_demand", "End Demand Obedience") + + // DS decrees action_button("collect", "Collect Tribute") action_button("end_collect", "End Collect Tribute") - action_button("tax", "Tax") - action_button("end_tax", "End Tax") - action_button("trade", "Trade") - action_button("end_trade", "End Trade") + action_button("campaign", "Campaign") + action_button("end_campaign", "End Campaign") + action_button("demand", "Demand Obedience") + action_button("end_demand", "End Demand Obedience") // MI buttons action_button("advance", "Advance") @@ -482,7 +482,6 @@ function goto_cavalry(n, next) { } } push_summary() - game.state = "cavalry" // Removing automatic cavalry tokens attribution // while (game.cav.n > 0 && n_available_cavalry() > 0) { @@ -508,8 +507,8 @@ function end_cavalry() { vm_next() } else if (game.cav.next) { upop_summary() - if (typeof game.cav.next === "function") - game.cav.next() + if (game.cav.next === "end_card") + end_card() else game.state = game.cav.next } else { @@ -703,7 +702,7 @@ states.cavalry = { inactive: "Gain Cavalry tokens", prompt() { if (game.cav.n > 0) { - view.prompt = `Gain Cavalry: Take ${game.cav.n} calvary tokens.` + view.prompt = `Gain Cavalry: Take ${game.cav.n} Calvary token${game.cav.n > 1 ? "s" : ""}.` gen_take_cavalry(game.current) } else { view.prompt = "Gain Cavalry: Done." @@ -711,6 +710,7 @@ states.cavalry = { } }, token(c) { + push_undo() game.cav.n -= 1 log_summary_cavalry(c) set_cavalry_faction(c, game.current) @@ -721,21 +721,22 @@ states.cavalry = { states.compromising_gifts = { inactive: "Compromising gifts", prompt() { - view.prompt = "Compromising gifts: Reduce your influence by one to gain two Resources and two Cavalry tokens." + view.prompt = "Compromising gifts: Reduce your Influence by one to gain two Resources and two Cavalry tokens." gen_action_influence(game.current) view.actions.end_gifts = 1 }, influence(f) { - log_h2(faction_name[f] + "Compromising Gifts") + push_undo() + log_h2(faction_name[f] + " - Compromising Gifts") log_resources(f, 2) add_resources(f, 2) game.inf_shift = { - "next": goto_cavalry, + "next": "goto_cavalry", } game.cav = { "n": 2, - "next": end_card + "next": "end_card" } remove_influence(f) }, @@ -854,7 +855,7 @@ states.strategic_assistance = { inactive: "Strategic Assistance", prompt() { let n_command = (game.cmd.free === 2) ? "two" : "one" - view.prompt = `Strategic Assistance: ${faction_name[game.current]} must execute ${n_command} Mongol Invaders Commands` + view.prompt = `Strategic Assistance: ${faction_name[game.current]} must execute ${n_command} Mongol Invaders Commands.` gen_mi_command() }, @@ -1349,7 +1350,7 @@ states.attack_cavalry = { view.prompt = "Attack: Use cavalry to Charge your dice or Screen your opponent's dice." if (has_cavalry(game.current)) for (let d of curr_die) - if (game.dice[d] > 1) + if (game.dice[d] > 1 && (game.current === game.cmd.attacker || game.dice[d] < 6)) gen_action_die(d) view.actions.next = 1 @@ -1453,6 +1454,7 @@ function goto_attack_resolution() { attack_influence_shift() else if (game.cmd.attacker === MI && !is_timurid()) { game.current = game.cmd.sa_faction + clear_undo() game.state = "plunder" } else if (game.vm) { vm_next() @@ -1473,7 +1475,7 @@ function attack_influence_shift() { if (up) { if (game.vm) - game.inf_shift = { "next": vm_next } + game.inf_shift = { "next": "vm_next" } else game.inf_shift = { "next": "attack" } add_influence(up) @@ -1870,9 +1872,9 @@ states.rally = { inactive: "Rally", prompt() { if (game.current === BK) - view.prompt = "Rally: Select Maharashtra or a Province with your presence" + 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" + 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) { @@ -1894,7 +1896,7 @@ states.rally = { states.rally_space = { inactive: "Rally", prompt() { - view.prompt = `Rally: Place up to ${rally_count()} ${PIECE_FACTION_TYPE_NAME[game.current][ELITE]}` + view.prompt = `Rally: Place up to ${format_unit_count(game.current, ELITE, rally_count())}.` view.where = game.cmd.where gen_place_piece(game.current, ELITE) @@ -2002,7 +2004,7 @@ function goto_collect() { states.collect = { inactive: "Collect Tribute", prompt() { - view.prompt = `Collect Tribute: Collect ${collect_count()} from half the Tributaries prosperity` + view.prompt = `Collect Tribute: Collect ${collect_count()} from half the Tributaries prosperity.` if (game.decree.count > 0) gen_action_resources(DS) @@ -2063,7 +2065,7 @@ states.campaign = { view.actions.campaign_spaces = [...game.decree.campaign].sort((a, b) => a - b) if (game.vm && game.vm.fp === 13) { - view.prompt = "Campaign: Select four contiguous spaces, finishing adjacent to Warangal" + view.prompt = "Campaign: Select four contiguous spaces, finishing adjacent to Warangal." if (game.decree.campaign.length === 0) { for (let s = first_space; s <= last_space; ++s) { if (can_start_campaign_in_space(s) && is_n_from_warangal(3, s)) @@ -2480,7 +2482,7 @@ function can_advance() { states.advance = { inactive: "Advance", prompt() { - view.prompt = "Advance: Select the Advance destination" + view.prompt = "Advance: Select the Advance destination." if (has_piece(S_MOUNTAIN_PASSES, MI, TROOPS)) gen_action_space(S_PUNJAB) @@ -2498,7 +2500,7 @@ states.advance = { states.advance_space = { inactive: "Advance", prompt() { - view.prompt = "Advance: Move any number of Mongol Invaders into destination" + view.prompt = "Advance: Move any number of Mongol Invaders into destination." let origin = game.cmd.where === S_DELHI ? S_PUNJAB : S_MOUNTAIN_PASSES for (let p = first_piece[MI][TROOPS]; p <= last_piece[MI][TROOPS]; ++p) @@ -2525,7 +2527,7 @@ function can_amass() { states.amass = { inactive: "Amass", prompt() { - view.prompt = "Amass: Place up to three invaders into the Mountain Passes" + view.prompt = "Amass: Place up to three invaders into the Mountain Passes." gen_action_space(S_MONGOL_INVADERS) }, @@ -2604,6 +2606,7 @@ states.plunder = { gen_action_resources(DS) }, resources(f) { + clear_undo() log_space(game.cmd.where, "Plunder") let n = Math.min(game.resources[DS] - 3, count_pieces(game.cmd.where, MI, TROOPS)) @@ -2638,7 +2641,7 @@ states.plunder_remove = { inactive: "Attack & Plunder", prompt() { if (game.cmd.count > 0 && has_troops_in_provinces()) { - view.prompt = `Attack & Plunder: Remove ${game.cmd.count} Troops from any Provinces.` + view.prompt = `Attack & Plunder: Remove ${format_unit_count(DS, TROOPS, game.cmd.count)} from any Provinces.` for (let s = first_space; s <= last_province; ++s) { if (has_piece(s, DS, TROOPS)) @@ -2650,6 +2653,7 @@ states.plunder_remove = { } }, space(s) { + push_undo() game.cmd.count -= 1 let p = find_piece(s, DS, TROOPS) log_summary_move_from(p) @@ -3169,7 +3173,7 @@ function add_influence(faction) { return game.inf[faction]++ - log(faction_name[faction] + " gains influence.") + log(faction_name[faction] + " gains Influence.") update_vp() if (faction === BK && game.inf[faction] === 2) @@ -3185,7 +3189,7 @@ function remove_influence(faction) { end_influence() } else { game.inf[faction]-- - log(faction_name[faction] + " loses influence.") + log(faction_name[faction] + " loses Influence.") update_vp() if (faction === BK && game.inf[faction] === 3) @@ -3205,8 +3209,10 @@ function end_influence() { else if (game.vm) vm_next() else { - if (typeof game.inf_shift.next === "function") - game.inf_shift.next() + if (game.inf_shift.next === "goto_cavalry") + goto_cavalry() + else if (game.inf_shift.next === "vm_next") + vm_next() else game.state = game.inf_shift.next } @@ -3244,7 +3250,7 @@ states.return_troops = { prompt() { if (game.inf_shift.n > 0) { - view.prompt = "Deccan Influence dwindles: Return troops to the influence track." + view.prompt = "Deccan Influence dwindles: Return Troops to the Influence track." for_each_piece(game.current, ELITE, p => { if (piece_space(p) >= 0 && piece_space(p) <= S_PUNJAB) gen_action_piece(p) @@ -3789,6 +3795,10 @@ function log_resources(faction, n) { log(faction_acronyms[faction] + " Resources " + n + ".") } +function format_unit_count(faction, type, n) { + return `${n} ${PIECE_FACTION_TYPE_NAME[faction][type]}${n > 1 ? "s" : ""}` +} + // === MISC PIECE QUERIES === function piece_space(p) { @@ -5289,7 +5299,7 @@ states.vm_influence_succession = { }, next: vm_next, skip() { - log("Declined influence shift.") + log("Declined Influence shift.") vm_next() }, } |