示例#1
0
    // a function that allows the enemy to move towards the powerup if they see it and if they are within range they will be able to use the power up
    public bool FindPowerUp(Sensing sense, AgentData data, AgentActions actions, bool PowerUpZone)
    {
        List <GameObject> objects = sense.GetCollectablesInView();

        for (int i = 0; i < objects.Count; i++)
        {
            if (objects[i].name == "Power Up")
            {
                if (sense.IsItemInReach(objects[i]))
                {
                    objects[i].GetComponent <PowerUp>().Use(data);
                }
            }
        }

        if (!PowerUpZone)
        {
            if (data.FriendlyTeamTag == Tags.BlueTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("Powerup"));
            }
            else if (data.FriendlyTeamTag == Tags.RedTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("Powerup"));
            }
        }

        return(true);
    }
示例#2
0
    // a function that once the Ai becomes low on health they will begin to move away from the fight and is they see the health kit within view then they will use it
    public bool Fleeing(AgentActions actions, AgentData data, Sensing sensing, bool HealthZone)
    {
        List <GameObject> objects = sensing.GetCollectablesInView();

        for (int i = 0; i < objects.Count; i++)
        {
            if (objects[i].name == "Health Kit")
            {
                objects[i].GetComponent <HealthKit>().Use(data);
            }
        }

        if (!HealthZone)
        {
            if (data.FriendlyTeamTag == Tags.BlueTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("HealthKit"));
            }
            else if (data.FriendlyTeamTag == Tags.RedTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("HealthKit"));
            }
        }



        return(true);
    }
示例#3
0
    protected override IEnumerator Execute()
    {
        SetState(NodeState.RUNNING);

        if (!String.IsNullOrEmpty(blackboardEntry))
        {
            target = (GameObject)bbData.GetData(blackboardEntry);
        }

        while (GetState() == NodeState.RUNNING)
        {
            actions.MoveTo(target);

            if (Vector3.Distance(agent.transform.position, target.transform.position) > tolerance)
            {
                // Usually do attacking stuff here but it does not work
                if (attackAction != null)
                {
                    attackAction.Evaluate();
                }
            }
            else
            {
                SetState(NodeState.SUCCESS);
                Debug.Log("Reached " + target.name);
                yield break;
            }

            yield return(null);
        }

        yield return(null);
    }
示例#4
0
    // an action to determine if we have the flag if we do then we will begin to move home
    public bool MoveHomeWithOurFlag(AgentActions actions, GameObject HomeBase, bool flag)
    {
        if (flag)
        {
            actions.MoveTo(HomeBase);
        }

        return(true);
    }
示例#5
0
    // a function that allows the ai to pick up a flag if they are close enough and see it within view
    public bool PickUpFlag(Sensing sight, AgentActions actions, AgentData data)
    {
        List <GameObject> temp = new List <GameObject>();

        foreach (GameObject g in sight.GetObjectsInViewByTag("Flag"))
        {
            temp.Add(g);
        }

        for (int i = 0; i < temp.Count; ++i)
        {
            if (temp[i].name == "Red Flag") //checks to make sure the item within range is the red flag
            {
                if (data.FriendlyTeamTag == Tags.BlueTeam)
                {
                    //when the Ai is within view distance
                    actions.MoveTo(temp[i]);
                    // then it collects the item
                    actions.CollectItem(temp[i]);
                }
            }
            else if (temp[i].name == "Blue Flag") //checks to make sure the item within range is the blue flag
            {
                if (data.FriendlyTeamTag == Tags.RedTeam)
                {
                    //when the Ai is within view distance
                    actions.MoveTo(temp[i]);
                    // then it collects the item
                    actions.CollectItem(temp[i]);
                }
            }
        }

        if (data.HasEnemyFlag)
        {
            return(true);
        }



        return(false);
    }
示例#6
0
    // a function that gets the ai to try and get thier own flag back and return it to thier base
    public bool RetrieveFlag(Sensing sight, AgentActions actions, AgentData data, AI theai)
    {
        List <GameObject> Temp = new List <GameObject>();

        foreach (GameObject G in sight.GetObjectsInViewByTag("Flag"))
        {
            Temp.Add(G);
        }

        for (int i = 0; i < Temp.Count; ++i)
        {
            if (Temp[i].name == "Red Flag") //checks to make sure the item within range is the red flag
            {
                if (data.FriendlyTeamTag == "Red Team")
                {
                    //when the Ai is within view distance
                    actions.MoveTo(Temp[i]);
                    // then it collects the item
                    actions.CollectItem(Temp[i]);
                }
            }
            else if (Temp[i].name == "Blue Flag") //checks to make sure the item within range is the blue flag
            {
                if (data.FriendlyTeamTag == "Blue Team")
                {
                    //when the Ai is within view distance
                    actions.MoveTo(Temp[i]);
                    // then it collects the item
                    actions.CollectItem(Temp[i]);
                }
            }
        }

        if (data.HasFriendlyFlag)
        {
            theai.GotFriendlyFlag = true;
        }

        return(true);
    }
示例#7
0
    //a function that allowed the AI to guard their base when they had both of thier flags within the base
    public bool Gaurd(AgentActions actions, Sensing sensing, AgentData data, GameObject HomeBase, GameObject GuardSpotOne, GameObject GuardSpotTwo, int GuardSpotNumber)
    {
        //move home
        MoveHome(actions, HomeBase);

        actions.DropAllItems();

        // if there are any enemies within view then they need to attack the enemy
        Attack(sensing, actions);

        if (GuardSpotNumber == 1)
        {
            //might want to change this so that it move between two spots every time the function is called to act more like a gaurding Ai
            actions.MoveTo(GuardSpotOne);
        }
        else if (GuardSpotNumber == 2)
        {
            actions.MoveTo(GuardSpotTwo);
        }

        return(true);
    }
示例#8
0
    // a function that allows the Ai to check to see if there are enemys near by. if there are then they will begin to move to wards them and attack. slowing down when they get close enough to attack
    public void Attack(Sensing view, AgentActions action)
    {
        //first see if an enemy comes into view
        foreach (GameObject G in view.GetEnemiesInView())
        {
            action.ResumeMovement();
            action.MoveTo(G);
            action.AttackEnemy(G);
            //this.GetComponent<AgentActions>().AttackEnemy(G);
        }

        //need to resume movement when enemyes are dead
    }
示例#9
0
    //if the AI does not have the flag it finds all tema mates and finds which ever one has the glag
    public bool ProtectTeamMate(Sensing sense, AgentData data, AgentActions actions)
    {
        List <GameObject> TeamMembers;

        TeamMembers = sense.GetFriendliesInView();

        if (!data.HasEnemyFlag)
        {
            foreach (GameObject G in TeamMembers)
            {
                if (G.GetComponent <AgentData>().HasEnemyFlag)
                {
                    actions.MoveTo(G);
                }
            }
        }

        return(true);
    }
示例#10
0
    // a function that allows the aI to be able to find the health kit and if it is within reach range then the ai will use it. if not they will then begin to move up to it
    public bool FindHealthKit(AgentActions actions, Sensing sensing, AgentData data, GameObject HealthZone)
    {
        actions.MoveTo(HealthZone);
        //actions.PauseMovement();


        // need to make this so that it only uses move to random once so it can actually move

        List <GameObject> objects = sensing.GetCollectablesInView();

        for (int i = 0; i < objects.Count; i++)
        {
            if (objects[i].name == "Health Kit")
            {
                if (sensing.IsItemInReach(objects[i]))
                {
                    objects[i].GetComponent <HealthKit>().Use(data);
                }
            }
        }

        return(true);
    }
示例#11
0
    void Update()
    {
        //Checking to see of the enemy is in view, if the enemies have the power up if for what their health is
        if (agentScript.IsObjectInView(EnemyName) && agentScript.HasPowerUp == EnemyScript.HasPowerUp && agentScript.CurrentHitPoints > 25 && EnemyScript.CurrentHitPoints > 25)

        {
            //Seetting the enemy to attack of the other enemy is within view
            if (agentScript.IsInAttackRange(EnemyObject))
            {
                currentState = State.Attack;
            }
            //Setting the enemy to locate the other enemy
            else
            {
                currentState = State.MoveToEnemy;
            }
        }
        //Otherwise if the enemy is in view and the current enemy has a health less than the other enemy set the current enemy to flee
        else if (agentScript.IsObjectInView(EnemyName) && agentScript.CurrentHitPoints < 25)
        {
            currentState = State.FleeFrom;
        }
        //If the current enemies health is less than the other enemy search for the health kit, but if the enemy is in view set the current enemy to flee while the other enemy is wandering
        else if (agentScript.CurrentHitPoints < 25)
        {
            if (agentScript.IsObjectInView("Health Kit"))
            {
                currentState = State.MoveToHealthKit;
            }
            else if (agentScript.IsObjectInView(EnemyName))
            {
                currentState = State.FleeFrom;
            }
            else
            {
                currentState = State.Wander;
            }
        }

        //If the power up is in the enemies view and the power up has not been collected before then it will move the enemy towards the power up and collect it
        else if (agentScript.IsObjectInView("Power Up") && agentScript.HasPowerUp == false)
        {
            currentState = State.MoveToPowerUp;
        }
        //If all above states are not used then default back to the enemies to wander
        else
        {
            currentState = State.Wander;
        }


        //Creating a multi optional methods for behaviour
        switch (currentState)
        {
        //Sets the enemy to random wander around the map
        case State.Wander:

            this.agentScript.RandomWander();
            Debug.Log("Random");
            break;

        //Sets the enemies if in view to move towards each other
        case State.MoveToEnemy:

            EnemyObject = agentScript.GetObjectInView(EnemyName);
            Debug.Log("LocatedEnemy");
            //Bug Trying to find an object that doesn't exist occured during testing, gameobject argument is null
            agentScript.MoveTo(EnemyObject);
            Debug.Log("MoveToEnemy");


            break;

        //Sets the enemies to move to the health kit if the health kit is within view
        case State.MoveToHealthKit:

            GameObject HealthKitObject = agentScript.GetObjectInView("HealthKit");
            agentScript.MoveTo(HealthKit);
            Debug.Log("MoveToHealthKit");

            break;

        //Sets the enemies to move towards the power up if within view
        case State.MoveToPowerUp:

            GameObject PowerUpObject = agentScript.GetObjectInView("PowerUpObj");
            agentScript.MoveTo(PowerUpObj);
            Debug.Log("MoveToPowerUp");

            break;

        //Sets the enemies to attack one another
        case State.Attack:

            agentScript.AttackEnemy(EnemyObject);
            Debug.Log("AttackEnemy");

            break;

        //Sets the enemies to flee for one another
        case State.FleeFrom:

            agentScript.Flee(EnemyObject);
            Debug.Log("Flee!");

            break;
        }
    }
示例#12
0
    private void Simulation(int option)
    {
        switch (option)
        {
        case 1:
            if (this.tag == Tags.BlueTeam)
            {
                _agentActions.MoveTo(GameObject.Find(Names.RedFlag).transform.position);
            }
            else if (this.tag == Tags.RedTeam)
            {
                _agentActions.MoveTo(GameObject.Find(Names.BlueFlag).transform.position);
            }
            break;

        case 2:
            _agentActions.MoveTo(_agentData.FriendlyBase);
            break;

        case 3:
            _agentActions.MoveTo(_agentSenses.GetObjectInViewByName(Names.HealthKit));
            break;

        case 4:
            _agentActions.MoveTo(_agentSenses.GetObjectInViewByName(Names.PowerUp));
            break;

        case 5:
            _agentActions.MoveToRandomLocation();
            break;

        case 6:
            if (this.tag == Tags.BlueTeam)
            {
                _agentActions.MoveTo(_agentSenses.GetObjectInViewByName(Names.BlueFlag));
            }
            else if (this.tag == Tags.RedTeam)
            {
                _agentActions.MoveTo(_agentSenses.GetObjectInViewByName(Names.RedFlag));
            }
            break;

        default:
            break;
        }
    }
    //******************************************************************************************************************//
    //******************************************************************************************************************//

    // An action to make the agent move towards its
    // opponent if it's in sight
    public static bool MoveTowardsOpponent(AgentActions agent, GameObject enemy, GameObject powerPickup, GameObject healthKit)
    {
        agent.MoveTo(enemy);
        return(true);
    }
示例#14
0
    // a function that allows the Ai to mvoe home
    public bool MoveHome(AgentActions actions, GameObject HomeBase)
    {
        actions.MoveTo(HomeBase);

        return(true);
    }
示例#15
0
    // these will be the actions that the AI can execute
    //actions return true or false to determine wether they have finished exectuing. for example you dont want the attcaker to hit once then just stop. it needs to loop until enemy is dead



    // this action allows the AI to move to the Enemy side
    public bool MoveToEnemyside(AgentActions actions, GameObject enemybase)
    {
        actions.MoveTo(enemybase);

        return(true);
    }