// Calculate the difference between two distances:
// (a) distance between this player and end of field.
// (b) distance between supporting player and BSS.
double temp = 0.0;
if(player->Team()->SupportingPlayer() != NULL)
{
// Distance between this player and the end of field.
double endOfFieldDist = player->Team()->OpponentsGoal()->Center().x - player->Pos().x;
// Distance between supporting player and bss.
double supPlayerAndBSSDist = Vec2DDistance(player->Team()->SupportingPlayer()->Pos(),
player->Team()->SupportingPlayer()->Steering()->Target());
temp = fabs(endOfFieldDist) - fabs(supPlayerAndBSSDist);
}
// If this player reaches the opponent goal before
// the supporting player reaches the BSS ...
if(temp < 0.0)
{
// Get the closest opponent to the ball
PlayerBase* closestOpponent = player->Team()->Opponents()->PlayerClosestToBall();
double dotPlayers = player->Heading().Dot(closestOpponent->Heading());
//if the ball is between the player and the closest opponent to the ball
//it needs to swivel the ball around by doing multiple small kicks and
// turns until the player covers the ball.
if (dotPlayers < 0.0)
{
//the player's heading is going to be rotated by a small amount (Pi/4)
//and then the ball will be kicked in that direction
Vector2D direction = player->Heading();
//calculate the sign (+/-) of the angle between the player heading and the
//facing direction of the goal so that the player rotates around in the
//correct direction
double angle = QuarterPi * -1 * closestOpponent->Heading().Sign(player->Heading());
Vec2DRotateAroundOrigin(direction, angle);
//this value works well when the player is attempting to control the
//ball and turn at the same time
const double KickingForce = 0.8;
player->Ball()->Kick(direction, KickingForce);
}
else
{
player->Ball()->SetVelocity(Vector2D());
player->Ball()->Kick(player->Heading(), Prm.MaxDribbleForce);
}
}