Esempio n. 1
0
    public IEnumerator EvadeHideState()                                                                                                          //used to evade
    {
        Debug.Log("Evade/Hide: ENTER");                                                                                                          //log entering the state

        preyState       = PreyStates.EvadeHide;                                                                                                  //set the state
        flock.behaviour = EvadeHideBehaviour;                                                                                                    //set the behaviour object

        while (preyState == PreyStates.EvadeHide)                                                                                                //while we are in this state
        {
            foreach (FlockAgent agent in flock.agents)                                                                                           //for each agent in our flock
            {
                List <Transform> filteredContext = (contextFilter == null) ? flock.areaContext : contextFilter.Filter(agent, flock.areaContext); //make a list of agents neaby from other flocks

                if (filteredContext.Count <= 0)                                                                                                  //if there arent agents on the list (aka no enemies nearby)
                {
                    preyState = PreyStates.Wander;                                                                                               //change to wander state
                    ChangeStateTo(PreyStates.Wander.ToString());                                                                                 //change states
                    //Debug.Log(filteredContext.Count);
                    yield return(null);                                                                                                          //return out of the loop
                }
            }

            yield return(null); //return out of the loop
        }

        Debug.Log("Evade: EXIT"); //log exiting the state
    }
Esempio n. 2
0
    // Start is called before the first frame update

    private void Awake()
    {
        this.prey = new Prey();
        curState  = PreyStates.FindFood;
        hasFood   = false;
        this.HP   = 2;
    }
Esempio n. 3
0
    ////This should acknowledge the food has been found so the Hivemind works and all the other prey are notified
    //public void EmitFoodLocation()
    //{

    //}

    public void GoToFoodSignal(Transform location)
    {
        if (Vector3.Distance(location.position, this.transform.position) <= distanceToHearSignal)
        {
            this.curState = PreyStates.FoundFood;
        }
    }
Esempio n. 4
0
    public void SetUpPrey()
    {
        groundP = GroundPredator.GetComponent <GroundPred>();

        this.prey.Attach(groundP.GroundPredSub);
        hasFood       = false;
        this.curState = this.prey.State;
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        //timeTrail += Time.deltaTime;
        switch (curState)
        {
        //The Prey should be searching for food, if it has seen food it should then switch to FoundFood State
        case PreyStates.FindFood:
            Wandering();
            if (this.GetComponentInChildren <Sight>().DetectAspect() && this.FoodLocation.GetComponent <Food>().IsHarvestable)
            {
                this.CurState = PreyStates.FoundFood;
                //Debug.Log("found food");
            }
            else
            {
                this.CurState = PreyStates.FindFood;
            }
            break;

        case PreyStates.FollowTrail:
            GoToFoodSignal(this.prey.FoodMessage);
            break;

        //This means when the prey ahs found food it will
        case PreyStates.FoundFood:
            FoundFood();
            break;

        case PreyStates.ReturnHome:
            ReturnHome();
            break;

        case PreyStates.Flee:
            FleeFromPredator();
            break;

        case PreyStates.Dead:
            this.gameObject.SetActive(false);
            this.gameObject.GetComponent <BoxCollider>().enabled = false;
            break;
        }
        this.transform.position = new Vector3(this.transform.position.x, 2, this.transform.position.z);
        if (this.HP <= 0)
        {
            this.curState = PreyStates.Dead;
        }

        //if (this.CurState != this.prey.State && this.CurState == PreyStates.FindFood && this.prey.State == PreyStates.FollowTrail)
        //{
        //    this.CurState = this.prey.State;
        //}
    }
Esempio n. 6
0
    public void FoundFood()
    {
        if (Vector3.Distance(FoodLocation.transform.position, transform.position) <= 4.5f)
        {
            this.curState = PreyStates.ReturnHome;
        }

        Quaternion tarRot = Quaternion.LookRotation(FoodLocation.transform.position - this.transform.position);

        tarRot.eulerAngles = new Vector3(0, tarRot.eulerAngles.y, 0);
        transform.rotation = Quaternion.Slerp(transform.rotation, tarRot, 10.0f * Time.deltaTime);
        transform.Translate(new Vector3(0, 0, 40.0f * Time.deltaTime));
    }
Esempio n. 7
0
 public void ObserverUpdate(object sender, object message)
 {
     if (sender is GroundPredSubject)
     {
         if (message is string)
         {
             switch (message.ToString())
             {
             case "Attack":
                 this.State = PreyStates.Flee;
                 break;
             }
         }
     }
 }
Esempio n. 8
0
    public void ReturnHome()
    {
        if (Vector3.Distance(HomeLocation.position, transform.position) <= 4.5f)
        {
            if (FoodLocation.gameObject.GetComponent <Food>().IsHarvestable)
            {
                this.curState = PreyStates.FoundFood;
            }
            else
            {
                this.curState = PreyStates.FindFood;
            }
            this.hasFood = false;
        }
        Quaternion tarRot = Quaternion.LookRotation(HomeLocation.position - this.transform.position);

        tarRot.eulerAngles = new Vector3(0, tarRot.eulerAngles.y, 0);
        transform.rotation = Quaternion.Slerp(transform.rotation, tarRot, 10.0f * Time.deltaTime);
        transform.Translate(new Vector3(0, 0, 40.0f * Time.deltaTime));
    }
Esempio n. 9
0
 private void OnTriggerEnter(Collider other)
 {
     if (this.curState == PreyStates.FoundFood)
     {
         if (other.gameObject.tag == "Food")
         {
             if (other.gameObject.GetComponent <Food>().IsHarvestable&& this.hasFood == false)
             {
                 other.gameObject.GetComponent <Food>().FoodTaken();
                 this.hasFood = true;
                 //Debug.Log("has food");
             }
             else
             {
                 this.hasFood  = false;
                 this.CurState = PreyStates.FindFood;
             }
         }
     }
 }
Esempio n. 10
0
 public void FleeFromPredator()
 {
     this.CurState = PreyStates.FindFood;
 }
Esempio n. 11
0
 public Prey()
 {
     this.state = PreyStates.FindFood;
 }
Esempio n. 12
0
 public Prey(GroundPredSubject sub)
 {
     this.state = PreyStates.FindFood;
     sub.Attach(this);
 }