Initial Commit

This commit is contained in:
AviiNL
2023-12-22 04:50:17 +01:00
parent 15f764aae8
commit f79b6b5dfb
41 changed files with 4379 additions and 270 deletions

96
src/tripwire.rs Normal file
View File

@@ -0,0 +1,96 @@
use bevy::{
app::{Plugin, Update},
ecs::{
component::Component,
entity::Entity,
query::{Added, With, Without},
system::{Commands, Query},
},
};
use guardian_core::{
components::*,
dcs::text::TextMessage,
srs::{voice::VoiceMessage, Radio, RadioInfo},
};
use crate::braa::Braa;
pub struct TripwirePlugin;
impl Plugin for TripwirePlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app.add_systems(Update, tripwire);
}
}
// this will be on a tripwire command event (from srs), instead of Added<Player>, not everyone may want it; opt-in over opt-out
// fn add_tripwire(mut commands: Commands, players: Query<Entity, Added<Player>>) {
// for ent in players.iter() {
// commands.entity(ent).insert(Tripwire {
// range: 2.0,
// reported: vec![],
// });
// }
// }
fn tripwire(
mut commands: Commands,
awacs: Query<(Entity, &Callsign, &Radio), (With<Awacs>, With<Blue>, With<Radio>)>,
mut players: Query<(&Callsign, &Position, &RadioInfo, &mut Tripwire), With<Player>>,
npc: Query<(&Id, &Position, &Heading), (Without<Player>, With<Red>)>,
) {
// get the players radio frequencies
// match the tuned frequency with one of the awacs'
// broadcast message on that ferquency and as that awacs
for (ent, awacs, radio) in awacs.iter() {
for (p_callsign, p_position, radioinfo, mut p_tripwire) in players.iter_mut() {
// check if user is on the same frequency as awacs
if !radioinfo
.radios
.iter()
.any(|f| f.freq as u64 == radio.frequency && f.modulation == radio.modulation)
{
continue;
}
for (n_id, n_position, n_heading) in npc.iter() {
let distance = n_position.distance_to_nmi(p_position);
if distance <= p_tripwire.range && !p_tripwire.reported.contains(n_id) {
p_tripwire.reported.push(*n_id);
let bra = Braa::new(p_position, n_position, n_heading);
let message = format!("{}, {} {}", p_callsign, awacs, bra);
let voice_message = format!(
"{}, {}, {}",
p_callsign.to_voice(),
awacs.to_voice(),
bra.to_voice()
);
commands.spawn(TextMessage::new(message));
commands
.entity(ent)
.insert(VoiceMessage::new(voice_message));
} else if distance > p_tripwire.range && p_tripwire.reported.contains(n_id) {
p_tripwire.reported.retain(|b| b != n_id);
}
}
}
}
}
#[derive(Debug, Component)]
pub struct Tripwire {
range: f64,
reported: Vec<Id>,
}
impl Tripwire {
pub fn new(distance: i32) -> Self {
Self {
range: distance as f64,
reported: vec![],
}
}
}