cCompetition.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:5k
- // RACE X
- //
- // Written by Mauricio Teichmann Ritter
- //
- // Copyright (C) 2002, Brazil. All rights reserved.
- //
- //
- #include "stdafx.h"
- #include "cCompetition.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- int comparepoints(const void* p1, const void* p2)
- {
- PLAYER_DATA *pData1, *pData2;
- pData1 = (PLAYER_DATA*) p1;
- pData2 = (PLAYER_DATA*)p2;
- if(pData1->m_iPoints < pData2->m_iPoints)
- return 1;
- if(pData1->m_iPoints > pData2->m_iPoints)
- return -1;
- return 0;
- }
- cCompetition::cCompetition()
- {
- m_iNumPlayers = 0;
- m_iNextRace = 0;
- }
- cCompetition::~cCompetition()
- {
- }
- void cCompetition::SetCompetitionMode(BOOL bActivate)
- {
- m_bCompetitionActive = bActivate;
- }
- BOOL cCompetition::GetCompetitionMode()
- {
- return m_bCompetitionActive;
- }
- void cCompetition::Reset()
- {
- m_iNumPlayers = 0;
- m_iNextRace = 0;
- }
- void cCompetition::AddPlayer(string sPlayerName, UINT iCarColor, int iControlType, BYTE bID, int iDPNID)
- {
- m_pPlayerData[m_iNumPlayers].m_sPlayerName = sPlayerName;
- m_pPlayerData[m_iNumPlayers].m_iPoints = 0;
- m_pPlayerData[m_iNumPlayers].m_iCarColor = iCarColor;
- m_pPlayerData[m_iNumPlayers].m_iControlType = iControlType;
- m_pPlayerData[m_iNumPlayers].m_bId = bID;
- m_pPlayerData[m_iNumPlayers].m_dpnid = iDPNID;
- m_pPlayerData[m_iNumPlayers].m_bPlayerIsReady = FALSE;
- m_iNumPlayers++;
- }
- /*string cCompetition::GetPlayerNameByColor(UINT iColor)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_iCarColor == iColor)
- return m_pPlayerData[i].m_sPlayerName;
- }
- return "";
- }
- string cCompetition::GetPlayerNameByPosition(int iPosition)
- {
- if(iPosition >= m_iNumPlayers)
- return "";
- return m_pPlayerData[iPosition].m_sPlayerName;
- }*/
- UINT cCompetition::GetColor(UINT iPosition)
- {
- if(iPosition >= m_iNumPlayers)
- return 0;
- return m_pPlayerData[iPosition].m_iCarColor;
- }
- string cCompetition::GetNextRace()
- {
- switch(m_iNextRace)
- {
- case 0:
- return "Track01.rxt";
- break;
- case 1:
- return "Track02.rxt";
- break;
- case 2:
- return "Track03.rxt";
- break;
- case 3:
- return "Track04.rxt";
- break;
- case 4:
- return "Track05.rxt";
- break;
- case 5:
- return "Track06.rxt";
- break;
- case 6:
- return "Track07.rxt";
- break;
- case 7:
- return "Track08.rxt";
- break;
- case 8:
- return "Track09.rxt";
- break;
- }
- return "";
- }
- void cCompetition::NextRace()
- {
- m_iNextRace++;
- }
- int cCompetition::GetPlayerPointsByPosition(int iPosition)
- {
- if(iPosition >= m_iNumPlayers)
- return 0;
-
- return m_pPlayerData[iPosition].m_iPoints;
- }
- int cCompetition::GetNumberOfCars()
- {
- return m_iNumPlayers;
- }
- void cCompetition::AddPointToPlayer(BYTE bID,int iPoints)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bId == bID)
- {
- m_pPlayerData[i].m_iPoints+=iPoints;
- qsort(m_pPlayerData, 4, sizeof(PLAYER_DATA), comparepoints);
- return;
- }
- }
-
- }
- int cCompetition::GetControlType(int iPosition)
- {
- if(iPosition >= m_iNumPlayers)
- return 0;
- return m_pPlayerData[iPosition].m_iControlType;
- }
- BOOL cCompetition::DPNIDExists(int iID)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_dpnid == iID)
- {
- return TRUE;
- }
- }
- return FALSE;
- }
- void cCompetition::SetPlayerColor(BYTE idPlayer, UINT iColor)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bId == idPlayer)
- {
- m_pPlayerData[i].m_iCarColor = iColor;
- return;
- }
- }
- }
- void cCompetition::SetPlayerName(BYTE idPlayer, char *sName)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bId == idPlayer)
- {
- m_pPlayerData[i].m_sPlayerName = sName;
- return;
- }
- }
- }
- DWORD cCompetition::GetPlayerColor(BYTE idPlayer)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bId == idPlayer)
- {
- return m_pPlayerData[i].m_iCarColor;
- }
- }
- return 0;
- }
- string cCompetition::GetPlayerName(BYTE idPlayer)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bId == idPlayer)
- {
- return m_pPlayerData[i].m_sPlayerName;
- }
- }
- return "";
- }
- int cCompetition::GetPlayerDPNID(BYTE idPlayer)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bId == idPlayer)
- {
- return m_pPlayerData[i].m_dpnid;
- }
- }
- return 0;
- //return m_pPlayerData[iIndex].m_bId;
- }
- BYTE cCompetition::GetPlayerID(int iIndex)
- {
- return m_pPlayerData[iIndex].m_bId;
- }
- BYTE cCompetition::GetPlayerIDbyDPNID(int iDPNID)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_dpnid == iDPNID)
- {
- return m_pPlayerData[i].m_bId;
- }
- }
- return 0;
- }
- void cCompetition::SetReadyState(BYTE bPlayerId, BOOL bReady)
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bId == bPlayerId)
- {
- m_pPlayerData[i].m_bPlayerIsReady = bReady;
- }
- }
- }
- void cCompetition::ResetReadyState()
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- m_pPlayerData[i].m_bPlayerIsReady = FALSE;
- }
- }
- BOOL cCompetition::AllPlayersReady()
- {
- for(int i=0;i<m_iNumPlayers;i++)
- {
- if(m_pPlayerData[i].m_bPlayerIsReady == FALSE)
- {
- return FALSE;
- }
- }
- return TRUE;
- }