public override GoalStatus Process()
        {
            // Remove all completed subgoals
            Subgoals.RemoveAll(g => g.GoalStatus == GoalStatus.Completed || g.GoalStatus == GoalStatus.Failed);

            // Activate goal when inactive
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Decide which atomic goal to choose or to stop
            if (Subgoals.Count == 0)
            {
                if (Entity.Hunger >= 0.8 && Entity.Sleep >= 0.5)
                {
                    Terminate();
                }
                else if (Entity.Hunger < Entity.Sleep)
                {
                    AddSubgoal(new EatGoal(Entity));
                }
                else
                {
                    AddSubgoal(new SleepGoal(Entity));
                }
            }

            Subgoals.ForEach(g => g.Process());

            return(GoalStatus);
        }
        public override GoalStatus Process()
        {
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Remove all completed subgoals
            Subgoals.RemoveAll(g => g.GoalStatus == GoalStatus.Completed || g.GoalStatus == GoalStatus.Failed);

            // If hunger or sleep is below a certain point attent to vitality
            if (!Subgoals.OfType <VitalityGoal>().Any() && GetDesirability(Entity.Hunger, Entity.Sleep) < 0.5)
            {
                AddSubgoal(new VitalityGoal(Entity));
            }

            Console.WriteLine($"Des: {GetDesirability(Entity.Hunger, Entity.Sleep)}        hung: {Entity.Hunger}, sleep: { Entity.Sleep}");

            // If the target changes follow the new target
            if (oldTarget != GameWorld.Instance.Target)
            {
                AddSubgoal(new FollowTargetGoal(Entity));
                oldTarget = GameWorld.Instance.Target;
            }

            // Process all subgoals
            Subgoals.ForEach(g => g.Process());

            return(GoalStatus);
        }
Пример #3
0
        public override GoalStatus Process()
        {
            // Activate goal when inactive
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Stop condition
            if (Path.Count == 0)
            {
                Terminate();
            }

            // When the target changes the goal has failed
            if (target != GameWorld.Instance.Target)
            {
                GoalStatus = GoalStatus.Failed;
            }

            // When completed or failed return
            if (GoalStatus == GoalStatus.Completed || GoalStatus == GoalStatus.Failed)
            {
                return(GoalStatus);
            }

            // Remove all completed subgoals
            Subgoals.RemoveAll(g => g.GoalStatus == GoalStatus.Completed);

            // Add subgoal
            if (Path.Count != 0 && !Subgoals.OfType <TraverseVertexGoal>().Any())
            {
                AddSubgoal(new TraverseVertexGoal(Entity, Path.First(), Path.Count));
                Path.RemoveFirst();
            }

            // Process all subgoals
            Subgoals.ForEach(g => g.Process());

            return(GoalStatus);
        }