aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_combat.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 15:38:57 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 15:38:57 +0300
commit1e0128c6de44aa73e446451a27469e9873bc7e93 (patch)
treedd056fd39a9223f11d27b21fca5d600b658bb5c7 /crates/fparkan-runtime/src/unit_combat.rs
parent2de3fd6567d6eee36910af260f1e5767213ba89c (diff)
downloadfparkan-1e0128c6de44aa73e446451a27469e9873bc7e93.tar.xz
fparkan-1e0128c6de44aa73e446451a27469e9873bc7e93.zip
fix(combat): fire autonomous turrets along their barrel and sights
Transform the live CPT axis through the weapon sockets and the chassis. Mounted weapons use the same sight convergence as manual shots for compatible profiles. The autonomous ray checks current chassis and mounted geometry. Checked the Control.dll CPT transform and convergence oracle against the Rust path, observed the initial AutoDemo combat in the Vulkan window, and ran the licensed AutoDemo combat test.
Diffstat (limited to 'crates/fparkan-runtime/src/unit_combat.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs43
1 files changed, 40 insertions, 3 deletions
diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs
index 01f1e164..e616a605 100644
--- a/crates/fparkan-runtime/src/unit_combat.rs
+++ b/crates/fparkan-runtime/src/unit_combat.rs
@@ -1,9 +1,13 @@
use super::{
+ aim_convergence::sight_target,
autodemo::MOBILE_UNIT,
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::{
+ load_projectile, projectile_unit_hit_with_poses, segment_sphere_fraction, unit_sphere,
+ ANIMAL_UNIT_CLASS,
+ },
projectile_flight::ProjectileFlightHit,
projectile_terrain_hit,
turret_aim::{hull_local_point, TurretAim},
@@ -31,6 +35,7 @@ pub struct AutoDemoProjectileType {
speed: f32,
lifetime_ms: u32,
volume: Option<f32>,
+ sight_convergence: bool,
autonomous_fire_distance: f32,
}
@@ -254,6 +259,7 @@ impl AutoDemoCombat {
speed: data.speed,
lifetime_ms: data.lifetime_ms,
volume: data.volume,
+ sight_convergence: data.sight_convergence,
autonomous_fire_distance: data.autonomous_fire_distance,
});
Some(battle.projectiles.len() - 1)
@@ -585,7 +591,9 @@ impl AutoDemoCombat {
&mission.control_device_tables,
Some(now),
);
- for unit in &mut self.units {
+ for unit_index in 0..self.units.len() {
+ let (before, tail) = self.units.split_at_mut(unit_index);
+ let (unit, after) = tail.split_first_mut().expect("unit index in bounds");
unit.weapons.read_control_energy(engine, unit.handle);
let Ok(state) = transform_state(&engine.world, unit.handle) else {
continue;
@@ -720,7 +728,36 @@ impl AutoDemoCombat {
continue;
}
let data = &self.projectiles[projectile];
- let direction = std::array::from_fn(|axis| to[axis] - from[axis]);
+ let direction = poses
+ .turret_sight_component(weapon.component_index)
+ .and_then(|component| {
+ let axis = poses.cpt_axis(state, weapon.component_index, barrel)?;
+ let hit = if data.sight_convergence {
+ poses
+ .sight_ray(&mission.mission_assets, unit.index, state, component)
+ .and_then(|[origin, axis]| {
+ sight_target(engine, origin, axis, |segment| {
+ projectile_unit_hit_with_poses(
+ engine,
+ unit.handle,
+ segment,
+ |index| {
+ collision_poses(before, index)
+ .or_else(|| collision_poses(after, index))
+ },
+ )
+ })
+ })
+ } else {
+ None
+ };
+ Some(hit.map_or(axis, |hit| {
+ std::array::from_fn(|axis| hit[axis] - from[axis])
+ }))
+ })
+ // shortcut: weapons without a sampled turret still use the
+ // target direction until their aiming controller is restored.
+ .unwrap_or_else(|| std::array::from_fn(|axis| to[axis] - from[axis]));
if let Some(pose) =
PlayerProjectile::new(from, direction, data.speed, data.lifetime_ms, now)
{