1
1
package statemachine
2
2
3
3
import (
4
+ "github.com/RoboCup-SSL/ssl-game-controller/internal/app/config"
4
5
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
5
6
"google.golang.org/protobuf/types/known/durationpb"
6
7
"google.golang.org/protobuf/types/known/timestamppb"
@@ -12,14 +13,12 @@ func (s *StateMachine) processChangeNewCommand(newState *state.State, newCommand
12
13
newState .GameState = s .newGameState (newState , newCommand )
13
14
newState .Command = newCommand .Command
14
15
15
- switch * newState .Command .Type {
16
- case state .Command_BALL_PLACEMENT :
17
- newState .CurrentActionTimeRemaining = durationpb .New (s .gameConfig .BallPlacementTime )
18
- case state .Command_DIRECT :
19
- newState .CurrentActionTimeRemaining = durationpb .New (s .gameConfig .FreeKickTimeout [newState .Division .Div ()])
20
- case state .Command_KICKOFF , state .Command_PENALTY :
21
- newState .CurrentActionTimeRemaining = durationpb .New (s .gameConfig .PrepareTimeout )
22
- case state .Command_TIMEOUT :
16
+ newState .CurrentActionTimeRemaining = s .currentActionTimeRemainingForCommand (
17
+ * newState .Command .Type ,
18
+ newState .Division .Div (),
19
+ )
20
+
21
+ if * newState .Command .Type == state .Command_TIMEOUT {
23
22
* newState .TeamInfo (* newState .Command .ForTeam ).TimeoutsLeft --
24
23
newState .TeamInfo (* newState .Command .ForTeam ).RequestsTimeoutSince = nil
25
24
}
@@ -77,6 +76,19 @@ func (s *StateMachine) processChangeNewCommand(newState *state.State, newCommand
77
76
return
78
77
}
79
78
79
+ func (s * StateMachine ) currentActionTimeRemainingForCommand (command state.Command_Type , division config.Division ) * durationpb.Duration {
80
+ switch command {
81
+ case state .Command_BALL_PLACEMENT :
82
+ return durationpb .New (s .gameConfig .BallPlacementTime )
83
+ case state .Command_DIRECT :
84
+ return durationpb .New (s .gameConfig .FreeKickTimeout [division ])
85
+ case state .Command_KICKOFF , state .Command_PENALTY :
86
+ return durationpb .New (s .gameConfig .PrepareTimeout )
87
+ default :
88
+ return durationpb .New (0 )
89
+ }
90
+ }
91
+
80
92
func (s * StateMachine ) newGameState (newState * state.State , newCommand * Change_NewCommand ) * state.GameState {
81
93
switch * newCommand .Command .Type {
82
94
case state .Command_HALT :
0 commit comments