Example #1
0
    public override void UpdateBehaviour(EnergyRegulator energyRegulator, float deltaTime)
    {
        if (energyRegulator.IsDepletedUnrecoverable())
        {
            if (IsLastBranch())
            {
                Kill();
            }
            else
            {
                // Don't kill but stop growing and stop all energy transfert
                // the consequence is that the child branch will die which seems good in this case
            }
        }
        else
        {
            // Branch consume additional energy based on their size
            //energyRegulator.ConsumeEnergy(deltaTime * CurrentSize * 0.2f * CountAllChildren(true)/* _sizeConsumptionFactor*/);

            if (CanCreateNewLeaf(energyRegulator))
            {
                Owner.AddNewLeaf(this, _nextLeafSpawn);
                energyRegulator.ConsumeEnergy(_energyNeededToCreateLeaf);
                _nextLeafSpawn = Random.Range(_leafSpawnPercentMin, _leafSpawnPercentMax);
            }

            // TODO make a component to manage Growable creation
            if (CanCreateNewBud(energyRegulator))
            {
                Owner.AddNewBud(this, _nextBudSpawn);
                energyRegulator.ConsumeEnergy(_energyNeededToCreateBud);
                _nextBudSpawn = Random.Range(_budSpawnPercentMin, _budSpawnPercentMax);
            }
        }
    }
Example #2
0
    public static bool TransfertEnergy(EnergyRegulator regulatorSource, EnergyRegulator regulatorDestination, float amount)
    {
        bool isTransfertDone = false;

        if (regulatorSource.HasEnergy(amount))
        {
            regulatorSource.ConsumeEnergy(amount);
            regulatorDestination.GainEnergy(amount);
            isTransfertDone = true;
        }

        return(isTransfertDone);
    }
Example #3
0
    public override void UpdateBehaviour(EnergyRegulator energyRegulator, float deltaTime)
    {
        if (energyRegulator.IsDepletedUnrecoverable())
        {
            Kill();
        }
        else
        {
            // Bud get energy from his parent branch
            EnergyRegulator.TransfertEnergy(Parent.EnergyRegulator, energyRegulator, deltaTime * _energyTransfertPerSecond);

            if (CanCreateNewBranch(energyRegulator))
            {
                Owner.AddNewBranch(Parent, RelativePercentPosition);
                energyRegulator.ConsumeEnergy(_energyNeededToCreateBranch);
                Kill();
            }
        }
    }
Example #4
0
    // Params, they must be configurable

    public AGrowable(Tree owner, GameObject gameObject, GrowableType type, Vector3 scale, float maxSize, float relativePercentPosition, EnergyRegulator.EnergyData energyData)
    {
        Owner      = owner;
        GameObject = gameObject;
        Type       = type;
        Scale      = scale;
        RelativePercentPosition = relativePercentPosition;
        EnergyRegulator         = new EnergyRegulator(energyData);

        // Initialiaze the children container
        Children = new Dictionary <GrowableType, List <AGrowable> >();
        foreach (GrowableType growableType in (GrowableType[])Enum.GetValues(typeof(GrowableType)))
        {
            Children[growableType] = new List <AGrowable>();
        }
        Depth       = 0;
        CurrentSize = 0;
        MaxSize     = maxSize;
        Parent      = null;
    }
Example #5
0
 public override void UpdateBehaviour(EnergyRegulator energyRegulator, float deltaTime)
 {
     if (energyRegulator.IsDepletedUnrecoverable())
     {
         Kill();
     }
     else if (!ShouldDie())
     {
         // Accumulate energy from the sun
         if (EnvironmentHelper.Instance.IsEnlightened(this))
         {
             AGrowable growable = Parent;
             while (growable != null)
             {
                 // Energy is distributed to all parent equally
                 // TODO gain energy only if all parent are not depletedUnrecoverable
                 float energyGain = (_energyGainPerSecond * deltaTime) / Depth;
                 growable.EnergyRegulator.GainEnergy(energyGain);
                 growable = growable.Parent;
             }
         }
     }
 }
Example #6
0
 bool CanCreateNewBranch(EnergyRegulator energyRegulator)
 {
     return(energyRegulator.HasEnergy(_energyNeededToCreateBranch) && !ShouldDie());
 }
Example #7
0
 bool CanCreateNewLeaf(EnergyRegulator energyRegulator)
 {
     return(energyRegulator.HasEnergy(_energyNeededToCreateLeaf) && CountChildren(GrowableType.Leaf) < _maxLeafs);
 }
Example #8
0
 bool CanCreateNewBud(EnergyRegulator energyRegulator)
 {
     return(CountChildren(GrowableType.Leaf) >= 1 && // Make sure to have at least one leaf otherwise there is no way to gain more energy
            energyRegulator.HasEnergy(_energyNeededToCreateBud) &&
            (CountChildren(GrowableType.Bud) + CountChildren(GrowableType.Branch)) < _maxBuds);
 }
Example #9
0
 public string DebugString()
 {
     return(EnergyRegulator.DebugString() + " | size " + CurrentSize + " / " + MaxSize);
 }
Example #10
0
 public abstract void UpdateBehaviour(EnergyRegulator energyRegulator, float deltaTime);
Example #11
0
 void UpdateEnergy(float deltaTime)
 {
     EnergyRegulator.Update(deltaTime);
 }