14.5 DistanceToBallArrayOpponents
This function is similar to DistanceToBallArrayTeammates
but in this case we are concerned with the opponents distances to the ball. It is worth noting that a very similar implementation can be utilised to get an array to some other position. Perhaps distance to goal or another player for instance. Here since we don’t have to worry about finding our own position since none of the WorldObject
’s would be this agent we, therefore, don’t require that if statement.
void NaoBehavior::DistanceToBallArrayOpponents(double* _opponentDistances){
for(int i = WO_OPPONENT1; i<WO_OPPONENT1+NUM_AGENTS;i++){ //OUR PLAYERS
WorldObject* opponent = worldModel->getWorldObject(i);
VecPosition temp;
temp = opponent->pos;
temp.setZ(0);
float distance = temp.getDistanceTo(ball);
_opponentDistances[i-WO_OPPONENT1] = distance;
worldModel->getRVSender()->drawText("distOPP",std::to_string(distance),temp.getX(),temp.getY(),1,1,1);
}
}