void PrepareForKickOff::Enter(BallTeam* team) { //reset key player pointers team->SetControllingPlayer(NULL); team->SetSupportingPlayer(NULL); team->SetReceiver(NULL); team->SetPlayerClosestToBall(NULL); int color = team->GetGame()->GetScored(); if(color == BallTeam::blue) printf("blue get scored\n"); else printf("red get scored\n"); if(team->Color() == BallTeam::blue){ if(team->GetGame()->GetScored() == BallTeam::blue){ const int BlueRegions[TeamSize] = {1,6,8,3,5}; ChangePlayerHomeRegions(team, BlueRegions); } else {//red team get score const int BlueRegions[TeamSize] = {16,20,23,21,13}; ChangePlayerHomeRegions(team, BlueRegions); } } else //red team { if(team->GetGame()->GetScored() == BallTeam::red){ const int RedRegions[TeamSize] = {16,20,23,21,13}; ChangePlayerHomeRegions(team, RedRegions); } else{ const int RedRegions[TeamSize] = {1,6,8,3,5}; ChangePlayerHomeRegions(team, RedRegions); } } team->UpdateTargetsOfWaitingPlayers(); if(team->GetGame()->GetScored() == BallTeam::blue) { double x = team->GetGame()->PlayingArea()->Left(); double top = team->GetGame()->PlayingArea()->Top(); double y = RandInRange(-top, top); team->GetGame()->GetBall()->PlaceAtPosition(Vector2D(x,y)); } else if(team->GetGame()->GetScored() == BallTeam::red) { double x = team->GetGame()->PlayingArea()->Right(); double top = team->GetGame()->PlayingArea()->Top(); double y = RandInRange(-top, top); team->GetGame()->GetBall()->PlaceAtPosition(Vector2D(x,y)); } if(team->GetGame()->GetScored() != team->Color()){ PlayerBase* it = team->GetPreparePlayer(); FieldPlayer* plyr = static_cast<FieldPlayer*>(it); plyr->GetFSM()->ChangeState(ChaseBall::Instance()); printf("I let player:%d to get ball\n",plyr->ID()); //getchar(); } }
//---------------------- UpdateTargetsOfWaitingPlayers ------------------------ // // void SoccerTeam::UpdateTargetsOfWaitingPlayers()const { std::vector<PlayerBase*>::const_iterator it = m_Players.begin(); for (it; it != m_Players.end(); ++it) { if ( (*it)->Role() != PlayerBase::goal_keeper ) { //cast to a field player FieldPlayer* plyr = static_cast<FieldPlayer*>(*it); if ( plyr->GetFSM()->isInState(*Wait::Instance()) || plyr->GetFSM()->isInState(*ReturnToHomeRegion::Instance()) ) { plyr->Steering()->SetTarget(plyr->HomeRegion()->Center()); } } } }