#include "GoalExplore.h" #include "../Raven_Game.h" #include "../Raven_Map.h" #include "../Vehicle.h" #include "../navigation/Raven_PathPlanner.h" #include "..\Raven_Messages.h" #include "Messaging/Telegram.h" #include "Goal_FollowPath.h" #include "Goal_SeekToPosition.h" //------------------------------ Activate ------------------------------------- //----------------------------------------------------------------------------- void GoalExplore::Activate() { m_Status = active; markOwnerWithGoal(); // if this goal is reactivated then there may be some existing subgoals that // must be removed removeAllSubgoals(); if (!m_DestinationIsSet) { // grab a random location m_CurrentDestination = m_Owner->getGameWorld() ->GetMap() ->GetRandomNodeLocation(); m_DestinationIsSet = true; } // and request a path to that position m_Owner->getPathPlanner()->RequestPathToPosition(m_CurrentDestination); // the bot may have to wait a few update cycles before a path is calculated // so for appearances sake it simple ARRIVES at the destination until a path // has been found addSubgoal(new Goal_SeekToPosition(m_Owner, m_CurrentDestination)); } //------------------------------ Process ------------------------------------- //----------------------------------------------------------------------------- int GoalExplore::Process() { // if status is inactive, call Activate() activateIfInactive(); // process the subgoals m_Status = processSubgoals(); return m_Status; } //---------------------------- HandleMessage ---------------------------------- //----------------------------------------------------------------------------- bool GoalExplore::HandleMessage(const Telegram& msg) { // first, pass the message down the goal hierarchy bool bHandled = forwardMessageToFrontMostSubgoal(msg); // if the msg was not handled, test to see if this goal can handle it if (bHandled == false) { switch (msg.Msg) { case Msg_PathReady: // clear any existing goals removeAllSubgoals(); addSubgoal( new Goal_FollowPath(m_Owner, m_Owner->getPathPlanner()->GetPath())); return true; // msg handled case Msg_NoPathAvailable: m_Status = failed; return true; // msg handled default: return false; } } // handled by subgoals return true; }