コード例 #1
0
ファイル: match.cpp プロジェクト: walsh06/grifball
Player* Match::getTeammate(Player* p)
{
    vector<Player *> teammates;
    vector<int> teammateProbs;
    int teamNum = p->getTeam();
    Team* team ;
    int total = 0;
    if(teamNum == 1)
    {
        team = teamOne;
    }
    else if(teamNum == 2)
    {
        team = teamTwo;
    }

    for(int i = 0; i < 5; i++)
    {
        Player* currentPlayer = team->getPlayer(i);
        if(currentPlayer->getNumber() != p->getNumber())
        {
            teammates.push_back(currentPlayer);
            if(currentPlayer->getRole() == 1)
            {
                teammateProbs.push_back(20);
                total+=20;
            }
            else if(currentPlayer->getRole() == 2)
            {
                teammateProbs.push_back(10);
                total+=10;
            }
            else if(currentPlayer->getRole() == 3)
            {
                teammateProbs.push_back(5);
                total+=5;
            }
        }
    }

    int teammatePick = rand()%total;
    int currentTotal = 0;
    for(int i = 0; i < 4; i++)
    {
        currentTotal+=teammateProbs[i];
        if(teammatePick < currentTotal)
        {
            return teammates[i];
        }
    }

    return NULL;
}