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