예제 #1
0
        private void Breed(Position other)
        {
            // Retrieve the target mate stats to mate
            LifeformStats mate = (LifeformStats)this.QueryP(EntityType.LIFEFORM_STATS,this.targetMate.Id,typeof(long),typeof(long),typeof(long),typeof(int),typeof(int),typeof(int),typeof(int),typeof(int),typeof(int));

            if (mate != null)
            {
                this.Stats.Life -= this.Stats.InitialLife / this.Stats.MaxNrChildren;
                this.FoodAmount -= this.breedingCost;

                long genom = 31 + this.Stats.Genom;
                genom = (genom * 31) + mate.Genom;

                int initiallife = (this.Stats.InitialLife + mate.InitialLife) / 2;
                initiallife += (this.rng.Next() % (initiallife / 2)) - (initiallife / 4);

                int food       = 0;
                int generation = Math.Max(this.Stats.Generation,mate.Generation) + 1;

                int visualRange = (this.Stats.VisualRange + mate.VisualRange) / 2;
                visualRange += (this.rng.Next() % visualRange) - ((visualRange - 1) / 2);

                int maxNrChildren = ((this.Stats.MaxNrChildren + mate.MaxNrChildren) / 2) + (this.rng.Next() % 5) - 2;
                int speed         = Math.Max(this.Stats.Speed,mate.Speed) + (this.rng.Next() % 5) - 2;

                // Spawn a new offspring
                this.Put(EntityType.SPAWN,genom,this.Stats.Genom,mate.Genom,initiallife,food,this.Position.X,this.Position.Y,generation,visualRange,maxNrChildren,speed);
                this.nrChildren++;
            }
            this.targetMate = null;
        }
예제 #2
0
        private bool CanBreed(Position other)
        {
            if (other == null)
            {
                return(false);
            }
            LifeformStats stats = (LifeformStats)this.QueryP(EntityType.LIFEFORM_STATS,other.Id,typeof(long),typeof(long),typeof(long),typeof(int),typeof(int),typeof(int),typeof(int),typeof(int),typeof(int));

            if (stats == null)
            {
                return(false);
            }

            return((this.Stats.Genom != stats.P1Genom && this.Stats.Genom != stats.P2Genom) &&
                   (this.Stats.P1Genom != stats.P1Genom && this.Stats.P1Genom != stats.P2Genom) &&
                   (this.Stats.P2Genom != stats.P1Genom && this.Stats.P2Genom != stats.P2Genom));
        }