Continuous engine sound on drones and missiles, live and in replays, through persistent sound sources (#95, fork patch 37)
build / mod (push) Successful in 3m51s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 16:10:24 +03:00
parent ab6b61db59
commit 766b292aec
43 changed files with 2700 additions and 58 deletions
+21 -21
View File
@@ -20,6 +20,7 @@ mod ew;
pub mod lights;
mod logistics;
mod orders;
mod voices;
pub mod outcome;
mod units;
mod why;
@@ -81,6 +82,10 @@ pub struct Out {
pub models: Vec<Model>,
pub particles: Vec<Particle>,
pub sounds: Vec<(&'static str, DVec3, f32, f32)>,
/// The engines sounding this tick (persistent sources, `crate::engines`), and whether the
/// picture cut (a replay seek or a new shot): every engine then starts afresh.
pub engines: Vec<crate::engines::Decl>,
pub engine_cut: bool,
pub commands: Vec<String>,
/// Camera jolt (strength, seconds), the strongest this tick.
pub shake: Option<(f32, f32)>,
@@ -109,6 +114,10 @@ impl Out {
pub fn sound(&mut self, event: &'static str, at: DVec3, volume: f32, pitch: f32) {
self.sounds.push((event, at, volume, pitch));
}
/// An engine that sounds: `vel` is the simulation's, blocks a tick.
pub fn engine(&mut self, key: u32, event: &'static str, at: DVec3, vel: DVec3, gain: f32, pitch: f32, damaged: bool) {
self.engines.push(crate::engines::Decl { key, event, at, vel: vel * 20.0, gain, pitch, damaged });
}
fn jolt(&mut self, strength: f32, seconds: f32) {
if self.shake.is_none_or(|(s, _)| s < strength) {
self.shake = Some((strength.min(1.0), seconds));
@@ -1684,6 +1693,9 @@ impl Sim {
out.particles("minecraft:large_smoke", d.pos, 0.2, DVec3::new(0.0, 0.05, 0.0), 0.02, 1);
}
out.particles("minecraft:flame", d.pos, 0.25, DVec3::ZERO, 0.02, 2);
if let Some((event, pitch)) = d.kind.engine_voice() {
out.engine(d.id, event, d.pos, d.vel, 0.8, pitch, true);
}
if sweep.hit().is_some() || ground.ground_hit(below, d.pos, 0.3, &sweep, now) || d.age > 600 {
// The wreck's warhead may still go off where it lands.
let warhead = if spec.decoy || !self.rng.chance(0.35) { 0 } else { spec.warhead.min(2) };
@@ -1927,9 +1939,9 @@ impl Sim {
out.particles("minecraft:cloud", back - d.vel.normalize_or_zero() * 1.5, 0.15, DVec3::ZERO, 0.005, 1);
}
}
let (event, pitch, every) = spec.sound;
if d.age % every == 0 {
out.sound(event, d.pos, 1.0, pitch);
// The engine is one source that follows the drone (#95).
if let Some((event, pitch)) = d.kind.engine_voice() {
out.engine(d.id, event, d.pos, d.vel, 0.8, pitch, false);
}
}
for (drone, pos) in splits {
@@ -2692,24 +2704,12 @@ impl Sim {
done.push((m.id, None, false, m.sam));
continue;
}
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);
}
if lit {
// The motor is one source that follows the missile from ignition on (#95).
let (event, gain, pitch) = m.kind.engine_voice();
out.engine(0x4000_0000 | m.id, event, m.pos, m.vel, gain, pitch, false);
}
if lit && spec.flame > 0.0 {
let back = m.pos - new * 1.4 * spec.scale;
out.particles("minecraft:flame", back, 0.05, -new * 0.1, 0.01, 2);
if m.age % 2 == 0 {
+40
View File
@@ -0,0 +1,40 @@
//! What the simulation tells the engine sources (`crate::engines`): which sound an entity's
//! engine makes, from the specs the rest of the simulation owns.
use super::{DroneKind, MissileKind};
impl DroneKind {
/// The sound of its engine and its pitch; none for the ballistic ones, which fall with a
/// scream played once (and the Oreshnik's blocks and submunitions, which have no engine).
pub fn engine_voice(self) -> Option<(&'static str, f32)> {
let spec = self.spec();
if spec.ballistic.is_some() || matches!(self, DroneKind::OreshnikBlock | DroneKind::OreshnikSub) {
return None;
}
Some((spec.sound.0, spec.sound.1))
}
}
impl MissileKind {
/// The sound of its motor, its gain and its pitch: a rocket's roar, or the electric whine of
/// a motor without a flame.
pub fn engine_voice(self) -> (&'static str, f32, f32) {
if self.spec().flame == 0.0 {
return ("airdef:drone.lancet", 0.8, 1.6);
}
let pitch = match self {
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,
};
("airdef:missile.flight", 1.0, pitch)
}
/// Ticks from the launch until the motor lights (a cold launch throws it out of the tube first).
pub fn lit_after(self) -> u32 {
self.spec().cold
}
}