diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-08-21 18:04:07 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-08-21 18:04:07 +0200 |
commit | 9c51180e362a11d7541d716d8235836b33518d0c (patch) | |
tree | 58c0589d386aded721ace0afdbba4a301c4a1f8c | |
parent | f591b678e291141ed66e7caa30ff94d86cb776d4 (diff) | |
download | washingtons-war-9c51180e362a11d7541d716d8235836b33518d0c.tar.gz |
refactor removing general when overstacked
-rw-r--r-- | rules.js | 251 |
1 files changed, 124 insertions, 127 deletions
@@ -951,6 +951,127 @@ function filter_place_american_pc_in_colony(list_of_colonies) { return result } +/* REMOVE GENERAL (STACKING) */ + +function prompt_remove_general(where) { + view.prompt = "Remove a general to the reinforcements box." + if (game.active === P_BRITAIN) { + for (let g of BRITISH_GENERALS) + if (is_general_at_location(g, where)) + gen_action_general(g) + } else { + for (let g of AMERICAN_GENERALS) + if (g !== WASHINGTON) + if (is_general_at_location(g, where)) + gen_action_general(g) + } +} + +function action_remove_general(g) { + if (game.active === P_BRITAIN) + move_general(g, BRITISH_REINFORCEMENTS) + else + move_general(g, AMERICAN_REINFORCEMENTS) +} + +function goto_remove_general_after_move(where) { + game.state = "remove_general_after_move" + game.where = where +} + +states.remove_general_after_move = { + inactive: "to remove a general", + prompt() { + prompt_remove_general(game.where) + }, + general(g) { + push_undo() + action_remove_general(g) + delete game.where + end_strategy_card() + }, +} + +function goto_remove_general_after_intercept() { + game.state = "remove_general_after_intercept" +} + +states.remove_general_after_intercept = { + inactive: "to remove a general", + prompt() { + prompt_remove_general(game.move.to) + }, + general(g) { + push_undo() + action_remove_general(g) + game.state = "remove_general_after_intercept_confirm" + }, +} + +states.remove_general_after_intercept_confirm = { + inactive: "to remove a general", + prompt() { + view.prompt = "Intercept done." + view.actions.next = 1 + }, + next() { + clear_undo() + end_intercept() + }, +} + +function goto_remove_general_after_retreat_before_battle(where) { + if (count_friendly_generals(where) > 1) { + game.state = "remove_general_after_retreat_before_battle" + game.where = where + } else { + end_retreat_before_battle() + } +} + +states.remove_general_after_retreat_before_battle = { + inactive: "to remove a general", + prompt() { + prompt_remove_general(game.where) + }, + general(g) { + push_undo() + action_remove_general(g) + delete game.where + game.state = "remove_general_after_retreat_before_battle_confirm" + }, +} + +states.remove_general_after_retreat_before_battle_confirm = { + inactive: "to remove a general", + prompt() { + view.prompt = "Retreat done." + view.actions.next = 1 + }, + next() { + clear_undo() + end_retreat_before_battle() + }, +} + +function goto_remove_general_after_retreat(where) { + game.state = "remove_general_after_retreat" + game.where = where +} + +states.remove_general_after_retreat = { + inactive: "to remove a general", + prompt() { + prompt_remove_general(game.where) + }, + general(g) { + push_undo() + action_remove_general(g) + delete game.where + game.state = "retreat_after_battle_confirm" + }, +} + /* SETUP PHASE */ function goto_committees_of_correspondence() { @@ -1899,101 +2020,6 @@ function gen_activate_american_general() { gen_action_general(g) } -function goto_remove_general(where) { - game.state = "remove_general" - game.where = where -} - -states.remove_general = { - inactive: "to remove a general", - prompt() { - view.prompt = "Remove a general to the reinforcements box." - gen_remove_general(game.where) - }, - general(g) { - push_undo() - delete game.where - if (game.active === P_BRITAIN) - move_general(g, BRITISH_REINFORCEMENTS) - else - move_general(g, AMERICAN_REINFORCEMENTS) - end_strategy_card() - }, -} - -function goto_remove_general_after_intercept() { - game.state = "remove_general_after_intercept" -} - -states.remove_general_after_intercept = { - inactive: "to remove a general", - prompt() { - view.prompt = "Remove a general to the reinforcements box." - gen_remove_general(game.move.to) - }, - general(g) { - push_undo() - if (game.active === P_BRITAIN) - move_general(g, BRITISH_REINFORCEMENTS) - else - move_general(g, AMERICAN_REINFORCEMENTS) - game.state = "remove_general_after_intercept_confirm" - }, -} - -states.remove_general_after_intercept_confirm = { - inactive: "to remove a general", - prompt() { - view.prompt = "Intercept done." - view.actions.next = 1 - }, - next() { - clear_undo() - end_intercept() - }, -} - -function goto_remove_general_after_retreat(where) { - game.state = "remove_general_after_retreat" - game.where = where -} - -states.remove_general_after_retreat = { - inactive: "to remove a general", - prompt() { - view.prompt = "Remove a general to the reinforcements box." - gen_remove_general(game.where) - }, - general(g) { - push_undo() - delete game.where - if (game.active === P_BRITAIN) - move_general(g, BRITISH_REINFORCEMENTS) - else - move_general(g, AMERICAN_REINFORCEMENTS) - game.state = "retreat_after_battle_confirm" - }, -} - -function gen_remove_general(where) { - if (game.active === P_BRITAIN) - return gen_remove_british_general(where) - else - return gen_remove_american_general(where) -} - -function gen_remove_british_general(where) { - for (let g of BRITISH_GENERALS) - if (is_general_at_location(g, where)) - gen_action_general(g) -} - -function gen_remove_american_general(where) { - for (let g of AMERICAN_GENERALS) - if (g !== WASHINGTON) - if (is_general_at_location(g, where)) - gen_action_general(g) -} function goto_ops_general_move(g, marblehead) { game.state = "ops_general_move" @@ -2230,7 +2256,7 @@ function end_move(stop) { delete game.move if (count_friendly_generals(where) > 1) - goto_remove_general(where) + goto_remove_general_after_move(where) else { if (end_strategy_card() && stop) next_strategy_card() @@ -2549,31 +2575,6 @@ states.retreat_before_battle_roll = { }, } -function goto_remove_general_after_retreat_before_battle(where) { - if (count_friendly_generals(where) > 1) { - game.state = "remove_general_after_retreat_before_battle" - game.where = where - } else { - end_retreat_before_battle() - } -} - -states.remove_general_after_retreat_before_battle = { - inactive: "to remove a general", - prompt() { - view.prompt = "Remove a general to the reinforcements box." - gen_remove_general(game.where) - }, - general(g) { - delete game.where - if (game.active === P_BRITAIN) - move_general(g, BRITISH_REINFORCEMENTS) - else - move_general(g, AMERICAN_REINFORCEMENTS) - end_retreat_before_battle() - }, -} - function end_retreat_before_battle() { game.active = P_BRITAIN @@ -4054,16 +4055,12 @@ states.remove_general_rochambeau = { inactive: "to remove a general", prompt() { let where = location_of_general(ROCHAMBEAU) - view.prompt = "Remove a general to the reinforcements box." + prompt_remove_general(where) view.move = { who: ROCHAMBEAU, from: where, to: where, carry_american: 0, carry_french: 5 } - gen_remove_general(where) }, general(g) { push_undo() - if (game.active === P_BRITAIN) - move_general(g, BRITISH_REINFORCEMENTS) - else - move_general(g, AMERICAN_REINFORCEMENTS) + action_remove_general(g) game.state = "end_place_rochambeau" }, } |