Skip to content

Commit

Permalink
Ignore team messages during first 30 seconds of Ready (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasselbring committed Apr 9, 2024
1 parent cd98dcd commit 322f522
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions game_controller_core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,11 @@ impl ActionContext<'_> {
}
}
}

/// This function returns the delayed game state if there is some, or [None].
pub fn delayed_game(&self) -> Option<&Game> {
self.delay
.as_ref()
.and_then(|delay| delay.as_ref().map(|delay| &delay.game))
}
}
8 changes: 6 additions & 2 deletions game_controller_core/src/actions/start_set_play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ impl Action for StartSetPlay {
if !c.params.game.test.no_delay
&& self.set_play == SetPlay::KickOff
&& (c.game.state == State::Initial || c.game.state == State::Timeout)
&& !c.fork(c.params.competition.delay_after_ready, |_| false)
&& !c.fork(c.params.competition.delay_after_ready, |action| {
matches!(action, VAction::TeamMessage(_))
})
{
return;
}
Expand All @@ -33,7 +35,9 @@ impl Action for StartSetPlay {
team.players.iter_mut().for_each(|player| {
// The Motion in Initial penalty is special because it needs to survive the
// transition from Initial to Ready, otherwise it would be pointless.
if !(self.set_play == SetPlay::KickOff && player.penalty == Penalty::MotionInInitial) {
if !(self.set_play == SetPlay::KickOff
&& player.penalty == Penalty::MotionInInitial)
{
player.penalty_timer = Timer::Stopped;
}
})
Expand Down
7 changes: 7 additions & 0 deletions game_controller_core/src/actions/team_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ pub struct TeamMessage {

impl Action for TeamMessage {
fn execute(&self, c: &mut ActionContext) {
// Do not consider messages that arrive while we are still pretending that it is
// Initial/Timeout.
if c.delayed_game()
.is_some_and(|game| game.state == State::Initial || game.state == State::Timeout)
{
return;
}
if c.game.teams[self.side].message_budget == 0 || self.illegal {
c.game.teams[self.side].illegal_communication = true;
c.game.teams[self.side].score = 0;
Expand Down

0 comments on commit 322f522

Please sign in to comment.