aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_patrol.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-03 18:00:18 +0300
committerValentin Popov <valentin@popov.link>2026-12-03 18:00:18 +0300
commit099e48fa775b849654d1102a6c1d9e84ded7e1f4 (patch)
tree25864aa84bdb465d0ca52f5d28c5a1b20a23e041 /crates/fparkan-runtime/src/unit_patrol.rs
parent4b9277258224ab846b84cafe1d6a3b91e29a05c5 (diff)
downloadfparkan-099e48fa775b849654d1102a6c1d9e84ded7e1f4.tar.xz
fparkan-099e48fa775b849654d1102a6c1d9e84ded7e1f4.zip
feat(game): cycle warbot cockpit control modes
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs42
1 files changed, 31 insertions, 11 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index a22543b6..45c45622 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -583,9 +583,7 @@ impl UnitPatrol {
for unit in &mut state.units {
if self.is_leaving_factory(unit.handle)
|| mission.boarding.is_some_and(|control| {
- control.remote.is_some()
- && control.controls_chassis()
- && control.cockpit.handle == unit.handle
+ control.controls_chassis() && control.cockpit.handle == unit.handle
})
{
continue;
@@ -881,6 +879,13 @@ impl UnitPatrol {
poses.push((unit.handle, before, after));
}
}
+ if let Some(boarding) = mission.boarding.filter(|board| !board.controls_chassis()) {
+ if let Some(passenger) = poses.iter().find_map(|&(handle, _, pose)| {
+ crate::boarding::passenger_pose(world, boarding, handle, pose)
+ }) {
+ poses.push(passenger);
+ }
+ }
Ok(PreparedPatrol {
state,
poses,
@@ -1131,21 +1136,36 @@ fn choose_route(
}
impl PreparedPatrol {
- pub(super) fn speed_of(&self, handle: ObjectHandle, can_fly: bool) -> f32 {
+ fn displacement_of(&self, handle: ObjectHandle) -> [f32; 3] {
self.poses
.iter()
.find(|(moved, _, _)| *moved == handle)
- .map_or(0.0, |(_, before, after)| {
+ .map_or([0.0; 3], |(_, 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)
+ let to = after.position.map(f32::from_bits);
+ std::array::from_fn(|axis| to[axis] - from[axis])
})
}
+ pub(super) fn speed_of(&self, handle: ObjectHandle, can_fly: bool) -> f32 {
+ if self.seconds <= 0.0 {
+ return 0.0;
+ }
+ let mut displacement = self.displacement_of(handle);
+ if !can_fly {
+ // Ground support moves the root vertically without driving the chassis.
+ displacement[2] = 0.0;
+ }
+ crate::cockpit_speedometer::length(displacement) / self.seconds
+ }
+
+ pub(super) fn flight_velocity_of(&self, handle: ObjectHandle) -> Option<[f32; 3]> {
+ (self.seconds > 0.0).then(|| {
+ self.displacement_of(handle)
+ .map(|distance| distance / 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 {