Beispiel #1
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);
    }