diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/fparkan-runtime/src/boarding.rs | 18 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/manual_chassis.rs | 19 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/player_motion.rs | 11 |
3 files changed, 41 insertions, 7 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs index 53ce8c81..e9dd7531 100644 --- a/crates/fparkan-runtime/src/boarding.rs +++ b/crates/fparkan-runtime/src/boarding.rs @@ -4,6 +4,7 @@ use super::{ starting_cockpit, Engine, EngineError, MissionControlDeviceTableState, MissionControlDeviceTableStatus, StartingCockpit, SurfaceQuery, TransformState, }; +use crate::player_motion::FLOOR_CLEARANCE; use fparkan_world::{ handle_by_original_id, identity_metadata, set_transform, transform_state, ObjectHandle, }; @@ -16,6 +17,7 @@ pub(super) struct Boarding { pub(super) hero: StartingCockpit, pub(super) can_fly: bool, pub(super) ground: Option<crate::ground_support::GroundSupport>, + pub(super) on_building_floor: bool, pub(super) flight_velocity: [f32; 3], } @@ -139,6 +141,7 @@ pub fn board_friendly_warbot( hero, can_fly, ground, + on_building_floor: false, flight_velocity: [0.0; 3], }); mission.player_pitch_bits = 0; @@ -186,6 +189,8 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result<Option<StartingCockpit>, let Some(Boarding { cockpit: vehicle, hero, + can_fly, + on_building_floor, .. }) = mission.boarding else { @@ -211,7 +216,7 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result<Option<StartingCockpit>, .height_at(xy) .map_err(EngineError::Terrain)? { - exit = Some([xy[0], xy[1], ground + 0.02]); + exit = Some([xy[0], xy[1], ground + FLOOR_CLEARANCE]); break; } } @@ -221,6 +226,17 @@ 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 { + // The passenger still has the destroyed chassis's root height. + let [x, y, _] = pose.position.map(f32::from_bits); + if let Some(ground) = mission + .terrain + .height_at([x, y]) + .map_err(EngineError::Terrain)? + { + pose.position[2] = (ground + FLOOR_CLEARANCE).to_bits(); + set_transform(&mut engine.world, hero.handle, pose)?; + } } mission.boarding = None; mission.player_pitch_bits = 0; diff --git a/crates/fparkan-runtime/src/manual_chassis.rs b/crates/fparkan-runtime/src/manual_chassis.rs index 49e0c7e7..3be28403 100644 --- a/crates/fparkan-runtime/src/manual_chassis.rs +++ b/crates/fparkan-runtime/src/manual_chassis.rs @@ -46,9 +46,10 @@ pub(super) fn support_step( mod tests { use super::*; use crate::{ - board_friendly_warbot, create, frame, frame_with_player_motion, load_gameplay_mission, - mission_object_handle, plan_player_motion, starting_cockpit, EngineServices, MissionMode, - MissionRequest, MissionStartupInput, PlayerMotion, + apply_projectile_hit, board_friendly_warbot, create, disembark_warbot, frame, + frame_with_player_motion, load_gameplay_mission, mission_object_handle, plan_player_motion, + starting_cockpit, EngineServices, MissionMode, MissionRequest, MissionStartupInput, + PlayerMotion, }; use fparkan_vfs::DirectoryVfs; use fparkan_world::{set_transform, transform_state, OriginalObjectId}; @@ -122,5 +123,17 @@ mod tests { .position, after.position ); + + assert_eq!( + apply_projectile_hit(&mut engine, robot, f32::MAX).unwrap(), + Some((0.0, true)) + ); + frame(&mut engine, 200).unwrap(); + assert!(mission_object_handle(&engine, id).is_none()); + assert_eq!(disembark_warbot(&mut engine).unwrap(), Some(hero)); + let exit = transform_state(&engine.world, hero.handle).unwrap(); + let terrain = &engine.loaded.as_ref().unwrap().terrain; + let floor = terrain.height_at([nx, ny]).unwrap().unwrap(); + assert_eq!(exit.position.map(f32::from_bits), [nx, ny, floor + 0.02]); } } diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs index 525bc7b3..73129d87 100644 --- a/crates/fparkan-runtime/src/player_motion.rs +++ b/crates/fparkan-runtime/src/player_motion.rs @@ -27,7 +27,7 @@ pub(super) fn drowns(engine: &Engine, cockpit: StartingCockpit, step: PlayerMoti // shortcut: bound stair steps and drops until the native hero collider is wired. const STEP_UP: f32 = 0.85; const STEP_DOWN: f32 = 2.0; -const FLOOR_CLEARANCE: f32 = 0.02; +pub(super) const FLOOR_CLEARANCE: f32 = 0.02; const WATER_SURFACE: u32 = 0x0002_0000; // shortcut: sample the temporary floor probe at most 0.16 units apart until native collision is wired. const WALK_COLLISION_DISTANCE: f32 = 0.16; @@ -620,9 +620,14 @@ pub(super) fn commit_motion_state( mission.hero_look = look; } } - if let (Some(boarding), Some(velocity)) = (&mut mission.boarding, step.flight_velocity) { - if boarding.cockpit.handle == cockpit.handle { + if let Some(boarding) = &mut mission.boarding { + if boarding.cockpit.handle != cockpit.handle { + return; + } + if let Some(velocity) = step.flight_velocity { boarding.flight_velocity = if blocked { [0.0; 3] } else { velocity }; + } else if !blocked && step.sweep.is_some() { + boarding.on_building_floor = step.on_building_floor(); } } } |
