@@ -17,9 +17,22 @@ namespace behaviac
1717{
1818 public class SelectorLoop : BehaviorNode
1919 {
20+ protected bool m_bResetChildren = false ;
21+
2022 protected override void load ( int version , string agentType , List < property_t > properties )
2123 {
2224 base . load ( version , agentType , properties ) ;
25+
26+ for ( int i = 0 ; i < properties . Count ; ++ i )
27+ {
28+ property_t p = properties [ i ] ;
29+
30+ if ( p . name == "ResetChildren" )
31+ {
32+ this . m_bResetChildren = ( p . value == "true" ) ;
33+ break ;
34+ }
35+ }
2336 }
2437
2538 public override bool IsValid ( Agent pAgent , BehaviorTask pTask )
@@ -44,9 +57,6 @@ protected override BehaviorTask createTask()
4457 return pTask ;
4558 }
4659
47- //List<BehaviorNode> m_preconditions;
48- //List<BehaviorNode> m_actions;
49-
5060 // ============================================================================
5161 /**
5262 behavives similarly to SelectorTask, i.e. executing chidren until the first successful one.
@@ -157,15 +167,29 @@ protected override EBTStatus update(Agent pAgent, EBTStatus childStatus)
157167 //clean up the current ticking action tree
158168 if ( index != ( int ) - 1 )
159169 {
160- if ( this . m_activeChildIndex != CompositeTask . InvalidChildIndex &&
161- this . m_activeChildIndex != index )
170+ if ( this . m_activeChildIndex != CompositeTask . InvalidChildIndex )
162171 {
163- WithPreconditionTask pCurrentSubTree = ( WithPreconditionTask ) this . m_children [ this . m_activeChildIndex ] ;
164- //BehaviorTask action = pCurrentSubTree.ActionNode;
165- pCurrentSubTree . abort ( pAgent ) ;
172+ bool abortChild = ( this . m_activeChildIndex != index ) ;
173+ if ( ! abortChild )
174+ {
175+ SelectorLoop pSelectorLoop = ( SelectorLoop ) ( this . GetNode ( ) ) ;
176+ Debug . Check ( pSelectorLoop != null ) ;
177+
178+ if ( pSelectorLoop != null )
179+ {
180+ abortChild = pSelectorLoop . m_bResetChildren ;
181+ }
182+ }
183+
184+ if ( abortChild )
185+ {
186+ WithPreconditionTask pCurrentSubTree = ( WithPreconditionTask ) this . m_children [ this . m_activeChildIndex ] ;
187+ //BehaviorTask action = pCurrentSubTree.ActionNode;
188+ pCurrentSubTree . abort ( pAgent ) ;
166189
167- //don't set it here
168- //this.m_activeChildIndex = index;
190+ //don't set it here
191+ //this.m_activeChildIndex = index;
192+ }
169193 }
170194
171195 for ( int i = index ; i < this . m_children . Count ; ++ i )
0 commit comments