Esempio n. 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);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
 /// <summary>
 ///  Creates a new movement action for an organism.
 /// </summary>
 /// <param name="organismID">The ID of the organism the action will work on.</param>
 /// <param name="actionID">The incremental ID representing this action.</param>
 /// <param name="moveTo">The movement vector that defines this action.</param>
 internal MoveToAction(string organismID, int actionID, MovementVector moveTo)
     : base(organismID, actionID)
 {
     MovementVector = moveTo;
 }