コード例 #1
0
    public HabitatSpecies AddSpecies(String speciesName)
    {
        HabitatSpecies newSpecies = new HabitatSpecies(speciesName, 0, 1, 0, false);

        speciesList.Add(newSpecies);
        return(newSpecies);
    }
コード例 #2
0
 public SpeciesAction(String name, string actionRequirements, string actionOutput, HabitatSpecies parentSpecies, Storage storage,
                      Func <Double, Double> timeTaken, double countOfSpeciesRemovedOnSuccess, String outputName, double countOfStorageItemProducedPerSpeciesRemoved,
                      Func <bool> requirementsPassed)
     : base(name, actionRequirements, actionOutput)
 {
     this.parentSpecies = parentSpecies;
     this.storage       = storage;
     this.timeTakenFunc = timeTaken;
     this.countOfSpeciesRemovedOnSuccess = countOfSpeciesRemovedOnSuccess;
     this.outputName = outputName;
     this.countOfStorageItemProducedPerSpeciesRemoved = countOfStorageItemProducedPerSpeciesRemoved;
     this.requirementsPassed = requirementsPassed;
 }
コード例 #3
0
    override public void Awake()
    {
        base.Awake();
        //finding the UI text to display the counts
        speciesCountTextObject = GameObject.Find(this.name + "/Canvas/SpeciesCount");

        //getting the tree views to update
        //TODO will need to change this in the future
        closeTrees = GameObject.Find(this.name + "/Grid/CloseTrees");
        midTrees   = GameObject.Find(this.name + "/Grid/MidTrees");
        farTrees   = GameObject.Find(this.name + "/Grid/FarTrees");

        //Creating the species in the habitat
        //totalLandCount = initialLandCount;
        trees   = new HabitatSpecies("Trees", InitialTreeCount, 0.99, 0.02, false);
        animals = new HabitatSpecies("Animals", InitialAnimalCount, 1, 0.05, true);
        HabitatSpecies berryBush = new HabitatSpecies("Berry Bushes", InitialBerryBushCount, 0.9, 0.03, false);

        berries = new HabitatSpecies("Berries", InitialBerryBushCount * 100, .95, 0.0, false);
        HabitatSpecies bugs = new HabitatSpecies("Bugs", InitialBugCount, 1.3, 0.06, true);

        //creating the relationships withing the habitat
        trees.SetLandCompetition(0.08);
        animals.AddFoodSource(bugs, 0.0, 50.0, 1.1);
        animals.AddHabitat(trees, 0.0, 1.0 / 3.0, 1.05);
        berryBush.SetLandCompetition(0.2);
        berries.AddPredator(bugs, 1.0, 1.0, 0);
        berries.AddProducer(berryBush, 20.0, 200.0, 0.0);
        bugs.AddPredator(animals, 1.0, 1.0 / 40.0, 0.0);
        bugs.AddFoodSource(berries, 0.25, 1.0, 3);

        //adding the species to the species list
        //species = new List<HabitatSpecies>();
        base.speciesList.Add(berries);
        base.speciesList.Add(trees);
        base.speciesList.Add(animals);
        base.speciesList.Add(berryBush);

        base.speciesList.Add(bugs);
    }
コード例 #4
0
    void FixedUpdate()
    {
        //Checks if day has passed, if so, update populations in all habitats
        timeSinceLastPopulationUpdate++;
        if (timeSinceLastPopulationUpdate * Time.fixedDeltaTime > DAY_LENGTH_IN_SECONDS)
        {
            UpdateAllPopulations();
            timeSinceLastPopulationUpdate = 0;

            //as the day ends all jobs are cancelled
            numberOfWorkers += taskQueue.Count;
            foreach (TaskItem task in taskQueue)
            {
                task.task.CancelTask();
            }
            taskQueue.Clear();

            HabitatSpecies food = storage.GetSpecies("Food");
            if (food == null || food.count <= 0)
            {
                //if no food, 40% of workers die
                numberOfWorkers = (int)(0.6 * numberOfWorkers);
            }
            else
            {
                //every worker eats 3 food at the end of the day
                food.count = food.count - numberOfWorkers * 3;
                if (food.count <= 0)
                {
                    //if this takes us below 0, find the number that were fed, and the rest die at a rate of 40%
                    int workersUnfed = numberOfWorkers - (int)(food.count / 3);
                    numberOfWorkers -= (int)(0.6 * numberOfWorkers);
                }
            }
        }
    }
コード例 #5
0
    public void Migrate(Habitat habitatA, Habitat habitatB)
    {
        //if either are null, return
        if (habitatA == null || habitatB == null)
        {
            return;
        }
        bool aHabitable = true;
        bool bHabitable = true;

        //check whether A and B have the necessary species within them to be habitable
        foreach (HabitatSpecies species in necessarryMigrationSpecies)
        {
            if (!habitatA.HasSpecies(species.name) || habitatA.GetSpecies(species.name).count <= 0)
            {
                aHabitable = false;
            }
            if (!habitatB.HasSpecies(species.name) || habitatB.GetSpecies(species.name).count <= 0)
            {
                bHabitable = false;
            }
        }
        //if one or the either or both is not habitable, no migration
        if (!(aHabitable && bHabitable))
        {
            return;
        }
        //if there are no population in either, there is no migration
        HabitatSpecies speciesInA = habitatA.GetSpecies(name);
        HabitatSpecies speciesInB = habitatB.GetSpecies(name);

        if ((speciesInA == null || speciesInA.count <= 0) && (speciesInB == null || speciesInB.count <= 0))
        {
            return;
        }
        //if one is still null, and the other has a count, instantiate it
        if (speciesInA == null)
        {
            speciesInA = habitatA.AddSpecies(name);
        }
        if (speciesInB == null)
        {
            speciesInB = habitatB.AddSpecies(name);
        }
        //determine direction of movement
        bool moveToB = speciesInA.count > speciesInB.count;
        //get the difference between the count of the species in each habitat
        double difference = Math.Abs(speciesInA.count - speciesInB.count);
        //move species to the lesser habitat by the difference * migration factor
        double amountMigrating = difference * migrationRate;

        if (moveToB)
        {
            speciesInB.count = speciesInB.count + amountMigrating;
        }
        else
        {
            speciesInA.count = speciesInA.count + amountMigrating;
        }
        //if the species is migratory, remove that amount from the larger land
        //it the species spreads seeds, don't change the amount from larger
        if (migratorySpecies)
        {
            if (moveToB)
            {
                speciesInA.count = speciesInA.count - amountMigrating;
            }
            else
            {
                speciesInB.count = speciesInB.count - amountMigrating;
            }
        }
    }
コード例 #6
0
 public void AddProducer(HabitatSpecies producer, double valueAt0, double valueWhen1, double asymptote)
 {
     producerRates.Add(NewFruitPerBush(valueAt0, valueWhen1, asymptote));
     producers.Add(producer);
 }
コード例 #7
0
 //allow for multiple habitats, where it will continue to survive if one dries out
 public void AddHabitat(HabitatSpecies species, double valueAt0, double valueWhen1, double asymptote)
 {
     growthFuncs.Add(HabitatGrowthFunction(valueAt0, valueWhen1, asymptote));
     dependantSpecies.Add(species);
     necessarryMigrationSpecies.Add(species);
 }
コード例 #8
0
 public void AddPredator(HabitatSpecies species, double valueAt0, double valueWhenHalf, double asymptote)
 {
     growthFuncs.Add(PredatorGrowthFunction(valueAt0, valueWhenHalf, asymptote));
     dependantSpecies.Add(species);
 }