HD render fixes (#35-#39, #41) and replay time of day (#57) (fork patch 25); radar scan cycles with ageing tracks (#46), damage to individual system parts (#50), long-lasting fires (#52)
build / mod (push) Successful in 3m22s
build / mod (push) Successful in 3m22s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+97
-32
@@ -11,29 +11,32 @@ use super::*;
|
||||
pub(super) const DEAD: u8 = 1;
|
||||
pub(super) const ROLE: u8 = 2;
|
||||
pub(super) const UNSEEN: u8 = 4;
|
||||
/// Its track is older than a launcher fires on.
|
||||
pub(super) const STALE: u8 = 8;
|
||||
|
||||
pub(super) fn target_blocks(roles: u8, seen: &[u32], d: &Drone) -> u8 {
|
||||
pub(super) fn target_blocks(roles: u8, track: Option<&Track>, now: u64, d: &Drone) -> u8 {
|
||||
(if d.alive() { 0 } else { DEAD })
|
||||
| (if roles & d.kind.spec().class.bit() != 0 { 0 } else { ROLE })
|
||||
| (if seen.contains(&d.id) { 0 } else { UNSEEN })
|
||||
| (if track.is_some() { 0 } else { UNSEEN })
|
||||
| (if track.is_some_and(|t| t.age(now) > sight::MISSILE_AGE) { STALE } else { 0 })
|
||||
}
|
||||
|
||||
/// Alive, of a class the system engages, and on its picture (own radar or the network's).
|
||||
pub(super) fn allowed(roles: u8, seen: &[u32], d: &Drone) -> bool {
|
||||
target_blocks(roles, seen, d) == 0
|
||||
/// Alive, of a class the system engages, and on its picture (own radar or the network's), fresh enough.
|
||||
pub(super) fn allowed(roles: u8, track: &Track, now: u64, d: &Drone) -> bool {
|
||||
target_blocks(roles, Some(track), now, d) == 0
|
||||
}
|
||||
|
||||
pub(super) const TOO_CLOSE: u8 = 1;
|
||||
pub(super) const TOO_FAR: u8 = 2;
|
||||
|
||||
/// Missile range: `min` to `max * k` (a target already held may stray to 1.1 × max).
|
||||
pub(super) fn reach_blocks(min: f64, max: f64, k: f64, pos: DVec3, d: &Drone) -> u8 {
|
||||
let dist = d.pos.distance(pos);
|
||||
pub(super) fn reach_blocks(min: f64, max: f64, k: f64, pos: DVec3, at: DVec3) -> u8 {
|
||||
let dist = at.distance(pos);
|
||||
(if dist >= min { 0 } else { TOO_CLOSE }) | (if dist < max * k { 0 } else { TOO_FAR })
|
||||
}
|
||||
|
||||
pub(super) fn in_reach(min: f64, max: f64, k: f64, pos: DVec3, d: &Drone) -> bool {
|
||||
reach_blocks(min, max, k, pos, d) == 0
|
||||
pub(super) fn in_reach(min: f64, max: f64, k: f64, pos: DVec3, at: DVec3) -> bool {
|
||||
reach_blocks(min, max, k, pos, at) == 0
|
||||
}
|
||||
|
||||
/// Interceptors a target has or will have: in flight, and other systems' launchers on it.
|
||||
@@ -47,9 +50,10 @@ pub(super) fn needed(d: &Drone) -> u32 {
|
||||
if d.kind.spec().class == Class::Ballistic { 2 } else { 1 }
|
||||
}
|
||||
|
||||
/// A gun's candidates: held by the system's own radar and within the gun's tracking range.
|
||||
pub(super) fn gun_candidate(roles: u8, seen: &[u32], own: &[u32], track: f64, pos: DVec3, d: &Drone) -> bool {
|
||||
allowed(roles, seen, d) && own.contains(&d.id) && d.pos.distance(pos) < track
|
||||
/// A gun's candidates: measured by the system's own radar a moment ago and within the gun's tracking range
|
||||
/// (by the track's forecast, not the target's true place).
|
||||
pub(super) fn gun_candidate(roles: u8, track: &Track, now: u64, gun_track: f64, pos: DVec3, d: &Drone) -> bool {
|
||||
allowed(roles, track, now, d) && track.own_within(now, sight::GUN_PICK_AGE) && track.est(now).distance(pos) < gun_track
|
||||
}
|
||||
|
||||
/// How many systems have each drone as their missile target and as their gun target.
|
||||
@@ -66,8 +70,8 @@ pub(super) fn engagement_counts(sams: &[Sam]) -> (HashMap<u32, u32>, HashMap<u32
|
||||
// ---------------------------------------------------------------- aiming
|
||||
|
||||
/// Where the lead point is and the yaw and pitch that point the mount at it.
|
||||
pub(super) fn aim_wants(mount: DVec3, aim: &Drone, lead_speed: f64) -> (DVec3, f64, f64) {
|
||||
let lead = aim.pos + aim.vel * (aim.pos.distance(mount) / lead_speed);
|
||||
pub(super) fn aim_wants(mount: DVec3, at: DVec3, vel: DVec3, lead_speed: f64) -> (DVec3, f64, f64) {
|
||||
let lead = at + vel * (at.distance(mount) / lead_speed);
|
||||
let to = lead - mount;
|
||||
let want_yaw = heading_of(to);
|
||||
let want_pitch = (to.y / to.length().max(0.01)).asin().clamp(-0.1, 1.45);
|
||||
@@ -88,19 +92,22 @@ pub(super) fn aim_error(family: Family, yaw: f64, pitch: f64, want_yaw: f64, wan
|
||||
pub(super) const COOLDOWN: u8 = 1;
|
||||
pub(super) const RELOADING: u8 = 2;
|
||||
pub(super) const NO_ROUNDS: u8 = 4;
|
||||
/// The launcher has failed.
|
||||
pub(super) const LAUNCHER_DOWN: u8 = 8;
|
||||
|
||||
/// What keeps a loaded launcher from firing now (aim aside).
|
||||
pub(super) fn missile_blocks(s: &Sam) -> u8 {
|
||||
(if s.cooldown == 0 { 0 } else { COOLDOWN })
|
||||
(if s.part(Part::Launcher) > 0.0 { 0 } else { LAUNCHER_DOWN })
|
||||
| (if s.cooldown == 0 { 0 } else { COOLDOWN })
|
||||
| (if s.reloading == 0 { 0 } else { RELOADING })
|
||||
| (if s.missiles > 0 { 0 } else { NO_ROUNDS })
|
||||
}
|
||||
|
||||
/// The launcher points near enough: a trainable one only by its training, a turret by its
|
||||
/// whole aim at this target, the vertical ones need nothing.
|
||||
pub(super) fn missile_aligned(family: Family, yaw: f64, mount: DVec3, t: Option<&Drone>, aim_id: u32, mt: u32, aim_error: f64) -> bool {
|
||||
pub(super) fn missile_aligned(family: Family, yaw: f64, mount: DVec3, t: Option<DVec3>, aim_id: u32, mt: u32, aim_error: f64) -> bool {
|
||||
match family {
|
||||
Family::Trainable => t.is_some_and(|t| angle_diff(yaw, heading_of(t.pos - mount)).abs() < 0.15),
|
||||
Family::Trainable => t.is_some_and(|t| angle_diff(yaw, heading_of(t - mount)).abs() < 0.15),
|
||||
Family::Turret => aim_id == mt && aim_error < 0.15,
|
||||
_ => true,
|
||||
}
|
||||
@@ -109,11 +116,17 @@ pub(super) fn missile_aligned(family: Family, yaw: f64, mount: DVec3, t: Option<
|
||||
pub(super) const NOT_AIMED: u8 = 8;
|
||||
pub(super) const AIM_ERROR: u8 = 16;
|
||||
pub(super) const OUT_OF_RANGE: u8 = 32;
|
||||
/// The gun is jammed (for a while, or failed).
|
||||
pub(super) const JAMMED: u8 = 64;
|
||||
/// Its radar has no fresh measurement of the target.
|
||||
pub(super) const NO_LOCK: u8 = 128;
|
||||
|
||||
/// What keeps a gun from firing now: the turret on another target, not yet laid, out of range,
|
||||
/// and the gun's own cooldown, reload and shells (`COOLDOWN`, `RELOADING`, `NO_ROUNDS` bits).
|
||||
pub(super) fn gun_blocks(s: &Sam, aim_id: u32, gt: u32, aim_error: f64, dist: f64, range: f64) -> u8 {
|
||||
pub(super) fn gun_blocks(s: &Sam, aim_id: u32, gt: u32, aim_error: f64, dist: f64, range: f64, now: u64) -> u8 {
|
||||
(if aim_id == gt { 0 } else { NOT_AIMED })
|
||||
| (if s.gun_up() { 0 } else { JAMMED })
|
||||
| (if s.track(gt).is_some_and(|t| t.own_within(now, sight::GUN_AGE)) { 0 } else { NO_LOCK })
|
||||
| (if aim_error < 0.1 { 0 } else { AIM_ERROR })
|
||||
| (if dist < range { 0 } else { OUT_OF_RANGE })
|
||||
| (if s.gun_cooldown == 0 { 0 } else { COOLDOWN })
|
||||
@@ -160,9 +173,38 @@ impl Sim {
|
||||
let logistics = self.logistics();
|
||||
let (missile_on, guns_on) = engagement_counts(&self.sams);
|
||||
let alive = self.drones.iter().filter(|d| d.alive()).count();
|
||||
let now = self.tick;
|
||||
let seen = self.drones.iter().filter(|d| d.alive() && sam.seen.contains(&d.id)).count();
|
||||
let own = self.drones.iter().filter(|d| d.alive() && sam.own.contains(&d.id)).count();
|
||||
v.push(check(alive > 0, format!("в небе {alive}, на картине {seen} (своя РЛС {own}, остальные по сети)")));
|
||||
// The parts: what is worn or failed and what it costs.
|
||||
if !sam.comps.whole() {
|
||||
v.push(check(false, format!("узлы: {}", sam.parts_text())));
|
||||
}
|
||||
for p in Part::ALL {
|
||||
if !p.on(sam.kind) || sam.part_state(p) == PartState::Ok {
|
||||
continue;
|
||||
}
|
||||
let failed = sam.part_state(p) == PartState::Failed;
|
||||
let effect = match (p, failed) {
|
||||
(Part::Sensor, true) => "РЛС отказала: своих измерений нет, стволы не стреляют, ракеты — по данным сети".to_string(),
|
||||
(Part::Sensor, false) => format!("РЛС повреждена: дальность {:.0}%, обзор вдвое реже при худшем", sam.radar_fit() * 100.0),
|
||||
(Part::Mount, true) => format!("привод наведения заклинил: стоит на {:.0}°, не доворачивается", sam.yaw.to_degrees().rem_euclid(360.0)),
|
||||
(Part::Mount, false) => format!("привод наведения повреждён: поворот {:.0}% от нормы", sam.drive_fit() * 100.0),
|
||||
(Part::Launcher, true) => "пусковая отказала: пуски невозможны".to_string(),
|
||||
(Part::Launcher, false) => format!("пусковая повреждена: {} ячеек из {}, перезарядка {:.0} с", sam.cells(), spec.missile.as_ref().map_or(0, |m| m.magazine), sam.reload_time() as f64 / 20.0),
|
||||
(Part::Gun, true) => "орудие заклинило: не стреляет".to_string(),
|
||||
(Part::Gun, false) => format!("орудие повреждено: меткость {:.0}%, заклинивает", sam.gun_fit() * 100.0),
|
||||
(Part::Tracks, true) => "ходовая отказала: на марш не выйдет".to_string(),
|
||||
(Part::Tracks, false) => format!("ходовая повреждена: скорость марша {:.0}%", sam.drive_speed() * 100.0),
|
||||
(Part::Comms, true) => "связь отказала: сети нет, цели только свои".to_string(),
|
||||
(Part::Comms, false) => format!("связь повреждена: линия {:.0} м", sam.link_range()),
|
||||
};
|
||||
v.push(check(false, effect));
|
||||
}
|
||||
if sam.jam > 0 {
|
||||
v.push(check(false, format!("орудие заклинило, ещё {:.1} с", sam.jam as f64 / 20.0)));
|
||||
}
|
||||
let drone_at = |id: u32| self.drones.iter().find(|d| d.id == id);
|
||||
let subject = sam.target.or(sam.gun_target).and_then(drone_at).or_else(|| {
|
||||
self.drones
|
||||
@@ -175,24 +217,42 @@ impl Sim {
|
||||
return v;
|
||||
};
|
||||
let held = sam.target == Some(t.id) || sam.gun_target == Some(t.id);
|
||||
let dist = t.pos.distance(sam.pos);
|
||||
let dist = sam.track(t.id).map_or(t.pos, |tr| tr.est(self.tick)).distance(sam.pos);
|
||||
v.push(check(
|
||||
true,
|
||||
format!("цель: {} {}, {}", t.kind.spec().name, if held { "(сопровождается)" } else { "(самая опасная)" }, crate::panel::distance(dist)),
|
||||
));
|
||||
let blocks = target_blocks(sam.roles, &sam.seen, t);
|
||||
let track = sam.track(t.id);
|
||||
let blocks = target_blocks(sam.roles, track, now, t);
|
||||
// Where the system believes the target is: its track's forecast (the true place only when it has no track).
|
||||
let est = track.map_or(t.pos, |tr| tr.est(now));
|
||||
let evel = track.map_or(t.vel, |tr| tr.vel);
|
||||
v.push(check(
|
||||
blocks & ROLE == 0,
|
||||
format!("роль: {} {} [{}]", t.kind.spec().class.name(), if blocks & ROLE == 0 { "в ролях" } else { "не в ролях" }, roles_text(sam.roles)),
|
||||
));
|
||||
let detect = match (sam.own.contains(&t.id), sam.seen.contains(&t.id)) {
|
||||
(true, _) => "обнаружена своей РЛС",
|
||||
(false, true) => "видна только по сети (стволы не стреляют)",
|
||||
_ => "не обнаружена ни своей РЛС, ни сетью",
|
||||
let detect = match (track, sam.own.contains(&t.id)) {
|
||||
(Some(tr), own) => {
|
||||
let kind = if own { "своей РЛС" } else { "по сети (стволы не стреляют)" };
|
||||
let age = tr.age(now) as f64 / 20.0;
|
||||
let lock = if tr.own_within(now, sight::GUN_AGE) && tr.locked { ", захват" } else { "" };
|
||||
let how = if tr.forecast(now) { format!("прогноз ±{:.0} м", tr.uncertainty(now)) } else { "измерение".to_string() };
|
||||
format!("трек {kind}: {}, возраст {age:.1} с, {how}{lock}, {}", tr.ident().name(), if blocks & STALE != 0 { "устарел для пуска" } else { "годен для пуска" })
|
||||
}
|
||||
_ => "не обнаружена ни своей РЛС, ни сетью".to_string(),
|
||||
};
|
||||
v.push(check(blocks & UNSEEN == 0, detect));
|
||||
let fit = sam.fitness();
|
||||
v.push(check(fit >= 0.9, format!("состояние {:.0}%: поворот и точность {:.0}%", sam.health * 100.0, fit * 100.0)));
|
||||
v.push(check(blocks & (UNSEEN | STALE) == 0, detect));
|
||||
if sam.kind.spec().sensor > 0.0 {
|
||||
let period = sam.scan_ticks();
|
||||
v.push(check(
|
||||
sam.radar_up(),
|
||||
if sam.radar_up() {
|
||||
format!("обзор: оборот {:.1} с{}, луч на {:.0}°", period / 20.0, if sam.kind.scan().agile { ", электронный, цели в треке чаще" } else { "" }, sam.beam.to_degrees())
|
||||
} else {
|
||||
"обзор: РЛС не работает".to_string()
|
||||
},
|
||||
));
|
||||
}
|
||||
// Ammunition and its supply.
|
||||
let mut rounds = String::new();
|
||||
if let Some(load) = &spec.missile {
|
||||
@@ -211,12 +271,12 @@ impl Sim {
|
||||
v.push(check(sam.reloading == 0 && !sam.empty && (sam.missiles > 0 || sam.bursts > 0), format!("{rounds}— {supply}")));
|
||||
let mount = sam.mount().0;
|
||||
let lead_speed = spec.gun.as_ref().map_or(5.0, |g| g.shell);
|
||||
let (_, want_yaw, want_pitch) = aim_wants(mount, t, lead_speed);
|
||||
let (_, want_yaw, want_pitch) = aim_wants(mount, est, evel, lead_speed);
|
||||
let err = aim_error(spec.family, sam.yaw, sam.pitch, want_yaw, want_pitch);
|
||||
let vertical = spec.family == Family::Vertical;
|
||||
let mut fires = false;
|
||||
if let Some(load) = &spec.missile {
|
||||
let reach = reach_blocks(load.min, load.max, 1.0, sam.pos, t);
|
||||
let reach = reach_blocks(load.min, load.max, 1.0, sam.pos, est);
|
||||
v.push(check(
|
||||
reach == 0,
|
||||
format!(
|
||||
@@ -241,15 +301,18 @@ impl Sim {
|
||||
if mb & NO_ROUNDS != 0 {
|
||||
why.push("нет ракет".to_string());
|
||||
}
|
||||
if mb & LAUNCHER_DOWN != 0 {
|
||||
why.push("пусковая отказала".to_string());
|
||||
}
|
||||
v.push(check(mb == 0, if mb == 0 { "пусковая готова".to_string() } else { format!("пусковая не готова: {}", why.join(", ")) }));
|
||||
let aligned = missile_aligned(spec.family, sam.yaw, mount, Some(t), t.id, t.id, err);
|
||||
let aligned = missile_aligned(spec.family, sam.yaw, mount, Some(est), t.id, t.id, err);
|
||||
let turn = if vertical { "вертикальный старт" } else { "доворот" };
|
||||
v.push(check(aligned, format!("{turn}: ошибка наведения {:.0}°{}", err.to_degrees(), if aligned { "" } else { " — ещё доворачивается" })));
|
||||
fires |= reach == 0 && free < need && mb == 0 && aligned && blocks == 0;
|
||||
}
|
||||
if let Some(gun) = &spec.gun {
|
||||
let on_it = guns_on.get(&t.id).copied().unwrap_or(0) - u32::from(sam.gun_target == Some(t.id));
|
||||
let cand = gun_candidate(sam.roles, &sam.seen, &sam.own, gun.track, sam.pos, t);
|
||||
let cand = track.is_some_and(|tr| gun_candidate(sam.roles, tr, now, gun.track, sam.pos, t));
|
||||
v.push(check(
|
||||
cand,
|
||||
format!(
|
||||
@@ -259,7 +322,7 @@ impl Sim {
|
||||
if cand { "" } else { " — вне сопровождения (нужна своя РЛС)" }
|
||||
),
|
||||
));
|
||||
let gb = gun_blocks(sam, t.id, t.id, err, mount.distance(t.pos), gun.range);
|
||||
let gb = gun_blocks(sam, t.id, t.id, err, mount.distance(est), gun.range, now);
|
||||
let mut why = Vec::new();
|
||||
for (bit, name) in [
|
||||
(AIM_ERROR, format!("орудие ещё наводится ({:.0}°)", err.to_degrees())),
|
||||
@@ -267,6 +330,8 @@ impl Sim {
|
||||
(COOLDOWN, "пауза между очередями".to_string()),
|
||||
(RELOADING, "перезарядка".to_string()),
|
||||
(NO_ROUNDS, "нет снарядов".to_string()),
|
||||
(JAMMED, "орудие заклинило".to_string()),
|
||||
(NO_LOCK, "нет свежего захвата своей РЛС".to_string()),
|
||||
] {
|
||||
if gb & bit != 0 {
|
||||
why.push(name);
|
||||
|
||||
Reference in New Issue
Block a user