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.rs24
-rw-r--r--crates/fparkan-runtime/src/boarding/remote_control.rs93
-rw-r--r--crates/fparkan-runtime/src/lib.rs3
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs17
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs6
5 files changed, 118 insertions, 25 deletions
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<RemoteWarbotControl>,
pub(super) can_fly: bool,
pub(super) ground: Option<crate::ground_support::GroundSupport>,
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<StartingCockpit> {
@@ -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<RemoteWarbotControl>,
) {
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<Option<StartingCockpit>,
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<Option<StartingCockpit>,
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;
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");
+ }
}
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 2300adc3..5c09bd2d 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -185,7 +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, select_boarding_target, VehicleEntry,
+ enter_vehicle, player_vehicle, remote_auto_gunner_weapons, 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/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs
index 59c9ec64..799f0009 100644
--- a/crates/fparkan-runtime/src/unit_combat.rs
+++ b/crates/fparkan-runtime/src/unit_combat.rs
@@ -60,6 +60,7 @@ pub fn autonomous_firing_effect_phases(
.loaded
.as_ref()
.and_then(|mission| mission.boarding)
+ .filter(|boarding| boarding.controls_weapons())
.map(|boarding| boarding.cockpit.handle);
engine
.autodemo_combat
@@ -363,6 +364,16 @@ impl AutoDemoCombat {
&self.pose_failures
}
+ pub(super) fn weapons(&self, handle: ObjectHandle) -> Option<&PlayerWeapons> {
+ Some(
+ &self
+ .units
+ .iter()
+ .find(|unit| unit.handle == handle)?
+ .weapons,
+ )
+ }
+
pub(super) fn turret_aim(&self, handle: ObjectHandle, component: usize) -> Option<TurretAim> {
self.units
.iter()
@@ -624,9 +635,9 @@ impl AutoDemoCombat {
.and_then(|identity| identity.owner_id);
let guard = owner
.is_some_and(|owner| self.guard_clans.get(usize::from(owner.0)) == Some(&true));
- let manually_controlled = mission
- .boarding
- .is_some_and(|boarding| boarding.cockpit.handle == unit.handle);
+ let manually_controlled = mission.boarding.is_some_and(|boarding| {
+ boarding.cockpit.handle == unit.handle && boarding.controls_weapons()
+ });
// shortcut: free warbots defend from their current position until the
// default Behavior task and its pursuit rules are wired.
let defends_from_position = matches!(
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index 1d83eaa8..594a4b7f 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -581,9 +581,9 @@ impl UnitPatrol {
}
for unit in &mut state.units {
if self.is_leaving_factory(unit.handle)
- || mission
- .boarding
- .is_some_and(|control| control.remote && control.cockpit.handle == unit.handle)
+ || mission.boarding.is_some_and(|control| {
+ control.remote.is_some() && control.cockpit.handle == unit.handle
+ })
{
continue;
}