Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recently-introduced bug with sequences #3427

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion sim/core/apl.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,18 @@ func (apl *APLRotation) DoNextAction(sim *Simulation) {

func (apl *APLRotation) getNextAction(sim *Simulation) *APLAction {
if apl.strictSequence != nil {
return apl.strictSequence
ss := apl.strictSequence.impl.(*APLActionStrictSequence)
if ss.actions[ss.curIdx].IsReady(sim) {
return apl.strictSequence
} else if apl.unit.GCD.IsReady(sim) {
// If the GCD is ready when the next subaction isn't, it means the sequence is bad
// so reset and exit the sequence.
ss.curIdx = 0
apl.strictSequence = nil
} else {
// Return nil to wait for the GCD to become ready.
return nil
}
}

for _, action := range apl.priorityList {
Expand Down
16 changes: 8 additions & 8 deletions sim/core/apl_actions_sequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func (rot *APLRotation) newActionSequence(config *proto.APLActionSequence) APLAc
return rot.newAPLAction(action)
})
actions = FilterSlice(actions, func(action *APLAction) bool { return action != nil })
if len(actions) == 0 {
return nil
}

return &APLActionSequence{
unit: rot.unit,
Expand All @@ -42,8 +45,8 @@ func (action *APLActionSequence) IsReady(sim *Simulation) bool {
return action.curIdx < len(action.actions) && action.actions[action.curIdx].IsReady(sim)
}
func (action *APLActionSequence) Execute(sim *Simulation) {
action.curIdx++
action.actions[action.curIdx].Execute(sim)
action.curIdx++
}
func (action *APLActionSequence) String() string {
return "Sequence(" + strings.Join(MapSlice(action.actions, func(subaction *APLAction) string { return fmt.Sprintf("(%s)", subaction) }), "+") + ")"
Expand Down Expand Up @@ -97,6 +100,9 @@ func (rot *APLRotation) newActionStrictSequence(config *proto.APLActionStrictSeq
return rot.newAPLAction(action)
})
actions = FilterSlice(actions, func(action *APLAction) bool { return action != nil })
if len(actions) == 0 {
return nil
}

return &APLActionStrictSequence{
unit: rot.unit,
Expand All @@ -123,14 +129,8 @@ func (action *APLActionStrictSequence) IsReady(sim *Simulation) bool {
return true
}
func (action *APLActionStrictSequence) Execute(sim *Simulation) {
if !action.actions[action.curIdx].IsReady(sim) {
action.curIdx = 0
action.unit.Rotation.strictSequence = nil
return
}

action.curIdx++
action.actions[action.curIdx].Execute(sim)
action.curIdx++

if action.curIdx == len(action.actions) {
action.curIdx = 0
Expand Down
Loading