diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-01-20 19:45:44 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-02-18 11:54:52 +0100 |
commit | 6cfb6ee52d79ec9de7eca8e82ab93800061810f3 (patch) | |
tree | 8b2633b8be52704c3e1ce31e6660dd580f73d7eb | |
parent | c2ecb6095bfcdefc65d61f7cf948fa36c2748abe (diff) | |
download | wilderness-war-6cfb6ee52d79ec9de7eca8e82ab93800061810f3.tar.gz |
Frontier duty.
-rw-r--r-- | rules.js | 53 |
1 files changed, 52 insertions, 1 deletions
@@ -4104,7 +4104,58 @@ const TODO = { can_play() { return false } }; events.campaign = TODO; -events.provincial_regiments_dispersed_for_frontier_duty = TODO; +function count_french_raids_in_dept(dept) { + let n = 0; + for (let i = 0; i < game.France.raids.length; ++i) { + let s = game.France.raids[i]; + if (departments[dept].includes(s)) + ++n; + } + return n; +} + +events.provincial_regiments_dispersed_for_frontier_duty = { + can_play() { + let s = Math.min(count_french_raids_in_dept('southern'), count_provincial_units_from('southern')); + let n = Math.min(count_french_raids_in_dept('northern'), count_provincial_units_from('northern')); + return (s + n) > 0; + }, + play() { + game.state = 'provincial_regiments_dispersed_for_frontier_duty'; + game.frontier_duty = { + southern: Math.min(count_french_raids_in_dept('southern'), count_provincial_units_from('southern')), + northern: Math.min(count_french_raids_in_dept('northern'), count_provincial_units_from('northern')), + }; + } +} + +states.provincial_regiments_dispersed_for_frontier_duty = { + prompt() { + view.prompt = `Eliminate ${game.frontier_duty.southern} southern and ${game.frontier_duty.northern} northern provincials.`; + let can_eliminate = false; + for (let p = first_british_unit; p <= last_british_unit; ++p) { + if ((game.frontier_duty.northern > 0 && is_provincial_unit_from(p, 'northern')) || + (game.frontier_duty.southern > 0 && is_provincial_unit_from(p, 'southern'))) { + can_eliminate = true; + gen_action_piece(p); + } + } + if (!can_eliminate) + gen_action_next(); + }, + piece(p) { + push_undo(); + if (is_provincial_unit_from(p, 'southern')) + game.frontier_duty.southern --; + if (is_provincial_unit_from(p, 'northern')) + game.frontier_duty.northern --; + eliminate_piece(p); + }, + next() { + delete game.frontier_duty; + end_action_phase(); + }, +} events.northern_indian_alliance = { can_play() { |