aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_combat.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/unit_combat.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs27
1 files changed, 22 insertions, 5 deletions
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<dyn Vfs>,
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();