diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 13:38:56 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 13:38:56 +0300 |
| commit | 05da53f0344416a5f14211a73f1f48d72c88b954 (patch) | |
| tree | d27d22f56a1bd185447b27223c79c9f97f7cc165 /crates/fparkan-runtime/src/boarding | |
| parent | 787279a1f514fbbaf09ca9dd6e5015bdce36635b (diff) | |
| download | fparkan-05da53f0344416a5f14211a73f1f48d72c88b954.tar.xz fparkan-05da53f0344416a5f14211a73f1f48d72c88b954.zip | |
feat(ui): drive a strategic warbot with an automatic gunner
Diffstat (limited to 'crates/fparkan-runtime/src/boarding')
| -rw-r--r-- | crates/fparkan-runtime/src/boarding/remote_control.rs | 93 |
1 files changed, 82 insertions, 11 deletions
diff --git a/crates/fparkan-runtime/src/boarding/remote_control.rs b/crates/fparkan-runtime/src/boarding/remote_control.rs index 960a19d2..12552671 100644 --- a/crates/fparkan-runtime/src/boarding/remote_control.rs +++ b/crates/fparkan-runtime/src/boarding/remote_control.rs @@ -5,10 +5,19 @@ use crate::{ component_cockpit, strategic_roster::warbot_rows, strategic_view::{command_post, CommandPost}, - Engine, StartingCockpit, + Engine, PlayerWeapons, StartingCockpit, }; use fparkan_world::{identity_metadata, ObjectHandle}; +/// Which operator fires while the player drives 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, +} + fn remote_cockpit( engine: &Engine, hero: StartingCockpit, @@ -48,35 +57,53 @@ pub fn can_control_warbot_remotely( remote_cockpit(engine, hero, target).is_some() } -/// Gives the hero manual control of a warbot while the hero remains at the bunker. +/// Lets the hero drive a warbot from the bunker in the chosen weapon mode. pub fn control_warbot_remotely( engine: &mut Engine, hero: StartingCockpit, target: ObjectHandle, + mode: RemoteWarbotControl, ) -> Option<StartingCockpit> { let cockpit = remote_cockpit(engine, hero, target)?; - if let Some(patrol) = engine.loaded.as_mut()?.unit_patrol.as_mut() { + if let Some(patrol) = engine + .loaded + .as_mut()? + .unit_patrol + .as_mut() + .filter(|_| mode == RemoteWarbotControl::Manual) + { patrol.release_orders_for_manual_control(target); } - start_warbot_control(engine, hero, cockpit, true); + start_warbot_control(engine, hero, cockpit, Some(mode)); Some(cockpit) } +/// The active remote gunner's ammunition, charge and firing phases. +#[must_use] +pub fn remote_auto_gunner_weapons(engine: &Engine) -> Option<&PlayerWeapons> { + let boarding = engine.loaded.as_ref()?.boarding?; + if boarding.controls_weapons() { + return None; + } + engine + .autodemo_combat + .as_ref()? + .weapons(boarding.cockpit.handle) +} + #[cfg(test)] mod tests { use super::*; use crate::{ - create, disembark_warbot, frame_with_player_motion, load_gameplay_mission, - plan_player_motion, starting_cockpit, strategic_orders, EngineServices, MissionMode, - MissionRequest, MissionStartupInput, PlayerMotion, + create, disembark_warbot, frame, frame_with_player_motion, load_gameplay_mission, + plan_player_motion, starting_cockpit, strategic_orders, AutoDemoCombatEvent, + EngineServices, MissionMode, MissionRequest, MissionStartupInput, PlayerMotion, }; use fparkan_vfs::DirectoryVfs; use fparkan_world::transform_state; use std::sync::Arc; - #[test] - #[ignore = "requires licensed corpus"] - fn licensed_fortresses_drives_the_warbot_without_moving_the_hero() { + fn stock_fortresses() -> Engine { 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( @@ -92,6 +119,13 @@ mod tests { None, ) .unwrap(); + engine + } + + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_fortresses_drives_the_warbot_without_moving_the_hero() { + let mut engine = stock_fortresses(); let hero = starting_cockpit(&engine).unwrap(); let actor = warbot_rows(&engine, hero)[0].handle; let hero_pose = transform_state(&engine.world, hero.handle).unwrap(); @@ -102,7 +136,8 @@ mod tests { ) .is_none()); assert!(strategic_orders::stand(&mut engine, hero, actor)); - let vehicle = control_warbot_remotely(&mut engine, hero, actor).unwrap(); + let vehicle = + control_warbot_remotely(&mut engine, hero, actor, RemoteWarbotControl::Manual).unwrap(); assert_eq!(vehicle.handle, actor); assert_eq!(warbot_rows(&engine, hero)[0].order_label, 0x1824); for time in [100, 200, 300, 400, 500] { @@ -134,4 +169,40 @@ mod tests { ); assert!(crate::player_vehicle(&engine).is_none()); } + + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_fortresses_auto_gunner_uses_live_ammunition_and_retains_the_order() { + let mut engine = stock_fortresses(); + let hero = starting_cockpit(&engine).unwrap(); + let actor = warbot_rows(&engine, hero)[0].handle; + let initial = transform_state(&engine.world, actor).unwrap(); + assert!(strategic_orders::stand(&mut engine, hero, actor)); + assert!( + control_warbot_remotely(&mut engine, hero, actor, RemoteWarbotControl::AutoGunner) + .is_some() + ); + let rounds = |engine: &Engine| -> u32 { + remote_auto_gunner_weapons(engine) + .unwrap() + .indicators() + .filter_map(|indicator| indicator.rounds) + .sum() + }; + let before = rounds(&engine); + for tick in 0..=60 * 210 { + let result = frame(&mut engine, tick * 1000 / 60).unwrap(); + if result.autodemo_combat_events.iter().any(|event| { + matches!(event, AutoDemoCombatEvent::Shot { shooter, .. } if *shooter == actor) + }) { + assert!(rounds(&engine) < before); + 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()); + return; + } + } + panic!("the stock defenders never opened fire with the auto gunner active"); + } } |
