Ok, so I am doing a homework assignment where we need to setup an interpose with players in the wait state.
And this is the code I have come up with so far, but for some reason everytime I try to run this code, the program crashes after a few seconds . . . Any help would be greatly appreciated!
This is not the entire code, just the new portion that I have written.
//interpose behavior
if (player->Pitch()->GameOn())
{
FieldPlayer*oppPlayer=NULL;
double rad = Prm.GoalWidth;
SoccerTeam*opposingTeam = player->Team()->Opponents();
if (opposingTeam->InControl())
{
std::vector<PlayerBase*>::const_iterator end=opposingTeam->Members().end();
std::vector<PlayerBase*>::const_iterator it=opposingTeam->Members().begin();
while (it != end)
{
//Get the iterator's player
FieldPlayer*p=(FieldPlayer*)(*it);
// if the iterators player is not the controlling player and falls within the radius
if (Vec2DDistanceSq(player->Pos(),p->Pos())<rad*rad&&!p->isControllingPlayer())
{
//if we found the first opposing player
if (oppPlayer == NULL || oppPlayer->DistToOppGoal()> p->DistToOppGoal())
{
oppPlayer= p;
}
else
{
oppPlayer= p;
//update iterator
++it;}
{
if (oppPlayer!= NULL)
{
//Set up interpose Steering Behavior
double distance = sqrt(oppPlayer->DistSqToBall())/2;
debug_con << "Player" << player ->ID() << "interposing" << "";
player->Steering()->SetTarget(oppPlayer->Pos());
player->Steering()->InterposeOn(distance);
}
else
{
return;
}
}
}
}
}
}