示例#1
0
 /* returns: >0 the intention was changed
  *           1 = intention must continue running
  *           2 = fail event was generated and added in C.E
  *           3 = simply removed without event
  */
 public virtual int DropDesire(Intention i, Trigger g, Reasoner rs, Unifier un)
 {
     if (i != null && i.DropDesire(g, un))
     {
         if (rs.HasDesireListener())
         {
             foreach (Desire gl in rs.GetDesiresListeners())
             {
                 gl.DesireFinished(g, Desire.FinishStates.achieved);
             }
         }
         //continue the intention
         if (!i.IsFinished())
         {
             if (rs.GetCircumstance().GetSelectedIntention() != i)
             {
                 i.Peek().RemoveCurrentStep();
             }
             rs.ApplyClrInt(i);
             return(1);
         }
         else
         {
             rs.ApplyClrInt(i);
             return(3);
         }
     }
     return(0);
 }
示例#2
0
        /* returns: >0 the intention was changed
         *           1 = intention must continue running
         *           2 = fail event was generated and added in C.E
         *           3 = simply removed without event
         */
        public override int DropDesire(Intention i, Trigger g, Reasoner rs, Unifier un)
        {
            if (i != null)
            {
                if (i.DropDesire(g, un))
                {
                    //notify listener
                    if (rs.HasDesireListener())
                    {
                        foreach (Desire gl in rs.GetDesiresListeners())
                        {
                            gl.DesireFailed(g);
                        }
                    }

                    //generate failure event
                    Event failEvent = rs.FindEventForFailure(i, g); //find fail event for the goal just dropped
                    if (failEvent != null)
                    {
                        failEvent = new Event(failEvent.GetTrigger().Capply(un), failEvent.GetIntention());
                        rs.GetCircumstance().AddEvent(failEvent);
                        return(2);
                    }
                    else //i is finished or without failure plan
                    {
                        if (rs.HasDesireListener())
                        {
                            foreach (Desire gl in rs.GetDesiresListeners())
                            {
                                gl.DesireFinished(g, Desire.FinishStates.unachieved);
                            }
                        }
                        i.Fail(rs.GetCircumstance());
                        return(3);
                    }
                }
            }
            return(0);
        }
示例#3
0
        public virtual void DropDesireInEvent(Reasoner rs, Event e, Intention i)
        {
            Circumstance C = rs.GetCircumstance();

            C.RemoveEvent(e);
            if (i != null)
            {
                if (rs.HasDesireListener())
                {
                    foreach (Desire gl in rs.GetDesiresListeners())
                    {
                        gl.DesireFinished(e.GetTrigger(), Desire.FinishStates.achieved);
                    }
                    i.Peek().RemoveCurrentStep();
                    rs.ApplyClrInt(i);
                    C.AddRunningIntention(i);
                }
            }
        }