aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-runtime/src/boarding.rs22
-rw-r--r--crates/fparkan-runtime/src/lib.rs37
2 files changed, 58 insertions, 1 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs
index 257b81f7..ec786a21 100644
--- a/crates/fparkan-runtime/src/boarding.rs
+++ b/crates/fparkan-runtime/src/boarding.rs
@@ -1,5 +1,6 @@
use super::{
- component_cockpit, projectile::unit_sphere, starting_cockpit, Engine, EngineError,
+ component_cockpit, control_device_provider_value, projectile::unit_sphere, starting_cockpit,
+ Engine, EngineError, MissionControlDeviceTableState, MissionControlDeviceTableStatus,
StartingCockpit, SurfaceQuery, TransformState,
};
use fparkan_world::{
@@ -52,6 +53,13 @@ pub fn board_friendly_warbot(engine: &mut Engine) -> Result<Option<StartingCockp
if identity_metadata(&engine.world, handle).ok()?.owner_id != Some(owner) {
return None;
}
+ let table = mission
+ .control_device_tables
+ .iter()
+ .find(|table| table.handle == handle)?;
+ if !has_working_pilot_control(table) {
+ return None;
+ }
let state = transform_state(&engine.world, handle).ok()?;
let (center, radius) = unit_sphere(&mission.mission_assets, index, state)?;
let distance = center
@@ -90,6 +98,18 @@ pub fn board_friendly_warbot(engine: &mut Engine) -> Result<Option<StartingCockp
Ok(Some(cockpit))
}
+fn has_working_pilot_control(table: &MissionControlDeviceTableState) -> bool {
+ let MissionControlDeviceTableStatus::Available(devices) = &table.status else {
+ return false;
+ };
+ devices
+ .iter()
+ .find(|device| device.descriptor.tag == 1)
+ .is_some_and(|device| {
+ control_device_provider_value(table, device).is_ok_and(|value| value > 0.0)
+ })
+}
+
/// Leaves the vehicle and restores the hero's cockpit.
///
/// # Errors
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 65e808fa..b1d8e6b2 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -18427,6 +18427,43 @@ mod tests {
let step = plan_player_motion(&engine, hero, walk).unwrap().unwrap();
frame_with_player_motion(&mut engine, tick * 100, hero, step, false).unwrap();
}
+ let table = engine
+ .loaded
+ .as_mut()
+ .unwrap()
+ .control_device_tables
+ .iter_mut()
+ .find(|table| table.handle == helicopter)
+ .unwrap();
+ let MissionControlDeviceTableStatus::Available(devices) = &mut table.status else {
+ panic!("helicopter Control devices unavailable");
+ };
+ let pilot = devices
+ .iter_mut()
+ .find(|device| device.descriptor.tag == 1)
+ .unwrap();
+ let key = pilot.key as usize;
+ let MissionControlNodeProviderTableStatus::Available(nodes) =
+ &mut table.node_provider_status
+ else {
+ panic!("helicopter Control nodes unavailable");
+ };
+ nodes[key].current_type1_value_bits = 0.0_f32.to_bits();
+ assert_eq!(board_friendly_warbot(&mut engine).unwrap(), None);
+ let table = engine
+ .loaded
+ .as_mut()
+ .unwrap()
+ .control_device_tables
+ .iter_mut()
+ .find(|table| table.handle == helicopter)
+ .unwrap();
+ let MissionControlNodeProviderTableStatus::Available(nodes) =
+ &mut table.node_provider_status
+ else {
+ panic!("helicopter Control nodes unavailable");
+ };
+ nodes[key].current_type1_value_bits = 1.0_f32.to_bits();
let vehicle = board_friendly_warbot(&mut engine).unwrap().unwrap();
assert_eq!(vehicle.handle, helicopter);
let [x, y, z] = position(&engine, vehicle);