safeguard commands

This commit is contained in:
AviiNL
2023-12-23 08:53:46 +01:00
parent 8851594537
commit 05f4859f67
14 changed files with 749 additions and 282 deletions

View File

@@ -21,11 +21,14 @@ impl Resource for BogeyDope {}
pub fn bogey_dope(
mut commands: Commands,
cmd: ConsoleCommand<BogeyDope>,
mut cmd: ConsoleCommand<BogeyDope>,
awacs: Query<&Callsign>,
player: Query<(&Callsign, &Position)>,
npc: Query<(&Position, &Heading), (Without<Player>, With<Red>)>,
) {
let Some(Ok(BogeyDope)) = cmd.take() else {
return;
};
let Some(pilot) = &cmd.pilot else {
return; // no pilot
};

View File

@@ -0,0 +1,58 @@
use bevy::ecs::system::{Commands, Query, Resource};
use clap::Parser;
use guardian_commands::{ConsoleCommand, NamedCommand};
use guardian_core::{components::*, dcs::text::TextMessage, srs::voice::VoiceMessage};
use crate::tripwire::Tripwire;
#[derive(Parser, Debug)]
pub struct ClearTripwireCommand;
impl NamedCommand for ClearTripwireCommand {
fn name() -> &'static str {
"clear [tripwire|warning]"
}
}
impl Resource for ClearTripwireCommand {}
pub fn clear_tripwire(
mut commands: Commands,
mut cmd: ConsoleCommand<ClearTripwireCommand>,
callsign: Query<&Callsign>,
) {
let Some(Ok(ClearTripwireCommand)) = cmd.take() else {
return;
};
let Some(pilot) = &cmd.pilot else {
return; // no pilot
};
let Some(operator) = &cmd.operator else {
eprintln!("no operator");
return;
};
let Ok(p_callsign) = callsign.get(*pilot) else {
eprintln!("no player, died?");
return;
};
let Ok(a_callsign) = callsign.get(*operator) else {
eprintln!("no awacs, they died?");
return;
};
commands.entity(*pilot).remove::<Tripwire>();
let message = format!("{}, {}, tripwire cleared", p_callsign, a_callsign);
let message_voice = format!(
"{}, {}, tripwire cleared",
p_callsign.to_voice(),
a_callsign.to_voice(),
);
commands.spawn(TextMessage::new(message));
commands
.entity(*operator)
.insert(VoiceMessage::new(message_voice));
}

View File

@@ -2,13 +2,14 @@ use bevy::app::Plugin;
use guardian_commands::AddConsoleCommand;
mod bogeydope;
mod cleartripwire;
mod radiocheck;
mod tripwire;
use bogeydope::*;
use cleartripwire::*;
use radiocheck::*;
use tripwire::*;
pub struct CommandsPlugin;
impl Plugin for CommandsPlugin {
@@ -17,5 +18,6 @@ impl Plugin for CommandsPlugin {
app.add_console_command::<BogeyDope, _>(bogey_dope);
app.add_console_command::<RadioCheck, _>(radio_check);
app.add_console_command::<TripwireCommand, _>(set_tripwire);
app.add_console_command::<ClearTripwireCommand, _>(clear_tripwire);
}
}

View File

@@ -16,9 +16,12 @@ impl Resource for RadioCheck {}
pub fn radio_check(
mut commands: Commands,
cmd: ConsoleCommand<RadioCheck>,
mut cmd: ConsoleCommand<RadioCheck>,
callsign: Query<&Callsign>,
) {
let Some(Ok(RadioCheck)) = cmd.take() else {
return;
};
let Some(pilot) = &cmd.pilot else {
return; // no pilot
};

View File

@@ -18,9 +18,12 @@ impl Resource for TripwireCommand {}
pub fn set_tripwire(
mut commands: Commands,
cmd: ConsoleCommand<TripwireCommand>,
mut cmd: ConsoleCommand<TripwireCommand>,
callsign: Query<&Callsign>,
) {
let Some(Ok(TripwireCommand)) = cmd.take() else {
return;
};
let Some(pilot) = &cmd.pilot else {
return; // no pilot
};

View File

@@ -50,7 +50,7 @@ fn tripwire(
p_tripwire.reported.push(*n_id);
let bra = Braa::new(p_position, n_position, n_heading);
let message = format!("{}, {} {}", p_callsign, awacs, bra);
let message = format!("{}, {}, {}", p_callsign, awacs, bra);
let voice_message = format!(
"{}, {}, {}",
p_callsign.to_voice(),