aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/lib.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 13:53:08 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 13:53:08 +0300
commitb64fec455724bf659a3ed9418f144d2c21b8f26a (patch)
treef0cdb73bb8639f5af0d845200877af638887eb04 /crates/fparkan-runtime/src/lib.rs
parent12be4b4e75bf089dd4710c6a0bb6ba4c42bd4c66 (diff)
downloadfparkan-b64fec455724bf659a3ed9418f144d2c21b8f26a.tar.xz
fparkan-b64fec455724bf659a3ed9418f144d2c21b8f26a.zip
feat(player): carry inertia across manual flight inputs
Use the current Control linear limits and the acceleration ramp exercised through the GOG Control DLL at RVA 0x153c0. On the stock Teleport map, walk to the helicopter, board, climb and move forward, release the controls to coast into a hover, then descend.
Diffstat (limited to 'crates/fparkan-runtime/src/lib.rs')
-rw-r--r--crates/fparkan-runtime/src/lib.rs144
1 files changed, 2 insertions, 142 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index a72b5f35..64c908a3 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -92,6 +92,7 @@ mod mesh_collision;
mod mining;
pub use laboratory::LaboratoryReport;
mod manual_chassis;
+mod manual_flight;
mod mission_events;
mod ore_transport;
mod patrol_points;
@@ -3033,6 +3034,7 @@ pub fn frame_with_player_motion(
if let Some(mission) = &mut engine.loaded {
mission.player_pitch_bits = motion.pitch_bits;
frame.player_pitch_bits = motion.pitch_bits;
+ player_motion::commit_flight(mission, cockpit, motion, blocked);
if !blocked
&& !drowned
&& mission.player_gait.footfall
@@ -18333,148 +18335,6 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
- fn licensed_teleport_helicopter_climbs_and_keeps_altitude() {
- let vfs: Arc<dyn Vfs> = Arc::new(DirectoryVfs::new(licensed_root("IS")));
- let mut engine = create(EngineServices::new(vfs)).unwrap();
- load_gameplay_mission(
- &mut engine,
- MissionRequest {
- key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.04/data.tma".into(),
- mode: MissionMode::SingleMission,
- },
- MissionStartupInput {
- queue_time_ms: 0,
- research_creation_gate: false,
- },
- None,
- )
- .unwrap();
- let hero = starting_cockpit(&engine).unwrap();
- let up = PlayerMotion {
- climb: 1.0,
- delta_seconds: 1.0,
- ..PlayerMotion::default()
- };
- assert!(plan_player_motion(&engine, hero, up).unwrap().is_none());
-
- let helicopter = mission_object_handle(&engine, OriginalObjectId(2)).unwrap();
- let position = |engine: &Engine, cockpit: StartingCockpit| {
- transform_state(&engine.world, cockpit.handle)
- .unwrap()
- .position
- .map(f32::from_bits)
- };
- let mut pose = transform_state(&engine.world, hero.handle).unwrap();
- let [hx, hy, _] = pose.position.map(f32::from_bits);
- let [x, y, _] = transform_state(&engine.world, helicopter)
- .unwrap()
- .position
- .map(f32::from_bits);
- let yaw = (y - hy).atan2(x - hx) - std::f32::consts::FRAC_PI_2;
- pose.orientation[2] = yaw.to_bits();
- set_transform(&mut engine.world, hero.handle, pose).unwrap();
- let walk = PlayerMotion {
- movement: [0.0, 1.0],
- delta_seconds: 0.1,
- ..PlayerMotion::default()
- };
- for tick in 1..=45 {
- 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, Some(helicopter)).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();
- assert_eq!(board_friendly_warbot(&mut engine, None).unwrap(), None);
- let [hx, hy, hz] = position(&engine, hero);
- let [tx, ty, tz] = transform_state(&engine.world, helicopter)
- .unwrap()
- .position
- .map(f32::from_bits);
- assert_eq!(
- select_boarding_target(&engine, hero, [[hx, hy, hz + 1.0], [tx, ty, tz + 0.5]]),
- Some(helicopter),
- );
- let vehicle = board_friendly_warbot(&mut engine, Some(helicopter))
- .unwrap()
- .unwrap();
- assert_eq!(vehicle.handle, helicopter);
- let [x, y, z] = position(&engine, vehicle);
- let step = plan_player_motion(&engine, vehicle, up).unwrap().unwrap();
- assert!(step.sweep.is_some());
- assert!(step.floor_probe().is_none());
- frame_with_player_motion(&mut engine, 5_500, vehicle, step, false).unwrap();
- assert_eq!(position(&engine, vehicle), [x, y, z + 16.0]);
- assert_eq!(position(&engine, hero), [x, y, z + 16.0]);
-
- let forward = PlayerMotion {
- climb: 0.0,
- movement: [0.0, 1.0],
- delta_seconds: 0.25,
- ..up
- };
- let step = plan_player_motion(&engine, vehicle, forward)
- .unwrap()
- .unwrap();
- frame_with_player_motion(&mut engine, 5_750, vehicle, step, false).unwrap();
- let [fx, fy, fz] = position(&engine, vehicle);
- assert!(((fx - x).hypot(fy - y) - 10.0).abs() < 0.0001);
- assert_eq!(fz, z + 16.0);
-
- let down = PlayerMotion {
- climb: -1.0,
- delta_seconds: 2.0,
- ..up
- };
- let step = plan_player_motion(&engine, vehicle, down).unwrap().unwrap();
- frame_with_player_motion(&mut engine, 7_750, vehicle, step, false).unwrap();
- let ground = loaded_terrain(&engine)
- .unwrap()
- .height_at([fx, fy])
- .unwrap()
- .unwrap();
- assert_eq!(position(&engine, vehicle), [fx, fy, ground + 0.02]);
- }
-
- #[test]
- #[ignore = "requires licensed corpus"]
fn licensed_teleport_checks_free_capturer_and_counts_captured_mobile_hq() {
let vfs: Arc<dyn Vfs> = Arc::new(DirectoryVfs::new(licensed_root("IS")));
let mut engine = create(EngineServices::new(vfs)).unwrap();