AIMovementModule Class Reference

#include <ai_movement_module.h>

Collaboration diagram for AIMovementModule:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AIMovementModule ()
void BeginTurn ()
void Move (uint current_time)
void StopMoving ()

Private Types

 NO_MOVEMENT
 WALKING
 BACK_TO_JUMP
 JUMPING
 FLYING
 ROPING
enum  movement_type_t {
  NO_MOVEMENT, WALKING, BACK_TO_JUMP, JUMPING,
  FLYING, ROPING
}

Private Member Functions

void InverseDirection ()
void MakeStep ()
void Walk ()
void StopWalking ()
void PrepareJump ()
void GoBackToJump ()
void Jump ()
void EndOfJump ()
bool ObstacleHeight (int &height)
bool RiskGoingOutOfMap ()

Private Attributes

uint m_current_time
Point2i last_position
uint time_at_last_position
Point2i last_blocked_position
movement_type_t current_movement

Detailed Description

Definition at line 26 of file ai_movement_module.h.


Member Enumeration Documentation

enum AIMovementModule::movement_type_t [private]

Enumerator:
NO_MOVEMENT 
WALKING 
BACK_TO_JUMP 
JUMPING 
FLYING 
ROPING 

Definition at line 29 of file ai_movement_module.h.

00029                {
00030     NO_MOVEMENT,
00031     WALKING,
00032     BACK_TO_JUMP,
00033     JUMPING,
00034     FLYING,
00035     ROPING,
00036   } movement_type_t;


Constructor & Destructor Documentation

AIMovementModule::AIMovementModule (  ) 

Definition at line 299 of file ai_movement_module.cpp.

00300 {
00301   std::cout << "o Artificial Intelligence Movement module initialization" << std::endl;
00302 }


Member Function Documentation

void AIMovementModule::BeginTurn (  ) 

Definition at line 291 of file ai_movement_module.cpp.

00292 {
00293   current_movement = NO_MOVEMENT;
00294   time_at_last_position = 0;
00295   last_position = Point2i(0,0);
00296   last_blocked_position = Point2i(0,0);
00297 }

Here is the caller graph for this function:

void AIMovementModule::EndOfJump (  )  [private]

Definition at line 145 of file ai_movement_module.cpp.

00146 {
00147   assert(current_movement = JUMPING);
00148 
00149   //GameMessages::GetInstance()->Add("finished to jump");
00150   
00151   
00152   if ( last_position.GetX() == ActiveCharacter().GetPosition().GetX() ) {
00153     // we have not moved since last movement
00154     StopMoving();
00155     
00156   } else {
00157     // No more blocked !!
00158     current_movement = WALKING;
00159   }  
00160 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::GoBackToJump (  )  [private]

Definition at line 120 of file ai_movement_module.cpp.

00121 {
00122   assert(current_movement = BACK_TO_JUMP);
00123 
00124   MakeStep();
00125 
00126   int height;
00127   bool blocked = !(ObstacleHeight(height));
00128 
00129   if ( abs(last_position.GetX() - ActiveCharacter().GetPosition().GetX()) >= 20
00130        || time_at_last_position +1 < m_current_time
00131        || blocked) {
00132     //it's time to jump!
00133     InverseDirection();
00134     Jump();
00135   }
00136 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::InverseDirection (  )  [private]

Definition at line 233 of file ai_movement_module.cpp.

00234 {
00235   if (ActiveCharacter().GetDirection() == Body::DIRECTION_RIGHT) {
00236     ActiveCharacter().SetDirection(Body::DIRECTION_LEFT);
00237   } else {
00238     ActiveCharacter().SetDirection(Body::DIRECTION_RIGHT);
00239   }
00240 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::Jump (  )  [private]

Definition at line 138 of file ai_movement_module.cpp.

00139 {
00140   //  GameMessages::GetInstance()->Add("try to jump!");
00141   current_movement = JUMPING;
00142   ActionHandler::GetInstance()->NewAction (new Action(Action::ACTION_HIGH_JUMP));
00143 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::MakeStep (  )  [private]

Definition at line 45 of file ai_movement_module.cpp.

00046 {
00047   if(ActiveCharacter().IsImmobile()) {
00048     if (ActiveCharacter().GetDirection() == Body::DIRECTION_RIGHT) {
00049       MoveCharacterRight(ActiveCharacter());
00050     }  else {
00051       MoveCharacterLeft(ActiveCharacter());
00052     }
00053   }
00054 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::Move ( uint  current_time  ) 

Definition at line 245 of file ai_movement_module.cpp.

00246 {
00247   m_current_time = current_time;
00248 
00249   // are we on the ground ?
00250   if ( ActiveCharacter().FootsInVacuum() ) { // No!
00251     return;
00252   }
00253 
00254   switch (current_movement) {
00255 
00256   case NO_MOVEMENT:
00257     // Begin to walk
00258     Walk();
00259     break;
00260 
00261   case WALKING:
00262     // Continue to walk
00263     Walk();
00264     break;
00265 
00266   case BACK_TO_JUMP:
00267     // Go back to have enough place to jump
00268     GoBackToJump();
00269     break;
00270 
00271   case JUMPING:
00272     EndOfJump();
00273  
00274     break;
00275   default:
00276     break;
00277   }
00278 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool AIMovementModule::ObstacleHeight ( int &  height  )  [private]

Definition at line 61 of file ai_movement_module.cpp.

00062 {
00063   if (ComputeHeightMovement(ActiveCharacter(), height, false))
00064     return true;
00065 
00066   int y_floor=ActiveCharacter().GetY();
00067   if (height < 0) {
00068 
00069     for (height = -15; height >= -150 ; height--) {
00070       if ( ActiveCharacter().IsInVacuum( Point2i(ActiveCharacter().GetDirection(), height) ) ) {
00071         break;
00072       }
00073     }
00074 
00075   } else {
00076 
00077     // Compute exact whole size
00078     for (height = 15; height <= 150 ; height++){
00079       if ( !ActiveCharacter().IsInVacuum(Point2i(ActiveCharacter().GetDirection(), height))
00080           ||  ActiveCharacter().FootsOnFloor(y_floor+height)){
00081         break;
00082       }
00083     }
00084 
00085   }
00086   return false;
00087 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::PrepareJump (  )  [private]

Definition at line 110 of file ai_movement_module.cpp.

00111 {
00112   ActiveCharacter().body->StartWalk();
00113   
00114   current_movement = BACK_TO_JUMP;
00115   time_at_last_position = m_current_time;
00116 
00117   InverseDirection();
00118 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool AIMovementModule::RiskGoingOutOfMap (  )  [private]

Definition at line 89 of file ai_movement_module.cpp.

00090 {
00091   if ( ActiveCharacter().GetDirection() == Body::DIRECTION_LEFT &&
00092        ActiveCharacter().GetX() <= 5 ) {
00093     return true;
00094   } else if ( ActiveCharacter().GetDirection() == Body::DIRECTION_RIGHT &&
00095               world.GetWidth() - 5 <= ActiveCharacter().GetX() + ActiveCharacter().GetSize().GetX() ) {
00096     return true;
00097   }
00098 
00099   return false;
00100 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::StopMoving (  ) 

Definition at line 280 of file ai_movement_module.cpp.

00281 {
00282   //  GameMessages::GetInstance()->Add("stop moving");
00283   StopWalking();
00284   //m_step++;
00285 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::StopWalking (  )  [private]

Definition at line 223 of file ai_movement_module.cpp.

00224 {
00225   current_movement = NO_MOVEMENT;
00226   ActiveCharacter().body->StopWalk();
00227 }

Here is the call graph for this function:

Here is the caller graph for this function:

void AIMovementModule::Walk (  )  [private]

Definition at line 168 of file ai_movement_module.cpp.

00169 {
00170   // Animate skin
00171   if ( current_movement != WALKING ) {
00172     ActiveCharacter().InitMouvementDG(100);
00173     ActiveCharacter().body->StartWalk();
00174     current_movement = WALKING;
00175   }
00176 
00177   MakeStep();
00178 
00179   int height;
00180   bool blocked = !(ObstacleHeight(height));
00181 
00182   // we are blocked, what next ?
00183   if ( blocked ) {
00184 
00185     if ( last_blocked_position.GetX() != ActiveCharacter().GetPosition().GetX() ) {
00186       
00187       last_blocked_position = ActiveCharacter().GetPosition();
00188       
00189       if (height < 0 ) {
00190         // There's a barrier
00191         
00192         if (height >= -80) { // we can try to jump!
00193           PrepareJump();
00194           return; // do not update position
00195         } else { // it's too high!
00196           //      GameMessages::GetInstance()->Add("It's too high!!");
00197           InverseDirection();
00198         }
00199       } else {
00200         // There's a hole
00201         
00202         if (height >= 100) { // it's too deep, go back!!
00203           //      GameMessages::GetInstance()->Add("It's too deep!" + ulong2str(height));
00204           InverseDirection();
00205         }
00206       }
00207     } else {
00208       // already have been blocked here...
00209       InverseDirection();
00210     }
00211   }
00212 
00213   // Inverse direction if there is a risk to go out of the map
00214   if (RiskGoingOutOfMap()) {
00215     InverseDirection();
00216   }
00217 
00218   // Update position if we are not jumping
00219   last_position = ActiveCharacter().GetPosition();
00220   time_at_last_position = m_current_time;
00221 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

movement_type_t AIMovementModule::current_movement [private]

Definition at line 43 of file ai_movement_module.h.

Point2i AIMovementModule::last_blocked_position [private]

Definition at line 42 of file ai_movement_module.h.

Point2i AIMovementModule::last_position [private]

Definition at line 40 of file ai_movement_module.h.

uint AIMovementModule::m_current_time [private]

Definition at line 38 of file ai_movement_module.h.

uint AIMovementModule::time_at_last_position [private]

Definition at line 41 of file ai_movement_module.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:33:03 2007 for Wormux by  doxygen 1.4.7