Fire P1-SUN on network fire plots, make S-400/S-500 launchers only, give radars own models
build / mod (push) Successful in 30m51s
build / mod (push) Successful in 30m51s
Gameplay fixes and art from the owner's balance review of 2026-12-05. - The P1-SUN never launched (0 launches in 12 seeds of a 196-target raid): it has no radar of its own and only a separate launcher could fire on another station's plot. A unit without its own radar now fires like one (`why::on_network`), on the fresh own fire plot of an engagement or multifunction radar within link reach. Seven P1-SUN then launch 26-42 and kill 13-24 per raid; the leak count does not change. - The С-400 and С-500 exist only as separate launchers (`mode: "launcher"` in the catalog). The `s400_launcher`/`s500_launcher` variants and their remotes are gone: `deploy s400`/`s500` and their remotes place a launcher. A system saved with its own radar loads as a launcher; `battery <n> integrated` is refused for these kinds. - Every radar role has its own model: a wide curved array (search), a parabolic dish (engagement), a small head on mast sections (height); the multifunction radar keeps its panel, the optical post gets its own post and a turning head with a lens. A variant may carry its own `parts` in `catalog/content.json`; `Sam::parts()` resolves them. - The enemy remembers the sides each approach raided from: a raid ordered the same way and within 200 blocks of the same distance comes from the same sides, so its sites stand where the last ones did. A launch area the radars fixed is remembered (up to 32): a site placed there again is known before its first launch and can be struck at once. Neither is saved yet. - `sim/balance.rs` flies several raids over one cluster with stocked depots (`supply_raids`). With the 16-block depot reach, depots 30 blocks from the batteries leave 10 / 36 / 80 leaks over three raids against 6 / 10 / 17 for depots within reach; the reach itself is unchanged by decision of the owner. The saturation checkpoint is re-recorded (123 kills / 323 launches instead of 129 / 344): that loadout has no fire radar, so its С-400/С-500 fire less as launchers. Verified: airdef-core release 363 passed and 8 scenarios; airdef-mod 135 passed, 1 boundary, 2 saturation, 5 scenarios; gen_catalog/gen_models/gen_sounds --check; test_gen_assets, test_model_bounds, test_web_panel; git diff --check. Not run: the actual WASM contract, the models in game, CI. Co-Authored-By: ZCode <zcode@localhost>
This commit is contained in:
+220
-63
@@ -64,6 +64,16 @@ pub(super) struct Result {
|
||||
pub tally: String,
|
||||
/// Drones that vanished short of their aim without being shot down: kind, where, how far from the aim.
|
||||
pub crashed: Vec<(DroneKind, DVec3, f64)>,
|
||||
/// Ticks into the raid when each drone got through, and the armed systems with no rounds left at the end.
|
||||
pub leak_ticks: Vec<u64>,
|
||||
pub empty: usize,
|
||||
pub armed: usize,
|
||||
/// Who brought each one down: kind, kills.
|
||||
pub kills_by: Vec<(SamKind, u32)>,
|
||||
/// Where the drones were first sent: "object", "radar", "<kind>", by the aim at their first tick in the sky.
|
||||
pub aims: Vec<(String, u32)>,
|
||||
/// The systems the raid destroyed, by kind.
|
||||
pub lost: Vec<(SamKind, u32)>,
|
||||
/// Chunk tickets the sim asked for.
|
||||
pub tickets: usize,
|
||||
pub scrubs: Vec<(MissileKind, u32, f64, f64, DVec3, f64, f64)>,
|
||||
@@ -92,6 +102,10 @@ pub(super) struct Setup {
|
||||
/// How steep the hills are (1 is the usual), and whether a forest's canopy stands on them (the game's height map shows the leaves).
|
||||
pub steep: f64,
|
||||
pub trees: bool,
|
||||
/// A depot this far from every armed system (0: none).
|
||||
pub depots: f64,
|
||||
/// Raids flown one after another.
|
||||
pub raids: u32,
|
||||
}
|
||||
|
||||
/// Rolling hills: ridges of 20-35 blocks over a plain at 64, wavelengths of 90-250 blocks.
|
||||
@@ -196,7 +210,7 @@ impl world::WorldSource for Seen<'_> {
|
||||
|
||||
impl Setup {
|
||||
pub fn new(systems: usize, smart: bool, seed: u64) -> Self {
|
||||
Setup { systems, smart, seed, size: 36, radars: (systems / 10).max(1), objects: 36, tweak: |_| {}, hilly: false, bury: 0.0, disc: None, mountains: false, dist: 500.0, steep: std::env::var("STEEP").ok().and_then(|v| v.parse().ok()).unwrap_or(1.0), trees: std::env::var("TREES").is_ok() }
|
||||
Setup { systems, smart, seed, size: 36, radars: (systems / 10).max(1), objects: 36, tweak: |_| {}, hilly: false, bury: 0.0, disc: None, mountains: false, dist: 500.0, steep: std::env::var("STEEP").ok().and_then(|v| v.parse().ok()).unwrap_or(1.0), trees: std::env::var("TREES").is_ok(), depots: 0.0, raids: 1 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,11 +244,61 @@ pub(super) fn cluster(sim: &mut Sim, s: &Setup) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Flies one raid to its end and counts.
|
||||
/// Flies the setup's raids to their end and counts them together.
|
||||
pub(super) fn fly(s: &Setup) -> Result {
|
||||
let mut all = Result::default();
|
||||
for r in fly_raids(s) {
|
||||
all.launched += r.launched;
|
||||
all.kills += r.kills;
|
||||
all.leaked += r.leaked;
|
||||
all.missiles += r.missiles;
|
||||
all.heavy += r.heavy;
|
||||
all.ticks += r.ticks;
|
||||
all.unseen += r.unseen;
|
||||
all.no_cover += r.no_cover;
|
||||
all.untracked += r.untracked;
|
||||
all.unshot += r.unshot;
|
||||
all.missed += r.missed;
|
||||
all.hits += r.hits;
|
||||
all.crashes += r.crashes;
|
||||
all.blocked += r.blocked;
|
||||
all.scrubbed += r.scrubbed;
|
||||
all.fuse_missed += r.fuse_missed;
|
||||
all.expired += r.expired;
|
||||
all.orphaned += r.orphaned;
|
||||
all.energy_lost += r.energy_lost;
|
||||
all.leak_ticks.extend(r.leak_ticks);
|
||||
all.crashed.extend(r.crashed);
|
||||
all.empty = r.empty;
|
||||
all.armed = r.armed;
|
||||
all.kills_by = r.kills_by.clone();
|
||||
for (k, n, _) in r.by_kind {
|
||||
match all.by_kind.iter_mut().find(|e| e.0 == k) {
|
||||
Some(e) => e.1 += n,
|
||||
None => all.by_kind.push((k, n, 0)),
|
||||
}
|
||||
}
|
||||
}
|
||||
all.by_kind.sort_by_key(|k| k.0 as u8);
|
||||
all
|
||||
}
|
||||
|
||||
/// The raids of a setup one after another on one cluster (`raids` of them, 35 s apart for the reloads),
|
||||
/// each counted on its own. With `depots` set, a stocked depot stands that far from every armed system.
|
||||
pub(super) fn fly_raids(s: &Setup) -> Vec<Result> {
|
||||
let mut sim = Sim::new(s.seed);
|
||||
cluster(&mut sim, s);
|
||||
(s.tweak)(&mut sim);
|
||||
let armed: Vec<DVec3> = sim.sams.iter().filter(|m| m.kind.armed()).map(|m| m.pos).collect();
|
||||
for (i, pos) in armed.iter().enumerate() {
|
||||
if s.depots <= 0.0 {
|
||||
break;
|
||||
}
|
||||
let id = sim.id();
|
||||
let mut depot = Sam::new(id, SamKind::Depot, pos + DVec3::new(s.depots, 0.0, (i % 5) as f64 * 3.0 - 6.0), 0.0);
|
||||
sim.roll_depot_stock(&mut depot);
|
||||
sim.sams.push(depot);
|
||||
}
|
||||
let mut ground = Ground::default();
|
||||
let mut land = Loader::new(s);
|
||||
let mut out = Out::default();
|
||||
@@ -250,79 +314,115 @@ pub(super) fn fly(s: &Setup) -> Result {
|
||||
order.approach = raid::Approach::AllSides;
|
||||
}
|
||||
let targets = sim.targets.clone();
|
||||
let fired0: u32 = sim.sams.iter().map(|m| m.fired).sum();
|
||||
sim.order_raid(&order, &targets, &mut out);
|
||||
let mut hist: HashMap<u32, Hist> = HashMap::new();
|
||||
let mut result = Result::default();
|
||||
let start = sim.tick;
|
||||
let mut gone_unkilled: Vec<Hist> = Vec::new();
|
||||
for _ in 0..9000 {
|
||||
land.serve(&mut ground, sim.tick);
|
||||
out = Out::default();
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
let now = sim.tick;
|
||||
for d in &sim.drones {
|
||||
let h = hist.entry(d.id).or_default();
|
||||
h.kind = Some(d.kind);
|
||||
h.last = (d.pos, d.target);
|
||||
if !d.alive() {
|
||||
h.dead = true;
|
||||
continue;
|
||||
}
|
||||
if sim.sams.iter().any(|m| m.seen.contains(&d.id)) {
|
||||
h.seen += 1;
|
||||
}
|
||||
let class = d.kind.spec().class.bit();
|
||||
let covers = |m: &&Sam| {
|
||||
m.alive() && m.roles & class != 0 && m.missiles > 0 && m.kind.spec().missile.as_ref().is_some_and(|l| (l.min..l.max).contains(&m.pos.distance(d.pos)))
|
||||
};
|
||||
let ttg = why::arrival(d);
|
||||
if h.cover == 0 && sim.sams.iter().filter(covers).next().is_some() {
|
||||
h.ttg.0 = ttg;
|
||||
}
|
||||
if h.reach == 0 && sim.sams.iter().filter(covers).any(|m| m.seen.contains(&d.id)) {
|
||||
h.ttg.1 = ttg;
|
||||
}
|
||||
h.cover += u32::from(sim.sams.iter().filter(covers).next().is_some());
|
||||
h.reach += u32::from(sim.sams.iter().filter(covers).any(|m| m.seen.contains(&d.id)));
|
||||
}
|
||||
for m in &sim.missiles {
|
||||
if let Some(h) = hist.get_mut(&m.target) {
|
||||
if h.shots.is_empty() {
|
||||
h.ttg.2 = h.last.0.distance(h.last.1) / h.kind.map_or(1.0, |k| k.spec().speed);
|
||||
let mut results = Vec::new();
|
||||
let mut leaked_before = 0;
|
||||
for _ in 0..s.raids.max(1) {
|
||||
let fired0: u32 = sim.sams.iter().map(|m| m.fired).sum();
|
||||
sim.order_raid(&order, &targets, &mut out);
|
||||
let mut hist: HashMap<u32, Hist> = HashMap::new();
|
||||
let start = sim.tick;
|
||||
let mut gone_unkilled: Vec<Hist> = Vec::new();
|
||||
let mut aims: Vec<(String, u32)> = Vec::new();
|
||||
loop {
|
||||
land.serve(&mut ground, sim.tick);
|
||||
out = Out::default();
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
let now = sim.tick;
|
||||
for d in &sim.drones {
|
||||
let h = hist.entry(d.id).or_default();
|
||||
if h.kind.is_none() {
|
||||
let what = if d.aim.unit == 0 { "object".to_string() } else { sim.sams.iter().find(|m| m.id == d.aim.unit).map_or("gone".to_string(), |m| format!("{:?}", m.kind)) };
|
||||
match aims.iter_mut().find(|a| a.0 == what) { Some(a) => a.1 += 1, None => aims.push((what, 1)) }
|
||||
}
|
||||
h.shots.insert(m.id);
|
||||
h.kind = Some(d.kind);
|
||||
h.last = (d.pos, d.target);
|
||||
if !d.alive() {
|
||||
h.dead = true;
|
||||
continue;
|
||||
}
|
||||
if sim.sams.iter().any(|m| m.seen.contains(&d.id)) {
|
||||
h.seen += 1;
|
||||
}
|
||||
let class = d.kind.spec().class.bit();
|
||||
let covers = |m: &&Sam| {
|
||||
m.alive() && m.roles & class != 0 && m.missiles > 0 && m.kind.spec().missile.as_ref().is_some_and(|l| (l.min..l.max).contains(&m.pos.distance(d.pos)))
|
||||
};
|
||||
let ttg = why::arrival(d);
|
||||
if h.cover == 0 && sim.sams.iter().filter(covers).next().is_some() {
|
||||
h.ttg.0 = ttg;
|
||||
}
|
||||
if h.reach == 0 && sim.sams.iter().filter(covers).any(|m| m.seen.contains(&d.id)) {
|
||||
h.ttg.1 = ttg;
|
||||
}
|
||||
h.cover += u32::from(sim.sams.iter().filter(covers).next().is_some());
|
||||
h.reach += u32::from(sim.sams.iter().filter(covers).any(|m| m.seen.contains(&d.id)));
|
||||
}
|
||||
}
|
||||
// Drones gone from the sky that were never brought down arrived (or crashed).
|
||||
let here: std::collections::HashSet<u32> = sim.drones.iter().map(|d| d.id).collect();
|
||||
let queued: std::collections::HashSet<u32> = sim.queue.iter().map(|q| q.1.id).collect();
|
||||
let vanished: Vec<u32> = hist.iter().filter(|(id, h)| !here.contains(id) && !queued.contains(id) && !h.dead && h.kind.is_some()).map(|(id, _)| *id).collect();
|
||||
for id in vanished {
|
||||
if let Some(h) = hist.remove(&id) {
|
||||
// Gone from the sky near its aim: arrived. (A kill that detonates or breaks up removes the drone too.)
|
||||
let k = h.kind.unwrap();
|
||||
if !k.spec().decoy && h.last.0.distance(h.last.1) < 2.0 * k.spec().speed + 12.0 {
|
||||
if std::env::var("LEAKS").is_ok() {
|
||||
eprintln!(" leak {k:?} seen {} cover {} reach {} shots {} ttg cover/track/shot {:.0}/{:.0}/{:.0}", h.seen, h.cover, h.reach, h.shots.len(), h.ttg.0, h.ttg.1, h.ttg.2);
|
||||
for m in &sim.missiles {
|
||||
if let Some(h) = hist.get_mut(&m.target) {
|
||||
if h.shots.is_empty() {
|
||||
h.ttg.2 = h.last.0.distance(h.last.1) / h.kind.map_or(1.0, |k| k.spec().speed);
|
||||
}
|
||||
gone_unkilled.push(h);
|
||||
h.shots.insert(m.id);
|
||||
}
|
||||
}
|
||||
// Drones gone from the sky that were never brought down arrived (or crashed).
|
||||
let here: std::collections::HashSet<u32> = sim.drones.iter().map(|d| d.id).collect();
|
||||
let queued: std::collections::HashSet<u32> = sim.queue.iter().map(|q| q.1.id).collect();
|
||||
let vanished: Vec<u32> = hist.iter().filter(|(id, h)| !here.contains(id) && !queued.contains(id) && !h.dead && h.kind.is_some()).map(|(id, _)| *id).collect();
|
||||
for id in vanished {
|
||||
if let Some(mut h) = hist.remove(&id) {
|
||||
// Gone from the sky near its aim: arrived. (A kill that detonates or breaks up removes the drone too.)
|
||||
let k = h.kind.unwrap();
|
||||
if !k.spec().decoy && h.last.0.distance(h.last.1) < 2.0 * k.spec().speed + 12.0 {
|
||||
if std::env::var("LEAKS").is_ok() {
|
||||
eprintln!(" leak {k:?} seen {} cover {} reach {} shots {} ttg cover/track/shot {:.0}/{:.0}/{:.0}", h.seen, h.cover, h.reach, h.shots.len(), h.ttg.0, h.ttg.1, h.ttg.2);
|
||||
}
|
||||
h.ttg.2 = (now - start) as f64;
|
||||
gone_unkilled.push(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Dead ones that have landed are forgotten.
|
||||
hist.retain(|id, h| !(h.dead && !here.contains(id)));
|
||||
if now - start > 300 && sim.queue.is_empty() && !sim.planning() && !sim.drones.iter().any(|d| d.alive()) && sim.missiles.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Dead ones that have landed are forgotten.
|
||||
hist.retain(|id, h| !(h.dead && !here.contains(id)));
|
||||
if now - start > 300 && sim.queue.is_empty() && !sim.planning() && !sim.drones.iter().any(|d| d.alive()) && sim.missiles.is_empty() {
|
||||
break;
|
||||
let mut r = count(&sim, &gone_unkilled, start, land.tickets);
|
||||
let mut lost: HashMap<SamKind, u32> = HashMap::new();
|
||||
for m in sim.sams.iter().filter(|m| !m.alive()) {
|
||||
*lost.entry(m.kind).or_default() += 1;
|
||||
}
|
||||
let mut lost: Vec<_> = lost.into_iter().collect();
|
||||
lost.sort_by_key(|k| k.0 as u8);
|
||||
r.lost = lost;
|
||||
r.aims = std::mem::take(&mut aims);
|
||||
aims.clear();
|
||||
r.missiles = r.missiles.saturating_sub(fired0);
|
||||
r.launched = r.launched.saturating_sub(results.iter().map(|p: &Result| p.launched).sum::<u32>());
|
||||
r.leaked = sim.hits - leaked_before;
|
||||
leaked_before = sim.hits;
|
||||
results.push(r);
|
||||
// The reloads before the next one.
|
||||
for _ in 0..700 {
|
||||
land.serve(&mut ground, sim.tick);
|
||||
out = Out::default();
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
}
|
||||
}
|
||||
result.tickets = land.tickets;
|
||||
results
|
||||
}
|
||||
|
||||
/// Counts the raid that has just ended: the drones that got through are `gone`.
|
||||
fn count(sim: &Sim, gone: &[Hist], start: u64, tickets: usize) -> Result {
|
||||
let mut result = Result::default();
|
||||
result.tickets = tickets;
|
||||
result.scrubs = sim.scrubs.clone();
|
||||
result.crashed = sim.crashed.iter().map(|c| (c.0, c.1, c.1.distance(c.2))).collect();
|
||||
result.ticks = sim.tick - start;
|
||||
result.launched = sim.launched;
|
||||
result.kills = sim.kills;
|
||||
result.missiles = sim.sams.iter().map(|m| m.fired).sum::<u32>() - fired0;
|
||||
result.missiles = sim.sams.iter().map(|m| m.fired).sum();
|
||||
result.heavy = sim.sams.iter().filter(|m| matches!(m.kind, SamKind::S400 | SamKind::S500 | SamKind::Patriot)).map(|m| m.fired).sum();
|
||||
result.hits = sim.hits;
|
||||
result.crashes = sim.crashes;
|
||||
@@ -333,8 +433,18 @@ pub(super) fn fly(s: &Setup) -> Result {
|
||||
result.orphaned = sim.tally.orphaned;
|
||||
result.energy_lost = sim.tally.energy_lost;
|
||||
result.leaked = sim.hits;
|
||||
result.leak_ticks = gone.iter().map(|h| h.ttg.2 as u64).collect();
|
||||
let armed: Vec<_> = sim.sams.iter().filter(|m| m.kind.armed()).collect();
|
||||
result.armed = armed.len();
|
||||
result.empty = armed.iter().filter(|m| m.missiles == 0 && m.bursts == 0).count();
|
||||
let mut by: HashMap<SamKind, u32> = HashMap::new();
|
||||
for m in &armed {
|
||||
*by.entry(m.kind).or_default() += m.kills;
|
||||
}
|
||||
result.kills_by = by.into_iter().collect();
|
||||
result.kills_by.sort_by_key(|k| k.0 as u8);
|
||||
let mut kinds: HashMap<DroneKind, (u32, u32)> = HashMap::new();
|
||||
for h in &gone_unkilled {
|
||||
for h in gone {
|
||||
let k = h.kind.unwrap();
|
||||
kinds.entry(k).or_default().0 += 1;
|
||||
if h.seen == 0 {
|
||||
@@ -355,6 +465,46 @@ pub(super) fn fly(s: &Setup) -> Result {
|
||||
result
|
||||
}
|
||||
|
||||
/// Three raids in a row from one cluster with a stocked depot by every system: the reloads keep the third
|
||||
/// raid close to the first (without them a big raid gets through almost whole once the magazines are empty).
|
||||
#[test]
|
||||
fn stocked_depots_keep_a_long_defence_standing() {
|
||||
let mut s = Setup::new(12, false, 4);
|
||||
s.size = 12;
|
||||
s.depots = DEPOT_REACH / 2.0;
|
||||
s.raids = 2;
|
||||
let rows = fly_raids(&s);
|
||||
assert_eq!(rows.len(), 2);
|
||||
assert!(rows[1].leaked <= rows[0].leaked + 4, "second raid leaked {} after {}", rows[1].leaked, rows[0].leaked);
|
||||
}
|
||||
|
||||
/// One raid in detail after another, with the depots' stock and how far they stand from the systems:
|
||||
/// `DEPOTD=30 RAIDS=3 SAMS=70 SIZE=160 cargo test --release supply_raids -- --ignored --nocapture`.
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn supply_raids() {
|
||||
let n: usize = std::env::var("SAMS").ok().and_then(|v| v.parse().ok()).unwrap_or(70);
|
||||
let size: u32 = std::env::var("SIZE").ok().and_then(|v| v.parse().ok()).unwrap_or(160);
|
||||
let depot: f64 = std::env::var("DEPOTD").ok().and_then(|v| v.parse().ok()).unwrap_or(30.0);
|
||||
let raids: u32 = std::env::var("RAIDS").ok().and_then(|v| v.parse().ok()).unwrap_or(3);
|
||||
let smart = std::env::var("SMART").is_ok();
|
||||
for seed in 1..=6u64 {
|
||||
let mut s = Setup::new(n, smart, seed);
|
||||
s.size = size;
|
||||
s.depots = depot;
|
||||
s.raids = raids;
|
||||
for (i, r) in fly_raids(&s).into_iter().enumerate() {
|
||||
let mut ticks = r.leak_ticks.clone();
|
||||
ticks.sort_unstable();
|
||||
eprintln!("depots {depot:.0} seed {seed} raid {}: sent {} kills {} leaked {} missiles {} ticks {}; unseen {} nocover {} untracked {} unshot {} missed {}; empty at the end {} of {}; leaks at ticks {:?}",
|
||||
i + 1, r.launched, r.kills, r.leaked, r.missiles, r.ticks, r.unseen, r.no_cover, r.untracked, r.unshot, r.missed, r.empty, r.armed, ticks);
|
||||
let mut aims: Vec<_> = r.aims.iter().map(|a| (a.1, a.0.clone())).collect();
|
||||
aims.sort_by(|a, b| b.0.cmp(&a.0));
|
||||
eprintln!(" aims {:?}; lost {:?}", aims, r.lost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn table(title: &str, smart: bool, size: u32, systems: &[usize], seeds: &[u64], tweak: fn(&mut Sim)) -> Vec<(usize, f64)> {
|
||||
table_on(title, smart, size, systems, seeds, tweak, std::env::var("HILLS").is_ok())
|
||||
}
|
||||
@@ -521,6 +671,13 @@ fn one_raid() {
|
||||
s.size = size;
|
||||
let r = fly(&s);
|
||||
eprintln!("seed {seed}: sent {} kills {} leaked {} missiles {} ticks {}", r.launched, r.kills, r.leaked, r.missiles, r.ticks);
|
||||
if std::env::var("ROWS").is_ok() {
|
||||
let mut ticks = r.leak_ticks.clone();
|
||||
ticks.sort_unstable();
|
||||
eprintln!(" leaks unseen {} nocover {} untracked {} unshot {} missed {}; by kind {:?}; at ticks {:?}",
|
||||
r.unseen, r.no_cover, r.untracked, r.unshot, r.missed, r.aims, ticks);
|
||||
eprintln!(" armed {} empty at the end {}; kills by {:?}", r.armed, r.empty, r.kills_by);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -243,6 +243,8 @@ impl Sam {
|
||||
/// Change the physical configuration. Invalid combinations leave the unit untouched.
|
||||
pub fn set_mode(&mut self, mode: SamMode) -> bool {
|
||||
if mode == SamMode::LauncherOnly && !catalog::has_separate_launcher(self.kind) { return false; }
|
||||
// A kind that exists only as a separate launcher has no radar to switch back to.
|
||||
if mode == SamMode::Integrated && catalog::has_separate_launcher(self.kind) && self.mode != SamMode::Integrated { return false; }
|
||||
if self.mode != mode {
|
||||
self.mode = mode;
|
||||
self.tracks.clear();
|
||||
@@ -480,27 +482,38 @@ mod tests {
|
||||
#[test]
|
||||
fn launcher_has_no_own_map_sensor_and_mode_switch_drops_stale_tracks() {
|
||||
let mut sim = Sim::new(3);
|
||||
// The С-400 is a separate launcher: no map sensor of its own from the start, and no radar to switch to.
|
||||
sim.sams.push(Sam::new(1, SamKind::S400, DVec3::ZERO, 0.0));
|
||||
assert!(sim.low_sensor(SamKind::S400, DVec3::ZERO, Some(1)).is_some());
|
||||
sim.sams[0].tracks.push(track(10));
|
||||
sim.sams[0].terrain.insert(42, (10, 1));
|
||||
assert!(sim.sams[0].set_mode(SamMode::LauncherOnly));
|
||||
assert_eq!(sim.sams[0].mode, SamMode::LauncherOnly);
|
||||
assert!(sim.low_sensor(SamKind::S400, DVec3::ZERO, Some(1)).is_none());
|
||||
assert!(sim.low_sensors().is_empty());
|
||||
assert!(sim.sams[0].track(42).is_none());
|
||||
assert!(sim.sams[0].terrain.is_empty());
|
||||
sim.sams[0].set_mode(SamMode::Integrated);
|
||||
assert!(sim.low_sensor(SamKind::S400, DVec3::ZERO, Some(1)).is_some());
|
||||
assert!(!sim.sams[0].set_mode(SamMode::Integrated));
|
||||
assert_eq!(sim.sams[0].mode, SamMode::LauncherOnly);
|
||||
// A kind that keeps its own radar maps it, and refuses the separate-launcher switch.
|
||||
let mut patriot = Sam::new(2, SamKind::Patriot, DVec3::new(50.0, 0.0, 0.0), 0.0);
|
||||
patriot.tracks.push(track(10));
|
||||
patriot.terrain.insert(42, (10, 1));
|
||||
assert!(sim.low_sensor(SamKind::Patriot, DVec3::new(50.0, 0.0, 0.0), Some(2)).is_some());
|
||||
sim.sams.push(patriot);
|
||||
assert!(!sim.sams[1].set_mode(SamMode::LauncherOnly));
|
||||
assert!(sim.sams[1].track(42).is_some() && sim.sams[1].terrain.len() == 1);
|
||||
assert!(sim.sams[1].radar_up());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configuration_clears_old_tracks_and_rejects_other_kinds() {
|
||||
let mut sam = Sam::new(1, SamKind::S400, DVec3::ZERO, 0.0);
|
||||
sam.tracks.push(track(10));
|
||||
assert!(sam.set_mode(SamMode::LauncherOnly));
|
||||
assert!(sam.tracks.is_empty());
|
||||
assert!(sam.set_mode(SamMode::Integrated));
|
||||
assert!(sam.radar_up());
|
||||
assert!(sam.set_mode(SamMode::LauncherOnly), "its own configuration is accepted");
|
||||
assert!(!sam.set_mode(SamMode::Integrated), "a separate launcher has no radar to switch to");
|
||||
assert_eq!(sam.mode, SamMode::LauncherOnly);
|
||||
assert!(!sam.radar_up());
|
||||
let mut patriot = Sam::new(3, SamKind::Patriot, DVec3::ZERO, 0.0);
|
||||
patriot.tracks.push(track(10));
|
||||
patriot.terrain.insert(42, (10, 1));
|
||||
patriot.mode = SamMode::LauncherOnly;
|
||||
assert!(patriot.set_mode(SamMode::Integrated));
|
||||
assert!(patriot.tracks.is_empty() && patriot.terrain.is_empty());
|
||||
assert!(patriot.radar_up());
|
||||
let mut other = Sam::new(2, SamKind::Patriot, DVec3::ZERO, 0.0);
|
||||
assert!(!other.set_mode(SamMode::LauncherOnly));
|
||||
assert_eq!(other.mode, SamMode::Integrated);
|
||||
|
||||
@@ -19,9 +19,11 @@ impl Aircraft {
|
||||
pub fn id(self) -> &'static str { self.kind.spec().key }
|
||||
}
|
||||
|
||||
use super::units::Parts;
|
||||
|
||||
/// A variant of a complex: a configuration over an existing kind, deployed
|
||||
/// under its own command/menu id. Not new balance.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct UnitVariant {
|
||||
/// Existing command/menu key; changing it requires an explicit migration.
|
||||
pub id: &'static str,
|
||||
@@ -34,6 +36,8 @@ pub struct UnitVariant {
|
||||
pub label: &'static str,
|
||||
/// What the configuration is for (shown in the deploy menu).
|
||||
pub description: &'static str,
|
||||
/// The models a unit in this configuration is drawn with, when they differ from its kind's.
|
||||
pub parts: Option<&'static Parts>,
|
||||
}
|
||||
|
||||
impl UnitVariant {
|
||||
@@ -64,6 +68,8 @@ impl GroundStrike {
|
||||
pub struct Unit {
|
||||
pub kind: SamKind,
|
||||
pub deploy_item: &'static str,
|
||||
/// The kind is deployed as a separate launcher only: it has no radar of its own and fires on the network.
|
||||
pub launcher_only: bool,
|
||||
}
|
||||
|
||||
impl Unit {
|
||||
@@ -159,16 +165,24 @@ pub const INVENTORY: [&str; INVENTORY_COUNT] = inventory_items();
|
||||
pub fn launch_item(id: &str) -> Option<DroneKind> {
|
||||
AIRCRAFT.iter().find(|entry| entry.launch_item == Some(id)).map(|entry| entry.kind)
|
||||
}
|
||||
pub fn deploy_item(id: &str) -> Option<SamKind> {
|
||||
UNITS.iter().find(|entry| entry.deploy_item == id).map(|entry| entry.kind)
|
||||
pub fn deploy_item(id: &str) -> Option<&'static Unit> {
|
||||
UNITS.iter().find(|entry| entry.deploy_item == id)
|
||||
}
|
||||
/// The configuration a remote item deploys: a unit's ordinary integrated
|
||||
/// system or a variant's own mode and radar role.
|
||||
/// Whether the kind exists only as a separate launcher (the catalog's `mode: "launcher"`).
|
||||
pub fn launcher_only(kind: SamKind) -> bool {
|
||||
UNITS.iter().any(|entry| entry.kind == kind && entry.launcher_only)
|
||||
}
|
||||
/// The configuration a unit of `kind` is deployed in: its own radar, or the network's.
|
||||
pub fn unit_mode(kind: SamKind) -> SamMode {
|
||||
if launcher_only(kind) { SamMode::LauncherOnly } else { SamMode::Integrated }
|
||||
}
|
||||
/// The configuration a remote item deploys: a unit's own mode (a separate launcher for
|
||||
/// the kinds that are only launchers, its integrated system otherwise) or a variant's mode and radar role.
|
||||
pub fn deploy_item_configuration(id: &str) -> Option<(SamKind, SamMode, RadarRole)> {
|
||||
if let Some(kind) = deploy_item(id) {
|
||||
return Some((kind, SamMode::Integrated, RadarRole::Multifunction));
|
||||
if let Some(entry) = VARIANTS.iter().find(|entry| entry.deploy_item == id) {
|
||||
return Some((entry.kind, entry.mode, entry.role));
|
||||
}
|
||||
VARIANTS.iter().find(|entry| entry.deploy_item == id).map(|entry| (entry.kind, entry.mode, entry.role))
|
||||
deploy_item(id).map(|entry| (entry.kind, unit_mode(entry.kind), RadarRole::Multifunction))
|
||||
}
|
||||
|
||||
pub fn variant(id: &str) -> Option<&'static UnitVariant> {
|
||||
@@ -176,7 +190,7 @@ pub fn variant(id: &str) -> Option<&'static UnitVariant> {
|
||||
}
|
||||
|
||||
pub fn has_separate_launcher(kind: SamKind) -> bool {
|
||||
VARIANTS.iter().any(|variant| variant.kind == kind && variant.mode == SamMode::LauncherOnly)
|
||||
launcher_only(kind)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -234,7 +248,7 @@ mod tests {
|
||||
let first_unit = 1 + launches;
|
||||
for (i, unit) in UNITS.iter().enumerate() {
|
||||
assert_eq!(INVENTORY[first_unit + i], unit.deploy_item);
|
||||
assert_eq!(deploy_item_configuration(unit.deploy_item), Some((unit.kind, SamMode::Integrated, RadarRole::Multifunction)));
|
||||
assert_eq!(deploy_item_configuration(unit.deploy_item), Some((unit.kind, unit_mode(unit.kind), RadarRole::Multifunction)));
|
||||
}
|
||||
let tail = first_unit + UNITS.len();
|
||||
assert_eq!(&INVENTORY[tail..tail + 3], &["airdef:mover", "airdef:flare_gun", "airdef:remover"]);
|
||||
@@ -249,7 +263,9 @@ mod tests {
|
||||
#[test]
|
||||
fn variants_configure_existing_units_under_free_ids() {
|
||||
let ids: Vec<&str> = VARIANTS.iter().map(|v| v.id).collect();
|
||||
assert_eq!(ids, ["s400_launcher", "s500_launcher", "radar_search", "radar_track", "radar_height"]);
|
||||
assert_eq!(ids, ["radar_search", "radar_track", "radar_height"]);
|
||||
assert_eq!(deploy_item_configuration("airdef:deploy_s400"), Some((SamKind::S400, SamMode::LauncherOnly, RadarRole::Multifunction)));
|
||||
assert_eq!(deploy_item_configuration("airdef:deploy_patriot"), Some((SamKind::Patriot, SamMode::Integrated, RadarRole::Multifunction)));
|
||||
for v in VARIANTS {
|
||||
assert!(UNITS.iter().any(|unit| unit.kind == v.kind), "{} configures an unknown kind", v.id);
|
||||
assert!(SamKind::from_key(v.id).is_none(), "{} shadows a unit kind", v.id);
|
||||
@@ -268,9 +284,15 @@ mod tests {
|
||||
assert!(v.radar_profile().is_none());
|
||||
}
|
||||
}
|
||||
let launcher = variant("s400_launcher").unwrap();
|
||||
assert_eq!((launcher.kind, launcher.mode, launcher.role), (SamKind::S400, SamMode::LauncherOnly, RadarRole::Multifunction));
|
||||
assert_eq!(VARIANTS[4].id, "radar_height");
|
||||
assert_eq!(VARIANTS[2].id, "radar_height");
|
||||
// Each radar role is drawn with its own antenna; a unit takes its variant's models.
|
||||
let own: Vec<&str> = VARIANTS.iter().map(|v| v.parts.and_then(|p| p.spinner).map_or("", |s| s.0)).collect();
|
||||
assert_eq!(own, ["airdef:radar_search_array", "airdef:radar_dish", "airdef:radar_height_head"]);
|
||||
let search = super::super::Sam::new(1, SamKind::Radar, glam::DVec3::ZERO, 0.0);
|
||||
assert_eq!(search.parts().spinner.map(|s| s.0), Some(SamKind::Radar.spec().parts.spinner.map(|s| s.0).unwrap()));
|
||||
let mut track = super::super::Sam::new(2, SamKind::Radar, glam::DVec3::ZERO, 0.0);
|
||||
assert!(track.set_radar_role(RadarRole::Engagement));
|
||||
assert_eq!(track.parts().spinner.map(|s| s.0), Some("airdef:radar_dish"));
|
||||
assert!(variant("miss").is_none() && variant("s400").is_none());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,20 +16,20 @@ pub const AIRCRAFT: &[Aircraft] = &[
|
||||
];
|
||||
|
||||
pub const UNITS: &[Unit] = &[
|
||||
Unit { kind: SamKind::Patriot, deploy_item: "airdef:deploy_patriot" },
|
||||
Unit { kind: SamKind::Gepard, deploy_item: "airdef:deploy_gepard" },
|
||||
Unit { kind: SamKind::Pantsir, deploy_item: "airdef:deploy_pantsir" },
|
||||
Unit { kind: SamKind::S400, deploy_item: "airdef:deploy_s400" },
|
||||
Unit { kind: SamKind::S500, deploy_item: "airdef:deploy_s500" },
|
||||
Unit { kind: SamKind::IrisT, deploy_item: "airdef:deploy_irist" },
|
||||
Unit { kind: SamKind::Nasams, deploy_item: "airdef:deploy_nasams" },
|
||||
Unit { kind: SamKind::Buk, deploy_item: "airdef:deploy_buk" },
|
||||
Unit { kind: SamKind::Tor, deploy_item: "airdef:deploy_tor" },
|
||||
Unit { kind: SamKind::P1sun, deploy_item: "airdef:deploy_p1sun" },
|
||||
Unit { kind: SamKind::Radar, deploy_item: "airdef:deploy_radar" },
|
||||
Unit { kind: SamKind::Depot, deploy_item: "airdef:deploy_depot" },
|
||||
Unit { kind: SamKind::Tzm, deploy_item: "airdef:deploy_tzm" },
|
||||
Unit { kind: SamKind::Ew, deploy_item: "airdef:deploy_ew" },
|
||||
Unit { kind: SamKind::Light, deploy_item: "airdef:deploy_light" },
|
||||
Unit { kind: SamKind::Optical, deploy_item: "airdef:deploy_optical" },
|
||||
Unit { kind: SamKind::Patriot, deploy_item: "airdef:deploy_patriot", launcher_only: false },
|
||||
Unit { kind: SamKind::Gepard, deploy_item: "airdef:deploy_gepard", launcher_only: false },
|
||||
Unit { kind: SamKind::Pantsir, deploy_item: "airdef:deploy_pantsir", launcher_only: false },
|
||||
Unit { kind: SamKind::S400, deploy_item: "airdef:deploy_s400", launcher_only: true },
|
||||
Unit { kind: SamKind::S500, deploy_item: "airdef:deploy_s500", launcher_only: true },
|
||||
Unit { kind: SamKind::IrisT, deploy_item: "airdef:deploy_irist", launcher_only: false },
|
||||
Unit { kind: SamKind::Nasams, deploy_item: "airdef:deploy_nasams", launcher_only: false },
|
||||
Unit { kind: SamKind::Buk, deploy_item: "airdef:deploy_buk", launcher_only: false },
|
||||
Unit { kind: SamKind::Tor, deploy_item: "airdef:deploy_tor", launcher_only: false },
|
||||
Unit { kind: SamKind::P1sun, deploy_item: "airdef:deploy_p1sun", launcher_only: false },
|
||||
Unit { kind: SamKind::Radar, deploy_item: "airdef:deploy_radar", launcher_only: false },
|
||||
Unit { kind: SamKind::Depot, deploy_item: "airdef:deploy_depot", launcher_only: false },
|
||||
Unit { kind: SamKind::Tzm, deploy_item: "airdef:deploy_tzm", launcher_only: false },
|
||||
Unit { kind: SamKind::Ew, deploy_item: "airdef:deploy_ew", launcher_only: false },
|
||||
Unit { kind: SamKind::Light, deploy_item: "airdef:deploy_light", launcher_only: false },
|
||||
Unit { kind: SamKind::Optical, deploy_item: "airdef:deploy_optical", launcher_only: false },
|
||||
];
|
||||
|
||||
@@ -526,7 +526,7 @@ pub(super) fn draw_wreck_of(sam: &Sam, out: &mut Out) {
|
||||
let hull = sam.pos + DVec3::Y * (0.5 * s - 0.35);
|
||||
let side = DQuat::from_rotation_y(sam.heading) * DVec3::new(1.8 * s, 0.0, 0.6 * s);
|
||||
let thrown = DQuat::from_rotation_y(sam.heading + 1.1) * DQuat::from_rotation_z(1.2);
|
||||
let parts = &sam.kind.spec().parts;
|
||||
let parts = &sam.parts();
|
||||
let (body, part) = (parts.body, parts.launcher.or(parts.pack));
|
||||
out.model(sam.id, super::units::wreck(body), hull, tilt, s, false);
|
||||
if let Some(part) = part {
|
||||
|
||||
@@ -49,6 +49,9 @@ pub fn bounds(id: &str) -> Option<([f64; 3], [f64; 3])> {
|
||||
"airdef:nasams_launcher_burnt" => ([0.0, 0.0, -16.0], [16.0, 9.0, 32.0]),
|
||||
"airdef:nasams_trailer" => ([-8.56, 0.0, -16.0], [24.56, 13.0, 26.0]),
|
||||
"airdef:nasams_trailer_burnt" => ([-8.56, 0.0, -16.0], [24.56, 13.0, 26.0]),
|
||||
"airdef:optical_head" => ([2.5, -6.0, -7.5], [13.5, 10.0, 12.0]),
|
||||
"airdef:optical_post" => ([-6.0, 0.0, -6.0], [22.0, 9.0, 22.0]),
|
||||
"airdef:optical_post_burnt" => ([-6.0, 0.0, -6.0], [22.0, 9.0, 22.0]),
|
||||
"airdef:p1sun" => ([-0.5, -0.5, -14.0], [16.5, 16.5, 10.0]),
|
||||
"airdef:p1sun_launcher" => ([-0.5, 0.0, -16.0], [16.5, 7.0, 32.0]),
|
||||
"airdef:p1sun_launcher_burnt" => ([-0.5, 0.0, -16.0], [16.5, 7.0, 32.0]),
|
||||
@@ -66,10 +69,14 @@ pub fn bounds(id: &str) -> Option<([f64; 3], [f64; 3])> {
|
||||
"airdef:patriot_trailer" => ([-9.06, 0.0, -16.0], [25.06, 16.0, 32.0]),
|
||||
"airdef:patriot_trailer_burnt" => ([-9.06, 0.0, -16.0], [25.0, 16.0, 32.0]),
|
||||
"airdef:patriot_truck" => ([-8.56, 0.0, -16.0], [24.56, 22.0, 32.0]),
|
||||
"airdef:radar_dish" => ([-8.5, -10.0, -2.0], [24.5, 20.5, 17.0]),
|
||||
"airdef:radar_height_head" => ([0.5, -8.0, 5.0], [15.5, 16.0, 11.0]),
|
||||
"airdef:radar_mast" => ([4.0, 0.0, 4.0], [12.0, 32.0, 12.0]),
|
||||
"airdef:radar_mast_burnt" => ([4.0, 0.0, 4.0], [12.0, 32.0, 12.0]),
|
||||
"airdef:radar_panel" => ([-10.5, -6.0, 7.0], [26.5, 26.5, 12.0]),
|
||||
"airdef:radar_search_array" => ([-16.002081, -10.0, 4.0], [32.002081, 32.0, 13.0]),
|
||||
"airdef:radar_trailer" => ([-9.0, -1.379664, -12.0], [25.0, 18.0, 26.379664]),
|
||||
"airdef:radar_trailer_burnt" => ([-9.0, -1.379664, -12.0], [25.0, 18.0, 26.379664]),
|
||||
"airdef:radar_truck" => ([-8.56, 0.0, -16.0], [24.56, 20.0, 32.0]),
|
||||
"airdef:radar_truck_burnt" => ([-8.56, 0.0, -16.0], [24.56, 20.0, 32.0]),
|
||||
"airdef:reentry" => ([6.5, 6.5, -16.0], [9.5, 9.5, 32.0]),
|
||||
|
||||
@@ -1283,7 +1283,7 @@ mod tests {
|
||||
#[test]
|
||||
fn depot_only_reloads_matching_system_and_weapon_channel() {
|
||||
let mut sim = Sim::new(1);
|
||||
for (kind, x) in [(SamKind::Depot, 0.0), (SamKind::S400, 10.0), (SamKind::Pantsir, 12.0), (SamKind::Patriot, 25.0)] {
|
||||
for (kind, x) in [(SamKind::Depot, 0.0), (SamKind::S400, 10.0), (SamKind::Pantsir, 12.0), (SamKind::Patriot, DEPOT_REACH + 10.0)] {
|
||||
let id = sim.id();
|
||||
sim.sams.push(Sam::new(id, kind, DVec3::new(x, 70.0, 0.0), 0.0));
|
||||
}
|
||||
@@ -1300,7 +1300,7 @@ mod tests {
|
||||
sim.step_supply(&mut Out::default());
|
||||
assert_eq!(sim.sams[1].reloading, 0, "S-400 must not reload from Patriot stock");
|
||||
assert!(sim.sams[1].empty);
|
||||
assert_eq!(sim.sams[3].reloading, 0, "Patriot beyond DEPOT_REACH (25 > 16) must not auto-reload directly");
|
||||
assert_eq!(sim.sams[3].reloading, 0, "Patriot beyond DEPOT_REACH must not auto-reload directly");
|
||||
assert!(sim.sams[3].empty);
|
||||
assert!(sim.sams[2].reloading > 0, "Pantsir must start reloading missiles");
|
||||
assert_eq!(sim.sams[0].ammo_stock.get(AmmoKind::PantsirMissile), 0);
|
||||
|
||||
@@ -1293,7 +1293,7 @@ impl Sam {
|
||||
Self {
|
||||
id,
|
||||
kind,
|
||||
mode: battery::SamMode::Integrated,
|
||||
mode: catalog::unit_mode(kind),
|
||||
radar_role: battery::RadarRole::Multifunction,
|
||||
radar_on: true,
|
||||
spent_cells: 0,
|
||||
@@ -1521,6 +1521,8 @@ pub struct Sim {
|
||||
pub queue: Vec<(u64, Drone)>,
|
||||
/// The raid's launch sites and their jobs (#100).
|
||||
pub sites: sites::Sites,
|
||||
/// The sides each approach last raided from, with its distance: (approach, distance, bearings).
|
||||
launch_areas: Vec<(raid::Approach, f64, Vec<f64>)>,
|
||||
/// Launch sites found by the radars, and the counter-strikes on them (#101).
|
||||
pub strikes: strike::Strikes,
|
||||
/// A raid being planned.
|
||||
@@ -1642,6 +1644,7 @@ impl Sim {
|
||||
intel: ew::Intel::default(),
|
||||
recon: recon::Recon::default(),
|
||||
smart_legacy: false,
|
||||
launch_areas: Vec::new(),
|
||||
refresh: None,
|
||||
refresh_applied: 0,
|
||||
bearing: ew::BearingReport::default(),
|
||||
@@ -2622,7 +2625,7 @@ impl Sim {
|
||||
if me.missiles == 0 || me.reloading > 0 || me.part(Part::Launcher) <= 0.0 || me.preparing.is_some_and(|p| p.ground) {
|
||||
return None;
|
||||
}
|
||||
let radars: Vec<&Sam> = if me.mode == battery::SamMode::LauncherOnly || (me.kind.far_shooter() && opts.far_shots) { self.sams.iter().filter(|s| s.kind == SamKind::Radar).collect() } else { Vec::new() };
|
||||
let radars: Vec<&Sam> = if why::on_network(me) || (me.kind.far_shooter() && opts.far_shots) { self.sams.iter().filter(|s| s.kind == SamKind::Radar).collect() } else { Vec::new() };
|
||||
let cued = |id: u32| !radars.is_empty() && why::radar_cue(me, &radars, id, now);
|
||||
let basis = |tr: &Track, k: f64, role_in_reach: bool| {
|
||||
let d = drone(tr).filter(|_| open(tr.id))?;
|
||||
|
||||
@@ -83,6 +83,9 @@ impl RaidOrder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Raids ordered about this far apart share their launch sides.
|
||||
const AREA_DIST: f64 = 200.0;
|
||||
|
||||
/// A drone of a raid being planned.
|
||||
struct Item {
|
||||
d: Drone,
|
||||
@@ -353,8 +356,18 @@ impl Sim {
|
||||
let leads = &knowledge.marks;
|
||||
// A smart enemy comes from where its raids got through best.
|
||||
let bearing = if smart { self.best_bearing() } else { self.rng.f() * TAU };
|
||||
// The raid's sides (1, 2, or 4-5): its launch sites go there (#100).
|
||||
let sides = sites::pick_sides(&mut self.rng, order.approach, bearing);
|
||||
// The raid's sides (1, 2, or 4-5): its launch sites go there (#100). An enemy that raided
|
||||
// this way and from this far before comes from the same sides again: its launch areas are
|
||||
// where they were, and the defence that found them once knows where to look.
|
||||
let sides = match self.launch_areas.iter().find(|a| a.0 == order.approach && (a.1 - order.dist).abs() <= AREA_DIST) {
|
||||
Some(a) => a.2.clone(),
|
||||
None => {
|
||||
let sides = sites::pick_sides(&mut self.rng, order.approach, bearing);
|
||||
self.launch_areas.retain(|a| a.0 != order.approach);
|
||||
self.launch_areas.push((order.approach, order.dist, sides.clone()));
|
||||
sides
|
||||
}
|
||||
};
|
||||
let mut wants: Vec<sites::Want> = Vec::new();
|
||||
// One grid over the whole raid; each kind's prices are worked out once, routes are shared
|
||||
// by the drones of a kind going from the same bearing to the same target.
|
||||
@@ -1067,6 +1080,7 @@ impl Sim {
|
||||
next_free: 0,
|
||||
offmap,
|
||||
});
|
||||
self.known_lair(w.site, pos, w.class);
|
||||
}
|
||||
if shortened {
|
||||
out.messages.push("Пуск ближе обычного: дальше нет известной земли или воды".into());
|
||||
|
||||
@@ -2575,7 +2575,9 @@ fn p1sun_stays_a_ramming_drone_without_a_plume() {
|
||||
fn recorded_ignition_is_cold_ticks_after_ejection_and_replay_follows_it() {
|
||||
let mut sim = Sim::new(0x129);
|
||||
let sam = sim.id();
|
||||
sim.sams.push(Sam::new(sam, SamKind::S400, DVec3::new(0.0, 64.0, 0.0), 0.0));
|
||||
let mut carrier = Sam::new(sam, SamKind::S400, DVec3::new(0.0, 64.0, 0.0), 0.0);
|
||||
carrier.mode = battery::SamMode::Integrated;
|
||||
sim.sams.push(carrier);
|
||||
sim.sams[0].cooldown = 0;
|
||||
let mut out = Out::default();
|
||||
sim.launch(DroneKind::Kh101, DVec3::new(0.0, 160.0, -600.0), DVec3::Z, DVec3::new(0.0, 64.0, 0.0), &mut out);
|
||||
|
||||
@@ -541,6 +541,39 @@ fn each_profile_is_useful_alone_and_the_full_set_covers_all_three_jobs() {
|
||||
assert!(duplicate.first_low_refined.is_none() && duplicate.first_close_fire.is_none(), "two search radars invented another function: {duplicate:?}");
|
||||
}
|
||||
|
||||
/// The P1-SUN has no radar of its own: like a separate launcher it fires on a fire radar's own fresh plot,
|
||||
/// and on nothing without one (it used to be neither: it never launched at all).
|
||||
#[test]
|
||||
fn a_p1sun_fires_on_a_fire_radars_plot_and_not_on_the_network_alone() {
|
||||
let mut sim = Sim::new(5);
|
||||
let (mut ground, mut out) = flat();
|
||||
let engagement = radar_with_role(&mut sim, RadarRole::Engagement, 0.0);
|
||||
let p = sim.id();
|
||||
sim.sams.push(Sam::new(p, SamKind::P1sun, DVec3::new(100.0, 70.0, 0.0), 0.0));
|
||||
assert!(why::on_network(sim.sams.iter().find(|s| s.id == p).unwrap()));
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(-150.0, 95.0, 40.0), DVec3::X, DVec3::new(5000.0, 95.0, 40.0));
|
||||
let mut fired = 0;
|
||||
for _ in 0..500 {
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
fired = (sim.sams.iter().filter(|s| s.kind == SamKind::P1sun).map(|s| s.fired).sum::<u32>(), ()).0;
|
||||
if fired > 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let _ = engagement;
|
||||
assert!(fired > 0, "the P1-SUN never launched on the engagement radar's plot");
|
||||
// A search radar's coarse plot is no basis, and without any fire radar nothing comes.
|
||||
let mut sim = Sim::new(5);
|
||||
radar_with_role(&mut sim, RadarRole::Search, 0.0);
|
||||
let p = sim.id();
|
||||
sim.sams.push(Sam::new(p, SamKind::P1sun, DVec3::new(100.0, 70.0, 0.0), 0.0));
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(-150.0, 95.0, 40.0), DVec3::X, DVec3::new(5000.0, 95.0, 40.0));
|
||||
for _ in 0..400 {
|
||||
sim.step(&mut ground, None, &mut out);
|
||||
}
|
||||
assert_eq!(sim.sams.iter().filter(|s| s.kind == SamKind::P1sun).map(|s| s.fired).sum::<u32>(), 0, "a search radar's plot launched a P1-SUN");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn network_relay_keeps_source_age_and_quality_but_not_launch_authority() {
|
||||
let mut sim = Sim::new(1341);
|
||||
@@ -549,6 +582,7 @@ fn network_relay_keeps_source_age_and_quality_but_not_launch_authority() {
|
||||
let receiver = {
|
||||
let id = sim.id();
|
||||
let mut s400 = Sam::new(id, SamKind::S400, DVec3::new(20.0, 70.0, 0.0), 0.0);
|
||||
s400.mode = battery::SamMode::Integrated;
|
||||
// A blind receiver: only the network can give it a track.
|
||||
s400.comps.0[Part::Sensor as usize] = 0.0;
|
||||
s400.roles = 0xff;
|
||||
|
||||
@@ -652,6 +652,40 @@ mod tests {
|
||||
n
|
||||
}
|
||||
|
||||
/// A raid ordered the same way and from about the same distance comes from the sides the last such
|
||||
/// raid used, so its sites stand where theirs did; another distance picks its own sides.
|
||||
#[test]
|
||||
fn a_raid_ordered_the_same_way_comes_from_the_same_sides_again() {
|
||||
let (land, mut ground, mut out) = (flat(), Ground::default(), Out::default());
|
||||
let mut sim = Sim::new(21);
|
||||
let places = |sim: &Sim| -> Vec<(SiteClass, i32, i32)> {
|
||||
let mut v: Vec<_> = sim.sites.list.iter().map(|s| (s.class, s.pos.x.round() as i32, s.pos.z.round() as i32)).collect();
|
||||
v.sort_by_key(|p| (p.0 as u8, p.1, p.2));
|
||||
v.dedup();
|
||||
v
|
||||
};
|
||||
plan(&mut sim, &mut ground, &land, &order(Approach::Sector, 300.0), &mut out);
|
||||
let first = places(&sim);
|
||||
assert_eq!(sim.sites.list.iter().map(|s| s.sector).collect::<std::collections::HashSet<_>>().len(), 1, "one sector");
|
||||
sim.sites.clear();
|
||||
plan(&mut sim, &mut ground, &land, &order(Approach::Sector, 300.0), &mut out);
|
||||
assert_eq!(places(&sim), first, "the same raid came from somewhere else");
|
||||
// About the same distance: the same side, at its own range.
|
||||
sim.sites.clear();
|
||||
plan(&mut sim, &mut ground, &land, &order(Approach::Sector, 350.0), &mut out);
|
||||
let near = places(&sim);
|
||||
assert_eq!(near.len(), first.len());
|
||||
assert!(near.iter().zip(&first).all(|(a, b)| a.0 == b.0 && a.1 == b.1 && (a.2 - b.2).abs() < 60), "{near:?}");
|
||||
sim.sites.clear();
|
||||
plan(&mut sim, &mut ground, &land, &order(Approach::Sector, 1200.0), &mut out);
|
||||
let far = places(&sim);
|
||||
assert!(far.iter().all(|p| p.2.abs() > 900), "a raid from 1200 blocks stood near the defence: {far:?}");
|
||||
// Another way in is remembered separately.
|
||||
sim.sites.clear();
|
||||
plan(&mut sim, &mut ground, &land, &order(Approach::TwoSectors, 300.0), &mut out);
|
||||
assert_eq!(sim.sites.list.iter().map(|s| s.sector).collect::<std::collections::HashSet<_>>().len(), 2, "two sectors");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sites_per_sector_mode_launch_every_drone_from_a_site_on_a_side() {
|
||||
for (approach, sides) in [(Approach::Sector, 1usize), (Approach::TwoSectors, 2), (Approach::AllSides, 5), (Approach::Waves, 1)] {
|
||||
|
||||
@@ -86,6 +86,11 @@ pub struct Tune {
|
||||
pub scout_life: u64,
|
||||
}
|
||||
|
||||
/// A new site this near a launch area the radars fixed before is that same place.
|
||||
pub const LAIR_R: f64 = 40.0;
|
||||
/// Launch areas remembered.
|
||||
pub const LAIRS: usize = 32;
|
||||
|
||||
pub const TUNE: Tune = Tune {
|
||||
track_sigma: 0.052,
|
||||
seen_sigma: (0.04, 8.0),
|
||||
@@ -340,6 +345,9 @@ pub struct Strikes {
|
||||
pub cancelled: Vec<(u32, u32)>,
|
||||
/// News for the player, said at the next step.
|
||||
news: Vec<String>,
|
||||
/// Launch areas the intelligence has located: where a fixed site stood (x, z) and the fix. A raid
|
||||
/// that stands a site there again is known at once, before its first launch.
|
||||
pub(super) lairs: Vec<(DVec2, Estimate)>,
|
||||
/// Strikes: fired, destroyed, stunned, missed, shot down.
|
||||
pub fired: u32,
|
||||
pub destroyed: u32,
|
||||
@@ -354,7 +362,7 @@ impl Strikes {
|
||||
use super::memory::vec_bytes;
|
||||
vec_bytes(&self.known) + vec_bytes(&self.flights) + vec_bytes(&self.pending) + vec_bytes(&self.flown)
|
||||
+ vec_bytes(&self.wrecks) + vec_bytes(&self.cancelled)
|
||||
+ self.news.iter().map(|s| s.capacity()).sum::<usize>()
|
||||
+ self.news.iter().map(|s| s.capacity()).sum::<usize>() + vec_bytes(&self.lairs)
|
||||
}
|
||||
pub fn new() -> Self {
|
||||
Strikes { stock: TUNE.stock, ..Default::default() }
|
||||
@@ -561,6 +569,20 @@ impl Sim {
|
||||
}
|
||||
out.messages.append(&mut self.strikes.news);
|
||||
}
|
||||
// A fixed site is a launch area the intelligence remembers when its raid is over.
|
||||
let mut found: Vec<(DVec2, Estimate)> = Vec::new();
|
||||
for k in self.strikes.known.iter().filter(|k| k.est.is_some_and(|e| e.fix)) {
|
||||
let Some(s) = self.sites.get(k.site) else { continue };
|
||||
let at = DVec2::new(s.pos.x, s.pos.z);
|
||||
if self.strikes.lairs.iter().chain(found.iter()).any(|(p, _)| p.distance(at) <= LAIR_R) {
|
||||
continue;
|
||||
}
|
||||
found.push((at, k.est.unwrap()));
|
||||
}
|
||||
self.strikes.lairs.extend(found);
|
||||
if self.strikes.lairs.len() > LAIRS {
|
||||
self.strikes.lairs.drain(..self.strikes.lairs.len() - LAIRS);
|
||||
}
|
||||
// A site gone from the raid is gone from the list.
|
||||
let sites = &self.sites;
|
||||
self.strikes.known.retain(|k| sites.get(k.site).is_some());
|
||||
@@ -1196,6 +1218,19 @@ impl Sim {
|
||||
}
|
||||
|
||||
/// Lines for `/airdef sites`.
|
||||
/// A site the raid has just stood: on a launch area the radars fixed before, it is known from the
|
||||
/// start, with the fix they had then (a fresh sighting replaces it).
|
||||
pub(super) fn known_lair(&mut self, site: u32, pos: DVec3, class: SiteClass) {
|
||||
let at = DVec2::new(pos.x, pos.z);
|
||||
let Some((_, est)) = self.strikes.lairs.iter().find(|(p, _)| p.distance(at) <= LAIR_R) else { return };
|
||||
let est = *est;
|
||||
if self.strikes.known.iter().any(|k| k.site == site) {
|
||||
return;
|
||||
}
|
||||
self.strikes.known.push(Known { site, class, obs: Vec::new(), est: Some(est), launches: 0, last: self.tick, state: SiteState::Active, aimed: false });
|
||||
self.strikes.news.push(format!("ПУ №{} ({}): известная позиция, здесь уже замечали площадку", site, class_name(class)));
|
||||
}
|
||||
|
||||
pub fn site_lines(&self, from: DVec3) -> Vec<String> {
|
||||
let now = self.tick;
|
||||
let mut v: Vec<String> = self.strikes.known.iter().map(|k| {
|
||||
@@ -1371,6 +1406,47 @@ mod tests {
|
||||
assert_eq!(k.est.unwrap().pos, DVec2::new(20.0, 700.0));
|
||||
}
|
||||
|
||||
/// A launch area the radars fixed is remembered: a raid that stands a site there again is known
|
||||
/// before its first launch, with the fix they had. A site elsewhere starts unknown.
|
||||
#[test]
|
||||
fn a_raid_that_reuses_a_fixed_launch_area_is_known_at_once() {
|
||||
let mut sim = Sim::new(11);
|
||||
let at = DVec3::new(20.0, 64.0, 700.0);
|
||||
let first = fixed_site(&mut sim, at, 3);
|
||||
sim.add_obs(first, SiteClass::Ramp, Obs::point(DVec2::new(at.x, at.z), 20.0));
|
||||
assert!(sim.strikes.get(first).unwrap().est.unwrap().fix);
|
||||
sim.step_strikes(&mut Ground::default(), None, &mut Out::default());
|
||||
sim.sites.clear();
|
||||
sim.strikes.known.clear();
|
||||
let again = fixed_site(&mut sim, at + DVec3::new(6.0, 0.0, -4.0), 3);
|
||||
sim.known_lair(again, at + DVec3::new(6.0, 0.0, -4.0), SiteClass::Ramp);
|
||||
let k = sim.strikes.get(again).expect("the launch area was not remembered");
|
||||
assert!(k.est.is_some_and(|e| e.fix) && k.obs.is_empty(), "{:?}", k.est);
|
||||
let elsewhere = sim.sites.add(LaunchSite {
|
||||
id: 0,
|
||||
side: 0,
|
||||
sector: 0,
|
||||
bearing: 0.0,
|
||||
class: SiteClass::Ramp,
|
||||
pos: at + DVec3::new(300.0, 0.0, 0.0),
|
||||
range: 0.0,
|
||||
water: false,
|
||||
stock: 3,
|
||||
planned: 3,
|
||||
alive: true,
|
||||
next_free: 0,
|
||||
offmap: false,
|
||||
});
|
||||
sim.known_lair(elsewhere, at + DVec3::new(300.0, 0.0, 0.0), SiteClass::Ramp);
|
||||
assert!(sim.strikes.get(elsewhere).is_none(), "a site nobody ever fixed was known by magic");
|
||||
// A bearing alone (no fix) is not a located area.
|
||||
let mut blind = Sim::new(11);
|
||||
let site = fixed_site(&mut blind, at, 3);
|
||||
blind.add_obs(site, SiteClass::Ramp, Obs::ray(DVec2::new(0.0, 0.0), DVec2::new(1.0, 0.0), 1.0));
|
||||
blind.step_strikes(&mut Ground::default(), None, &mut Out::default());
|
||||
assert!(blind.strikes.lairs.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launches_seen_by_a_radar_in_reach_locate_the_site_and_the_circle_shrinks() {
|
||||
let (mut sim, mut ground, mut out, id) = scene(11, 12, Some(DVec3::new(0.0, 64.0, 200.0)));
|
||||
|
||||
@@ -443,12 +443,12 @@ const UNIT_SPEC_OPTICAL: SamSpec = SamSpec {
|
||||
roles: 0,
|
||||
family: Family::Static,
|
||||
parts: Parts {
|
||||
body: "airdef:radar_truck",
|
||||
body: "airdef:optical_post",
|
||||
launcher: None,
|
||||
pack: None,
|
||||
dish: None,
|
||||
fixed: &[],
|
||||
spinner: Some(("airdef:radar_panel", 1.2, 0.0, 0.6, -0.2)),
|
||||
spinner: Some(("airdef:optical_head", 0.4, 0.0, 1.0, 0.0)),
|
||||
},
|
||||
mount: (0.0, 0.0),
|
||||
pivot: DVec3::ZERO,
|
||||
|
||||
@@ -1,8 +1,31 @@
|
||||
// Generated by tools/gen_catalog.py from catalog/content.json. Do not edit.
|
||||
const PARTS_RADAR_SEARCH: Parts = Parts {
|
||||
body: "airdef:radar_trailer",
|
||||
launcher: None,
|
||||
pack: None,
|
||||
dish: None,
|
||||
fixed: &[],
|
||||
spinner: Some(("airdef:radar_search_array", 0.75, 0.0, 1.2, -0.1)),
|
||||
};
|
||||
const PARTS_RADAR_TRACK: Parts = Parts {
|
||||
body: "airdef:radar_trailer",
|
||||
launcher: None,
|
||||
pack: None,
|
||||
dish: None,
|
||||
fixed: &[],
|
||||
spinner: Some(("airdef:radar_dish", 0.75, 0.0, 1.25, -0.3)),
|
||||
};
|
||||
const PARTS_RADAR_HEIGHT: Parts = Parts {
|
||||
body: "airdef:radar_trailer",
|
||||
launcher: None,
|
||||
pack: None,
|
||||
dish: None,
|
||||
fixed: &[],
|
||||
spinner: Some(("airdef:radar_height_head", 0.7, 0.0, 1.0, 0.0)),
|
||||
};
|
||||
|
||||
pub const VARIANTS: &[UnitVariant] = &[
|
||||
UnitVariant { id: "s400_launcher", deploy_item: "airdef:deploy_s400_launcher", kind: SamKind::S400, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-400 — отдельная пусковая", description: "Пусковая С-400 без своей РЛС: работает по данным сети." },
|
||||
UnitVariant { id: "s500_launcher", deploy_item: "airdef:deploy_s500_launcher", kind: SamKind::S500, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-500 — отдельная пусковая", description: "Пусковая С-500 без своей РЛС: работает по данным сети." },
|
||||
UnitVariant { id: "radar_search", deploy_item: "airdef:deploy_radar_search", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Search, label: "РЛС обзора", description: "Дальний обзор: редкие грубые отметки и область поиска; права на пуск не даёт." },
|
||||
UnitVariant { id: "radar_track", deploy_item: "airdef:deploy_radar_track", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Engagement, label: "РЛС сопровождения", description: "Сопровождение: локальный поиск, два канала точных треков; собственное измерение даёт право на пуск." },
|
||||
UnitVariant { id: "radar_height", deploy_item: "airdef:deploy_radar_height", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Height, label: "Мачтовая РЛС", description: "Мачтовая: поднятая антенна уточняет низкие контакты над рельефом; права на пуск не даёт." },
|
||||
UnitVariant { id: "radar_search", deploy_item: "airdef:deploy_radar_search", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Search, label: "РЛС обзора", description: "Дальний обзор: редкие грубые отметки и область поиска; права на пуск не даёт.", parts: Some(&PARTS_RADAR_SEARCH) },
|
||||
UnitVariant { id: "radar_track", deploy_item: "airdef:deploy_radar_track", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Engagement, label: "РЛС сопровождения", description: "Сопровождение: локальный поиск, два канала точных треков; собственное измерение даёт право на пуск.", parts: Some(&PARTS_RADAR_TRACK) },
|
||||
UnitVariant { id: "radar_height", deploy_item: "airdef:deploy_radar_height", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Height, label: "Мачтовая РЛС", description: "Мачтовая: поднятая антенна уточняет низкие контакты над рельефом; права на пуск не даёт.", parts: Some(&PARTS_RADAR_HEIGHT) },
|
||||
];
|
||||
|
||||
@@ -39,6 +39,7 @@ pub enum Muzzle {
|
||||
}
|
||||
|
||||
/// The models a unit is drawn with.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Parts {
|
||||
/// The chassis, trailer or base.
|
||||
pub body: &'static str,
|
||||
@@ -188,6 +189,13 @@ impl SamKind {
|
||||
}
|
||||
|
||||
impl Sam {
|
||||
/// The models this unit is drawn with: a variant's own (a radar's antenna by its role), else its kind's.
|
||||
pub fn parts(&self) -> Parts {
|
||||
match catalog::VARIANTS.iter().find(|v| v.kind == self.kind && v.mode == self.mode && v.role == self.radar_role).and_then(|v| v.parts) {
|
||||
Some(parts) => *parts,
|
||||
None => self.kind.spec().parts,
|
||||
}
|
||||
}
|
||||
pub(super) fn base(&self) -> DQuat {
|
||||
DQuat::from_rotation_y(self.heading)
|
||||
}
|
||||
@@ -268,7 +276,7 @@ pub(super) fn draw_sam_model(sam: &Sam, rng: &mut Rng, out: &mut Out) {
|
||||
return;
|
||||
}
|
||||
let spec = sam.kind.spec();
|
||||
let parts = &spec.parts;
|
||||
let parts = &sam.parts();
|
||||
let base = sam.base();
|
||||
let s = spec.scale;
|
||||
let up = DVec3::Y * 0.5 * s;
|
||||
@@ -383,6 +391,8 @@ pub(super) fn wreck(model: &'static str) -> &'static str {
|
||||
"airdef:tor_turret" => "airdef:tor_turret_burnt",
|
||||
"airdef:p1sun_launcher" => "airdef:p1sun_launcher_burnt",
|
||||
"airdef:radar_truck" => "airdef:radar_truck_burnt",
|
||||
"airdef:radar_trailer" => "airdef:radar_trailer_burnt",
|
||||
"airdef:optical_post" => "airdef:optical_post_burnt",
|
||||
"airdef:depot" => "airdef:depot_burnt",
|
||||
"airdef:tzm_truck" => "airdef:tzm_truck_burnt",
|
||||
"airdef:ew_truck" => "airdef:ew_truck_burnt",
|
||||
|
||||
+21
-10
@@ -131,7 +131,7 @@ pub(super) fn radar_cue(sam: &Sam, radars: &[&Sam], id: u32, now: u64) -> bool {
|
||||
&& r.radar_up()
|
||||
&& r.pos.distance(sam.pos) <= r.link_range().min(sam.link_range())
|
||||
&& r.track(id).is_some_and(|t| {
|
||||
let age = if sam.mode == battery::SamMode::LauncherOnly { sight::MISSILE_AGE } else { FAR_RADAR_AGE };
|
||||
let age = if on_network(sam) { sight::MISSILE_AGE } else { FAR_RADAR_AGE };
|
||||
t.own_fire_within(now, age)
|
||||
})
|
||||
})
|
||||
@@ -193,6 +193,13 @@ pub(super) struct Opts {
|
||||
pub far_shots: bool,
|
||||
}
|
||||
|
||||
/// A launcher that fires on the network's picture: a separate launcher, or a unit with no radar of its
|
||||
/// own (the P1-SUN). It may launch on a fire-capable radar's own fresh plot within link reach; a system
|
||||
/// with its own radar rests on its own measurement (and only takes long shots on the cue).
|
||||
pub(super) fn on_network(sam: &Sam) -> bool {
|
||||
sam.mode == battery::SamMode::LauncherOnly || sam.kind.spec().sensor <= 0.0
|
||||
}
|
||||
|
||||
/// Whether, and on what basis, `sam` may launch at `d` on `track`: `k` stretches the reach (a held target
|
||||
/// may stray); `claimed` is the interceptors others have on it; `cued` that a big radar holds it; and
|
||||
/// `role_in_reach` that the system has a target of its roles in range anyway (no long shots then).
|
||||
@@ -204,7 +211,7 @@ pub(super) fn basis(sam: &Sam, load: &units::MissileLoad, track: &Track, d: &Dro
|
||||
// ordinary shot. A heavy system's *far* shot is the exception it already
|
||||
// had: it may use the cue radar's own confirmed fire plot beyond its reach.
|
||||
let own = track.own_authorizes(now);
|
||||
if sam.mode == battery::SamMode::LauncherOnly {
|
||||
if on_network(sam) {
|
||||
if !cued { return None; }
|
||||
} else if !own && !cued {
|
||||
return None;
|
||||
@@ -223,12 +230,12 @@ pub(super) fn basis(sam: &Sam, load: &units::MissileLoad, track: &Track, d: &Dro
|
||||
if reach == 0 {
|
||||
// A normal shot belongs to the battery's own confirmed measurement;
|
||||
// a launcher-only battery uses its supporting radar's (checked above).
|
||||
return (own || sam.mode == battery::SamMode::LauncherOnly).then_some(Basis::Role);
|
||||
return (own || on_network(sam)).then_some(Basis::Role);
|
||||
}
|
||||
let far = reach == TOO_FAR && reach_blocks(load.min, load.max, FAR_K, sam.pos, track.est(now)) == 0;
|
||||
return (far && far_blocks(opts.far_shots, sam, load, cued, role_in_reach) == 0).then_some(Basis::FarShot);
|
||||
}
|
||||
(reach == 0 && (own || sam.mode == battery::SamMode::LauncherOnly) && last_chance(opts.last_chance, sam, est, d, claimed)).then_some(Basis::LastChance)
|
||||
(reach == 0 && (own || on_network(sam)) && last_chance(opts.last_chance, sam, est, d, claimed)).then_some(Basis::LastChance)
|
||||
}
|
||||
|
||||
/// The kill chance of an interceptor that met its target `dist` from the launcher whose reach is `max`:
|
||||
@@ -426,7 +433,7 @@ impl Sim {
|
||||
&& closest(mount, sam.gun_cooldown).distance(mount) < gun.range
|
||||
});
|
||||
gun || spec.missile.as_ref().is_some_and(|load| {
|
||||
let authority = if sam.mode == battery::SamMode::LauncherOnly {
|
||||
let authority = if on_network(sam) {
|
||||
self.sams.iter().any(|radar| radar_cue(sam, &[radar], d.id, now))
|
||||
} else {
|
||||
track.own_authorizes(now)
|
||||
@@ -481,7 +488,7 @@ impl Sim {
|
||||
}
|
||||
let own = tr.own_authorizes(now);
|
||||
let cue = cued(d.id);
|
||||
let authorized = if sam.mode == battery::SamMode::LauncherOnly { cue } else { own || cue };
|
||||
let authorized = if on_network(sam) { cue } else { own || cue };
|
||||
if !authorized {
|
||||
a.no_authority += 1;
|
||||
continue;
|
||||
@@ -506,7 +513,7 @@ impl Sim {
|
||||
a.out_of_reach += 1;
|
||||
continue;
|
||||
}
|
||||
if reach == 0 && !(own || sam.mode == battery::SamMode::LauncherOnly) {
|
||||
if reach == 0 && !(own || on_network(sam)) {
|
||||
a.no_authority += 1;
|
||||
continue;
|
||||
}
|
||||
@@ -800,12 +807,12 @@ impl Sim {
|
||||
let own_fire = tr.own_authorizes(now);
|
||||
let gun_ready = spec.gun.is_some() && tr.own_within(now, sight::GUN_PICK_AGE);
|
||||
let authorized = if spec.missile.is_some() {
|
||||
own_fire || (sam.mode == battery::SamMode::LauncherOnly && cued) || far_ok
|
||||
own_fire || (on_network(sam) && cued) || far_ok
|
||||
} else {
|
||||
gun_ready
|
||||
};
|
||||
if !authorized {
|
||||
if sam.mode == battery::SamMode::LauncherOnly {
|
||||
if on_network(sam) {
|
||||
// The launcher's picture is the supporting radar's. If that radar has the
|
||||
// contact but every tracked-contact channel is taken, the reason is the
|
||||
// channels, not a missing hand-off.
|
||||
@@ -1294,7 +1301,11 @@ mod tests {
|
||||
fn setup(kind: SamKind) -> (Sim, Ground, Land<fn(i32, i32) -> i32>, Out) {
|
||||
let mut sim = Sim::new(5);
|
||||
let id = sim.id();
|
||||
sim.sams.push(Sam::new(id, kind, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
let mut sam = Sam::new(id, kind, DVec3::new(0.0, 70.0, 0.0), 0.0);
|
||||
// The weapon's own behaviour is tried on a system measuring for itself (the С-400 is
|
||||
// deployed as a separate launcher; its firing on the network's plot is `sensor_tests`').
|
||||
sam.mode = battery::SamMode::Integrated;
|
||||
sim.sams.push(sam);
|
||||
(sim, Ground::default(), Land(|_, _| 64), Out::default())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user