Skip to content

Commit

Permalink
[game] wrap call to undoLastMoveAction in a method call
Browse files Browse the repository at this point in the history
ghthor committed Feb 22, 2015

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 31fd6a7 commit b023f45
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions game/actor.go
Original file line number Diff line number Diff line change
@@ -173,6 +173,12 @@ func (a *actor) applyTurnAction(ta coord.TurnAction) {
a.actorCmdRequest.moveRequest = nil
}

func (a *actor) revertMoveAction() {
if a.undoLastMoveAction != nil {
a.undoLastMoveAction()
}
}

func (a *actorConn) startIO() {
// Setup communication channels
cmdCh := make(chan actorCmd)
20 changes: 10 additions & 10 deletions game/sim.go
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ func (phase narrowPhase) resolveActorActorCollision(a, b *actor) {

switch cellCollision.Type() {
case coord.CT_CELL_DEST:
a.undoLastMoveAction()
a.revertMoveAction()
}

case a.pathAction != nil && b.pathAction != nil:
@@ -151,8 +151,8 @@ func (phase narrowPhase) resolveActorActorCollision(a, b *actor) {
return

case coord.CT_SWAP:
a.undoLastMoveAction()
b.undoLastMoveAction()
a.revertMoveAction()
b.revertMoveAction()

case coord.CT_A_INTO_B_FROM_SIDE:
if a.pathAction.End() >= b.pathAction.End() {
@@ -162,30 +162,30 @@ func (phase narrowPhase) resolveActorActorCollision(a, b *actor) {
fallthrough

case coord.CT_A_INTO_B:
a.undoLastMoveAction()
a.revertMoveAction()

case coord.CT_HEAD_TO_HEAD:
fallthrough

case coord.CT_FROM_SIDE:
if a.pathAction.Start() < b.pathAction.Start() {
// A has already won the destination
b.undoLastMoveAction()
b.revertMoveAction()
return
} else if a.pathAction.Start() > b.pathAction.Start() {
// B has already won the destination
a.undoLastMoveAction()
a.revertMoveAction()
return
}
// Start values are equal

if a.pathAction.End() < b.pathAction.End() {
// A is moving faster and wins the destination
b.undoLastMoveAction()
b.revertMoveAction()
return
} else if a.pathAction.End() > b.pathAction.End() {
// B is moving faster and wins the destination
a.undoLastMoveAction()
a.revertMoveAction()
return
}
// End values are equal
@@ -194,11 +194,11 @@ func (phase narrowPhase) resolveActorActorCollision(a, b *actor) {
// N -> E -> S -> W
if a.facing < b.facing {
// A's movement direction has a higher priority
b.undoLastMoveAction()
b.revertMoveAction()
return
} else {
// B's movement direction has a higher priority
a.undoLastMoveAction()
a.revertMoveAction()
return
}
}

0 comments on commit b023f45

Please sign in to comment.