Exemplo n.º 1
0
 /// <summary>
 ///  Method used to add an organism to the organism removal queue.
 /// </summary>
 /// <param name="killedOrganism">The organism to remove.</param>
 public void RemoveOrganismQueued(KilledOrganism killedOrganism)
 {
     // Queue it up to be removed at the proper point
     _removeOrganismQueue.Enqueue(killedOrganism);
 }
Exemplo n.º 2
0
        /// <summary>
        ///  Method used to remove an organism given a KilledOrganism object.
        ///  This method instantly removes the organism and so should not
        ///  be called by normal code, rather call RemoveOrganismQueued.
        /// </summary>
        /// <param name="killedOrganism">The organism to be removed.</param>
        private void removeOrganism(KilledOrganism killedOrganism)
        {
            OrganismState killedState = _newWorldState.GetOrganismState(killedOrganism.ID);

            if (killedOrganism.DeathReason == PopulationChangeReason.Error ||
                killedOrganism.DeathReason == PopulationChangeReason.Timeout ||
                killedOrganism.DeathReason == PopulationChangeReason.SecurityViolation ||
                killedOrganism.DeathReason == PopulationChangeReason.OrganismBlacklisted)
            {
                OnEngineStateChanged(EngineStateChangedEventArgs.AnimalDestroyed(killedState, killedOrganism.DeathReason));
            }

            // Tell the developer the details
            if (killedOrganism.DeathReason == PopulationChangeReason.Error ||
                killedOrganism.DeathReason == PopulationChangeReason.SecurityViolation)
            {
                if (!string.IsNullOrEmpty(killedOrganism.ExtraInformation))
                {
                    string developerMessage = "**** An exception occurred in a '" + ((Species) killedState.Species).Name +
                                              "': \r\n" + killedOrganism.ExtraInformation;
                    OnEngineStateChanged(new EngineStateChangedEventArgs(EngineStateChangeType.DeveloperInformation,
                                                                         developerMessage));
                }
            }

            if (killedOrganism.DeathReason == PopulationChangeReason.Error &&
                string.IsNullOrEmpty(killedOrganism.ExtraInformation))
            {
                OrganismState state = _newWorldState.GetOrganismState(killedOrganism.ID);
                state.Kill(killedOrganism.DeathReason);
            }
            else
            {
                uncountOrganism(killedState, killedOrganism.DeathReason);

                // Remove it from the Host
                Scheduler.Remove(killedOrganism.ID);

                // Remove it from the world state
                _newWorldState.RemoveOrganism(killedOrganism.ID);
            }
        }