From 79635316902c69a363f1d1a9ebef110d94190356 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 08:55:10 +0400 Subject: fix(combat): let projectiles destroy mounted warbot parts Resolve mounted model triangles through the sampled socket chain and publish the damage to the assembled Control provider. Remove the damaged geometry, stop weapons whose provider was depleted, and preserve already separated ranges when the chassis later dies. Confirmed with a licensed AutoDemo ray query and two frames around a controlled hit in the Vulkan window. --- crates/fparkan-runtime/src/unit_combat.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 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 1ebbac2a..2629aba9 100644 --- a/crates/fparkan-runtime/src/unit_combat.rs +++ b/crates/fparkan-runtime/src/unit_combat.rs @@ -4,8 +4,11 @@ use super::{ combat_report::{CombatObject, CombatReport}, default_weapon_target::{self, DefaultWeaponTarget}, player_weapon::prepare_unit_weapons, - projectile::{load_projectile, segment_sphere_fraction, unit_sphere, ANIMAL_UNIT_CLASS}, - projectile_terrain_hit, projectile_unit_hit, + projectile::{ + load_projectile, projectile_unit_hit_with_poses, segment_sphere_fraction, unit_sphere, + ANIMAL_UNIT_CLASS, + }, + projectile_terrain_hit, turret_aim::{hull_local_point, TurretAim}, unit_patrol::UnitPatrol, weapon_pose::WeaponPoses, @@ -123,6 +126,13 @@ struct Unit { idle_target: DefaultWeaponTarget, } +fn collision_poses(units: &[Unit], index: usize) -> Option<&WeaponPoses> { + units + .iter() + .find(|unit| unit.index == index) + .map(|unit| &unit.poses) +} + impl Unit { fn uses_default_targeting(&self, patrol: Option<&UnitPatrol>) -> bool { self.class == super::boarding::WARBOT_CLASS @@ -140,6 +150,10 @@ struct Flight { } impl AutoDemoCombat { + pub(super) fn poses_for_collision(&self, index: usize) -> Option<&WeaponPoses> { + collision_poses(&self.units, index) + } + pub(super) fn new( vfs: &Arc, mission: &MissionDocument, @@ -477,6 +491,7 @@ impl AutoDemoCombat { let mut events = Vec::new(); let mut unavailable = 0; self.finished_segments.clear(); + let units = &self.units; self.flights.retain_mut(|flight| { let mut contact = None; let mut travelled = None; @@ -485,7 +500,9 @@ impl AutoDemoCombat { }; let stays = flight.pose.advance(now, |segment| { let ground = projectile_terrain_hit(&mission.terrain, segment)?; - contact = projectile_unit_hit(engine, flight.shooter, 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)); @@ -1076,7 +1093,7 @@ mod tests { assert!(destruction_effects.iter().any(|event| { event.archive == "system.rlb" && event.name == "explode_rbr_b.exp" - && matches!(event.mesh, Some(crate::DestroyedMesh::Mounted { object_index }) + && matches!(event.mesh, Some(crate::DestroyedMesh::Mounted { object_index, .. }) if drafts[object_index].original_id.map(|id| id.0) == retired.original_id) && event .position @@ -1313,7 +1330,7 @@ mod tests { let ground = projectile_terrain_hit(&mission.terrain, ray) .unwrap() .unwrap(); - let contact = projectile_unit_hit(&engine, enemy, ray).unwrap(); + let contact = crate::projectile_unit_hit(&engine, enemy, ray).unwrap(); assert_eq!(contact.handle, hero.handle); assert!(contact.fraction < ground); let mut shots = Vec::new(); -- cgit v1.2.3