Guest

Untitled

By: a guest on Nov 11th, 2009  |  syntax: C++  |  size: 2.06 KB  |  hits: 131  |  expires: Never
download  |  raw  |  embed  |  report abuse
This paste has a previous version, view the difference. Copied
  1.     // Calculate the difference between two distances:
  2.     // (a) distance between this player and end of field.
  3.     // (b) distance between supporting player and BSS.
  4.     double temp = 0.0;
  5.     if(player->Team()->SupportingPlayer() != NULL)
  6.     {
  7.  
  8.         // Distance between this player and the end of field.
  9.         double endOfFieldDist = player->Team()->OpponentsGoal()->Center().x - player->Pos().x;
  10.  
  11.         // Distance between supporting player and bss.
  12.         double supPlayerAndBSSDist = Vec2DDistance(player->Team()->SupportingPlayer()->Pos(),
  13.                 player->Team()->SupportingPlayer()->Steering()->Target());
  14.  
  15.         temp = fabs(endOfFieldDist) - fabs(supPlayerAndBSSDist);
  16.  
  17.     }
  18.  
  19.     // If this player reaches the opponent goal before
  20.     // the supporting player reaches the BSS ...
  21.     if(temp < 0.0)
  22.     {
  23.  
  24.         // Get the closest opponent to the ball
  25.         PlayerBase* closestOpponent = player->Team()->Opponents()->PlayerClosestToBall();
  26.  
  27.         double dotPlayers = player->Heading().Dot(closestOpponent->Heading());
  28.  
  29.         //if the ball is between the player and the closest opponent to the ball
  30.         //it needs to swivel the ball around by doing multiple small kicks and
  31.         // turns until the player covers the ball.
  32.         if (dotPlayers < 0.0)
  33.         {
  34.  
  35.             //the player's heading is going to be rotated by a small amount (Pi/4)
  36.             //and then the ball will be kicked in that direction
  37.             Vector2D direction = player->Heading();
  38.  
  39.             //calculate the sign (+/-) of the angle between the player heading and the
  40.             //facing direction of the goal so that the player rotates around in the
  41.             //correct direction
  42.             double angle = QuarterPi * -1 * closestOpponent->Heading().Sign(player->Heading());
  43.  
  44.             Vec2DRotateAroundOrigin(direction, angle);
  45.  
  46.             //this value works well when the player is attempting to control the
  47.             //ball and turn at the same time
  48.             const double KickingForce = 0.8;
  49.  
  50.             player->Ball()->Kick(direction, KickingForce);
  51.  
  52.         }
  53.  
  54.         else
  55.         {
  56.  
  57.             player->Ball()->SetVelocity(Vector2D());
  58.             player->Ball()->Kick(player->Heading(), Prm.MaxDribbleForce);
  59.  
  60.         }
  61.  
  62.     }