aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/projectile_flight.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 14:37:59 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 14:37:59 +0300
commitf03b144907be8ad8cec2e1c7487b5d9e0a43f13e (patch)
tree219582ffa8178775ead715b45f9cdee6d578a4a1 /crates/fparkan-runtime/src/projectile_flight.rs
parent06df070ba0d7bd2435b8b1313019278090889d09 (diff)
downloadfparkan-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_flight.rs')
-rw-r--r--crates/fparkan-runtime/src/projectile_flight.rs99
1 files changed, 99 insertions, 0 deletions
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<ProjectileFlightHit>,
+ /// Volume remaining for any physical impact or the next tick.
+ pub volume: Option<f32>,
+}
+
+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<ProjectileFlightStep, TerrainError> {
+ 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<ProjectileFlightStep, TerrainError> {
+ 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<ProjectileContact>,
+ ) -> Result<ProjectileFlightStep, TerrainError> {
+ 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,
+ })
+ }
+}