diff options
Diffstat (limited to 'crates/fparkan-runtime/src/unit_combat.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_combat.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs index 2629aba9..92c81d0e 100644 --- a/crates/fparkan-runtime/src/unit_combat.rs +++ b/crates/fparkan-runtime/src/unit_combat.rs @@ -50,6 +50,25 @@ pub struct FiringEffectInstance { pub row_index: usize, } +/// Current firing-node phases for live weapons controlled by the mission. +pub fn autonomous_firing_effect_phases( + engine: &Engine, +) -> impl Iterator<Item = (FiringEffectInstance, f32)> + '_ { + let boarded = engine + .loaded + .as_ref() + .and_then(|mission| mission.boarding) + .map(|boarding| boarding.cockpit.handle); + engine + .autodemo_combat + .iter() + .flat_map(|combat| &combat.units) + .filter(move |unit| { + Some(unit.handle) != boarded && transform_state(&engine.world, unit.handle).is_ok() + }) + .flat_map(|unit| unit.weapons.firing_effect_phases(unit.index)) +} + /// One autonomous combat event on the mission clock. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum AutoDemoCombatEvent { @@ -968,11 +987,14 @@ mod tests { let mut observed_aimed_turret = false; let mut observed_finished_segment = false; let mut observed_weapon_effect = false; + let mut observed_intermediate_flash = false; let mut observed_opening_shot = false; crate::collect_unit_destruction_effects(&mut engine); let mut observed_unavailable = engine.autodemo_combat.as_ref().unwrap().unavailable as u64; for now in (0..=120_000).step_by(50) { let frame = frame(&mut engine, now).unwrap(); + observed_intermediate_flash |= autonomous_firing_effect_phases(&engine) + .any(|(_, phase)| phase > 0.0 && phase < 1.0 && phase != 0.5); let destruction_effects = crate::take_unit_destruction_effects(&mut engine); assert!(crate::take_unit_destruction_effects(&mut engine).is_empty()); observed_unavailable += frame.autodemo_combat_unavailable as u64; @@ -1113,6 +1135,10 @@ mod tests { "no segment survived its projectile's removal" ); assert!(observed_weapon_effect, "no shot carried its weapon effect"); + assert!( + observed_intermediate_flash, + "no autonomous flash followed a firing node through its cycle" + ); return; } } |
