aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-assets/src/strategic_roster.rs34
-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
6 files changed, 145 insertions, 32 deletions
diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs
index 86d54b0d..15ccf018 100644
--- a/crates/fparkan-assets/src/strategic_roster.rs
+++ b/crates/fparkan-assets/src/strategic_roster.rs
@@ -29,6 +29,7 @@ const TEXT_LEFT: u32 = 10 + 19 * 2 + 5 + 10;
pub enum ListHit {
Close,
ManualControl,
+ AutoGunner,
Row(usize),
}
@@ -46,6 +47,9 @@ pub fn hit_test([x, y]: [f32; 2], row_count: usize) -> Option<ListHit> {
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);
+ }
let y = (y as u32).checked_sub(ROW_TOP)?;
let row = (y / ROW_PITCH) as usize;
(row < row_count && y % ROW_PITCH < ROW_HEIGHT).then_some(ListHit::Row(row))
@@ -82,7 +86,7 @@ pub struct RosterImages {
end: RgbaImage,
class_icon: RgbaImage,
chassis_icons: [RgbaImage; 4],
- manual_control: [RgbaImage; 2],
+ cockpit_controls: [RgbaImage; 3],
orders: OrderImages,
}
@@ -170,10 +174,14 @@ impl RosterImages {
end,
class_icon: icon(49, 110)?,
chassis_icons: [icon(97, 94)?, icon(49, 94)?, icon(65, 94)?, icon(81, 94)?],
- manual_control: load_ui_sprites(
+ cockpit_controls: load_ui_sprites(
vfs,
"ui/hq.cfg",
- ["short_button_frame_off", "buildscreen_hq_icon"],
+ [
+ "short_button_frame_off",
+ "buildscreen_hq_icon",
+ "botscreen_autogunner_icon",
+ ],
)?,
orders: OrderImages::load(vfs)?,
})
@@ -184,7 +192,7 @@ impl RosterImages {
&self,
rows: &[Row<'_>],
card: &[Option<CardLine<'_>>],
- manual_control_enabled: bool,
+ cockpit_controls_enabled: bool,
orders: Option<([&str; 6], Option<RosterOrder>)>,
) -> Result<RgbaImage, String> {
let mut panel = self.background.clone();
@@ -194,13 +202,16 @@ impl RosterImages {
let name = self.font.centered_line(row.label, width as u16, 16)?;
stamp(&mut panel, &name, [49, 25, 49 + width, 41], [255, 255, 0]);
warbot_card::paint(&self.font, &mut panel, card)?;
- let tint = if manual_control_enabled {
+ let tint = if cockpit_controls_enabled {
[255; 3]
} else {
[128; 3]
};
- stamp(&mut panel, &self.manual_control[0], [9, 88, 30, 109], tint);
- stamp(&mut panel, &self.manual_control[1], [12, 91, 27, 106], tint);
+ 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);
}
for (index, row) in rows.iter().take(19).enumerate() {
let y = ROW_TOP + index as u32 * ROW_PITCH;
@@ -319,6 +330,15 @@ mod tests {
}
#[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);
+ }
+
+ #[test]
fn original_durability_colours_follow_the_rounded_health_percentage() {
let durability_fill = |percent| super::durability_fill(percent, TEXT_WIDTH);
assert_eq!(durability_fill(0), None);
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;
}