Separate search and engagement roles, support launcher-only SAMs, animate individual tube lids and delay ground strike spending until ejection. Preserve battery configuration and launch poses in saves and replay. Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
+54
-20
@@ -36,6 +36,8 @@ const NEAR: f64 = 24.0;
|
||||
pub(super) struct Horizon {
|
||||
/// Per ray, per sample out: the steepest rise of the land so far (tan of its elevation).
|
||||
pub(super) rays: Vec<Vec<f32>>,
|
||||
antenna: DVec3,
|
||||
reach: f64,
|
||||
}
|
||||
|
||||
impl Horizon {
|
||||
@@ -58,9 +60,12 @@ impl Horizon {
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
Self { rays }
|
||||
Self { rays, antenna, reach }
|
||||
}
|
||||
|
||||
fn matches(&self, sam: &Sam) -> bool {
|
||||
self.antenna == antenna(sam) && self.reach == sensor_span(sam)
|
||||
}
|
||||
/// Whether the land between the antenna and `p` rises over the line to it.
|
||||
pub(super) fn hides(&self, antenna: DVec3, p: DVec3) -> bool {
|
||||
let rel = p - antenna;
|
||||
@@ -78,7 +83,11 @@ impl Horizon {
|
||||
|
||||
/// Where a unit's radar antenna is.
|
||||
pub(super) fn antenna(sam: &Sam) -> DVec3 {
|
||||
sam.pos + DVec3::Y * sam.kind.spec().mast
|
||||
sam.pos + DVec3::Y * sam.sensor_mast()
|
||||
}
|
||||
|
||||
fn sensor_span(sam: &Sam) -> f64 {
|
||||
sam.kind.spec().sensor * if sam.kind == SamKind::Radar { sam.radar_role.reach_factor() } else { 1.0 }
|
||||
}
|
||||
|
||||
/// How far a system's search radar reaches for this kind at `height` over the land:
|
||||
@@ -88,8 +97,8 @@ pub(super) fn reach(sam: &Sam, kind: DroneKind, height: f64) -> f64 {
|
||||
if spec.sensor <= 0.0 {
|
||||
return 0.0;
|
||||
}
|
||||
let radar = spec.sensor * sam.radar_fit() * kind.rcs().powf(0.25);
|
||||
let horizon = HORIZON * (spec.mast.sqrt() + height.max(0.0).sqrt());
|
||||
let radar = spec.sensor * sam.radar_fit() * if sam.kind == SamKind::Radar { sam.radar_role.reach_factor() } else { 1.0 } * kind.rcs().powf(0.25);
|
||||
let horizon = HORIZON * (sam.sensor_mast().sqrt() + height.max(0.0).sqrt());
|
||||
radar.min(horizon).max(NEAR)
|
||||
}
|
||||
|
||||
@@ -127,15 +136,17 @@ impl Sim {
|
||||
/// A radar for a unit of `kind` at `pos` as the map draws it; `id`: the unit it is (its parts and horizon), None for a ghost.
|
||||
pub fn low_sensor(&self, kind: SamKind, pos: DVec3, id: Option<u32>) -> Option<LowSensor> {
|
||||
let spec = kind.spec();
|
||||
if spec.sensor <= 0.0 {
|
||||
if spec.sensor <= 0.0 || id.and_then(|i| self.sams.iter().find(|s| s.id == i)).is_some_and(|s| s.mode == battery::SamMode::LauncherOnly) {
|
||||
return None;
|
||||
}
|
||||
let fit = id.and_then(|i| self.sams.iter().find(|s| s.id == i)).map_or(1.0, |s| s.radar_fit());
|
||||
let height = LOW_KIND.spec().clearance;
|
||||
let radar = spec.sensor * fit * LOW_KIND.rcs().powf(0.25);
|
||||
let reach = radar.min(HORIZON * (spec.mast.sqrt() + height.sqrt())).max(NEAR);
|
||||
let terrain = id.is_some_and(|i| self.horizons.contains_key(&i));
|
||||
Some(LowSensor { id: id.unwrap_or(u32::MAX), ant: pos + DVec3::Y * spec.mast, base: pos.y, reach, terrain })
|
||||
let mast = id.and_then(|i| self.sams.iter().find(|s| s.id == i)).map_or(spec.mast, |s| s.sensor_mast());
|
||||
let factor = id.and_then(|i| self.sams.iter().find(|s| s.id == i)).filter(|s| s.kind == SamKind::Radar).map_or(1.0, |s| s.radar_role.reach_factor());
|
||||
let radar = spec.sensor * fit * factor * LOW_KIND.rcs().powf(0.25);
|
||||
let reach = radar.min(HORIZON * (mast.sqrt() + height.sqrt())).max(NEAR);
|
||||
let terrain = id.and_then(|i| self.sams.iter().find(|s| s.id == i)).is_some_and(|s| self.horizons.get(&s.id).is_some_and(|h| h.matches(s)));
|
||||
Some(LowSensor { id: id.unwrap_or(u32::MAX), ant: pos + DVec3::Y * mast, base: pos.y, reach, terrain })
|
||||
}
|
||||
|
||||
/// The radars that are up now.
|
||||
@@ -297,13 +308,26 @@ impl Track {
|
||||
}
|
||||
|
||||
impl Sam {
|
||||
/// Fictional antenna height and scan characteristics for gameplay roles.
|
||||
pub(super) fn sensor_mast(&self) -> f64 {
|
||||
self.kind.spec().mast + if self.kind == SamKind::Radar && self.radar_role == battery::RadarRole::Height { 8.0 } else { 0.0 }
|
||||
}
|
||||
pub(super) fn scan_profile(&self) -> Scan {
|
||||
if self.kind != SamKind::Radar { return self.kind.scan(); }
|
||||
match self.radar_role {
|
||||
battery::RadarRole::Multifunction => self.kind.scan(),
|
||||
battery::RadarRole::Search => Scan { period: 170, agile: false },
|
||||
battery::RadarRole::Engagement => Scan { period: 70, agile: true },
|
||||
battery::RadarRole::Height => Scan { period: 140, agile: false },
|
||||
}
|
||||
}
|
||||
/// Ticks for its beam to go round (longer when the radar is damaged).
|
||||
pub(super) fn scan_ticks(&self) -> f64 {
|
||||
self.kind.scan().period as f64 / self.radar_fit().max(0.2)
|
||||
self.scan_profile().period as f64 / self.radar_fit().max(0.2)
|
||||
}
|
||||
/// Its own radar works: it has one, it is not failed and the unit is deployed.
|
||||
pub fn radar_up(&self) -> bool {
|
||||
self.alive() && !self.moving() && self.kind.spec().sensor > 0.0 && self.part(Part::Sensor) > 0.0
|
||||
self.mode != battery::SamMode::LauncherOnly && self.alive() && !self.moving() && self.kind.spec().sensor > 0.0 && self.part(Part::Sensor) > 0.0
|
||||
}
|
||||
pub fn track(&self, id: u32) -> Option<&Track> {
|
||||
self.tracks.iter().find(|t| t.id == id)
|
||||
@@ -339,18 +363,24 @@ impl Sim {
|
||||
/// into the tracks, old tracks out, and the network's tracks shared.
|
||||
pub(super) fn update_sight(&mut self, ground: &mut Ground) {
|
||||
let now = self.tick;
|
||||
// A role, mast or location change invalidates the cached terrain immediately.
|
||||
for sam in &self.sams {
|
||||
if sam.radar_up() && self.horizons.get(&sam.id).is_some_and(|h| !h.matches(sam)) {
|
||||
self.horizons.insert(sam.id, Horizon::build(antenna(sam), sensor_span(sam), ground, now));
|
||||
}
|
||||
}
|
||||
// One horizon every few ticks: the land answers come in over time.
|
||||
if !self.sams.is_empty() && now % 3 == 0 {
|
||||
let radars: Vec<usize> =
|
||||
(0..self.sams.len()).filter(|&i| self.sams[i].alive() && self.sams[i].kind.spec().sensor > 0.0).collect();
|
||||
(0..self.sams.len()).filter(|&i| self.sams[i].radar_up()).collect();
|
||||
if !radars.is_empty() {
|
||||
let i = radars[(now / 3) as usize % radars.len()];
|
||||
let sam = &self.sams[i];
|
||||
let h = Horizon::build(antenna(sam), sam.kind.spec().sensor, ground, now);
|
||||
let h = Horizon::build(antenna(sam), sensor_span(sam), ground, now);
|
||||
self.horizons.insert(sam.id, h);
|
||||
}
|
||||
}
|
||||
let alive: std::collections::HashSet<u32> = self.sams.iter().filter(|s| s.alive()).map(|s| s.id).collect();
|
||||
let alive: std::collections::HashSet<u32> = self.sams.iter().filter(|s| s.radar_up()).map(|s| s.id).collect();
|
||||
self.horizons.retain(|id, _| alive.contains(id));
|
||||
// Each drone's height over the land under it (or over the systems' ground, unknown).
|
||||
let heights: Vec<Option<f64>> =
|
||||
@@ -371,7 +401,7 @@ impl Sim {
|
||||
index.clear();
|
||||
index.extend(sam.tracks.iter().enumerate().map(|(k, t)| (t.id, k)));
|
||||
let spec = sam.kind.spec();
|
||||
let scan = sam.kind.scan();
|
||||
let scan = sam.scan_profile();
|
||||
let period = sam.scan_ticks();
|
||||
let w = TAU / period;
|
||||
let (b0, ttl) = (sam.beam, ((period * 3.0) as u32).max(60));
|
||||
@@ -385,7 +415,7 @@ impl Sim {
|
||||
}
|
||||
let rel = d.pos - at;
|
||||
let dist = rel.length();
|
||||
if dist > spec.sensor * 1.2 {
|
||||
if dist > spec.sensor * if sam.kind == SamKind::Radar { sam.radar_role.reach_factor().max(1.0) * 1.2 } else { 1.2 } {
|
||||
continue;
|
||||
}
|
||||
let locked = sam.target == Some(d.id) || sam.gun_target == Some(d.id);
|
||||
@@ -393,7 +423,11 @@ impl Sim {
|
||||
// The beam passes its bearing this tick (the angle wraps at 2π: the difference is taken round).
|
||||
let in_beam = swept(rel.x.atan2(-rel.z), b0, w);
|
||||
let revisit = scan.agile && held.is_some_and(|t| t.own_tick > 0 && now - t.own_tick >= (period / 3.0) as u64);
|
||||
if !(in_beam || locked || revisit) {
|
||||
// A search radar's network track cues this fictional tracking radar to look, but is
|
||||
// never itself a measurement: reach, terrain, probability and noise still apply.
|
||||
let cue = sam.kind == SamKind::Radar && sam.radar_role == battery::RadarRole::Engagement
|
||||
&& held.is_some_and(|t| t.own_tick == 0 && t.age(now) <= MISSILE_AGE);
|
||||
if !(in_beam || locked || revisit || cue) {
|
||||
continue;
|
||||
}
|
||||
let height = h.unwrap_or(d.pos.y - sam.pos.y);
|
||||
@@ -412,7 +446,7 @@ impl Sim {
|
||||
if dist > NEAR && dice(seed, now, key, 0) >= p {
|
||||
continue;
|
||||
}
|
||||
let sigma = if locked { 0.3 } else { 0.8 + dist * 0.004 };
|
||||
let sigma = if locked { 0.3 } else if sam.kind == SamKind::Radar && sam.radar_role == battery::RadarRole::Engagement { 0.45 + dist * 0.002 } else { 0.8 + dist * 0.004 };
|
||||
let noise = DVec3::new(dice(seed, now, key, 1) - 0.5, (dice(seed, now, key, 2) - 0.5) * 0.5, dice(seed, now, key, 3) - 0.5) * 2.0 * sigma;
|
||||
fresh.push(Track {
|
||||
id: d.id,
|
||||
@@ -435,12 +469,12 @@ impl Sim {
|
||||
let shared: Vec<(u32, DVec3, f64, Vec<Track>)> = self
|
||||
.sams
|
||||
.iter()
|
||||
.filter(|s| s.alive() && !s.moving() && s.link_range() > 0.0)
|
||||
.filter(|s| s.radar_up() && s.link_range() > 0.0)
|
||||
.map(|s| (s.id, s.pos, s.link_range(), s.tracks.iter().filter(|t| t.own_tick == t.tick).copied().collect::<Vec<_>>()))
|
||||
.filter(|s| !s.3.is_empty())
|
||||
.collect();
|
||||
for sam in &mut self.sams {
|
||||
if sam.alive() && !sam.moving() && sam.kind.armed() && sam.link_range() > 0.0 && !shared.is_empty() {
|
||||
if sam.alive() && !sam.moving() && (sam.kind.armed() || (sam.kind == SamKind::Radar && sam.radar_role == battery::RadarRole::Engagement)) && sam.link_range() > 0.0 && !shared.is_empty() {
|
||||
index.clear();
|
||||
index.extend(sam.tracks.iter().enumerate().map(|(k, t)| (t.id, k)));
|
||||
let mine = sam.link_range();
|
||||
|
||||
Reference in New Issue
Block a user