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); } } }
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); }
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(); } } }
// 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; }
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; } } } }
bool CanCreateNewBranch(EnergyRegulator energyRegulator) { return(energyRegulator.HasEnergy(_energyNeededToCreateBranch) && !ShouldDie()); }
bool CanCreateNewLeaf(EnergyRegulator energyRegulator) { return(energyRegulator.HasEnergy(_energyNeededToCreateLeaf) && CountChildren(GrowableType.Leaf) < _maxLeafs); }
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); }
public string DebugString() { return(EnergyRegulator.DebugString() + " | size " + CurrentSize + " / " + MaxSize); }
public abstract void UpdateBehaviour(EnergyRegulator energyRegulator, float deltaTime);
void UpdateEnergy(float deltaTime) { EnergyRegulator.Update(deltaTime); }