Esempio n. 1
0
    // setup our creature, define colour, scale, limb count (and segments count), etc.
    private void SetupCreatures()
    {
        // create actorA new chromosome stgructure for our new creature
        _chromosomeComposition = new ChromosomeComposition();

        // random colours (unity colours seem to be defined as actorA value between 0 and 1
        var col = new Color(Random.Range(0.0F, 1.0F),
                            Random.Range(0.0F, 1.0F),
                            Random.Range(0.0F, 1.0F)
                            );

        // set limb and root colour in our chromosome to our random colours
        _chromosomeComposition.SetColour(col.r, col.g, col.b);
        _chromosomeComposition.SetLimbColour(col.r, col.g, col.b);

        // define hunger threshold as the hunger_threshold value from the settings file
        _chromosomeComposition.HungerPoint = _settingsReader.CreatureHungerThreshold;

        // random root scale
        var rootScale = new Vector3(Random.Range(_minimumRootScale.x, _maximumRootScale.x),
                                    Random.Range(_minimumRootScale.y, _maximumRootScale.y),
                                    Random.Range(_minimumRootScale.z, _maximumRootScale.z)
                                    );

        // set root scale in chromosome to our random Vector 3
        _chromosomeComposition.SetRootScale(rootScale);

        // random initial limbs
        var bs = Random.Range(1, _branchLimit + 1);     // random branch count

        _chromosomeComposition.SetNumberOfBranches(bs); // Set the number of branches in our chromosome
        var branches = new ArrayList();

        for (var j = 0; j < bs; j++)
        {
            var limbs = new ArrayList();

            var recurrences = Random.Range(0, _recurrenceLimit);    // limb recurrence (i.e. how many segments)
            _chromosomeComposition.NumRecurrences[j] = recurrences; // set limb segment (recurrence) in our chromosome

            // iterate through our segments
            for (var k = 0; k <= recurrences; k++)
            {
                // creat erandom scale for each segment
                var scale = new Vector3(Random.Range(_minimumLimbScale.x, _maximumLimbScale.x),
                                        Random.Range(_minimumLimbScale.y, _maximumLimbScale.y),
                                        Random.Range(_minimumLimbScale.z, _maximumLimbScale.z)
                                        );

                var position = Utility.RandomPointInsideCube(rootScale);

                var limb = new ArrayList();
                limb.Add(position);
                limb.Add(scale);
                limbs.Add(limb);
            }

            branches.Add(limbs);
        }

        _chromosomeComposition.SetFequency(Random.Range(3, 20));
        _chromosomeComposition.SetAmplitude(Random.Range(3, 6));
        _chromosomeComposition.SetPhase(Random.Range(0, 360));
        _chromosomeComposition.SetBranches(branches);

        var pos = Utility.RandomVector3(-_wideSpread, _wideSpreadY, _wideSpread);

        _environment.SpawnerOrganiser.Spawn(
            pos,
            Utility.RandomVector3(),
            _creatureInitEnergy,
            _chromosomeComposition);
    }