void IAI.ActionDone(ActionDoneEvent e) { if (m_currentAction == null) return; if (e.GUID == m_currentAction.GUID) { Debug.Assert(m_actions[0] == m_currentAction); m_currentAction = null; m_actions.RemoveAt(0); } }
void IAI.ActionDone(ActionDoneEvent e) { if (m_currentAction == null) { return; } if (e.GUID == m_currentAction.GUID) { Debug.Assert(m_actions[0] == m_currentAction); m_currentAction = null; m_actions.RemoveAt(0); } }
public void HandleActionDone(ActionDoneEvent e) { Debug.Assert(this.HasAction); if (this.AI != null) { this.AI.ActionDone(e); } this.PreviousAction = this.CurrentAction; this.CurrentAction = null; this.ActionPriority = Dwarrowdelf.ActionPriority.Undefined; this.ActionTotalTicks = 0; this.ActionTicksUsed = 0; }
public void ActionDone(ActionDoneEvent e) { var assignment = this.CurrentAssignment; trace.TraceVerbose("ActionDone({0}, State {1}): Worker.Action = {2}, CurrentAssignment {3}, CurrentAssignment.Action = {4}", e.GUID, e.State, this.Worker.HasAction ? this.Worker.CurrentAction.ToString() : "<none>", assignment != null ? assignment.ToString() : "<none>", assignment != null && assignment.CurrentAction != null ? assignment.CurrentAction.ToString() : "<none>"); Debug.Assert(this.Worker.HasAction); Debug.Assert(e.GUID == this.Worker.CurrentAction.GUID); if (assignment == null) { trace.TraceVerbose("ActionDone: no assignment, so not for me"); return; } if (e.State == ActionState.Abort && assignment.CurrentAction != null && assignment.CurrentAction.GUID != e.GUID) { trace.TraceVerbose("ActionDone: cancel event for action not started by us, ignore"); return; } if (assignment.CurrentAction == null) { // XXX this can happen when doing a multi-turn action, and the user aborts the action. throw new NotImplementedException("implement cancel work"); } // does the action originate from us? if (assignment.CurrentAction.GUID != e.GUID) { throw new NotImplementedException("implement cancel work"); } var state = assignment.ActionDone(e.State); trace.TraceVerbose("ActionDone: {0} in {1}", state, assignment); }
void HandleActionDone(ActionState state) { var e = new ActionDoneEvent() { GUID = this.CurrentAction.GUID, State = state, }; if (m_ai != null) { m_ai.ActionDone(e); } var c = new ActionDoneChange(this) { ActionDoneEvent = e, }; this.CurrentAction = null; this.ActionPriority = Dwarrowdelf.ActionPriority.Undefined; this.ActionTotalTicks = this.ActionTicksUsed = 0; this.World.AddChange(c); }
void HandleActionDone(ActionState state) { var e = new ActionDoneEvent() { MagicNumber = this.CurrentAction.MagicNumber, UserID = this.ActionUserID, State = state, Action = this.CurrentAction, }; if (m_ai != null) m_ai.ActionDone(e); var c = new ActionDoneChange(this) { ActionDoneEvent = e, }; this.CurrentAction = null; this.ActionPriority = Dwarrowdelf.ActionPriority.Undefined; this.ActionTotalTicks = this.ActionTicksUsed = 0; this.ActionUserID = 0; this.World.AddChange(c); }
public void HandleActionDone(ActionDoneEvent e) { Debug.Assert(this.HasAction); //if (e.State != ActionState.Done) // Debug.Print("ActionDone({0}, {1}, {2})", this, e.State, this.CurrentAction); if (this.AI != null) this.AI.ActionDone(e); this.PreviousAction = this.CurrentAction; this.CurrentAction = null; this.ActionPriority = Dwarrowdelf.ActionPriority.Undefined; this.ActionTotalTicks = 0; this.ActionTicksUsed = 0; }
private bool Tick() { if (lockCount > 0) { return(false); } Actor actor = Queue[0]; if (actor == null) { return(false); } if (currentActorRemoved) { currentActorRemoved = false; return(true); } while (actor.Energy > 0) { Profiler.BeginSample("Scheduler: Act()"); currentActor = actor; int actionCost = actor.Act(); currentActor = null; Profiler.EndSample(); if (currentActorRemoved) { currentActorRemoved = false; return(true); } if (actionCost == 0) { UnityEngine.Debug.LogWarning( "A command with 0 energy cost was scheduled."); } SendActorDebugEvent(actor); // Handle asynchronous input by returning -1 if (actionCost < 0) { return(false); } // An action has just been done actor.Energy -= actionCost; ActionDoneEvent?.Invoke(); Profiler.BeginSample("Scheduler: Draw Dirty"); actor.Entity.Level.Draw(dirtyCells); dirtyCells.Clear(); Profiler.EndSample(); Profiler.BeginSample("Scheduler: Player"); if (actor.Control == ActorControl.Player) { FOV.RefreshFOV(player.Entity.Level, player.Entity.Cell, true); float speedFactor = actor.Speed / TurnTime; turnProgress += Mathf.FloorToInt(actionCost / speedFactor); if (turnProgress >= TurnTime) { int turnsPassed = turnProgress / TurnTime; turns += turnsPassed; turnProgress %= TurnTime; for (int i = 0; i < turnsPassed; i++) { ClockTickEvent?.Invoke(); } TimeChangeEvent?.Invoke(turns); } // Signals a successful player action to HUD PlayerActionEvent?.Invoke(actor.Energy); } Profiler.EndSample(); // Action may have added a lock if (lockCount > 0) { return(false); } } // Give the actor their speed value's worth of energy back actor.Energy += actor.Speed; // Update HUD again to reflect refill if (actor.Control == ActorControl.Player) { PlayerActionEvent?.Invoke(actor.Energy); } Actor dequeued = Queue[0]; Queue.RemoveAt(0); Queue.Add(dequeued); return(true); }
public void HandleActionDone(ActionDoneEvent e) { Debug.Assert(this.HasAction); if (this.AI != null) this.AI.ActionDone(e); this.PreviousAction = this.CurrentAction; this.CurrentAction = null; this.ActionPriority = Dwarrowdelf.ActionPriority.Undefined; this.ActionTotalTicks = 0; this.ActionTicksUsed = 0; }
public void ActionDone(ActionDoneEvent e) { var assignment = this.CurrentAssignment; trace.TraceVerbose("ActionDone({0}, State {1}): Worker.Action = {2}, CurrentAssignment {3}, CurrentAssignment.Action = {4}", e.MagicNumber, e.State, this.Worker.HasAction ? this.Worker.CurrentAction.ToString() : "<none>", assignment != null ? assignment.ToString() : "<none>", assignment != null && assignment.CurrentAction != null ? assignment.CurrentAction.ToString() : "<none>"); Debug.Assert(this.Worker.HasAction); Debug.Assert(e.MagicNumber == this.Worker.CurrentAction.MagicNumber); if (assignment == null) { trace.TraceVerbose("ActionDone: no assignment, so not for me"); return; } if (e.State == ActionState.Abort && assignment.CurrentAction != null && assignment.CurrentAction.MagicNumber != e.MagicNumber) { trace.TraceVerbose("ActionDone: cancel event for action not started by us, ignore"); return; } if (assignment.CurrentAction == null) { // XXX this can happen when doing a multi-turn action, and the user aborts the action. throw new NotImplementedException("implement cancel work"); } // does the action originate from us? if (assignment.CurrentAction.MagicNumber != e.MagicNumber) { throw new NotImplementedException("implement cancel work"); } var state = assignment.ActionDone(e.State); trace.TraceVerbose("ActionDone: {0} in {1}", state, assignment); }