//! 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) { self.spec().voice } /// 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 } } #[cfg(test)] mod tests { use super::*; use super::super::catalog::sound; /// The catalog holds the voice that is actually played. P1-SUN has no flame, so it uses the /// Lancet voice at 1.6; its old `P1sun => 1.7` match arm was unreachable behind `flame == 0`. #[test] fn missile_engine_voices_keep_their_played_values() { assert_eq!(MissileKind::P1sun.engine_voice(), (sound::DRONE_LANCET, 0.8, 1.6)); assert_eq!(MissileKind::M48n6.engine_voice(), (sound::MISSILE_FLIGHT, 1.0, 0.88)); } }