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.rs77
1 files changed, 77 insertions, 0 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 {