diff options
author | Mischa Untaga <99098079+MischaU8@users.noreply.github.com> | 2023-10-10 16:03:16 +0200 |
---|---|---|
committer | Mischa Untaga <99098079+MischaU8@users.noreply.github.com> | 2023-10-10 16:03:16 +0200 |
commit | ad288b0df7b7ce601953e6065a1dcc15ac3c0a98 (patch) | |
tree | 80337b9e9107877f4d66bb6b1a7adccfb3e5839a | |
parent | 6123fb2357ae4845be6512c3556e123bd276a520 (diff) | |
download | algeria-ad288b0df7b7ce601953e6065a1dcc15ac3c0a98.tar.gz |
gov mission requirements
-rw-r--r-- | rules.js | 80 |
1 files changed, 73 insertions, 7 deletions
@@ -374,7 +374,7 @@ function is_area_urban(l) { } function is_area_rural(l) { - return areas[l].type === RURAL + return areas[l].type === RURAL && !is_area_resettled(l) } function is_border_crossing(from, to) { @@ -600,9 +600,37 @@ function is_harass_unit(u) { return (type === BAND || type === FAILEK) && has_enemy_unit_in_loc(loc) } +function is_flush_unit(u) { + let loc = unit_loc(u) + return is_mobile_unit(u) && has_enemy_unit_in_loc_boxes(loc, [OPS, OC]) + // TODO airmobile && division +} + +function is_intelligence_unit(u) { + let loc = unit_loc(u) + return is_police_unit(u) && is_unit_not_neutralized(u) && has_enemy_unit_in_loc_boxes(loc, [UG]) +} + +function is_civil_affairs_unit(u) { + let loc = unit_loc(u) + return is_police_unit(u) && is_unit_not_neutralized(u) && !is_area_civil_affaired(loc) && !is_area_remote(loc) +} + +function is_suppression_unit(u) { + let loc = unit_loc(u) + return is_police_unit(u) && is_unit_not_neutralized(u) && !is_area_suppressed(loc) && has_enemy_unit_in_loc(loc) +} + +function is_population_resettlement_unit(u) { + let loc = unit_loc(u) + return is_police_unit(u) && is_unit_not_neutralized(u) && is_area_rural(loc) +} + +const DISPERSED_FIREPOWER = 12 + function unit_firepower(u) { if (is_unit_dispersed(u)) { - return 12 + return DISPERSED_FIREPOWER } else { return units[u].firepower } @@ -661,6 +689,12 @@ function for_each_friendly_unit_on_map_box(box, fn) { fn(u) } +function for_each_friendly_unit_on_map_boxes(boxes, fn) { + for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) + if (unit_loc(u) > 2 && boxes.includes(unit_box(u))) + fn(u) +} + function for_each_enemy_unit_in_loc_box(loc, box, fn) { for (let u = first_enemy_unit; u <= last_enemy_unit; ++u) if (unit_loc(u) === loc && unit_box(u) === box) @@ -747,6 +781,13 @@ function has_enemy_unit_in_loc(x) { return false } +function has_enemy_unit_in_loc_boxes(x, boxes) { + for (let u = first_enemy_unit; u <= last_enemy_unit; ++u) + if (unit_loc(u) === x && boxes.includes(unit_box(u))) + return true + return false +} + function has_friendly_not_neutralized_unit_in_loc(x) { for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) if (unit_loc(u) === x && is_unit_not_neutralized(u)) @@ -2879,16 +2920,41 @@ function goto_gov_operations_phase() { game.state = "gov_operations" } +const GOV_INTELLIGENCE_COST = 1 +const GOV_CIVIL_AFFAIRS_COST = 1 +const GOV_SUPPRESSION_COST = 1 +const GOV_POPULATION_RESETTLEMENT_COST = 1 + states.gov_operations = { inactive: "to do operations", prompt() { view.prompt = "Operations: Perform a mission, or Pass." - gen_action("flush") - gen_action("intelligence") - gen_action("civil_affairs") - gen_action("suppression") - gen_action("population_resettlement") + // check if any GOV missions can actually be performed + view.actions.flush = 0 + view.actions.intelligence = 0 + view.actions.civil_affairs = 0 + view.actions.suppression = 0 + view.actions.population_resettlement = 0 + + for_each_friendly_unit_on_map_boxes([OPS, PTL], u => { + if (is_flush_unit(u)) { + view.actions.flush = 1 + } + if (game.gov_psl >= GOV_INTELLIGENCE_COST && is_intelligence_unit(u)) { + view.actions.intelligence = 1 + } + if (game.gov_psl >= GOV_CIVIL_AFFAIRS_COST && is_civil_affairs_unit(u)) { + view.actions.civil_affairs = 1 + } + if (game.gov_psl >= GOV_SUPPRESSION_COST && is_suppression_unit(u)) { + view.actions.suppression = 1 + } + if (game.gov_psl >= GOV_POPULATION_RESETTLEMENT_COST && is_population_resettlement_unit(u)) { + view.actions.population_resettlement = 1 + } + }) + gen_action("pass") }, flush() { |