Ejemplo n.º 1
0
    void Awake()
    {
        //this determines what team they are on and then sets thier home base depending on this
        if (this.CompareTag("Blue Team"))
        {
            HomeBase = GameObject.FindGameObjectWithTag("BlueBase");
        }
        else
        {
            HomeBase = GameObject.FindGameObjectWithTag("RedBase");
        }


        ///////////////////////////////////////////
        //goal One go get Flag and Bring it back//
        Goals GoPickUpFlag = new Goals(AIGoals.CaptureFlag, 0.0f, 10.0f, 0.0f, Valuefunctions);

        //actions included within the first goal
        CaptureFlagMove = new TheAction(TheActions, "MoveEnemySide", true, true, 0.0f, true);
        CaptureFlagMove.SetGoalSatisfaction(AIGoals.CaptureFlag, 1);

        CaptureFlagAttack = new TheAction(TheActions, "Attack", false, true, 0.0f, false);
        CaptureFlagAttack.SetGoalSatisfaction(AIGoals.attack, 2);

        CaptureFlagPickUp = new TheAction(TheActions, "PickUpFlag", true, true, 0.0f, false);
        CaptureFlagPickUp.SetGoalSatisfaction(AIGoals.CaptureFlag, 3);

        CaptrueFlagMoveHome = new TheAction(TheActions, "MoveHome", true, true, 0.0f, false);
        CaptrueFlagMoveHome.SetGoalSatisfaction(AIGoals.CaptureFlag, 4);

        CaptureFlagDropFlag = new TheAction(TheActions, "DropFlag", true, true, 0.0f, false);
        CaptureFlagDropFlag.SetGoalSatisfaction(AIGoals.CaptureFlag, 5);


        //the actions sequence for the first goal
        ActionSequence Sequence = new ActionSequence();

        Sequence.AddAction(CaptureFlagMove);
        Sequence.AddAction(CaptureFlagAttack);
        Sequence.AddAction(CaptureFlagPickUp);
        Sequence.AddAction(CaptrueFlagMoveHome);
        Sequence.AddAction(CaptureFlagDropFlag);
        Sequence.SetGoalSatisfaction(AIGoals.CaptureFlag, 5);
        //////////////////////////////////////////////////////////



        /////////////////////////////////////////////////
        //goal two protect the team mate with the flag//
        Goals ProtectTeamMate = new Goals(AIGoals.ProtectFriend, 0.0f, 1.0f, 0.0f, Valuefunctions);

        // the unique actions for the second goal
        ProtectTeamMateAction = new TheAction(TheActions, "ProtectTeamMateWithFlag", true, true, 0.0f, true);
        ProtectTeamMateAction.SetGoalSatisfaction(AIGoals.ProtectFriend, 1);

        AttackEnemy = new TheAction(TheActions, "Attack", false, true, 0.0f, false);
        AttackEnemy.SetGoalSatisfaction(AIGoals.ProtectFriend, 1);

        // the action sequence for the second goal
        ActionSequence Sequence2 = new ActionSequence();

        Sequence2.AddAction(ProtectTeamMateAction);
        Sequence2.AddAction(AttackEnemy);
        Sequence2.SetGoalSatisfaction(AIGoals.ProtectFriend, 5);
        ////////////////////////////////////////////////////////


        ///////////////////////////////////////////////////////
        //goal to guard the base once you have the enemy flag//
        Goals GuardBase = new Goals(AIGoals.Guard, 0, 5, 0, Valuefunctions);

        //the actions unique included within the third goal
        GuardTheBase = new TheAction(TheActions, "Guard", true, true, 0.0f, true);
        GuardTheBase.SetGoalSatisfaction(AIGoals.Guard, 1);

        AttackEnemyAtBase = new TheAction(TheActions, "Attack", true, true, 0.0f, false);
        AttackEnemyAtBase.SetGoalSatisfaction(AIGoals.Guard, 1);


        //the action sequence for the third goal
        ActionSequence Sequence3 = new ActionSequence();

        Sequence3.AddAction(GuardTheBase);
        Sequence3.AddAction(AttackEnemyAtBase);
        Sequence3.SetGoalSatisfaction(AIGoals.Guard, 5);
        //////////////////////////////////////////////////


        //////////////////////////////////////
        //goal four to flee and find health//
        Goals FleeAndGetHealth = new Goals(AIGoals.retreat, 0, 10, 0, Valuefunctions);

        // the actions that are needed for the fourth goal
        RetreatToSaftey = new TheAction(TheActions, "Flee", false, false, 0.0f, true);
        RetreatToSaftey.SetGoalSatisfaction(AIGoals.retreat, 5);

        HealHealth = new TheAction(TheActions, "Heal", false, false, 0.0f, true);
        HealHealth.SetGoalSatisfaction(AIGoals.retreat, 5);

        ActionSequence Sequence4 = new ActionSequence();

        Sequence4.AddAction(RetreatToSaftey);
        //Sequence4.AddAction(HealHealth);
        Sequence4.SetGoalSatisfaction(AIGoals.retreat, 10);
        ///////////////////////////////////////////////////

        /////////////////////////////////////////
        //goal five to get back thier own flag//
        Goals RetriveFlag = new Goals(AIGoals.Retrive, 0, 10, 0, Valuefunctions);

        // The actions that are needed for the fifth action
        GetFlagMoveToEnemySide = new TheAction(TheActions, "MoveEnemySide", false, true, 0, true);
        GetFlagMoveToEnemySide.SetGoalSatisfaction(AIGoals.Retrive, 3);

        GetFlagRetrieveFlag = new TheAction(TheActions, "RetrieveFriendlyFlag", false, false, 0.0f, false);
        GetFlagRetrieveFlag.SetGoalSatisfaction(AIGoals.Retrive, 4);

        GetFlagDrop = new TheAction(TheActions, "DropFlag", false, true, 0, false);
        GetFlagDrop.SetGoalSatisfaction(AIGoals.Retrive, 3);

        GetFlagAttack = new TheAction(TheActions, "Attack", false, true, 0, false);
        GetFlagAttack.SetGoalSatisfaction(AIGoals.Retrive, 2);

        GetFlagMoveHome = new TheAction(TheActions, "MoveHomeWithFriendlyFlag", false, true, 0, false);
        GetFlagMoveHome.SetGoalSatisfaction(AIGoals.Retrive, 2);

        ActionSequence Sequence5 = new ActionSequence();

        Sequence5.AddAction(GetFlagMoveToEnemySide);
        Sequence5.AddAction(GetFlagRetrieveFlag);
        Sequence5.AddAction(GetFlagAttack);
        Sequence5.AddAction(GetFlagMoveHome);
        Sequence5.AddAction(GetFlagDrop);

        Sequence5.SetGoalSatisfaction(AIGoals.Retrive, 10);
        /////////////////////////////////////////////////////

        //Goal Six to pick up power Up//

        Goals GetPowerUp = new Goals(AIGoals.PowerUp, 0, 10, 0, Valuefunctions);


        PickUpPowerUp = new TheAction(TheActions, "GetPowerUp", true, true, 0, false);
        PickUpPowerUp.SetGoalSatisfaction(AIGoals.PowerUp, 2);
        /////////////////////////////////////////////////////

        ActionSequence Sequence6 = new ActionSequence();

        Sequence6.AddAction(PickUpPowerUp);
        Sequence6.SetGoalSatisfaction(AIGoals.PowerUp, 10);


        //adding the goals and actions to the AI
        TheAI.AddGoal(GoPickUpFlag);
        TheAI.AddAction(Sequence);
        TheAI.AddGoal(ProtectTeamMate);
        TheAI.AddAction(Sequence2);
        TheAI.AddGoal(GuardBase);
        TheAI.AddAction(Sequence3);
        TheAI.AddGoal(FleeAndGetHealth);
        TheAI.AddAction(Sequence4);
        TheAI.AddGoal(RetriveFlag);
        TheAI.AddAction(Sequence5);
        TheAI.AddGoal(GetPowerUp);
        TheAI.AddAction(Sequence6);
    }