Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions yggdrasil/src/behavior/roles/striker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
vision::ball_detection::ball_tracker::BallTracker,
};

use std::time::Duration;
use std::time::{Duration, Instant};

const WALK_WITH_BALL_ANGLE: f32 = 0.3;
const ALIGN_WITH_BALL_DISTANCE: f32 = 0.3;
Expand All @@ -47,14 +47,37 @@ fn in_set_play(
gamecontroller_message: Option<Res<GameControllerMessage>>,
primary_state: Res<PrimaryState>,
player_config: Res<PlayerConfig>,
mut whistle_time: Local<Option<Instant>>,
) -> bool {
if let Some(message) = gamecontroller_message {
return match *primary_state {
// return true if there is a set play OR we are in Playing state with a secondary time (Kick-Off)
PrimaryState::Playing { .. } => {
PrimaryState::Playing {
whistle_in_set: false,
} => {
*whistle_time = None;

(message.set_play != SetPlay::None || message.secondary_time != 0)
&& message.kicking_team != player_config.team_number
}
PrimaryState::Playing {
whistle_in_set: true,
} => {
if message.kicking_team == player_config.team_number {
false
} else if let Some(instant) = *whistle_time {
if instant.elapsed() > Duration::from_secs(10) {
false
} else {
// Await timer
true
}
} else {
*whistle_time = Some(Instant::now());
// Await timer
return true;
}
}
_ => false,
};
}
Expand Down