public override void ExecuteTask(Simulation Sim) { switch (State) { case States.Mining: AssignedGnome.FacingDirection = CellLink.DirectionFromAToB(AssignedGnome.Location, Location); Progress -= 0.1f;//Game.ElapsedSeconds; if (Progress <= 0.0f) { MineMutation = new WorldMutations.RemoveBlockMutation(Location, AssignedGnome); Sim.AddWorldMutation(MineMutation); State = States.Finalizing; } return; case States.Finalizing: if (MineMutation.Result == MutationResult.Failure) State = States.Mining; else { State = States.Done; Sim.AddTask(new RemoveExcessResource(Location)); } return; case States.Done: throw new InvalidProgramException("Task should have been deemed completed."); } }
public override void ExecuteTask(Simulation Sim) { AssignedGnome.FacingDirection = CellLink.DirectionFromAToB(AssignedGnome.Location, Location); var cell = Sim.World.CellAt(Location); switch (State) { case States.Preparing: ClearResourcesMutation = new WorldMutations.ClearResourcesMutation(Location, new List<String>(cell.Resources)); Sim.AddWorldMutation(ClearResourcesMutation); State = States.ClearingResources; return; case States.ClearingResources: if (ClearResourcesMutation.Result != MutationResult.Success) State = States.Preparing; else { Progress = 1.0f; State = States.Constructing; } return; case States.Constructing: Progress -= 0.1f;//Sim.ElapsedSeconds; if (Progress <= 0.0f) { BuildMutation = new WorldMutations.PlaceBlockMutation(Location, BlockType); Sim.AddWorldMutation(BuildMutation); State = States.Finalizing; } return; case States.Finalizing: if (BuildMutation.Result == MutationResult.Success) throw new InvalidProgramException("Task should have been deemed completed."); Progress = 0.0f; State = States.Constructing; // Try to build it again. return; default: throw new InvalidProgramException("Uknown Case"); } }
public override void ExecuteTask(Simulation Sim) { var cell = Sim.World.CellAt(Location); int resourceIndex = 0; if (ParentTask != null) { var excess = Task.FindExcessResources(cell, ParentTask); resourceIndex = cell.Resources.FindIndex(i => excess.Contains(i)); } if (resourceIndex >= 0) Sim.AddWorldMutation(new WorldMutations.PickupResourceMutation(Location, cell.Resources[resourceIndex], AssignedGnome)); }
public override void ExecuteTask(Simulation Sim) { var dropLocation = EnumerateAdjacent(AssignedGnome.Location).First(c => Sim.World.Check(c) && CanPlace(Sim.World.CellAt(c), AssignedGnome.CarriedResource)); Sim.AddWorldMutation(new WorldMutations.DropResourceMutation(dropLocation, AssignedGnome.CarriedResource, AssignedGnome)); }
public override void ExecuteTask(Simulation Sim) { Sim.AddWorldMutation(new WorldMutations.DropResourceMutation(Location, AssignedGnome.CarriedResource, AssignedGnome)); }