Contains the information needed to intialize a new organism within the Terrarium.
コード例 #1
0
ファイル: GameEngine.cs プロジェクト: Carolasb/Terrarium
        /// <summary>
        ///  Add a new organism given the species of the creature, and the
        ///  preferred location of insertion.
        /// </summary>
        /// <param name="species">The species for the new organism.</param>
        /// <param name="preferredLocation">The preferred insertion point.</param>
        public void AddNewOrganism(Species species, Point preferredLocation)
        {
            NewOrganism newOrganism;
            if (preferredLocation == Point.Empty)
            {
                newOrganism = new NewOrganism(species.InitializeNewState(new Point(0, 0), 0), null);
            }
            else
            {
                newOrganism = new NewOrganism(species.InitializeNewState(preferredLocation, 0), null);
                newOrganism.AddAtRandomLocation = false;
            }

            _newOrganismQueue.Enqueue(newOrganism);
        }
コード例 #2
0
ファイル: GameEngine.cs プロジェクト: Carolasb/Terrarium
        private void incubate()
        {
            foreach (string organismID in _organismIDList)
            {
                OrganismState organismState = _newWorldState.GetOrganismState(organismID);
                if (organismState == null || !organismState.IsAlive || !organismState.IsIncubating) continue;
                if (organismState.IncubationTicks == EngineSettings.TicksToIncubate)
                {
                    Point newPosition = findEmptyPosition(organismState.CellRadius, Point.Empty);
                    if (newPosition != Point.Empty)
                    {
                        // Only birth an organism if there is space
                        NewOrganism newOrganism = new NewOrganism(
                            ((Species) organismState.Species).InitializeNewState(newPosition,
                                                                                 organismState.Generation + 1),
                            (organismState.CurrentReproduceAction.Dna == null)
                                ? (new byte[0])
                                : ((byte[]) organismState.CurrentReproduceAction.Dna.Clone()));
                        _newOrganismQueue.Enqueue(newOrganism);
                    }
                    else
                    {
                        // Kill the organism since there is no place to put it
                        OnEngineStateChanged(new EngineStateChangedEventArgs(EngineStateChangeType.Other,
                                                                             "A '" +
                                                                             ((Species) organismState.Species).Name +
                                                                             "' died during birth: couldn't find an open spot quickly enough."));
                    }

                    organismState.OrganismEvents.ReproduceCompleted =
                        new ReproduceCompletedEventArgs(organismState.CurrentReproduceAction.ActionID,
                                                        organismState.CurrentReproduceAction);
                    organismState.ResetReproductionWait();
                    organismState.CurrentReproduceAction = null;
                }
                else
                {
                    // Only incubate if the organism isn't hungry
                    if (organismState.EnergyState >= EnergyState.Normal)
                    {
                        if (organismState is AnimalState)
                        {
                            organismState.BurnEnergy(organismState.Radius*
                                                     EngineSettings.AnimalIncubationEnergyPerUnitOfRadius);
                        }
                        else
                        {
                            Debug.Assert(organismState is PlantState);
                            organismState.BurnEnergy(organismState.Radius*
                                                     EngineSettings.PlantIncubationEnergyPerUnitOfRadius);
                        }

                        organismState.AddIncubationTick();
                    }
                }
            }
        }