From f0f0d0c550daa41bd7a1dda16dddf88f9552fc89 Mon Sep 17 00:00:00 2001 From: AviiNL Date: Thu, 28 Dec 2023 12:40:27 +0100 Subject: [PATCH] ignore (almost) stationary targets, they're probably ground-bound --- crates/guardian_commands/src/console.rs | 5 +---- crates/guardian_core/src/components/mod.rs | 2 ++ crates/guardian_core/src/components/velocity.rs | 14 ++++++++++++++ crates/guardian_core/src/dcs/mission.rs | 6 ++++++ src/commands/bogeydope.rs | 8 ++++++-- src/tripwire.rs | 8 ++++---- 6 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 crates/guardian_core/src/components/velocity.rs diff --git a/crates/guardian_commands/src/console.rs b/crates/guardian_commands/src/console.rs index f5fde72..80b5ce5 100644 --- a/crates/guardian_commands/src/console.rs +++ b/crates/guardian_commands/src/console.rs @@ -118,10 +118,7 @@ unsafe impl SystemParam for ConsoleCommand { let clap_command = T::command().no_binary_name(true); let arg_matches = clap_command.try_get_matches_from(command.args.iter()); - debug!( - "Trying to parse as `{}`. Result: {arg_matches:?}", - command.command_name - ); + debug!("Trying to parse as `{}`.", command.command_name); match arg_matches { Ok(matches) => match T::from_arg_matches(&matches) { diff --git a/crates/guardian_core/src/components/mod.rs b/crates/guardian_core/src/components/mod.rs index 724dba7..cea8731 100644 --- a/crates/guardian_core/src/components/mod.rs +++ b/crates/guardian_core/src/components/mod.rs @@ -10,6 +10,7 @@ mod side; mod srs_socket_addr; mod stt_base_url; mod unit_type; +mod velocity; pub use awacs::*; pub use callsign::*; @@ -23,3 +24,4 @@ pub use side::*; pub use srs_socket_addr::*; pub use stt_base_url::*; pub use unit_type::*; +pub use velocity::*; diff --git a/crates/guardian_core/src/components/velocity.rs b/crates/guardian_core/src/components/velocity.rs new file mode 100644 index 0000000..0860a25 --- /dev/null +++ b/crates/guardian_core/src/components/velocity.rs @@ -0,0 +1,14 @@ +use bevy::ecs::component::Component; +use dcs_grpc::dcs::common::v0::Vector; + +#[derive(Debug, Component)] +pub struct Velocity(pub Vector); + +impl Velocity { + pub fn speed(&self) -> f64 { + let x = self.0.x; + let y = self.0.y; + let z = self.0.z; + (x * x + y * y + z * z).sqrt() + } +} diff --git a/crates/guardian_core/src/dcs/mission.rs b/crates/guardian_core/src/dcs/mission.rs index 7c5420e..36fed43 100644 --- a/crates/guardian_core/src/dcs/mission.rs +++ b/crates/guardian_core/src/dcs/mission.rs @@ -173,6 +173,12 @@ fn update_units( e.insert(Heading(orientation.heading)); } + if let Some(velocity) = &event.velocity { + if let Some(velocity) = &velocity.velocity { + e.insert(Velocity(velocity.clone())); + } + } + if let Some(playername) = &event.player_name { e.insert(Player::new(playername.clone())); } diff --git a/src/commands/bogeydope.rs b/src/commands/bogeydope.rs index 7f3e194..96aee84 100644 --- a/src/commands/bogeydope.rs +++ b/src/commands/bogeydope.rs @@ -25,7 +25,7 @@ pub fn bogey_dope( mut cmd: ConsoleCommand, awacs: Query<&Callsign>, player: Query<(&Callsign, &Position)>, - npc: Query<(&Position, &Heading), (Without, With)>, + npc: Query<(&Position, &Heading, &Velocity), (Without, With)>, ) { let Some(Ok(BogeyDope)) = cmd.take() else { return; @@ -49,7 +49,11 @@ pub fn bogey_dope( let mut distance: f64 = f64::MAX; let mut n = (None, None); - for (n_pos, n_heading) in npc.iter() { + for (n_pos, n_heading, n_velocity) in npc.iter() { + if n_velocity.speed() < 10.0 { + // ignore slow/on-ground units + continue; + } let d = p_pos.distance_to_nmi(n_pos); if d < distance { distance = d; diff --git a/src/tripwire.rs b/src/tripwire.rs index 04233da..90ab9e8 100644 --- a/src/tripwire.rs +++ b/src/tripwire.rs @@ -27,7 +27,7 @@ fn tripwire( mut commands: Commands, awacs: Query<(Entity, &Callsign, &Radio), (With, With, With)>, mut players: Query<(&Callsign, &Position, &RadioInfo, &mut Tripwire), With>, - npc: Query<(&Id, &Position, &Heading), (Without, With)>, + npc: Query<(&Id, &Position, &Heading, &Velocity), (Without, With)>, ) { // get the players radio frequencies // match the tuned frequency with one of the awacs' @@ -44,9 +44,9 @@ fn tripwire( continue; } - for (n_id, n_position, n_heading) in npc.iter() { - if n_position.angels() == 0 { - // ignore on-ground units + for (n_id, n_position, n_heading, n_velocity) in npc.iter() { + if n_velocity.speed() < 10.0 { + // ignore slow/on-ground units continue; } let distance = n_position.distance_to_nmi(p_position);