Observe emitting radars and expose emission control
Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
+22
-18
@@ -588,10 +588,14 @@ impl Sim {
|
||||
// themselves away; the rest of the player's layout is not in its hands.
|
||||
let known = self.known_units();
|
||||
let alive: Vec<&Sam> = alive.iter().copied().filter(|s| Self::enemy_knows(s, &known)).collect();
|
||||
let pick_known = |list: &[&Sam], r: f64| -> Option<(DVec3, u32)> {
|
||||
let s = *list.get((r * list.len() as f64) as usize)?;
|
||||
known.iter().find(|(id, _)| *id == s.id).map(|(_, pos)| (*pos, s.id))
|
||||
};
|
||||
let known_ew: Vec<&Sam> = alive.iter().copied().filter(|s| s.kind == SamKind::Ew).collect();
|
||||
if matches!(kind, DroneKind::Lancet | DroneKind::Kh22) && !known_ew.is_empty() && roll < 0.6 {
|
||||
let s = known_ew[(r * known_ew.len() as f64) as usize % known_ew.len()];
|
||||
return (s.pos, Some(s.id));
|
||||
return (known.iter().find(|(id, _)| *id == s.id).unwrap().1, Some(s.id));
|
||||
}
|
||||
// Short-range systems (guns, Tor, P1-SUN) for the Lancets; long-range ones and the radars
|
||||
// that feed them for the fast missiles.
|
||||
@@ -599,10 +603,10 @@ impl Sim {
|
||||
let long: Vec<&Sam> =
|
||||
alive.iter().copied().filter(|s| s.kind.range() >= 450.0 || s.kind == SamKind::Radar).collect();
|
||||
let choice = match kind {
|
||||
DroneKind::Lancet if roll < 0.75 => pick(&guns, r).or_else(|| pick(&alive, r)),
|
||||
DroneKind::Kh22 | DroneKind::Zircon if roll < 0.45 => pick(&long, r),
|
||||
DroneKind::Iskander | DroneKind::Kinzhal if roll < 0.3 => pick(&long, r),
|
||||
DroneKind::Shahed | DroneKind::Geran3 if roll < 0.2 => pick(&alive, r),
|
||||
DroneKind::Lancet if roll < 0.75 => pick_known(&guns, r).or_else(|| pick_known(&alive, r)),
|
||||
DroneKind::Kh22 | DroneKind::Zircon if roll < 0.45 => pick_known(&long, r),
|
||||
DroneKind::Iskander | DroneKind::Kinzhal if roll < 0.3 => pick_known(&long, r),
|
||||
DroneKind::Shahed | DroneKind::Geran3 if roll < 0.2 => pick_known(&alive, r),
|
||||
_ => None,
|
||||
};
|
||||
choice.map_or((object, None), |(p, id)| (p, Some(id)))
|
||||
@@ -627,11 +631,12 @@ impl Sim {
|
||||
if kind.jammable() {
|
||||
let known = self.known_units();
|
||||
for s in self.sams.iter().filter(|s| s.kind == SamKind::Ew && s.alive() && known.iter().any(|k| k.0 == s.id)) {
|
||||
let (ci, cj) = grid.index(s.pos);
|
||||
let pos = known.iter().find(|(id, _)| *id == s.id).unwrap().1;
|
||||
let (ci, cj) = grid.index(pos);
|
||||
let r = (EW_RADIUS / grid.cell).ceil() as i32;
|
||||
for i in (ci - r).max(0)..=(ci + r).min(n - 1) {
|
||||
for j in (cj - r).max(0)..=(cj + r).min(n - 1) {
|
||||
if horizontal(grid.centre((i, j), s.pos.y) - s.pos).length() < EW_RADIUS {
|
||||
if horizontal(grid.centre((i, j), pos.y) - pos).length() < EW_RADIUS {
|
||||
prices[(i * n + j) as usize] += 12.0;
|
||||
}
|
||||
}
|
||||
@@ -640,30 +645,29 @@ impl Sim {
|
||||
}
|
||||
// Only the systems the enemy knows of are priced in (#93): a hidden one is flown into.
|
||||
for s in self.sams.iter().filter(|s| s.alive() && s.roles & spec.class.bit() != 0 && Self::enemy_knows(s, &known_now)) {
|
||||
let pos = known_now.iter().find(|(id, _)| *id == s.id).unwrap().1;
|
||||
let sp = s.kind.spec();
|
||||
let (lo, hi) = sp.missile.as_ref().map_or((0.0, 0.0), |m| (m.min, m.max));
|
||||
let gun = sp.gun.as_ref().map_or(0.0, |g| g.range);
|
||||
// A gun needs its own radar; a missile also flies on the tracks of any radar within data-link range.
|
||||
let own = sight::reach(s, kind, height);
|
||||
let net = self
|
||||
.sams
|
||||
.iter()
|
||||
.filter(|r| r.alive() && r.id != s.id && r.pos.distance(s.pos) <= sight::LINK)
|
||||
.map(|r| sight::reach(r, kind, height))
|
||||
.fold(0.0, f64::max);
|
||||
let net = self.sams.iter().filter_map(|r| {
|
||||
let at = known_now.iter().find(|(id, _)| *id == r.id)?.1;
|
||||
(r.id != s.id && at.distance(pos) <= sight::LINK).then(|| sight::reach(r, kind, height))
|
||||
}).fold(0.0, f64::max);
|
||||
let (hi, gun) = (hi.min(own.max(net)), gun.min(own));
|
||||
let far = hi.max(gun);
|
||||
let at = sight::antenna(s);
|
||||
let horizon = self.horizons.get(&s.id);
|
||||
let at = pos + (sight::antenna(s) - s.pos);
|
||||
let horizon = (pos == s.pos).then(|| self.horizons.get(&s.id)).flatten();
|
||||
// Only the cells round it.
|
||||
let (ci, cj) = grid.index(s.pos);
|
||||
let (ci, cj) = grid.index(pos);
|
||||
let r = (far / grid.cell).ceil() as i32 + 1;
|
||||
for i in (ci - r).max(0)..=(ci + r).min(n - 1) {
|
||||
for j in (cj - r).max(0)..=(cj + r).min(n - 1) {
|
||||
cost += 1;
|
||||
let ground = land.map(|l| l[(i * n + j) as usize]).filter(|g| g.is_finite());
|
||||
let p = grid.centre((i, j), ground.map_or(s.pos.y + height, |g| f64::from(g) + height));
|
||||
let d = horizontal(p - s.pos).length();
|
||||
let p = grid.centre((i, j), ground.map_or(pos.y + height, |g| f64::from(g) + height));
|
||||
let d = horizontal(p - pos).length();
|
||||
if d > far {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user