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);
        }
    }
示例#2
0
    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;
            }
        }
    }