aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-assets/src/strategic_roster.rs72
-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
6 files changed, 135 insertions, 42 deletions
diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs
index 15ccf018..cc4741ee 100644
--- a/crates/fparkan-assets/src/strategic_roster.rs
+++ b/crates/fparkan-assets/src/strategic_roster.rs
@@ -24,12 +24,25 @@ const CLOSE_LEFT: u32 = 5 + TITLE_WIDTH;
const TEXT_WIDTH: u32 = 248;
const TEXT_LEFT: u32 = 10 + 19 * 2 + 5 + 10;
+/// A cockpit control button in its left-to-right card position.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub enum CockpitControl {
+ Manual,
+ AutoGunner,
+ Autopilot,
+}
+
+const COCKPIT_CONTROLS: [CockpitControl; 3] = [
+ CockpitControl::Manual,
+ CockpitControl::AutoGunner,
+ CockpitControl::Autopilot,
+];
+
/// The visible interactive area of the original list.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ListHit {
Close,
- ManualControl,
- AutoGunner,
+ Cockpit(CockpitControl),
Row(usize),
}
@@ -44,11 +57,13 @@ pub fn hit_test([x, y]: [f32; 2], row_count: usize) -> Option<ListHit> {
return Some(ListHit::Close);
}
// iron3d+0x85c70 expands the icon rectangle by two logical pixels.
- if row_count != 0 && (10.0..29.0).contains(&x) && (89.0..108.0).contains(&y) {
- return Some(ListHit::ManualControl);
- }
- if row_count != 0 && (34.0..53.0).contains(&x) && (89.0..108.0).contains(&y) {
- return Some(ListHit::AutoGunner);
+ if row_count != 0 && (89.0..108.0).contains(&y) {
+ for (index, control) in COCKPIT_CONTROLS.into_iter().enumerate() {
+ let left = 10.0 + 24.0 * index as f32;
+ if (left..left + 19.0).contains(&x) {
+ return Some(ListHit::Cockpit(control));
+ }
+ }
}
let y = (y as u32).checked_sub(ROW_TOP)?;
let row = (y / ROW_PITCH) as usize;
@@ -86,7 +101,7 @@ pub struct RosterImages {
end: RgbaImage,
class_icon: RgbaImage,
chassis_icons: [RgbaImage; 4],
- cockpit_controls: [RgbaImage; 3],
+ cockpit_controls: [RgbaImage; 4],
orders: OrderImages,
}
@@ -181,6 +196,7 @@ impl RosterImages {
"short_button_frame_off",
"buildscreen_hq_icon",
"botscreen_autogunner_icon",
+ "botscreen_autodriver_icon",
],
)?,
orders: OrderImages::load(vfs)?,
@@ -207,11 +223,12 @@ impl RosterImages {
} else {
[128; 3]
};
- let [frame, manual, gunner] = &self.cockpit_controls;
- stamp(&mut panel, frame, [9, 88, 30, 109], tint);
- stamp(&mut panel, manual, [12, 91, 27, 106], tint);
- stamp(&mut panel, frame, [33, 88, 54, 109], tint);
- stamp(&mut panel, gunner, [36, 91, 51, 106], tint);
+ let [frame, icons @ ..] = &self.cockpit_controls;
+ for (index, icon) in icons.iter().enumerate() {
+ let x = 9 + 24 * index as u32;
+ stamp(&mut panel, frame, [x, 88, x + 21, 109], tint);
+ stamp(&mut panel, icon, [x + 3, 91, x + 18, 106], tint);
+ }
}
for (index, row) in rows.iter().take(19).enumerate() {
let y = ROW_TOP + index as u32 * ROW_PITCH;
@@ -321,21 +338,20 @@ mod tests {
}
#[test]
- fn manual_control_uses_the_enlarged_native_hit_box() {
- assert_eq!(hit_test([61.0, 89.0], 3), Some(ListHit::ManualControl));
- assert_eq!(hit_test([79.0, 107.0], 3), Some(ListHit::ManualControl));
- assert_eq!(hit_test([80.0, 107.0], 3), None);
- assert_eq!(hit_test([61.0, 108.0], 3), None);
- assert_eq!(hit_test([61.0, 89.0], 0), None);
- }
-
- #[test]
- fn auto_gunner_uses_its_own_native_hit_box() {
- assert_eq!(hit_test([84.0, 89.0], 3), None);
- assert_eq!(hit_test([85.0, 89.0], 3), Some(ListHit::AutoGunner));
- assert_eq!(hit_test([103.0, 107.0], 3), Some(ListHit::AutoGunner));
- assert_eq!(hit_test([104.0, 107.0], 3), None);
- assert_eq!(hit_test([85.0, 108.0], 3), None);
+ fn cockpit_buttons_use_enlarged_hit_boxes_with_gaps() {
+ for (x, button) in [
+ (61.0, super::CockpitControl::Manual),
+ (85.0, super::CockpitControl::AutoGunner),
+ (109.0, super::CockpitControl::Autopilot),
+ ] {
+ let hit = Some(ListHit::Cockpit(button));
+ assert_eq!(hit_test([x, 89.0], 3), hit);
+ assert_eq!(hit_test([x + 18.0, 107.0], 3), hit);
+ assert_eq!(hit_test([x - 1.0, 89.0], 3), None);
+ assert_eq!(hit_test([x + 19.0, 107.0], 3), None);
+ assert_eq!(hit_test([x, 108.0], 3), None);
+ assert_eq!(hit_test([x, 89.0], 0), None);
+ }
}
#[test]
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;