From 05da53f0344416a5f14211a73f1f48d72c88b954 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 14:38:56 +0400 Subject: feat(ui): drive a strategic warbot with an automatic gunner --- crates/fparkan-runtime/src/boarding.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'crates/fparkan-runtime/src/boarding.rs') diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs index 28ed6f61..b8ec9518 100644 --- a/crates/fparkan-runtime/src/boarding.rs +++ b/crates/fparkan-runtime/src/boarding.rs @@ -12,7 +12,10 @@ use fparkan_world::{ pub(super) const WARBOT_CLASS: u32 = 0x0100_8000; mod remote_control; -pub use remote_control::{can_control_warbot_remotely, control_warbot_remotely}; +pub use remote_control::{ + can_control_warbot_remotely, control_warbot_remotely, remote_auto_gunner_weapons, + RemoteWarbotControl, +}; /// Ownership and cockpit changes from one Enter command. pub struct VehicleEntry { @@ -34,13 +37,19 @@ impl VehicleEntry { pub(super) struct Boarding { pub(super) cockpit: StartingCockpit, pub(super) hero: StartingCockpit, - pub(super) remote: bool, + pub(super) remote: Option, pub(super) can_fly: bool, pub(super) ground: Option, pub(super) on_building_floor: bool, pub(super) flight_velocity: [f32; 3], } +impl Boarding { + pub(super) fn controls_weapons(self) -> bool { + self.remote != Some(RemoteWarbotControl::AutoGunner) + } +} + /// The vehicle cockpit while the player is aboard. #[must_use] pub fn player_vehicle(engine: &Engine) -> Option { @@ -167,7 +176,7 @@ pub fn board_friendly_warbot( ..hero_pose }, )?; - start_warbot_control(engine, hero, cockpit, false); + start_warbot_control(engine, hero, cockpit, None); Ok(Some(cockpit)) } @@ -175,7 +184,7 @@ fn start_warbot_control( engine: &mut Engine, hero: StartingCockpit, cockpit: StartingCockpit, - remote: bool, + remote: Option, ) { let can_fly = crate::player_motion::warbot_can_fly(engine, cockpit.object_index); if let Some(mission) = &mut engine.loaded { @@ -306,7 +315,8 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result, return Ok(None); }; let mut pose = transform_state(&engine.world, hero.handle)?; - let vehicle_pose = (!remote) + let vehicle_pose = remote + .is_none() .then(|| transform_state(&engine.world, vehicle.handle).ok()) .flatten(); if let Some(vehicle_pose) = vehicle_pose { @@ -338,7 +348,7 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result, pose.position = exit.map(f32::to_bits); pose.orientation[2] = yaw.to_bits(); set_transform(&mut engine.world, hero.handle, pose)?; - } else if !remote && !can_fly && !on_building_floor { + } else if remote.is_none() && !can_fly && !on_building_floor { // The passenger still has the destroyed chassis's root height. let [x, y, _] = pose.position.map(f32::from_bits); if let Some(ground) = mission @@ -363,7 +373,7 @@ pub(super) fn move_passenger( vehicle_pose: TransformState, ) -> Option<(ObjectHandle, TransformState)> { let boarding = engine.loaded.as_ref()?.boarding.as_ref()?; - if boarding.remote || boarding.cockpit.handle != cockpit.handle { + if boarding.remote.is_some() || boarding.cockpit.handle != cockpit.handle { return None; } let hero = boarding.hero; -- cgit v1.2.3