public void trackTarget(LabelHandle target) { trackedTargets.Add(target); target.getPosition(); foreach (InherentEndeavourFactory factory in inherentEndeavours) { if (factory.isApplicable(target)) { Endeavour action = factory.constructEndeavour(this, target); if (action != null) { availableEndeavours.Add(action); dirty = true; } } } if (target.label != null) { foreach (Endeavour action in target.label.getAvailableEndeavours(this)) { availableEndeavours.Add(action); dirty = true; } } }
public virtual List <Endeavour> getAvailableEndeavours(RobotController controller) { List <Endeavour> availableEndeavours = new List <Endeavour> (); foreach (EndeavourFactory endeavour in endeavours) { Endeavour newEndeavour = endeavour.constructEndeavour(controller); if (newEndeavour != null) { availableEndeavours.Add(newEndeavour); } } return(availableEndeavours); }
public bool Equals(Endeavour endeavour) { return controller == endeavour.controller && name.Equals(endeavour.name); }
public void addEndeavour(Endeavour action) { availableEndeavours.Add (action); //evaluateActions (); dirty = true; }
private void evaluateActions() { List <DecisionInfoObject> debugText = new List <DecisionInfoObject>(); //print("****EVALUATE****"); dirty = false; PriorityQueue endeavourQueue = new PriorityQueue(); List <Endeavour> staleEndeavours = new List <Endeavour>(); //print("\tCurrent Endeavours"); foreach (Endeavour action in currentEndeavours) { if (action.isStale()) { //print("\t\tstale: " + action.getName()); action.stopExecution(); staleEndeavours.Add(action); } else { //print("\t\t++" + action.getName()); availableEndeavours.Add(action); } } //print("\tAvailable Endeavours"); foreach (Endeavour action in availableEndeavours) { if (action.isStale()) { //print("\t\t--" + action.getName()); staleEndeavours.Add(action); } else { //print("\t\t++" + action.getName()); endeavourQueue.Enqueue(action); } } foreach (Endeavour action in staleEndeavours) { //print("remove: " + action.getName()); availableEndeavours.Remove(action); currentEndeavours.Remove(action); } HashSet <Endeavour> proposedEndeavours = new HashSet <Endeavour>(); Dictionary <System.Type, int> componentMap = getComponentUsageMap(); #if UNITY_EDITOR bool maxPrioritySet = false; float localMaxPriority = 0; float localMinPriority = 0; #endif while (endeavourQueue.Count > 0) { Endeavour action = (Endeavour)endeavourQueue.Dequeue(); if (action.isReady(componentMap)) { #if UNITY_EDITOR if (debug) { float priority = action.getPriority(); if (!maxPrioritySet) { maxPrioritySet = true; localMaxPriority = priority; localMinPriority = priority; } else { if (priority > localMaxPriority) { localMaxPriority = priority; } if (priority < localMinPriority) { localMinPriority = priority; } } debugText.Add(new DecisionInfoObject(action.getName(), action.getParent().getName(), priority, true)); } #endif if (proposedEndeavours.Contains(action)) { Debug.LogError("action already proposed!!!"); } proposedEndeavours.Add(action); availableEndeavours.Remove(action); } else { #if UNITY_EDITOR if (debug) { float priority = action.getPriority(); if (!maxPrioritySet) { maxPrioritySet = true; localMaxPriority = priority; localMinPriority = priority; } else { if (priority > localMaxPriority) { localMaxPriority = priority; } if (priority < localMinPriority) { localMinPriority = priority; } } debugText.Add(new DecisionInfoObject(action.getName(), action.getParent().getName(), priority, false)); } #endif if (action.active) { action.stopExecution(); } } } // All previous actions MUST be stopped before we start the new ones foreach (Endeavour action in proposedEndeavours) { if (!action.active) { action.execute(); } } currentEndeavours = proposedEndeavours; #if UNITY_EDITOR if (debug) { lines = debugText; maxPriority = (Mathf.Abs(localMaxPriority) > Mathf.Abs(localMinPriority)) ? Mathf.Abs(localMaxPriority) : Mathf.Abs(localMinPriority); if (shouldAlphabetize) { alphabetize(); } } #endif }
public void addEndeavour(Endeavour action) { availableEndeavours.Add(action); //evaluateActions (); dirty = true; }
public void addEndeavour(Endeavour action) { availableEndeavours.Add (action); evaluateActions (); }
public bool Equals(Endeavour endeavour) { return(controller == endeavour.controller && name.Equals(endeavour.name)); }