protected override void ComposePrioritizedEffectors(List <Effector> effList) { Effector actionEffector = null; Object actionObject = null; Reflex reflex = null; #if PRIORITYDISTANCE // find the nearest attractor foreach (KeyValuePair <Reflex, ActionSet> pair in itemSets) { Action testTarget = pair.Value.Closest(); if (testTarget != null && (actionTarget == null || actionTarget.distance > testTarget.distance)) { actionTarget = testTarget; actionObject = pair.Key; } } #else // find the highest priority action ActionSet prioritizedSet = null; foreach (KeyValuePair <Reflex, ActionSet> pair in itemSets) { ActionSet testSet = pair.Value; Effector testEffector = pair.Value.ClosestAction(); if (testEffector != null) { if (prioritizedSet == null || testSet.priority < prioritizedSet.priority) { prioritizedSet = testSet; actionEffector = testEffector; actionObject = pair.Key; } } } #endif if (actionEffector != null) { actionEffector.used = true; // let the reflex know it was prioritized and used reflex = actionObject as Reflex; if (reflex != null) { reflex.Used(reflex != lastReflex); } effList.Add(actionEffector); return; } lastReflex = reflex; }