Example #1
0
        public override void Activate()
        {
            Status = StatusTypes.Active;

            // if this goal is reactivated then there may be some existing subgoals that must be removed
            RemoveAllSubgoals();

            // it is possible for the target to die while this goal is active so we
            // must test to make sure the agent always has an active target
            if (Agent.TargetingSystem.IsTargetPresent)
            {
                // grab a local copy of the last recorded position (LRP) of the target
                var lrp = Agent.TargetingSystem.LastRecordedPosition;

                // if the agent has reached the LRP and it still hasn't found the target
                // it starts to search by using the explore goal to move to random
                // map locations
                if (Epsilon.IsZero(lrp) || Agent.IsAtPosition(lrp))
                {
                    AddSubgoal(new Explore(Agent));
                }

                // else move to the LRP
                else
                {
                    AddSubgoal(new MoveToPosition(Agent, lrp));
                }
            }

            // if there is no active target then this goal can be removed from the queue
            else
            {
                Status = StatusTypes.Completed;
            }
        }