Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }