コード例 #1
0
ファイル: World.cs プロジェクト: kraidiky/TribeSim
        public static void Initialize(Dispatcher d, int randomSeed)
        {
            WorldProperties.ResetFeatureDescriptions();
            randomizer = new Random(randomSeed);
            StatisticsCollector.Reset();
            Meme.ClearMemePool();
            tribes.Clear();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (!string.IsNullOrWhiteSpace(baseFolder))
            {
                logFolder = Path.Combine(baseFolder, DateTime.Now.ToString("yyyyMMdd_HHmmss"));
            }
            else
            {
                baseFolder = Properties.Settings.Default.LogBaseFolder;
                if (string.IsNullOrWhiteSpace(baseFolder))
                {
                    logFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Tribe Sim Results", DateTime.Now.ToString("yyyyMMdd_HHmmss"));
                }
                else
                {
                    logFolder = Path.Combine(baseFolder, DateTime.Now.ToString("yyyyMMdd_HHmmss"));
                }
            }
            Directory.CreateDirectory(logFolder);
            tribesLogFolder    = Path.Combine(logFolder, "Tribes");
            memesLogFolder     = Path.Combine(logFolder, "Memes");
            tribesmanLogFolder = Path.Combine(logFolder, "Tribesmen");
            simDataFolder      = Path.Combine(logFolder, "Results");
            Directory.CreateDirectory(tribesmanLogFolder);
            Directory.CreateDirectory(tribesLogFolder);
            Directory.CreateDirectory(memesLogFolder);
            if (WorldProperties.CollectFilesData > 0.5)
            {
                Directory.CreateDirectory(simDataFolder);
            }
            Year = 0;
            int i;

            for (i = 0; i < WorldProperties.StartingNumberOfTribes; i++)
            {
                Tribe t = new Tribe(randomizer.Next(int.MaxValue));
                int   numberOfTribesmen = (int)Math.Round(randomizer.NormalRandom(WorldProperties.StartingTribePopulationMean, WorldProperties.StartingTribePopulationStdDev));
                for (int ii = 0; ii < numberOfTribesmen; ii++)
                {
                    Tribesman man = Tribesman.GenerateTribesmanFromAStartingSet(randomizer);
                    t.AcceptMember(man);
                }
                tribes.Add(t);
            }
            int maxReproductionAge = 5000; // Это сломатся если у нас появятся сверхдолгожители

            if (WorldProperties.MaximumBreedingAge > 0)
            {
                maxReproductionAge = (int)WorldProperties.MaximumBreedingAge + 1;
            }
            Tribesman.reproductionCostIncrease = new double[maxReproductionAge];
            i = 0;
            for (; i < WorldProperties.BreedingCostsIncreaseAge; i++)
            {
                Tribesman.reproductionCostIncrease[i] = 0;
            }
            for (; i < maxReproductionAge; i++)
            {
                Tribesman.reproductionCostIncrease[i] = (i - WorldProperties.BreedingCostsIncreaseAge) * WorldProperties.BreedingCostsIncreaseCoefficient;
            }

            ReportEndOfYearStatistics();

            d.Invoke(new Action(delegate()
            {
                StatisticsCollector.ConsolidateNewYear();
            }));
            Tribesman.UseGompertzAgeing = WorldProperties.UseGompertzAgeing > 0.5;
        }