@@ -28,6 +28,21 @@ func NewEngine(config config.Game) (e Engine) {
28
28
return
29
29
}
30
30
31
+ func (e * Engine ) loadStages () {
32
+ e .StageTimes = map [Stage ]time.Duration {}
33
+ for _ , stage := range Stages {
34
+ e .StageTimes [stage ] = 0
35
+ }
36
+ e .StageTimes [StageFirstHalf ] = e .config .Normal .HalfDuration
37
+ e .StageTimes [StageHalfTime ] = e .config .Normal .HalfTimeDuration
38
+ e .StageTimes [StageSecondHalf ] = e .config .Normal .HalfDuration
39
+ e .StageTimes [StageOvertimeBreak ] = e .config .Normal .BreakAfter
40
+ e .StageTimes [StageOvertimeFirstHalf ] = e .config .Overtime .HalfDuration
41
+ e .StageTimes [StageOvertimeHalfTime ] = e .config .Overtime .HalfTimeDuration
42
+ e .StageTimes [StageOvertimeSecondHalf ] = e .config .Overtime .HalfDuration
43
+ e .StageTimes [StageShootoutBreak ] = e .config .Overtime .BreakAfter
44
+ }
45
+
31
46
func (e * Engine ) ResetGame () {
32
47
e .State = NewState ()
33
48
for _ , team := range []Team {TeamBlue , TeamYellow } {
@@ -50,6 +65,36 @@ func (e *Engine) Tick(delta time.Duration) {
50
65
}
51
66
}
52
67
68
+ func (e * Engine ) updateTimes (delta time.Duration ) {
69
+ if e .countStageTime () {
70
+ e .State .StageTimeElapsed += delta
71
+ e .State .StageTimeLeft -= delta
72
+
73
+ if e .State .StageTimeLeft + delta > 0 && e .State .StageTimeLeft <= 0 {
74
+ e .LogTime ("Stage time elapsed" , "" )
75
+ }
76
+
77
+ for team , teamState := range e .State .TeamState {
78
+ reduceYellowCardTimes (teamState , delta )
79
+ e .removeElapsedYellowCards (team , teamState )
80
+ e .updateMaxBots ()
81
+ }
82
+ }
83
+
84
+ if e .State .GameState () == GameStateTimeout && e .State .CommandFor .Known () {
85
+ e .State .TeamState [e .State .CommandFor ].TimeoutTimeLeft -= delta
86
+
87
+ timeLeft := e .State .TeamState [e .State .CommandFor ].TimeoutTimeLeft
88
+ if timeLeft + delta > 0 && timeLeft <= 0 {
89
+ e .LogTime ("Timeout time elapsed" , e .State .CommandFor )
90
+ }
91
+ }
92
+ }
93
+
94
+ func (e * Engine ) countStageTime () bool {
95
+ return e .State .Stage .IsPausedStage () || e .State .GameState () == GameStateRunning
96
+ }
97
+
53
98
func (e * Engine ) SendCommand (command RefCommand , forTeam Team ) {
54
99
e .State .Command = command
55
100
e .State .CommandFor = forTeam
@@ -95,25 +140,6 @@ func (e *Engine) Continue() {
95
140
}
96
141
}
97
142
98
- func (e * Engine ) updateNextCommand () {
99
- if e .State .Command == CommandPenalty || e .State .Command == CommandKickoff {
100
- e .State .NextCommand = CommandNormalStart
101
- e .State .NextCommandFor = ""
102
- return
103
- }
104
- primaryEvent := e .State .PrimaryGameEvent ()
105
- if primaryEvent == nil {
106
- return
107
- }
108
- command , forTeam , err := e .CommandForEvent (primaryEvent )
109
- if err != nil {
110
- log .Print ("Warn: " , err )
111
- return
112
- }
113
- e .State .NextCommand = command
114
- e .State .NextCommandFor = forTeam
115
- }
116
-
117
143
func (e * Engine ) CommandForEvent (event * GameEvent ) (command RefCommand , forTeam Team , err error ) {
118
144
if event .IsSecondary () {
119
145
return
@@ -217,49 +243,23 @@ func (e *Engine) updateMaxBots() {
217
243
}
218
244
}
219
245
220
- func (e * Engine ) loadStages () {
221
- e .StageTimes = map [Stage ]time.Duration {}
222
- for _ , stage := range Stages {
223
- e .StageTimes [stage ] = 0
246
+ func (e * Engine ) updateNextCommand () {
247
+ if e .State .Command == CommandPenalty || e .State .Command == CommandKickoff {
248
+ e .State .NextCommand = CommandNormalStart
249
+ e .State .NextCommandFor = ""
250
+ return
224
251
}
225
- e .StageTimes [StageFirstHalf ] = e .config .Normal .HalfDuration
226
- e .StageTimes [StageHalfTime ] = e .config .Normal .HalfTimeDuration
227
- e .StageTimes [StageSecondHalf ] = e .config .Normal .HalfDuration
228
- e .StageTimes [StageOvertimeBreak ] = e .config .Normal .BreakAfter
229
- e .StageTimes [StageOvertimeFirstHalf ] = e .config .Overtime .HalfDuration
230
- e .StageTimes [StageOvertimeHalfTime ] = e .config .Overtime .HalfTimeDuration
231
- e .StageTimes [StageOvertimeSecondHalf ] = e .config .Overtime .HalfDuration
232
- e .StageTimes [StageShootoutBreak ] = e .config .Overtime .BreakAfter
233
- }
234
-
235
- func (e * Engine ) countStageTime () bool {
236
- return e .State .Stage .IsPausedStage () || e .State .GameState () == GameStateRunning
237
- }
238
-
239
- func (e * Engine ) updateTimes (delta time.Duration ) {
240
- if e .countStageTime () {
241
- e .State .StageTimeElapsed += delta
242
- e .State .StageTimeLeft -= delta
243
-
244
- if e .State .StageTimeLeft + delta > 0 && e .State .StageTimeLeft <= 0 {
245
- e .LogTime ("Stage time elapsed" , "" )
246
- }
247
-
248
- for team , teamState := range e .State .TeamState {
249
- reduceYellowCardTimes (teamState , delta )
250
- e .removeElapsedYellowCards (team , teamState )
251
- e .updateMaxBots ()
252
- }
252
+ primaryEvent := e .State .PrimaryGameEvent ()
253
+ if primaryEvent == nil {
254
+ return
253
255
}
254
-
255
- if e .State .GameState () == GameStateTimeout && e .State .CommandFor .Known () {
256
- e .State .TeamState [e .State .CommandFor ].TimeoutTimeLeft -= delta
257
-
258
- timeLeft := e .State .TeamState [e .State .CommandFor ].TimeoutTimeLeft
259
- if timeLeft + delta > 0 && timeLeft <= 0 {
260
- e .LogTime ("Timeout time elapsed" , e .State .CommandFor )
261
- }
256
+ command , forTeam , err := e .CommandForEvent (primaryEvent )
257
+ if err != nil {
258
+ log .Print ("Warn: " , err )
259
+ return
262
260
}
261
+ e .State .NextCommand = command
262
+ e .State .NextCommandFor = forTeam
263
263
}
264
264
265
265
func (e * Engine ) processEvent (event Event ) error {
0 commit comments