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