//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); }
public void eatFood(SimDim.Food _targetFood) { this.Hunger = 0; // End of starvation _targetFood.beEaten(); //TODO: for blog: eat (_victim) or beEaten(_killer) Debug.Log(this.gameObject.name + " eat " + _targetFood.root.name); _targetFood.belonging.destroyMatter(_targetFood); }
public SimDim.Food lookForFood(List <SimDim.Food> _TheList) { SimDim.Food nearestFood = _TheList[0]; float minDistance = Vector3.Distance(this.transform.position, nearestFood.root.transform.position); foreach (SimDim.Food FoodCandidate in _TheList) { float currentDistance = Vector3.Distance(this.transform.position, FoodCandidate.root.transform.position); if (currentDistance < minDistance) { nearestFood = FoodCandidate; minDistance = currentDistance; } } return(nearestFood); }
void Update() { this.Locomotion.StepLength = this.Hunger.Hunger; //speed is hunger if (this.Hunger.isHungry()) { //When we are hungry we look for food. if (this.Sight.FoodList.Count == 0) { //No food at sight, let's random walk this.Locomotion.walkAtRandom(); } else { //Searching nearest Food... SimDim.Food nearestFood = this.Hunger.lookForFood(this.Sight.FoodList); //Going forward Nearest food: float distance = this.Locomotion.goTo(nearestFood.root.transform.position); //Debug.Log (this.gameObject.name+" is at "+DistanceToGoal+"m from its goal"); if (distance < this.Locomotion.StepLength) { //Start Eating //Debug.Log (this.gameObject.name+" has reached its goal"); this.Hunger.eatFood(nearestFood); //this.Sight.FoodList.Remove(nearestFood); // not accurate. Must be removed from sight of anybodies. //this.Sight.currentVision.Remove(nearestFood); //theLivingCreature.belonging.destroyMatter(nearestFood); } } } else { //not hungry //going for as BHV_Walk ? this.Locomotion.walkAtRandom(); } }