aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/boarding.rs11
-rw-r--r--crates/fparkan-runtime/src/boarding/remote_control.rs73
-rw-r--r--crates/fparkan-runtime/src/lib.rs4
-rw-r--r--crates/fparkan-runtime/src/player_motion.rs13
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs4
5 files changed, 91 insertions, 14 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs
index b8ec9518..c453b74e 100644
--- a/crates/fparkan-runtime/src/boarding.rs
+++ b/crates/fparkan-runtime/src/boarding.rs
@@ -13,8 +13,8 @@ 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, remote_auto_gunner_weapons,
- RemoteWarbotControl,
+ can_control_warbot_remotely, control_warbot_remotely, remote_automatic_weapons,
+ remote_warbot_control, RemoteWarbotControl,
};
/// Ownership and cockpit changes from one Enter command.
@@ -45,8 +45,13 @@ pub(super) struct Boarding {
}
impl Boarding {
+ pub(super) fn controls_chassis(self) -> bool {
+ self.remote != Some(RemoteWarbotControl::Autopilot)
+ }
+
pub(super) fn controls_weapons(self) -> bool {
- self.remote != Some(RemoteWarbotControl::AutoGunner)
+ self.remote
+ .is_none_or(|mode| mode == RemoteWarbotControl::Manual)
}
}
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);
+ }
}
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 5c09bd2d..f9f83c0c 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -185,8 +185,8 @@ pub use aim_convergence::{projectile_sight_target, turret_sight_points};
pub use autodemo::{autodemo_camera, AutoDemoCamera, AutoDemoReinforcement, AutoDemoView};
pub use boarding::{
board_friendly_warbot, can_control_warbot_remotely, control_warbot_remotely, disembark_warbot,
- enter_vehicle, player_vehicle, remote_auto_gunner_weapons, select_boarding_target,
- RemoteWarbotControl, VehicleEntry,
+ enter_vehicle, player_vehicle, remote_automatic_weapons, remote_warbot_control,
+ select_boarding_target, RemoteWarbotControl, VehicleEntry,
};
pub use building_door::{has_proximity_doors, sample_capture_doors, sample_proximity_doors};
pub use capture_barrier::sample_capture_barrier;
diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs
index 73129d87..be910936 100644
--- a/crates/fparkan-runtime/src/player_motion.rs
+++ b/crates/fparkan-runtime/src/player_motion.rs
@@ -429,7 +429,16 @@ fn plan_player_steps(
let boarded = mission
.boarding
.filter(|boarding| boarding.cockpit.handle == cockpit.handle);
- let flight = boarded.filter(|boarding| boarding.can_fly).map(|boarding| {
+ let driving = boarded.filter(|boarding| boarding.controls_chassis());
+ if boarded.is_some() && driving.is_none() {
+ input.movement = [0.0; 2];
+ input.climb = 0.0;
+ if !input.look_around {
+ input.mouse_x = 0.0;
+ input.mouse_y = 0.0;
+ }
+ }
+ let flight = driving.filter(|boarding| boarding.can_fly).map(|boarding| {
let profile = mission
.control_device_tables
.iter()
@@ -443,7 +452,7 @@ fn plan_player_steps(
}
});
let flying = flight.is_some();
- let chassis_ground = boarded.and_then(|boarding| boarding.ground);
+ let chassis_ground = driving.and_then(|boarding| boarding.ground);
let hero_profile = if mission.local_hero == Some(cockpit.handle) {
mission
.control_device_tables
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index 594a4b7f..c25b309f 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -582,7 +582,9 @@ impl UnitPatrol {
for unit in &mut state.units {
if self.is_leaving_factory(unit.handle)
|| mission.boarding.is_some_and(|control| {
- control.remote.is_some() && control.cockpit.handle == unit.handle
+ control.remote.is_some()
+ && control.controls_chassis()
+ && control.cockpit.handle == unit.handle
})
{
continue;