diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-04-12 02:41:21 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-02-18 11:54:52 +0100 |
commit | 64f2533c09ad196eafaf43cf7b08e81c29fc78c9 (patch) | |
tree | 6489e2826234e353c12c85a946076cebe2a71e41 /rules.js | |
parent | d0efeaef7e3f97841c67b8c8dca47a1a497f4fc7 (diff) | |
download | wilderness-war-64f2533c09ad196eafaf43cf7b08e81c29fc78c9.tar.gz |
Make fort u/c removal more robust.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 31 |
1 files changed, 21 insertions, 10 deletions
@@ -1400,6 +1400,13 @@ function has_friendly_drilled_troops(s) { return false; } +function has_enemy_drilled_troops(s) { + for (let p = first_enemy_unit; p <= last_enemy_unit; ++p) + if (is_drilled_troops(p) && is_piece_in_space(p, s)) + return true; + return false; +} + function has_friendly_regulars(s) { for (let p = first_friendly_unit; p <= last_friendly_unit; ++p) if (is_regular(p) && is_piece_in_space(p, s)) @@ -1909,6 +1916,20 @@ function lift_sieges_and_amphib() { if (game.french.fortresses.includes(s) && is_british_controlled_space(s)) recapture_british_fortress(s); + // Remove forts u/c if solely occupied by enemy drilled troops + for (let s of player.forts_uc) { + if (has_enemy_drilled_troops(s) && !has_friendly_units(s)) { + log(`Removed fort u/c at ${space_name(s)}.`); + remove_friendly_fort_uc(s); + } + } + for (let s of enemy_player.forts_uc) { + if (has_friendly_drilled_troops(s) && !has_enemy_units(s)) { + log(`Removed fort u/c at ${space_name(s)}.`); + remove_enemy_fort_uc(s); + } + } + // Check ownership of other VP locations: update_vp("niagara", NIAGARA); update_vp("ohio_forks", OHIO_FORKS); @@ -2855,13 +2876,6 @@ function resume_move() { game.state = 'move'; } -function remove_enemy_forts_uc_in_path(s) { - if (has_enemy_fort_uc(s)) { - log(`Removed fort u/c at ${space_name(s)}`); - remove_enemy_fort_uc(s); - } -} - function is_land_path(from, to) { return spaces[from].land.includes(to); } @@ -3495,9 +3509,6 @@ function end_move_step(final=false, overrun=false) { delete game.battle; game.move.did_attempt_intercept = 0; // reset flag for next move step - if (force_has_drilled_troops(who)) - remove_enemy_forts_uc_in_path(where); - if (final) stop_move(); |