Oreshnik with MIRV, impact power tiers, far missile glow, SAM cameras and command post grid

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 22:31:14 +03:00
parent 2ec7861173
commit 43346aecfe
57 changed files with 1662 additions and 126 deletions
+59 -13
View File
@@ -18,7 +18,7 @@ mod radar;
mod sim;
use sim::{Class, DroneKind, Ground, Out, Sam, SamKind, Sim};
const ITEMS: [&str; 16] = [
const ITEMS: [&str; 17] = [
"airdef:designator",
"airdef:launch_shahed",
"airdef:launch_geran3",
@@ -29,6 +29,7 @@ const ITEMS: [&str; 16] = [
"airdef:launch_zircon",
"airdef:launch_iskander",
"airdef:launch_kinzhal",
"airdef:launch_oreshnik",
"airdef:deploy_patriot",
"airdef:deploy_gepard",
"airdef:deploy_pantsir",
@@ -45,6 +46,8 @@ struct AirDef {
/// The system the monitor shows (K cycles), none: hidden.
monitor: Option<usize>,
monitor_shown: bool,
/// Every system's monitor in a grid (J).
grid: bool,
/// The menu's page while it is open.
menu: Option<Page>,
/// Where the player is, for the sounds' delay and far variants.
@@ -75,6 +78,7 @@ const BTN_HOLD: u32 = 10;
const BTN_SHADER: u32 = 11;
const BTN_DAMAGE: u32 = 12;
const BTN_MONITOR: u32 = 13;
const BTN_GRID: u32 = 14;
const BTN_CLASS: u32 = 100;
const BTN_ALL: u32 = 120;
const BTN_DEFAULT: u32 = 121;
@@ -198,6 +202,7 @@ impl AirDef {
"airdef:flash" => (1.0, 0.85, 0.5, 2.0),
"airdef:target" => (1.0, 0.1, 0.1, 0.5),
"airdef:tracer" => (1.0, 0.12, 0.05, 0.9),
"airdef:reentry" => (1.0, 0.6, 0.3, 1.4),
_ => continue,
};
p.extend([m.at.x as f32, m.at.y as f32, m.at.z as f32, m.scale * 1.6]);
@@ -290,7 +295,8 @@ impl AirDef {
fn draw_hud(&mut self, player: DVec3, yaw: f32) {
let air: Vec<&sim::Drone> = self.sim.drones.iter().filter(|d| d.alive()).collect();
if air.is_empty() && self.sim.sams.is_empty() && self.sim.missiles.is_empty() {
// The command post's grid covers the screen: the other panels wait under it.
if self.grid || (air.is_empty() && self.sim.sams.is_empty() && self.sim.missiles.is_empty()) {
if self.hud_shown {
hud::clear();
render::clear_corner();
@@ -401,6 +407,7 @@ impl AirDef {
None => "скрыт".into(),
};
widgets.push(Widget::Button(ButtonWidget { id: BTN_MONITOR, label: format!("Монитор: {monitor}") }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_GRID, label: "Командный пункт: все комплексы (J)".into() }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_SHADER, label: format!("Эффекты: {}", onoff(self.sim.shader)) }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_DAMAGE, label: format!("Разрушения: {}", onoff(self.sim.damage)) }));
}
@@ -442,7 +449,7 @@ impl AirDef {
}
}
const HELP: &str = "/airdef menu | monitor | give | wave <тип|mix> [кол-во] [дальность] | clear | targets clear | damage on|off | shader on|off | hold on|off | roles [комплекс классы] | stats";
const HELP: &str = "/airdef menu | monitor | grid | give | deploy <комплекс> | wave <тип|mix> [кол-во] [дальность] | clear | targets clear | damage on|off | shader on|off | hold on|off | roles [комплекс классы] | stats";
impl Mod for AirDef {
fn init() -> Result<(Self, Registration), String> {
@@ -454,12 +461,14 @@ impl Mod for AirDef {
hud_shown: false,
monitor: None,
monitor_shown: false,
grid: false,
menu: None,
listener: DVec3::ZERO,
pending: Vec::new(),
};
let _ = input::register_key("menu", "Меню AirDef", "key.keyboard.n");
let _ = input::register_key("monitor", "Монитор ПВО: следующий комплекс", "key.keyboard.k");
let _ = input::register_key("grid", "Командный пункт: все комплексы", "key.keyboard.j");
me.load();
input::claim_items(&ITEMS.map(String::from));
render::set_post(include_str!("../shaders/effects.wgsl"));
@@ -474,6 +483,7 @@ impl Mod for AirDef {
Event::UseStart(u) => self.use_item(&u.item.id),
Event::KeyDown(k) if k == "menu" => self.open_menu(Page::Main),
Event::KeyDown(k) if k == "monitor" => self.cycle_monitor(),
Event::KeyDown(k) if k == "grid" => self.grid = !self.grid,
_ => {}
}
}
@@ -488,15 +498,25 @@ impl Mod for AirDef {
}
self.emit(out);
self.draw_hud(DVec3::new(p.x, p.y, p.z), p.yaw);
match self.monitor {
Some(i) if i < self.sim.sams.len() => {
render::set_hud(&monitor::draw(&self.sim, i));
self.monitor_shown = true;
}
_ => {
if self.monitor_shown {
render::set_hud(&[]);
self.monitor_shown = false;
// The monitors and the cameras they show.
if self.grid {
render::set_hud(&monitor::grid(&self.sim, render::gui_size()));
let views: Vec<_> = self.sim.sams.iter().take(8).map(|s| monitor::camera(&self.sim, s)).collect();
render::set_views(&views);
self.monitor_shown = true;
} else {
match self.monitor {
Some(i) if i < self.sim.sams.len() => {
render::set_hud(&monitor::draw(&self.sim, i));
render::set_views(&[monitor::camera(&self.sim, &self.sim.sams[i])]);
self.monitor_shown = true;
}
_ => {
if self.monitor_shown {
render::set_hud(&[]);
render::set_views(&[]);
self.monitor_shown = false;
}
}
}
}
@@ -516,6 +536,12 @@ impl Mod for AirDef {
}
(Page::Main, BTN_HOLD) => self.sim.hold = !self.sim.hold,
(Page::Main, BTN_MONITOR) => self.cycle_monitor(),
(Page::Main, BTN_GRID) => {
self.grid = true;
self.menu = None;
ui::close_screen();
return;
}
(Page::Main, BTN_SHADER) => {
self.sim.shader = !self.sim.shader;
if self.sim.shader {
@@ -560,10 +586,30 @@ impl Mod for AirDef {
self.cycle_monitor();
None
}
["grid"] => {
self.grid = !self.grid;
None
}
["give"] => {
self.give();
None
}
["deploy", kind] => {
// A system where the player stands, a few blocks ahead.
let kind = SamKind::from_key(kind).ok_or("Комплексы: patriot, gepard, pantsir, s400, s500")?;
let p = player().ok_or("Нет игрока")?;
let d = view(&p);
let flat = DVec3::new(d.x, 0.0, d.z).normalize_or(DVec3::NEG_Z);
let at = DVec3::new(p.x, p.y, p.z) + flat * 8.0;
let sid = self.sim.id();
let mut sam = Sam::new(sid, kind, at, (-flat.x).atan2(-flat.z));
if let Some(r) = self.sim.roles.get(&kind) {
sam.roles = *r;
}
self.sim.sams.push(sam);
self.dirty = true;
Some(format!("{} развёрнут", kind.name()))
}
["wave", kind, rest @ ..] => {
let count = rest.first().and_then(|v| v.parse().ok()).unwrap_or(5u32).clamp(1, 80);
let dist = rest.get(1).and_then(|v| v.parse().ok()).unwrap_or(260.0f64).clamp(60.0, 800.0);
@@ -571,7 +617,7 @@ impl Mod for AirDef {
let target = self
.sim
.nearest_target(DVec3::new(p.x, p.y, p.z))
.ok_or("Сначала отметьте цель Целеуказателем")?;
.unwrap_or(DVec3::new(p.x, p.y, p.z));
if *kind == "mix" {
// A combined strike: decoys first, then Shaheds, jets and cruise missiles.
let n = count.max(4);
+144 -88
View File
@@ -1,14 +1,11 @@
//! The air-defence monitor (top left): one system at a time (K cycles them):
//! its state, its radar's picture round it and a thermal camera locked on
//! its target.
//! The air-defence monitor: a system's state, its radar's picture round it
//! and its camera (a real view of the world from the system, the game
//! renders it) locked on its target. K shows one system at a time, J all of
//! them in a grid.
use crate::panel::distance;
use crate::sim::{Sim, SamState, heading_of, roles_text};
use horizon_mod_sdk::render::{FillShape, ItemShape, Point, QuadShape, Rect, Shape, TextShape};
const W: f32 = 212.0;
const H: f32 = 132.0;
const X: f32 = 4.0;
const Y: f32 = 4.0;
use crate::sim::{Sam, SamState, Sim, heading_of, roles_text};
use glam::DVec3;
use horizon_mod_sdk::render::{self, CameraView, FillShape, Point, QuadShape, Rect, Shape, TextShape, ViewShape};
fn fill(x: f32, y: f32, w: f32, h: f32, color: u32) -> Shape {
Shape::Fill(FillShape { rect: Rect { x, y, w, h }, color })
@@ -23,6 +20,18 @@ fn quad(a: (f32, f32), b: (f32, f32), c: (f32, f32), d: (f32, f32), color: u32)
Shape::Quad(QuadShape { corners: (p(a), p(b), p(c), p(d)), color })
}
/// `t` cut to `w` GUI pixels, with an ellipsis.
fn fit(t: String, w: f32) -> String {
if render::text_width(&t) <= w {
return t;
}
let mut cut: String = t;
while !cut.is_empty() && render::text_width(&format!("{cut}…")) > w {
cut.pop();
}
format!("{cut}…")
}
fn argb(rgb: u32, a: u32) -> u32 {
(a << 24) | (rgb & 0xFFFFFF)
}
@@ -37,25 +46,52 @@ fn brackets(s: &mut Vec<Shape>, x: f32, y: f32, w: f32, h: f32, len: f32, color:
}
}
pub fn draw(sim: &Sim, index: usize) -> Vec<Shape> {
let mut s = Vec::new();
let Some(sam) = sim.sams.get(index) else { return s };
/// The camera's picture size, pixels.
const PICTURE: (u32, u32) = (320, 200);
/// Where system `sam`'s camera is and looks: at its target, zoomed so the
/// target fills a good part of the picture; else ahead and a little up.
pub fn camera(sim: &Sim, sam: &Sam) -> CameraView {
let eye = sam.pos + DVec3::Y * 3.5;
let (dir, fov) = match sim.watched(sam) {
Some(d) => {
let rel = d.pos - eye;
let dist = rel.length().max(1.0);
// About 14 blocks of view round a missile far off, wider when it is near.
let fov = (2.0 * (7.0 / dist).atan()).to_degrees().clamp(1.5, 50.0);
(rel / dist, fov as f32)
}
None => {
let h = sam.heading + (sim.tick as f64 * 0.004).sin() * 0.6;
(DVec3::new(-h.sin(), 0.25, -h.cos()).normalize(), 55.0)
}
};
// Minecraft's yaw: 0 looks to +z, 90 to -x; pitch 90 looks down.
let yaw = (-dir.x).atan2(dir.z).to_degrees() as f32;
let pitch = (-dir.y).asin().to_degrees() as f32;
CameraView { id: sam.id, x: eye.x, y: eye.y, z: eye.z, yaw, pitch, fov, width: PICTURE.0, height: PICTURE.1 }
}
/// One system's monitor in the box (x, y, w, h).
fn cell(sim: &Sim, index: usize, x: f32, y: f32, w: f32, h: f32, s: &mut Vec<Shape>) {
let Some(sam) = sim.sams.get(index) else { return };
let spec = sam.kind.spec();
let tick = sim.tick;
// Frame.
s.push(fill(X, Y, W, H, 0xC0080C0A));
s.push(fill(X, Y, W, 12.0, 0xE0142018));
s.push(fill(x, y, w, h, 0xC0080C0A));
s.push(fill(x, y, w, 12.0, 0xE0142018));
let state = sam.state;
let blink = matches!(state, SamState::Lock | SamState::Launch | SamState::Fire) && (tick / 4) % 2 == 0;
s.push(text(format!("{} №{}", spec.name, index + 1), X + 3.0, Y + 2.0, 0xFF9FE0FF));
let lock = matches!(state, SamState::Lock | SamState::Launch | SamState::Fire);
let blink = lock && (tick / 4) % 2 == 0;
let label = state.name();
let lx = X + W - 3.0 - label.chars().count() as f32 * 6.0;
s.push(text(label, lx, Y + 2.0, argb(state.color(), if blink { 0x80 } else { 0xFF })));
let lw = render::text_width(label);
s.push(text(fit(format!("№{} {}", index + 1, spec.name), w - lw - 12.0), x + 3.0, y + 2.0, 0xFF9FE0FF));
s.push(text(label, x + w - 3.0 - lw, y + 2.0, argb(state.color(), if blink { 0x80 } else { 0xFF })));
// The system's radar: round it, its reach at the edge, north up.
let (rx, ry, rr) = (X + 48.0, Y + 64.0, 44.0);
// The radar, at the left: round the system, north up.
let rr = ((h - 28.0) / 2.0).min(w * 0.2).max(10.0);
let (rx, ry) = (x + 4.0 + rr, y + 14.0 + (h - 26.0) / 2.0);
s.push(fill(rx - rr, ry - rr, rr * 2.0, rr * 2.0, 0x60103018));
let seg = 32;
let seg = if rr > 30.0 { 32 } else { 20 };
for k in [0.5f32, 1.0] {
for i in 0..seg {
let a0 = i as f32 / seg as f32 * std::f32::consts::TAU;
@@ -66,14 +102,14 @@ pub fn draw(sim: &Sim, index: usize) -> Vec<Shape> {
}
}
let reach = sam.kind.range();
let sweep = (tick as f32 * 0.12) % std::f32::consts::TAU;
for k in 0..8 {
let a1 = sweep - k as f32 * 0.07;
let a0 = a1 - 0.07;
let sweep = (tick as f32 * 0.12 + index as f32) % std::f32::consts::TAU;
for k in 0..6 {
let a1 = sweep - k as f32 * 0.09;
let a0 = a1 - 0.09;
let p = |a: f32| (rx + a.sin() * rr, ry - a.cos() * rr);
s.push(quad((rx, ry), p(a0), p(a1), p(a1), argb(0x40FF70, (0x70 - k * 8) as u32)));
s.push(quad((rx, ry), p(a0), p(a1), p(a1), argb(0x40FF70, (0x70 - k * 10) as u32)));
}
let target = sam.gun_target.or(sam.target).and_then(|t| sim.drones.iter().find(|d| d.id == t));
let target = sim.watched(sam);
let mut seen = 0;
for d in sim.drones.iter().filter(|d| d.alive()) {
let rel = d.pos - sam.pos;
@@ -83,7 +119,7 @@ pub fn draw(sim: &Sim, index: usize) -> Vec<Shape> {
}
seen += 1;
let k = (rr as f64 / (reach * 1.25)) as f32;
let (x, y) = (rx + rel.x as f32 * k, ry + rel.z as f32 * k);
let (bx, by) = (rx + rel.x as f32 * k, ry + rel.z as f32 * k);
let allowed = sam.roles & d.kind.spec().class.bit() != 0;
let color = if Some(d.id) == target.map(|t| t.id) {
0xFFFFE040
@@ -92,84 +128,104 @@ pub fn draw(sim: &Sim, index: usize) -> Vec<Shape> {
} else {
0xFF808080
};
s.push(fill(x - 1.5, y - 1.5, 3.0, 3.0, color));
s.push(fill(bx - 1.5, by - 1.5, 3.0, 3.0, color));
}
s.push(fill(rx - 1.5, ry - 1.5, 3.0, 3.0, 0xFF40A0FF));
s.push(text(format!("РЛС {} · {}", distance(reach), seen), X + 4.0, Y + H - 10.0, 0xFF80FF90));
s.push(text(fit(format!("РЛС {} · {}", distance(reach), seen), rr * 2.0 + 4.0), x + 4.0, y + h - 10.0, 0xFF80FF90));
// The camera: a thermal picture of the target, the lock box.
let (cx, cy, cw, ch) = (X + 98.0, Y + 16.0, W - 102.0, 92.0);
s.push(fill(cx, cy, cw, ch, 0xF0101410));
// Scan lines.
for i in 0..(ch as i32 / 4) {
let y = cy + i as f32 * 4.0 + ((tick % 4) as f32);
if y < cy + ch {
s.push(fill(cx, y, cw, 1.0, 0x18A0FFA0));
}
}
// The camera, at the right: the world as the system sees it, thermal.
let cx = rx + rr + 6.0;
let (cy, cw, ch) = (y + 15.0, x + w - 4.0 - cx, h - 28.0);
s.push(fill(cx - 1.0, cy - 1.0, cw + 2.0, ch + 2.0, 0xFF203020));
// Searching: colour by day, night vision at night; tracking: thermal.
let night = horizon_mod_sdk::game::get_clock().is_some_and(|c| (13000..23000).contains(&(c.day_time % 24000)));
let mode = match (target.is_some(), night) {
(true, _) => 1,
(false, true) => 2,
(false, false) => 0,
};
s.push(Shape::View(ViewShape { view: sam.id, rect: Rect { x: cx, y: cy, w: cw, h: ch }, mode }));
// Crosshair.
s.push(fill(cx + cw / 2.0 - 0.5, cy + 3.0, 1.0, ch * 0.18, 0x90FFFFFF));
s.push(fill(cx + cw / 2.0 - 0.5, cy + ch * 0.82 - 3.0, 1.0, ch * 0.18, 0x90FFFFFF));
s.push(fill(cx + 3.0, cy + ch / 2.0 - 0.5, cw * 0.18, 1.0, 0x90FFFFFF));
s.push(fill(cx + cw * 0.82 - 3.0, cy + ch / 2.0 - 0.5, cw * 0.18, 1.0, 0x90FFFFFF));
match target {
Some(t) => {
let size = 3.0;
let ix = cx + cw / 2.0 - 8.0 * size;
let iy = cy + ch / 2.0 - 8.0 * size;
// Track wobble: the picture jitters while the turret is still slewing.
let jitter = if state == SamState::Slew { ((tick * 7) % 5) as f32 - 2.0 } else { 0.0 };
s.push(Shape::Item(ItemShape {
item: format!("airdef:cam_{}", t.kind.spec().key),
at: Point { x: ix + jitter, y: iy - jitter * 0.5 },
scale: size,
}));
// A warm tint over the image, as a thermal camera's.
s.push(fill(cx, cy, cw, ch, 0x2840FF40));
let lock = matches!(state, SamState::Lock | SamState::Launch | SamState::Fire);
let color = if lock { if blink { 0xFFFF3030 } else { 0xFFFF8080 } } else { 0xFFFFE060 };
let (bw, bh) = (54.0, 40.0);
brackets(&mut s, cx + cw / 2.0 - bw / 2.0, cy + ch / 2.0 - bh / 2.0, bw, bh, 7.0, color);
s.push(fill(cx + cw / 2.0 - 0.5, cy + 4.0, 1.0, 10.0, 0x80FFFFFF));
s.push(fill(cx + cw / 2.0 - 0.5, cy + ch - 14.0, 1.0, 10.0, 0x80FFFFFF));
let (bw, bh) = (cw * 0.3, ch * 0.34);
brackets(s, cx + cw / 2.0 - bw / 2.0, cy + ch / 2.0 - bh / 2.0, bw, bh, 6.0, color);
if lock {
s.push(text("ЗАХВАТ", cx + cw / 2.0 - 18.0, cy + 3.0, color));
}
if !t.alive() {
s.push(text("ПОРАЖЕНА", cx + cw / 2.0 - 24.0, cy + ch / 2.0 + bh / 2.0 + 2.0, 0xFF60FF60));
}
let rel = t.pos - sam.pos;
let bearing = (heading_of(rel).to_degrees() + 180.0).rem_euclid(360.0);
s.push(text(t.kind.spec().name, cx + 3.0, cy + ch - 20.0, 0xFFFFFFFF));
s.push(text(
format!(
"{} в{:.0} {:.0}км/ч П{:03.0}",
distance(rel.length()),
t.pos.y - sam.pos.y,
t.vel.length() * 72.0,
bearing
),
cx + 3.0,
cy + ch - 10.0,
0xFFC0FFC0,
));
}
None => {
let noise = (tick * 2654435761) % 997;
for i in 0..14 {
let x = cx + ((noise as f32 * (i + 3) as f32 * 13.7) % cw);
let y = cy + ((noise as f32 * (i + 7) as f32 * 7.3) % ch);
s.push(fill(x, y, 2.0, 1.0, 0x50FFFFFF));
if ch > 50.0 {
s.push(text(fit(t.kind.spec().name.into(), cw - 6.0), cx + 3.0, cy + ch - 20.0, 0xFFFFFFFF));
}
s.push(text("НЕТ ЦЕЛИ", cx + cw / 2.0 - 24.0, cy + ch / 2.0 - 4.0, 0xFF80FF90));
let mut info = format!("{} в{:.0} {:.0}км/ч", distance(rel.length()), t.pos.y - sam.pos.y, t.vel.length() * 72.0);
if cw > 220.0 {
info += &format!(" П{bearing:03.0}");
}
s.push(text(fit(info, cw - 6.0), cx + 3.0, cy + ch - 10.0, 0xFFC0FFC0));
}
None => s.push(text("ПОИСК", cx + 3.0, cy + ch - 10.0, 0xFF80FF90)),
}
// What it carries and does.
let mut line = String::new();
if spec_missiles(sam) {
line += &format!("ракеты {} ", sam.missiles);
if !matches!(sam.kind, crate::sim::SamKind::Gepard) {
line += &format!("Р{} ", sam.missiles);
}
if sam.bursts > 0 || sam.kind.spec().key == "gepard" {
line += &format!("снар. {} ", sam.bursts);
if sam.bursts > 0 || spec.key == "gepard" {
line += &format!("С{} ", sam.bursts);
}
line += &format!("сбил {} · [{}]", sam.kills, roles_text(sam.roles));
s.push(text(line, cx, Y + H - 10.0, 0xFF9FE0FF));
line += &format!("сб.{} [{}]", sam.kills, roles_text(sam.roles));
s.push(text(fit(line, cw), cx, y + h - 10.0, 0xFF9FE0FF));
}
/// One system, top left.
pub fn draw(sim: &Sim, index: usize) -> Vec<Shape> {
let mut s = Vec::new();
cell(sim, index, 4.0, 4.0, 300.0, 150.0, &mut s);
s
}
fn spec_missiles(sam: &crate::sim::Sam) -> bool {
!matches!(sam.kind, crate::sim::SamKind::Gepard)
/// Every system in a grid over the screen.
pub fn grid(sim: &Sim, (gw, gh): (f32, f32)) -> Vec<Shape> {
let mut s = Vec::new();
let n = sim.sams.len().min(8);
s.push(fill(0.0, 0.0, gw, gh, 0xE0050806));
s.push(text(
fit(
format!("КОМАНДНЫЙ ПУНКТ ПВО · комплексов {n} · целей {} · сбито {} · J закрыть", sim.drones.iter().filter(|d| d.alive()).count(), sim.kills),
gw - 16.0,
),
8.0,
6.0,
0xFF9FE0FF,
));
if n == 0 {
s.push(text("Нет комплексов: поставьте их пультами развёртывания", 8.0, 24.0, 0xFFFFC060));
return s;
}
let cols = match n {
1 => 1,
2..=4 => 2,
_ => 3,
};
let rows = n.div_ceil(cols);
let (top, gap) = (18.0, 4.0);
let cw = (gw - gap * (cols as f32 + 1.0)) / cols as f32;
let ch = ((gh - top - gap * rows as f32) / rows as f32).min(cw * 0.62);
for i in 0..n {
let (c, r) = (i % cols, i / cols);
let x = gap + c as f32 * (cw + gap);
let y = top + r as f32 * (ch + gap);
cell(sim, i, x, y, cw, ch, &mut s);
}
s
}
+153 -15
View File
@@ -284,6 +284,11 @@ pub enum DroneKind {
Zircon,
Iskander,
Kinzhal,
/// An IRBM: its bus releases six blocks high over the target.
Oreshnik,
/// One of the Oreshnik's blocks: it splits into six glowing submunitions.
OreshnikBlock,
OreshnikSub,
}
/// What a drone carries on its tail.
@@ -325,7 +330,7 @@ pub struct DroneSpec {
}
impl DroneKind {
pub const ALL: [DroneKind; 10] = [
pub const ALL: [DroneKind; 13] = [
DroneKind::Shahed,
DroneKind::Geran3,
DroneKind::Lancet,
@@ -336,6 +341,9 @@ impl DroneKind {
DroneKind::Zircon,
DroneKind::Iskander,
DroneKind::Kinzhal,
DroneKind::Oreshnik,
DroneKind::OreshnikBlock,
DroneKind::OreshnikSub,
];
pub fn spec(self) -> &'static DroneSpec {
match self {
@@ -519,6 +527,60 @@ impl DroneKind {
class: Class::Ballistic,
ballistic: Some(1500.0),
},
DroneKind::Oreshnik => &DroneSpec {
name: "Орешник",
key: "oreshnik",
model: "airdef:iskander",
speed: 9.0,
turn: 0.0,
cruise: 0.0,
clearance: 0.0,
dive: 0.0,
warhead: 0,
scale: 2.6,
engine: Engine::Rocket(1.5, 2.4),
decoy: false,
stealth: 3.0,
sound: ("airdef:drone.rocket", 0.5, 46),
class: Class::Ballistic,
ballistic: Some(2600.0),
},
DroneKind::OreshnikBlock => &DroneSpec {
name: "Орешник: блок",
key: "oreshnik_block",
model: "airdef:reentry",
speed: 9.0,
turn: 0.0,
cruise: 0.0,
clearance: 0.0,
dive: 0.0,
warhead: 4,
scale: 1.6,
engine: Engine::Rocket(1.0, 1.0),
decoy: false,
stealth: 3.5,
sound: ("airdef:drone.ballistic", 0.8, 9999),
class: Class::Ballistic,
ballistic: None,
},
DroneKind::OreshnikSub => &DroneSpec {
name: "Орешник: суббоеприпас",
key: "oreshnik_sub",
model: "airdef:reentry",
speed: 9.0,
turn: 0.05,
cruise: 0.0,
clearance: 0.0,
dive: 0.0,
warhead: 3,
scale: 1.1,
engine: Engine::Rocket(1.0, 1.0),
decoy: false,
stealth: 4.0,
sound: ("airdef:drone.ballistic", 1.0, 9999),
class: Class::Ballistic,
ballistic: None,
},
}
}
pub fn from_key(key: &str) -> Option<Self> {
@@ -526,6 +588,9 @@ impl DroneKind {
}
}
/// Height over the target where the Oreshnik's blocks release their submunitions.
const BLOCK_SPLIT: f64 = 300.0;
#[derive(PartialEq)]
enum Flight {
Cruise,
@@ -1013,6 +1078,16 @@ impl Sim {
self.next * PARTS
}
/// 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> {
let id = sam
.gun_target
.or(sam.target)
.or_else(|| self.missiles.iter().find(|m| m.sam == sam.id).map(|m| m.target))?;
self.drones.iter().find(|d| d.id == id)
}
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)))
}
@@ -1096,6 +1171,8 @@ impl Sim {
let now = self.tick;
let mut boom: Vec<(DVec3, u32, bool)> = Vec::new();
let mut removed: Vec<u32> = Vec::new();
// Oreshnik pieces released this tick: kind, at, velocity, target.
let mut released: Vec<(DroneKind, DVec3, DVec3, DVec3)> = Vec::new();
for d in &mut self.drones {
d.age += 1;
let spec = d.kind.spec();
@@ -1120,7 +1197,13 @@ impl Sim {
if d.flight == Flight::Ballistic {
// The motor burns for 3 s; then the arc, and the warhead steers in at the end.
let burning = d.age < 60;
d.vel.y -= GRAVITY;
match d.kind {
// A block glides to its point high over the target; its submunitions fall from there
// nearly straight down, braked by the air: a rain of fire for seconds.
DroneKind::OreshnikBlock => d.vel = (d.target + DVec3::Y * BLOCK_SPLIT - d.pos).normalize_or(DVec3::NEG_Y) * 6.5,
DroneKind::OreshnikSub => d.vel = (d.target - d.pos).normalize_or(DVec3::NEG_Y) * 3.2,
_ => d.vel.y -= GRAVITY,
}
if d.vel.y < 0.0 && d.pos.distance(d.target) < 260.0 {
let sp = d.vel.length();
d.vel = turn(d.vel, d.target - d.pos, spec.turn) * sp;
@@ -1129,6 +1212,7 @@ impl Sim {
let speed = d.vel.length();
let hit = d.pos.distance(d.target) < speed.max(2.0)
|| below.is_some_and(|g| d.pos.y <= g + 0.2)
|| (d.vel.y < 0.0 && d.pos.y < d.target.y - 1.0)
|| d.age > 4000;
if hit {
boom.push((d.pos, spec.warhead, false));
@@ -1136,8 +1220,39 @@ impl Sim {
self.hits += 1;
continue;
}
// The bus releases its six blocks over the target, each block its six submunitions lower down.
let split = match d.kind {
DroneKind::Oreshnik => (d.vel.y < 0.0 && horizontal(d.target - d.pos).length() < 900.0)
.then_some((DroneKind::OreshnikBlock, 45.0)),
DroneKind::OreshnikBlock => (d.pos.distance(d.target + DVec3::Y * BLOCK_SPLIT) < 8.0)
.then_some((DroneKind::OreshnikSub, 9.0)),
_ => None,
};
if let Some((piece, spread)) = split {
let turn0 = self.rng.f() * TAU;
for i in 0..6 {
let a = turn0 + i as f64 * TAU / 6.0;
let r = spread * (0.6 + 0.4 * self.rng.f());
let aim = d.target + DVec3::new(a.sin() * r, 0.0, a.cos() * r);
// Straight down at the aim point, at the bus's speed.
let v = (aim - d.pos).normalize_or(DVec3::NEG_Y) * 3.0;
released.push((piece, d.pos + v.normalize_or_zero() * (i as f64 * 0.3), v, aim));
}
out.sound("airdef:boom.sonic", d.pos, 1.0, 0.7);
// Its pieces count as launched instead of it.
self.launched += 5;
out.particles("minecraft:firework", d.pos, 1.5, DVec3::ZERO, 0.3, 40);
if d.kind == DroneKind::OreshnikBlock && self.rng.chance(0.5) {
out.sound("airdef:drone.ballistic", d.pos, 1.0, 1.1);
}
removed.push(d.id);
continue;
}
let dir = d.vel.normalize_or_zero();
if burning {
if d.kind == DroneKind::OreshnikSub || d.kind == DroneKind::OreshnikBlock {
out.particles("minecraft:flame", d.pos - dir * 1.5, 0.1, DVec3::ZERO, 0.0, 1);
out.particles("minecraft:white_smoke", d.pos - dir * 3.0, 0.15, DVec3::ZERO, 0.0, 1);
} else if burning {
out.particles("minecraft:flame", d.pos - dir * 2.5 * spec.scale, 0.15, -dir * 0.2, 0.02, 3);
out.particles("minecraft:cloud", d.pos - dir * 3.5 * spec.scale, 0.4, DVec3::ZERO, 0.01, 3);
} else if d.vel.y < -2.0 {
@@ -1213,6 +1328,10 @@ impl Sim {
self.explode(pos, warhead, small, ground, player, out);
}
self.drones.retain(|d| !removed.contains(&d.id));
for (kind, pos, vel, target) in released {
let id = self.id();
self.drones.push(Drone { id, kind, pos, vel, target, flight: Flight::Ballistic, roll: 0.0, spin: 1.0, age: 60, engaged: 0 });
}
for d in &self.drones {
let spec = d.kind.spec();
let s = spec.scale;
@@ -1220,7 +1339,9 @@ impl Sim {
if d.flight == Flight::Falling {
rot = rot * DQuat::from_rotation_z(d.spin) * DQuat::from_rotation_x(-0.6);
}
out.model(d.id, spec.model, d.pos, rot, s, false);
if !matches!(d.kind, DroneKind::OreshnikBlock | DroneKind::OreshnikSub) || !d.alive() {
out.model(d.id, spec.model, d.pos, rot, s, false);
}
if !d.alive() {
continue;
}
@@ -1236,10 +1357,18 @@ impl Sim {
out.model(d.id + 1, "airdef:geran3_flame", at, rot, s * size * flicker, true);
}
Engine::Rocket(back, size) => {
// Ballistic missiles fly far and high: their glow keeps a size on screen, so they are seen
// all the way (the motor while it burns, then the hot body).
let far = player.map_or(1.0, |p| (d.pos.distance(p) / 140.0).max(1.0));
let flicker = 0.8 + 0.2 * self.rng.f();
if d.flight != Flight::Ballistic || d.age < 60 {
let flicker = 0.8 + 0.2 * self.rng.f();
let size = if d.flight == Flight::Ballistic { size * far.sqrt() } else { size };
let at = d.pos + rot * DVec3::new(0.0, 0.0, back * s + size * flicker);
out.model(d.id + 1, "airdef:flame", at, rot, size * flicker, true);
} else if !matches!(d.kind, DroneKind::OreshnikBlock | DroneKind::OreshnikSub) {
out.model(d.id + 1, "airdef:reentry", d.pos, rot, s * 0.6 * far.sqrt() * flicker, true);
} else {
out.model(d.id + 1, "airdef:reentry", d.pos, rot, s * far.sqrt().min(4.0) * flicker, true);
}
}
}
@@ -1250,14 +1379,17 @@ impl Sim {
/// `damage`) primed TNT for the land.
fn explode(&mut self, pos: DVec3, tnt: u32, small: bool, ground: &mut Ground, player: Option<DVec3>, out: &mut Out) {
let big = tnt >= 3;
let size = match tnt {
0 => 2.5,
1 | 2 => 4.5,
3..=4 => 7.0,
_ => 9.0,
// Power: 0 air burst, 1 small, 2 drone, 3 cruise missile, 4 ballistic.
let power = match tnt {
0 => 0,
1 | 2 => 1,
3..=5 => 2,
6 | 7 => 3,
_ => 4,
};
self.fireball(pos, size, if big { 18 } else { 11 });
out.particles("minecraft:explosion_emitter", pos, 0.5, DVec3::ZERO, 0.0, if big { 3 } else { 1 });
let size = [2.5, 4.5, 7.0, 10.0, 13.0][power];
self.fireball(pos, size, [11, 11, 18, 22, 26][power]);
out.particles("minecraft:explosion_emitter", pos, 0.5 + power as f32, DVec3::ZERO, 0.0, [1, 1, 3, 5, 8][power]);
// The shader draws the fireball and smoke; particles add sparks and debris.
let n = if self.shader { 12 } else { 40 };
out.particles("minecraft:large_smoke", pos, size as f32 * 0.4, DVec3::new(0.0, 0.1, 0.0), 0.08, n);
@@ -1265,13 +1397,19 @@ impl Sim {
out.particles("minecraft:lava", pos, 1.0, DVec3::ZERO, 0.0, 16);
out.particles("minecraft:campfire_signal_smoke", pos, 1.2, DVec3::new(0.0, 0.04, 0.0), 0.01, if big { 30 } else { 10 });
let pitch = 0.9 + self.rng.f() as f32 * 0.2;
let event = if big { "airdef:blast.big" } else if tnt > 0 { "airdef:blast.medium" } else { "airdef:blast.air" };
let event = ["airdef:blast.air", "airdef:blast.medium", "airdef:blast.big", "airdef:blast.heavy", "airdef:blast.huge"][power];
out.sound(event, pos, 1.0, if small { pitch * 1.15 } else { pitch });
if power >= 3 {
// A heavy warhead throws a column of dirt and a ring of dust.
out.particles("minecraft:campfire_cosy_smoke", pos, size as f32 * 0.5, DVec3::new(0.0, 0.15, 0.0), 0.05, 20 * power as u32);
out.particles("minecraft:explosion", pos, size as f32 * 0.6, DVec3::ZERO, 0.0, 10 * power as u32);
}
if let Some(p) = player {
let d = p.distance(pos);
let reach = if big { 100.0 } else { 45.0 };
let reach = [45.0, 45.0, 100.0, 160.0, 240.0][power];
if d < reach {
out.jolt((1.0 - d / reach) as f32 * if big { 0.9 } else { 0.4 }, if big { 1.6 } else { 0.8 });
let strength = [0.4, 0.4, 0.9, 1.3, 1.8][power];
out.jolt((1.0 - d / reach) as f32 * strength, [0.8, 0.8, 1.6, 2.2, 3.0][power]);
}
}
if self.damage && tnt > 0 {