Playtest fixes: smoke by engine, searchlights, far launch sites that load their chunks, air defence balance, last chance and radar-cued shots, radars in smart raids, echo, Windows release build from a tag
build / mod (push) Successful in 4m4s
release / windows (push) Successful in 23m13s

Smoke: one rule by engine, no heat on trails, no trail on P1-SUN. Searchlights: two lamps a target, off with an empty sky. Halos fade before their reach and their sum is limited. Launch sites load chunks through the server thread, go off-map as a last resort, and reach 4000 blocks. Air defence: ranges x1.5, shots grow with urgency, claims released, /airdef lastchance, long shots on a big radar's tracks. Build: rust-toolchain.toml, airdef.py check, generator manifest and --check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 23:44:14 +03:00
parent 5003376e70
commit ccc3e20902
67 changed files with 4573 additions and 328 deletions
+322 -19
View File
@@ -45,9 +45,115 @@ pub(super) fn claimed(d: &Drone, missile_on: &HashMap<u32, u32>, had_target: Opt
d.engaged + on
}
/// Ballistic missiles get a pair; anything else one.
/// Ticks until the target reaches its aim at its present speed.
pub(super) fn arrival(d: &Drone) -> f64 {
d.pos.distance(d.target) / d.vel.length().max(0.1)
}
/// Shoot-look-shoot that grows with urgency: ballistic missiles get a pair, anything else one; a target
/// this close to its aim (ticks) has one more interceptor allowed on it at once, closer still another, and in the last seconds a fourth.
pub(super) const URGENT: f64 = 240.0;
pub(super) const DESPERATE: f64 = 110.0;
pub(super) const FINAL: f64 = 60.0;
pub(super) fn needed(d: &Drone) -> u32 {
if d.kind.spec().class == Class::Ballistic { 2 } else { 1 }
let base = if d.kind.spec().class == Class::Ballistic { 2 } else { 1 };
let t = arrival(d);
base + u32::from(t < URGENT) + u32::from(t < DESPERATE) + u32::from(t < FINAL)
}
/// Ticks a launcher may hold a target without launching before it lets go, and how long it then keeps away from it.
pub(super) const HOLD_MAX: u32 = 24;
pub(super) const SHY_TICKS: u64 = 120;
// ---------------------------------------------------------------- the grounds to launch on
/// Last chance (`/airdef lastchance`): a target of a class the system does not engage that is about to
/// hit, with nobody's interceptor on it, is shot at anyway; a system told to hold fire (no roles) keeps to it.
pub(super) const LAST_CHANCE_TICKS: f64 = 200.0;
pub(super) fn last_chance(on: bool, roles: u8, d: &Drone, claimed: u32) -> bool {
on && roles != 0 && roles & d.kind.spec().class.bit() == 0 && claimed == 0 && arrival(d) < LAST_CHANCE_TICKS
}
/// The big radar's cue (heavy systems only): they may fire out to `FAR_K` × max at a target the radar holds.
pub(super) const FAR_K: f64 = 1.6;
/// Ticks between one system's long shots; the share of the magazine it keeps for them; the radar track's age.
pub(super) const FAR_COOLDOWN: u32 = 300;
pub(super) const FAR_RADAR_AGE: u64 = 150;
impl SamKind {
/// Whether the kind takes long shots on a big radar's data.
pub(super) fn far_shooter(self) -> bool {
matches!(self, SamKind::S400 | SamKind::S500 | SamKind::Patriot)
}
}
/// A live big radar in data-link reach of `sam` that measured `id` recently.
pub(super) fn radar_cue(sam: &Sam, radars: &[&Sam], id: u32, now: u64) -> bool {
radars.iter().any(|r| {
r.alive()
&& !r.moving()
&& r.radar_up()
&& r.pos.distance(sam.pos) <= r.link_range().min(sam.link_range())
&& r.track(id).is_some_and(|t| t.own_tick > 0 && t.age(now) <= FAR_RADAR_AGE)
})
}
/// The ground beyond `max`: a long shot is allowed (the system, its launcher and magazine, the flag, a cue).
pub(super) fn far_blocks(on: bool, sam: &Sam, load: &units::MissileLoad, cued: bool, in_reach_of_any: bool) -> u8 {
(if on && sam.kind.far_shooter() { 0 } else { FAR_OFF })
| (if cued { 0 } else { FAR_NO_CUE })
| (if sam.far_cooldown == 0 { 0 } else { FAR_WAIT })
| (if sam.missiles * 2 >= load.magazine { 0 } else { FAR_LOW })
| (if in_reach_of_any { FAR_BUSY } else { 0 })
}
pub(super) const FAR_OFF: u8 = 1;
pub(super) const FAR_NO_CUE: u8 = 2;
pub(super) const FAR_WAIT: u8 = 4;
pub(super) const FAR_LOW: u8 = 8;
pub(super) const FAR_BUSY: u8 = 16;
/// Why a system may launch at a target: its role, the last chance, or a long shot on the radar's cue.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(super) enum Basis {
Role,
LastChance,
FarShot,
}
/// What is switched on beyond the roles (the sim's settings).
#[derive(Clone, Copy)]
pub(super) struct Opts {
pub last_chance: bool,
pub far_shots: bool,
}
/// 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).
#[allow(clippy::too_many_arguments)]
pub(super) fn basis(sam: &Sam, load: &units::MissileLoad, track: &Track, d: &Drone, now: u64, claimed: u32, k: f64, opts: Opts, cued: bool, role_in_reach: bool) -> Option<Basis> {
let blocks = target_blocks(sam.roles, Some(track), now, d);
if blocks & !ROLE != 0 {
return None;
}
let est = track.est(now);
let reach = reach_blocks(load.min, load.max, k, sam.pos, est);
if blocks & ROLE == 0 {
if reach == 0 {
return Some(Basis::Role);
}
let far = reach == TOO_FAR && reach_blocks(load.min, load.max, FAR_K, sam.pos, est) == 0;
return (far && far_blocks(opts.far_shots, sam, load, cued, role_in_reach) == 0).then_some(Basis::FarShot);
}
(reach == 0 && last_chance(opts.last_chance, sam.roles, d, claimed)).then_some(Basis::LastChance)
}
/// The kill chance of an interceptor that met its target `dist` from the launcher whose reach is `max`:
/// whole up to `max`, falling linearly to half at `FAR_K` × max.
pub(super) fn reach_fit(max: f64, dist: f64) -> f64 {
1.0 - 0.5 * ((dist - max) / (max * (FAR_K - 1.0))).clamp(0.0, 1.0)
}
/// A gun's candidates: measured by the system's own radar a moment ago and within the gun's tracking range
@@ -209,7 +315,7 @@ impl Sim {
let subject = sam.target.or(sam.gun_target).and_then(drone_at).or_else(|| {
self.drones
.iter()
.filter(|d| d.alive() && sam.roles & d.kind.spec().class.bit() != 0)
.filter(|d| d.alive() && (sam.roles & d.kind.spec().class.bit() != 0 || last_chance(self.last_chance, sam.roles, d, claimed(d, &missile_on, sam.target))))
.max_by(|a, b| a.threat(sam.pos).total_cmp(&b.threat(sam.pos)))
});
let Some(t) = subject else {
@@ -227,10 +333,21 @@ impl Sim {
// 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 first_claim = claimed(t, &missile_on, sam.target);
let chance = blocks & ROLE != 0 && last_chance(self.last_chance, sam.roles, t, first_claim);
let role_text = if blocks & ROLE == 0 {
format!("роль: {} в ролях [{}]", t.kind.spec().class.name(), roles_text(sam.roles))
} else if chance {
format!(
"последний шанс: {} не в ролях [{}], но до цели {:.0} с, перехватчиков на ней нет",
t.kind.spec().class.name(),
roles_text(sam.roles),
arrival(t) / 20.0
)
} else {
format!("роль: {} не в ролях [{}]", t.kind.spec().class.name(), roles_text(sam.roles))
};
v.push(check(blocks & ROLE == 0 || chance, role_text));
let detect = match (track, sam.own.contains(&t.id)) {
(Some(tr), own) => {
let kind = if own { "своей РЛС" } else { "по сети (стволы не стреляют)" };
@@ -277,17 +394,31 @@ impl Sim {
let mut fires = false;
if let Some(load) = &spec.missile {
let reach = reach_blocks(load.min, load.max, 1.0, sam.pos, est);
v.push(check(
reach == 0,
format!(
"ракеты: дальность {}–{}, цель на {}{}",
crate::panel::distance(load.min),
crate::panel::distance(load.max),
crate::panel::distance(dist),
if reach & TOO_CLOSE != 0 { " — слишком близко" } else if reach & TOO_FAR != 0 { " — слишком далеко" } else { "" }
),
));
let free = claimed(t, &missile_on, sam.target);
// Beyond the normal reach, a heavy system may fire on a big radar's cue.
let radars: Vec<&Sam> = self.sams.iter().filter(|s| s.kind == SamKind::Radar).collect();
let cued = sam.kind.far_shooter() && radar_cue(sam, &radars, t.id, now);
let role_in_reach = self.drones.iter().any(|o| {
sam.track(o.id).is_some_and(|tr| allowed(sam.roles, tr, now, o) && in_reach(load.min, load.max, 1.0, sam.pos, tr.est(now)) && claimed(o, &missile_on, sam.target) < needed(o))
});
let far = reach == TOO_FAR && reach_blocks(load.min, load.max, FAR_K, sam.pos, est) == 0;
let far_ok = far && track.is_some_and(|tr| basis(sam, load, tr, t, now, 0, 1.0, Opts { last_chance: self.last_chance, far_shots: self.far_shots }, cued, role_in_reach) == Some(Basis::FarShot));
if far {
let fb = far_blocks(self.far_shots, sam, load, cued, role_in_reach);
let mut no = Vec::new();
for (bit, name) in [
(FAR_OFF, "не для этого комплекса"),
(FAR_NO_CUE, "нет свежего трека большой РЛС"),
(FAR_WAIT, "дальний пуск уже был недавно"),
(FAR_LOW, "меньше половины боезапаса"),
(FAR_BUSY, "есть цель в обычной дальности"),
] {
if fb & bit != 0 {
no.push(name);
}
}
v.push(check(far_ok, if far_ok { format!("дальний пуск по РЛС: цель на {} дальше обычных {}", crate::panel::distance(dist), crate::panel::distance(load.max)) } else { format!("дальний пуск по РЛС не разрешён: {}", no.join(", ")) }));
}
let free = first_claim;
let need = needed(t);
v.push(check(free < need, format!("цель занята перехватчиками: {free} из {need}{}", if free < need { "" } else { " — другие уже на ней" })));
let mb = missile_blocks(sam);
@@ -320,7 +451,8 @@ impl Sim {
},
));
}
fires |= reach == 0 && free < need && mb == 0 && aligned && blocks == 0 && land == 0;
let grounds = blocks & !ROLE == 0 && (blocks & ROLE == 0 || chance) && (reach == 0 || far_ok);
fires |= grounds && free < need && mb == 0 && aligned && land == 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));
@@ -379,4 +511,175 @@ mod tests {
sim.sams[0].roles = 0xFF;
assert!(sim.why(0).iter().any(|c| c.text.starts_with("роль")));
}
use super::sites::testland::{Land, serve};
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));
(sim, Ground::default(), Land(|_, _| 64), Out::default())
}
/// Steps `ticks` or until something is fired; returns the drone's ticks to its aim at the first launch.
fn until_fired(sim: &mut Sim, ground: &mut Ground, land: &Land<fn(i32, i32) -> i32>, out: &mut Out, ticks: u32) -> Option<f64> {
for _ in 0..ticks {
serve(ground, land, sim.tick);
sim.step(ground, None, out);
if sim.sams[0].fired > 0 {
return sim.drones.first().map(arrival);
}
}
None
}
/// A Shahed `blocks` short of its aim, which is `80` out from the system, coming in along z.
fn shahed_at(sim: &mut Sim, blocks: f64) {
sim.add_drone(DroneKind::Shahed, DVec3::new(0.0, 75.0, -80.0 - blocks), DVec3::Z, DVec3::new(0.0, 70.0, -80.0));
}
#[test]
fn last_chance_fires_at_a_class_out_of_roles_only_when_it_is_about_to_hit() {
// The S-400 does not engage drones by default.
assert_eq!(SamKind::S400.spec().roles & Class::Drone.bit(), 0);
let (mut sim, mut ground, land, mut out) = setup(SamKind::S400);
shahed_at(&mut sim, 60.0);
let at = until_fired(&mut sim, &mut ground, &land, &mut out, 140).expect("the S-400 never fired on a Shahed about to hit");
assert!(at < LAST_CHANCE_TICKS, "fired with {at:.0} ticks to go");
// The diagnostic names why: the last chance.
let (mut sim, mut ground, land, mut out) = setup(SamKind::S400);
shahed_at(&mut sim, 100.0);
for _ in 0..30 {
serve(&mut ground, &land, sim.tick);
sim.step(&mut ground, None, &mut out);
}
let w = sim.why(0);
assert!(w.iter().any(|c| c.ok && c.text.starts_with("последний шанс")), "{:?}", w.iter().map(|c| &c.text).collect::<Vec<_>>());
}
#[test]
fn last_chance_waits_for_a_target_far_from_its_aim() {
let (mut sim, mut ground, land, mut out) = setup(SamKind::S400);
// In plain view 120 blocks off, but flying away from its aim, 480 blocks (800 ticks) ahead.
sim.add_drone(DroneKind::Shahed, DVec3::new(0.0, 75.0, -120.0), DVec3::NEG_Z, DVec3::new(0.0, 70.0, -600.0));
assert!(until_fired(&mut sim, &mut ground, &land, &mut out, 150).is_none(), "fired at a Shahed far from its aim");
let w = sim.why(0);
// Still named as the role block it was: no target of its classes.
assert!(w.last().is_some_and(|c| !c.ok) && w.iter().any(|c| c.text.contains("нет целей классов")), "{:?}", w.iter().map(|c| &c.text).collect::<Vec<_>>());
assert!(!w.iter().any(|c| c.text.starts_with("последний шанс")));
}
#[test]
fn last_chance_is_off_when_switched_off_and_with_no_roles() {
for (off, roles) in [(true, 30u8), (false, 0u8)] {
let (mut sim, mut ground, land, mut out) = setup(SamKind::S400);
sim.last_chance = !off;
sim.sams[0].roles = roles;
shahed_at(&mut sim, 60.0);
assert!(until_fired(&mut sim, &mut ground, &land, &mut out, 140).is_none(), "fired with last chance off={off}, roles {roles}");
}
}
#[test]
fn last_chance_leaves_a_target_that_already_has_an_interceptor_on_it() {
let (mut sim, mut ground, land, mut out) = setup(SamKind::S400);
shahed_at(&mut sim, 60.0);
// Another system's interceptor is on it.
let id = sim.drones[0].id;
sim.drones[0].engaged = 1;
assert!(until_fired(&mut sim, &mut ground, &land, &mut out, 40).is_none(), "fired at {id} that is claimed");
}
/// A Kh101 `dist` from the origin on the far side, at height, coming in along z; a radar beside the system.
fn far_setup(radar: bool, dist: f64) -> (Sim, Ground, Land<fn(i32, i32) -> i32>, Out) {
let (mut sim, ground, land, out) = setup(SamKind::S400);
if radar {
let id = sim.id();
sim.sams.push(Sam::new(id, SamKind::Radar, DVec3::new(40.0, 70.0, 0.0), 0.0));
}
sim.add_drone(DroneKind::Kh101, DVec3::new(0.0, 300.0, -dist), DVec3::Z, DVec3::new(0.0, 70.0, 0.0));
(sim, ground, land, out)
}
/// The radar's measurement of every live drone, fresh this tick (as if its beam had just passed).
fn radar_sees(sim: &mut Sim) {
let now = sim.tick;
let tracks: Vec<Track> = sim
.drones
.iter()
.filter(|d| d.alive())
.map(|d| Track { id: d.id, pos: d.pos, vel: d.vel, tick: now, own_tick: now, ttl: 400, hits: 3, locked: false })
.collect();
for r in sim.sams.iter_mut().filter(|s| s.kind == SamKind::Radar) {
for t in &tracks {
r.tracks.retain(|o| o.id != t.id);
r.tracks.push(*t);
}
}
}
fn fire_far(sim: &mut Sim, ground: &mut Ground, land: &Land<fn(i32, i32) -> i32>, out: &mut Out, ticks: u32) -> u32 {
for _ in 0..ticks {
radar_sees(sim);
serve(ground, land, sim.tick);
sim.step(ground, None, out);
}
sim.sams[0].fired
}
#[test]
fn heavy_systems_shoot_far_on_a_radars_cue_but_not_without_one() {
let max = SamKind::S400.spec().missile.as_ref().unwrap().max;
let (mut sim, mut ground, land, mut out) = far_setup(true, max * 1.4);
assert!(fire_far(&mut sim, &mut ground, &land, &mut out, 80) >= 1, "no long shot at 1.4 x max with a radar");
let w = sim.why(0);
assert!(w.iter().any(|c| c.text.starts_with("дальний пуск по РЛС")), "{:?}", w.iter().map(|c| &c.text).collect::<Vec<_>>());
// No radar, no shot (the system's own radar may well see it: that is not a cue).
let (mut sim, mut ground, land, mut out) = far_setup(false, max * 1.4);
assert_eq!(fire_far(&mut sim, &mut ground, &land, &mut out, 80), 0, "a long shot with no radar");
// And a kind that is not a heavy one never does.
let (mut sim, mut ground, land, mut out) = far_setup(true, max * 1.4);
sim.far_shots = false;
assert_eq!(fire_far(&mut sim, &mut ground, &land, &mut out, 80), 0, "a long shot with them switched off");
}
#[test]
fn a_long_shot_waits_out_its_cooldown_and_for_nothing_closer() {
let max = SamKind::S400.spec().missile.as_ref().unwrap().max;
// Two far targets: one long shot, the second waits its 300 ticks.
let (mut sim, mut ground, land, mut out) = far_setup(true, max * 1.4);
sim.add_drone(DroneKind::Kh101, DVec3::new(0.0, 300.0, max * 1.4), DVec3::NEG_Z, DVec3::new(0.0, 70.0, 0.0));
assert_eq!(fire_far(&mut sim, &mut ground, &land, &mut out, 70), 1, "not exactly one long shot in the cooldown");
// A closer target in normal reach: the far one is not fired at while it stands.
let (mut sim, mut ground, land, mut out) = far_setup(true, max * 1.4);
let far = sim.drones[0].id;
sim.add_drone(DroneKind::Kh101, DVec3::new(300.0, 120.0, 0.0), DVec3::NEG_X, DVec3::new(0.0, 70.0, 0.0));
for _ in 0..40 {
radar_sees(&mut sim);
serve(&mut ground, &land, sim.tick);
sim.step(&mut ground, None, &mut out);
assert!(!sim.missiles.iter().any(|m| m.target == far), "a long shot while a closer target was in reach");
}
assert!(sim.sams[0].fired > 0, "the closer target was not fired at");
}
#[test]
fn the_kill_chance_falls_to_half_at_the_far_end() {
assert_eq!(reach_fit(100.0, 80.0), 1.0);
assert_eq!(reach_fit(100.0, 100.0), 1.0);
assert!((reach_fit(100.0, 130.0) - 0.75).abs() < 1e-9);
assert!((reach_fit(100.0, 160.0) - 0.5).abs() < 1e-9);
assert!((reach_fit(100.0, 400.0) - 0.5).abs() < 1e-9);
}
#[test]
fn every_interceptor_lives_long_enough_to_fly_its_reach() {
// Life × top speed must cover the far end of a heavy system's reach with room to chase; the rest their plain reach.
for kind in SamKind::ARMED {
let Some(load) = kind.spec().missile.as_ref() else { continue };
let m = load.kind.spec();
let reach = load.max * if kind.far_shooter() { FAR_K } else { 1.0 };
assert!(m.life as f64 * m.speed > reach * 1.2, "{}: {} x {} does not cover {reach}", kind.name(), m.life, m.speed);
}
}
}