public void GenMountainPositionsForGridCell(List <MountainData> locs, Vector2i mountainPos, Vector2i chunkPos, int seed)
        {
            Vector2i mtChunk     = new Vector2i((int)(mountainPos.X * MountainGridSize), (int)(mountainPos.Y * MountainGridSize));
            Location chunkCenter = chunkPos.ToLocation() * Constants.CHUNK_WIDTH;
            MTRandom random      = new MTRandom(39, (ulong)(mountainPos.X * 39 + mountainPos.Y + seed));
            int      count       = random.Next(1, 3);

            for (int i = 0; i < count; i++)
            {
                int rangeSize;
                if (random.Next(10) > 5)
                {
                    rangeSize = random.Next(5, 13);
                }
                else
                {
                    rangeSize = random.Next(3, 8);
                }
                double       ca       = random.NextDouble();
                double       cb       = random.NextDouble();
                Vector2i     centerMt = new Vector2i(mtChunk.X * Constants.CHUNK_WIDTH + (int)(ca * MountainGridSize * Constants.CHUNK_WIDTH), mtChunk.Y * Constants.CHUNK_WIDTH + (int)(cb * MountainGridSize * Constants.CHUNK_WIDTH));
                double       ch       = random.NextDouble() * 512 + 512;
                double       cradius  = random.NextDouble() * ch * 0.25 + ch * 0.75;
                MountainData cmt      = new MountainData()
                {
                    Center = centerMt, Height = ch, Radius = cradius
                };
                if (centerMt.ToLocation().DistanceSquared(chunkCenter) < (MountainMaxSizeBlocks * MountainMaxSizeBlocks))
                {
                    locs.Add(cmt);
                }
                double ph = ch;
                for (int r = 1; r < rangeSize; r++)
                {
                    double ra = random.NextDouble() * 2.0 - 1.0;
                    double rb = random.NextDouble() * 2.0 - 1.0;
                    ra = ra > 0 ? Math.Max(r / (double)rangeSize, ra) : Math.Min(-r / (double)rangeSize, ra);
                    rb = rb > 0 ? Math.Max(r / (double)rangeSize, rb) : Math.Min(-r / (double)rangeSize, rb);
                    Vector2i     rngMt   = new Vector2i(centerMt.X + (int)(ra * MountainRangeRadius), centerMt.Y + (int)(rb * MountainRangeRadius));
                    double       rh      = random.NextDouble() * (ph * 0.5) + (ph * 0.5);
                    double       rradius = random.NextDouble() * rh * 0.25 + rh * 0.75;
                    MountainData rmt     = new MountainData()
                    {
                        Center = rngMt, Height = rh, Radius = rradius
                    };
                    if (rngMt.ToLocation().DistanceSquared(chunkCenter) < (MountainMaxSizeBlocks * MountainMaxSizeBlocks))
                    {
                        locs.Add(rmt);
                    }
                }
            }
        }
        private void GeneratePattern(int num)
        {
            // If all patterns of 'val' level are stale, swap allPatternsList and patternStaleList
            if (allPatternsList[num].Count == 0)
            {
                Console.WriteLine("allPatterns Count: " + allPatternsList[num].Count);
                Console.WriteLine("patternStale Count: " + patternStaleList[num].Count);
                allPatternsList[num].AddRange(patternStaleList[num]);
                patternStaleList[num].Clear();
            }
            if (allPatternsList[num].Count == 0)
            {
                return;
            }

            int ran = random.Next(0, allPatternsList[num].Count - 1);

            if (process == null)
            {
                process = (Process)Activator.CreateInstance(allPatternsList[num][ran], new object[] { Engine, ProcessManager, this });
                process.SetNext(new WaitForFamilyCountProcess(Engine, _enemyFamily, CVars.Get <int>("spawner_max_enemy_count")));
            }
            else
            {
                process.SetNext((Process)Activator.CreateInstance(allPatternsList[num][ran], new object[] { Engine, ProcessManager, this }));
                process.SetNext(new WaitForFamilyCountProcess(Engine, _enemyFamily, CVars.Get <int>("spawner_max_enemy_count")));
            }

            patternStaleList[num].Add(allPatternsList[num][ran]);
            allPatternsList[num].RemoveAt(ran);
        }
            public void GenerateTrees(SimpleGeneratorCore sgc, Vector3i chunkPos, int Seed, int seed, int seed3, int seed4, int seed5)
            {
                Trees         = new List <KeyValuePair <Vector2i, int> >();
                ChunkPosition = chunkPos;
                CPos          = chunkPos.ToLocation() * Chunk.CHUNK_SIZE;
                MTRandom random = new MTRandom((ulong)chunkPos.GetHashCode());
                // TODO: Biome basis!
                int c = 0;

                if (random.Next(1, 5) == 1)
                {
                    if (random.Next(1, 5) == 1)
                    {
                        if (random.Next(1, 5) == 1)
                        {
                            c = random.Next(1, 3);
                        }
                        else
                        {
                            c = random.Next(1, 2);
                        }
                    }
                    else
                    {
                        c = 1;
                    }
                }
                for (int i = 0; i < c; i++)
                {
                    Trees.Add(new KeyValuePair <Vector2i, int>(new Vector2i(random.Next(Chunk.CHUNK_SIZE), random.Next(Chunk.CHUNK_SIZE)), random.Next()));
                }
            }
Exemple #4
0
        /// <summary>
        /// Loads the world configuration onto this world object.
        /// Is called as part of the startup sequence for a world.
        /// </summary>
        public void LoadConfig()
        {
            string folder = "saves/" + Name;

            TheServer.Files.CreateDirectory(folder);
            // TODO: Journaling read
            string fname = folder + "/world.fds";

            if (TheServer.Files.Exists(fname))
            {
                Config = new FDSSection(TheServer.Files.ReadText(fname));
            }
            else
            {
                Config = new FDSSection();
            }
            Config.Set("general.IMPORTANT_NOTE", "Edit this configuration at your own risk!");
            Config.Set("general.name", Name);
            Config.Default("general.seed", Utilities.UtilRandom.Next(SeedMax) - SeedMax / 2);
            Config.Default("general.spawnpoint", new Location(0, 0, 50).ToString());
            Config.Default("general.time", 0);
            Config.Default("general.generator", "simple");
            Config.Default("general.generator_scale", 1.0);
            Settings = new WorldSettings();
            Settings.LoadFromSection(TheServer, Config);
            GlobalTickTime = Config.GetDouble("general.time", 0).Value;
            CFGEdited      = true;
            Seed           = Config.GetInt("general.seed", DefaultSeed).Value;
            SpawnPoint     = Location.FromString(Config.GetString("general.spawnpoint", DefaultSpawnPoint));
            Generator      = Config.GetString("general.generator", "simple").ToLowerFast();
            GeneratorScale = Config.GetDouble("general.generator_scale", 1.0).Value;
            MTRandom seedGen = new MTRandom(39, (ulong)Seed);

            Seed2 = (seedGen.Next(SeedMax) - SeedMax / 2);
            Seed3 = (seedGen.Next(SeedMax) - SeedMax / 2);
            Seed4 = (seedGen.Next(SeedMax) - SeedMax / 2);
            Seed5 = (seedGen.Next(SeedMax) - SeedMax / 2);
            SaveConfig();
        }
        private void SpawnEntity()
        {
            float zoom = Camera.TotalZoom;

            Entity             entity        = _entityCreationFunctions[_random.Next(0, _entityCreationFunctions.Length - 1)].Invoke(Engine);
            TransformComponent transformComp = entity.GetComponent <TransformComponent>();

            transformComp.SetPosition(CVars.Get <float>("entity_background_spawner_x") / zoom,
                                      _random.NextSingle(CVars.Get <float>("entity_background_spawner_y_min"),
                                                         CVars.Get <float>("entity_background_spawner_y_max")), true);
            transformComp.SetRotation((float)(_random.NextSingle() * Math.PI * 2), true);
            entity.AddComponent(new MovementComponent(new Vector2(-1, 0),
                                                      _random.NextSingle(CVars.Get <float>("entity_background_entity_speed_min"),
                                                                         CVars.Get <float>("entity_background_entity_speed_max"))));
            entity.GetComponent <MovementComponent>().UpdateRotationWithDirection = false;
            entity.AddComponent(new RotationComponent(_random.NextSingle(CVars.Get <float>("entity_background_entity_angular_speed_min"),
                                                                         CVars.Get <float>("entity_background_entity_angular_speed_max"))));
            entity.AddComponent(new MenuBackgroundComponent());
        }
Exemple #6
0
        /// <summary>
        /// 按权重获取随机整数
        /// </summary>
        /// <param name="weights">Weights.</param>
        public static int RandomByWeight(int[] weights)
        {
            int sum = 0;

            for (int i = 0; i < weights.Length; i++)
            {
                sum += weights [i];
            }
            int rnd = MTRandom.Next(sum);

            int cumulate = 0;

            for (int i = 0; i < weights.Length; i++)
            {
                if (cumulate > rnd)
                {
                    return(i - 1);
                }
                cumulate += weights [i];
            }
            return(weights.Length - 1);
        }
Exemple #7
0
        /// <summary>
        /// 按权重获取随机整数
        /// </summary>
        /// <param name="weights">Weights.</param>
        public static int RandomByWeight(List <int> weights)
        {
            int sum = 0;

            for (int i = 0; i < weights.Count; i++)
            {
                sum += weights [i];
            }
            int rnd = MTRandom.Next(sum);

            int cumulate = 0;

            for (int i = 0; i < weights.Count; i++)
            {
                if (cumulate > rnd)
                {
                    return(i - 1);
                }
                cumulate += weights [i];
            }
            return(weights.Count - 1);
        }
Exemple #8
0
        void AttachFluctuationSequence()
        {
            int availableFluctuationsCount = 0;

            for (int i = 0; i < _fluctuationUnlockedLevel; i++)
            {
                availableFluctuationsCount += Constants.Fluctuations.FLUCTUATIONS[i].Length;
            }

            Type[] fluctuations = new Type[availableFluctuationsCount];
            int    k            = 0;

            for (int i = 0; i < _fluctuationUnlockedLevel; i++)
            {
                for (int j = 0; j < Constants.Fluctuations.FLUCTUATIONS[i].Length; j++)
                {
                    fluctuations[k++] = Constants.Fluctuations.FLUCTUATIONS[i][j];
                }
            }

            Type fluctuationType = null;

            do
            {
                int index = _random.Next(0, fluctuations.Length - 1);
                fluctuationType = fluctuations[index];
            } while (fluctuationType == _lastFluctuation);

            WaitProcessKillOnEvent timerProcess = new WaitProcessKillOnEvent(_random.NextSingle() * (Constants.Fluctuations.TIMER_MAX - Constants.Fluctuations.TIMER_MIN) + Constants.Fluctuations.TIMER_MIN,
                                                                             typeof(GoalEvent));

            timerProcess.SetNext((Fluctuation)Activator.CreateInstance(fluctuationType, _owner));
            _processManager.Attach(timerProcess);
            _lastFluctuation = fluctuationType;

            _fluctuationUnlockedLevel = MathHelper.Min(++_fluctuationUnlockedLevel, Constants.Fluctuations.FLUCTUATIONS.Length);
        }