Exemplo n.º 1
0
    // Update is called once per frame
    new void LateUpdate()
    {
        //Debug.Log ( NormalBehaviour );
        base.LateUpdate( );         //calls GetDistanceToTarget

        //near
        if (DistanceToTarget < TriggerDistance)
        {
            CurrentBehaviour        = NearBehaviour;
            NearBehaviour.enabled   = true;
            NormalBehaviour.enabled = false;
            FarBehaviour.enabled    = false;
            NearBehaviour.Target    = this.Target;
        }         //far
        else if ((DistanceToTarget > TriggerDistance * 2) && (FarBehaviour))
        {
            CurrentBehaviour        = FarBehaviour;
            NormalBehaviour.enabled = false;
            NearBehaviour.enabled   = false;
            FarBehaviour.enabled    = true;
            FarBehaviour.Target     = this.Target;
        }
        else         //wherever you are
        {
            CurrentBehaviour        = NormalBehaviour;
            NearBehaviour.enabled   = false;
            FarBehaviour.enabled    = false;
            NormalBehaviour.Target  = this.Target;
            NormalBehaviour.enabled = true;
        }
    }
Exemplo n.º 2
0
 void Start()
 {
     controller = GetComponent <CharacterController>();
     obj        = GameObject.FindGameObjectWithTag("NPC");
     aa         = obj.GetComponent <AI_Agent>();
     moveNpc    = obj.GetComponent <MoveNPC>();
 }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        elapsedTime = 0.0f;
        ai          = GetComponent <AI_Agent>();

        // 플레이어 위치 찾기
        playerTrans = GameObject.FindGameObjectWithTag("Player").transform;
    }
Exemplo n.º 4
0
 private void Awake()
 {
     clock            = new GameLengthClock();
     playerModel      = new PlayerModel(PlayerType.PLAYER);
     agentModel       = new PlayerModel(PlayerType.AI);
     ai_agent         = new AI_Agent();
     combatController = new CombatController();
     InitialiseHealthViews();
 }
Exemplo n.º 5
0
    void Start()
    {
        obj     = GameObject.FindGameObjectWithTag("NPC");
        ai      = obj.GetComponent <AI_Agent>();
        moveNpc = obj.GetComponent <MoveNPC>();

        // 플레이어 위치 찾기
        playerTrans = GameObject.FindGameObjectWithTag("Player").transform;
    }
Exemplo n.º 6
0
    public PlanState(AI_Agent inputAgent)
    {
        agent = inputAgent;

        availableActions = new HashSet <AI_Action>();
        currentActions   = new Queue <AI_Action>();

        worldState = dataProvider.getWorldState();
        goal       = dataProvider.createGoalState();

        Queue <AI_Action> plan = planner.plan(gameObject, availableActions, worldState, goal);
    }
Exemplo n.º 7
0
    public ScoringInfo(GridManager a_grid, AI_Agent a_agent, Unit a_player)
    {
        if (a_grid == null || a_agent == null || a_player == null)
        {
            Debug.LogError("ScoringInfo was given a null value in its constructor.");
        }

        grid   = a_grid;
        agent  = a_agent;
        player = a_player;

        path            = ClacPathToAttackRange(grid, agent, player);
        isInAttackRange = path != null && path.Count == 1 && path[0] == agent.CurrentTile;

        movesToAttackRange = path == null ? int.MinValue : ClacMovesToAttackRange(player, path);
    }
Exemplo n.º 8
0
    void OnCollisionEnter(Collision other)
    {
        //print ( "hit with " + other.collider.name );
        AI_Agent ai = other.gameObject.GetComponent <AI_Agent>( );

        if (ai)
        {
            if ((Owner == null) || (other.gameObject != Owner.gameObject))
            {
                ai.Health -= Damage;

                if (ai.Health <= 0)
                {
                    Destroy(other.gameObject);
                }
            }
        }
        if (Explosion)
        {
            Destroy(Instantiate(Explosion, transform.position, transform.rotation), 10);
        }

        Destroy(this.gameObject);
    }
    private void errorCheck(BT_TreeNode root, Status returnStatus, ref int errors, AI_Agent agent)
    {
        //RebuildTree(root);
        agent.CheckTreeVersion();
        Status beh = root.Tick(agent);

        // Check if it is the correct return type and if its not TC.invalid
        if (beh != returnStatus)
            errors++;
        if (beh == Status.Invalid)
            errors++;
    }
Exemplo n.º 10
0
 private void SetAgent(AI_Agent.BlackBoard access, string p1, string p2, object obj1, object obj2, AI_Agent agent)
 {
     agent[p1, access] = obj1;
     agent[p2, access] = obj2;
 }
Exemplo n.º 11
0
    public void TestDepth(AI_Agent agent)
    {
        BT_TreeNode f = T.UDel(T.failUpdate, "Fail");
        BT_TreeNode s = T.UDel(T.succesUpdate, "Succes");
        BT_TreeNode r = T.UDel(T.runningUpdate, "Running");
        BT_TreeNode b = T.UDel(T.pauseUpdate, "Pause");

        BT_TreeNode tree = T.sel(T.sel(T.sel(T.sel(s, s), s), s), s);

        //RebuildTree(tree);
        agent.CheckTreeVersion();

        tree.Tick(agent);
    }
Exemplo n.º 12
0
    public void SetTestTree(AI_Agent agent)
    {
        BT_TreeNode f = T.UDel(T.failUpdate, "Fail");
        BT_TreeNode s = T.UDel(T.succesUpdate, "Succes");
        BT_TreeNode r = T.UDel(T.runningUpdate, "Running");
        BT_TreeNode b = T.UDel(T.pauseUpdate, "Pause");

        //Root = TC.sel(TC.seq(TC.sel(TC.seq(s, f), s), s), s);
        //RebuildTree();
        agent.CheckTreeVersion();
    }
Exemplo n.º 13
0
    public void TestBTBasicCompontents(AI_Agent agent)
    {
        int errors = 0;

        #region Standard nodes

        BT_TreeNode f = T.UDel(T.failUpdate, "Fail");
        BT_TreeNode s = T.UDel(T.succesUpdate, "Succes");
        BT_TreeNode r = T.UDel(T.runningUpdate, "Running");
        BT_TreeNode b = T.UDel(T.pauseUpdate, "Pause");

        #endregion

        //if ((int)agent["Depth"] != 0)
        //    errors++;

        //SetAgentDebug(true);

        #region Composits: TC.selector, Sequencer

        // Check the TC.selector
        errorCheck(T.sel(f, f, r, s), Status.Running, ref errors, agent);
        errorCheck(T.sel(f, f, f, f), Status.Failed, ref errors, agent);
        errorCheck(T.sel(f, f, s, f), Status.Succes, ref errors, agent);

        // Check the sequencer
        errorCheck(T.seq(s, s, r, f), Status.Running, ref errors, agent);
        errorCheck(T.seq(s, s, r, s), Status.Running, ref errors, agent);
        errorCheck(T.seq(f, f, f, f), Status.Failed, ref errors, agent);
        errorCheck(T.seq(s, s, s, s), Status.Succes, ref errors, agent);

        #endregion

        #region Depth test

        // Generic depth test
        //TestDepth(agent);

        #endregion

        #region Decorators: TC.invert & alwaysFail

        // Check the TC.inverter
        errorCheck(T.inv(s), Status.Failed, ref errors, agent);
        errorCheck(T.inv(f), Status.Succes, ref errors, agent);
        errorCheck(T.inv(r), Status.Running, ref errors, agent);

        // Check the alwaysFailed
        errorCheck(T.fail(s), Status.Failed, ref errors, agent);
        errorCheck(T.fail(f), Status.Failed, ref errors, agent);
        errorCheck(T.fail(r), Status.Failed, ref errors, agent);

        #endregion

        //BT_TreeNode node = new BT_TreeNode(new BT_Decorator());

        #region Condition: CheckEqualBBParameter

        // Things to compare
        int int1 = 0;
        int int2 = 0;
        int int3 = 1;
        string str1 = "bla";
        string str2 = "bla";
        string str3 = "notbla";
        Vector3 v1 = Vector3.zero;
        Vector3 v2 = Vector3.zero;
        Vector3 v3 = Vector3.up;

        // BB params
        string p1 = "TestParam1";
        string p2 = "TestParam2";
        AI_Agent.BlackBoard local = AI_Agent.BlackBoard.local;
        AI_Agent.BlackBoard global = AI_Agent.BlackBoard.global;

        // Simple int check
        agent[p1, local] = int1;
        agent[p2, local] = int2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 0), Status.Succes, ref errors, agent);

        agent[p2, local] = int3;
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 1), Status.Failed, ref errors, agent);

        // cross global and local int check
        agent[p1, global] = int1;
        agent[p2, global] = int3;
        errorCheck(T.eqBB(p1, local, p1, global), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, p2, global), Status.Failed, ref errors, agent);

        // string check
        agent[p1, local] = str1;
        agent[p2, local] = str2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);

        agent[p2, local] = int3;
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);

        // cross global and local int check
        agent[p1, global] = str1;
        agent[p2, global] = str3;
        errorCheck(T.eqBB(p1, local, p1, global), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, p2, global), Status.Failed, ref errors, agent);

        // Vector3 check
        agent[p1, local] = v1;
        agent[p2, local] = v2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);

        agent[p2, local] = v3;
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);

        // cross global and local int check
        agent[p1, global] = v1;
        agent[p2, global] = v3;
        errorCheck(T.eqBB(p1, local, p1, global), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, p2, global), Status.Failed, ref errors, agent);


        #endregion

        #region Action: TC.copy BB value

        // int TC.copy
        // Check first
        agent[p1, local] = int1;
        agent[p2, local] = int2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 0), Status.Succes, ref errors, agent);

        // now TC.copy in 3
        errorCheck(T.copy(p1, local, 3), Status.Succes, ref errors, agent);
        // Check if it went allright
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 3), Status.Succes, ref errors, agent);

        // now TC.copy from p1 to p2
        errorCheck(T.copy(p2, local, p1, local), Status.Succes, ref errors, agent);

        // Check
        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 3), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p2, local, 3), Status.Succes, ref errors, agent);

        #endregion

        #region Action: Queue push, pop, checkSize

        string queueP1 = "TestQueue";
        string qCompare = "TestQueueComparer";

        // Create queue and populate
        fc.Queue<int> queue1 = new fc.Queue<int>();
        queue1.Add(1);
        queue1.Add(2);
        queue1.Add(3);

        // Populate the board
        agent[queueP1, local] = queue1;
        agent[qCompare, local] = -1;

        // Check size
        errorCheck(T.qSize(queueP1, local, 3), Status.Succes, ref errors, agent);

        // Check push
        errorCheck(T.qPush(queueP1, local, 4), Status.Succes, ref errors, agent);
        errorCheck(T.qSize(queueP1, local, 4), Status.Succes, ref errors, agent);

        // Check pop
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.qSize(queueP1, local, 3), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 1), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 2), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 3), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 4), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //Debug.Log(agent[qCompare, local]);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.qSize(queueP1, local, 0), Status.Succes, ref errors, agent);

        #region Test stuff
        //Queue<int> q = new Queue<int>();
        //q.Enqueue(6);
        //q.Enqueue(4);
        //q.Enqueue(2);

        //BT_QueuePop whatev = new BT_QueuePop("test", local, "test2", local);
        ////int testooh = (int)whatev.GetFromGenericQueue(q);
        //Debug.Log((int)whatev.GetFromGenericQueue(q));
        //Debug.Log((int)whatev.GetFromGenericQueue(q));
        //Debug.Log((int)whatev.GetFromGenericQueue(q));

        //List<int> test = new List<int>() { 1, 2, 3 };
        //IList list = (IList)test;
        //Debug.Log(list[0]);


        //fc.Stack<int> stack1 = new fc.Stack<int>();
        //fc.Stack<string> stack2 = new fc.Stack<string>();
        //stack1.Add(1);
        //stack1.Add(2);
        //stack1.Add(3);

        //Debug.Log(stack1.GetType().GetGenericTypeDefinition() + " - " + stack1.Get() + " " + stack1.Get() + " " + stack1.Get() + " " + stack1.Get());
        //fc.Queue<int> queue1 = new fc.Queue<int>();
        //queue1.Add(1);
        //queue1.Add(2);
        //queue1.Add(3);

        //fc.IQueue queueI = queue1;
        //Debug.Log(queue1.GetType().GetGenericTypeDefinition() == typeof(fc.Queue<>));
        //Debug.Log(queue1.GetType().GetGenericTypeDefinition());// + " - " + queue1.Get() + " " + queue1.Get() + " " + queue1.Get() + " " + queue1.Get());
        //Debug.Log(queueI.GetType().GetGenericTypeDefinition() + " - " + queueI.Get() + " " + queueI.Get() + " " + queueI.Get() + " " + queueI.Get());
        
        #endregion

        #endregion

        //Debug.Log("Depth" + (int)agent["Depth"]);
        //if ((int)agent["Depth"] != 0)
        //    errors++;

        if (errors != 0)
            Debug.Log("Behavior Tree test FAILED - " + errors + " Errors.");
        else
            Debug.Log("Behavior Tree test SUCCES - 0 Errors.");
    }
Exemplo n.º 14
0
 public PlanState(AI_Agent agent)
 {
     myAgent = agent;
 }
Exemplo n.º 15
0
 public DoActionState(AI_Agent inputAgent)
 {
 }
 public AI_AgentParameter(string parametername = "", AI_Agent.BlackBoard access = AI_Agent.BlackBoard.local)
     : this(parametername, access, null)
 { }
Exemplo n.º 17
0
 public static BT_TreeNode GetTreeNode(string bbParameter1, AI_Agent.BlackBoard param1, string bbParameter2, AI_Agent.BlackBoard param2)
 {
     return GetTreeNode(new AI_AgentParameter(bbParameter1, param1), new AI_AgentParameter(bbParameter2, param2));
 }
Exemplo n.º 18
0
 public static BT_TreeNode SetParameters(BT_TreeNode node, string bbParameter, AI_Agent.BlackBoard accesparam1, object setObject)
 {
     return SetParameters(node, new AI_AgentParameter(bbParameter, accesparam1), setObject);
 }
Exemplo n.º 19
0
 public static BT_TreeNode GetTreeNode(string bbParameter, AI_Agent.BlackBoard accesparam1, object setObject)
 {
     return GetTreeNode(new AI_AgentParameter(bbParameter, accesparam1), setObject);
 }
Exemplo n.º 20
0
    public void Init(AI_Agent a_Agent)
    {
        agent = a_Agent;

        scorer = new AI_Scorer(calculationCanvas, agent);
    }
Exemplo n.º 21
0
 public PerformActionState(AI_Agent agent)
 {
     myAgent = agent;
 }
Exemplo n.º 22
0
 public MoveToState(AI_Agent agent)
 {
     myAgent = agent;
 }
Exemplo n.º 23
0
 /// <summary>
 /// Used to add a AI_Agent that just spawned
 /// </summary>
 /// <param name="a_newAgent">The agent that should be added</param>
 public Unit[] AddUnit(AI_Agent a_newAgent)
 {
     agents.Add(a_newAgent);
     a_newAgent.OnDeath += RemoveUnit;
     return(players);
 }
Exemplo n.º 24
0
 void Start()
 {
     npc     = GameObject.FindGameObjectWithTag("NPC");
     ai      = npc.GetComponent <AI_Agent>();
     moveNpc = npc.GetComponent <MoveNPC>();
 }
Exemplo n.º 25
0
 public AI_Scorer(CalculationCanvasType a_calculationCanvas, AI_Agent a_agent)
 {
     calculationCanvas = a_calculationCanvas;
     agent             = a_agent;
 }
Exemplo n.º 26
0
    //public T GetObjectOrDefault

    #endregion

    //public Status this[int index]
    //{
    //    get { return NodeStatus[index]; }
    //    set { NodeStatus[index] = value; }
    //}

    ///// <summary>
    ///// Returns the ID of the child
    ///// </summary>
    //public int this[int nodeIndex, int childIndex]
    //{
    //    get { return childIndex < TreeMemory[nodeIndex].Children.Count ? TreeMemory[nodeIndex].Children[childIndex] : -1; }
    //   // set { TreeMemory[childIndex].Status = value; }
    //}

    #endregion

    #region CreateAgent

    public static AI_Agent CreateAgent(BT_TreeNode Root = null)
    {
        AI_Agent agent = new AI_Agent();
        agent.LocalBlackboard = AI_Blackboard.Create();
        agent.GlobalBlackboard = AI_Blackboard.Create();
        agent.Tree = BT_Tree.CreateTree(Root);

        agent.LocalBlackboard.SetObject("Name", agent.Name);
        agent.LocalBlackboard.SetObject("DebugTree", false);
        agent.LocalBlackboard.SetObject("Depth", 0);

        return agent;
    }
 public AI_AgentParameter(string parametername, AI_Agent.BlackBoard access, GUIContent content)
 {
     Content = content;
     ParameterName = parametername;
     AgentAccesType = access;
 }
Exemplo n.º 28
0
 public static BT_TreeNode SetParameters(BT_TreeNode node, string bbParameter1, AI_Agent.BlackBoard param1, string bbParameter2, AI_Agent.BlackBoard param2)
 {
     return SetParameters(node, new AI_AgentParameter(bbParameter1, param1), new AI_AgentParameter(bbParameter2, param2));
 }