Skip to content

Commit

Permalink
[bugfix] Restart with kickoff/penalty after fouls
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Apr 13, 2019
1 parent bab4c97 commit 3660f81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 16 additions & 7 deletions internal/app/controller/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,26 @@ func (e *Engine) updateNextCommand() {
if primaryEvent == nil {
return
}

if primaryEvent.Type == GameEventDefenderTooCloseToKickPoint {
e.State.NextCommand, e.State.NextCommandFor =
e.lastCommand([]RefCommand{CommandIndirect, CommandDirect, CommandKickoff, CommandPenalty})
} else {
command, forTeam, err := e.CommandForEvent(primaryEvent)
if err != nil {
log.Print("Warn: ", err)
return
lastCommand, lastCommandFor :=
e.lastCommand([]RefCommand{CommandKickoff, CommandPenalty, CommandNormalStart})
if lastCommand.IsPrepare() {
// if the last command was a kickoff or penalty, restart with that
e.State.NextCommand = lastCommand
e.State.NextCommandFor = lastCommandFor
} else {
command, forTeam, err := e.CommandForEvent(primaryEvent)
if err != nil {
log.Print("Warn: ", err)
return
}
e.State.NextCommand = command
e.State.NextCommandFor = forTeam
}
e.State.NextCommand = command
e.State.NextCommandFor = forTeam
}
}

Expand Down Expand Up @@ -752,7 +761,7 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
} else if event.Type == GameEventDefenderTooCloseToKickPoint {
// stop the game and let bots move away from the ball first. The autoRef will continue the game afterwards
e.SendCommand(CommandStop, "")
} else if !event.IsSkipped() && !event.IsSecondary() {
} else if !event.IsSkipped() && !event.IsSecondary() && !e.State.Command.IsPrepare() {
e.placeBall(event)
} else if e.State.AutoContinue && event.IsContinueGame() {
e.Continue()
Expand Down
4 changes: 4 additions & 0 deletions internal/app/controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ func (c RefCommand) IsFreeKick() bool {
return c == CommandDirect || c == CommandIndirect
}

func (c RefCommand) IsPrepare() bool {
return c == CommandKickoff || c == CommandPenalty
}

// GameState of a game
type GameState string

Expand Down

0 comments on commit 3660f81

Please sign in to comment.