Skip to content

Commit e07c49a

Browse files
committed
[feature] Implement game event "multiple fouls"
1 parent 7103f1e commit e07c49a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

internal/app/controller/engine.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controller
22

33
import (
44
"fmt"
5+
"github.com/RoboCup-SSL/ssl-game-controller/pkg/refproto"
56
"github.com/pkg/errors"
67
"log"
78
"strconv"
@@ -547,7 +548,7 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
547548
e.AddGameEvent(*event)
548549
e.State.PlacementPos = e.BallPlacementPos()
549550

550-
if e.State.GameState() != GameStateHalted && !event.IsContinued() {
551+
if e.State.GameState() != GameStateHalted && !event.IsContinued() && !event.IsSecondary() {
551552
teamInFavor := event.ByTeam().Opposite()
552553
if e.State.PlacementPos != nil {
553554
if e.State.TeamState[teamInFavor].CanPlaceBall {
@@ -563,6 +564,18 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
563564
}
564565

565566
log.Printf("Processed game event %v", event)
567+
568+
for _, team := range []Team{TeamBlue, TeamYellow} {
569+
counter := e.State.TeamState[team].FoulCounter
570+
counterPunished := e.State.TeamState[team].FoulCounterPunished
571+
if counter > 0 && counter%3 == 0 && counter != counterPunished {
572+
e.State.TeamState[team].FoulCounterPunished = counter
573+
teamProto := team.toProto()
574+
return e.processGameEvent(&GameEvent{Type: GameEventMultipleFouls,
575+
Details: GameEventDetails{MultipleFouls: &refproto.GameEvent_MultipleFouls{ByTeam: &teamProto}}})
576+
}
577+
}
578+
566579
return nil
567580
}
568581

internal/app/controller/state.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ func (t Team) Known() bool {
4040
return !t.Unknown()
4141
}
4242

43+
func (t Team) toProto() refproto.Team {
44+
if t == TeamYellow {
45+
return refproto.Team_YELLOW
46+
} else if t == TeamBlue {
47+
return refproto.Team_BLUE
48+
}
49+
return refproto.Team_UNKNOWN
50+
}
51+
4352
// NewTeam creates a team from a protobuf team
4453
func NewTeam(team refproto.Team) Team {
4554
if team == refproto.Team_YELLOW {
@@ -225,6 +234,7 @@ type TeamInfo struct {
225234
TimeoutTimeLeft time.Duration `json:"timeoutTimeLeft"`
226235
OnPositiveHalf bool `json:"onPositiveHalf"`
227236
FoulCounter int `json:"foulCounter"`
237+
FoulCounterPunished int `json:"foulCounterPunished"`
228238
BallPlacementFailures int `json:"ballPlacementFailures"`
229239
CanPlaceBall bool `json:"canPlaceBall"`
230240
}

0 commit comments

Comments
 (0)