Ejemplo n.º 1
0
    //typically a method of SimDim.LivingCreature. but not BHV-friendly
    //public void kill( SimDim.Matter _Victim)
    public void kill(SimDim.LivingCreature _Victim)
    {
        //Debug.Log (this.gameObject.name+" killed "+_Victim.root.name +"===============================================");
        Debug.Log(this.gameObject.name + " killed " + _Victim.root.name);
        _Victim.belonging.Population.Remove(_Victim as Matter);


        foreach (GameObject shrapnel in _Victim.Body)
        {               //Spread Food
            if (Random.value > 0.7f)
            {
                SimDim.Food toto = new SimDim.Food(_Victim.belonging);
                toto.root.transform.position = shrapnel.transform.position;

                //spreading  (TODO: paybe animate that...)  //and remove magic numbers!
                float OffsetX = Random.Range(-0.04f * _Victim.Age, 0.04f * _Victim.Age);
                float OffsetZ = Random.Range(-0.04f * _Victim.Age, 0.04f * _Victim.Age);
                toto.root.transform.Translate(OffsetX, 0.0f, OffsetZ, Space.World);

                _Victim.belonging.Population.Add(toto);
            }
        }
//		SimDim.Food toto = new SimDim.Food(_Victim.belonging);
//		toto.root.transform.position = this.gameObject.transform.position;
//		_Victim.belonging.Population.Add(toto);

        _Victim.root.SetActive(false);
    }
Ejemplo n.º 2
0
    //Todo a unique loop to return if I see food or danger or social.

    //Each update, I refresh my vision:
    public void Update()
    {
        //this.currentVision = new List<Matter>(); //empty list for solving big issue, no time to fix (sight is not updated when food is eaten)
        //this.currentVision.Clear();

        Vector3 position    = this.transform.position;      //The position of the creature
        Vector3 EyePosition = TheEye.transform.position;


        //Debug.Log ("this.Belonging.Population"+this.Belonging.Population.Count);
        foreach (Matter currentItem in this.Belonging.Population)
        {
            //Debug.Log (this.Belonging.Population.IndexOf(currentItem) +" = "+ currentItem.root.name);

            //remove itself from loop !
            if (currentItem.root != this.gameObject)
            {
                float d = Vector3.Distance(currentItem.root.transform.position, this.gameObject.transform.position);

                //Collision detection (TODO: not the right place)
                if (currentItem.GetType().ToString() != "SimDim.Food")
                {
                    SimDim.LivingCreature currentSeenGuy = currentItem as SimDim.LivingCreature;

                    //behaviour from Social, but call here to optimize loop:
                    if (d < 0.1f * currentSeenGuy.Age)
                    {                                                                                //Contact Management.
                        BHV_Social comp = this.gameObject.GetComponent <BHV_Social>() as BHV_Social; //mayve, LATER, we can manage food like any kills.
                        comp.kill(currentSeenGuy);
                        return;
                    }

                    /*
                     * if(d<10.0f)
                     * {	//Social Management.
                     *
                     *      BHV_See comp = currentSeenGuy.root.GetComponent<BHV_See>() as BHV_See;
                     *      foreach(SimDim.Matter cur in this.currentVision)
                     *      {
                     *              if(cur.root == currentItem.root)
                     *              {	//I see a guy who is very near (maybe too much?)
                     *
                     *                      //BHV_Social comp2 = this.gameObject.GetComponent<BHV_Social>() as BHV_Social;
                     *                      //comp2.salute(currentItem);
                     *                      //return ;
                     *              }
                     *      }
                     *
                     * }
                     */
                }



                if (d < SightRange)
                {                  // here we are at range
                    //TODO: test if we are at angle
                    Vector3 vSightDirection = EyePosition - position;
                    Vector3 vObjDirection   = currentItem.root.transform.position - EyePosition;


                    float DotProduct = Vector3.Dot(vSightDirection, vObjDirection);

                    //Debug.Log ( currentItem.root.name +" ==> "+ DotProduct );
                    //Debug.Log (currentItem.GetType());

                    if (DotProduct > 0)
                    {                    //We are in front of the creature
                        if (!this.currentVision.Contains(currentItem))
                        {
                            this.currentVision.Add(currentItem);

                            //FOOD MANAGEMENT
                            if (currentItem.GetType().ToString() == "SimDim.Food")                             //There must be a better way but... NO NET
                            {
                                //Debug.Log (this.gameObject.name+" see food :"+currentItem.root.name);
                                this.FoodList.Add(currentItem as Food);
                            }
                            else
                            {
                                //SOCIAL MANAGEMENT
                                //Debug.Log (currentItem.GetType().ToString());


                                //Debug.Log (this.gameObject.name+" see :"+currentItem.root.name);
                            }
                        }
                    }
                    else
                    {
                        if (this.currentVision.Contains(currentItem))
                        {
                            this.currentVision.Remove(currentItem);
                        }
                    }
                }
                else
                {
                    if (this.currentVision.Contains(currentItem))
                    {
                        this.currentVision.Remove(currentItem);
                    }
                }
            }
        }
    }