@@ -52,23 +52,13 @@ func (e *Engine) SendCommand(command RefCommand, forTeam Team) {
52
52
e .State .CommandFor = forTeam
53
53
e .LogCommand ()
54
54
55
- if command .RunningState () {
56
- if e .State .GameEvent .Type != GameEventNone {
57
- e .State .GameEvent = GameEvent {Type : GameEventNone }
58
- }
59
- if e .State .GameEventSecondary .Type != GameEventNone {
60
- e .State .GameEventSecondary = GameEvent {Type : GameEventNone }
61
- }
55
+ if command .RunningState () && len (e .State .GameEvents ) > 0 {
56
+ e .State .GameEvents = []* GameEvent {}
62
57
}
63
58
}
64
59
65
- func (e * Engine ) SendGameEventPrimary (gameEvent GameEvent ) {
66
- e .State .GameEvent = gameEvent
67
- e .LogGameEvent (gameEvent )
68
- }
69
-
70
- func (e * Engine ) SendGameEventSecondary (gameEvent GameEvent ) {
71
- e .State .GameEventSecondary = gameEvent
60
+ func (e * Engine ) AddGameEvent (gameEvent GameEvent ) {
61
+ e .State .GameEvents = append (e .State .GameEvents , & gameEvent )
72
62
e .LogGameEvent (gameEvent )
73
63
}
74
64
@@ -83,7 +73,31 @@ func (e *Engine) UndoLastAction() {
83
73
}
84
74
85
75
func (e * Engine ) Continue () error {
86
- switch e .State .GameEvent .Type {
76
+ if len (e .State .GameEvents ) == 0 {
77
+ return errors .New ("No game events available to determine next action" )
78
+ }
79
+ primaryEvent := e .State .GameEvents [0 ]
80
+ teamInFavor := primaryEvent .ByTeam ().Opposite ()
81
+
82
+ if e .State .Division == DivA {
83
+ for _ , event := range e .State .GameEvents {
84
+ if event .Type == GameEventPlacementFailedByTeamInFavor {
85
+ switch primaryEvent .Type {
86
+ case
87
+ GameEventGoal ,
88
+ GameEventDefenderInDefenseArea ,
89
+ GameEventMultipleYellowCards :
90
+ default :
91
+ // the placement failed by team in favor
92
+ // the game is continued by the other team
93
+ e .SendCommand (CommandIndirect , teamInFavor .Opposite ())
94
+ }
95
+ return nil
96
+ }
97
+ }
98
+ }
99
+
100
+ switch primaryEvent .Type {
87
101
case
88
102
GameEventBallLeftFieldTouchLine ,
89
103
GameEventIcing ,
@@ -96,7 +110,7 @@ func (e *Engine) Continue() error {
96
110
GameEventDefenderInDefenseAreaPartially ,
97
111
GameEventKickTimeout ,
98
112
GameEventKeeperHeldBall :
99
- e .SendCommand (CommandIndirect , e . State . GameEvent . ByTeam (). Opposite () )
113
+ e .SendCommand (CommandIndirect , teamInFavor )
100
114
case
101
115
GameEventBallLeftFieldGoalLine ,
102
116
GameEventIndirectGoal ,
@@ -105,30 +119,25 @@ func (e *Engine) Continue() error {
105
119
GameEventBotCrashUnique ,
106
120
GameEventBotPushedBot ,
107
121
GameEventBotHeldBallDeliberately :
108
- e .SendCommand (CommandDirect , e . State . GameEvent . ByTeam (). Opposite () )
122
+ e .SendCommand (CommandDirect , teamInFavor )
109
123
case
110
124
GameEventGoal :
111
- e .SendCommand (CommandKickoff , e . State . GameEvent . ByTeam (). Opposite () )
125
+ e .SendCommand (CommandKickoff , teamInFavor )
112
126
case
113
127
GameEventBotCrashDrawn ,
114
128
GameEventNoProgressInGame :
115
129
e .SendCommand (CommandForceStart , TeamUnknown )
116
130
case
117
131
GameEventDefenderInDefenseArea ,
118
132
GameEventMultipleYellowCards :
119
- e .SendCommand (CommandPenalty , e . State . GameEvent . ByTeam (). Opposite () )
133
+ e .SendCommand (CommandPenalty , teamInFavor )
120
134
case
121
135
GameEventBotInterferedPlacement ,
122
136
GameEventDefenderTooCloseToKickPoint :
123
137
if cmd , err := e .LastGameStartCommand (); err != nil {
124
138
log .Print ("Warn: " , err )
125
139
} else {
126
- e .SendCommand (cmd , e .State .GameEvent .ByTeam ().Opposite ())
127
- }
128
- case
129
- GameEventPlacementFailedByTeamInFavor :
130
- if e .State .PlacementPos != nil {
131
- e .SendCommand (CommandBallPlacement , e .State .GameEvent .ByTeam ().Opposite ())
140
+ e .SendCommand (cmd , teamInFavor )
132
141
}
133
142
case
134
143
GameEventBotTooFastInStop ,
@@ -137,10 +146,11 @@ func (e *Engine) Continue() error {
137
146
GameEventBotCrashUniqueContinue ,
138
147
GameEventBotPushedBotContinue ,
139
148
GameEventMultipleFouls ,
149
+ GameEventPlacementFailedByTeamInFavor ,
140
150
GameEventPlacementFailedByOpponent :
141
151
// no command
142
152
default :
143
- return errors .Errorf ("Unknown game event: %v" , e .State .GameEvent )
153
+ return errors .Errorf ("Unknown game event: %v" , e .State .GameEvents )
144
154
}
145
155
return nil
146
156
}
@@ -177,7 +187,7 @@ func (e *Engine) appendHistory() {
177
187
178
188
func (e * Engine ) LogGameEvent (event GameEvent ) {
179
189
gameEvent := RefereeEvent {
180
- Timestamp : e .TimeProvider (),
190
+ Timestamp : e .TimeProvider (). UnixNano () ,
181
191
StageTime : e .State .StageTimeElapsed ,
182
192
Type : RefereeEventGameEvent ,
183
193
Name : string (event .Type ),
@@ -189,7 +199,7 @@ func (e *Engine) LogGameEvent(event GameEvent) {
189
199
190
200
func (e * Engine ) LogCommand () {
191
201
refereeEvent := RefereeEvent {
192
- Timestamp : e .TimeProvider (),
202
+ Timestamp : e .TimeProvider (). UnixNano () ,
193
203
StageTime : e .State .StageTimeElapsed ,
194
204
Type : RefereeEventCommand ,
195
205
Name : string (e .State .Command ),
@@ -200,7 +210,7 @@ func (e *Engine) LogCommand() {
200
210
201
211
func (e * Engine ) LogCard (card * EventCard ) {
202
212
refereeEvent := RefereeEvent {
203
- Timestamp : e .TimeProvider (),
213
+ Timestamp : e .TimeProvider (). UnixNano () ,
204
214
StageTime : e .State .StageTimeElapsed ,
205
215
Type : RefereeEventCard ,
206
216
Name : fmt .Sprintf ("%v %v card" , card .Operation , card .Type ),
@@ -211,7 +221,7 @@ func (e *Engine) LogCard(card *EventCard) {
211
221
212
222
func (e * Engine ) LogTime (description string , forTeam Team ) {
213
223
refereeEvent := RefereeEvent {
214
- Timestamp : e .TimeProvider (),
224
+ Timestamp : e .TimeProvider (). UnixNano () ,
215
225
StageTime : e .State .StageTimeElapsed ,
216
226
Type : RefereeEventTime ,
217
227
Name : description ,
@@ -222,7 +232,7 @@ func (e *Engine) LogTime(description string, forTeam Team) {
222
232
223
233
func (e * Engine ) LogStage (stage Stage ) {
224
234
refereeEvent := RefereeEvent {
225
- Timestamp : e .TimeProvider (),
235
+ Timestamp : e .TimeProvider (). UnixNano () ,
226
236
StageTime : e .State .StageTimeElapsed ,
227
237
Type : RefereeEventStage ,
228
238
Name : string (stage ),
@@ -532,15 +542,11 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
532
542
addCard (& EventCard {Type : CardTypeRed , ForTeam : team , Operation : CardOperationAdd }, e .State .TeamState [team ], 0 )
533
543
}
534
544
535
- if event .IsSecondary () {
536
- e .SendGameEventSecondary (* event )
537
- } else {
538
- e .SendGameEventPrimary (* event )
539
- e .State .PlacementPos = e .BallPlacementPos ()
540
- }
545
+ e .AddGameEvent (* event )
546
+ e .State .PlacementPos = e .BallPlacementPos ()
541
547
542
548
if e .State .GameState () != GameStateHalted && ! event .IsContinued () {
543
- teamInFavor := e . State . GameEvent .ByTeam ().Opposite ()
549
+ teamInFavor := event .ByTeam ().Opposite ()
544
550
if e .State .PlacementPos == nil {
545
551
e .SendCommand (CommandStop , "" )
546
552
} else if e .State .TeamState [teamInFavor ].CanPlaceBall {
0 commit comments