private int triggerCount; // the count that needs to be reached before triggering

        #endregion Fields

        #region Constructors

        public TriggerCollision(AIState _state, CollisionCounter c, int count, bool lt)
            : base(_state)
        {
            this.cCounter = c;
            this.triggerCount = count;
            this.LessThan = lt;
        }
Exemple #2
0
 /* Board constructor. This Constructor
  * is used once per actor. One actor only ever
  * has one AI, though they may go through multiple states
  * and triggers.
  */
 public AI(AI ai, Actor _body)
 {
     //IMP
     this.CurrentState = ai.CurrentState.Copy();
     this.Attach(_body);
     this.ActiveTriggers = new List<AITrigger>();
     this.ResetActiveTriggers();
 }
 public void InitializeAIHoming()
 {
     AIState move = new AIState(true, false);
     AIState home = new AIState(true, true);
     CollisionCounter c = new CollisionCounter(40, 3, Device);
     var t1 = new TriggerCollision(home, c, 0, false);
     move.AddTrigger(t1);
     AIHoming = new AI(move);
 }
 /* AI For enemy actors. When a friendly (player)
  * actor comes close, the actor will stop moving.
  */
 public void InitializeAICloseStop()
 {
     AIState move = new AIState(true, false);
     AIState stop = new AIState(false, false);
     CollisionCounter c = new CollisionCounter(30, 3, Device);//radius of 15, collides with Friendly Actors
     var t1 = new TriggerCollision(stop, c, 0, false); // trips when more than 1 friendly actor in radius
     var t2 = new TriggerCollision(move, c, 1, true); // trips when there are no friendly actors in radius
     move.AddTrigger(t1);
     stop.AddTrigger(t2);
     AICloseStop = new AI(move);
 }
 /* AI that sets the actor to move and shoot
  */
 public void InitializeAIStartStop()
 {
     //first, the two basic states: move or stop
     AIState move = new AIState(true, false);
     AIState stop = new AIState(false, false);
     //now, we connect them with the appropriate triggers
     var t1 = new TriggerTime(stop, 0.25f);
     var t2 = new TriggerTime(move, 0.25f);
     move.AddTrigger(t1);
     stop.AddTrigger(t2);
     AIStartStop = new AI(move);
 }
        /* Used for generating board copies of AIStates
         */
        public AIState Copy()
        {
            AIState retstate = new AIState(this.Moving, this.Shooting);
            retstate.Body = this.Body; // this is fine, as Copy() is only used for board copies.
                                        // the data copy is guaranteed to have a body.
            retstate.MoveTarget = this.MoveTarget;
            retstate.ShootTarget = this.ShootTarget;
            retstate.TriggerList = this.TriggerList;
            /* pass by reference ok for this as the AI will have
             * to make its own deep copies of the AITriggers to add
             * to the board. This TriggerList is just so the AI can copy
             * the correct triggers.
             */

            return retstate;
        }
 public TriggerTime(AIState _state, float _time)
     : base(_state)
 {
     this.time = _time;
 }
 protected AITrigger(AIState _state)
 {
     this.State = _state;
 }
Exemple #9
0
 /* This method runs before updating the AI
  * in the list.
  * 1: check if triggers are flipped
  * 2: if so, update current state = new copy of trigger.state
  * 3: Destroy any triggers already in place
  * 4: then, update ActiveTriggers (by making new copies of the ones in the currstate)
  * (The Actor Manager will handle adding the triggers to list)
  */
 public bool CheckTriggers()
 {
     bool ret = false;
     AITrigger newTrigger = null;
     foreach (var t in ActiveTriggers)
     {
         if (t.IsTriggered())
         {
             ret = true;
             newTrigger = t;
             break;
         }
     }
     if (newTrigger != null)
     {
         CurrentState = newTrigger.GetState().Copy();
         CurrentState.Attach(Body);
         CurrentState.SetMoveTarget(newTrigger.GetMoveTarget());
         CurrentState.SetShootTarget(newTrigger.GetShootTarget());
         ResetActiveTriggers();
     }
     return ret;
 }
Exemple #10
0
 /* Data constructor
  */
 public AI(AIState ai)
 {
     this.CurrentState = ai;
     this.ActiveTriggers = ai.GetTriggers();
 }