67a2a523b4
build / mod (push) Successful in 2m26s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
718 lines
26 KiB
Rust
718 lines
26 KiB
Rust
//! Every unit the player deploys, as data: the air-defence systems (their
|
||
//! weapons, radar and how their vehicles are put together and drawn) and the
|
||
//! units that serve them — long-range radars, ammunition depots, reload
|
||
//! trucks, EW stations and searchlights. They share a position, health,
|
||
//! wrecks, saving and move orders; only what they carry differs.
|
||
use super::*;
|
||
|
||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
||
pub enum SamKind {
|
||
Patriot,
|
||
Gepard,
|
||
Pantsir,
|
||
S400,
|
||
S500,
|
||
IrisT,
|
||
Nasams,
|
||
Buk,
|
||
Tor,
|
||
P1sun,
|
||
/// A long-range search radar: no weapons, it feeds the network.
|
||
Radar,
|
||
/// An ammunition depot: the reload trucks fill up there.
|
||
Depot,
|
||
/// A transport-loader: drives missiles from a depot to the systems.
|
||
Tzm,
|
||
/// An electronic-warfare station: jams the drones' navigation while switched on.
|
||
Ew,
|
||
/// A searchlight: lights up targets at night for the guns.
|
||
Light,
|
||
}
|
||
|
||
/// How a vehicle is put together: how its launcher or turret moves and is drawn.
|
||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||
pub enum Family {
|
||
/// A launcher on a trailer that trains on the target (Patriot, NASAMS, P1-SUN).
|
||
Trainable,
|
||
/// A gun turret with a radar dish (Gepard).
|
||
Gun,
|
||
/// A turret with an elevating pack (Pantsir, Buk).
|
||
Turret,
|
||
/// Vertical launch from a raised pack (S-400, S-500, IRIS-T) or a turning turret (Tor).
|
||
Vertical,
|
||
/// Nothing that aims: a radar, a depot, an EW station.
|
||
Static,
|
||
/// A truck (the transport-loader).
|
||
Truck,
|
||
/// A searchlight.
|
||
Light,
|
||
}
|
||
|
||
/// Where missile `n` leaves the launcher, as the launcher's model lays its tubes out.
|
||
#[derive(Clone, Copy)]
|
||
pub enum Muzzle {
|
||
None,
|
||
Patriot,
|
||
Pantsir,
|
||
/// `cols × rows` tubes `size` model units wide, from the pack's pivot to its far end.
|
||
Grid(u32, u32, f64),
|
||
/// Missiles on rails, at these x (model units).
|
||
Rails(&'static [f64]),
|
||
/// The Tor's eight vertical cells on top of its turret.
|
||
Cells,
|
||
}
|
||
|
||
/// The models a unit is drawn with.
|
||
pub struct Parts {
|
||
/// The chassis, trailer or base.
|
||
pub body: &'static str,
|
||
/// The launcher, the tubes or the turret.
|
||
pub launcher: Option<&'static str>,
|
||
/// A turret's elevating pack or guns.
|
||
pub pack: Option<&'static str>,
|
||
/// A dish on the turret: model, height and forward offset (× scale), tilt.
|
||
pub dish: Option<(&'static str, f64, f64, f64)>,
|
||
/// Other fixed models: model, height, backward offset (× scale).
|
||
pub fixed: &'static [(&'static str, f64, f64)],
|
||
/// A turning antenna: model, height, backward offset, size, tilt.
|
||
pub spinner: Option<(&'static str, f64, f64, f64, f64)>,
|
||
}
|
||
|
||
pub(super) struct MissileLoad {
|
||
pub kind: MissileKind,
|
||
pub magazine: u32,
|
||
pub min: f64,
|
||
pub max: f64,
|
||
/// Ticks between launches.
|
||
pub interval: u32,
|
||
}
|
||
|
||
pub(super) struct GunSpec {
|
||
pub range: f64,
|
||
/// Starts tracking from here.
|
||
pub track: f64,
|
||
/// Chance per burst at point blank.
|
||
pub p: f64,
|
||
pub bursts: u32,
|
||
/// Shell speed for the lead, blocks a tick.
|
||
pub shell: f64,
|
||
pub slew: (f64, f64),
|
||
}
|
||
|
||
/// How fast a weapon's mount turns: per axis the top speed (radians a tick) and the acceleration, which
|
||
/// is also the braking (radians a tick²). Game settings, not the real machines' figures.
|
||
#[derive(Clone, Copy)]
|
||
pub(super) struct Drive {
|
||
pub yaw: (f64, f64),
|
||
pub pitch: (f64, f64),
|
||
}
|
||
|
||
/// The drives are this share of the speeds they had before they had a speed of their own.
|
||
const DRIVE_SCALE: f64 = 0.4;
|
||
/// Ticks a drive takes to reach its top speed (and to stop from it).
|
||
const DRIVE_RAMP: f64 = 8.0;
|
||
|
||
pub struct SamSpec {
|
||
pub name: &'static str,
|
||
pub key: &'static str,
|
||
pub(super) missile: Option<MissileLoad>,
|
||
pub(super) gun: Option<GunSpec>,
|
||
pub(super) reload: u32,
|
||
pub(super) scale: f64,
|
||
/// Where it points its launcher at rest (pitch, radians).
|
||
pub(super) rest_pitch: f64,
|
||
/// Which classes of target it engages unless told otherwise.
|
||
pub roles: u8,
|
||
pub family: Family,
|
||
pub parts: Parts,
|
||
/// The launcher's or turret's centre over the vehicle's centre: up and forward, × scale.
|
||
pub(super) mount: (f64, f64),
|
||
/// The launcher model's pivot from its centre (blocks).
|
||
pub(super) pivot: DVec3,
|
||
pub(super) muzzle: Muzzle,
|
||
/// Its own search radar's reach (0: none, it fires on the network's tracks), and the antenna's height.
|
||
pub sensor: f64,
|
||
pub mast: f64,
|
||
}
|
||
|
||
impl SamSpec {
|
||
/// The mount's drive: the guns' own slew rates, the old rates of the launchers, scaled down.
|
||
pub(super) fn drive(&self) -> Drive {
|
||
let (yaw, pitch) = match (&self.gun, self.family) {
|
||
(Some(g), _) => g.slew,
|
||
(None, Family::Trainable) => (0.12, 0.0),
|
||
(None, Family::Vertical) => (0.15, 0.0),
|
||
(None, _) => (0.05, 0.05),
|
||
};
|
||
let axis = |speed: f64| (speed * DRIVE_SCALE, speed * DRIVE_SCALE / DRIVE_RAMP);
|
||
Drive { yaw: axis(yaw), pitch: axis(pitch) }
|
||
}
|
||
}
|
||
|
||
const NO_PARTS: Parts = Parts { body: "", launcher: None, pack: None, dish: None, fixed: &[], spinner: None };
|
||
/// The battery radar trailer behind a vertical launcher.
|
||
const BATTERY_RADAR: &[(&str, f64, f64)] = &[("airdef:radar_trailer", 0.0, 4.2)];
|
||
const BATTERY_SPINNER: Option<(&str, f64, f64, f64, f64)> = Some(("airdef:radar_panel", 0.9, 4.2, 0.9, -0.3));
|
||
const TUBE_PIVOT: DVec3 = DVec3::new(0.0, -0.5, 1.5);
|
||
|
||
impl SamKind {
|
||
pub const ALL: [SamKind; 15] = [
|
||
SamKind::Patriot,
|
||
SamKind::Gepard,
|
||
SamKind::Pantsir,
|
||
SamKind::S400,
|
||
SamKind::S500,
|
||
SamKind::IrisT,
|
||
SamKind::Nasams,
|
||
SamKind::Buk,
|
||
SamKind::Tor,
|
||
SamKind::P1sun,
|
||
SamKind::Radar,
|
||
SamKind::Depot,
|
||
SamKind::Tzm,
|
||
SamKind::Ew,
|
||
SamKind::Light,
|
||
];
|
||
/// The ones that shoot (the roles menu lists these).
|
||
pub const ARMED: [SamKind; 10] = [
|
||
SamKind::Patriot,
|
||
SamKind::Gepard,
|
||
SamKind::Pantsir,
|
||
SamKind::S400,
|
||
SamKind::S500,
|
||
SamKind::IrisT,
|
||
SamKind::Nasams,
|
||
SamKind::Buk,
|
||
SamKind::Tor,
|
||
SamKind::P1sun,
|
||
];
|
||
pub fn spec(self) -> &'static SamSpec {
|
||
match self {
|
||
SamKind::Patriot => {
|
||
const S: SamSpec = 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,
|
||
family: Family::Trainable,
|
||
parts: Parts {
|
||
body: "airdef:patriot_trailer",
|
||
launcher: Some("airdef:patriot_launcher"),
|
||
fixed: &[("airdef:patriot_truck", 0.0, -3.0), ("airdef:patriot_radar", 0.0, 3.6)],
|
||
..NO_PARTS
|
||
},
|
||
mount: (0.69, 1.2),
|
||
pivot: DVec3::new(0.0, -0.5, 1.375),
|
||
muzzle: Muzzle::Patriot,
|
||
sensor: 390.0,
|
||
mast: 5.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Gepard => {
|
||
const S: SamSpec = 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,
|
||
family: Family::Gun,
|
||
parts: Parts {
|
||
body: "airdef:gepard_hull",
|
||
launcher: Some("airdef:gepard_turret"),
|
||
pack: Some("airdef:gepard_guns"),
|
||
dish: Some(("airdef:gepard_dish", 0.95, 0.6, 0.0)),
|
||
..NO_PARTS
|
||
},
|
||
mount: (1.55, 0.25),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::None,
|
||
sensor: 170.0,
|
||
mast: 3.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Pantsir => {
|
||
const S: SamSpec = 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,
|
||
family: Family::Turret,
|
||
parts: Parts {
|
||
body: "airdef:pantsir_truck",
|
||
launcher: Some("airdef:pantsir_turret"),
|
||
pack: Some("airdef:pantsir_pack"),
|
||
dish: Some(("airdef:pantsir_dish", 0.85, 0.3, 0.3)),
|
||
..NO_PARTS
|
||
},
|
||
mount: (1.35, 0.69),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::Pantsir,
|
||
sensor: 195.0,
|
||
mast: 4.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::S400 => {
|
||
const S: SamSpec = 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,
|
||
family: Family::Vertical,
|
||
parts: Parts {
|
||
body: "airdef:s400_chassis",
|
||
launcher: Some("airdef:s400_tubes"),
|
||
fixed: BATTERY_RADAR,
|
||
spinner: BATTERY_SPINNER,
|
||
..NO_PARTS
|
||
},
|
||
mount: (0.7, 1.45),
|
||
pivot: TUBE_PIVOT,
|
||
muzzle: Muzzle::Grid(2, 2, 7.0),
|
||
sensor: 624.0,
|
||
mast: 5.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::S500 => {
|
||
const S: SamSpec = 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,
|
||
family: Family::Vertical,
|
||
parts: Parts {
|
||
body: "airdef:s500_chassis",
|
||
launcher: Some("airdef:s500_tubes"),
|
||
fixed: BATTERY_RADAR,
|
||
spinner: BATTERY_SPINNER,
|
||
..NO_PARTS
|
||
},
|
||
mount: (0.7, 1.45),
|
||
pivot: TUBE_PIVOT,
|
||
muzzle: Muzzle::Grid(2, 1, 9.5),
|
||
sensor: 910.0,
|
||
mast: 5.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::IrisT => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "IRIS-T SLM",
|
||
key: "irist",
|
||
missile: Some(MissileLoad { kind: MissileKind::IrisT, magazine: 8, min: 15.0, max: 400.0, interval: 10 }),
|
||
gun: None,
|
||
reload: 300,
|
||
scale: 1.4,
|
||
rest_pitch: HALF_PI - 0.02,
|
||
roles: 15,
|
||
family: Family::Vertical,
|
||
parts: Parts {
|
||
body: "airdef:irist_chassis",
|
||
launcher: Some("airdef:irist_tubes"),
|
||
fixed: BATTERY_RADAR,
|
||
spinner: BATTERY_SPINNER,
|
||
..NO_PARTS
|
||
},
|
||
mount: (0.7, 1.45),
|
||
pivot: TUBE_PIVOT,
|
||
muzzle: Muzzle::Grid(4, 2, 4.0),
|
||
sensor: 520.0,
|
||
mast: 5.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Nasams => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "NASAMS",
|
||
key: "nasams",
|
||
missile: Some(MissileLoad { kind: MissileKind::Amraam, magazine: 6, min: 10.0, max: 300.0, interval: 14 }),
|
||
gun: None,
|
||
reload: 260,
|
||
scale: 1.3,
|
||
rest_pitch: 0.5,
|
||
roles: 14,
|
||
family: Family::Trainable,
|
||
parts: Parts {
|
||
body: "airdef:nasams_trailer",
|
||
launcher: Some("airdef:nasams_launcher"),
|
||
fixed: &[("airdef:radar_trailer", 0.0, 3.4)],
|
||
spinner: Some(("airdef:radar_panel", 0.9, 3.4, 0.6, -0.3)),
|
||
..NO_PARTS
|
||
},
|
||
mount: (0.62, 0.4),
|
||
pivot: TUBE_PIVOT,
|
||
muzzle: Muzzle::Grid(3, 2, 4.0),
|
||
sensor: 390.0,
|
||
mast: 5.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Buk => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "Бук-М2",
|
||
key: "buk",
|
||
missile: Some(MissileLoad { kind: MissileKind::M9m317, magazine: 4, min: 20.0, max: 450.0, interval: 18 }),
|
||
gun: None,
|
||
reload: 400,
|
||
scale: 1.4,
|
||
rest_pitch: 0.0,
|
||
roles: 14,
|
||
family: Family::Turret,
|
||
parts: Parts {
|
||
body: "airdef:buk_chassis",
|
||
launcher: Some("airdef:buk_turret"),
|
||
pack: Some("airdef:buk_rails"),
|
||
..NO_PARTS
|
||
},
|
||
mount: (1.55, 0.2),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::Rails(&[-9.0, -3.0, 13.0, 19.0]),
|
||
sensor: 585.0,
|
||
mast: 4.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Tor => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "Тор-М2",
|
||
key: "tor",
|
||
missile: Some(MissileLoad { kind: MissileKind::M9m338, magazine: 8, min: 8.0, max: 160.0, interval: 8 }),
|
||
gun: None,
|
||
reload: 300,
|
||
scale: 1.3,
|
||
rest_pitch: 0.0,
|
||
roles: 15,
|
||
family: Family::Vertical,
|
||
parts: Parts { body: "airdef:tor_chassis", launcher: Some("airdef:tor_turret"), ..NO_PARTS },
|
||
mount: (1.5, 0.0),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::Cells,
|
||
sensor: 210.0,
|
||
mast: 3.5,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::P1sun => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "P1-SUN",
|
||
key: "p1sun",
|
||
missile: Some(MissileLoad { kind: MissileKind::P1sun, magazine: 8, min: 5.0, max: 450.0, interval: 12 }),
|
||
gun: None,
|
||
reload: 240,
|
||
scale: 1.1,
|
||
rest_pitch: 0.35,
|
||
roles: 1,
|
||
family: Family::Trainable,
|
||
parts: Parts { body: "airdef:nasams_trailer", launcher: Some("airdef:p1sun_launcher"), ..NO_PARTS },
|
||
mount: (0.6, 0.3),
|
||
pivot: TUBE_PIVOT,
|
||
muzzle: Muzzle::Grid(4, 2, 3.0),
|
||
// No radar of its own: it fires on the network's tracks.
|
||
sensor: 0.0,
|
||
mast: 2.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Radar => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "РЛС дальнего обнаружения",
|
||
key: "radar",
|
||
missile: None,
|
||
gun: None,
|
||
reload: 0,
|
||
scale: 1.5,
|
||
rest_pitch: 0.0,
|
||
roles: 0,
|
||
family: Family::Static,
|
||
parts: Parts {
|
||
body: "airdef:radar_truck",
|
||
spinner: Some(("airdef:radar_panel", 1.2, 1.2, 1.5, -0.25)),
|
||
..NO_PARTS
|
||
},
|
||
mount: (0.0, 0.0),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::None,
|
||
sensor: 1700.0,
|
||
mast: 16.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Depot => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "Склад боеприпасов",
|
||
key: "depot",
|
||
missile: None,
|
||
gun: None,
|
||
reload: 0,
|
||
scale: 1.5,
|
||
rest_pitch: 0.0,
|
||
roles: 0,
|
||
family: Family::Static,
|
||
parts: Parts { body: "airdef:depot", ..NO_PARTS },
|
||
mount: (0.0, 0.0),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::None,
|
||
sensor: 0.0,
|
||
mast: 1.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Tzm => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "ТЗМ",
|
||
key: "tzm",
|
||
missile: None,
|
||
gun: None,
|
||
reload: 0,
|
||
scale: 1.3,
|
||
rest_pitch: 0.0,
|
||
roles: 0,
|
||
family: Family::Truck,
|
||
parts: Parts { body: "airdef:tzm_truck", ..NO_PARTS },
|
||
mount: (0.0, 0.0),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::None,
|
||
sensor: 0.0,
|
||
mast: 2.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Ew => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "Станция РЭБ",
|
||
key: "ew",
|
||
missile: None,
|
||
gun: None,
|
||
reload: 0,
|
||
scale: 1.3,
|
||
rest_pitch: 0.0,
|
||
roles: 0,
|
||
family: Family::Static,
|
||
parts: Parts { body: "airdef:ew_truck", ..NO_PARTS },
|
||
mount: (0.0, 0.0),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::None,
|
||
sensor: 0.0,
|
||
mast: 3.0,
|
||
};
|
||
&S
|
||
}
|
||
SamKind::Light => {
|
||
const S: SamSpec = SamSpec {
|
||
name: "Прожектор",
|
||
key: "light",
|
||
missile: None,
|
||
gun: None,
|
||
reload: 0,
|
||
scale: 1.2,
|
||
rest_pitch: 0.6,
|
||
roles: 0,
|
||
family: Family::Light,
|
||
parts: Parts { body: "airdef:searchlight", launcher: Some("airdef:searchlight_head"), ..NO_PARTS },
|
||
mount: (0.85, 0.0),
|
||
pivot: DVec3::ZERO,
|
||
muzzle: Muzzle::None,
|
||
sensor: 0.0,
|
||
mast: 1.5,
|
||
};
|
||
&S
|
||
}
|
||
}
|
||
}
|
||
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)
|
||
}
|
||
/// How far it reaches: its missiles or guns; 0 for a unit with neither.
|
||
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))
|
||
}
|
||
pub fn armed(self) -> bool {
|
||
let s = self.spec();
|
||
s.missile.is_some() || s.gun.is_some()
|
||
}
|
||
}
|
||
|
||
impl Sam {
|
||
pub(super) fn base(&self) -> DQuat {
|
||
DQuat::from_rotation_y(self.heading)
|
||
}
|
||
pub(super) 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.
|
||
pub(super) fn mount(&self) -> (DVec3, DQuat) {
|
||
let spec = self.kind.spec();
|
||
let s = spec.scale;
|
||
let base = self.base();
|
||
let (up, fwd) = spec.mount;
|
||
let aim = DQuat::from_rotation_y(self.yaw) * DQuat::from_rotation_x(self.pitch);
|
||
match spec.family {
|
||
Family::Trainable => (self.pos + base * DVec3::new(0.0, up * s, fwd * s), aim),
|
||
Family::Gun | Family::Turret | Family::Light => {
|
||
(self.pos + DVec3::new(0.0, up * s, 0.0) + base * DVec3::new(0.0, 0.0, fwd * s), aim)
|
||
}
|
||
Family::Vertical if matches!(spec.muzzle, Muzzle::Cells) => {
|
||
(self.pos + DVec3::new(0.0, up * s, 0.0), DQuat::from_rotation_y(self.yaw))
|
||
}
|
||
Family::Vertical => (self.pos + base * DVec3::new(0.0, up * s, fwd * s), base * DQuat::from_rotation_x(self.pitch)),
|
||
Family::Static | Family::Truck => (self.pos + DVec3::Y * s, base),
|
||
}
|
||
}
|
||
/// Where missile `n` of the magazine leaves (world), and which way.
|
||
pub(super) fn muzzle(&self, n: u32) -> (DVec3, DVec3) {
|
||
let (at, rot) = self.mount();
|
||
let s = self.scale();
|
||
let local = match self.kind.spec().muzzle {
|
||
Muzzle::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,
|
||
),
|
||
Muzzle::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)
|
||
}
|
||
Muzzle::Grid(cols, rows, size) => {
|
||
// From the pivot (rear bottom of the pack) to the far end of tube n.
|
||
let (i, j) = (n % cols, (n / cols) % rows);
|
||
DVec3::new(
|
||
(i as f64 - (cols - 1) as f64 / 2.0) * (size + 1.0) / 16.0,
|
||
(j as f64 * (size + 1.0) + size / 2.0) / 16.0,
|
||
-3.0,
|
||
)
|
||
}
|
||
Muzzle::Rails(xs) => {
|
||
let x = xs[n as usize % xs.len()];
|
||
DVec3::new((x - 8.0) / 16.0, 0.1 - 2.5 / 16.0, -1.5)
|
||
}
|
||
Muzzle::Cells => {
|
||
let (i, j) = (n % 4, (n / 4) % 2);
|
||
DVec3::new((i as f64 * 5.0 + 1.0 - 8.0) / 16.0, 0.6, (j as f64 * 8.0 + 7.0 - 8.0) / 16.0)
|
||
}
|
||
Muzzle::None => DVec3::ZERO,
|
||
};
|
||
// Cells launch straight up whichever way the turret faces.
|
||
let dir = if matches!(self.kind.spec().muzzle, Muzzle::Cells) { DVec3::Y } else { rot * DVec3::NEG_Z };
|
||
(at + rot * local * s, dir)
|
||
}
|
||
}
|
||
|
||
impl Sim {
|
||
/// Draws unit `i`: its vehicle, its launcher or turret where it points, its antennas turning.
|
||
pub(super) 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 spec = sam.kind.spec();
|
||
let parts = &spec.parts;
|
||
let base = sam.base();
|
||
let s = spec.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);
|
||
// A unit on the move is packed: launcher down, turret ahead.
|
||
out.model(id, parts.body, sam.pos + up, base, s, false);
|
||
let mut k = 1;
|
||
let mut part = |out: &mut Out, model: &'static str, at: DVec3, r: DQuat, size: f64| {
|
||
out.model(id + k, model, at, r, size, false);
|
||
k += 1;
|
||
};
|
||
match spec.family {
|
||
Family::Trainable => {
|
||
if let Some(l) = parts.launcher {
|
||
part(out, l, mount - rot * spec.pivot * s, rot, s);
|
||
}
|
||
}
|
||
Family::Vertical if !matches!(spec.muzzle, Muzzle::Cells) => {
|
||
if let Some(l) = parts.launcher {
|
||
part(out, l, mount - rot * spec.pivot * s, rot, s);
|
||
}
|
||
}
|
||
Family::Vertical => {
|
||
if let Some(l) = parts.launcher {
|
||
part(out, l, mount, turret, s);
|
||
}
|
||
}
|
||
Family::Gun => {
|
||
if let Some(l) = parts.launcher {
|
||
part(out, l, mount + DVec3::Y * 0.12 * s, turret, s);
|
||
}
|
||
let recoil = rot * DVec3::new(0.0, 0.0, 0.15 * sam.recoil * s);
|
||
if let Some(p) = parts.pack {
|
||
part(out, p, mount + recoil, rot, s);
|
||
}
|
||
}
|
||
Family::Turret => {
|
||
if let Some(l) = parts.launcher {
|
||
part(out, l, mount - DVec3::Y * 0.2 * s, turret, s);
|
||
}
|
||
let recoil = rot * DVec3::new(0.0, 0.0, 0.1 * sam.recoil * s);
|
||
if let Some(p) = parts.pack {
|
||
part(out, p, mount + DVec3::Y * 0.1 * s + recoil, rot, s);
|
||
}
|
||
}
|
||
Family::Light => {
|
||
if let Some(l) = parts.launcher {
|
||
part(out, l, mount, rot, s);
|
||
}
|
||
}
|
||
Family::Static | Family::Truck => {}
|
||
}
|
||
if let Some((model, h, f, tilt)) = parts.dish {
|
||
part(out, model, mount + turret * DVec3::new(0.0, h * s, f * s), DQuat::from_rotation_y(sam.dish) * DQuat::from_rotation_x(tilt), s);
|
||
}
|
||
for &(model, h, back) in parts.fixed {
|
||
part(out, model, sam.pos + up + DVec3::Y * h * s + base * DVec3::new(0.0, 0.0, back * s), base, s);
|
||
}
|
||
if let Some((model, h, back, size, tilt)) = parts.spinner {
|
||
let at = sam.pos + up + DVec3::Y * h * s + base * DVec3::new(0.0, 0.0, back * s);
|
||
part(out, model, at, DQuat::from_rotation_y(sam.dish * 0.6) * DQuat::from_rotation_x(tilt), s * size);
|
||
}
|
||
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 (n, b) in barrels.iter().enumerate() {
|
||
let r = rot * DQuat::from_rotation_z(self.rng.f() * TAU);
|
||
out.model(id + 12 + n as u32, "airdef:flash", mount + rot * *b * s, r, 0.9, true);
|
||
}
|
||
}
|
||
}
|
||
}
|