Exemplo n.º 1
0
    private void FlagBroughtHome()
    {
        Debug.Log("Team " + Team + " wins, for bringing the flag back home first!");

        RemoveFlagChaserRole();

        // let's make sure there are no more goal seekers
        switch (Team)
        {
        case Teams.Red:
            RedFlagSeekerActive = true;
            break;

        case Teams.Blue:
            BlueFlagSeekerActive = true;
            break;

        case Teams.Green:
            GreenFlagSeekerActive = true;
            break;

        case Teams.Neutral:
            break;
        }

        CurrentAction = CTFActions.Idle;
        DetermineActionUpdate();
    }
Exemplo n.º 2
0
    public void Rescue()
    {
        IsCarryingFlag = false;
        IsFrozenInJail = false;

        CurrentAction = CTFActions.Idle;
    }
Exemplo n.º 3
0
    private void GetFlagUpdate()
    {
        IsFlagChaser = true;

        Body.GetComponent <Renderer>().material = FlagRoleMaterial;

        if (ClosestEnemyInRange != null && CurrentBase == ClosestEnemyInRange.Team)
        {
            if (!IsCarryingFlag)
            {
                RemoveFlagChaserRole();
                CurrentAction = CTFActions.EvadeEnemy;
                DetermineActionUpdate();
                return;
            }
            else
            {
                CurrentAction   = CTFActions.EvadeEnemy;
                Target          = ClosestEnemyInRange.gameObject;
                TargetRigidbody = Target.GetComponent <Rigidbody>();
                DetermineActionUpdate();
                return;
            }
        }

        if (IsCarryingFlag)
        {                                          // Head on home! To Victory!
            TargetFlag.transform.position = transform.position;
            Target          = HomeBase.gameObject; // replace with closest point, needs architectural update :(
            TargetRigidbody = Target.GetComponent <Rigidbody>();

            float distanceFromGoal = (new Vector3(HomeBase.transform.position.x, transform.position.y, HomeBase.transform.position.z) - transform.position)
                                     .magnitude;
            if (distanceFromGoal <= 1f)
            {
                FlagBroughtHome();
            }
        }
        else
        { // Find the flag
            GameObject[] flags = GameObject.FindGameObjectsWithTag("flag");
            flags           = flags.Where(flag => flag.GetComponent <Flag>().Team != Team).ToArray();
            TargetFlag      = flags[0];
            Target          = TargetFlag;
            TargetRigidbody = Target.GetComponent <Rigidbody>();

            Vector3 distanceFromFlag = transform.position - Target.transform.position;
            distanceFromFlag.y = 0;

            if (distanceFromFlag.magnitude < SteppingRadius)
            {
                IsCarryingFlag = true;
            }
        }

        SteeringBehaviourSelection    = SteeringBehaviourSelection.SteeringArrive;
        KinematicBehaviourSelection   = KinematicBehaviourSelection.KinematicSeek;
        OrientationBehaviourSelection = OrientationBehaviourSelection.SteeringFace;
        HumanHeuristicMode            = HumanHeuristicMode.ReachingATarget;
    }
Exemplo n.º 4
0
    private void PersueEnemyUpdate()
    {
        // if no more enemy to persue, or the enemy is out of our base
        if (ClosestEnemyInRange == null || ClosestEnemyInRange.CurrentBase != Team)
        {
            CurrentAction = CTFActions.Idle;
            DetermineActionUpdate();
            return;
        }

        Target = ClosestEnemyInRange;

        SteeringBehaviourSelection    = SteeringBehaviourSelection.SteeringPersue;
        KinematicBehaviourSelection   = KinematicBehaviourSelection.KinematicSeek; // TODO replace with Persue
        OrientationBehaviourSelection = OrientationBehaviourSelection.SteeringFace;
        HumanHeuristicMode            = HumanHeuristicMode.ReachingATarget;
    }
Exemplo n.º 5
0
    private void RescueTeamateUpdate()
    {
        if ((ClosestEnemyInRange != null && CurrentBase == ClosestEnemyInRange.Team) ||
            ClosestFrozenAllyInRange == null)
        {
            CurrentAction = CTFActions.Idle;
            DetermineActionUpdate();
            return;
        }

        Target = ClosestFrozenAllyInRange;

        SteeringBehaviourSelection    = SteeringBehaviourSelection.SteeringArrive;
        KinematicBehaviourSelection   = KinematicBehaviourSelection.KinematicArrive;
        OrientationBehaviourSelection = OrientationBehaviourSelection.SteeringFace;
        HumanHeuristicMode            = HumanHeuristicMode.ReachingATarget;
    }
Exemplo n.º 6
0
    private void PersueEnemyUpdate()
    {
        // if no more enemy to persue, or the enemy is out of our base
        if (ClosestEnemyInRange == null || ClosestEnemyInRange.CurrentBase != Team)
        {
            CurrentAction = CTFActions.Idle;
            DetermineActionUpdate();
            return;
        }

        Target          = ClosestEnemyInRange.gameObject;
        TargetRigidbody = Target.GetComponent <Rigidbody>();

        SteeringBehaviourSelection    = SteeringBehaviourSelection.SteeringPersue;
        KinematicBehaviourSelection   = KinematicBehaviourSelection.KinematicSeek;
        OrientationBehaviourSelection = OrientationBehaviourSelection.SteeringFace;
        HumanHeuristicMode            = HumanHeuristicMode.ReachingATarget;
    }
Exemplo n.º 7
0
    private void HandleCollision(Collider other)
    {
        switch (CurrentAction)
        {
        case CTFActions.RescueTeamate:
            CTFCharacterController ally = other.GetComponent <CTFCharacterController>();
            if (ally == null || ally.Team != Team || ally.CurrentAction != CTFActions.Frozen)
            {
                return;
            }
            ally.Rescue();
            CurrentAction = CTFActions.Idle;
            break;

        case CTFActions.PersueEnemy:
            if (CurrentBase != Team)
            {
                return;
            }
            CTFCharacterController enemy = other.GetComponent <CTFCharacterController>();
            if (enemy == null || enemy.Team == Team || enemy.CurrentAction == CTFActions.Frozen)
            {
                return;
            }
            enemy.Jail();
            CurrentAction = CTFActions.Idle;
            break;

        default:
            break;
        }

        // even if we aren't rescuing, let's unfreeze any allies we cross
        CTFCharacterController frozenAlly = other.GetComponent <CTFCharacterController>();

        if (frozenAlly != null &&
            frozenAlly.Team == Team &&
            frozenAlly.CurrentAction == CTFActions.Frozen &&
            frozenAlly != this)
        {
            frozenAlly.Rescue();
        }
    }
Exemplo n.º 8
0
    private void EvadeEnemyUpdate()
    {
        if (ClosestEnemyInRange == null || CurrentBase != ClosestEnemyInRange.Team)
        {
            CurrentAction = CTFActions.Idle;
            DetermineActionUpdate();
            return;
        }

        if (IsFlagChaser)
        {
            TargetFlag.transform.position = transform.position;
        }

        Target = ClosestEnemyInRange;

        SteeringBehaviourSelection    = SteeringBehaviourSelection.SteeringEvade;
        KinematicBehaviourSelection   = KinematicBehaviourSelection.KinematicFlee;
        OrientationBehaviourSelection = OrientationBehaviourSelection.SteeringFaceAway;
        HumanHeuristicMode            = HumanHeuristicMode.StayingAwayFromATarget;
    }
Exemplo n.º 9
0
    private void EvadeEnemyUpdate()
    {
        if (ClosestEnemyInRange == null || CurrentBase != ClosestEnemyInRange.Team)
        {
            CurrentAction = CTFActions.Idle;
            DetermineActionUpdate();
            return;
        }

        if (IsFlagChaser)
        {
            TargetFlag.transform.position = transform.position;
        }

        Target          = ClosestEnemyInRange.gameObject;
        TargetRigidbody = Target.GetComponent <Rigidbody>();

        SteeringBehaviourSelection    = SteeringBehaviourSelection.SteeringEvade;
        KinematicBehaviourSelection   = KinematicBehaviourSelection.KinematicFlee;
        OrientationBehaviourSelection = OrientationBehaviourSelection.SteeringLookWhereYoureGoing;
        HumanHeuristicMode            = HumanHeuristicMode.StayingAwayFromATarget;
    }
Exemplo n.º 10
0
    public void Jail()
    {
        if (IsCarryingFlag)
        {
            RemoveFlagChaserRole();
            TargetFlag.transform.gameObject.GetComponent <Flag>().ResetPosition();
        }

        // If we want to send them back to Home base
        //transform.position = 5f * Vector3.forward + new Vector3(
        //    HomeBase.transform.position.x,
        //    transform.position.y,
        //    HomeBase.transform.position.z
        //);

        IsFlagChaser   = false;
        IsCarryingFlag = false;

        CurrentAction = CTFActions.Frozen;

        CurrentVelocity        = Vector3.zero;
        CurrentAngularVelocity = Vector3.zero;
    }
Exemplo n.º 11
0
    private void IdleUpdate()
    {
        if (ClosestEnemyInRange != null)
        {
            if (CurrentBase == ClosestEnemyInRange.Team)
            {
                // AVOID
                CurrentAction = CTFActions.EvadeEnemy;
                EvadeEnemyUpdate();
                return;
            }

            if (ClosestEnemyInRange.CurrentBase == Team)
            {
                // CHASE
                CurrentAction = CTFActions.PersueEnemy;
                PersueEnemyUpdate();
                return;
            }
        }

        switch (Team)
        {
        case Teams.Red:
            if (!RedFlagSeekerActive || IsFlagChaser)
            {
                CurrentAction       = CTFActions.GetFlag;
                RedFlagSeekerActive = true;
                GetFlagUpdate();
                return;
            }
            break;

        case Teams.Blue:
            if (!BlueFlagSeekerActive || IsFlagChaser)
            {
                CurrentAction        = CTFActions.GetFlag;
                BlueFlagSeekerActive = true;
                GetFlagUpdate();
                return;
            }
            break;

        case Teams.Green:
            if (!GreenFlagSeekerActive || IsFlagChaser)
            {
                CurrentAction         = CTFActions.GetFlag;
                GreenFlagSeekerActive = true;
                GetFlagUpdate();
                return;
            }
            break;

        case Teams.Neutral:
            break;
        }

        if (ClosestFrozenAllyInRange != null)
        {
            CurrentAction = CTFActions.RescueTeamate;
            RescueTeamateUpdate();
        }

        SteeringBehaviourSelection    = SteeringBehaviourSelection.SteeringWander;
        KinematicBehaviourSelection   = KinematicBehaviourSelection.KinematicWander;
        OrientationBehaviourSelection = OrientationBehaviourSelection.SteeringLookWhereYoureGoing;
        HumanHeuristicMode            = HumanHeuristicMode.None;
    }