示例#1
0
        private static float SetNewBlobSize(BlobBehavior parent, GameObject gameObject)
        {
            var sizeModifier = GetDrift();

            gameObject.transform.localScale = gameObject.transform.localScale * sizeModifier;
            return(parent.size * sizeModifier);
        }
示例#2
0
        private static void RandomizeTraits(BlobBehavior mother, BlobBehavior newBlob)
        {
            SetPerceptionFields(mother, newBlob);
            newBlob.randomRotation      = MeOrMate(mother).randomRotation *GetDrift();
            newBlob.aggression          = MeOrMate(mother).aggression *GetDrift();
            newBlob.speed               = MeOrMate(mother).speed *GetDrift();
            newBlob.jogModifier         = MeOrMate(mother).jogModifier *GetDrift();
            newBlob.runModifier         = MeOrMate(mother).runModifier *GetDrift();
            newBlob.fearOfPredator      = MeOrMate(mother).fearOfPredator *GetDrift();
            newBlob.wantForPrey         = MeOrMate(mother).wantForPrey *GetDrift();
            newBlob.childGenderRatio    = MeOrMate(mother).childGenderRatio *GetDrift();
            newBlob.incubationTicks     = (int)(mother.incubationTicks * GetDrift());
            newBlob.reproductionLimit   = (int)(mother.reproductionLimit * GetDrift());
            newBlob.useMemoryPercent    = MeOrMate(mother).useMemoryPercent *GetDrift();
            newBlob.reserveEnergy       = (int)(MeOrMate(mother).reserveEnergy *GetDrift());
            newBlob.jogRotationModifier = MeOrMate(mother).jogRotationModifier *GetDrift();
            newBlob.runRotationModifier = MeOrMate(mother).runRotationModifier *GetDrift();
            //newBlob.lifespan = (int)(MeOrMate(mother).lifespan * GetDrift());

            if (newBlob.gender.Equals(GenderType.Female))
            {
                newBlob.sexualMaturity = (int)(mother.sexualMaturity * GetDrift());
            }
            else
            {
                newBlob.sexualMaturity = (int)(mother.partner.sexualMaturity * GetDrift());
            }
        }
示例#3
0
    private bool IsGoodPartner(BlobBehavior blob, bool checkingRivalry)
    {
        // girls pick boys unless it's a rivalry
        if ((gender == GenderType.Male || blob.gender == GenderType.Female) && !checkingRivalry)
        {
            return(false);
        }

        // check size
        if (blob.size / size > mateLimit || size / blob.size > mateLimit)
        {
            return(false);
        }
        if (partner == null || partner == this)
        {
            return(true);
        }

        if (partner.ticksLived == 0)
        {
            return(true);
        }
        if (blob.ticksLived < sexualMaturity)
        {
            return(false);
        }

        return(partner.energy / partner.ticksLived < blob.energy / blob.ticksLived);
    }
示例#4
0
    private void displayBlob()
    {
        BlobBehavior blob = (BlobBehavior)player;
        string       text = blob.Blobies.ToString();

        display("Blob", text, blobText);
    }
示例#5
0
    // this happens after the new blob is instantiated
    public void UpdateSurvivalStatistics(BlobBehavior blob)
    {
        BothGenderRecords(blob);

        if (recordChildren < blob.children)
        {
            recordChildren = blob.children;
        }
    }
示例#6
0
 private static BlobBehavior MeOrMate(BlobBehavior mother)
 {
     if (Random.value < 0.5f)
     {
         return(mother);
     }
     else
     {
         return(mother.partner);
     }
 }
示例#7
0
 private static GenderType RandomGender(BlobBehavior mother)
 {
     if (Random.value < mother.childGenderRatio)
     {
         return(GenderType.Female);
     }
     else
     {
         return(GenderType.Male);
     }
 }
示例#8
0
    public void UpdateAverages(BlobBehavior blob, StatType statType)
    {
        averageSize = CalculateNewAverage(averageSize, blob.size, statType);

        averageJogModifier = CalculateNewAverage(averageJogModifier, blob.jogModifier, statType);

        averageRunModifier = CalculateNewAverage(averageRunModifier, blob.runModifier, statType);

        averageRandomRotation = CalculateNewAverage(averageRandomRotation, blob.randomRotation, statType);

        averageAggression = CalculateNewAverage(averageAggression, blob.aggression, statType);

        averageFearOfPredator = CalculateNewAverage(averageFearOfPredator, blob.fearOfPredator, statType);

        averageWantOfPrey = CalculateNewAverage(averageWantOfPrey, blob.wantForPrey, statType);

        averageIncubationTicks = CalculateNewAverage(averageIncubationTicks, blob.incubationTicks, statType);

        averageReproductionLimit = CalculateNewAverage(averageReproductionLimit, blob.reproductionLimit, statType);

        //percentFemale = CalculateNewAverage(percentFemale, (int)blob.gender, statType);

        if (blob.gender.Equals(GenderType.Female) && statType == StatType.Death)
        {
            totalChildren -= blob.children;                                                                      //averageChildrenPerFemale = CalculateChildrenAverage(averageChildrenPerFemale, blob.children, statType);
        }
        numFruitEaten -= blob.fruitEaten;
        numBlobsEaten -= blob.blobsEaten;

        if (statType.Equals(StatType.Birth))
        {
            if (blob.generation > 0)
            {
                totalChildren++;
            }
            numBlobs++;
            if (blob.gender.Equals(GenderType.Female))
            {
                totalFemales++;
            }
            if (recordBlobCount < numBlobs)
            {
                recordBlobCount = numBlobs;
            }
        }
        else
        {
            numBlobs--;
            if (blob.gender.Equals(GenderType.Female))
            {
                totalFemales--;
            }
        }
    }
示例#9
0
        public static void ReproduceBlob(BlobBehavior mother, GameObject gameObject)
        {
            BlobBehavior newBlob = gameObject.GetComponent <BlobBehavior>();

            newBlob.generation = mother.generation + 1;

            newBlob.Start();

            newBlob.transform.position = new Vector3(mother.transform.position.x, yConstant, mother.transform.position.z);

            newBlob.size = SetNewBlobSize(MeOrMate(mother), gameObject);

            // compensate for size of baby
            mother.energy += (int)(100000 * (mother.size - newBlob.size));

            RandomizeTraits(mother, newBlob);

            newBlob.rotationSpeed /= newBlob.size * newBlob.size;
            newBlob.ground         = mother.ground;
            newBlob.blobPrefab     = mother.blobPrefab;

            newBlob.energy = mother.incubatedEnergy;

            newBlob.places      = (Vector2[])mother.places.Clone();
            newBlob.latestPlace = mother.latestPlace;



            newBlob.gender = RandomGender(mother);



            newBlob.name   = newBlob.gender.ToString() + "Blob";
            newBlob.parent = mother;

            mother.incubatedEnergy   = 0;
            mother.currentIncubation = 0;
            mother.children++;

            // Because of starting positions.  Don't judgde me.
            if (mother != mother.partner)
            {
                mother.partner.children++;
            }
            mother.energy /= 3;


            var stats = mother.ground.GetComponent <Statistics>();

            stats.BothGenderRecords(mother.partner);
            stats.UpdateSurvivalStatistics(mother);
            stats.UpdateAverages(newBlob, StatType.Birth);
        }
示例#10
0
    void OnTriggerEnter(Collider triggerCollider)
    {
        if (triggerCollider.gameObject.name.StartsWith("Fruit"))
        {
            LatestFruit = triggerCollider.gameObject;
            return;
        }

        if (triggerCollider.gameObject.name.StartsWith("Percepticon"))
        {
            LatestBlob = triggerCollider.gameObject.GetComponentInParent <BlobBehavior>();
        }
    }
示例#11
0
    private void SetStatus()
    {
        if (ShouldProvide())
        {
            SetSpeedAndColor(BlobSpeedType.Running, incubationColor, BlobStatusType.Providing);
            return;
        }

        if (predator != null)
        {
            if (Vector3.Distance(predator.transform.position, transform.position) > fearOfPredator)
            {
                predator = null;
            }

            else
            {
                SetSpeedAndColor(BlobSpeedType.Running, scaredColor, BlobStatusType.Fleeing);
                return;
            }
        }
        if (rival != null)
        {
            // collision resets rival
            SetSpeedAndColor(BlobSpeedType.Running, angryColor, BlobStatusType.Fighting);
            return;
        }
        if (prey != null)
        {
            if (Vector3.Distance(prey.transform.position, transform.position) > wantForPrey)
            {
                prey = null;
            }

            else
            {
                SetSpeedAndColor(BlobSpeedType.Running, hungryColor, BlobStatusType.Chasing);
                return;
            }
        }
        if (food != null)
        {
            SetSpeedAndColor(BlobSpeedType.Jogging, hungryColor, BlobStatusType.Foraging);
            return;
        }

        SetSpeedAndColor(BlobSpeedType.Walking, normalColor, BlobStatusType.Wandering);
    }
示例#12
0
        private static void SetPerceptionFields(BlobBehavior mother, BlobBehavior newBlob)
        {
            var parent = MeOrMate(mother);

            var perceptionTransform = newBlob.perception.gameObject.transform;

            newBlob.perceptionDepth = parent.perceptionDepth * GetDrift();
            newBlob.perceptionWidth = parent.perceptionWidth * GetDrift();

            // to keep from stagnating at 0
            newBlob.perceptionShift = parent.perceptionShift + (GetDrift() - 0.999f);

            perceptionTransform.localScale = new Vector3(newBlob.perceptionWidth, newBlob.perceptionWidth, newBlob.perceptionDepth);

            perceptionTransform.localPosition = new Vector3(0, 0, perceptionTransform.localScale.z * newBlob.perceptionShift);
        }
示例#13
0
    private void UpdateTargetReferences()
    {
        energy -= (int)(perceptionWidth * perceptionDepth);

        if (food == null)
        {
            food = perception.LatestFruit;
        }

        if (perception.LatestBlob != null)
        {
            var newBlob = perception.LatestBlob;
            perception.LatestBlob = null;

            if (parent != null && (newBlob.Equals(parent) || (newBlob.parent != null && newBlob.parent.Equals(this))))
            {
                return;
            }

            if (newBlob.size > size * predationLimit)
            {
                predator = newBlob;
                food     = null;
            }
            else if (newBlob.size < size / predationLimit)
            {
                prey = newBlob;
                food = null;
            }
            else if (IsGoodPartner(newBlob, false))
            {
                if (partner != null)
                {
                    partner.partner = null;
                }
                partner         = newBlob;
                newBlob.partner = this;
            }
            else if (IsRival(newBlob))
            {
                rival         = newBlob;
                newBlob.rival = this;
                LookAt(rival.transform.position);
                rival.LookAt(transform.position);
            }
        }
    }
示例#14
0
 public void BothGenderRecords(BlobBehavior blob)
 {
     // First time reproducers get to contribute to records
     if (blob.children == 1)
     {
         if (recordHighIncubationTicks < blob.incubationTicks)
         {
             recordHighIncubationTicks = blob.incubationTicks;
         }
         if (recordHighJogModifier < blob.jogModifier)
         {
             recordHighJogModifier = blob.jogModifier;
         }
         if (recordHighReproductionLimit < blob.reproductionLimit)
         {
             recordHighReproductionLimit = blob.reproductionLimit;
         }
         if (recordHighRunModifier < blob.runModifier)
         {
             recordHighRunModifier = blob.runModifier;
         }
         if (recordHighSize < blob.size)
         {
             recordHighSize = blob.size;
         }
         if (recordLowIncubationTicks > blob.incubationTicks || recordLowIncubationTicks == 0)
         {
             recordLowIncubationTicks = blob.incubationTicks;
         }
         if (recordLowJogModifier > blob.jogModifier || recordLowJogModifier == 0)
         {
             recordLowJogModifier = blob.jogModifier;
         }
         if (recordLowReproductionLimit > blob.reproductionLimit || recordLowReproductionLimit == 0)
         {
             recordLowReproductionLimit = blob.reproductionLimit;
         }
         if (recordLowRunModifier > blob.runModifier || recordLowRunModifier == 0)
         {
             recordLowRunModifier = blob.runModifier;
         }
         if (recordLowSize > blob.size)
         {
             recordLowSize = blob.size;
         }
     }
 }
示例#15
0
    internal void Start()
    {
        stats = ground.GetComponent <Statistics>();

        if (generation == 0)
        {
            fruitEaten       = 0;
            blobsEaten       = 0;
            energyFromFruit  = 0;
            energyFromBlobs  = 0;
            children         = 0;
            ticksLived       = 0;
            perceptionShift  = 0.5f;
            energy           = 300000000;
            gender           = GenderType.Female;
            childGenderRatio = 0.5f;
        }

        if (generation < 2)
        {
            partner = this;
        }
    }
示例#16
0
    void OnTriggerEnter(Collider triggerCollider)
    {
        if (triggerCollider.gameObject.name.StartsWith("Fruit"))
        {
            var fruit = triggerCollider.gameObject.GetComponent <FruitBehavior>();
            seedInPoop = fruit.genes;

            if (fruit.genes == null)
            {
                energy          += energyPerFruit;
                energyFromFruit += energyPerFruit;
            }
            else
            {
                energy          += energyPerTreeFruit;
                energyFromFruit += energyPerTreeFruit;
            }

            Destroy(fruit.gameObject);
            Destroy(fruit);
            food = null;

            fruitEaten++;
            stats.numFruitEaten++;

            if (stats.recordFruitEaten < fruitEaten)
            {
                stats.recordFruitEaten = fruitEaten;
            }

            RememberThisPlace();
        }

        else if (triggerCollider.gameObject.name.StartsWith("Percepticon"))
        {
            var targetBlob = triggerCollider.gameObject.GetComponentInParent <BlobBehavior>();

            if (targetBlob == null || targetBlob.size < size / predationLimit)
            {
                var deltaEnergy = (int)(energyPerFruit * targetBlob.size);

                food             = null;
                energy          += deltaEnergy;
                energyFromBlobs += deltaEnergy;
                targetBlob.die   = true;
                blobsEaten++;
                stats.numBlobsEaten++;

                if (stats.recordBlobsEaten < blobsEaten)
                {
                    stats.recordBlobsEaten = blobsEaten;
                }

                RememberThisPlace();
                return;
            }

            if (targetBlob.Equals(rival))
            {
                int hurtRivalAmount = (int)(size * size * size * currentSpeed * currentSpeed * aggression * 100);
                int hurtSelfAmount  = hurtRivalAmount / 2;
                int hurtFromRival   = (int)(rival.size * rival.size * rival.size * rival.currentSpeed * rival.currentSpeed * rival.aggression * 100);
                int hurtRivalSelf   = hurtFromRival / 2;
                int totalSelfHurt   = hurtSelfAmount + hurtFromRival;
                int totalRivalHurt  = hurtRivalAmount + hurtRivalSelf;

                if (totalSelfHurt > energy && totalRivalHurt > rival.energy)
                {
                    if (energy > rival.energy)
                    {
                        energy      -= rival.energy;
                        rival.energy = 0;
                    }
                    else
                    {
                        rival.energy -= energy;
                        energy        = 0;
                    }
                }
                else
                {
                    energy       -= totalSelfHurt;
                    rival.energy -= totalRivalHurt;
                }


                if (hurtRivalAmount > hurtFromRival && rival.partner != null && partner == null)
                {
                    rival.partner.partner = this;
                    partner       = rival.partner;
                    rival.partner = null;
                }

                else if (hurtRivalAmount < hurtFromRival && rival.partner == null && partner != null)
                {
                    partner.partner = rival;
                    rival.partner   = partner;
                    partner         = null;
                }

                if (rival.energy <= 0)
                {
                    rival = null;
                }
                else if (energy > 0)
                {
                    // make them flee each other after the encounter
                    predator = rival;
                    transform.Rotate(0f, 180f, 0f);
                    rival.predator = this;

                    rival.rival = null;
                    rival       = null;
                }
            }

            if (targetBlob.Equals(partner) && status.Equals(BlobStatusType.Providing) && energy > reserveEnergy)
            {
                var energyToProvide = Math.Abs(reserveEnergy - energy);
                energy         -= energyToProvide;
                partner.energy += energyToProvide;
            }
        }

        //else if (triggerCollider.gameObject.name.StartsWith("Tree"))
        //{
        //    var targetTree = triggerCollider.gameObject.GetComponentInParent<TreeBehavior>();

        //    if (targetTree.transform.localScale.x < size)
        //    {
        //        Destroy(targetTree.gameObject);
        //        Destroy(targetTree);
        //    }
        //}
    }
示例#17
0
 private bool IsRival(BlobBehavior newBlob)
 {
     // must both be male, and need to steal their partner
     return(gender == GenderType.Male && newBlob.gender == GenderType.Male && partner == null & newBlob.partner != null && rival == null && newBlob.rival == null && IsGoodPartner(newBlob.partner, true));
 }
示例#18
0
    private void UserControl()
    {
        amount = 1;

        if (target == null)
        {
            HandleTranslation();

            HandleRotation();
        }
        else
        {
            FollowTarget();
        }

        HandlePerception();

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            target = null;
        }

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            if (target != null)
            {
                showStats = !showStats;
            }
            else
            {
                switch (displayType)
                {
                case DisplayType.None:
                    displayType = DisplayType.Statistics;
                    break;

                case DisplayType.Statistics:
                    displayType = DisplayType.Records;
                    break;

                case DisplayType.Records:
                    displayType = DisplayType.None;
                    break;
                }
            }
        }

        if (Input.GetKey(KeyCode.Comma) && Time.timeScale > 0.05f)
        {
            Time.timeScale -= 0.05f;
        }

        if (Input.GetKey(KeyCode.Period))
        {
            Time.timeScale += 0.05f;
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            switch (colorToggle)
            {
            case ColorDisplayType.None:
                colorToggle = ColorDisplayType.Action;
                break;

            case ColorDisplayType.Action:
                colorToggle = ColorDisplayType.Gender;
                break;

            case ColorDisplayType.Gender:
                colorToggle = ColorDisplayType.None;
                break;
            }
        }
    }