public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { MyBehaviorTreeDecoratorNodeMemory nodeMemoryByIndex = botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory; if (this.m_child != null) { if (nodeMemoryByIndex.ChildState == MyBehaviorTreeState.RUNNING) { return(this.TickChild(bot, botTreeMemory, nodeMemoryByIndex)); } this.m_decoratorLogic.Update(nodeMemoryByIndex.DecoratorLogicMemory); if (this.m_decoratorLogic.CanRun(nodeMemoryByIndex.DecoratorLogicMemory)) { return(this.TickChild(bot, botTreeMemory, nodeMemoryByIndex)); } if (this.IsRunningStateSource) { bot.BotMemory.ProcessLastRunningNode(this); } botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex).NodeState = this.m_defaultReturnValue; if (MyDebugDrawSettings.DEBUG_DRAW_BOTS && (this.m_defaultReturnValue == MyBehaviorTreeState.RUNNING)) { base.m_runningActionName = "Par_N" + this.m_decoratorLogicName; } } return(this.m_defaultReturnValue); }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { var decoratorMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory; if (m_child == null) { return(m_defaultReturnValue); } if (decoratorMemory.ChildState != MyBehaviorTreeState.RUNNING) { m_decoratorLogic.Update(decoratorMemory.DecoratorLogicMemory); if (m_decoratorLogic.CanRun(decoratorMemory.DecoratorLogicMemory)) { return(TickChild(bot, botTreeMemory, decoratorMemory)); } else { if (IsRunningStateSource) { bot.BotMemory.ProcessLastRunningNode(this); } botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = m_defaultReturnValue; return(m_defaultReturnValue); } } else { return(TickChild(bot, botTreeMemory, decoratorMemory)); } }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeControlNodeMemory; for (int i = nodeMemory.InitialIndex; i < m_children.Count; i++) { bot.BotMemory.RememberNode(m_children[i].MemoryIndex); var state = m_children[i].Tick(bot, botTreeMemory); if (state == SearchedValue || state == FinalValue) { m_children[i].PostTick(bot, botTreeMemory); } if (state == MyBehaviorTreeState.RUNNING || state == SearchedValue) { nodeMemory.NodeState = state; if (state == MyBehaviorTreeState.RUNNING) { if (m_isMemorable) { nodeMemory.InitialIndex = i; } } else { bot.BotMemory.ForgetNode(); } return(state); } bot.BotMemory.ForgetNode(); } nodeMemory.NodeState = FinalValue; return(FinalValue); }
public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).PostTickMemory(); foreach (var child in m_children) { child.PostTick(bot, botTreeMemory); } }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { MyBehaviorTreeState state; MyBehaviorTreeControlNodeMemory nodeMemoryByIndex = botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex) as MyBehaviorTreeControlNodeMemory; int initialIndex = nodeMemoryByIndex.InitialIndex; while (true) { if (initialIndex >= this.m_children.Count) { nodeMemoryByIndex.NodeState = this.FinalValue; nodeMemoryByIndex.InitialIndex = 0; return(this.FinalValue); } bot.BotMemory.RememberNode(this.m_children[initialIndex].MemoryIndex); if (MyDebugDrawSettings.DEBUG_DRAW_BOTS) { if (this.m_children[initialIndex] is MyBehaviorTreeControlBaseNode) { string name = (this.m_children[initialIndex] as MyBehaviorTreeControlBaseNode).m_name; } else if (this.m_children[initialIndex] is MyBehaviorTreeActionNode) { (this.m_children[initialIndex] as MyBehaviorTreeActionNode).GetActionName(); } else if (this.m_children[initialIndex] is MyBehaviorTreeDecoratorNode) { (this.m_children[initialIndex] as MyBehaviorTreeDecoratorNode).GetName(); } base.m_runningActionName = ""; } state = this.m_children[initialIndex].Tick(bot, botTreeMemory); if ((state == this.SearchedValue) || (state == this.FinalValue)) { this.m_children[initialIndex].PostTick(bot, botTreeMemory); } if (state == MyBehaviorTreeState.RUNNING) { break; } if (state == this.SearchedValue) { break; } bot.BotMemory.ForgetNode(); initialIndex++; } nodeMemoryByIndex.NodeState = state; if (state != MyBehaviorTreeState.RUNNING) { bot.BotMemory.ForgetNode(); } else if (this.m_isMemorable) { nodeMemoryByIndex.InitialIndex = initialIndex; } return(state); }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { var decoratorMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory; if (m_child == null) { return(m_defaultReturnValue); } if (decoratorMemory.ChildState != MyBehaviorTreeState.RUNNING) { m_decoratorLogic.Update(decoratorMemory.DecoratorLogicMemory); if (m_decoratorLogic.CanRun(decoratorMemory.DecoratorLogicMemory)) { MyBehaviorTreeState state = TickChild(bot, botTreeMemory, decoratorMemory); RecordRunningNodeName(state); return(state); } else { if (IsRunningStateSource) { bot.BotMemory.ProcessLastRunningNode(this); } botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = m_defaultReturnValue; if (Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS && m_defaultReturnValue == MyBehaviorTreeState.RUNNING) { m_runningActionName = ParentName + m_decoratorLogicName; } return(m_defaultReturnValue); } } else { MyBehaviorTreeState state = TickChild(bot, botTreeMemory, decoratorMemory); RecordRunningNodeName(state); return(state); //return TickChild(bot, botTreeMemory, decoratorMemory); } }
public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex).PostTickMemory(); using (List <MyBehaviorTreeNode> .Enumerator enumerator = this.m_children.GetEnumerator()) { while (enumerator.MoveNext()) { enumerator.Current.PostTick(bot, botTreeMemory); } } }
public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { MyBehaviorTreeNodeMemory nodeMemoryByIndex = botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex); if (nodeMemoryByIndex.InitCalled) { if (bot.ActionCollection.ContainsPostAction(this.m_actionName)) { bot.ActionCollection.PerformPostAction(bot, this.m_actionName); } nodeMemoryByIndex.InitCalled = false; } }
public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex); if (nodeMemory.InitCalled) { if (bot.ActionCollection.ContainsPostAction(m_actionName)) { bot.ActionCollection.PerformPostAction(bot, m_actionName); } nodeMemory.InitCalled = false; } }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { bot.BotMemory.RememberNode(m_child.MemoryIndex); var state = m_child.Tick(bot, botTreeMemory); botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = state; if (state != MyBehaviorTreeState.RUNNING) { bot.BotMemory.ForgetNode(); } return(state); }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { bot.BotMemory.RememberNode(this.m_child.MemoryIndex); if (MyDebugDrawSettings.DEBUG_DRAW_BOTS) { bot.LastBotMemory = bot.BotMemory.Clone(); } MyBehaviorTreeState state = this.m_child.Tick(bot, botTreeMemory); botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex).NodeState = state; if (state != MyBehaviorTreeState.RUNNING) { bot.BotMemory.ForgetNode(); } return(state); }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { var nodeMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeControlNodeMemory; for (int i = nodeMemory.InitialIndex; i < m_children.Count; i++) { bot.BotMemory.RememberNode(m_children[i].MemoryIndex); if (Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS) { string childName = (m_children[i] is MyBehaviorTreeControlBaseNode) ? ((m_children[i] as MyBehaviorTreeControlBaseNode)).m_name : (m_children[i] is MyBehaviorTreeActionNode)? (m_children[i] as MyBehaviorTreeActionNode).GetActionName(): (m_children[i] is MyBehaviorTreeDecoratorNode)? (m_children[i] as MyBehaviorTreeDecoratorNode).GetName(): ""; // just variable for conditional debugging m_runningActionName = ""; // this line is good candidate for breakpoint is you want to debug special part of behavior tree } var state = m_children[i].Tick(bot, botTreeMemory); if (state == SearchedValue || state == FinalValue) { m_children[i].PostTick(bot, botTreeMemory); } if (state == MyBehaviorTreeState.RUNNING || state == SearchedValue) { nodeMemory.NodeState = state; if (state == MyBehaviorTreeState.RUNNING) { if (m_isMemorable) { nodeMemory.InitialIndex = i; } } else { bot.BotMemory.ForgetNode(); } RecordRunningNodeName(state, m_children[i]); return(state); } bot.BotMemory.ForgetNode(); } nodeMemory.NodeState = FinalValue; nodeMemory.InitialIndex = 0; return(FinalValue); }
private void SendDataToTool(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { if (!this.DebugIsCurrentTreeVerified || (this.DebugLastWindowHandle.ToInt32() != this.m_toolWindowHandle.ToInt32())) { IntPtr wParam = new IntPtr(this.m_BTDataByName[this.m_botBehaviorIds[bot]].BehaviorTree.GetHashCode()); WinApi.PostMessage(this.m_toolWindowHandle, 0x403, wParam, IntPtr.Zero); this.DebugIsCurrentTreeVerified = true; this.DebugLastWindowHandle = new IntPtr(this.m_toolWindowHandle.ToInt32()); } WinApi.PostMessage(this.m_toolWindowHandle, 0x401, IntPtr.Zero, IntPtr.Zero); for (int i = 0; i < botTreeMemory.NodesMemoryCount; i++) { MyBehaviorTreeState nodeState = botTreeMemory.GetNodeMemoryByIndex(i).NodeState; if (nodeState != MyBehaviorTreeState.NOT_TICKED) { WinApi.PostMessage(this.m_toolWindowHandle, 0x400, new IntPtr((long)((ulong)i)), new IntPtr((int)nodeState)); } } WinApi.PostMessage(this.m_toolWindowHandle, 0x402, IntPtr.Zero, IntPtr.Zero); }
public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { base.PostTick(bot, botTreeMemory); var decoratorMemory = botTreeMemory.GetNodeMemoryByIndex(MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory; if (decoratorMemory.ChildState != MyBehaviorTreeState.NOT_TICKED) { decoratorMemory.PostTickMemory(); if (m_child != null) { m_child.PostTick(bot, botTreeMemory); } } else { if (IsRunningStateSource) { decoratorMemory.PostTickMemory(); } } }
public override void PostTick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { base.PostTick(bot, botTreeMemory); MyBehaviorTreeDecoratorNodeMemory nodeMemoryByIndex = botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex) as MyBehaviorTreeDecoratorNodeMemory; if (nodeMemoryByIndex.ChildState == MyBehaviorTreeState.NOT_TICKED) { if (this.IsRunningStateSource) { nodeMemoryByIndex.PostTickMemory(); } } else { nodeMemoryByIndex.PostTickMemory(); if (this.m_child != null) { this.m_child.PostTick(bot, botTreeMemory); } } }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { if (bot.ActionCollection.ReturnsRunning(this.m_actionName)) { bot.BotMemory.ProcessLastRunningNode(this); } MyBehaviorTreeNodeMemory nodeMemoryByIndex = botTreeMemory.GetNodeMemoryByIndex(base.MemoryIndex); if (!nodeMemoryByIndex.InitCalled) { nodeMemoryByIndex.InitCalled = true; if (bot.ActionCollection.ContainsInitAction(this.m_actionName)) { bot.ActionCollection.PerformInitAction(bot, this.m_actionName); } } MyBehaviorTreeState state = bot.ActionCollection.PerformAction(bot, this.m_actionName, this.m_parameters); nodeMemoryByIndex.NodeState = state; return(state); }
public override MyBehaviorTreeState Tick(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { bot.BotMemory.RememberNode(m_child.MemoryIndex); if (Sandbox.Engine.Utils.MyDebugDrawSettings.DEBUG_DRAW_BOTS) { // store this old memory bot.LastBotMemory = bot.BotMemory.Clone(); } var state = m_child.Tick(bot, botTreeMemory); botTreeMemory.GetNodeMemoryByIndex(MemoryIndex).NodeState = state; RecordRunningNodeName(bot, state); if (state != MyBehaviorTreeState.RUNNING) { bot.BotMemory.ForgetNode(); } return(state); }
private void SendDataToTool(IMyBot bot, MyPerTreeBotMemory botTreeMemory) { if (!DebugIsCurrentTreeVerified || DebugLastWindowHandle.ToInt32() != m_toolWindowHandle.ToInt32()) { int hash = bot.BehaviorTree.GetHashCode(); IntPtr toSend = new IntPtr(hash); WinApi.PostMessage(m_toolWindowHandle, MyWMCodes.BEHAVIOR_TOOL_VALIDATE_TREE, toSend, IntPtr.Zero); DebugIsCurrentTreeVerified = true; DebugLastWindowHandle = new IntPtr(m_toolWindowHandle.ToInt32()); } WinApi.PostMessage(m_toolWindowHandle, MyWMCodes.BEHAVIOR_TOOL_CLEAR_NODES, IntPtr.Zero, IntPtr.Zero); for (int i = 0; i < botTreeMemory.NodesMemoryCount; ++i) { var state = botTreeMemory.GetNodeMemoryByIndex(i).NodeState; if (state == MyBehaviorTreeState.NOT_TICKED) { continue; } WinApi.PostMessage(m_toolWindowHandle, MyWMCodes.BEHAVIOR_TOOL_SET_DATA, new IntPtr((uint)i), new IntPtr((int)state)); } WinApi.PostMessage(m_toolWindowHandle, MyWMCodes.BEHAVIOR_TOOL_END_SENDING_DATA, IntPtr.Zero, IntPtr.Zero); }