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/projectile_flight.rs | 99 +++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 crates/fparkan-runtime/src/projectile_flight.rs (limited to 'crates/fparkan-runtime/src/projectile_flight.rs') diff --git a/crates/fparkan-runtime/src/projectile_flight.rs b/crates/fparkan-runtime/src/projectile_flight.rs new file mode 100644 index 00000000..2efb8bb7 --- /dev/null +++ b/crates/fparkan-runtime/src/projectile_flight.rs @@ -0,0 +1,99 @@ +//! Order field crossings and physical contacts along the traveled segment. + +use crate::{ + projectile::{projectile_unit_hit_with_poses, segment_point}, + projectile_shield::{absorb, shield_crossings}, + projectile_terrain_hit, Engine, ObjectHandle, PlayerProjectile, ProjectileContact, +}; +use fparkan_terrain::TerrainError; + +/// What ended this flight segment before its planned endpoint. +pub enum ProjectileFlightHit { + /// The flight reached the ground or water surface. + Terrain, + /// A charged field absorbed all the remaining volume. + Shield, + /// The segment reached geometry or a physical collision fallback. + Body(ProjectileContact), +} + +/// Result of one queue tick of projectile flight. +pub struct ProjectileFlightStep { + pub flying: bool, + /// Traveled trace clipped to the contact, absent if this tick covered no distance. + pub segment: Option<[[f32; 3]; 2]>, + pub hit: Option, + /// Volume remaining for any physical impact or the next tick. + pub volume: Option, +} + +impl PlayerProjectile { + /// Advances a player shot through the mission terrain, fields and live bodies. + pub fn advance_in_world( + &mut self, + engine: &mut Engine, + shooter: ObjectHandle, + clock_ms: u32, + ) -> Result { + self.advance_in_world_with(engine, shooter, clock_ms, crate::projectile_unit_hit) + } + + pub(super) fn advance_in_world_with_poses<'a>( + &mut self, + engine: &mut Engine, + shooter: ObjectHandle, + clock_ms: u32, + poses: impl Fn(usize) -> Option<&'a crate::weapon_pose::WeaponPoses>, + ) -> Result { + self.advance_in_world_with(engine, shooter, clock_ms, |engine, shooter, segment| { + projectile_unit_hit_with_poses(engine, shooter, segment, &poses) + }) + } + + fn advance_in_world_with( + &mut self, + engine: &mut Engine, + shooter: ObjectHandle, + clock_ms: u32, + body_contact: impl Fn(&Engine, ObjectHandle, [[f32; 3]; 2]) -> Option, + ) -> Result { + let mut traveled = None; + let mut hit = None; + let mut volume = self.volume; + let flying = self.advance(clock_ms, |segment| { + let Some(mission) = &engine.loaded else { + return Ok(true); + }; + let ground = projectile_terrain_hit(&mission.terrain, segment)?; + let body = body_contact(engine, shooter, segment) + .filter(|contact| ground.is_none_or(|fraction| contact.fraction < fraction)); + let mut stop = body.as_ref().map(|contact| contact.fraction).or(ground); + hit = body + .map(ProjectileFlightHit::Body) + .or_else(|| ground.map(|_| ProjectileFlightHit::Terrain)); + if let Some(mut remaining) = volume { + for crossing in shield_crossings(engine, shooter, segment, stop) { + remaining = absorb(engine, crossing, remaining); + if remaining == 0.0 { + stop = Some(crossing.fraction); + hit = Some(ProjectileFlightHit::Shield); + break; + } + } + volume = Some(remaining); + } + traveled = Some(match stop { + Some(fraction) => [segment[0], segment_point(segment, fraction)], + None => segment, + }); + Ok(stop.is_some()) + })?; + self.volume = volume; + Ok(ProjectileFlightStep { + flying, + segment: traveled, + hit, + volume, + }) + } +} -- cgit v1.2.3