@@ -19,6 +19,7 @@ type Publisher struct {
1919
2020type RefMessage struct {
2121 ProtoMsg * refproto.Referee
22+ goal map [Team ]bool
2223 Send func ()
2324}
2425
@@ -28,7 +29,10 @@ func NewPublisher(address string) (publisher Publisher) {
2829 publisher .address = address
2930
3031 // 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+
3236 initRefereeMessage (publisher .Message .ProtoMsg )
3337
3438 publisher .connect ()
@@ -135,8 +139,8 @@ func (p *RefMessage) setState(state *State) (republish bool) {
135139 * p .ProtoMsg .NextCommand = mapCommand (state .NextCommand , state .NextCommandFor )
136140 * p .ProtoMsg .CurrentActionTimeRemaining = int32 (state .CurrentActionTimeRemaining .Nanoseconds () / 1000 )
137141
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 )
140144 return
141145}
142146
@@ -156,14 +160,16 @@ func (p *RefMessage) sendCommands(state *State) {
156160 newCommand := mapCommand (state .Command , state .CommandFor )
157161
158162 // 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 ] {
160164 p .updateCommand (refproto .Referee_GOAL_YELLOW )
161165 p .Send ()
162166 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 ] {
164169 p .updateCommand (refproto .Referee_GOAL_BLUE )
165170 p .Send ()
166171 p .updateCommand (newCommand )
172+ p .goal [TeamBlue ] = false
167173 } else if * p .ProtoMsg .Command != newCommand {
168174 switch state .Command {
169175 case CommandBallPlacement ,
@@ -230,19 +236,24 @@ func commandByTeam(team Team, blueCommand refproto.Referee_Command, yellowComman
230236 return yellowCommand
231237}
232238
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 )
246257}
247258
248259func mapTimes (durations []time.Duration ) []uint32 {
0 commit comments