Skip to content

Commit 3660f81

Browse files
committed
[bugfix] Restart with kickoff/penalty after fouls
1 parent bab4c97 commit 3660f81

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

internal/app/controller/engine.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,17 +380,26 @@ func (e *Engine) updateNextCommand() {
380380
if primaryEvent == nil {
381381
return
382382
}
383+
383384
if primaryEvent.Type == GameEventDefenderTooCloseToKickPoint {
384385
e.State.NextCommand, e.State.NextCommandFor =
385386
e.lastCommand([]RefCommand{CommandIndirect, CommandDirect, CommandKickoff, CommandPenalty})
386387
} else {
387-
command, forTeam, err := e.CommandForEvent(primaryEvent)
388-
if err != nil {
389-
log.Print("Warn: ", err)
390-
return
388+
lastCommand, lastCommandFor :=
389+
e.lastCommand([]RefCommand{CommandKickoff, CommandPenalty, CommandNormalStart})
390+
if lastCommand.IsPrepare() {
391+
// if the last command was a kickoff or penalty, restart with that
392+
e.State.NextCommand = lastCommand
393+
e.State.NextCommandFor = lastCommandFor
394+
} else {
395+
command, forTeam, err := e.CommandForEvent(primaryEvent)
396+
if err != nil {
397+
log.Print("Warn: ", err)
398+
return
399+
}
400+
e.State.NextCommand = command
401+
e.State.NextCommandFor = forTeam
391402
}
392-
e.State.NextCommand = command
393-
e.State.NextCommandFor = forTeam
394403
}
395404
}
396405

@@ -752,7 +761,7 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
752761
} else if event.Type == GameEventDefenderTooCloseToKickPoint {
753762
// stop the game and let bots move away from the ball first. The autoRef will continue the game afterwards
754763
e.SendCommand(CommandStop, "")
755-
} else if !event.IsSkipped() && !event.IsSecondary() {
764+
} else if !event.IsSkipped() && !event.IsSecondary() && !e.State.Command.IsPrepare() {
756765
e.placeBall(event)
757766
} else if e.State.AutoContinue && event.IsContinueGame() {
758767
e.Continue()

internal/app/controller/state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ func (c RefCommand) IsFreeKick() bool {
279279
return c == CommandDirect || c == CommandIndirect
280280
}
281281

282+
func (c RefCommand) IsPrepare() bool {
283+
return c == CommandKickoff || c == CommandPenalty
284+
}
285+
282286
// GameState of a game
283287
type GameState string
284288

0 commit comments

Comments
 (0)