/// <summary>
        ///  Creates a new event relating to a creature being destroyed.
        /// </summary>
        /// <param name="organismState">The creature being destroyed.</param>
        /// <param name="reason">The reason the creature is being destroyed.</param>
        /// <returns>State change initialized for a creature being destroyed with messages.</returns>
        public static EngineStateChangedEventArgs AnimalDestroyed(OrganismState organismState,
                                                                  PopulationChangeReason reason)
        {
            var reasonDescription = "";

            switch (reason)
            {
                case PopulationChangeReason.Timeout:
                    reasonDescription = "thought for too long";
                    break;

                case PopulationChangeReason.Error:
                    reasonDescription = "had an error";
                    break;

                case PopulationChangeReason.SecurityViolation:
                    reasonDescription = "attempted to violate security";
                    break;

                case PopulationChangeReason.OrganismBlacklisted:
                    reasonDescription = "is blacklisted due to past bad behavior and won't be loaded";
                    break;
            }

            return new EngineStateChangedEventArgs(
                EngineStateChangeType.Other,
                string.Format("A {0} was destroyed because it {1}.", ((Species) organismState.Species).Name,
                              reasonDescription),
                string.Format("A {0} was destroyed because it {1}.", ((Species) organismState.Species).Name,
                              reasonDescription)
                );
        }
Exemple #2
0
        /// <summary>
        ///  Creates a new event relating to a creature being destroyed.
        /// </summary>
        /// <param name="organismState">The creature being destroyed.</param>
        /// <param name="reason">The reason the creature is being destroyed.</param>
        /// <returns>State change initialized for a creature being destroyed with messages.</returns>
        public static EngineStateChangedEventArgs AnimalDestroyed(OrganismState organismState,
                                                                  PopulationChangeReason reason)
        {
            var reasonDescription = "";

            switch (reason)
            {
            case PopulationChangeReason.Timeout:
                reasonDescription = "thought for too long";
                break;

            case PopulationChangeReason.Error:
                reasonDescription = "had an error";
                break;

            case PopulationChangeReason.SecurityViolation:
                reasonDescription = "attempted to violate security";
                break;

            case PopulationChangeReason.OrganismBlacklisted:
                reasonDescription = "is blacklisted due to past bad behavior and won't be loaded";
                break;
            }

            return(new EngineStateChangedEventArgs(
                       EngineStateChangeType.Other,
                       string.Format("A {0} was destroyed because it {1}.", ((Species)organismState.Species).Name,
                                     reasonDescription),
                       string.Format("A {0} was destroyed because it {1}.", ((Species)organismState.Species).Name,
                                     reasonDescription)
                       ));
        }
Exemple #3
0
        /// <summary>
        ///  Counts a new organism and adds it to the current dataset.
        /// </summary>
        /// <param name="speciesName">The name of the species being added.</param>
        /// <param name="reason">The reason for being added.</param>
        /// <param name="count">The number to add.</param>
        public void CountOrganism(string speciesName, PopulationChangeReason reason, int count)
        {
            var row = _populationChangeTable.Rows.Find(new Object[] { _currentTick, speciesName, reason });

            if (row == null)
            {
                var totalsRow = _totalsTable.Rows.Find(new Object[] { speciesName });
                if (totalsRow == null)
                {
                    totalsRow            = _totalsTable.NewRow();
                    totalsRow["Species"] = speciesName;
                    _totalsTable.Rows.Add(totalsRow);
                }

                row = _populationChangeTable.NewRow();
                row["TickNumber"] = _currentTick;
                row["Species"]    = speciesName;
                row["Delta"]      = count;
                row["Reason"]     = reason;
                _populationChangeTable.Rows.Add(row);
            }
            else
            {
                row["Delta"] = (int)row["Delta"] + count;
            }
        }
Exemple #4
0
        /// <summary>
        ///  Called by the game engine in order to kill the current creature.
        ///  Since this method can only be called when the state is mutable
        ///  player's can't use the method to arbitrarily kill competing
        ///  organisms.
        /// </summary>
        /// <internal/>
        public void Kill(PopulationChangeReason reason)
        {
            if (IsImmutable)
            {
                throw new GameEngineException("Object is immutable.");
            }

            _currentMoveToAction = null;
            _energy     = 0;
            DeathReason = reason;
        }
Exemple #5
0
        /// <summary>
        ///  Counts a new organism and removes it from the reporting data.
        /// </summary>
        /// <param name="speciesName">The name of the species the data is for.</param>
        /// <param name="reason">The reason for removing.</param>
        /// <param name="count">The number to remove.</param>
        public void UncountOrganism(string speciesName, PopulationChangeReason reason, int count)
        {
            var row = _populationChangeTable.Rows.Find(new Object[] { _currentTick, speciesName, reason });

            if (row == null)
            {
                var totalsRow = _totalsTable.Rows.Find(new Object[] { speciesName });

                // There should always be a totals row if we are decrementing population since
                // it stores the current population
                Debug.Assert(totalsRow != null);

                row = _populationChangeTable.NewRow();
                row["TickNumber"] = _currentTick;
                row["Species"]    = speciesName;
                row["Delta"]      = -count;
                row["Reason"]     = reason;
                _populationChangeTable.Rows.Add(row);
            }
            else
            {
                row["Delta"] = (int)row["Delta"] - count;
            }
        }
Exemple #6
0
        /// <summary>
        ///  Subtracts an organism from the count of organisms.  Depending on the 
        ///  organism type either plants or animals will be decremented.
        /// </summary>
        /// <param name="state">The state of the creature.</param>
        /// <param name="reason">The reason the creature is being removed.</param>
        private void uncountOrganism(OrganismState state, PopulationChangeReason reason)
        {
            Debug.Assert(state != null);

            _populationData.UncountOrganism(((Species) state.Species).Name, reason);
            if (state is AnimalState)
            {
                _animalCount--;
            }
            else
            {
                _plantCount--;
            }
        }
 /// <summary>
 ///  Creates a new KilledOrganism based on information in an OrganismState.
 /// </summary>
 /// <param name="state">The state object that ID and death reason will be pulled from.</param>
 public KilledOrganism(OrganismState state)
 {
     this.id = state.ID;
     this.deathReason = state.DeathReason;
 }
 /// <summary>
 ///  Creates a new KilledOrganism based on ID and reason for death.
 /// </summary>
 /// <param name="id">The Unique ID of the organism.</param>
 /// <param name="reason">The reason the organism was killed.</param>
 public KilledOrganism(string id, PopulationChangeReason reason)
 {
     this.id = id;
     this.deathReason = reason;
 }
Exemple #9
0
 /// <summary>
 ///  Counts a new organism and removes it from the data.
 /// </summary>
 /// <param name="speciesName">The name of the species the data is for.</param>
 /// <param name="reason">The reason the creature is being removed.</param>
 public void UncountOrganism(string speciesName, PopulationChangeReason reason)
 {
     UncountOrganism(speciesName, reason, 1);
 }
Exemple #10
0
 /// <summary>
 ///  Counts a new organism and removes it from the data.
 /// </summary>
 /// <param name="speciesName">The name of the species the data is for.</param>
 /// <param name="reason">The reason the creature is being removed.</param>
 public void UncountOrganism(string speciesName, PopulationChangeReason reason)
 {
     UncountOrganism(speciesName, reason, 1);
 }
Exemple #11
0
 /// <summary>
 ///  Creates a new KilledOrganism based on ID and reason for death.
 /// </summary>
 /// <param name="id">The Unique ID of the organism.</param>
 /// <param name="reason">The reason the organism was killed.</param>
 public KilledOrganism(string id, PopulationChangeReason reason)
 {
     ExtraInformation = "";
     ID = id;
     DeathReason = reason;
 }
Exemple #12
0
        /// <summary>
        ///  Counts a new organism and removes it from the reporting data.
        /// </summary>
        /// <param name="speciesName">The name of the species the data is for.</param>
        /// <param name="reason">The reason for removing.</param>
        /// <param name="count">The number to remove.</param>
        public void UncountOrganism(string speciesName, PopulationChangeReason reason, int count)
        {
            var row = _populationChangeTable.Rows.Find(new Object[] {_currentTick, speciesName, reason});
            if (row == null)
            {
                var totalsRow = _totalsTable.Rows.Find(new Object[] {speciesName});

                // There should always be a totals row if we are decrementing population since
                // it stores the current population
                Debug.Assert(totalsRow != null);

                row = _populationChangeTable.NewRow();
                row["TickNumber"] = _currentTick;
                row["Species"] = speciesName;
                row["Delta"] = -count;
                row["Reason"] = reason;
                _populationChangeTable.Rows.Add(row);
            }
            else
            {
                row["Delta"] = (int) row["Delta"] - count;
            }
        }
Exemple #13
0
        /// <summary>
        ///  Counts a new organism and adds it to the current dataset.
        /// </summary>
        /// <param name="speciesName">The name of the species being added.</param>
        /// <param name="reason">The reason for being added.</param>
        /// <param name="count">The number to add.</param>
        public void CountOrganism(string speciesName, PopulationChangeReason reason, int count)
        {
            var row = _populationChangeTable.Rows.Find(new Object[] {_currentTick, speciesName, reason});
            if (row == null)
            {
                var totalsRow = _totalsTable.Rows.Find(new Object[] {speciesName});
                if (totalsRow == null)
                {
                    totalsRow = _totalsTable.NewRow();
                    totalsRow["Species"] = speciesName;
                    _totalsTable.Rows.Add(totalsRow);
                }

                row = _populationChangeTable.NewRow();
                row["TickNumber"] = _currentTick;
                row["Species"] = speciesName;
                row["Delta"] = count;
                row["Reason"] = reason;
                _populationChangeTable.Rows.Add(row);
            }
            else
            {
                row["Delta"] = (int) row["Delta"] + count;
            }
        }
Exemple #14
0
 /// <summary>
 ///  Creates a new KilledOrganism based on ID and reason for death.
 /// </summary>
 /// <param name="id">The Unique ID of the organism.</param>
 /// <param name="reason">The reason the organism was killed.</param>
 public KilledOrganism(string id, PopulationChangeReason reason)
 {
     ExtraInformation = "";
     ID          = id;
     DeathReason = reason;
 }
        /// <summary>
        ///  Called by the game engine in order to kill the current creature.
        ///  Since this method can only be called when the state is mutable
        ///  player's can't use the method to arbitrarily kill competing
        ///  organisms.
        /// </summary>
        /// <internal/>
        public void Kill(PopulationChangeReason reason)
        {
            if (immutable)
            {
                throw new GameEngineException("Object is immutable.");
            }

            isAlive = false;
            currentMoveToAction = null;
            energy = 0;
            deathReason = reason;
        }
        /// <summary>
        ///  Called by the game engine in order to kill the current creature.
        ///  Since this method can only be called when the state is mutable
        ///  player's can't use the method to arbitrarily kill competing
        ///  organisms.
        /// </summary>
        /// <internal/>
        public void Kill(PopulationChangeReason reason)
        {
            if (IsImmutable)
            {
                throw new GameEngineException("Object is immutable.");
            }

            _currentMoveToAction = null;
            _energy = 0;
            DeathReason = reason;
        }