/********************************************************************* * \file BehaviourTreeSelector.cs * \author Ryan Wang Nian Jing * \brief Based off Kheng Ian's SC_BTSelector.cs * Selectors function like "OR" nodes, returning success on the * first successful child and stopping operation * * \copyright Copyright (c) 2022 DigiPen Institute of Technology. Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SHADE_Scripting.AIBehaviour.BehaviourTree { public class BehaviourTreeSelector : BehaviourTreeNode { public BehaviourTreeSelector(string name) : base(name) { } public BehaviourTreeSelector(string name, List children) : base(name, children) { } public override BehaviourTreeNodeStatus Evaluate() { onEnter(BehaviourTreeNodeStatus.RUNNING); for (int i = 0; i < children.Count; ++i) { switch (children[i].Evaluate()) { case BehaviourTreeNodeStatus.RUNNING: status = BehaviourTreeNodeStatus.RUNNING; onExit(BehaviourTreeNodeStatus.RUNNING); return status; case BehaviourTreeNodeStatus.SUCCESS: status = BehaviourTreeNodeStatus.SUCCESS; onExit(BehaviourTreeNodeStatus.SUCCESS); return status; case BehaviourTreeNodeStatus.FAILURE: continue; } } status = BehaviourTreeNodeStatus.FAILURE; onExit(BehaviourTreeNodeStatus.FAILURE); return status; } } }