aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/boarding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/boarding.rs')
-rw-r--r--crates/fparkan-runtime/src/boarding.rs62
1 files changed, 47 insertions, 15 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs
index c8f586b5..4aaf2cc8 100644
--- a/crates/fparkan-runtime/src/boarding.rs
+++ b/crates/fparkan-runtime/src/boarding.rs
@@ -14,8 +14,8 @@ pub(super) const WARBOT_CLASS: u32 = 0x0100_8000;
pub mod bunker;
mod remote_control;
pub use remote_control::{
- can_control_warbot_remotely, control_warbot_remotely, remote_automatic_weapons,
- remote_warbot_control, RemoteWarbotControl,
+ can_control_warbot_remotely, control_warbot_remotely, cycle_warbot_control,
+ remote_automatic_weapons, remote_warbot_control, warbot_control_mode, RemoteWarbotControl,
};
/// Ownership and cockpit changes from one Enter command.
@@ -38,7 +38,8 @@ impl VehicleEntry {
pub(super) struct Boarding {
pub(super) cockpit: StartingCockpit,
pub(super) hero: StartingCockpit,
- pub(super) remote: Option<RemoteWarbotControl>,
+ pub(super) remote: bool,
+ pub(super) control_mode: RemoteWarbotControl,
pub(super) turret: Option<crate::TurretAim>,
pub(super) can_fly: bool,
pub(super) ground: Option<crate::ground_support::GroundSupport>,
@@ -48,12 +49,11 @@ pub(super) struct Boarding {
impl Boarding {
pub(super) fn controls_chassis(self) -> bool {
- self.turret.is_none() && self.remote != Some(RemoteWarbotControl::Autopilot)
+ self.turret.is_none() && self.control_mode != RemoteWarbotControl::Autopilot
}
pub(super) fn controls_weapons(self) -> bool {
- self.remote
- .is_none_or(|mode| mode == RemoteWarbotControl::Manual)
+ self.control_mode == RemoteWarbotControl::Manual
}
}
@@ -202,7 +202,8 @@ fn start_player_control(
mission.boarding = Some(Boarding {
cockpit,
hero,
- remote,
+ remote: remote.is_some(),
+ control_mode: remote.unwrap_or(RemoteWarbotControl::Manual),
turret,
can_fly,
ground: (turret.is_none() && !can_fly)
@@ -292,6 +293,27 @@ mod tests {
assert_eq!(entry.cockpit.unwrap().handle, target);
assert_eq!(entry.capture_notice(), None);
assert_eq!(player_vehicle(&engine), entry.cockpit);
+
+ assert_eq!(
+ super::warbot_control_mode(&engine),
+ Some(super::RemoteWarbotControl::Manual)
+ );
+ assert_eq!(
+ super::cycle_warbot_control(&mut engine, None),
+ Some(super::RemoteWarbotControl::AutoGunner)
+ );
+ assert_eq!(
+ super::cycle_warbot_control(&mut engine, None),
+ Some(super::RemoteWarbotControl::Autopilot)
+ );
+ let boarding = engine.loaded.as_ref().unwrap().boarding.unwrap();
+ let mut autonomous_pose = transform_state(&engine.world, target).unwrap();
+ autonomous_pose.position[0] = (x + 5.0).to_bits();
+ let (passenger, _, following) =
+ super::passenger_pose(&engine.world, boarding, target, autonomous_pose).unwrap();
+ assert_eq!(passenger, hero.handle);
+ assert_eq!(following.position, autonomous_pose.position);
+ assert!(super::remote_warbot_control(&engine).is_none());
}
}
@@ -329,8 +351,7 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result<Option<StartingCockpit>,
return Ok(None);
};
let mut pose = transform_state(&engine.world, hero.handle)?;
- let vehicle_pose = remote
- .is_none()
+ let vehicle_pose = (!remote)
.then(|| transform_state(&engine.world, vehicle.handle).ok())
.flatten();
if let Some(vehicle_pose) = vehicle_pose {
@@ -362,7 +383,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 remote.is_none() && !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
@@ -392,16 +413,27 @@ pub(super) fn move_passenger(
cockpit: StartingCockpit,
vehicle_pose: TransformState,
) -> Option<(ObjectHandle, TransformState)> {
- let boarding = engine.loaded.as_ref()?.boarding.as_ref()?;
- if boarding.remote.is_some() || boarding.cockpit.handle != cockpit.handle {
+ let boarding = engine.loaded.as_ref()?.boarding?;
+ let (hero, previous, pose) =
+ passenger_pose(&engine.world, boarding, cockpit.handle, vehicle_pose)?;
+ set_transform(&mut engine.world, hero, pose).ok()?;
+ Some((hero, previous))
+}
+
+pub(super) fn passenger_pose(
+ world: &fparkan_world::World,
+ boarding: Boarding,
+ vehicle: ObjectHandle,
+ vehicle_pose: TransformState,
+) -> Option<(ObjectHandle, TransformState, TransformState)> {
+ if boarding.remote || boarding.cockpit.handle != vehicle {
return None;
}
let hero = boarding.hero;
- let previous = transform_state(&engine.world, hero.handle).ok()?;
+ let previous = transform_state(world, hero.handle).ok()?;
let pose = TransformState {
position: vehicle_pose.position,
..previous
};
- set_transform(&mut engine.world, hero.handle, pose).ok()?;
- Some((hero.handle, previous))
+ Some((hero.handle, previous, pose))
}