示例#1
0
 // FixedUpdate is called a fixed number of times a second
 public static void FixedUpdate()
 {
     UIController.FixedUpdate();
     InputController.FixedUpdate();
     World.FixedUpdate();
     Lifeforms.FixedUpdate();
 }
示例#2
0
 // Start is called before the first frame update
 public static void Start()
 {
     Logger.InitializeLog();
     CameraController.SetupCamera();
     UIController.Start();
     InputController.Start();
     World.Start();
     Lifeforms.Start();
 }
示例#3
0
文件: World.cs 项目: AliTsuki/EvoSim
 // Generates a new world
 public static void GenerateNewWorld()
 {
     ClearTiles();
     UpdateNoiseSettings();
     CreateTiles();
     AssignTilesToMesh();
     Lifeforms.ResetAllLife();
     Debug.Log($@"New World Generated!");
 }
示例#4
0
    // Spawn sapling
    public void SpawnSapling()
    {
        int        x = GameController.random.Next(this.currentTile.position.x - Mathf.RoundToInt(this.genes[geneSeedingDistance] * distanceScale), this.currentTile.position.x + Mathf.RoundToInt(this.genes[geneSeedingDistance] * distanceScale));
        int        y = GameController.random.Next(this.currentTile.position.y - Mathf.RoundToInt(this.genes[geneSeedingDistance] * distanceScale), this.currentTile.position.y + Mathf.RoundToInt(this.genes[geneSeedingDistance] * distanceScale));
        Vector2Int seedingLocation = new Vector2Int(x, y);

        if (World.IsPositionValid(seedingLocation) == true)
        {
            WorldTile seedingTile = World.Tiles[seedingLocation];
            if (seedingTile.plant == null)
            {
                Plant newPlant = new Plant(Lifeforms.plantID, seedingTile, this.genes, this.matesGenes);
                Lifeforms.SpawnParentedLifeform(newPlant);
            }
        }
        this.ModifyEnergy(-this.genes[geneEnergyCostReproduction] * energyScale);
        this.isCarryingSpawn          = false;
        this.isReproductionOnCooldown = true;
        this.lastBirthedTime          = Time.time;
    }
示例#5
0
        public async Task <IEnumerable <PlantInfo> > Process(IEnumerable <PlantInfo> plantInfos)
        {
            var newOrigins    = new List <Origin>();
            var newPlantInfos = new List <PlantInfo>();
            var newTaxons     = new List <Taxon>();

            foreach (var plantInfo in plantInfos)
            {
                var lifeform = Lifeforms.FirstOrDefault(l => l.ScientificName == plantInfo.ScientificName);

                if (lifeform == null)
                {
                    lifeform = await _lifeformService.AddOrUpdateLifeformAsync(plantInfo.Lifeform);

                    Lifeforms.Add(lifeform);
                }

                plantInfo.Lifeform = lifeform;

                var taxon = Taxons.FirstOrDefault(t => t.Kingdom == plantInfo.Taxon.Kingdom &&
                                                  t.Genus == plantInfo.Taxon.Genus &&
                                                  t.Species == plantInfo.Taxon.Species &&
                                                  (t.Subspecies == plantInfo.Taxon.Subspecies || !string.IsNullOrEmpty(plantInfo.Taxon.Variety)) &&
                                                  t.Variety == plantInfo.Taxon.Variety);

                if (taxon == null)
                {
                    // Do we already have the same taxon in our insert list?
                    var taxonResult = newTaxons.FirstOrDefault(t => t.Kingdom == plantInfo.Taxon.Kingdom &&
                                                               t.Genus == plantInfo.Taxon.Genus &&
                                                               t.Species == plantInfo.Taxon.Species &&
                                                               (t.Subspecies == plantInfo.Taxon.Subspecies || !string.IsNullOrEmpty(plantInfo.Taxon.Variety)) &&
                                                               t.Variety == plantInfo.Taxon.Variety);

                    if (taxonResult == null)
                    {
                        newTaxons.Add(plantInfo.Taxon);
                    }
                }

                // Do we already have the same origin in our insert list?
                var originResult = newOrigins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId &&
                                                             o.ExternalId == plantInfo.Origin.ExternalId &&
                                                             o.AltExternalId == plantInfo.Origin.AltExternalId);
                if (originResult == null)
                {
                    // See if it already exists, if not, add it to the insert list
                    originResult = Origins.FirstOrDefault(o => o.ExternalId == plantInfo.Origin.ExternalId && o.AltExternalId == plantInfo.Origin.AltExternalId);
                    if (originResult == null)
                    {
                        newOrigins.Add(plantInfo.Origin);
                    }
                }
            }

            if (newOrigins.Any())
            {
                newOrigins = (await _originService.AddOriginsAsync(newOrigins)).ToList();
                Origins.AddRange(newOrigins);
            }

            if (newTaxons.Any())
            {
                newTaxons = (await _taxonService.AddTaxonsAsync(newTaxons)).ToList();
                Taxons.AddRange(newTaxons);
            }

            foreach (var plantInfo in plantInfos)
            {
                var origin = Origins.FirstOrDefault(o => o.ExternalId == plantInfo.Origin.ExternalId &&
                                                    o.AltExternalId == plantInfo.Origin.AltExternalId);
                if (origin == null)
                {
                    origin = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId);
                }

                plantInfo.Origin = origin;

                if (plantInfo.Taxon != null)
                {
                    var taxon = Taxons.FirstOrDefault(t => t.Kingdom == plantInfo.Taxon.Kingdom &&
                                                      t.Genus == plantInfo.Taxon.Genus &&
                                                      t.Species == plantInfo.Taxon.Species &&
                                                      (t.Subspecies == plantInfo.Taxon.Subspecies || !string.IsNullOrEmpty(plantInfo.Taxon.Variety)) &&
                                                      t.Variety == plantInfo.Taxon.Variety);

                    plantInfo.Taxon = taxon;
                }

                newPlantInfos.Add(plantInfo);
            }

            if (newPlantInfos.Any())
            {
                newPlantInfos = (await _plantInfoService.AddPlantInfosAsync(newPlantInfos)).ToList();
            }

            foreach (var newPlantInfo in newPlantInfos)
            {
                var plantInfo = plantInfos.First(p => p.Origin.OriginId == newPlantInfo.Origin.OriginId);

                plantInfo.PlantInfoId = newPlantInfo.PlantInfoId;
                newPlantInfo.Taxon    = plantInfo.Taxon;
                newPlantInfo.Origin   = plantInfo.Origin;
                newPlantInfo.Lifeform = plantInfo.Lifeform;
            }

            var plantInfoLocations = plantInfos.Where(p => p.Locations != null && p.Locations.Any())
                                     .SelectMany(p => p.Locations)
                                     .DistinctBy(pl => new { pl.PlantInfo.Origin.AltExternalId, pl.Location.StateOrProvince })
                                     .ToList();

            if (plantInfoLocations.Any() && newPlantInfos.Any())
            {
                var states    = plantInfos.SelectMany(p => p.Locations).Select(l => l.Location.StateOrProvince).Distinct();
                var countries = plantInfos.SelectMany(p => p.Locations).Select(l => l.Location.Country).Distinct();
                var locations = (await _locationService.GetLocationsAsync(l =>
                                                                          (countries.Contains(l.Country) || states.Contains(l.StateOrProvince)) &&
                                                                          l.PostalCode == null && l.Region == null && l.AddressLine1 == null & l.City == null)).ToList();

                var missingLocations = plantInfoLocations.Select(pl => pl.Location)
                                       .GroupJoin(locations,
                                                  pl => new { pl.StateOrProvince, pl.Country },
                                                  l => new { l.StateOrProvince, l.Country },
                                                  (pl, l) => new { pl, l })
                                       .Where(pll => !pll.l.Any())
                                       .Select(pll => pll.pl).DistinctBy(pl => new { pl.StateOrProvince, pl.Country })
                                       .ToList();

                if (missingLocations.Any())
                {
                    var locationResult = await _locationService.AddLocationsAsync(missingLocations);

                    locations.AddRange(locationResult.ToList());
                }

                var plantLocationsToAdd = new List <PlantLocation>();
                foreach (var plantInfoLocation in plantInfoLocations)
                {
                    var newPlantInfo = newPlantInfos.FirstOrDefault(npl => npl.Origin.AltExternalId == plantInfoLocation.PlantInfo.Origin.AltExternalId);
                    if (newPlantInfo != null)
                    {
                        var location = locations.First(l => l.Country == plantInfoLocation.Location.Country &&
                                                       l.StateOrProvince == plantInfoLocation.Location.StateOrProvince);

                        plantLocationsToAdd.Add(new PlantLocation
                        {
                            PlantInfo          = newPlantInfo,
                            Location           = location,
                            Status             = plantInfoLocation.Status,
                            ConservationStatus = plantInfoLocation.ConservationStatus
                        });
                    }
                }

                if (plantInfoLocations.Any())
                {
                    var plantLocationsResult = (await _plantInfoService.AddPlantLocations(plantLocationsToAdd)).ToList();

                    foreach (var newPlantInfo in newPlantInfos)
                    {
                        var newPlantInfoLocations = plantLocationsResult.Where(pl => pl.PlantInfo.PlantInfoId == newPlantInfo.PlantInfoId);

                        // Hydrate Locations
                        foreach (var newPlantInfoLocation in newPlantInfoLocations)
                        {
                            newPlantInfoLocation.Location = locations.Where(l => l.LocationId == newPlantInfoLocation.Location.LocationId).First();
                        }

                        newPlantInfo.Locations = newPlantInfoLocations.Any() ? newPlantInfoLocations : null;
                    }
                }
            }

            var indexResult = await _plantInfoIndex.IndexManyAsync(newPlantInfos.Select(p => p.AsSearchModel(null, null)));

            return(newPlantInfos);
        }
示例#6
0
        public async Task <PlantInfo> Process(PlantInfo plantInfo)
        {
            var lifeform = Lifeforms.FirstOrDefault(l => l.ScientificName == plantInfo.ScientificName);

            if (lifeform == null)
            {
                throw new Exception("We shouldn't have any missing lifeforms at this point.");
            }

            var taxon = Taxons.FirstOrDefault(t => t.Kingdom == plantInfo.Taxon.Kingdom &&
                                              t.Subkingdom == plantInfo.Taxon.Subkingdom &&
                                              t.Infrakingdom == plantInfo.Taxon.Infrakingdom &&
                                              t.Phylum == plantInfo.Taxon.Phylum &&
                                              t.Subphylum == plantInfo.Taxon.Subphylum &&
                                              t.Class == plantInfo.Taxon.Class &&
                                              t.Subclass == plantInfo.Taxon.Subclass &&
                                              t.Superorder == plantInfo.Taxon.Superorder &&
                                              t.Order == plantInfo.Taxon.Order &&
                                              t.Family == plantInfo.Taxon.Family &&
                                              t.Genus == plantInfo.Taxon.Genus &&
                                              t.Species == plantInfo.Taxon.Species &&
                                              (t.Subspecies == plantInfo.Taxon.Subspecies || plantInfo.Taxon.Variety != null) &&
                                              t.Variety == plantInfo.Taxon.Variety &&
                                              t.Subvariety == plantInfo.Taxon.Subvariety &&
                                              t.Form == plantInfo.Taxon.Form);

            if (taxon == null)
            {
                throw new Exception("We shouldn't have any missing taxa at this point.");
            }

            var originResult = Origins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId &&
                                                      o.ExternalId == plantInfo.Origin.ExternalId &&
                                                      o.AltExternalId == plantInfo.Origin.AltExternalId);

            if (originResult == null)
            {
                originResult = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId);
            }

            if (originResult != null)
            {
                Origins.Add(originResult);
            }
            else
            {
                originResult = await _originService.AddOrUpdateOriginAsync(plantInfo.Origin, null);

                Origins.Add(originResult);
            }

            var plantInfoResult = await _plantInfoService.GetPlantInfoAsync(originResult.OriginId, taxon.TaxonId);

            if (plantInfoResult == null)
            {
                plantInfo.Origin   = originResult;
                plantInfo.Lifeform = lifeform;
                plantInfo.Taxon    = taxon;
                plantInfoResult    = await _plantInfoService.AddOrUpdatePlantInfoAsync(plantInfo);
            }

            return(plantInfoResult);
        }
示例#7
0
        public async Task <PlantInfo> Process(PlantInfo plantInfo)
        {
            var lifeform = Lifeforms.FirstOrDefault(l => l.ScientificName == plantInfo.ScientificName);

            if (lifeform == null)
            {
                lifeform = await _lifeformService.AddOrUpdateLifeformAsync(plantInfo.Lifeform);

                Lifeforms.Add(lifeform);
            }

            var taxon = Taxons.FirstOrDefault(t => t.Kingdom == plantInfo.Taxon.Kingdom &&
                                              t.Subkingdom == plantInfo.Taxon.Subkingdom &&
                                              t.Infrakingdom == plantInfo.Taxon.Infrakingdom &&
                                              t.Phylum == plantInfo.Taxon.Phylum &&
                                              t.Subphylum == plantInfo.Taxon.Subphylum &&
                                              t.Class == plantInfo.Taxon.Class &&
                                              t.Subclass == plantInfo.Taxon.Subclass &&
                                              t.Superorder == plantInfo.Taxon.Superorder &&
                                              t.Order == plantInfo.Taxon.Order &&
                                              t.Family == plantInfo.Taxon.Family &&
                                              t.Genus == plantInfo.Taxon.Genus &&
                                              t.Species == plantInfo.Taxon.Species &&
                                              t.Subspecies == plantInfo.Taxon.Subspecies &&
                                              t.Variety == plantInfo.Taxon.Variety &&
                                              t.Subvariety == plantInfo.Taxon.Subvariety &&
                                              t.Form == plantInfo.Taxon.Form);

            if (taxon == null)
            {
                taxon = await _taxonService.AddOrUpdateTaxonAsync(plantInfo.Taxon);

                Taxons.Add(taxon);
            }

            var originResult = Origins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId &&
                                                      o.ExternalId == plantInfo.Origin.ExternalId &&
                                                      o.AltExternalId == plantInfo.Origin.AltExternalId);

            if (originResult == null)
            {
                originResult = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId);

                Origins.Add(originResult);
            }

            if (originResult == null)
            {
                originResult = await _originService.AddOrUpdateOriginAsync(plantInfo.Origin, null);

                Origins.Add(originResult);
            }

            var plantInfoResult = await _plantInfoService.GetPlantInfoAsync(originResult.OriginId, taxon.TaxonId);

            if (plantInfoResult == null)
            {
                plantInfo.Origin   = originResult;
                plantInfo.Lifeform = lifeform;
                plantInfo.Taxon    = taxon;
                plantInfoResult    = await _plantInfoService.AddOrUpdatePlantInfoAsync(plantInfo);
            }

            return(plantInfoResult);
        }
示例#8
0
        public async Task <IEnumerable <PlantInfo> > Process(IEnumerable <PlantInfo> plantInfos)
        {
            var newOrigins    = new List <Origin>();
            var newPlantInfos = new List <PlantInfo>();

            foreach (var plantInfo in plantInfos)
            {
                var lifeform = Lifeforms.FirstOrDefault(l => l.ScientificName == plantInfo.ScientificName);

                if (lifeform == null)
                {
                    lifeform = await _lifeformService.AddOrUpdateLifeformAsync(plantInfo.Lifeform);

                    Lifeforms.Add(lifeform);
                }
                plantInfo.Lifeform = lifeform;

                var taxon = Taxons.FirstOrDefault(t => t.Kingdom == plantInfo.Taxon.Kingdom &&
                                                  t.Subkingdom == plantInfo.Taxon.Subkingdom &&
                                                  t.Infrakingdom == plantInfo.Taxon.Infrakingdom &&
                                                  t.Phylum == plantInfo.Taxon.Phylum &&
                                                  t.Subphylum == plantInfo.Taxon.Subphylum &&
                                                  t.Class == plantInfo.Taxon.Class &&
                                                  t.Subclass == plantInfo.Taxon.Subclass &&
                                                  t.Superorder == plantInfo.Taxon.Superorder &&
                                                  t.Order == plantInfo.Taxon.Order &&
                                                  t.Family == plantInfo.Taxon.Family &&
                                                  t.Genus == plantInfo.Taxon.Genus &&
                                                  t.Species == plantInfo.Taxon.Species &&
                                                  t.Subspecies == plantInfo.Taxon.Subspecies &&
                                                  t.Variety == plantInfo.Taxon.Variety &&
                                                  t.Subvariety == plantInfo.Taxon.Subvariety &&
                                                  t.Form == plantInfo.Taxon.Form);

                if (taxon == null || taxon.Kingdom != plantInfo.Taxon.Kingdom || taxon.Family != plantInfo.Taxon.Family)
                {
                    taxon = await _taxonService.AddOrUpdateTaxonAsync(plantInfo.Taxon);

                    Taxons.Add(taxon);
                }
                plantInfo.Taxon = taxon;

                // Do we already have the same origin in our insert list?
                var originResult = newOrigins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId &&
                                                             o.ExternalId == plantInfo.Origin.ExternalId &&
                                                             o.AltExternalId == plantInfo.Origin.AltExternalId);
                if (originResult == null)
                {
                    // See if it already exists, if not, add it to the insert list
                    originResult = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId);

                    if (originResult == null)
                    {
                        newOrigins.Add(plantInfo.Origin);
                    }
                    else
                    {
                        Origins.Add(originResult);
                    }
                }
            }

            if (newOrigins.Any())
            {
                newOrigins = (await _originService.AddOriginsAsync(newOrigins)).ToList();
                Origins.AddRange(newOrigins);
            }

            var distinctPlantInfos = plantInfos.DistinctBy(p => new
            {
                p.Taxon.Genus,
                p.Taxon.Species,
                p.Taxon.Subspecies,
                p.Taxon.Variety,
                p.Taxon.Subvariety,
                p.Taxon.Form
            });

            foreach (var plantInfo in distinctPlantInfos)
            {
                var origin = Origins.FirstOrDefault(o => o.ExternalId == plantInfo.Origin.ExternalId &&
                                                    o.AltExternalId == plantInfo.Origin.AltExternalId);
                if (origin == null)
                {
                    origin = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId);
                }

                plantInfo.Origin = origin;

                var plantInfoResult = await _plantInfoService.GetPlantInfoAsync(plantInfo.Origin.OriginId, plantInfo.Taxon.TaxonId);

                if (plantInfoResult == null)
                {
                    newPlantInfos.Add(plantInfo);
                }
            }

            if (newPlantInfos.Any())
            {
                newPlantInfos = (await _plantInfoService.AddPlantInfosAsync(newPlantInfos)).ToList();
            }

            foreach (var newPlantInfo in newPlantInfos)
            {
                var plantInfo = plantInfos.First(p => p.Origin.OriginId == newPlantInfo.Origin.OriginId &&
                                                 p.Taxon.TaxonId == newPlantInfo.Taxon.TaxonId);

                plantInfo.PlantInfoId = newPlantInfo.PlantInfoId;
                newPlantInfo.Taxon    = plantInfo.Taxon;
                newPlantInfo.Origin   = plantInfo.Origin;
                newPlantInfo.Lifeform = plantInfo.Lifeform;
            }

            var plantInfoLocations = plantInfos.Where(p => p.Locations != null && p.Locations.Any())
                                     .SelectMany(p => p.Locations)
                                     .DistinctBy(pl => new { pl.PlantInfo.PlantInfoId, pl.Location.LocationId })
                                     .ToList();

            if (plantInfoLocations.Any() && newPlantInfos.Any())
            {
                var regions   = plantInfos.SelectMany(p => p.Locations).Select(l => l.Location.Region).Distinct();
                var countries = plantInfos.SelectMany(p => p.Locations).Select(l => l.Location.Country).Distinct();
                var locations = (await _locationService.GetLocationsAsync(l => countries.Contains(l.Country) || regions.Contains(l.Region))).ToList();

                var missingLocations = plantInfoLocations.GroupJoin(locations,
                                                                    pl => new { pl.Location.Region, pl.Location.Country },
                                                                    l => new { l.Region, l.Country },
                                                                    (pl, l) => pl.Location)
                                       .DistinctBy(l => new { l.Region, l.Country })
                                       .ToList();

                if (missingLocations.Any())
                {
                    var locationResult = await _locationService.AddLocationsAsync(missingLocations);

                    locations.AddRange(locationResult.ToList());
                }

                var plantLocationsToAdd = new List <PlantLocation>();
                foreach (var plantInfoLocation in plantInfoLocations)
                {
                    var newPlantInfo = newPlantInfos.FirstOrDefault(npl => npl.Origin.OriginId == plantInfoLocation.PlantInfo.Origin.OriginId &&
                                                                    npl.Taxon.TaxonId == plantInfoLocation.PlantInfo.Taxon.TaxonId);
                    if (newPlantInfo != null)
                    {
                        var location = locations.First(l => l.Country == plantInfoLocation.Location.Country &&
                                                       l.Region == plantInfoLocation.Location.Region);
                        plantLocationsToAdd.Add(new PlantLocation
                        {
                            PlantInfo = newPlantInfo,
                            Location  = location,
                            Status    = plantInfoLocation.Status
                        });
                    }
                }

                if (plantInfoLocations.Any())
                {
                    var plantLocationsResult = (await _plantInfoService.AddPlantLocations(plantLocationsToAdd)).ToList();

                    foreach (var newPlantInfo in newPlantInfos)
                    {
                        var newPlantInfoLocations = plantLocationsResult.Where(pl => pl.PlantInfo.PlantInfoId == newPlantInfo.PlantInfoId);
                        newPlantInfo.Locations = newPlantInfoLocations.Any() ? newPlantInfoLocations : null;
                    }
                }
            }

            return(newPlantInfos);
        }
示例#9
0
 // Spawn lifeforms
 public void SpawnLifeforms()
 {
     Lifeforms.ResetAllLife();
     Lifeforms.SpawnLifeforms();
 }