Beispiel #1
0
 PlantScript.GrowthStage GetSeedGerminationResults(PlantScript.PlantData plant)
 {
     if (plant.age > seedGerminationRequirement.timeMaximum)
     {
         return(PlantScript.GrowthStage.Dead);
     }
     if (plant.age > seedGerminationRequirement.timeRequirement && earthState.humidity > seedGerminationRequirement.humidityRequirement && earthState.temperature > seedGerminationRequirement.tempetureRequirement)
     {
         return(PlantScript.GrowthStage.Germinating);
     }
     return(PlantScript.GrowthStage.Seed);
 }
Beispiel #2
0
    float GetWaterGain(PlantScript.PlantData plant)
    {
        float rootArea           = (math.PI * plant.rootGrowth.x * plant.rootGrowth.y) + (math.pow(plant.rootGrowth.x / 2, 2) * 2);
        float overLapingRootArea = 0f;

        if (plantsInZones.TryGetFirstValue(plant.zone, out int targetPlant, out var iterator))
        {
            do
            {
                float distance     = GetDistanceToPlant(plant, allPlants[targetPlant]);
                float rootDistance = GetRootSize(plant) + GetRootSize(allPlants[targetPlant]);
                if (distance < rootDistance)
                {
                    float reletiveDepth    = (plant.rootGrowth.y - allPlants[targetPlant].rootGrowth.y) / plant.rootGrowth.y;
                    float reletiveDistance = rootDistance - distance;
                    overLapingRootArea += (reletiveDistance / 2) / (1 + reletiveDepth);
                }
            } while (plantsInZones.TryGetNextValue(out targetPlant, ref iterator));
        }
        int zoneNumber;

        if (neiboringZones.TryGetFirstValue(plant.zone, out zoneNumber, out var iterator2))
        {
            do
            {
                if (plantsInZones.TryGetFirstValue(zoneNumber, out targetPlant, out var iterator3))
                {
                    do
                    {
                        float distance     = GetDistanceToPlant(plant, allPlants[targetPlant]);
                        float rootDistance = GetRootSize(plant) + GetRootSize(allPlants[targetPlant]);
                        if (distance < rootDistance)
                        {
                            float reletiveDepth    = (plant.rootGrowth.y - allPlants[targetPlant].rootGrowth.y) / plant.rootGrowth.y;
                            float reletiveDistance = rootDistance - distance;
                            overLapingRootArea += (reletiveDistance / 2) / (1 + reletiveDepth);
                        }
                    } while (plantsInZones.TryGetNextValue(out targetPlant, ref iterator3));
                }
            } while (neiboringZones.TryGetNextValue(out zoneNumber, ref iterator2));
        }

        rootArea = rootArea - overLapingRootArea;
        float rootUnderWaterPercent = 1 - (zones[plant.zone].waterDepth / plant.rootGrowth.y);

        if (rootUnderWaterPercent < 0)
        {
            return(0);
        }
        return(rootUnderWaterPercent * rootArea * plant.rootDensity * .01f);
    }
Beispiel #3
0
    PlantScript.GrowthStage GetGrowthStage(PlantScript.PlantData plant)
    {
        int stageIndex = (int)plant.stage;

        if (stageIndex == growthStages.Length - 1)
        {
            return(plant.stage);
        }
        if (plant.bladeArea >= growthStages[stageIndex].bladeArea && plant.stemHeight >= growthStages[stageIndex].stemHeight && plant.rootGrowth.y >= growthStages[stageIndex].rootDepth)
        {
            return(growthStages[stageIndex + 1].stage);
        }
        return(plant.stage);
    }
Beispiel #4
0
 public void Execute(int plantIndex)
 {
     PlantScript.PlantData plant = allPlants[updatePlants[plantIndex]];
     if (plant.stage == PlantScript.GrowthStage.Dead)
     {
         return;
     }
     if (plant.zone == -1)
     {
         Debug.LogError("The zone of this plant should not be " + plant.zone + ". Curent growth stage is " + plant.stage);
         return;
     }
     if (plant.stage == PlantScript.GrowthStage.Seed)
     {
         plantGrowthStage[plantIndex] = GetSeedGerminationResults(plant);
         return;
     }
     plantReasourceGain[plantIndex] = new float2(GetSunGain(plant), GetWaterGain(plant));
     plantGrowthStage[plantIndex]   = GetGrowthStage(plant);
 }
Beispiel #5
0
 float GetSunGain(PlantScript.PlantData plant)
 {
     return(plant.bladeArea * GetSunValue(plant.position) / 2);
 }
Beispiel #6
0
 float GetRootSize(PlantScript.PlantData plant)
 {
     return(plant.rootGrowth.x);
 }
Beispiel #7
0
 float GetDistanceToPlant(PlantScript.PlantData from, PlantScript.PlantData to)
 {
     return(math.distance(from.position, to.position));
 }