Esempio n. 1
0
        private static void CreateDbIfNotExists(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            var context = services.GetRequiredService <ZooManagementDbContext>();

            context.Database.EnsureCreated();

            if (!context.AnimalClasses.Any())
            {
                var animalClasses = SampleAnimalClasses.GetClasses();
                context.AnimalClasses.AddRange(animalClasses);
                context.SaveChanges();

                var enclosures = SampleEnclosures.GetEnclosures();
                context.Enclosures.AddRange(enclosures);
                context.SaveChanges();

                var zookeepers = SampleZookeepers.GetZookeepers(context);
                context.Zookeepers.AddRange(zookeepers);
                context.SaveChanges();

                var animals = SpeciesGenerator.GetAnimals();
                context.Animals.AddRange(animals);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
    public void GenerateEntities()
    {
        data = GameDataManager.instance.masterGalaxyData;
        GameDataManager.instance.ClearAllEntities();
        GameDataManager.instance.ClearAllSpecies();

        string[] speciesNames = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("SpeciesButterfly"), numberOfSpecies);
        for (int i = 0; i < numberOfSpecies; i++)
        {
            GameDataManager.instance.AddNewSpecies(SpeciesGenerator.GetSpecies(speciesNames[i]));
        }
        for (int i = 0; i < data.sectors.Length; i++)
        {
            for (int j = 0; j < data.sectors[0].Length; j++)
            {
                if (data.sectors[i][j].Owner == null && data.sectors[i][j].SystemCount > 0)
                {
                    unoccupiedSectors.Add(data.sectors[i][j]);
                }
            }
        }
        List <List <SectorData> > partitions = GenerateSectorPartitions(unoccupiedSectors);

        string[] entityNames = MarkovGenerator.GenerateMarkovWord(StringLoader.GetAllStrings("StarNames"), partitions.Count);
        for (int i = 0; i < partitions.Count; i++)
        {
            float averageSystem = 0;
            float maxSystem     = 0;
            float minSystem     = 10000;
            float sumOfSquares  = 0;
            foreach (SectorData d in partitions[i])
            {
                averageSystem += d.SystemCount;
                sumOfSquares  += d.SystemCount * d.SystemCount;
                if (d.SystemCount > maxSystem)
                {
                    maxSystem = d.SystemCount;
                }
                if (d.SystemCount < minSystem)
                {
                    minSystem = d.SystemCount;
                }
            }
            float totalSystem = averageSystem;
            averageSystem = averageSystem / partitions[i].Count;
            float sumOfSquaresAverage = sumOfSquares / partitions[i].Count;
            float standardDeviation   = Mathf.Sqrt(sumOfSquaresAverage - (averageSystem * averageSystem));
            Debug.Log("Total System:" + totalSystem + " averageSystem:" + averageSystem + " minSystem:" + minSystem + " maxSystem:" + maxSystem + " stdDeviation:" + standardDeviation);
            GalaxyEntity g = GetEntity(partitions[i]);
            g.name = entityNames[i];
            Debug.Log(g.leader.FullName + " " + g.Government.governmentName + " " + g.Government.governmentCatagory);
            GameDataManager.instance.AddNewEntity(g);
        }
        entityList.Display(GameDataManager.instance.Entitites);
        speciesList.Display(GameDataManager.instance.Species);
        WorldMap.instance.ShowTerritory();
    }