aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_combat.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 10:43:57 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 10:43:57 +0300
commitbf991ad728dd6cdc02168b4d6552f0e7e85181a2 (patch)
tree20f796e1fd77ec39a63f2f25a9a42f491dd9ce55 /crates/fparkan-runtime/src/unit_combat.rs
parent6bd2930a1805ee27b32f9329fa8d9aeb16479da9 (diff)
downloadfparkan-bf991ad728dd6cdc02168b4d6552f0e7e85181a2.tar.xz
fparkan-bf991ad728dd6cdc02168b4d6552f0e7e85181a2.zip
fix(render): drive warbot muzzle flashes with firing phases
Use the first CPT node when the effect has no explicit override. Feed the autonomous weapon banks into the same phase sampling path as manual weapons. Confirm the effect constructor and phase reads in the original DLLs, and compare the two cannon flashes in a live AutoDemo window at the same clock sample.
Diffstat (limited to 'crates/fparkan-runtime/src/unit_combat.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs26
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;
}
}