diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 13:59:29 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 13:59:29 +0300 |
| commit | 98569dc5e8ee01b19ee82852a807f6a2b911dae4 (patch) | |
| tree | 71dce6e11eaef918fc817b9393c0e190f661dd1c /crates/fparkan-runtime/src/boarding/remote_control.rs | |
| parent | 05da53f0344416a5f14211a73f1f48d72c88b954 (diff) | |
| download | fparkan-98569dc5e8ee01b19ee82852a807f6a2b911dae4.tar.xz fparkan-98569dc5e8ee01b19ee82852a807f6a2b911dae4.zip | |
feat(ui): watch a warbot on autopilot from its cockpit
Diffstat (limited to 'crates/fparkan-runtime/src/boarding/remote_control.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/boarding/remote_control.rs | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/crates/fparkan-runtime/src/boarding/remote_control.rs b/crates/fparkan-runtime/src/boarding/remote_control.rs index 12552671..ee030e2f 100644 --- a/crates/fparkan-runtime/src/boarding/remote_control.rs +++ b/crates/fparkan-runtime/src/boarding/remote_control.rs @@ -9,13 +9,15 @@ use crate::{ }; use fparkan_world::{identity_metadata, ObjectHandle}; -/// Which operator fires while the player drives from the command post. +/// Which systems the player operates from the command post. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum RemoteWarbotControl { /// The player pilots the chassis and fires the weapons. Manual, /// The player drives while the automatic gunner aims and fires. AutoGunner, + /// The player watches while the autonomous controller drives and fires. + Autopilot, } fn remote_cockpit( @@ -57,7 +59,7 @@ pub fn can_control_warbot_remotely( remote_cockpit(engine, hero, target).is_some() } -/// Lets the hero drive a warbot from the bunker in the chosen weapon mode. +/// Opens a warbot cockpit from the bunker in the chosen control mode. pub fn control_warbot_remotely( engine: &mut Engine, hero: StartingCockpit, @@ -78,9 +80,15 @@ pub fn control_warbot_remotely( Some(cockpit) } -/// The active remote gunner's ammunition, charge and firing phases. +/// The active control mode of a warbot linked to the command post. #[must_use] -pub fn remote_auto_gunner_weapons(engine: &Engine) -> Option<&PlayerWeapons> { +pub fn remote_warbot_control(engine: &Engine) -> Option<RemoteWarbotControl> { + engine.loaded.as_ref()?.boarding?.remote +} + +/// The active autonomous weapons' ammunition, charge and firing phases. +#[must_use] +pub fn remote_automatic_weapons(engine: &Engine) -> Option<&PlayerWeapons> { let boarding = engine.loaded.as_ref()?.boarding?; if boarding.controls_weapons() { return None; @@ -183,7 +191,7 @@ mod tests { .is_some() ); let rounds = |engine: &Engine| -> u32 { - remote_auto_gunner_weapons(engine) + remote_automatic_weapons(engine) .unwrap() .indicators() .filter_map(|indicator| indicator.rounds) @@ -199,10 +207,63 @@ mod tests { assert_eq!(warbot_rows(&engine, hero)[0].order_label, 0x1827); assert_eq!(transform_state(&engine.world, actor).unwrap(), initial); assert_eq!(disembark_warbot(&mut engine).unwrap(), Some(hero)); - assert!(remote_auto_gunner_weapons(&engine).is_none()); + assert!(remote_automatic_weapons(&engine).is_none()); return; } } panic!("the stock defenders never opened fire with the auto gunner active"); } + + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_fortresses_autopilot_keeps_the_route_and_ignores_manual_drive() { + let mut engine = stock_fortresses(); + let hero = starting_cockpit(&engine).unwrap(); + let actor = warbot_rows(&engine, hero)[0].handle; + let hero_start = transform_state(&engine.world, hero.handle).unwrap(); + let start = transform_state(&engine.world, actor).unwrap(); + let extent = crate::satellite_contacts::landscape_extent(&engine).unwrap(); + // The left valley waypoint on the stock satellite map. + let waypoint = [34.0, 62.0].map(|axis| axis * extent / 256.0); + assert!(strategic_orders::follow_route( + &mut engine, + hero, + actor, + &[waypoint] + )); + let cockpit = + control_warbot_remotely(&mut engine, hero, actor, RemoteWarbotControl::Autopilot) + .unwrap(); + assert_eq!(warbot_rows(&engine, hero)[0].order_label, 0x1828); + assert!(remote_automatic_weapons(&engine).is_some()); + for time in (0..=12_000).step_by(100) { + assert!(plan_player_motion( + &engine, + cockpit, + PlayerMotion { + movement: [-1.0, -1.0], + climb: 1.0, + mouse_x: 100.0, + mouse_y: 100.0, + delta_seconds: 0.1, + ..PlayerMotion::default() + }, + ) + .unwrap() + .is_none()); + frame(&mut engine, time).unwrap(); + } + let from_waypoint = |position: [u32; 3]| { + let [x, y, _] = position.map(f32::from_bits); + (x - waypoint[0]).hypot(y - waypoint[1]) + }; + let current = transform_state(&engine.world, actor).unwrap(); + assert!(from_waypoint(current.position) < from_waypoint(start.position)); + assert_eq!(disembark_warbot(&mut engine).unwrap(), Some(hero)); + assert_eq!( + transform_state(&engine.world, hero.handle).unwrap(), + hero_start + ); + assert_eq!(warbot_rows(&engine, hero)[0].order_label, 0x1828); + } } |
