New systems (IRIS-T, NASAMS, Buk, Tor, P1-SUN), air-defence network with long-range radars, logistics, move orders, EW, adaptive enemy, searchlights and flares; grid holds a kill in view
build / mod (push) Successful in 5m7s
build / mod (push) Successful in 5m7s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+266
-250
@@ -13,6 +13,14 @@ mod damage;
|
||||
mod raid;
|
||||
pub mod record;
|
||||
mod sight;
|
||||
mod ew;
|
||||
mod lights;
|
||||
mod logistics;
|
||||
mod orders;
|
||||
mod units;
|
||||
pub use ew::EW_RADIUS;
|
||||
pub use units::{Family, SamKind};
|
||||
use units::Muzzle;
|
||||
pub use raid::{Approach, Aim, RaidOrder};
|
||||
|
||||
pub const TAU: f64 = std::f64::consts::TAU;
|
||||
@@ -645,6 +653,10 @@ pub struct Drone {
|
||||
route: Vec<DVec3>,
|
||||
/// Hugs the land all the way, under the radars.
|
||||
low: bool,
|
||||
/// Its navigation is being jammed.
|
||||
pub jammed: bool,
|
||||
/// The approach sector it came from (the enemy keeps score).
|
||||
sector: u8,
|
||||
}
|
||||
|
||||
impl Drone {
|
||||
@@ -667,6 +679,12 @@ pub enum MissileKind {
|
||||
M57e6,
|
||||
M48n6,
|
||||
M77n6,
|
||||
IrisT,
|
||||
Amraam,
|
||||
M9m317,
|
||||
M9m338,
|
||||
/// Not a missile: an interceptor drone, slow and cheap, that rams Shaheds.
|
||||
P1sun,
|
||||
}
|
||||
|
||||
struct MissileSpec {
|
||||
@@ -695,6 +713,9 @@ impl MissileKind {
|
||||
MissileKind::M57e6 => "airdef:launch.pantsir",
|
||||
MissileKind::M48n6 => "airdef:launch.s400_eject",
|
||||
MissileKind::M77n6 => "airdef:launch.s500_eject",
|
||||
MissileKind::IrisT | MissileKind::M9m338 => "airdef:launch.s400_eject",
|
||||
MissileKind::Amraam | MissileKind::M9m317 => "airdef:launch.patriot",
|
||||
MissileKind::P1sun => "airdef:drone.lancet",
|
||||
}
|
||||
}
|
||||
fn spec(self) -> &'static MissileSpec {
|
||||
@@ -755,6 +776,77 @@ impl MissileKind {
|
||||
flame: 1.6,
|
||||
rear: 32.0,
|
||||
},
|
||||
MissileKind::IrisT => &MissileSpec {
|
||||
model: "airdef:pac3",
|
||||
speed: 7.0,
|
||||
accel: 0.5,
|
||||
turn: 0.35,
|
||||
boost: 6,
|
||||
cold: 4,
|
||||
pk: 0.9,
|
||||
fuse: 4.0,
|
||||
life: 260,
|
||||
scale: 0.95,
|
||||
flame: 0.9,
|
||||
rear: 28.0,
|
||||
},
|
||||
MissileKind::Amraam => &MissileSpec {
|
||||
model: "airdef:pac3",
|
||||
speed: 6.0,
|
||||
accel: 0.45,
|
||||
turn: 0.3,
|
||||
boost: 6,
|
||||
cold: 0,
|
||||
pk: 0.85,
|
||||
fuse: 4.0,
|
||||
life: 260,
|
||||
scale: 0.9,
|
||||
flame: 0.9,
|
||||
rear: 28.0,
|
||||
},
|
||||
MissileKind::M9m317 => &MissileSpec {
|
||||
model: "airdef:m48n6",
|
||||
speed: 6.5,
|
||||
accel: 0.5,
|
||||
turn: 0.25,
|
||||
boost: 8,
|
||||
cold: 0,
|
||||
pk: 0.85,
|
||||
fuse: 5.0,
|
||||
life: 300,
|
||||
scale: 1.1,
|
||||
flame: 1.2,
|
||||
rear: 32.0,
|
||||
},
|
||||
MissileKind::M9m338 => &MissileSpec {
|
||||
model: "airdef:m57e6",
|
||||
speed: 5.5,
|
||||
accel: 0.6,
|
||||
turn: 0.4,
|
||||
boost: 4,
|
||||
cold: 4,
|
||||
pk: 0.9,
|
||||
fuse: 3.0,
|
||||
life: 160,
|
||||
scale: 1.0,
|
||||
flame: 0.8,
|
||||
rear: 28.0,
|
||||
},
|
||||
MissileKind::P1sun => &MissileSpec {
|
||||
model: "airdef:p1sun",
|
||||
speed: 2.8,
|
||||
accel: 0.12,
|
||||
turn: 0.3,
|
||||
boost: 4,
|
||||
cold: 0,
|
||||
pk: 0.8,
|
||||
fuse: 3.0,
|
||||
life: 900,
|
||||
scale: 0.8,
|
||||
// Electric: no flame.
|
||||
flame: 0.0,
|
||||
rear: 10.0,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -772,120 +864,6 @@ pub struct Missile {
|
||||
|
||||
// ---------------------------------------------------------------- air defence
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum SamKind {
|
||||
Patriot,
|
||||
Gepard,
|
||||
Pantsir,
|
||||
S400,
|
||||
S500,
|
||||
}
|
||||
|
||||
struct MissileLoad {
|
||||
kind: MissileKind,
|
||||
magazine: u32,
|
||||
min: f64,
|
||||
max: f64,
|
||||
/// Ticks between launches.
|
||||
interval: u32,
|
||||
}
|
||||
|
||||
struct GunSpec {
|
||||
range: f64,
|
||||
/// Starts tracking from here.
|
||||
track: f64,
|
||||
/// Chance per burst at point blank.
|
||||
p: f64,
|
||||
bursts: u32,
|
||||
/// Shell speed for the lead, blocks a tick.
|
||||
shell: f64,
|
||||
slew: (f64, f64),
|
||||
}
|
||||
|
||||
pub struct SamSpec {
|
||||
pub name: &'static str,
|
||||
pub key: &'static str,
|
||||
missile: Option<MissileLoad>,
|
||||
gun: Option<GunSpec>,
|
||||
reload: u32,
|
||||
scale: f64,
|
||||
/// Where it points its launcher at rest (pitch, radians).
|
||||
rest_pitch: f64,
|
||||
/// Which classes of target it engages unless told otherwise.
|
||||
pub roles: u8,
|
||||
}
|
||||
|
||||
impl SamKind {
|
||||
pub const ALL: [SamKind; 5] = [SamKind::Patriot, SamKind::Gepard, SamKind::Pantsir, SamKind::S400, SamKind::S500];
|
||||
pub fn spec(self) -> &'static SamSpec {
|
||||
match self {
|
||||
SamKind::Patriot => &SamSpec {
|
||||
name: "Patriot",
|
||||
key: "patriot",
|
||||
missile: Some(MissileLoad { kind: MissileKind::Pac3, magazine: 4, min: 10.0, max: 300.0, interval: 16 }),
|
||||
gun: None,
|
||||
reload: 220,
|
||||
scale: 1.3,
|
||||
rest_pitch: 0.66,
|
||||
roles: 30,
|
||||
},
|
||||
SamKind::Gepard => &SamSpec {
|
||||
name: "Гепард",
|
||||
key: "gepard",
|
||||
missile: None,
|
||||
gun: Some(GunSpec { range: 90.0, track: 130.0, p: 0.3, bursts: 160, shell: 10.0, slew: (0.22, 0.16) }),
|
||||
reload: 160,
|
||||
scale: 1.25,
|
||||
rest_pitch: 0.0,
|
||||
roles: 7,
|
||||
},
|
||||
SamKind::Pantsir => &SamSpec {
|
||||
name: "Панцирь-С1",
|
||||
key: "pantsir",
|
||||
missile: Some(MissileLoad { kind: MissileKind::M57e6, magazine: 12, min: 25.0, max: 150.0, interval: 14 }),
|
||||
gun: Some(GunSpec { range: 60.0, track: 90.0, p: 0.25, bursts: 140, shell: 9.0, slew: (0.25, 0.18) }),
|
||||
reload: 280,
|
||||
scale: 1.3,
|
||||
rest_pitch: 0.0,
|
||||
roles: 15,
|
||||
},
|
||||
SamKind::S400 => &SamSpec {
|
||||
name: "С-400",
|
||||
key: "s400",
|
||||
missile: Some(MissileLoad { kind: MissileKind::M48n6, magazine: 4, min: 30.0, max: 480.0, interval: 20 }),
|
||||
gun: None,
|
||||
reload: 420,
|
||||
scale: 1.5,
|
||||
rest_pitch: HALF_PI - 0.02,
|
||||
roles: 30,
|
||||
},
|
||||
SamKind::S500 => &SamSpec {
|
||||
name: "С-500",
|
||||
key: "s500",
|
||||
missile: Some(MissileLoad { kind: MissileKind::M77n6, magazine: 4, min: 40.0, max: 700.0, interval: 20 }),
|
||||
gun: None,
|
||||
reload: 520,
|
||||
scale: 1.6,
|
||||
rest_pitch: HALF_PI - 0.02,
|
||||
roles: 24,
|
||||
},
|
||||
}
|
||||
}
|
||||
pub fn name(self) -> &'static str {
|
||||
self.spec().name
|
||||
}
|
||||
pub fn key(self) -> &'static str {
|
||||
self.spec().key
|
||||
}
|
||||
pub fn from_key(key: &str) -> Option<Self> {
|
||||
Self::ALL.into_iter().find(|k| k.key() == key)
|
||||
}
|
||||
pub fn range(self) -> f64 {
|
||||
let s = self.spec();
|
||||
s.missile.as_ref().map_or(0.0, |m| m.max).max(s.gun.as_ref().map_or(0.0, |g| g.range))
|
||||
}
|
||||
}
|
||||
|
||||
/// What a system is doing, for the monitor.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum SamState {
|
||||
@@ -898,6 +876,12 @@ pub enum SamState {
|
||||
Reload,
|
||||
Hold,
|
||||
Destroyed,
|
||||
/// A move order: packing up, on the march, deploying again.
|
||||
Packing,
|
||||
Moving,
|
||||
Deploying,
|
||||
/// Out of missiles, waiting for a reload truck (logistics on: a depot stands).
|
||||
Waiting,
|
||||
}
|
||||
|
||||
impl SamState {
|
||||
@@ -912,6 +896,10 @@ impl SamState {
|
||||
SamState::Reload => "ПЕРЕЗАРЯДКА",
|
||||
SamState::Hold => "ОГОНЬ ЗАПРЕЩЁН",
|
||||
SamState::Destroyed => "УНИЧТОЖЕН",
|
||||
SamState::Packing => "СВЁРТЫВАНИЕ",
|
||||
SamState::Moving => "НА МАРШЕ",
|
||||
SamState::Deploying => "РАЗВЁРТЫВАНИЕ",
|
||||
SamState::Waiting => "ЖДЁТ БК",
|
||||
}
|
||||
}
|
||||
pub fn color(self) -> u32 {
|
||||
@@ -924,6 +912,8 @@ impl SamState {
|
||||
SamState::Reload => 0x80A0FF,
|
||||
SamState::Hold => 0xA0A0A0,
|
||||
SamState::Destroyed => 0xFF2020,
|
||||
SamState::Packing | SamState::Moving | SamState::Deploying => 0xC0A0FF,
|
||||
SamState::Waiting => 0xFF9040,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -959,8 +949,28 @@ pub struct Sam {
|
||||
pub health: f64,
|
||||
/// Ticks its wreck still burns.
|
||||
burn: u32,
|
||||
/// The drones its radar holds this tick.
|
||||
/// The drones it has tracks of this tick: its own radar's and the network's.
|
||||
pub seen: Vec<u32>,
|
||||
/// The drones its own radar (or optics) holds: guns need these.
|
||||
pub own: Vec<u32>,
|
||||
/// What it just shot down, where, and till when its camera stays on it.
|
||||
pub kill_view: Option<(u32, DVec3, u64)>,
|
||||
/// A move order's destination, and ticks left packing up or deploying.
|
||||
pub dest: Option<DVec3>,
|
||||
march: u32,
|
||||
/// A depot's reloads in stock; a reload truck's on board.
|
||||
pub cargo: u32,
|
||||
/// A reload truck's job: the system it is driving to, or a depot.
|
||||
job: Option<u32>,
|
||||
/// Out of ammunition, waiting for a reload (logistics on).
|
||||
pub empty: bool,
|
||||
/// An EW station: jamming, and its transmitter's heat (0 cold, 1 forced off).
|
||||
pub ew_on: bool,
|
||||
pub heat: f64,
|
||||
/// Overheated: off until it cools.
|
||||
pub ew_lock: bool,
|
||||
/// Ticks till a gun fires its next illumination flare.
|
||||
flare_cd: u32,
|
||||
}
|
||||
|
||||
impl Sam {
|
||||
@@ -991,6 +1001,21 @@ impl Sam {
|
||||
health: 1.0,
|
||||
burn: 0,
|
||||
seen: Vec::new(),
|
||||
own: Vec::new(),
|
||||
kill_view: None,
|
||||
dest: None,
|
||||
march: 0,
|
||||
cargo: match kind {
|
||||
SamKind::Depot => 30,
|
||||
SamKind::Tzm => 2,
|
||||
_ => 0,
|
||||
},
|
||||
job: None,
|
||||
empty: false,
|
||||
ew_on: false,
|
||||
heat: 0.0,
|
||||
ew_lock: false,
|
||||
flare_cd: 0,
|
||||
}
|
||||
}
|
||||
pub fn alive(&self) -> bool {
|
||||
@@ -1000,67 +1025,29 @@ impl Sam {
|
||||
fn fitness(&self) -> f64 {
|
||||
0.45 + 0.55 * self.health.clamp(0.0, 1.0)
|
||||
}
|
||||
fn base(&self) -> DQuat {
|
||||
DQuat::from_rotation_y(self.heading)
|
||||
}
|
||||
fn scale(&self) -> f64 {
|
||||
self.kind.spec().scale
|
||||
}
|
||||
/// Where shells and missiles leave: the centre of the turret or the
|
||||
/// launcher's pivot, and the rotation they leave with.
|
||||
fn mount(&self) -> (DVec3, DQuat) {
|
||||
let s = self.scale();
|
||||
let base = self.base();
|
||||
match self.kind {
|
||||
SamKind::Patriot => (
|
||||
self.pos + base * DVec3::new(0.0, 0.69 * s, 1.2 * s),
|
||||
DQuat::from_rotation_y(self.yaw) * DQuat::from_rotation_x(self.pitch),
|
||||
),
|
||||
SamKind::Gepard => (
|
||||
self.pos + DVec3::new(0.0, 1.55 * s, 0.0) + base * DVec3::new(0.0, 0.0, 0.25 * s),
|
||||
DQuat::from_rotation_y(self.yaw) * DQuat::from_rotation_x(self.pitch),
|
||||
),
|
||||
SamKind::Pantsir => (
|
||||
self.pos + DVec3::new(0.0, 1.35 * s, 0.0) + base * DVec3::new(0.0, 0.0, 0.69 * s),
|
||||
DQuat::from_rotation_y(self.yaw) * DQuat::from_rotation_x(self.pitch),
|
||||
),
|
||||
SamKind::S400 | SamKind::S500 => (
|
||||
self.pos + base * DVec3::new(0.0, 0.7 * s, 1.45 * s),
|
||||
base * DQuat::from_rotation_x(self.pitch),
|
||||
),
|
||||
}
|
||||
}
|
||||
/// Where missile `n` of the magazine leaves (world), and which way.
|
||||
fn muzzle(&self, n: u32) -> (DVec3, DVec3) {
|
||||
let (at, rot) = self.mount();
|
||||
let s = self.scale();
|
||||
let local = match self.kind {
|
||||
SamKind::Patriot => DVec3::new(
|
||||
if n % 2 == 0 { -0.42 } else { 0.42 },
|
||||
0.625 + if n % 4 < 2 { 0.28 } else { -0.28 },
|
||||
-2.8,
|
||||
),
|
||||
SamKind::Pantsir => {
|
||||
let side = if n % 2 == 0 { -0.94 } else { 0.94 };
|
||||
let row = (n / 2) % 6;
|
||||
DVec3::new(side + ((row % 3) as f64 - 1.0) * 0.15, 0.1 + if row < 3 { 0.15 } else { -0.15 }, -1.5)
|
||||
}
|
||||
SamKind::S400 => {
|
||||
let i = n % 4;
|
||||
// From the pivot (rear bottom of the pack) to the top of tube i.
|
||||
DVec3::new(if i % 2 == 0 { -0.25 } else { 0.25 }, if i < 2 { 0.22 } else { 0.72 }, -3.0)
|
||||
}
|
||||
SamKind::S500 => DVec3::new(if n % 2 == 0 { -0.33 } else { 0.33 }, 0.3, -3.0),
|
||||
SamKind::Gepard => DVec3::ZERO,
|
||||
};
|
||||
(at + rot * local * s, rot * DVec3::NEG_Z)
|
||||
}
|
||||
pub fn status(&self) -> String {
|
||||
let spec = self.kind.spec();
|
||||
let mut text = spec.name.to_string();
|
||||
if !self.alive() {
|
||||
return text + " УНИЧТОЖЕН";
|
||||
}
|
||||
if self.moving() {
|
||||
return text + " " + &self.state.name().to_lowercase();
|
||||
}
|
||||
match self.kind {
|
||||
SamKind::Depot => return format!("{text}: запас {} перезарядок", self.cargo),
|
||||
SamKind::Tzm => return format!("{text}: на борту {}/2{}", self.cargo, if self.job.is_some() { ", в пути" } else { "" }),
|
||||
SamKind::Ew => {
|
||||
let state = if self.ew_on { "ГЛУШИТ" } else if self.ew_lock { "остывает" } else { "готова" };
|
||||
return format!("{text}: {state}, нагрев {:.0}%", self.heat * 100.0);
|
||||
}
|
||||
SamKind::Radar => return format!("{text}: целей {}", self.own.len()),
|
||||
SamKind::Light => return format!("{text}{}", if self.target.is_some() { ": в луче цель" } else { "" }),
|
||||
_ => {}
|
||||
}
|
||||
if self.empty && self.missiles == 0 {
|
||||
text += " ЖДЁТ БК";
|
||||
}
|
||||
if self.health < 1.0 {
|
||||
text += &format!(" ({:.0}%)", self.health * 100.0);
|
||||
}
|
||||
@@ -1129,6 +1116,13 @@ pub struct Sim {
|
||||
rec: Option<record::Recording>,
|
||||
pub replays: Vec<record::Recording>,
|
||||
recordings: u32,
|
||||
/// What the enemy has learned.
|
||||
intel: ew::Intel,
|
||||
/// Night: guns need light (the mod sets it from the game's clock).
|
||||
pub night: bool,
|
||||
/// Illumination flares in the sky, and the drones lit this tick.
|
||||
pub flares: Vec<lights::Flare>,
|
||||
lit: Vec<u32>,
|
||||
}
|
||||
|
||||
/// Ids: objects get multiples of 16, their parts the low bits.
|
||||
@@ -1162,6 +1156,10 @@ impl Sim {
|
||||
rec: None,
|
||||
replays: Vec::new(),
|
||||
recordings: 0,
|
||||
intel: ew::Intel::default(),
|
||||
night: false,
|
||||
flares: Vec::new(),
|
||||
lit: Vec::new(),
|
||||
}
|
||||
}
|
||||
pub fn id(&mut self) -> u32 {
|
||||
@@ -1172,6 +1170,12 @@ impl Sim {
|
||||
/// What a system's camera follows: its guns' or missiles' target, else what its missiles in
|
||||
/// flight are after.
|
||||
pub fn watched(&self, sam: &Sam) -> Option<&Drone> {
|
||||
// A kill stays in view a few seconds: the wreck falling, before the next target.
|
||||
if let Some((id, _, until)) = sam.kill_view
|
||||
&& self.tick < until
|
||||
{
|
||||
return self.drones.iter().find(|d| d.id == id);
|
||||
}
|
||||
let id = sam
|
||||
.gun_target
|
||||
.or(sam.target)
|
||||
@@ -1179,6 +1183,22 @@ impl Sim {
|
||||
self.drones.iter().find(|d| d.id == id)
|
||||
}
|
||||
|
||||
/// Where a system's camera looks: what it watches, or where its last kill was while that
|
||||
/// stays in view (the wreck may be gone).
|
||||
pub fn focus(&self, sam: &Sam) -> Option<DVec3> {
|
||||
if let Some((_, at, until)) = sam.kill_view
|
||||
&& self.tick < until
|
||||
{
|
||||
return Some(self.watched(sam).map_or(at, |d| d.pos));
|
||||
}
|
||||
self.watched(sam).map(|d| d.pos)
|
||||
}
|
||||
|
||||
/// Whether a system's camera is showing its kill.
|
||||
pub fn showing_kill(&self, sam: &Sam) -> bool {
|
||||
sam.kill_view.is_some_and(|(_, _, until)| self.tick < until)
|
||||
}
|
||||
|
||||
pub fn nearest_target(&self, to: DVec3) -> Option<DVec3> {
|
||||
self.targets.iter().copied().min_by(|a, b| a.distance_squared(to).total_cmp(&b.distance_squared(to)))
|
||||
}
|
||||
@@ -1208,6 +1228,8 @@ impl Sim {
|
||||
engaged: 0,
|
||||
route: Vec::new(),
|
||||
low: false,
|
||||
jammed: false,
|
||||
sector: 0,
|
||||
});
|
||||
self.launched += 1;
|
||||
}
|
||||
@@ -1253,10 +1275,15 @@ impl Sim {
|
||||
pub fn step(&mut self, ground: &mut Ground, player: Option<DVec3>, out: &mut Out) {
|
||||
self.tick += 1;
|
||||
self.plan_step(out);
|
||||
self.adapt();
|
||||
self.release_queue();
|
||||
self.step_drones(ground, player, out);
|
||||
self.step_later(ground, player, out);
|
||||
self.step_moves(ground, out);
|
||||
self.step_supply(out);
|
||||
self.step_ew(out);
|
||||
self.update_sight(ground);
|
||||
self.step_lights(out);
|
||||
self.step_sams(out);
|
||||
self.step_missiles(out);
|
||||
self.step_fx(ground, out);
|
||||
@@ -1384,6 +1411,10 @@ impl Sim {
|
||||
if d.flight == Flight::Cruise && d.route.len() <= 1 && horizontal(d.target - d.pos).length() < spec.dive {
|
||||
d.flight = Flight::Dive;
|
||||
}
|
||||
// An interceptor coming: drones drop to the treetops (radars lose them sooner).
|
||||
if d.engaged > 0 && matches!(spec.class, Class::Drone | Class::Jet) {
|
||||
d.low = true;
|
||||
}
|
||||
// A planned route: the next point, then the next.
|
||||
// Reached when near (as near as it can turn), or passed: behind it and close.
|
||||
let radius = (spec.speed / spec.turn.max(0.01)).max(24.0);
|
||||
@@ -1453,6 +1484,9 @@ impl Sim {
|
||||
self.log(pos, record::EventKind::Split { drone });
|
||||
}
|
||||
for (drone, kind, pos, tnt) in impacts {
|
||||
if let Some(sector) = self.drones.iter().find(|x| x.id == drone).map(|x| x.sector as usize) {
|
||||
self.learn(sector, false);
|
||||
}
|
||||
let power = match tnt {
|
||||
0 => 0,
|
||||
1 | 2 => 1,
|
||||
@@ -1483,6 +1517,8 @@ impl Sim {
|
||||
engaged: 0,
|
||||
route: Vec::new(),
|
||||
low: false,
|
||||
jammed: false,
|
||||
sector: 0,
|
||||
});
|
||||
}
|
||||
for d in &self.drones {
|
||||
@@ -1597,6 +1633,12 @@ impl Sim {
|
||||
if !self.drones[idx].alive() {
|
||||
return;
|
||||
}
|
||||
let sector = self.drones[idx].sector as usize;
|
||||
self.learn(sector, true);
|
||||
let until = self.tick + 70;
|
||||
if let Some(s) = self.sams.iter_mut().find(|s| s.id == by) {
|
||||
s.kill_view = Some((self.drones[idx].id, self.drones[idx].pos, until));
|
||||
}
|
||||
if let Some((i, s)) = self.sams.iter().enumerate().find(|(_, s)| s.id == by) {
|
||||
let (drone, kind, pos) = (self.drones[idx].id, self.drones[idx].kind, self.drones[idx].pos);
|
||||
let kill = record::EventKind::Kill { drone, kind, sam: by, sam_kind: s.kind, sam_index: i, missile };
|
||||
@@ -1630,13 +1672,14 @@ impl Sim {
|
||||
fn step_sams(&mut self, out: &mut Out) {
|
||||
if self.hold {
|
||||
for i in 0..self.sams.len() {
|
||||
if self.sams[i].alive() {
|
||||
if self.sams[i].alive() && !self.sams[i].moving() {
|
||||
self.sams[i].state = SamState::Hold;
|
||||
}
|
||||
self.draw_sam(i, out);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let logistics = self.logistics();
|
||||
let mut launches: Vec<(MissileKind, DVec3, DVec3, u32, u32)> = Vec::new();
|
||||
let mut gun_hits: Vec<(u32, u32)> = Vec::new();
|
||||
let mut tracers: Vec<(u32, DVec3, DVec3, u32)> = Vec::new();
|
||||
@@ -1666,10 +1709,21 @@ impl Sim {
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.sams[i].moving() {
|
||||
continue;
|
||||
}
|
||||
if !self.sams[i].kind.armed() {
|
||||
let sam = &mut self.sams[i];
|
||||
sam.state = SamState::Search;
|
||||
sam.target = None;
|
||||
sam.gun_target = None;
|
||||
continue;
|
||||
}
|
||||
let pos = self.sams[i].pos;
|
||||
let me = self.sams[i].id;
|
||||
let roles = self.sams[i].roles;
|
||||
let seen = self.sams[i].seen.clone();
|
||||
let own = self.sams[i].own.clone();
|
||||
let allowed = |d: &Drone| d.alive() && roles & d.kind.spec().class.bit() != 0 && seen.contains(&d.id);
|
||||
// Interceptors a target has or will have: in flight, and other systems' launchers on it.
|
||||
let claimed = |d: &Drone| {
|
||||
@@ -1699,7 +1753,7 @@ impl Sim {
|
||||
self.sams[i].gun_target = self
|
||||
.drones
|
||||
.iter()
|
||||
.filter(|d| allowed(d) && d.pos.distance(pos) < gun.track)
|
||||
.filter(|d| allowed(d) && own.contains(&d.id) && d.pos.distance(pos) < gun.track)
|
||||
.map(|d| {
|
||||
let busy = 1.0 + 2.0 * guns_on(d) + if d.engaged > 0 { 1.5 } else { 0.0 };
|
||||
(d.pos.distance(pos) * busy, d.id)
|
||||
@@ -1713,10 +1767,16 @@ impl Sim {
|
||||
sam.launched = sam.launched.saturating_sub(1);
|
||||
let Some(aim) = aim else {
|
||||
// Out of missiles and nothing to shoot: reload now, guns or not.
|
||||
if spec.missile.is_some() && sam.missiles == 0 && sam.reloading == 0 {
|
||||
sam.reloading = spec.reload;
|
||||
if spec.missile.is_some() && sam.missiles == 0 && sam.reloading == 0 && !sam.empty {
|
||||
if logistics { sam.empty = true } else { sam.reloading = spec.reload }
|
||||
}
|
||||
sam.state = if sam.reloading > 0 { SamState::Reload } else { SamState::Search };
|
||||
sam.state = if sam.reloading > 0 {
|
||||
SamState::Reload
|
||||
} else if sam.empty {
|
||||
SamState::Waiting
|
||||
} else {
|
||||
SamState::Search
|
||||
};
|
||||
sam.yaw = slew(sam.yaw, sam.heading, 0.03);
|
||||
sam.pitch += (spec.rest_pitch - sam.pitch) * 0.05;
|
||||
continue;
|
||||
@@ -1729,9 +1789,12 @@ impl Sim {
|
||||
let want_pitch = (to.y / to.length().max(0.01)).asin().clamp(-0.1, 1.45);
|
||||
let (yaw_rate, pitch_rate) = spec.gun.as_ref().map_or((0.05, 0.05), |g| g.slew);
|
||||
let (yaw_rate, pitch_rate) = (yaw_rate * fit, pitch_rate * fit);
|
||||
match sam.kind {
|
||||
SamKind::S400 | SamKind::S500 => {} // vertical launch: no aiming
|
||||
SamKind::Patriot => sam.yaw = slew(sam.yaw, want_yaw, 0.12 * fit),
|
||||
let cells = matches!(spec.muzzle, Muzzle::Cells);
|
||||
match spec.family {
|
||||
// Vertical launch: no aiming (the Tor's turret turns its radar to the target).
|
||||
Family::Vertical if cells => sam.yaw = slew(sam.yaw, want_yaw, 0.15 * fit),
|
||||
Family::Vertical => {}
|
||||
Family::Trainable => sam.yaw = slew(sam.yaw, want_yaw, 0.12 * fit),
|
||||
_ => {
|
||||
sam.yaw = slew(sam.yaw, want_yaw, yaw_rate);
|
||||
sam.pitch = slew(sam.pitch, want_pitch, pitch_rate);
|
||||
@@ -1739,9 +1802,11 @@ impl Sim {
|
||||
}
|
||||
let aim_error = angle_diff(sam.yaw, want_yaw).abs()
|
||||
+ if spec.gun.is_some() { (want_pitch - sam.pitch).abs() } else { 0.0 };
|
||||
let vertical = matches!(sam.kind, SamKind::S400 | SamKind::S500);
|
||||
let vertical = spec.family == Family::Vertical;
|
||||
sam.state = if sam.reloading > 0 {
|
||||
SamState::Reload
|
||||
} else if sam.empty && sam.missiles == 0 && sam.bursts == 0 {
|
||||
SamState::Waiting
|
||||
} else if sam.launched > 0 {
|
||||
SamState::Launch
|
||||
} else if sam.flash > 0 {
|
||||
@@ -1763,7 +1828,7 @@ impl Sim {
|
||||
sam.flash = 2;
|
||||
sam.recoil = 1.0;
|
||||
if sam.bursts == 0 && sam.missiles == 0 {
|
||||
sam.reloading = spec.reload;
|
||||
if logistics { sam.empty = true } else { sam.reloading = spec.reload }
|
||||
}
|
||||
let (_, rot) = sam.mount();
|
||||
let s = spec.scale;
|
||||
@@ -1787,7 +1852,9 @@ impl Sim {
|
||||
let event = if sam.kind == SamKind::Pantsir { "airdef:gun.pantsir" } else { "airdef:gun.gepard" };
|
||||
out.sound(event, mount, 1.0, 0.95 + self.rng.f() as f32 * 0.1);
|
||||
}
|
||||
let p = gun.p * fit / t.kind.spec().stealth * (1.0 - dist / (gun.range * 1.3)).max(0.35);
|
||||
// At night a gun sees what is lit (a searchlight, a flare) and little else.
|
||||
let dark = if self.night && !self.lit.contains(&t.id) { lights::DARK_HITS } else { 1.0 };
|
||||
let p = gun.p * fit * dark / t.kind.spec().stealth * (1.0 - dist / (gun.range * 1.3)).max(0.35);
|
||||
if self.rng.chance(p) {
|
||||
gun_hits.push((gt, sam.id));
|
||||
} else {
|
||||
@@ -1799,13 +1866,13 @@ impl Sim {
|
||||
// Missiles.
|
||||
if let (Some(load), Some(mt)) = (&spec.missile, sam.target) {
|
||||
let ready = sam.cooldown == 0 && sam.reloading == 0 && sam.missiles > 0;
|
||||
let aligned = match sam.kind {
|
||||
SamKind::Patriot => {
|
||||
let aligned = match spec.family {
|
||||
Family::Trainable => {
|
||||
let t = self.drones.iter().find(|d| d.id == mt);
|
||||
// The missile turns after its boost: the launcher needn't be exact.
|
||||
t.is_some_and(|t| angle_diff(sam.yaw, heading_of(t.pos - mount)).abs() < 0.45)
|
||||
}
|
||||
SamKind::Pantsir => aim.id == mt && aim_error < 0.2,
|
||||
Family::Turret => aim.id == mt && aim_error < 0.2,
|
||||
_ => true,
|
||||
};
|
||||
if ready && aligned {
|
||||
@@ -1819,12 +1886,16 @@ impl Sim {
|
||||
sam.fired += 1;
|
||||
sam.cooldown = load.interval;
|
||||
if sam.missiles == 0 && (spec.gun.is_none() || sam.bursts == 0) {
|
||||
sam.reloading = spec.reload;
|
||||
if logistics { sam.empty = true } else { sam.reloading = spec.reload }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (kind, muzzle, dir, target, sam) in launches {
|
||||
// A launch gives the system away.
|
||||
if let Some(s) = self.sams.iter().find(|s| s.id == sam) {
|
||||
self.intel.revealed.push((sam, s.pos, self.tick));
|
||||
}
|
||||
let spec = kind.spec();
|
||||
let id = self.id();
|
||||
let v0 = if spec.cold > 0 { 0.7 } else { 0.8 };
|
||||
@@ -1858,69 +1929,6 @@ impl Sim {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_sam(&mut self, i: usize, out: &mut Out) {
|
||||
if !self.sams[i].alive() {
|
||||
self.draw_wreck(i, out);
|
||||
return;
|
||||
}
|
||||
let sam = &self.sams[i];
|
||||
let base = sam.base();
|
||||
let s = sam.scale();
|
||||
let up = DVec3::Y * 0.5 * s;
|
||||
let id = sam.id;
|
||||
let (mount, rot) = sam.mount();
|
||||
let turret = DQuat::from_rotation_y(sam.yaw);
|
||||
match sam.kind {
|
||||
SamKind::Patriot => {
|
||||
out.model(id, "airdef:patriot_trailer", sam.pos + up, base, s, false);
|
||||
out.model(id + 1, "airdef:patriot_truck", sam.pos + up + base * DVec3::new(0.0, 0.0, -3.0 * s), base, s, false);
|
||||
// The launcher's pivot is its back bottom edge (0, -0.5, 1.375).
|
||||
out.model(id + 2, "airdef:patriot_launcher", mount - rot * DVec3::new(0.0, -0.5, 1.375) * s, rot, s, false);
|
||||
// Its radar stands right behind the trailer, facing the same way.
|
||||
out.model(id + 3, "airdef:patriot_radar", sam.pos + up + base * DVec3::new(0.0, 0.0, 3.6 * s), base, s, false);
|
||||
}
|
||||
SamKind::Gepard => {
|
||||
out.model(id, "airdef:gepard_hull", sam.pos + up, base, s, false);
|
||||
out.model(id + 1, "airdef:gepard_turret", mount + DVec3::Y * 0.12 * s, turret, s, false);
|
||||
let recoil = rot * DVec3::new(0.0, 0.0, 0.15 * sam.recoil * s);
|
||||
out.model(id + 2, "airdef:gepard_guns", mount + recoil, rot, s, false);
|
||||
out.model(id + 3, "airdef:gepard_dish", mount + turret * DVec3::new(0.0, 0.95 * s, 0.6 * s), DQuat::from_rotation_y(sam.dish), s, false);
|
||||
}
|
||||
SamKind::Pantsir => {
|
||||
out.model(id, "airdef:pantsir_truck", sam.pos + up, base, s, false);
|
||||
out.model(id + 1, "airdef:pantsir_turret", mount - DVec3::Y * 0.2 * s, turret, s, false);
|
||||
let recoil = rot * DVec3::new(0.0, 0.0, 0.1 * sam.recoil * s);
|
||||
out.model(id + 2, "airdef:pantsir_pack", mount + DVec3::Y * 0.1 * s + recoil, rot, s, false);
|
||||
out.model(id + 3, "airdef:pantsir_dish", mount + turret * DVec3::new(0.0, 0.85 * s, 0.3 * s), DQuat::from_rotation_y(sam.dish) * DQuat::from_rotation_x(0.3), s, false);
|
||||
}
|
||||
SamKind::S400 | SamKind::S500 => {
|
||||
let (chassis, tubes) = if sam.kind == SamKind::S400 {
|
||||
("airdef:s400_chassis", "airdef:s400_tubes")
|
||||
} else {
|
||||
("airdef:s500_chassis", "airdef:s500_tubes")
|
||||
};
|
||||
out.model(id, chassis, sam.pos + up, base, s, false);
|
||||
// The pack's pivot is its back bottom edge (0, -0.5, 1.5).
|
||||
out.model(id + 1, tubes, mount - rot * DVec3::new(0.0, -0.5, 1.5) * s, rot, s, false);
|
||||
// The battery's search radar behind it, turning.
|
||||
let radar = sam.pos + DVec3::Y * 0.5 * s + base * DVec3::new(0.0, 0.0, 4.2 * s);
|
||||
out.model(id + 2, "airdef:radar_trailer", radar, base, s, false);
|
||||
out.model(id + 3, "airdef:radar_panel", radar + DVec3::Y * 0.9 * s, DQuat::from_rotation_y(sam.dish * 0.6) * DQuat::from_rotation_x(-0.3), s * 0.9, false);
|
||||
}
|
||||
}
|
||||
if sam.flash > 0 {
|
||||
let barrels: &[DVec3] = match sam.kind {
|
||||
SamKind::Pantsir => &[DVec3::new(-0.95, 0.33, -1.7), DVec3::new(0.95, 0.33, -1.7)],
|
||||
SamKind::Gepard => &[DVec3::new(-0.92, -0.11, -1.7), DVec3::new(0.92, -0.11, -1.7)],
|
||||
_ => &[],
|
||||
};
|
||||
for (k, b) in barrels.iter().enumerate() {
|
||||
let r = rot * DQuat::from_rotation_z(self.rng.f() * TAU);
|
||||
out.model(id + 4 + k as u32, "airdef:flash", mount + rot * *b * s, r, 0.9, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------ interceptors
|
||||
|
||||
fn step_missiles(&mut self, out: &mut Out) {
|
||||
@@ -1971,13 +1979,21 @@ impl Sim {
|
||||
done.push((m.id, None, false, m.sam));
|
||||
continue;
|
||||
}
|
||||
if lit {
|
||||
if lit && spec.flame == 0.0 {
|
||||
if m.age % 20 == 1 {
|
||||
out.sound("airdef:drone.lancet", m.pos, 0.8, 1.6);
|
||||
}
|
||||
} else if lit {
|
||||
if (m.age - spec.cold) % 46 == 1 {
|
||||
let pitch = match m.kind {
|
||||
MissileKind::Pac3 => 1.0,
|
||||
MissileKind::M57e6 => 1.12,
|
||||
MissileKind::M48n6 => 0.88,
|
||||
MissileKind::M77n6 => 0.8,
|
||||
MissileKind::IrisT | MissileKind::Amraam => 1.05,
|
||||
MissileKind::M9m317 => 0.9,
|
||||
MissileKind::M9m338 => 1.15,
|
||||
MissileKind::P1sun => 1.7,
|
||||
};
|
||||
out.sound("airdef:missile.flight", m.pos, 1.0, pitch);
|
||||
}
|
||||
@@ -2017,7 +2033,7 @@ impl Sim {
|
||||
let spec = m.kind.spec();
|
||||
let rot = look(m.vel, 0.0) * DQuat::from_rotation_z(m.age as f64 * 0.3);
|
||||
out.model(m.id, spec.model, m.pos, rot, spec.scale, false);
|
||||
if m.age > spec.cold {
|
||||
if m.age > spec.cold && spec.flame > 0.0 {
|
||||
let back = (spec.rear - 8.0) / 16.0 * spec.scale + spec.flame;
|
||||
let size = spec.flame * if m.age < 40 { 1.2 } else { 0.8 } * (0.85 + 0.15 * self.rng.f());
|
||||
out.model(m.id + 1, "airdef:flame", m.pos + rot * DVec3::new(0.0, 0.0, back), rot, size, true);
|
||||
|
||||
Reference in New Issue
Block a user