|
| 1 | +use std::time::Duration; |
| 2 | + |
| 3 | +use bevy::prelude::*; |
| 4 | + |
| 5 | +use linear_algebra::{point, vector}; |
| 6 | +use scenario::scenario; |
| 7 | +use spl_network_messages::{GameState, Penalty, PlayerNumber, Team}; |
| 8 | + |
| 9 | +use bevyhavior_simulator::{ |
| 10 | + ball::BallResource, |
| 11 | + game_controller::GameControllerCommand, |
| 12 | + robot::Robot, |
| 13 | + time::{Ticks, TicksTime}, |
| 14 | +}; |
| 15 | +use types::{ball_position::SimulatorBallState, motion_command::MotionCommand}; |
| 16 | + |
| 17 | +#[scenario] |
| 18 | +fn standing_searcher(app: &mut App) { |
| 19 | + app.add_systems(Startup, startup); |
| 20 | + app.add_systems(Update, update); |
| 21 | +} |
| 22 | + |
| 23 | +fn startup( |
| 24 | + mut commands: Commands, |
| 25 | + mut game_controller_commands: EventWriter<GameControllerCommand>, |
| 26 | +) { |
| 27 | + for number in [ |
| 28 | + PlayerNumber::One, |
| 29 | + PlayerNumber::Two, |
| 30 | + PlayerNumber::Three, |
| 31 | + PlayerNumber::Four, |
| 32 | + PlayerNumber::Five, |
| 33 | + PlayerNumber::Seven, |
| 34 | + ] { |
| 35 | + commands.spawn(Robot::new(number)); |
| 36 | + } |
| 37 | + game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready)); |
| 38 | +} |
| 39 | + |
| 40 | +fn update( |
| 41 | + time: Res<Time<Ticks>>, |
| 42 | + mut ball: ResMut<BallResource>, |
| 43 | + mut exit: EventWriter<AppExit>, |
| 44 | + mut robots: Query<&mut Robot>, |
| 45 | + mut game_controller_commands: EventWriter<GameControllerCommand>, |
| 46 | +) { |
| 47 | + if time.ticks() == 4150 { |
| 48 | + game_controller_commands.send(GameControllerCommand::Penalize( |
| 49 | + PlayerNumber::Two, |
| 50 | + Penalty::Manual { |
| 51 | + remaining: Duration::from_secs(1), |
| 52 | + }, |
| 53 | + Team::Hulks, |
| 54 | + )); |
| 55 | + } |
| 56 | + |
| 57 | + if time.ticks() == 4155 { |
| 58 | + game_controller_commands.send(GameControllerCommand::Unpenalize( |
| 59 | + PlayerNumber::Two, |
| 60 | + Team::Hulks, |
| 61 | + )); |
| 62 | + } |
| 63 | + |
| 64 | + if time.ticks() == 4200 { |
| 65 | + ball.state = None; |
| 66 | + } |
| 67 | + |
| 68 | + if time.ticks() == 4660 { |
| 69 | + if let MotionCommand::Stand { .. } = robots |
| 70 | + .iter_mut() |
| 71 | + .find(|robot| robot.parameters.player_number == PlayerNumber::Two) |
| 72 | + .unwrap() |
| 73 | + .database |
| 74 | + .main_outputs |
| 75 | + .motion_command |
| 76 | + { |
| 77 | + println!("Standing searcher at penalty walk-in"); |
| 78 | + exit.send(AppExit::from_code(1)); |
| 79 | + } |
| 80 | + if let MotionCommand::Walk { .. } = robots |
| 81 | + .iter_mut() |
| 82 | + .find(|robot| robot.parameters.player_number == PlayerNumber::Three) |
| 83 | + .unwrap() |
| 84 | + .database |
| 85 | + .main_outputs |
| 86 | + .motion_command |
| 87 | + { |
| 88 | + println!("Moving searcher after ball loss"); |
| 89 | + exit.send(AppExit::from_code(1)); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + if time.ticks() == 5500 { |
| 94 | + ball.state = Some(SimulatorBallState { |
| 95 | + position: point![-2.7, -0.2], |
| 96 | + velocity: vector![0.0, 0.0], |
| 97 | + }); |
| 98 | + } |
| 99 | + if time.ticks() == 6000 { |
| 100 | + ball.state = None; |
| 101 | + } |
| 102 | + if time.ticks() == 6750 { |
| 103 | + ball.state = Some(SimulatorBallState { |
| 104 | + position: point![4.0, -0.2], |
| 105 | + velocity: vector![0.0, 0.0], |
| 106 | + }); |
| 107 | + } |
| 108 | + if time.ticks() == 7200 { |
| 109 | + ball.state = None; |
| 110 | + } |
| 111 | + if time.ticks() >= 10_000 { |
| 112 | + println!("Done"); |
| 113 | + exit.send(AppExit::Success); |
| 114 | + } |
| 115 | +} |
0 commit comments