aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/boarding
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 13:16:58 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 13:16:58 +0300
commit787279a1f514fbbaf09ca9dd6e5015bdce36635b (patch)
tree6adce388ed0fe42fe1e95dc2af536ce584015107 /crates/fparkan-runtime/src/boarding
parentad31192ab5d8c5f2b0d2d44b787d04c29cb49dc8 (diff)
downloadfparkan-787279a1f514fbbaf09ca9dd6e5015bdce36635b.tar.xz
fparkan-787279a1f514fbbaf09ca9dd6e5015bdce36635b.zip
feat(ui): control a warbot from the strategic card
Diffstat (limited to 'crates/fparkan-runtime/src/boarding')
-rw-r--r--crates/fparkan-runtime/src/boarding/remote_control.rs137
1 files changed, 137 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/boarding/remote_control.rs b/crates/fparkan-runtime/src/boarding/remote_control.rs
new file mode 100644
index 00000000..960a19d2
--- /dev/null
+++ b/crates/fparkan-runtime/src/boarding/remote_control.rs
@@ -0,0 +1,137 @@
+//! The command-post link to a friendly warbot's cockpit.
+
+use super::{has_working_pilot_control, start_warbot_control};
+use crate::{
+ component_cockpit,
+ strategic_roster::warbot_rows,
+ strategic_view::{command_post, CommandPost},
+ Engine, StartingCockpit,
+};
+use fparkan_world::{identity_metadata, ObjectHandle};
+
+fn remote_cockpit(
+ engine: &Engine,
+ hero: StartingCockpit,
+ target: ObjectHandle,
+) -> Option<StartingCockpit> {
+ let mission = engine.loaded.as_ref()?;
+ if mission.boarding.is_some()
+ || !matches!(command_post(engine, hero), Some(CommandPost::Bunker(_)))
+ || !warbot_rows(engine, hero)
+ .iter()
+ .any(|row| row.handle == target && row.selectable)
+ || mission
+ .unit_patrol
+ .as_ref()
+ .is_some_and(|patrol| patrol.is_leaving_factory(target))
+ {
+ return None;
+ }
+ let table = mission
+ .control_device_tables
+ .iter()
+ .find(|table| table.handle == target)?;
+ if !has_working_pilot_control(table) {
+ return None;
+ }
+ let id = identity_metadata(&engine.world, target).ok()?.original_id?;
+ component_cockpit(mission, id.0 as usize, target)
+}
+
+/// Whether the selected friendly warbot has a usable manual-control cockpit.
+#[must_use]
+pub fn can_control_warbot_remotely(
+ engine: &Engine,
+ hero: StartingCockpit,
+ target: ObjectHandle,
+) -> bool {
+ remote_cockpit(engine, hero, target).is_some()
+}
+
+/// Gives the hero manual control of a warbot while the hero remains at the bunker.
+pub fn control_warbot_remotely(
+ engine: &mut Engine,
+ hero: StartingCockpit,
+ target: ObjectHandle,
+) -> Option<StartingCockpit> {
+ let cockpit = remote_cockpit(engine, hero, target)?;
+ if let Some(patrol) = engine.loaded.as_mut()?.unit_patrol.as_mut() {
+ patrol.release_orders_for_manual_control(target);
+ }
+ start_warbot_control(engine, hero, cockpit, true);
+ Some(cockpit)
+}
+
+#[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,
+ };
+ 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() {
+ 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/Single.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 actor = warbot_rows(&engine, hero)[0].handle;
+ let hero_pose = transform_state(&engine.world, hero.handle).unwrap();
+ let vehicle_pose = transform_state(&engine.world, actor).unwrap();
+ assert!(crate::boarding::vehicle_interaction_distance_sq(
+ hero_pose.position.map(f32::from_bits),
+ vehicle_pose.position.map(f32::from_bits)
+ )
+ .is_none());
+ assert!(strategic_orders::stand(&mut engine, hero, actor));
+ let vehicle = control_warbot_remotely(&mut engine, hero, actor).unwrap();
+ assert_eq!(vehicle.handle, actor);
+ assert_eq!(warbot_rows(&engine, hero)[0].order_label, 0x1824);
+ for time in [100, 200, 300, 400, 500] {
+ let motion = plan_player_motion(
+ &engine,
+ vehicle,
+ PlayerMotion {
+ movement: [0.0, 1.0],
+ delta_seconds: 0.1,
+ ..PlayerMotion::default()
+ },
+ )
+ .unwrap()
+ .unwrap();
+ frame_with_player_motion(&mut engine, time, vehicle, motion, false).unwrap();
+ }
+ assert_ne!(
+ transform_state(&engine.world, actor).unwrap().position,
+ vehicle_pose.position
+ );
+ assert_eq!(
+ transform_state(&engine.world, hero.handle).unwrap(),
+ hero_pose
+ );
+ assert_eq!(disembark_warbot(&mut engine).unwrap(), Some(hero));
+ assert_eq!(
+ transform_state(&engine.world, hero.handle).unwrap(),
+ hero_pose
+ );
+ assert!(crate::player_vehicle(&engine).is_none());
+ }
+}