Skip to content

Commit 0bc9d6c

Browse files
committed
Add current num robots to remote-control protocol
1 parent 39edbff commit 0bc9d6c

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
lines changed

internal/app/engine/common.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ func (e *Engine) ballSteady() bool {
5555
}
5656
return e.gcState.TrackerStateGc.Ball.Vel.ToVector2().Length() < ballSteadyThreshold
5757
}
58+
59+
func (x *GcStateTracker) NumTeamRobots(team state.Team) (count int32) {
60+
for _, robot := range x.Robots {
61+
if *robot.Id.Team == team {
62+
count++
63+
}
64+
}
65+
return
66+
}

internal/app/engine/process_botremoved.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (e *Engine) processBotNumberPerTeam(team state.Team) {
4343
e.gameConfig.YellowCardDuration-e.gameConfig.YellowCardBotRemovalTime,
4444
)
4545

46-
numBots := numRobotsOfTeam(e.gcState.TrackerStateGc.Robots, team)
46+
numBots := e.gcState.TrackerStateGc.NumTeamRobots(team)
4747
numBotsAllowed := *teamInfo.MaxAllowedBots + newCards
4848
if numBots > numBotsAllowed {
4949

@@ -78,12 +78,3 @@ func newActiveYellowCards(cards []*state.YellowCard, minRemaining time.Duration)
7878
}
7979
return
8080
}
81-
82-
func numRobotsOfTeam(robots []*Robot, team state.Team) (count int32) {
83-
for _, robot := range robots {
84-
if *robot.Id.Team == team {
85-
count++
86-
}
87-
}
88-
return
89-
}

internal/app/engine/process_continue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (e *Engine) posInsideGoal(pos *geom.Vector2) bool {
174174

175175
func (e *Engine) tooManyRobots(team state.Team) bool {
176176
maxAllowed := *e.currentState.TeamState[team.String()].MaxAllowedBots
177-
current := numRobotsOfTeam(e.gcState.TrackerStateGc.Robots, team)
177+
current := e.gcState.TrackerStateGc.NumTeamRobots(team)
178178
return current > maxAllowed
179179
}
180180

internal/app/rcon/server_remotecontrol.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func (c *RemoteControlClient) replyWithState(reply *ControllerReply) {
150150
yellowCardsDue := c.findYellowCardDueTimes()
151151
availableRequests := c.findAvailableRequestTypes()
152152
activeRequests := c.findActiveRequestTypes()
153+
robotsOnField := c.gcEngine.CurrentGcState().TrackerStateGc.NumTeamRobots(*c.team)
153154

154155
response := &ControllerToRemoteControl{
155156
State: &RemoteControlTeamState{
@@ -160,6 +161,7 @@ func (c *RemoteControlClient) replyWithState(reply *ControllerReply) {
160161
TimeoutsLeft: teamState.TimeoutsLeft,
161162
ChallengeFlagsLeft: teamState.ChallengeFlags,
162163
MaxRobots: teamState.MaxAllowedBots,
164+
RobotsOnField: &robotsOnField,
163165
YellowCardsDue: yellowCardsDue,
164166
},
165167
ControllerReply: reply,

internal/app/rcon/ssl_gc_rcon_remotecontrol.pb.go

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

proto/ssl_gc_rcon_remotecontrol.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ message RemoteControlTeamState {
8181
// max number of robots currently allowed
8282
optional int32 max_robots = 7;
8383

84+
// current number of robots visible on field
85+
optional int32 robots_on_field = 9;
86+
8487
// list of due times for each active yellow card (in seconds)
8588
repeated float yellow_cards_due = 8;
8689
}

0 commit comments

Comments
 (0)