diff options
-rw-r--r-- | rules.js | 42 |
1 files changed, 36 insertions, 6 deletions
@@ -831,6 +831,15 @@ function for_each_friendly_leader_in_space(s, fn) { } } +function for_each_unit_in_space(s, fn) { + for (let p = first_french_unit; p <= last_french_unit; ++p) + if (is_piece_in_space(p, s)) + fn(p) + for (let p = first_british_unit; p <= last_british_unit; ++p) + if (is_piece_in_space(p, s)) + fn(p) +} + function for_each_friendly_unit_in_space(s, fn) { for (let p = first_friendly_unit; p <= last_friendly_unit; ++p) { if (is_piece_in_space(p, s)) @@ -1311,6 +1320,17 @@ function has_unbesieged_french_fortification(s) { return is_space_unbesieged(s) && has_french_fortifications(s) } +function count_units_in_space(s) { + let n = 0 + for (let p = first_french_unit; p <= last_french_unit; ++p) + if (is_piece_in_space(p, s)) + ++n + for (let p = first_british_unit; p <= last_british_unit; ++p) + if (is_piece_in_space(p, s)) + ++n + return n +} + function count_enemy_units_in_space(s) { let n = 0 for (let p = first_enemy_unit; p <= last_enemy_unit; ++p) @@ -1430,6 +1450,16 @@ function has_friendly_rangers(s) { return false } +function has_any_indians(s) { + for (let p = first_french_unit; p <= last_french_unit; ++p) + if (is_indian(p) && is_piece_in_space(p, s)) + return true + for (let p = first_british_unit; p <= last_british_unit; ++p) + if (is_indian(p) && is_piece_in_space(p, s)) + return true + return false +} + function has_friendly_indians(s) { for (let p = first_friendly_unit; p <= last_friendly_unit; ++p) if (is_indian(p) && is_piece_in_space(p, s)) @@ -7601,7 +7631,7 @@ states.governor_vaudreuil_interferes = { events.small_pox = { can_play() { for (let s = first_space; s <= last_space; ++s) - if (count_enemy_units_in_space(s) > 4) + if (count_units_in_space(s) > 4) return true return false }, @@ -7614,13 +7644,13 @@ states.small_pox = { prompt() { view.prompt = "Small Pox: Choose a space with more than 4 units." for (let s = first_space; s <= last_space; ++s) - if (count_enemy_units_in_space(s) > 4) + if (count_units_in_space(s) > 4) gen_action_space(s) }, space(s) { log(`Small Pox at ${space_name(s)}.`) let roll = roll_die() - if (count_enemy_units_in_space(s) > 8) { + if (count_units_in_space(s) > 8) { game.count = roll } else { game.count = Math.ceil(roll / 2) @@ -7667,7 +7697,7 @@ states.small_pox_eliminate_steps = { reduce_unit(p, false) }, next() { - if (has_friendly_indians(game.small_pox)) { + if (has_any_indians(game.small_pox)) { game.state = 'small_pox_remove_indians' } else { end_small_pox() @@ -7681,14 +7711,14 @@ states.small_pox_remove_indians = { }, prompt() { view.prompt = `Small Pox at ${space_name(game.small_pox)}: Remove all indians.` - for_each_friendly_unit_in_space(game.small_pox, p => { + for_each_unit_in_space(game.small_pox, p => { if (is_indian(p)) gen_action_piece(p) }) }, piece(p) { eliminate_piece(p, false) - if (!has_friendly_indians(game.small_pox)) + if (!has_any_indians(game.small_pox)) end_small_pox() }, } |