@@ -19,6 +19,7 @@ type Publisher struct {
19
19
20
20
type RefMessage struct {
21
21
ProtoMsg * refproto.Referee
22
+ goal map [Team ]bool
22
23
Send func ()
23
24
}
24
25
@@ -28,7 +29,10 @@ func NewPublisher(address string) (publisher Publisher) {
28
29
publisher .address = address
29
30
30
31
// initialize default referee message
31
- publisher .Message = RefMessage {Send : publisher .send , ProtoMsg : new (refproto.Referee )}
32
+ publisher .Message = RefMessage {Send : publisher .send , ProtoMsg : new (refproto.Referee ), goal : map [Team ]bool {}}
33
+ publisher .Message .goal [TeamBlue ] = false
34
+ publisher .Message .goal [TeamYellow ] = false
35
+
32
36
initRefereeMessage (publisher .Message .ProtoMsg )
33
37
34
38
publisher .connect ()
@@ -135,8 +139,8 @@ func (p *RefMessage) setState(state *State) (republish bool) {
135
139
* p .ProtoMsg .NextCommand = mapCommand (state .NextCommand , state .NextCommandFor )
136
140
* p .ProtoMsg .CurrentActionTimeRemaining = int32 (state .CurrentActionTimeRemaining .Nanoseconds () / 1000 )
137
141
138
- updateTeam (p .ProtoMsg .Yellow , state .TeamState [TeamYellow ])
139
- updateTeam (p .ProtoMsg .Blue , state .TeamState [TeamBlue ])
142
+ p . updateTeam (p .ProtoMsg .Yellow , state .TeamState [TeamYellow ], TeamYellow )
143
+ p . updateTeam (p .ProtoMsg .Blue , state .TeamState [TeamBlue ], TeamBlue )
140
144
return
141
145
}
142
146
@@ -156,14 +160,16 @@ func (p *RefMessage) sendCommands(state *State) {
156
160
newCommand := mapCommand (state .Command , state .CommandFor )
157
161
158
162
// send the GOAL command based on the team score for compatibility with old behavior
159
- if state . TeamState [TeamYellow ]. Goals > int ( * p . ProtoMsg . Yellow . Score ) {
163
+ if p . goal [TeamYellow ] {
160
164
p .updateCommand (refproto .Referee_GOAL_YELLOW )
161
165
p .Send ()
162
166
p .updateCommand (newCommand )
163
- } else if state .TeamState [TeamBlue ].Goals > int (* p .ProtoMsg .Blue .Score ) {
167
+ p .goal [TeamYellow ] = false
168
+ } else if p .goal [TeamBlue ] {
164
169
p .updateCommand (refproto .Referee_GOAL_BLUE )
165
170
p .Send ()
166
171
p .updateCommand (newCommand )
172
+ p .goal [TeamBlue ] = false
167
173
} else if * p .ProtoMsg .Command != newCommand {
168
174
switch state .Command {
169
175
case CommandBallPlacement ,
@@ -230,19 +236,24 @@ func commandByTeam(team Team, blueCommand refproto.Referee_Command, yellowComman
230
236
return yellowCommand
231
237
}
232
238
233
- func updateTeam (team * refproto.Referee_TeamInfo , state * TeamInfo ) {
234
- * team .Name = state .Name
235
- * team .Score = uint32 (state .Goals )
236
- * team .RedCards = uint32 (state .RedCards )
237
- team .YellowCardTimes = mapTimes (state .YellowCardTimes )
238
- * team .YellowCards = uint32 (state .YellowCards )
239
- * team .Timeouts = uint32 (state .TimeoutsLeft )
240
- * team .TimeoutTime = uint32 (state .TimeoutTimeLeft .Nanoseconds () / 1000 )
241
- * team .Goalkeeper = uint32 (state .Goalkeeper )
242
- * team .FoulCounter = uint32 (state .FoulCounter )
243
- * team .BallPlacementFailures = uint32 (state .BallPlacementFailures )
244
- * team .CanPlaceBall = state .CanPlaceBall
245
- * team .MaxAllowedBots = uint32 (state .MaxAllowedBots )
239
+ func (p * RefMessage ) updateTeam (teamInfo * refproto.Referee_TeamInfo , state * TeamInfo , team Team ) {
240
+
241
+ if state .Goals > int (* teamInfo .Score ) {
242
+ p .goal [team ] = true
243
+ }
244
+
245
+ * teamInfo .Name = state .Name
246
+ * teamInfo .Score = uint32 (state .Goals )
247
+ * teamInfo .RedCards = uint32 (state .RedCards )
248
+ teamInfo .YellowCardTimes = mapTimes (state .YellowCardTimes )
249
+ * teamInfo .YellowCards = uint32 (state .YellowCards )
250
+ * teamInfo .Timeouts = uint32 (state .TimeoutsLeft )
251
+ * teamInfo .TimeoutTime = uint32 (state .TimeoutTimeLeft .Nanoseconds () / 1000 )
252
+ * teamInfo .Goalkeeper = uint32 (state .Goalkeeper )
253
+ * teamInfo .FoulCounter = uint32 (state .FoulCounter )
254
+ * teamInfo .BallPlacementFailures = uint32 (state .BallPlacementFailures )
255
+ * teamInfo .CanPlaceBall = state .CanPlaceBall
256
+ * teamInfo .MaxAllowedBots = uint32 (state .MaxAllowedBots )
246
257
}
247
258
248
259
func mapTimes (durations []time.Duration ) []uint32 {
0 commit comments