コード例 #1
0
ファイル: TeamState.cpp プロジェクト: 4ker/Basketball_demo
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();
    }

}
コード例 #2
0
ファイル: Team.cpp プロジェクト: LiuJack/FootballAI
// Send back to home region
void Team::updateTargetsOfWaitingPlayers()
{
	for (auto it = mPlayers.begin(); it != mPlayers.end(); ++it)
	{
		if ((*it)->getPlayerRole() != Player::GOAL_KEEPER)
		{
			FieldPlayer* player = static_cast<FieldPlayer*>(*it);

			if (player->getStateMachine()->isInState(*Waiting::get()) ||
				player->getStateMachine()->isInState(*BackToOrigin::get()))
			{
				player->setTarget(player->getAssignedRegion()->getCenter());
			}
		}
	}
}
コード例 #3
0
ファイル: SoccerTeam.cpp プロジェクト: evavro/Artificial-Fun
//---------------------- 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());
      }
    }
  }
}
コード例 #4
0
bool BEWD_GlobalPlayerState::OnMessage(FieldPlayer* player, const Telegram& telegram)
{
  switch(telegram.Msg)
  {
  case Msg_ReceiveBall:
    {
      //set the target
      player->Steering()->SetTarget(*(static_cast<Vector2D*>(telegram.ExtraInfo)));

      //change state 
      player->GetFSM()->ChangeState(BEWD_ReceiveBall::Instance());

      return true;
    }

    break;

  case Msg_SupportAttacker:
    {
      //if already supporting just return
      if (player->GetFSM()->isInState(*BEWD_SupportAttacker::Instance()))
      {
        return true;
      }
      
      //set the target to be the best supporting position
      player->Steering()->SetTarget(player->Team()->GetSupportSpot());

      //change the state
      player->GetFSM()->ChangeState(BEWD_SupportAttacker::Instance());

      return true;
    }

    break;

 case Msg_Wait:
    {
      //change the state
      player->GetFSM()->ChangeState(BEWD_Wait::Instance());

      return true;
    }

    break;

  case Msg_GoHome:
    {
      player->SetDefaultHomeRegion();
      
      player->GetFSM()->ChangeState(BEWD_ReturnToHomeRegion::Instance());

      return true;
    }

    break;

  case Msg_PassToMe:
    {  
      
      //get the position of the player requesting the pass 
      FieldPlayer* receiver = static_cast<FieldPlayer*>(telegram.ExtraInfo);

      #ifdef PLAYER_STATE_INFO_ON
      //debug_con << "Player " << player->ID() << " received request from " <<
                    receiver->ID() << " to make pass" << "";
      #endif

      //if the ball is not within kicking range or their is already a 
      //receiving player, this player cannot pass the ball to the player
      //making the request.
      if (player->Team()->Receiver() != NULL ||
         !player->BallWithinKickingRange() )
      {
        #ifdef PLAYER_STATE_INFO_ON
        //debug_con << "Player " << player->ID() << " cannot make requested pass <cannot kick ball>" << "";
        #endif

        return true;
      }
      
      //make the pass   
      player->Ball()->Kick(receiver->Pos() - player->Ball()->Pos(),
                           Prm.MaxPassingForce);

          
     #ifdef PLAYER_STATE_INFO_ON
     //debug_con << "Player " << player->ID() << " Passed ball to requesting player" << "";
     #endif
        
      //let the receiver know a pass is coming 
      Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY,
                              player->ID(),
                              receiver->ID(),
                              Msg_ReceiveBall,
                              &receiver->Pos());

      //change state   
      player->GetFSM()->ChangeState(BEWD_Wait::Instance());

      player->FindSupport();

      return true;
    }

    break;

  }//end switch

  return false;
}