home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 04 Pathfinding and Movement / 05 Hancock / Goal.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-20  |  1.2 KB  |  60 lines

  1.  
  2. #include "Goal.h"
  3.  
  4. GoalQueue::GoalQueue()
  5. {
  6. }
  7.  
  8. GoalQueue::~GoalQueue()
  9. {
  10.     ResetSubgoals();
  11. }
  12.  
  13. typeGoalStatus GoalQueue::UpdateSubgoals( float secs_elapsed )
  14. {
  15.     if (mGoals.empty()) return statusSucceeded; //return success when no goals left
  16.     
  17.     mGoals.front()->Update( secs_elapsed );
  18.     
  19.     //if the goal is in progress, simply return this status
  20.     //if the goal has failed, clear the entire subgoal list
  21.     //if the goal has succeeded, remove it, return 
  22.     typeGoalStatus status = mGoals.front()->GoalStatus();
  23.     
  24.     switch (status){
  25.     case statusInProgress:
  26.         break;
  27.     case statusFailed:
  28.         ResetSubgoals();
  29.         return statusFailed; //return failure
  30.         break;
  31.     case statusSucceeded:
  32.         delete mGoals.front();
  33.         mGoals.pop_front();
  34.         break;
  35.     }
  36.     
  37.     //returns statusInProgress if we didn't fail and there are still goals on the list
  38.     return statusInProgress; 
  39. }
  40.  
  41. void GoalQueue::NewSubgoal( Goal* pGoal )
  42. {
  43.     mGoals.push_back( pGoal );
  44. }
  45.  
  46. void GoalQueue::InsertSubgoal( Goal* pGoal )
  47. {
  48.     mGoals.push_back( pGoal );
  49. }
  50.  
  51. void GoalQueue::ResetSubgoals() 
  52.     while (!mGoals.empty()){
  53.         Goal *pGoal = mGoals.back();
  54.         delete pGoal;
  55.         mGoals.pop_back();
  56.     }
  57. }
  58.  
  59.