aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/player_motion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/player_motion.rs')
-rw-r--r--crates/fparkan-runtime/src/player_motion.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs
index be910936..6733f921 100644
--- a/crates/fparkan-runtime/src/player_motion.rs
+++ b/crates/fparkan-runtime/src/player_motion.rs
@@ -72,6 +72,7 @@ pub struct PlayerMotionStep {
flight_velocity: Option<[f32; 3]>,
hero_walk_velocity: Option<[f32; 2]>,
hero_look: Option<HeroLook>,
+ turret: Option<crate::TurretAim>,
max_floor_clearance: f32,
previous_terrain_height: Option<f32>,
terrain_height: Option<f32>,
@@ -228,6 +229,7 @@ mod tests {
flight_velocity: None,
hero_walk_velocity: None,
hero_look: None,
+ turret: None,
max_floor_clearance: FLOOR_CLEARANCE,
previous_terrain_height: None,
terrain_height: Some(11.5),
@@ -268,6 +270,7 @@ mod tests {
flight_velocity: None,
hero_walk_velocity: None,
hero_look: None,
+ turret: None,
max_floor_clearance: 1.25,
previous_terrain_height: Some(10.0),
terrain_height: Some(10.0),
@@ -293,6 +296,7 @@ mod tests {
flight_velocity: None,
hero_walk_velocity: None,
hero_look: None,
+ turret: None,
max_floor_clearance: FLOOR_CLEARANCE,
previous_terrain_height: None,
terrain_height: None,
@@ -429,6 +433,31 @@ fn plan_player_steps(
let boarded = mission
.boarding
.filter(|boarding| boarding.cockpit.handle == cockpit.handle);
+ if let Some(aim) = boarded.and_then(|boarding| boarding.turret) {
+ if [input.mouse_x, input.mouse_y] == [0.0; 2] && !mission.hero_look.has_state() {
+ return Ok(None);
+ }
+ if ![input.mouse_x, input.mouse_y]
+ .into_iter()
+ .all(f32::is_finite)
+ {
+ return Err(EngineError::Movement("invalid gunner input".into()));
+ }
+ let (look, aim) =
+ crate::bunker_control::advance(engine, cockpit, input, mission.hero_look, aim);
+ let mut step = plan_motion(
+ &mission.terrain,
+ pose,
+ aim.elevation,
+ 0.0,
+ None,
+ [0.0; 2],
+ PlayerMotion::default(),
+ )?;
+ step.hero_look = Some(look);
+ step.turret = Some(aim);
+ return Ok(Some(step));
+ }
let driving = boarded.filter(|boarding| boarding.controls_chassis());
if boarded.is_some() && driving.is_none() {
input.movement = [0.0; 2];
@@ -633,6 +662,9 @@ pub(super) fn commit_motion_state(
if boarding.cockpit.handle != cockpit.handle {
return;
}
+ if let Some(aim) = step.turret {
+ boarding.turret = Some(aim);
+ }
if let Some(velocity) = step.flight_velocity {
boarding.flight_velocity = if blocked { [0.0; 3] } else { velocity };
} else if !blocked && step.sweep.is_some() {
@@ -743,6 +775,7 @@ fn plan_motion(
flight_velocity,
hero_walk_velocity: None,
hero_look: None,
+ turret: None,
max_floor_clearance: FLOOR_CLEARANCE,
previous_terrain_height,
terrain_height,