diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 20:39:54 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 20:39:54 +0300 |
| commit | 3c6341d162de663ade969f2d0df8510b89a69da7 (patch) | |
| tree | 221648859379b9ff4184610f82cf46fa8edc0da1 /crates | |
| parent | 9238e2ec8c578145629b5b774b15a0aa205aee32 (diff) | |
| download | fparkan-3c6341d162de663ade969f2d0df8510b89a69da7.tar.xz fparkan-3c6341d162de663ade969f2d0df8510b89a69da7.zip | |
fix(control): board a captured warbot on the same Enter
The native Enter branch transfers the neutral owner before requesting a cockpit switch when the pilot device works. The firing-range window captured and boarded each of its two warbots on one press, and Teleport still credited the mobile HQ without boarding.
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/fparkan-runtime/src/boarding.rs | 77 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 10 |
2 files changed, 82 insertions, 5 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs index 165df6b1..c1b3651e 100644 --- a/crates/fparkan-runtime/src/boarding.rs +++ b/crates/fparkan-runtime/src/boarding.rs @@ -7,10 +7,19 @@ use super::{ use crate::player_motion::FLOOR_CLEARANCE; use fparkan_world::{ handle_by_original_id, identity_metadata, set_transform, transform_state, ObjectHandle, + OriginalObjectId, }; pub(super) const WARBOT_CLASS: u32 = 0x0100_8000; +/// Ownership and cockpit changes from one Enter command. +pub struct VehicleEntry { + /// Original ID of the neutral machine transferred to the player's clan. + pub captured: Option<OriginalObjectId>, + /// New player cockpit if the machine supports boarding. + pub cockpit: Option<StartingCockpit>, +} + #[derive(Clone, Copy)] pub(super) struct Boarding { pub(super) cockpit: StartingCockpit, @@ -60,6 +69,30 @@ pub fn select_boarding_target( .then_some(target.handle) } +/// Boards a selected ally or captures an available neutral machine. +/// +/// Capturing a working warbot also boards it during the same command. +/// +/// # Errors +/// +/// Returns an error if the hero's world state or the ownership update fails. +pub fn enter_vehicle( + engine: &mut Engine, + hero: StartingCockpit, + target: Option<ObjectHandle>, +) -> Result<VehicleEntry, EngineError> { + if let Some(cockpit) = board_friendly_warbot(engine, target)? { + return Ok(VehicleEntry { + captured: None, + cockpit: Some(cockpit), + }); + } + let captured = super::mission_events::capture_neutral_warbot(engine, hero)?; + let new_ally = captured.and_then(|id| handle_by_original_id(&engine.world, id)); + let cockpit = board_friendly_warbot(engine, new_ally)?; + Ok(VehicleEntry { captured, cockpit }) +} + /// Boards the selected compatible allied warbot within 20 units in XY. /// /// # Errors @@ -173,6 +206,50 @@ mod tests { assert!(vehicle_interaction_distance_sq(hero, [20.0, 0.0, 0.0]).is_none()); assert!(vehicle_interaction_distance_sq(hero, [f32::NAN, 0.0, 0.0]).is_none()); } + + #[test] + #[ignore = "requires licensed corpus"] + fn one_enter_captures_and_boards_the_neutral_warbot() { + use super::{enter_vehicle, player_vehicle, starting_cockpit, OriginalObjectId}; + use crate::{ + create, load_gameplay_mission, EngineServices, MissionMode, MissionRequest, + MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + use fparkan_world::{handle_by_original_id, set_transform, transform_state}; + use std::sync::Arc; + + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.01/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + let hero = starting_cockpit(&engine).unwrap(); + let id = OriginalObjectId(11); + let target = handle_by_original_id(&engine.world, id).unwrap(); + let mut pose = transform_state(&engine.world, hero.handle).unwrap(); + let [x, y, z] = transform_state(&engine.world, target) + .unwrap() + .position + .map(f32::from_bits); + pose.position = [x - 15.0, y, z].map(f32::to_bits); + set_transform(&mut engine.world, hero.handle, pose).unwrap(); + + let entry = enter_vehicle(&mut engine, hero, None).unwrap(); + assert_eq!(entry.captured, Some(id)); + assert_eq!(entry.cockpit.unwrap().handle, target); + assert_eq!(player_vehicle(&engine), entry.cockpit); + } } fn has_working_pilot_control(table: &MissionControlDeviceTableState) -> bool { diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 98592d6a..b6efbcf0 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -171,7 +171,8 @@ pub use wheel_animation::WheelAnimation; pub use aim_convergence::{projectile_sight_target, turret_sight_points}; pub use autodemo::{autodemo_camera, AutoDemoCamera, AutoDemoReinforcement, AutoDemoView}; pub use boarding::{ - board_friendly_warbot, disembark_warbot, player_vehicle, select_boarding_target, + board_friendly_warbot, disembark_warbot, enter_vehicle, player_vehicle, select_boarding_target, + VehicleEntry, }; pub use building_door::{has_proximity_doors, sample_capture_doors, sample_proximity_doors}; pub use capture_barrier::sample_capture_barrier; @@ -18019,10 +18020,9 @@ mod tests { let mut pose = transform_state(&engine.world, cockpit.handle).unwrap(); pose.position = transform_state(&engine.world, hq).unwrap().position; set_transform(&mut engine.world, cockpit.handle, pose).unwrap(); - assert_eq!( - capture_neutral_warbot(&mut engine, cockpit).unwrap(), - Some(OriginalObjectId(0)) - ); + let entry = enter_vehicle(&mut engine, cockpit, None).unwrap(); + assert_eq!(entry.captured, Some(OriginalObjectId(0))); + assert_eq!(entry.cockpit, None); assert_eq!( mission_object_handle(&engine, OriginalObjectId(0)), Some(hq) |
