Example #1
0
        /// <summary>
        ///  <para>
        ///   Method used to command a creature to begin moving towards a specific location
        ///   at a specific speed.  The actual movement operation may take several turns,
        ///   but is always initiated using this method.  Your movement location should
        ///   be within the world boundary and your movement speed should be less than or
        ///   equal to your creature's Species.MaximumSpeed.
        ///  </para>
        ///  <para>
        ///   Once called the creature will begin moving towards the specified point.  This
        ///   movement will continue until you issue a different BeginMoving command to your
        ///   creature, it reaches its destination, or becomes blocked by something.  Any
        ///   calls to BeginMoving will clear out any previous calls, so care should be taken
        ///   when issuing multi-part path movements.
        ///  </para>
        ///  <para>
        ///   Once the movement is completed the MoveCompleted event will be fired and your
        ///   event handler for this function will be called if you've provided one.  The
        ///   event handler will provide full information about the results of an attempted
        ///   movement operation.
        ///  </para>
        /// </summary>
        /// <param name="vector">
        ///  The MovementVector that determines the point you are moving to and how fast to move there.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown if the vector parameter is null.
        /// </exception>
        /// <exception cref="OutOfBoundsException">
        ///  Thrown if the destination is outside of the world boundaries.
        /// </exception>
        /// <exception cref="TooFastException">
        ///  Thrown if the speed defined in the vector is greater than Species.MaximumSpeed.
        /// </exception>
        public void BeginMoving(MovementVector vector)
        {
            if (vector == null)
            {
                throw new ArgumentNullException("vector", "The argument 'vector' cannot be null");
            }

            if (vector.Speed > State.AnimalSpecies.MaximumSpeed)
            {
                throw new TooFastException();
            }

            if (vector.Destination.X > World.WorldWidth - 1 ||
                vector.Destination.X < 0 ||
                vector.Destination.Y > World.WorldHeight - 1 ||
                vector.Destination.Y < 0)
            {
                throw new OutOfBoundsException();
            }

            var actionID = GetNextActionID();
            var action   = new MoveToAction(ID, actionID, vector);

            lock (PendingActions)
            {
                PendingActions.SetMoveToAction(action);
                InProgressActions.SetMoveToAction(action);
            }
        }
        ///<summary>
        ///</summary>
        ///<param name="moveToAction"></param>
        ///<exception cref="ApplicationException"></exception>
        public void SetMoveToAction(MoveToAction moveToAction)
        {
            if (IsImmutable)
            {
                throw new ApplicationException("PendingActions must be mutable to modify actions.");
            }

            MoveToAction = moveToAction;
        }
Example #3
0
        ///<summary>
        ///</summary>
        ///<param name="moveToAction"></param>
        ///<exception cref="ApplicationException"></exception>
        public void SetMoveToAction(MoveToAction moveToAction)
        {
            if (IsImmutable)
            {
                throw new ApplicationException("PendingActions must be mutable to modify actions.");
            }

            MoveToAction = moveToAction;
        }
Example #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;
        }
Example #5
0
        /// <summary>
        ///  <para>
        ///   Method used to command a creature to begin moving towards a specific location
        ///   at a specific speed.  The actual movement operation may take several turns,
        ///   but is always initiated using this method.  Your movement location should
        ///   be within the world boundary and your movement speed should be less than or
        ///   equal to your creature's Species.MaximumSpeed.
        ///  </para>
        ///  <para>
        ///   Once called the creature will begin moving towards the specified point.  This
        ///   movement will continue until you issue a different BeginMoving command to your
        ///   creature, it reaches its destination, or becomes blocked by something.  Any
        ///   calls to BeginMoving will clear out any previous calls, so care should be taken
        ///   when issuing multi-part path movements.
        ///  </para>
        ///  <para>
        ///   Once the movement is completed the MoveCompleted event will be fired and your
        ///   event handler for this function will be called if you've provided one.  The
        ///   event handler will provide full information about the results of an attempted
        ///   movement operation.
        ///  </para>
        /// </summary>
        /// <param name="vector">
        ///  The MovementVector that determines the point you are moving to and how fast to move there.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown if the vector parameter is null.
        /// </exception>
        /// <exception cref="OutOfBoundsException">
        ///  Thrown if the destination is outside of the world boundaries.
        /// </exception>
        /// <exception cref="TooFastException">
        ///  Thrown if the speed defined in the vector is greater than Species.MaximumSpeed.
        /// </exception>
        public void BeginMoving(MovementVector vector)
        {
            if (vector == null)
            {
                throw new ArgumentNullException("vector", "The argument 'vector' cannot be null");
            }

            if (vector.Speed > State.AnimalSpecies.MaximumSpeed)
            {
                throw new TooFastException();
            }

            if (vector.Destination.X > World.WorldWidth - 1 ||
                vector.Destination.X < 0 ||
                vector.Destination.Y > World.WorldHeight - 1 ||
                vector.Destination.Y < 0)
            {
                throw new OutOfBoundsException();
            }

            var actionID = GetNextActionID();
            var action = new MoveToAction(ID, actionID, vector);
            lock (PendingActions)
            {
                PendingActions.SetMoveToAction(action);
                InProgressActions.SetMoveToAction(action);
            }
        }
 /// <internal/>
 public MoveCompletedEventArgs(int actionID, MoveToAction action, ReasonForStop reason, OrganismState blockingOrganism)
     : base(actionID, action)
 {
     this.reason = reason;
     this.blockingOrganism = blockingOrganism;
 }
        /// <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;
        }