From f03b144907be8ad8cec2e1c7487b5d9e0a43f13e Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 15:37:59 +0400 Subject: fix(combat): continue projectile flight after piercing shields Resolve shield sphere entrances before the first physical hit. Carry leftover volume into later ticks for both player and autonomous fire and let a geometric miss pass through a warbot bounding sphere. Checked Control.dll RVAs 0x1e9f0 and 0xd0c0 in-process with a sphere-only contact. The AutoDemo corpus covers a charged stop, a pierced field, and an unchanged hull on a miss. Ran the workspace suite and AutoDemo in the game window with Vulkan validation. --- crates/fparkan-runtime/src/unit_combat.rs | 93 ++++++++++--------------------- 1 file changed, 29 insertions(+), 64 deletions(-) (limited to 'crates/fparkan-runtime/src/unit_combat.rs') diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs index 92c81d0e..01f1e164 100644 --- a/crates/fparkan-runtime/src/unit_combat.rs +++ b/crates/fparkan-runtime/src/unit_combat.rs @@ -1,13 +1,10 @@ use super::{ - apply_projectile_impact, autodemo::MOBILE_UNIT, combat_report::{CombatObject, CombatReport}, default_weapon_target::{self, DefaultWeaponTarget}, player_weapon::prepare_unit_weapons, - projectile::{ - load_projectile, projectile_unit_hit_with_poses, segment_sphere_fraction, unit_sphere, - ANIMAL_UNIT_CLASS, - }, + projectile::{load_projectile, segment_sphere_fraction, unit_sphere, ANIMAL_UNIT_CLASS}, + projectile_flight::ProjectileFlightHit, projectile_terrain_hit, turret_aim::{hull_local_point, TurretAim}, unit_patrol::UnitPatrol, @@ -512,32 +509,32 @@ impl AutoDemoCombat { self.finished_segments.clear(); let units = &self.units; self.flights.retain_mut(|flight| { - let mut contact = None; - let mut travelled = None; - let Some(mission) = &engine.loaded else { - return false; + let step = match flight.pose.advance_in_world_with_poses( + engine, + flight.shooter, + now, + |index| collision_poses(units, index), + ) { + Ok(step) => step, + Err(_) => { + unavailable += 1; + self.report + .unavailable(flight.shooter_identity, "projectile_advance", now, 1); + return false; + } }; - let stays = flight.pose.advance(now, |segment| { - let ground = projectile_terrain_hit(&mission.terrain, segment)?; - contact = projectile_unit_hit_with_poses(engine, flight.shooter, segment, |index| { - collision_poses(units, index) - }) - .filter(|hit| ground.is_none_or(|fraction| hit.fraction < fraction)); - let fraction = contact.map(|hit| hit.fraction).or(ground).unwrap_or(1.0); - travelled = Some(clip_segment(segment, fraction)); - Ok(ground.is_some() || contact.is_some()) - }); - if let Some(hit) = - contact.filter(|hit| hit.node != Some(crate::ProjectileNode::CaptureBarrier)) - { - let data = &self.projectiles[flight.projectile]; + let contact = match step.hit { + Some(ProjectileFlightHit::Body(hit)) + if hit.node != Some(crate::ProjectileNode::CaptureBarrier) => Some(hit), + _ => None, + }; + if let Some(hit) = contact { // Capture the target before applying damage, which may remove it. let target = CombatObject::read(&engine.world, hit.handle); - match data + match step .volume - .map(|volume| apply_projectile_impact(engine, hit, volume)) + .map(|volume| hit.apply_body_impact(engine, volume)) { - Some(Ok(ProjectileImpact::ShieldAbsorbed)) => {} Some(Ok(ProjectileImpact::Damage { removed: true, .. })) => { self.report.destroyed(flight.shooter_identity, target, now); events.push(AutoDemoCombatEvent::Destroyed { @@ -571,24 +568,12 @@ impl AutoDemoCombat { } } } - match stays { - Ok(true) => { - flight.segment = travelled; - true - } - Ok(false) => { - if let Some(segment) = travelled { - self.finished_segments.push((flight.projectile, segment)); - } - false - } - Err(_) => { - unavailable += 1; - self.report - .unavailable(flight.shooter_identity, "projectile_advance", now, 1); - false - } + if step.flying { + flight.segment = step.segment; + } else if let Some(segment) = step.segment { + self.finished_segments.push((flight.projectile, segment)); } + step.flying }); let Some(mission) = &engine.loaded else { return (events, unavailable); @@ -744,7 +729,7 @@ impl AutoDemoCombat { shooter: unit.handle, shooter_identity: shooter, projectile, - pose, + pose: pose.with_volume(data.volume), segment: None, }); self.next_flight_id += 1; @@ -813,17 +798,6 @@ fn within_firing_distance(from: [f32; 3], to: [f32; 3], range: f32) -> bool { distance_sq <= range * range } -fn clip_segment([start, end]: [[f32; 3]; 2], fraction: f32) -> [[f32; 3]; 2] { - if fraction == 1.0 { - [start, end] - } else { - [ - start, - std::array::from_fn(|i| start[i] + (end[i] - start[i]) * fraction), - ] - } -} - #[cfg(test)] mod tests { use super::*; @@ -841,15 +815,6 @@ mod tests { )); } - #[test] - fn visible_segment_ends_at_world_contact() { - let segment = [[10.0, 20.0, 8.0], [18.0, 24.0, 0.0]]; - assert_eq!( - clip_segment(segment, 0.25), - [[10.0, 20.0, 8.0], [12.0, 21.0, 6.0]] - ); - assert_eq!(clip_segment(segment, 1.0), segment); - } use crate::{ apply_projectile_hit, control_node_provider_row, create, frame, load_gameplay_mission, loaded_mission_assets, loaded_mission_control_device_tables, loaded_mission_script_outcome, -- cgit v1.2.3