home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 04 Pathfinding and Movement / 05 Hancock / Goal_HitSwitch.cpp < prev    next >
Encoding:
Text File  |  2001-08-19  |  1010 b   |  44 lines

  1.  
  2.  
  3. Goal_HitSwitch::Goal_HitSwitch(AI* pAI, const PathNode *switchNode_) : Goal( pAI ), GoalQueue()
  4.  switchNode(switchNode_), timer(0.0f), active(false)
  5. {
  6.     Assert(switchNode->flags & CPathNode::flagNodeSwitch);
  7.     const CEntity *pEntity = switchNode->GetEntity();
  8.     pSwitch = pEntity->Switch();
  9.     Assert(pSwitch);
  10. }
  11.  
  12. bool Goal_HitSwitch::ReplanSubgoals(){
  13.     ResetSubgoals();
  14.     NewSubgoal(new Goal_GotoNode(mpAI, switchNode)); //goto the switch
  15.     NewSubgoal(new Goal_TurnToEntity(mpAI, pSwitch)); //turn towards the switch
  16.     return true;
  17. }
  18.  
  19. Goal_HitSwitch::~Goal_HitSwitch()
  20. {
  21. }
  22.  
  23. // Update the goal
  24. void Goal_HitSwitch::Update( float secs_elapsed )
  25. {    
  26.     if (!active){
  27.         ReplanSubgoals();
  28.         active = true;
  29.     }
  30.  
  31.     typeGoalStatus status = UpdateSubgoals( secs_elapsed );
  32.     if (status==statusFailed) {
  33.         mGoalStatus = statusFailed;    
  34.         return; 
  35.     }
  36.  
  37.     if (!NoSubgoals())
  38.         return;
  39.  
  40.     mpAI->Nudge(pSwitch->ID()); //send an activation message to the switch
  41.  
  42.     mGoalStatus = statusSucceeded;
  43. }
  44.