public static void ShiftCells(Vector3 startingPoint, Vector3 direction, Organism organism) { Vector3 currentPos = startingPoint; CellAttributes currentCell = organism.cells.RemoveCell(currentPos); while (currentCell != null) { Vector3 shiftedPosition = currentPos + direction; currentCell.relativePosition = shiftedPosition; if (currentCell.instance != null) { var newPositionAndRotation = CellsCreator.RealPositionAndRotation(currentCell, organism.transform); currentCell.instance.transform.position = newPositionAndRotation.Key; currentCell.instance.transform.rotation = newPositionAndRotation.Value; } CellAttributes nextCell = organism.cells.RemoveCell(shiftedPosition); currentPos = shiftedPosition; organism.cells.AddCell(currentCell); currentCell = nextCell; } }
public static void GrowCell(CellAttributes cellToGrow, Organism organism) { organism.cells.AddCell(cellToGrow); CellsCreator.InstantiateCell(cellToGrow, organism.transform); organism.orderOfGrowth.RemoveFirst(); SubtractEnergyForGrowth(cellToGrow.type.GetComponent <Cell>().bodyEnergy, organism.organismEnergy); organism.SetTotalEnergyStorage(); int freeEnergyStorage = organism.organismEnergy.TotalEnergyStorage - organism.organismEnergy.Value; if (organism.organismEnergy.EggEnergy > freeEnergyStorage) { organism.organismEnergy.Value += freeEnergyStorage; organism.organismEnergy.EggEnergy -= freeEnergyStorage; } else { organism.organismEnergy.Value += organism.organismEnergy.EggEnergy; organism.organismEnergy.EggEnergy = 0; } }
void Start() { startingAge = Map.minutes; _tracker = chromosome.MutationTracker; _viewChromosome = chromosome.ToString(); cells = new CellsStructure(); bodyEnergy = OrganismSetter.BodyEnergy(chromosome); orderOfGrowth = CellsCreator.GetOrderOfGrowth(this); OrganismSetter.SetNeuralNetwork(this); OrganismSetter.SetDrag(this); OrganismSetter.SetName(this); OrganismCellsGrowth.GrowCell(this, false); if (fullyGrow) { OrganismCellsGrowth.FullyGrow(this); } InvokeRepeating("Routine", 2f, 5f); InvokeRepeating("Think", 2f, SimulationParameters.brainTick); InvokeRepeating("Physics", 2f, SimulationParameters.physics); }
public static void GrowCell(Organism organism, bool killDetached) { if (!organism.orderOfGrowth.Any()) { return; } KeyValuePair <CellAttributes, CellAttributes> pair = organism.orderOfGrowth.First.Value; CellAttributes startingCell = pair.Key; CellAttributes cellToGrow = pair.Value; int cellEnergy = cellToGrow.type.GetComponent <Cell>().bodyEnergy; if (organism.organismEnergy.EggEnergy + organism.organismEnergy.Value - cellEnergy < organism.bodyEnergy * organism.chromosome.Parameters.MinimumEnergyToGrow) { return;//no energy for growth } if (startingCell == null) {//first cell if (CellsCreator.CanInstantiate(cellToGrow, organism.transform)) { GrowCell(cellToGrow, organism); } } else { if (startingCell.alive) { Vector3 direction = cellToGrow.relativePosition; cellToGrow.relativePosition += startingCell.relativePosition; if (!CellsCreator.CanInstantiate(cellToGrow, organism.transform)) { cellToGrow.relativePosition = direction; return; } ShiftCells(cellToGrow.relativePosition, direction, organism); GrowCell(cellToGrow, organism); } } if (killDetached) { OrganismHealthCheck.KillDeatachedCells(organism.cells); } }
private bool CellHasLivingNeighbour(CellAttributes cell) { Vector3[] vectors = Cell.vectors; for (int i = 0; i < vectors.Length; i++) { if (CellsCreator.AllowGrowthInDirection(cell, vectors[i])) { CellAttributes c = cells.GetCell(cell.relativePosition + vectors[i]); if (c != null && c.alive && CellsCreator.AllowGrowthInDirection(c, -vectors[i])) { return(true); } } } return(false); }
private void Heal() { int healProb = 10;//inverse heal probability for each dead cell next to living cell foreach (CellAttributes cell in cells) { if ((!cell.alive) && GenesManager.r.Next(healProb * cell.type.GetComponent <Cell>().bodyEnergy) < organismEnergy.Value && CellHasLivingNeighbour(cell) && organismEnergy.Value > cell.type.GetComponent <Cell>().bodyEnergy&& CellsCreator.CanInstantiate(cell, transform)) { organismEnergy.Value -= cell.type.GetComponent <Cell>().bodyEnergy; organismEnergy.SetTotalEnergyStorage(organismEnergy.GetTotalEnergyStorage() + cell.type.GetComponent <Cell>().energyStorage); cell.alive = true; CellsCreator.InstantiateCell(cell, transform); cells.deadCells--; return; } } }
private static bool CellLink(CellAttributes currentCell, Vector3 direction) { return(CellsCreator.AllowGrowthInDirection(currentCell, direction)); }