Exemple #1
0
    public Creature modify(int ID)
    {
        // create a new instance of creature to be modified
        Creature modifiedCreature = CreatureHolder.CreateCreature(Vector3.zero, ID, new List <Node>(0), new List <Muscle>(0), 0, true, creatureTimer + randGet() * 16 * mutability, Mathf.Min(mutability * Random.Range(0.8f, 1.25f), 2));

        // add all the nodes of the current creature to the new creature
        for (int i = 0; i < nodeCount; i++)
        {
            Node temp = nodes[i];
            Node node = modifiedCreature.CreateNode(Vector2.zero, gameObject.transform, temp.prevX, temp.prevY, temp.M, temp.friction, temp.value, temp.operation, temp.axon1, temp.axon2);
            node.modify(mutability, nodeCount, mutationChance, operationCount);
        }

        // add all the muscles of the current creature to the new creatures
        for (int i = 0; i < muscles.Count; i++)
        {
            Muscle temp   = muscles[i];
            Muscle muscle = modifiedCreature.CreateMuscle(gameObject.transform, temp.axon, temp.p1, temp.p2, temp.Length, temp.rigidity);
            muscle.modify(nodeCount, mutability, mutationChance, nodes);
        }

        // if a random float between 0 and 1 is larger then the mutationChance of the creature, or if the creature has 2 or less nodes
        if (Random.Range(0f, 1f) < mutationChance || nodeCount <= 2)
        {
            modifiedCreature.addRandNode(gameObject.transform, 0, 0, 0.4f, Random.Range(0f, 1f), Random.Range(0f, 1f), (int)Mathf.Floor(Random.Range(0f, operationCount)),
                                         Random.Range(0, nodeCount), Random.Range(0, nodeCount)); // add a new node
        }
        // if a random float between 0 and 1 is larger then the mutationChance of the creature
        if (Random.Range(0f, 1f) < mutationChance)
        {
            modifiedCreature.addRandMuscle(gameObject.transform, -1, -1); // add a new muscle connecting two of the nodes
        }
        // if a random float between 0 and 1 is larger then the mutationChance of the creature
        if (Random.Range(0f, 1f) < mutationChance && modifiedCreature.nodeCount >= 4)
        {
            modifiedCreature.removeRandNode(); // remove a random node
        }
        // if a random float between 0 and 1 is larger then the mutationChance of the creature
        if (Random.Range(0f, 1f) < mutationChance && modifiedCreature.muscleCount >= 2)
        {
            modifiedCreature.removeRandMuscle(); // remove a random muscle
        }
        modifiedCreature.checkForOverlap();
        modifiedCreature.checkForLoneNodes();
        modifiedCreature.checkForBadAxons();

        return(modifiedCreature);
    }