Skip to content

Commit a667072

Browse files
committed
[feature] Add a new game event for bot substitution
1 parent ed5efe6 commit a667072

File tree

7 files changed

+266
-147
lines changed

7 files changed

+266
-147
lines changed

internal/app/controller/engine.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ func (e *Engine) UndoLastAction() {
8686
}
8787

8888
func (e *Engine) Continue() {
89-
if e.State.BotSubstitutionIntend() {
89+
substitutionIntend := e.State.BotSubstitutionIntend()
90+
if substitutionIntend != TeamUnknown {
9091
e.State.TeamState[TeamBlue].BotSubstitutionIntend = false
9192
e.State.TeamState[TeamYellow].BotSubstitutionIntend = false
93+
teamProto := substitutionIntend.toProto()
94+
e.AddGameEvent(GameEvent{
95+
Type: GameEventBotSubstitution,
96+
Details: GameEventDetails{
97+
BotSubstitution: &refproto.GameEvent_BotSubstitution{ByTeam: &teamProto}}})
9298
e.SendCommand(CommandHalt, "")
9399
} else if e.State.NextCommand != CommandUnknown {
94100
e.SendCommand(e.State.NextCommand, e.State.NextCommandFor)

internal/app/controller/gameEvent.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
GameEventPlacementFailedByTeamInFavor GameEventType = "placementFailedByTeamInFavor"
1919
GameEventPlacementFailedByOpponent GameEventType = "placementFailedByOpponent"
2020
GameEventPlacementSucceeded GameEventType = "placementSucceeded"
21+
GameEventBotSubstitution GameEventType = "gameEventBotSubstitution"
2122

2223
GameEventBallLeftFieldTouchLine GameEventType = "ballLeftFieldTouchLine"
2324
GameEventBallLeftFieldGoalLine GameEventType = "ballLeftFieldGoalLine"
@@ -286,6 +287,8 @@ func (e GameEvent) ToProto() *refproto.GameEvent {
286287
protoEvent.Event = &refproto.GameEvent_PlacementSucceeded_{PlacementSucceeded: e.Details.PlacementSucceeded}
287288
case GameEventPrepared:
288289
protoEvent.Event = &refproto.GameEvent_Prepared_{Prepared: e.Details.Prepared}
290+
case GameEventBotSubstitution:
291+
protoEvent.Event = &refproto.GameEvent_BotSubstitution_{BotSubstitution: e.Details.BotSubstitution}
289292
default:
290293
log.Printf("Warn: Could not map game e %v", e.Type)
291294
return nil
@@ -331,6 +334,7 @@ type GameEventDetails struct {
331334
PlacementFailedByOpponent *refproto.GameEvent_PlacementFailedByOpponent `json:"placementFailedByOpponent,omitempty"`
332335
PlacementSucceeded *refproto.GameEvent_PlacementSucceeded `json:"placementSucceeded,omitempty"`
333336
Prepared *refproto.GameEvent_Prepared `json:"prepared,omitempty"`
337+
BotSubstitution *refproto.GameEvent_BotSubstitution `json:"botSubstitution,omitempty"`
334338
}
335339

336340
func (d GameEventDetails) EventType() GameEventType {
@@ -442,6 +446,9 @@ func (d GameEventDetails) EventType() GameEventType {
442446
if d.Prepared != nil {
443447
return GameEventPrepared
444448
}
449+
if d.BotSubstitution != nil {
450+
return GameEventBotSubstitution
451+
}
445452
return GameEventNone
446453
}
447454

@@ -638,6 +645,9 @@ func (d GameEventDetails) Description() string {
638645
if d.Prepared != nil {
639646
return ""
640647
}
648+
if d.BotSubstitution != nil {
649+
return ""
650+
}
641651
return ""
642652
}
643653

@@ -678,5 +688,6 @@ func NewGameEventDetails(event refproto.GameEvent) (d GameEventDetails) {
678688
d.PlacementFailedByOpponent = event.GetPlacementFailedByOpponent()
679689
d.PlacementSucceeded = event.GetPlacementSucceeded()
680690
d.Prepared = event.GetPrepared()
691+
d.BotSubstitution = event.GetBotSubstitution()
681692
return
682693
}

internal/app/controller/state.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const (
1717
TeamBlue Team = "Blue"
1818
// TeamUnknown is an unknown team
1919
TeamUnknown Team = ""
20+
// TeamBoth are both teams
21+
TeamBoth = "Both"
2022
)
2123

2224
// Opposite returns the other team
@@ -45,6 +47,8 @@ func (t Team) toProto() refproto.Team {
4547
return refproto.Team_YELLOW
4648
} else if t == TeamBlue {
4749
return refproto.Team_BLUE
50+
} else if t == TeamBoth {
51+
return refproto.Team_BOTH
4852
}
4953
return refproto.Team_UNKNOWN
5054
}
@@ -334,8 +338,17 @@ func (s State) GameState() GameState {
334338
return ""
335339
}
336340

337-
func (s State) BotSubstitutionIntend() bool {
338-
return s.TeamState[TeamYellow].BotSubstitutionIntend || s.TeamState[TeamBlue].BotSubstitutionIntend
341+
func (s State) BotSubstitutionIntend() Team {
342+
if s.TeamState[TeamYellow].BotSubstitutionIntend && s.TeamState[TeamBlue].BotSubstitutionIntend {
343+
return TeamBoth
344+
}
345+
if s.TeamState[TeamYellow].BotSubstitutionIntend {
346+
return TeamYellow
347+
}
348+
if s.TeamState[TeamBlue].BotSubstitutionIntend {
349+
return TeamBlue
350+
}
351+
return TeamUnknown
339352
}
340353

341354
func newTeamInfo() (t TeamInfo) {

pkg/refproto/ssl_game_controller_common.pb.go

Lines changed: 31 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/refproto/ssl_game_controller_common.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ enum Team {
88
YELLOW = 1;
99
// blue team
1010
BLUE = 2;
11+
// both teams
12+
BOTH = 3;
1113
}
1214

1315
// BotId is the combination of a team and a robot id

0 commit comments

Comments
 (0)