Ejemplo n.º 1
0
 public override void Activate()
 {
     State = Statusgoal.active;
     SubGoals.Clear();
     SubGoals.Add(new PathFollowingGoal(smartEntity, Target));
     SubGoals.Add(new DrinkGoal(smartEntity, Target));
 }
Ejemplo n.º 2
0
 private void CheckStraight()
 {
     if (Player.CanGoStraight(Destination))
     {
         SubGoals.Clear();
         var moveGoal = new MoveTo(Player, Destination);
         moveGoal.Achieved += MoveGoal_Achieved;
         this.AddSubGoal(moveGoal);
         Path.Clear();
         return;
     }
     for (var i = Path.Count - 1; i > 0; i--)
     {
         if (Player.CanGoStraight(Path[i].transform.position))
         {
             var subPath = new Waypoint[Path.Count - i];
             Path.CopyTo(i, subPath, 0, Path.Count - i);
             Path = new List <Waypoint>(subPath);
             this.SubGoals.Clear();
             var moveGoal = new MoveTo(Player, Path[0].transform.position);
             moveGoal.Achieved += MoveGoal_Achieved;
             this.AddSubGoal(moveGoal);
         }
     }
 }
Ejemplo n.º 3
0
        public override GoalStatus Process()
        {
            SubGoals.RemoveAll(sg => sg.GoalStatus == GoalStatus.Completed || sg.GoalStatus == GoalStatus.Failed);

            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Decide if there is a need for fulfillment and which need
            if (SubGoals.Count == 0)
            {
                if (ME.Hunger >= 3 && ME.Fatique >= 5)
                {
                    Terminate();
                }
                else if (ME.Hunger < ME.Fatique)
                {
                    AddSubGoal(new DealWithHungerGoal(ME, ME.em));
                }
                else
                {
                    AddSubGoal(new DealWithFatiqueGoal(ME, ME.em));
                }
            }

            SubGoals.ForEach(sg => sg.Process());

            return(GoalStatus);
        }
Ejemplo n.º 4
0
        public override GoalStatus Process()
        {
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Remove subgoals
            SubGoals.RemoveAll(sg => sg.GoalStatus == GoalStatus.Completed ||
                               sg.GoalStatus == GoalStatus.Failed);

            // Calculate, if there is need to attend to fatique or hunger
            if (!SubGoals.OfType <DecideBetweenNeedsGoal>().Any() && GetDesirability(ME.Hunger, ME.Fatique) < 0.5)
            {
                AddSubGoal(new DecideBetweenNeedsGoal(ME));
            }

            // If the target changes and is not used by other goals, get a new path
            if (Target != Game1.Instance.Target && !SubGoals.OfType <DecideBetweenNeedsGoal>().Any())
            {
                AddSubGoal(new FollowPathGoal(ME));
                Target = Game1.Instance.Target;
            }

            // Process through all subgoals
            SubGoals.ForEach(sg => sg.Process());

            return(GoalStatus);
        }
Ejemplo n.º 5
0
 public override void Activate()
 {
     //Target = new Target(new Vector2(Robot.MyWorld.Random.Next(20, 1260), Robot.MyWorld.Random.Next(20, 940)), Robot.MyWorld);
     State = Statusgoal.active;
     SubGoals.Clear();
     SubGoals.Add(new PathFollowingGoal(smartEntity, Target));
     SubGoals.Add(new EatGoal(smartEntity, Target));
 }
Ejemplo n.º 6
0
        public bool notPresent(Agent_Goal_Types goaltype)
        {
            if (SubGoals.Count > 0)
            {
                return(SubGoals.Peek().GetGoalType() != goaltype);
            }

            return(true);
        }
Ejemplo n.º 7
0
        public void RemoveAllSubgoals()
        {
            for (int i = 0; i < SubGoals.Count; i++)
            {
                if (SubGoals[i] != null)
                {
                    SubGoals[i].Terminate();
                }
            }

            SubGoals.Clear();
        }
Ejemplo n.º 8
0
        public override GoalStatus Process()
        {
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Condition to complete the goal
            if (PathToFollow.Count == 0)
            {
                Terminate();
            }


            if (!SubGoals.OfType <DecideBetweenNeedsGoal>().Any())
            {
                // If target changes during pathfinding and pathfinding is not used by another goal, return from this goal
                if (Target != Game1.Instance.Target && !PathFindingAsSubGoal)
                {
                    Console.WriteLine("Pathfinding failed, calculating new path");
                    GoalStatus = GoalStatus.Failed;
                }
            }


            if (GoalStatus == GoalStatus.Completed || GoalStatus == GoalStatus.Failed)
            {
                return(GoalStatus);
            }

            SubGoals.RemoveAll(sg => sg.GoalStatus == GoalStatus.Completed);

            // Add traversing each node as subgoal to process them later
            if (PathToFollow.Count != 0 && !SubGoals.OfType <TraverseNodeGoal>().Any())
            {
                AddSubGoal(new TraverseNodeGoal(ME, PathToFollow.First()));
                PathToFollow.RemoveFirst();
            }

            SubGoals.ForEach(sg => sg.Process());

            return(GoalStatus);
        }
Ejemplo n.º 9
0
        private object TerminateAndRemoveCompletedAndFailedGoalsOnClients(Command command)
        {
            for (int i = 0; i < SubGoals.Count; i++)
            {
                var subGoal = SubGoals[i];

                if (subGoal._clientStatus == GoalStatus.Failed || subGoal._clientStatus == GoalStatus.Completed)
                {
                    subGoal.Terminate();
                    SubGoals.Remove(subGoal);

                    if (_mostDesirableSubGoalIndexOnClient == i)
                    {
                        _mostDesirableSubGoalIndexOnClient = -1;
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 10
0
        public override GoalStatus Process()
        {
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Make sure that eating subgoal is terminated first and terminate, when hunger is good
            if (ME.Hunger >= 3f && SubGoals[0].GetType() == typeof(EatGoal) && SubGoals[0].GoalStatus == GoalStatus.Completed)
            {
                Terminate();
            }

            if (GoalStatus == GoalStatus.Completed || GoalStatus == GoalStatus.Failed)
            {
                return(GoalStatus);
            }

            SubGoals.RemoveAll(sg => sg.GoalStatus == GoalStatus.Completed);

            // Get a path to traverse to the bush
            if (!SubGoals.OfType <FollowPathGoal>().Any())
            {
                FollowPathGoal comp = new FollowPathGoal(ME, BushAsTarget);
                AddSubGoal(comp);
            }

            SubGoals.ForEach(sg => sg.Process());

            // Once path is traversed, eat
            if (Vector2.Subtract(BushAsTarget, ME.Pos).Length() < 10 && !SubGoals.OfType <EatGoal>().Any())
            {
                SubGoals.RemoveAll(sg => sg.GoalStatus == GoalStatus.Completed);
                AddSubGoal(new EatGoal(ME));
            }

            SubGoals.ForEach(sg => sg.Process());

            return(GoalStatus);
        }
Ejemplo n.º 11
0
 public override void AddSubGoal(Goal <T> g)
 {
     SubGoals.Insert(0, g);
 }
Ejemplo n.º 12
0
 public virtual void AddSubGoal(Goal goal)
 {
     SubGoals.Add(goal);
 }