ignore (almost) stationary targets, they're probably ground-bound

This commit is contained in:
AviiNL
2023-12-28 12:40:27 +01:00
parent a11402e763
commit f0f0d0c550
6 changed files with 33 additions and 10 deletions

View File

@@ -118,10 +118,7 @@ unsafe impl<T: Command> SystemParam for ConsoleCommand<T> {
let clap_command = T::command().no_binary_name(true); let clap_command = T::command().no_binary_name(true);
let arg_matches = clap_command.try_get_matches_from(command.args.iter()); let arg_matches = clap_command.try_get_matches_from(command.args.iter());
debug!( debug!("Trying to parse as `{}`.", command.command_name);
"Trying to parse as `{}`. Result: {arg_matches:?}",
command.command_name
);
match arg_matches { match arg_matches {
Ok(matches) => match T::from_arg_matches(&matches) { Ok(matches) => match T::from_arg_matches(&matches) {

View File

@@ -10,6 +10,7 @@ mod side;
mod srs_socket_addr; mod srs_socket_addr;
mod stt_base_url; mod stt_base_url;
mod unit_type; mod unit_type;
mod velocity;
pub use awacs::*; pub use awacs::*;
pub use callsign::*; pub use callsign::*;
@@ -23,3 +24,4 @@ pub use side::*;
pub use srs_socket_addr::*; pub use srs_socket_addr::*;
pub use stt_base_url::*; pub use stt_base_url::*;
pub use unit_type::*; pub use unit_type::*;
pub use velocity::*;

View File

@@ -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()
}
}

View File

@@ -173,6 +173,12 @@ fn update_units(
e.insert(Heading(orientation.heading)); 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 { if let Some(playername) = &event.player_name {
e.insert(Player::new(playername.clone())); e.insert(Player::new(playername.clone()));
} }

View File

@@ -25,7 +25,7 @@ pub fn bogey_dope(
mut cmd: ConsoleCommand<BogeyDope>, mut cmd: ConsoleCommand<BogeyDope>,
awacs: Query<&Callsign>, awacs: Query<&Callsign>,
player: Query<(&Callsign, &Position)>, player: Query<(&Callsign, &Position)>,
npc: Query<(&Position, &Heading), (Without<Player>, With<Red>)>, npc: Query<(&Position, &Heading, &Velocity), (Without<Player>, With<Red>)>,
) { ) {
let Some(Ok(BogeyDope)) = cmd.take() else { let Some(Ok(BogeyDope)) = cmd.take() else {
return; return;
@@ -49,7 +49,11 @@ pub fn bogey_dope(
let mut distance: f64 = f64::MAX; let mut distance: f64 = f64::MAX;
let mut n = (None, None); 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); let d = p_pos.distance_to_nmi(n_pos);
if d < distance { if d < distance {
distance = d; distance = d;

View File

@@ -27,7 +27,7 @@ fn tripwire(
mut commands: Commands, mut commands: Commands,
awacs: Query<(Entity, &Callsign, &Radio), (With<Awacs>, With<Blue>, With<Radio>)>, awacs: Query<(Entity, &Callsign, &Radio), (With<Awacs>, With<Blue>, With<Radio>)>,
mut players: Query<(&Callsign, &Position, &RadioInfo, &mut Tripwire), With<Player>>, mut players: Query<(&Callsign, &Position, &RadioInfo, &mut Tripwire), With<Player>>,
npc: Query<(&Id, &Position, &Heading), (Without<Player>, With<Red>)>, npc: Query<(&Id, &Position, &Heading, &Velocity), (Without<Player>, With<Red>)>,
) { ) {
// get the players radio frequencies // get the players radio frequencies
// match the tuned frequency with one of the awacs' // match the tuned frequency with one of the awacs'
@@ -44,9 +44,9 @@ fn tripwire(
continue; continue;
} }
for (n_id, n_position, n_heading) in npc.iter() { for (n_id, n_position, n_heading, n_velocity) in npc.iter() {
if n_position.angels() == 0 { if n_velocity.speed() < 10.0 {
// ignore on-ground units // ignore slow/on-ground units
continue; continue;
} }
let distance = n_position.distance_to_nmi(p_position); let distance = n_position.distance_to_nmi(p_position);