Exemplo n.º 1
0
// --------------------------------------------------------------------------- //
//
//	ROUTINE:	TeamBalancer::BalanceTeamScore
//
//	PURPOSE:	balance teams by using playground sorting based on player scores
//
// --------------------------------------------------------------------------- //
bool TeamBalancer::BalanceTeamScore()
{

	m_nRoundsSinceScoreBalance = 0;

	bool bDoSort = false;


	//figure out the score difference
	int32 nDiff = LTDIFF(m_nTeamScores[0],m_nTeamScores[1]);
	if (nDiff > 0)
	{
		ServerConnectionMgr::GameClientDataList& gameClientDataList = ServerConnectionMgr::Instance( ).GetGameClientDataList( );
		//for 2 or fewer players don't bother doing a complicated sort, just balance the team sizes if needed
//		if (gameClientDataList.size() <= 2)
//		{
//			BalanceTeamSize();
//		}
//		else
		{
			int32 nLower = LTMIN(m_nTeamScores[0],m_nTeamScores[1]);

			//if the lower score is 0, treat it as one for these calculations to avoid divide by 0 errors
			if (nLower == 0)
			{
				nLower = 1;
			}

			//how much did the winners win by? This formula 1+(diff/lower) is used instead of
			//	(high/low) in order to handle 0 and negative high score more cleanly
			float fRatio = 1.0f + (float)nDiff/ (float)LTAbs(nLower);
			
			//see if the margin was wide enough to trigger a shuffle
			bDoSort = (fRatio >= GameModeMgr::Instance().m_grfTeamScoreBalancingPercent);
		}

	}

	if (bDoSort)
	{
		PlaygroundSort();

		CAutoMessage cClientMsg;
		cClientMsg.Writeuint8(MID_PLAYER_EVENT);
		cClientMsg.Writeuint8(kPEAutobalance);
		cClientMsg.Writebool( true ); //did score balancing
		g_pLTServer->SendToClient(cClientMsg.Read(), NULL, MESSAGE_GUARANTEED);

	}

	//chear the history, whether or not we actually sorted
	m_nTeamScores[0] = 0;
	m_nTeamScores[1] = 0;
	m_vecPlayerScores.clear();

	return bDoSort;
}
Exemplo n.º 2
0
// Setup the resolution control based on the currently selected resolution
void CScreenDisplay::SetupResolutionCtrl()
{
	if (!m_pResolutionCtrl)
	{
		return;
	}


	// Get the selected renderer
	int nResolutionIndex=m_pResolutionCtrl->GetSelIndex();

	// Clear the current resolutions
	m_pResolutionCtrl->RemoveAll();
    uint32 dwOldWidth=0;
    uint32 dwOldHeight=0;
    uint32 dwOldBitDepth=0;
    uint32 dwCurWidth = 0;
    uint32 dwCurHeight = 0;
    uint32 dwCurBitDepth = 0;
	int	 nNewRes = 0;

	unsigned int nResolutions=m_rendererData.m_resolutionArray.GetSize();

	if ((unsigned int)nResolutionIndex < nResolutions)
	{
		dwOldWidth=m_rendererData.m_resolutionArray[nResolutionIndex].m_dwWidth;
		dwOldHeight=m_rendererData.m_resolutionArray[nResolutionIndex].m_dwHeight;
		dwOldBitDepth=m_rendererData.m_resolutionArray[nResolutionIndex].m_dwBitDepth;
	}


	// Add each resolution
	unsigned int i;
	for (i=0; i < nResolutions; i++)
	{
        uint32 dwWidth=m_rendererData.m_resolutionArray[i].m_dwWidth;
        uint32 dwHeight=m_rendererData.m_resolutionArray[i].m_dwHeight;
        uint32 dwBitDepth=m_rendererData.m_resolutionArray[i].m_dwBitDepth;

        if (    LTDIFF(dwWidth,dwOldWidth) <= LTDIFF(dwCurWidth,dwOldWidth) &&
                LTDIFF(dwHeight,dwOldHeight) <= LTDIFF(dwCurHeight,dwOldHeight) &&
                LTDIFF(dwBitDepth,dwOldBitDepth) < LTDIFF(dwCurBitDepth,dwOldBitDepth)
				)
		{
			nNewRes = i;
			dwCurWidth = dwWidth;
			dwCurHeight = dwHeight;
			dwCurBitDepth = dwBitDepth;
		}
		// Load the resolution format string.  This is "Resolution: [%dx%dx%d]" in English
		m_pResolutionCtrl->AddString(FormatTempString(IDS_DMODE_RESOLUTION, dwWidth, dwHeight, dwBitDepth));
	}

	m_pResolutionCtrl->SetSelIndex(nNewRes);

}
// Setup the resolution control based on the currently selected resolution
void CFolderDisplay::SetupResolutionCtrl()
{
	if (!m_pRendererCtrl || !m_pResolutionCtrl)
	{
		return;
	}


	// Get the selected renderer
	int nRendererIndex=m_pRendererCtrl->GetSelIndex();
	int nResolutionIndex=m_pResolutionCtrl->GetSelIndex();

	// Clear the current resolutions
	m_pResolutionCtrl->RemoveAll();
    uint32 dwOldWidth=0;
    uint32 dwOldHeight=0;
    uint32 dwOldBitDepth=0;
    uint32 dwCurWidth = 0;
    uint32 dwCurHeight = 0;
    uint32 dwCurBitDepth = 0;
	int	 nNewRes = 0;

	// Get the number of resolutions
	if (nRendererIndex < 0 || nRendererIndex > (int)m_rendererArray.GetSize()-1)
	{
		return;
	}

	unsigned int nResolutions=m_rendererArray[nRendererIndex].m_resolutionArray.GetSize();

	if ((unsigned int)nResolutionIndex < nResolutions)
	{
		dwOldWidth=m_rendererArray[nRendererIndex].m_resolutionArray[nResolutionIndex].m_dwWidth;
		dwOldHeight=m_rendererArray[nRendererIndex].m_resolutionArray[nResolutionIndex].m_dwHeight;
		dwOldBitDepth=m_rendererArray[nRendererIndex].m_resolutionArray[nResolutionIndex].m_dwBitDepth;
	}


	// Add each resolution
	unsigned int i;
	for (i=0; i < nResolutions; i++)
	{
        uint32 dwWidth=m_rendererArray[nRendererIndex].m_resolutionArray[i].m_dwWidth;
        uint32 dwHeight=m_rendererArray[nRendererIndex].m_resolutionArray[i].m_dwHeight;
        uint32 dwBitDepth=m_rendererArray[nRendererIndex].m_resolutionArray[i].m_dwBitDepth;

        if (    LTDIFF(dwWidth,dwOldWidth) <= LTDIFF(dwCurWidth,dwOldWidth) &&
                LTDIFF(dwHeight,dwOldHeight) <= LTDIFF(dwCurHeight,dwOldHeight) &&
                LTDIFF(dwBitDepth,dwOldBitDepth) < LTDIFF(dwCurBitDepth,dwOldBitDepth)
				)
		{
			nNewRes = i;
			dwCurWidth = dwWidth;
			dwCurHeight = dwHeight;
			dwCurBitDepth = dwBitDepth;
		}
		// Load the resolution format string.  This is "Resolution: [%dx%dx%d]" in English
        HSTRING hResolutionFormat=g_pLTClient->FormatString(IDS_DMODE_RESOLUTION, dwWidth, dwHeight, dwBitDepth);
		m_pResolutionCtrl->AddString(hResolutionFormat);
        g_pLTClient->FreeString(hResolutionFormat);
	}

	m_pResolutionCtrl->SetSelIndex(nNewRes);

}
Exemplo n.º 4
0
// --------------------------------------------------------------------------- //
//
//	ROUTINE:	TeamBalancer::BalanceTeamSize
//
//	PURPOSE:	balance team sizes by moving the lowest score player(s) from the larger team
//
// --------------------------------------------------------------------------- //
bool TeamBalancer::BalanceTeamSize()
{
	bool bMovedPlayer = false;
	uint32 nTeamSizes[2] = {0,0};
	for (uint8 nTeam = 0;nTeam < 2;++nTeam)
	{
		CTeam* pTeam = CTeamMgr::Instance( ).GetTeam(nTeam);
		if (pTeam)
		{
			nTeamSizes[nTeam] = pTeam->GetNumPlayers();
		}
	}

	//check to see if one team is larger by at least 2 people
	if (LTDIFF(nTeamSizes[0],nTeamSizes[1]) > 1)
	{
		uint8 nLargerTeam = ((nTeamSizes[0] < nTeamSizes[1]) ? 1 : 0);
		uint8 nSmallerTeam = (nLargerTeam + 1) % MAX_TEAMS;

		//make a list of players on the team
		PlayerScoreHistoryArray vecScores;
		ServerConnectionMgr::GameClientDataList& gameClientDataList = ServerConnectionMgr::Instance( ).GetGameClientDataList( );
		ServerConnectionMgr::GameClientDataList::iterator iter = gameClientDataList.begin( );
		for( ; iter != gameClientDataList.end( ); iter++ )
		{
			GameClientData* pGameClientData = *iter;
			if( !pGameClientData->GetClient( ))
				continue;

			//if player is on the larger team, add him to our list
			if (nLargerTeam == pGameClientData->GetLastTeamId())
			{
				PlayerScoreHistory pairScore;
				pairScore.first = g_pLTServer->GetClientID(pGameClientData->GetClient( ));
				pairScore.second = 0;
				CPlayerScore* pScore = pGameClientData->GetPlayerScore(); 
				if (pScore)
				{
					pairScore.second = pScore->GetScore();
				}
				vecScores.push_back(pairScore);
			}
		}
		//sort the player list from highest to lowest
		std::sort(vecScores.begin(),vecScores.end(),PlayerScoreHistoryCompare());

		//while the teams are still unbalanced move lowest scoring players from the larger team to the smaller
		PlayerScoreHistoryArray::reverse_iterator scoreIter = vecScores.rbegin();
		while (LTDIFF(nTeamSizes[nLargerTeam],nTeamSizes[nSmallerTeam]) > 1 && scoreIter != vecScores.rend())
		{
			
			uint32 nID = scoreIter->first;
			GameClientData* pGameClientData = ServerConnectionMgr::Instance().GetGameClientDataByClientId(nID);

			if (pGameClientData)
			{
				pGameClientData->SetRequestedTeam(nSmallerTeam);
				CPlayerObj* pPlayer = (CPlayerObj*)g_pLTServer->HandleToObject(pGameClientData->GetPlayer());
				if (pPlayer)
				{
					pPlayer->HandleTeamSwitchRequest();
				}
				//shrink the larger team and grow the smaller
				nTeamSizes[nLargerTeam]--;
				nTeamSizes[nSmallerTeam]++;

				bMovedPlayer = true;
			}
			scoreIter++;
		}
	}

	if (bMovedPlayer)
	{
		CAutoMessage cClientMsg;
		cClientMsg.Writeuint8(MID_PLAYER_EVENT);
		cClientMsg.Writeuint8(kPEAutobalance);
		cClientMsg.Writebool( false ); //didn't do score balancing
		g_pLTServer->SendToClient(cClientMsg.Read(), NULL, MESSAGE_GUARANTEED);
	}

	return bMovedPlayer;
}