diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 14:37:59 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 14:37:59 +0300 |
| commit | f03b144907be8ad8cec2e1c7487b5d9e0a43f13e (patch) | |
| tree | 219582ffa8178775ead715b45f9cdee6d578a4a1 /crates/fparkan-runtime/src/projectile.rs | |
| parent | 06df070ba0d7bd2435b8b1313019278090889d09 (diff) | |
| download | fparkan-f03b144907be8ad8cec2e1c7487b5d9e0a43f13e.tar.xz fparkan-f03b144907be8ad8cec2e1c7487b5d9e0a43f13e.zip | |
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.
Diffstat (limited to 'crates/fparkan-runtime/src/projectile.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/projectile.rs | 103 |
1 files changed, 82 insertions, 21 deletions
diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs index 55e5da46..720aad08 100644 --- a/crates/fparkan-runtime/src/projectile.rs +++ b/crates/fparkan-runtime/src/projectile.rs @@ -103,6 +103,7 @@ pub struct PlayerProjectile { lifetime_ms: u32, born_ms: u32, updated_ms: u32, + pub(super) volume: Option<f32>, } impl PlayerProjectile { @@ -131,9 +132,16 @@ impl PlayerProjectile { lifetime_ms, born_ms: clock_ms, updated_ms: clock_ms, + volume: None, }) } + /// Sets the launch volume. A pierced shield spends part of this volume in flight. + pub fn with_volume(mut self, volume: Option<f32>) -> Self { + self.volume = volume; + self + } + /// Queue time at launch, retained when the projectile's pose changes. pub fn born_ms(&self) -> u32 { self.born_ms @@ -209,9 +217,30 @@ impl ProjectileContact { None } } + + /// Applies the volume remaining after crossing any fields along the flight. + pub fn apply_body_impact( + self, + engine: &mut Engine, + volume: f32, + ) -> Result<ProjectileImpact, ControlResourceAccessError> { + let key = match self.node { + Some(ProjectileNode::CaptureBarrier) => return Ok(ProjectileImpact::Unresolved), + None | Some(ProjectileNode::Chassis(0)) => None, + Some( + ProjectileNode::Chassis(key) + | ProjectileNode::Mounted(key) + | ProjectileNode::Building(key), + ) => Some(key), + }; + Ok(match apply_contact_damage(engine, self, key, volume)? { + Some((remaining, removed)) => ProjectileImpact::Damage { remaining, removed }, + None => ProjectileImpact::Unresolved, + }) + } } -/// Finds the first unit or building intersected by this flight segment. +/// Finds the first physical unit or building contact along this flight segment. pub fn projectile_unit_hit( engine: &Engine, shooter: ObjectHandle, @@ -261,7 +290,6 @@ pub(super) fn projectile_unit_hit_with_poses<'a>( handle, state, segment, - (center, radius), sphere_fraction, poses(index), )? @@ -271,9 +299,7 @@ pub(super) fn projectile_unit_hit_with_poses<'a>( Some(ProjectileContact { handle, fraction, - position: std::array::from_fn(|axis| { - segment[0][axis] + (segment[1][axis] - segment[0][axis]) * fraction - }), + position: segment_point(segment, fraction), node, }) }) @@ -331,25 +357,14 @@ pub fn apply_projectile_impact( contact: ProjectileContact, volume: f32, ) -> Result<ProjectileImpact, ControlResourceAccessError> { - let key = match contact.node { - Some(ProjectileNode::CaptureBarrier) => return Ok(ProjectileImpact::Unresolved), - None | Some(ProjectileNode::Chassis(0)) => None, - Some( - ProjectileNode::Chassis(key) - | ProjectileNode::Mounted(key) - | ProjectileNode::Building(key), - ) => Some(key), - }; + if contact.node == Some(ProjectileNode::CaptureBarrier) { + return Ok(ProjectileImpact::Unresolved); + } let unabsorbed = super::projectile_shield::absorb(engine, contact, volume); if volume > 0.0 && unabsorbed == 0.0 { return Ok(ProjectileImpact::ShieldAbsorbed); } - Ok( - match apply_contact_damage(engine, contact, key, unabsorbed)? { - Some((remaining, removed)) => ProjectileImpact::Damage { remaining, removed }, - None => ProjectileImpact::Unresolved, - }, - ) + contact.apply_body_impact(engine, unabsorbed) } fn apply_contact_damage( @@ -433,10 +448,31 @@ fn apply_contact_damage( Ok(Some(((remaining - volume).max(0.0), false))) } +pub(super) fn segment_point([start, end]: [[f32; 3]; 2], fraction: f32) -> [f32; 3] { + std::array::from_fn(|axis| start[axis] + (end[axis] - start[axis]) * fraction) +} + pub(super) fn segment_sphere_fraction( + segment: [[f32; 3]; 2], + center: [f32; 3], + radius: f32, +) -> Option<f32> { + segment_sphere_query(segment, center, radius, true) +} + +pub(super) fn segment_sphere_entrance( + segment: [[f32; 3]; 2], + center: [f32; 3], + radius: f32, +) -> Option<f32> { + segment_sphere_query(segment, center, radius, false) +} + +fn segment_sphere_query( [start, end]: [[f32; 3]; 2], center: [f32; 3], radius: f32, + include_overlap: bool, ) -> Option<f32> { if !radius.is_finite() || radius <= 0.0 { return None; @@ -445,11 +481,15 @@ pub(super) fn segment_sphere_fraction( let rel: [f32; 3] = std::array::from_fn(|i| start[i] - center[i]); let dot = |a: [f32; 3], b: [f32; 3]| a.into_iter().zip(b).map(|(a, b)| a * b).sum::<f32>(); let c = dot(rel, rel) - radius * radius; - if c <= 0.0 { + if include_overlap && c <= 0.0 { return Some(0.0); } let a = dot(dir, dir); let b = dot(rel, dir); + // Control+0x1e9f0 reports overlap without a crossing flag inside the sphere. + if !include_overlap && (c < 0.0 || a < 1e-6 || b > 0.0) { + return None; + } let d = b * b - a * c; let fraction = (-b - d.sqrt()) / a; (0.0..=1.0).contains(&fraction).then_some(fraction) @@ -866,3 +906,24 @@ mod tests { .unwrap()); } } +#[test] +fn shield_entrance_is_distinct_from_an_initial_overlap() { + let center = [0.0; 3]; + let exit = [10.0, 4.0, 0.0]; + assert_eq!( + segment_sphere_entrance([[-10.0, 4.0, 0.0], exit], center, 5.0), + Some(0.35) + ); + assert_eq!( + segment_sphere_entrance([[0.0, 4.0, 0.0], exit], center, 5.0), + None + ); + assert_eq!( + segment_sphere_entrance([[-3.0, 4.0, 0.0], exit], center, 5.0), + Some(0.0) + ); + assert_eq!( + segment_sphere_entrance([[-3.0, 4.0, 0.0], [-10.0, 4.0, 0.0]], center, 5.0), + None + ); +} |
