コード例 #1
0
    public void Revise(Agent reviseur, Creature from, Creature to)
    {
        DataSpecies data = reviseur.Memory.Species.GetByKey(from.SpecieID);

        if (data == null)
        {
            return;
        }

        bool          fromIsPredateur      = false;
        GoalComposite currentCompositeGoal = from.agentCreature.IsThinking ? from.agentCreature.Thinking.ActiveGoal as GoalComposite : null;

        while (currentCompositeGoal != null)
        {
            Goal currentGoal = currentCompositeGoal.GetActiveGoal();
            if (currentGoal.GetType() == typeof(GoalHunt))
            {
                fromIsPredateur = true;
                break;
            }
            currentCompositeGoal = currentGoal as GoalComposite;
        }

        if (fromIsPredateur)
        {
            data.addCarnivorousFood(new CarnivorousFood(to.SpecieID, Time.time));
        }

        base.Revise(reviseur);
    }
コード例 #2
0
    public override void Write(Data data)
    {
        if (!(data is DataSpecies))
        {
            return;
        }
        DataSpecies dataSpecies = data as DataSpecies;

        DataSpecies sameData = species.Find(d => d.SpeciesID == dataSpecies.SpeciesID);

        if (sameData != null)
        {
            /*sameData.preyIDs = sameData.preyIDs.Union(dataSpecies.preyIDs).ToList();
             * sameData.eatFoodTypes = sameData.eatFoodTypes.Union(dataSpecies.eatFoodTypes).ToList();*/
            foreach (CarnivorousFood food in dataSpecies.CarnivorousFoods)
            {
                sameData.addCarnivorousFood(new CarnivorousFood(food));
            }
            foreach (HerbivorFood food in dataSpecies.HerbivorFoods)
            {
                sameData.addHerbivorFood(new HerbivorFood(food));
            }
        }
        else
        {
            species.Add(new DataSpecies(dataSpecies));
        }
    }
コード例 #3
0
    public void Revise(Agent reviseur, Creature from, Creature to)
    {
        DataSpecies data = reviseur.Memory.Species.GetByKey(from.SpecieID);

        if (data == null)
        {
            return;
        }

        data.addCarnivorousFood(new CarnivorousFood(to.SpecieID, Time.time));

        base.Revise(reviseur);
    }
コード例 #4
0
    /*public void Reproduce(GameObject parent1, GameObject parent2)
     * {
     *  Assert.IsNotNull(parent1);
     *  Assert.IsNotNull(parent2);
     *  GetCreature(parent1.transform.parent, (parent1.transform.position + parent2.transform.position) / 2f + new Vector3(0, 1f, 0),
     *      Quaternion.Slerp(parent1.transform.rotation, parent2.transform.rotation, 0.5f),
     *      spawnedCreatures[parent1].values.attackPower, spawnedCreatures[parent1].values.nutritionnal,
     *      spawnedCreatures[parent1].values.maxLifeNumber, spawnedCreatures[parent1].values.SpecieID,
     *      spawnedCreatures[parent1].values.Traits, null);
     *  //ARDUINO ISLAND
     *  parent1.GetComponent<Creature>();
     *  //
     * }*/

    /*public Creature Reproduce(Creature parent1, Creature parent2)
     * {
     *  Assert.IsNotNull(parent1);
     *  Assert.IsNotNull(parent2);
     *
     *  // TODO
     *  // faudrais merge les listes d'alimentation des deux parent en vrai, là je prend juste le parent 1 pour implémenter le changement rapidement
     *  IReadOnlyCollection<CarnivorousFood> carnivorousFoodsParent1 = parent1.agentCreature.Memory.Species.GetByKey(parent1.SpecieID).CarnivorousFoods;
     *  IReadOnlyCollection<HerbivorFood> herbivorFoodsParent1 = parent1.agentCreature.Memory.Species.GetByKey(parent1.SpecieID).HerbivorFoods;
     *
     *  List<int> carnivorousFoods = new List<int>(carnivorousFoodsParent1.Select(food => food.preyID));
     *  List<FoodType> herbivorFoods = new List<FoodType>(herbivorFoodsParent1.Select(food => food.foodType));
     *
     *  Creature creature = GetCreature((parent1.transform.position + parent2.transform.position) / 2f + new Vector3(0, 1f, 0),
     *      Quaternion.Slerp(parent1.transform.rotation, parent2.transform.rotation, 0.5f),
     *      parent1.SpecieID,
     *      parent1.Traits, null,
     *      carnivorousFoods, herbivorFoods);
     *
     *  creature.agentCreature.Memory.MergeFrom(parent1.agentCreature, MemoryType.Species);
     *  creature.agentCreature.Memory.MergeFrom(parent2.agentCreature, MemoryType.Species);
     *
     *  return creature;
     * }*/

    /*public GameObject[] AllSpawnedGameObjects
     * {
     *  get
     *  {
     *      return spawnedCreatures.Keys.ToArray();
     *  }
     * }*/

    /*public Creature[] AllSpawnedCreatures
     * {
     *  get
     *  {
     *      Creature[] returned = new Creature[spawnedCreatures.Count];
     *      int i = -1;
     *      foreach (CreatureReferences value in spawnedCreatures.Values)
     *      {
     ++i;
     *          returned[i] = value.values;
     *      }
     *
     *      return returned;
     *  }
     * }*/
    //private Dictionary<GameObject, CreatureReferences> spawnedCreatures;

    /*public Creature GetCreature(Transform newParent, Vector3 worldPosition, Quaternion rotation, int attackPower, int nutritionnal, int maxLifeNumber, int SpecieID, CreatureTraits newTrait, CreatureGauges newGauge)
     * {
     *  CreatureReferences refCreat = new CreatureReferences();
     *  Creature newCreature = Instantiate(CreaturePrefab, worldPosition, rotation);
     *
     *  if(newParent != null)
     *      newCreature.transform.SetParent(newParent);
     *  newCreature.transform.position = worldPosition;
     *  newCreature.transform.rotation = rotation;
     *  newCreature.nutritionnal = nutritionnal;
     *  newCreature.attackPower = attackPower;
     *  newCreature.maxLifeNumber = maxLifeNumber;
     *  newCreature.SpecieID = SpecieID;
     *
     *  if(newTrait != null)
     *      newCreature.Traits = new CreatureTraits(newTrait);
     *  if(newGauge != null)
     *      newCreature.Gauges = new CreatureGauges(newGauge);
     *
     *  newCreature.gameObject.SetActive(true);
     *
     *  configGauges.InitializeGauges(newCreature, true, false, false);
     *
     *  refCreat.go = newCreature.gameObject;
     *  refCreat.values = newCreature;
     *  refCreat.listenerEvent = (x) => updateGaugesOnTraitModified(x, refCreat.values);
     *  refCreat.values.Traits.UpdatedTrait += refCreat.listenerEvent;
     *  spawnedCreatures[newCreature] = refCreat;
     *  refCreat.values.ColorSwap.Swap(CreatureTraits.GetColor(refCreat.values.Traits));
     *  //Metrics.NotifyCreatureCreated(refCreat.values);
     *  return newCreature;
     * }*/

    public Creature GetCreature(Vector3 worldPosition, Quaternion rotation, int SpecieID,
                                CreatureTraits newTrait, CreatureGauges newGauge,
                                List <int> carnivorousFoods, List <FoodType> herbivorFoods,
                                List <ParticularityType> particularities, Color color)
    {
        Creature newCreature = Instantiate(CreaturePrefab, worldPosition, rotation);

        //newCreature.attackPower = attackPower;
        //newCreature.maxLifeNumber = maxLifeNumber;
        newCreature.SpecieID = SpecieID;

        if (newTrait != null)
        {
            newCreature.Traits = new CreatureTraits(newTrait);
        }
        if (newGauge != null)
        {
            newCreature.Gauges = new CreatureGauges(newGauge);
        }

        foreach (ParticularityType particularityType in particularities)
        {
            newCreature.DNADistortion.AddParticularity(ParticularitiesManager.Instance.CreateParticularity(newCreature, particularityType));
        }

        newCreature.agentCreature.Init();

        DataSpecies data = newCreature.agentCreature.Memory.Species.GetByKey(SpecieID);

        if (newTrait.Carnivorous > 0.5f)
        {
            foreach (int food in carnivorousFoods)
            {
                if (food == SpecieID)
                {
                    continue;
                }
                data.addCarnivorousFood(new CarnivorousFood(food, Time.time));
            }
        }
        else
        {
            foreach (FoodType food in herbivorFoods)
            {
                data.addHerbivorFood(new HerbivorFood(food, Time.time));
            }
        }

        Nest nest = nests != null?nests.FirstOrDefault(n => n.SpecieID == SpecieID) : null;

        if (nest)
        {
            newCreature.agentCreature.Memory.Nests.Write(new DataNest(nest));
        }

        newCreature.gameObject.SetActive(true);

        configGauges.InitializeGauges(newCreature, true, false, false);

        if (customColor)
        {
            newCreature.ColorSwap.Swap(color);
        }
        else
        {
            newCreature.ColorSwap.Swap(CreatureTraits.GetColor(newCreature.Traits));
        }

        aliveCreatures.Add(newCreature);
        //ARDUINO ISLAND
        if (CreatureCountTable != null)
        {
            ++CreatureCountTable[newCreature.SpecieID];
        }

        // Jirachi
        creaturePopulationChangedEvent?.Invoke();

        // Lucas
        CreatureBirth?.Invoke();
        newCreature.CreatureDoing.CreatureEatCreature += CreatureEatCreature;
        newCreature.CreatureDoing.CreatureEatFood     += CreatureEatFood;

        /*Debug.Log("--------------CreatureList-------------");
         * foreach (int specie in CreatureCountTable)
         * {
         *  Debug.Log(specie);
         * }
         * Debug.Log("-----------");*/
        //

        //Metrics.NotifyCreatureCreated(refCreat.values);
        return(newCreature);
    }
コード例 #5
0
    private List <Creature> CreateCreaturesFromConfig(int specieID, int nb)
    {
        List <Creature> creatures = new List <Creature>();

        Specie specie       = configSpawn.Species[specieID];
        float  boundRandMin = specie.randomizer * -1f;
        float  boundRandMax = specie.randomizer;
        //TODO FORMULE POUR ATTACK POWER, NUTRITIONNAL VALUE, MAX LIFE NUMBER
        //TODO je le fais dans l'init physique de l'agent

        /*int attackPow = (int) specie.specieTraits.Strength * 15 + 5;
         * int nuttritionnalValue = (int) specie.specieTraits.Constitution * 100 + 50;*/
        //int maxLifeNumber = 50;
        CreatureTraits newCreatureTrait = new CreatureTraits(specie.specieTraits);

        if (specie.randomizeOneTraitOnly)
        {
            float traitValue = specie.specieTraits.Get(specie.randomizedTraitOnly).Value;
            newCreatureTrait.Get(specie.randomizedTraitOnly).AddValueClamped(UnityEngine.Random.Range(
                                                                                 (traitValue + boundRandMin) < 0f ? 0f : boundRandMin,
                                                                                 (traitValue + boundRandMax) > 1f ? 1f : boundRandMax
                                                                                 )
                                                                             );
        }
        else
        {
            foreach (CREATURE_TRAITS traits in (CREATURE_TRAITS[])System.Enum.GetValues(typeof(CREATURE_TRAITS)))
            {
                float traitValue = specie.specieTraits.Get(traits).Value;
                newCreatureTrait.Get(traits).AddValueClamped(UnityEngine.Random.Range(
                                                                 (traitValue + boundRandMin) < 0f ? 0f : boundRandMin,
                                                                 (traitValue + boundRandMax) > 1f ? 1f : boundRandMax
                                                                 )
                                                             );
            }
        }
        for (int i = 0; i < nb; ++i)
        {
            Creature spawnedCreature = GetCreature(Vector3.zero, Quaternion.identity,
                                                   specieID, newCreatureTrait, null, specie.CarnivorousFoods, specie.HerbivorFoods,
                                                   specie.particularities, specie.defaultColor);
            spawnedCreature.gameObject.SetActive(false);

            spawnedCreature.Age = UnityEngine.Random.Range(0, 0.5f);

            for (int k = 0; k < configSpawn.Species.Length; ++k)
            {
                Specie      specieInfo = configSpawn.Species[k];
                DataSpecies data       = new DataSpecies(k);
                foreach (int food in specieInfo.CarnivorousFoods)
                {
                    data.addCarnivorousFood(new CarnivorousFood(food, Time.time));
                }
                foreach (FoodType food in specieInfo.HerbivorFoods)
                {
                    data.addHerbivorFood(new HerbivorFood(food, Time.time));
                }
                spawnedCreature.agentCreature.Memory.Species.Write(data);
            }

            creatures.Add(spawnedCreature);
        }

        return(creatures);
    }