diff options
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index c25b309f..a22543b6 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -71,6 +71,7 @@ pub(super) struct PatrollingUnit { pub(super) struct PreparedPatrol { pub(super) state: UnitPatrol, poses: Vec<(ObjectHandle, TransformState, TransformState)>, + seconds: f32, } #[derive(Clone, Copy)] @@ -880,7 +881,11 @@ impl UnitPatrol { poses.push((unit.handle, before, after)); } } - Ok(PreparedPatrol { state, poses }) + Ok(PreparedPatrol { + state, + poses, + seconds, + }) } } @@ -1126,6 +1131,21 @@ fn choose_route( } impl PreparedPatrol { + pub(super) fn speed_of(&self, handle: ObjectHandle, can_fly: bool) -> f32 { + self.poses + .iter() + .find(|(moved, _, _)| *moved == handle) + .map_or(0.0, |(_, before, after)| { + let from = before.position.map(f32::from_bits); + let mut to = after.position.map(f32::from_bits); + if !can_fly { + // Ground support moves the root vertically without driving the chassis. + to[2] = from[2]; + } + crate::cockpit_speedometer::translation_speed(from, to, self.seconds) + }) + } + pub(super) fn apply_poses(&self, world: &mut World) -> Result<(), EngineError> { // These handles were read during preparation and the world has yet to step. for &(handle, _, after) in &self.poses { |
