From 3c0ff06870dd1490c9ff3e6a5ed25247875f4fee Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 15 Nov 2026 01:19:58 +0400 Subject: fix(player): board the selected friendly warbot Route the F command to the cockpit sight selection and keep that target for Enter. Use the original strict 20-unit horizontal reach and preserve the working Control gate. Select the neutral target immediately after capture. The original iron3d distance block accepts 19.99, rejects 20 and rejects larger values. A windowed stock Teleport run selected and boarded the helicopter through the ordinary input handlers, then climbed, with Vulkan validation clean. --- crates/fparkan-runtime/src/boarding.rs | 92 +++++++++++++++++++++++++--------- crates/fparkan-runtime/src/lib.rs | 35 ++++++++++--- 2 files changed, 97 insertions(+), 30 deletions(-) (limited to 'crates/fparkan-runtime/src') diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs index 9a1479f8..e2c4eeb0 100644 --- a/crates/fparkan-runtime/src/boarding.rs +++ b/crates/fparkan-runtime/src/boarding.rs @@ -1,7 +1,8 @@ use super::{ - component_cockpit, control_device_provider_value, projectile::unit_sphere, starting_cockpit, - Engine, EngineError, MissionControlDeviceTableState, MissionControlDeviceTableStatus, - StartingCockpit, SurfaceQuery, TransformState, + component_cockpit, control_device_provider_value, + projectile::{projectile_terrain_hit, projectile_unit_hit, unit_sphere}, + starting_cockpit, Engine, EngineError, MissionControlDeviceTableState, + MissionControlDeviceTableStatus, StartingCockpit, SurfaceQuery, TransformState, }; use fparkan_world::{ handle_by_original_id, identity_metadata, set_transform, transform_state, ObjectHandle, @@ -22,12 +23,51 @@ pub fn player_vehicle(engine: &Engine) -> Option { Some(engine.loaded.as_ref()?.boarding.as_ref()?.cockpit) } -/// Boards the closest compatible allied warbot. +/// Selects the friendly warbot under a line of sight supplied by the camera. +pub fn select_boarding_target( + engine: &Engine, + hero: StartingCockpit, + segment: [[f32; 3]; 2], +) -> Option { + let target = projectile_unit_hit(engine, hero.handle, segment)?; + let owner = identity_metadata(&engine.world, hero.handle) + .ok()? + .owner_id?; + let mission = engine.loaded.as_ref()?; + // shortcut: use the cockpit sight ray until the original selection ranking is recovered. + if projectile_terrain_hit(&mission.terrain, segment) + .ok()? + .is_some_and(|ground| ground <= target.fraction) + { + return None; + } + let warbot = mission.object_drafts.iter().any(|draft| { + draft.unit_dat_header_flags == Some(WARBOT_CLASS) + && draft + .original_id + .and_then(|id| handle_by_original_id(&engine.world, id)) + == Some(target.handle) + }); + (warbot + && identity_metadata(&engine.world, target.handle) + .ok()? + .owner_id + == Some(owner)) + .then_some(target.handle) +} + +/// Boards the selected compatible allied warbot within 20 units in XY. /// /// # Errors /// /// Returns an error if the hero's world handle is stale. -pub fn board_friendly_warbot(engine: &mut Engine) -> Result, EngineError> { +pub fn board_friendly_warbot( + engine: &mut Engine, + target: Option, +) -> Result, EngineError> { + let Some(target) = target else { + return Ok(None); + }; let Some(hero) = starting_cockpit(engine) else { return Ok(None); }; @@ -41,7 +81,7 @@ pub fn board_friendly_warbot(engine: &mut Engine) -> Result Result Result() - .sqrt() - - radius; - // shortcut: same-clan proximity replaces native selection and boarding admission. - if !distance.is_finite() || distance > 6.0 { + let [x, y, _] = state.position.map(f32::from_bits); + if !within_boarding_range([hero_x, hero_y], [x, y]) { return None; } - Some(( - distance, - component_cockpit(mission, index, handle)?, - state.position, - )) + Some((component_cockpit(mission, index, handle)?, state.position)) }) - .min_by(|a, b| a.0.total_cmp(&b.0)); - let Some((_, cockpit, position)) = candidate else { + .next(); + let Some((cockpit, position)) = candidate else { return Ok(None); }; let can_fly = crate::player_motion::warbot_can_fly(engine, cockpit.object_index); @@ -104,6 +134,20 @@ pub fn board_friendly_warbot(engine: &mut Engine) -> Result bool { + (x - hero_x).hypot(y - hero_y) < 20.0 +} + +#[cfg(test)] +mod tests { + #[test] + fn boarding_reach_excludes_the_horizontal_boundary() { + assert!(super::within_boarding_range([0.0, 0.0], [12.0, 15.99])); + assert!(!super::within_boarding_range([0.0, 0.0], [12.0, 16.0])); + assert!(!super::within_boarding_range([0.0, 0.0], [f32::NAN, 0.0])); + } +} + fn has_working_pilot_control(table: &MissionControlDeviceTableState) -> bool { let MissionControlDeviceTableStatus::Available(devices) = &table.status else { return false; diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 81f6e899..a2d24893 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -71,7 +71,9 @@ mod unit_patrol; pub use autodemo::{ autodemo_camera, AutoDemoCamera, AutoDemoReinforcement, AutoDemoView, SpawnedUnit, }; -pub use boarding::{board_friendly_warbot, disembark_warbot, player_vehicle}; +pub use boarding::{ + board_friendly_warbot, disembark_warbot, player_vehicle, select_boarding_target, +}; pub use building_door::{has_proximity_doors, sample_proximity_doors}; pub use fparkan_assets::MissionAssets; pub use mesh_collision::{query_building_segment_world, BuildingMeshHit, BuildingMeshNode}; @@ -18775,7 +18777,10 @@ mod tests { 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); + assert_eq!( + board_friendly_warbot(&mut engine, Some(helicopter)).unwrap(), + None + ); let table = engine .loaded .as_mut() @@ -18790,7 +18795,19 @@ mod tests { 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!(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(); @@ -19055,11 +19072,14 @@ mod tests { loaded_mission_script_outcome(&engine), Some(MissionScriptOutcome::Completed) ); - assert_eq!(board_friendly_warbot(&mut engine).unwrap(), None); + assert_eq!( + board_friendly_warbot(&mut engine, Some(robot.handle)).unwrap(), + None + ); let robot_pose = transform_state(&engine.world, robot.handle).unwrap(); player_pose.position = robot_pose.position; set_transform(&mut engine.world, cockpit.handle, player_pose).unwrap(); - let vehicle = board_friendly_warbot(&mut engine) + let vehicle = board_friendly_warbot(&mut engine, Some(robot.handle)) .unwrap() .expect("vehicle cockpit"); assert_eq!(vehicle.handle, robot.handle); @@ -19079,7 +19099,10 @@ mod tests { }) .collect::>(); assert_eq!(shots, [(1, "bf_b_01".into())]); - assert_eq!(board_friendly_warbot(&mut engine).unwrap(), None); + assert_eq!( + board_friendly_warbot(&mut engine, Some(robot.handle)).unwrap(), + None + ); let motion = plan_player_motion( &engine, vehicle, -- cgit v1.2.3