Created
September 30, 2011 03:33
-
-
Save dlwh/1252573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Action { | |
// ... | |
def instantiate(inventory: ResourceMap[Resource], units: Iterable[Unit]):ActionMachine | |
} | |
class BuildAction(tpe: UnitType) extends AwesomeAction { | |
def instantiate(inventory: ResourceMap[Resource], units: Iterable[Unit]):ActionMachine = new ActionMachine { | |
val builder = units.head | |
// register failure handler | |
val failHandle = on(builder.death) { event => fail()} | |
var position = findBuildSpot(...) | |
self.loop(frame) until (builder.closeTo(position) | failure) { frame => | |
if(!builder.canBuildHere(position,tpe)) { | |
position = findBuildSpot(...) | |
} | |
} | |
// suspend until building started, return new building | |
builder.startBuilding(position,tpe) match { | |
Some(building) => | |
None => fail() | |
} | |
// register completion and failure handlers | |
on(newBuilding.complete) { event => succeed() } | |
on(newBuilding.death) { event => fail() } | |
} | |
val failure = new EventSource[Fail[MoveAction]] | |
val success = new EventSource[Success[MoveAction]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment