working on AI
This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
|  | using RebootKit.Engine.Simulation; | ||||||
|  |  | ||||||
| namespace RebootKit.Engine.AI { | namespace RebootKit.Engine.AI { | ||||||
|     public class BehaviourNode { |     public class BehaviourNode { | ||||||
| @@ -23,8 +24,8 @@ namespace RebootKit.Engine.AI { | |||||||
|             Children.Add(child); |             Children.Add(child); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public virtual Status Process(float dt) { |         public virtual Status Process(Actor target, float dt) { | ||||||
|             return Children[m_CurrentChild].Process(dt); |             return Children[m_CurrentChild].Process(target, dt); | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         public virtual void Reset() { |         public virtual void Reset() { | ||||||
|   | |||||||
| @@ -1,11 +1,13 @@ | |||||||
| namespace RebootKit.Engine.AI { | using RebootKit.Engine.Simulation; | ||||||
|  |  | ||||||
|  | namespace RebootKit.Engine.AI { | ||||||
|     public class BehaviourTree : BehaviourNode { |     public class BehaviourTree : BehaviourNode { | ||||||
|         public BehaviourTree(string name) : base(name) { |         public BehaviourTree(string name) : base(name) { | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Status Process(float dt) { |         public override Status Process(Actor target, float dt) { | ||||||
|             while (m_CurrentChild < Children.Count) { |             while (m_CurrentChild < Children.Count) { | ||||||
|                 Status status = Children[m_CurrentChild].Process(dt); |                 Status status = Children[m_CurrentChild].Process(target, dt); | ||||||
|                 if (status != Status.Success) { |                 if (status != Status.Success) { | ||||||
|                     return status; |                     return status; | ||||||
|                 } |                 } | ||||||
|   | |||||||
| @@ -1,8 +1,9 @@ | |||||||
| using System; | using System; | ||||||
|  | using RebootKit.Engine.Simulation; | ||||||
|  |  | ||||||
| namespace RebootKit.Engine.AI { | namespace RebootKit.Engine.AI { | ||||||
|     public interface IStrategy { |     public interface IStrategy { | ||||||
|         BehaviourNode.Status Process(float dt); |         BehaviourNode.Status Process(Actor target, float dt); | ||||||
|         void Reset() { |         void Reset() { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -14,7 +15,7 @@ namespace RebootKit.Engine.AI { | |||||||
|             m_Predicate = predicate; |             m_Predicate = predicate; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         public BehaviourNode.Status Process(float dt) { |         public BehaviourNode.Status Process(Actor target, float dt) { | ||||||
|             if (m_Predicate()) { |             if (m_Predicate()) { | ||||||
|                 return BehaviourNode.Status.Success; |                 return BehaviourNode.Status.Success; | ||||||
|             } |             } | ||||||
| @@ -30,7 +31,7 @@ namespace RebootKit.Engine.AI { | |||||||
|             m_Action = action; |             m_Action = action; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public BehaviourNode.Status Process(float dt) { |         public BehaviourNode.Status Process(Actor target, float dt) { | ||||||
|             m_Action(); |             m_Action(); | ||||||
|             return BehaviourNode.Status.Success; |             return BehaviourNode.Status.Success; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -1,4 +1,6 @@ | |||||||
| namespace RebootKit.Engine.AI { | using RebootKit.Engine.Simulation; | ||||||
|  |  | ||||||
|  | namespace RebootKit.Engine.AI { | ||||||
|     public class Leaf : BehaviourNode { |     public class Leaf : BehaviourNode { | ||||||
|         readonly IStrategy m_Strategy; |         readonly IStrategy m_Strategy; | ||||||
|          |          | ||||||
| @@ -6,8 +8,8 @@ | |||||||
|             m_Strategy = strategy; |             m_Strategy = strategy; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Status Process(float dt) { |         public override Status Process(Actor target, float dt) { | ||||||
|             return m_Strategy.Process(dt); |             return m_Strategy.Process(target, dt); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override void Reset() { |         public override void Reset() { | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| using System; | using System; | ||||||
|  | using RebootKit.Engine.Simulation; | ||||||
|  |  | ||||||
| namespace RebootKit.Engine.AI { | namespace RebootKit.Engine.AI { | ||||||
|     public class Selector : BehaviourNode { |     public class Selector : BehaviourNode { | ||||||
| @@ -8,13 +9,13 @@ namespace RebootKit.Engine.AI { | |||||||
|             m_Condition = condition; |             m_Condition = condition; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         public override Status Process(float dt) { |         public override Status Process(Actor target, float dt) { | ||||||
|             if (m_Condition != null && !m_Condition()) { |             if (m_Condition != null && !m_Condition()) { | ||||||
|                 return Status.Failure; |                 return Status.Failure; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (m_CurrentChild < Children.Count) { |             if (m_CurrentChild < Children.Count) { | ||||||
|                 Status status = Children[m_CurrentChild].Process(dt); |                 Status status = Children[m_CurrentChild].Process(target, dt); | ||||||
|              |              | ||||||
|                 switch (status) { |                 switch (status) { | ||||||
|                 case Status.Success: |                 case Status.Success: | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| using System; | using System; | ||||||
|  | using RebootKit.Engine.Simulation; | ||||||
|  |  | ||||||
| namespace RebootKit.Engine.AI { | namespace RebootKit.Engine.AI { | ||||||
|     public class Sequence : BehaviourNode { |     public class Sequence : BehaviourNode { | ||||||
| @@ -8,13 +9,13 @@ namespace RebootKit.Engine.AI { | |||||||
|             m_Condition = condition; |             m_Condition = condition; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Status Process(float dt) { |         public override Status Process(Actor target, float dt) { | ||||||
|             if (m_Condition != null && !m_Condition()) { |             if (m_Condition != null && !m_Condition()) { | ||||||
|                 return Status.Failure; |                 return Status.Failure; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (m_CurrentChild < Children.Count) { |             if (m_CurrentChild < Children.Count) { | ||||||
|                 Status status = Children[m_CurrentChild].Process(dt); |                 Status status = Children[m_CurrentChild].Process(target, dt); | ||||||
|              |              | ||||||
|                 switch (status) { |                 switch (status) { | ||||||
|                 case Status.Success: |                 case Status.Success: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user