diff options
Diffstat (limited to 'crates/fparkan-runtime/src/boarding.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/boarding.rs | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs index 9d15fedd..28ed6f61 100644 --- a/crates/fparkan-runtime/src/boarding.rs +++ b/crates/fparkan-runtime/src/boarding.rs @@ -11,6 +11,8 @@ use fparkan_world::{ }; pub(super) const WARBOT_CLASS: u32 = 0x0100_8000; +mod remote_control; +pub use remote_control::{can_control_warbot_remotely, control_warbot_remotely}; /// Ownership and cockpit changes from one Enter command. pub struct VehicleEntry { @@ -32,6 +34,7 @@ impl VehicleEntry { pub(super) struct Boarding { pub(super) cockpit: StartingCockpit, pub(super) hero: StartingCockpit, + pub(super) remote: bool, pub(super) can_fly: bool, pub(super) ground: Option<crate::ground_support::GroundSupport>, pub(super) on_building_floor: bool, @@ -156,15 +159,6 @@ pub fn board_friendly_warbot( let Some((cockpit, position)) = candidate else { return Ok(None); }; - let can_fly = crate::player_motion::warbot_can_fly(engine, cockpit.object_index); - let ground = (!can_fly) - .then(|| { - crate::ground_support::GroundSupport::prepare( - &mission.mission_assets, - cockpit.object_index, - ) - }) - .flatten(); set_transform( &mut engine.world, hero.handle, @@ -173,12 +167,31 @@ pub fn board_friendly_warbot( ..hero_pose }, )?; + start_warbot_control(engine, hero, cockpit, false); + Ok(Some(cockpit)) +} + +fn start_warbot_control( + engine: &mut Engine, + hero: StartingCockpit, + cockpit: StartingCockpit, + remote: bool, +) { + let can_fly = crate::player_motion::warbot_can_fly(engine, cockpit.object_index); if let Some(mission) = &mut engine.loaded { mission.boarding = Some(Boarding { cockpit, hero, + remote, can_fly, - ground, + ground: (!can_fly) + .then(|| { + crate::ground_support::GroundSupport::prepare( + &mission.mission_assets, + cockpit.object_index, + ) + }) + .flatten(), on_building_floor: false, flight_velocity: [0.0; 3], }); @@ -186,7 +199,6 @@ pub fn board_friendly_warbot( mission.hero_walk_velocity = [0.0; 2]; mission.hero_look.reset(); } - Ok(Some(cockpit)) } pub(super) fn vehicle_interaction_distance_sq( @@ -285,6 +297,7 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result<Option<StartingCockpit>, let Some(Boarding { cockpit: vehicle, hero, + remote, can_fly, on_building_floor, .. @@ -293,7 +306,10 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result<Option<StartingCockpit>, return Ok(None); }; let mut pose = transform_state(&engine.world, hero.handle)?; - if let Ok(vehicle_pose) = transform_state(&engine.world, vehicle.handle) { + let vehicle_pose = (!remote) + .then(|| transform_state(&engine.world, vehicle.handle).ok()) + .flatten(); + if let Some(vehicle_pose) = vehicle_pose { let [x, y, _] = vehicle_pose.position.map(f32::from_bits); let yaw = f32::from_bits(vehicle_pose.orientation[2]); let (sin, cos) = yaw.sin_cos(); @@ -322,7 +338,7 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result<Option<StartingCockpit>, pose.position = exit.map(f32::to_bits); pose.orientation[2] = yaw.to_bits(); set_transform(&mut engine.world, hero.handle, pose)?; - } else if !can_fly && !on_building_floor { + } else if !remote && !can_fly && !on_building_floor { // The passenger still has the destroyed chassis's root height. let [x, y, _] = pose.position.map(f32::from_bits); if let Some(ground) = mission @@ -347,7 +363,7 @@ pub(super) fn move_passenger( vehicle_pose: TransformState, ) -> Option<(ObjectHandle, TransformState)> { let boarding = engine.loaded.as_ref()?.boarding.as_ref()?; - if boarding.cockpit.handle != cockpit.handle { + if boarding.remote || boarding.cockpit.handle != cockpit.handle { return None; } let hero = boarding.hero; |
