LifeSimulation.Core.World.spawnInitialLifelets C# (CSharp) Method

spawnInitialLifelets() private method

private spawnInitialLifelets ( ) : void
return void
        private void spawnInitialLifelets()
        {
            // Init
            int lifeletsPerRace = _initialLifelets / _races.Count;

            // We spawn races around a outside ring
            if(_spawnMethod == SpawnMethod.GroupedRacesOnRing) {
                double radiansPerRace = (2*Math.PI) / (_races.Count);
                int lifeletRandomDispersion = (int)(Config.WorldInitialLifeletsDispersionAmount * (_races.Count/(_races.Count*Config.WorldInitialLifeletsToRaceDispersionRatio)));
                for(int i = 0; i < _races.Count; i++) {

                    // Get the actual type and figure out center point
                    Type lifeletType = (Type)_races[i];
                    Vector raceCenter = Vector.FromAngle(Config.WorldInitialSpawnRadius,radiansPerRace*i);

                    // Loop lifelets for race
                    for(int ii = 0; ii < lifeletsPerRace; ii++) {

                        // New position
                        double x = raceCenter.X + _randomGen.Next(-lifeletRandomDispersion,lifeletRandomDispersion);
                        double y = raceCenter.Y + _randomGen.Next(-lifeletRandomDispersion,lifeletRandomDispersion);

                        // Create and register life
                        Lifelet newLife = (Lifelet)Activator.CreateInstance(lifeletType,this,new Vector(x,y));
                        newLife.VerifyIntegrity();
                        _lifelets.Add(newLife);
                    }
                }
            }

            // We spawn randomly on outside ring
            else if (_spawnMethod == SpawnMethod.RandomOnRing) {
                for(int i = 0; i < _races.Count; i++) {

                    // Get the actual type and figure out center point
                    Type lifeletType = (Type)_races[i];

                    // Loop lifelets for race
                    for(int ii = 0; ii < lifeletsPerRace; ii++) {

                        // Position
                        int angle = _randomGen.Next(0,360);
                        Vector pos = Vector.FromAngle(Config.WorldInitialSpawnRadius,Math2.DegreeToRadian(angle));

                        // Create and register life
                        Lifelet newLife = (Lifelet)Activator.CreateInstance(lifeletType,this,pos);
                        _lifelets.Add(newLife);
                    }
                }
            }

            // Spawn food
            for(int i = 0; i < Config.WorldInitialFoodAmount; i++) {

                // Position
                int angle = _randomGen.Next(0,360);
                int length = _randomGen.Next(0,Config.WorldRadius);
                Vector pos = Vector.FromAngle(length,Math2.DegreeToRadian(angle));

                // Create and register food
                Food newFood = new Food(this,pos,Math2.JitteredValue(Config.FoodEnergy,Config.FoodEnergyJitter));
                _food.Add(newFood);
            }
        }