diff options
| author | Tom Adams <Tom_Adams@web.de> | 2010-05-31 20:35:47 +0000 |
|---|---|---|
| committer | Tom Adams <Tom_Adams@web.de> | 2010-05-31 20:35:47 +0000 |
| commit | c9ff80a17d1bdb2632c13696af71a1352fdf9f20 (patch) | |
| tree | 951d6b18f4ccefc04e0a07a915f551c598d7175d /src/game/server | |
| parent | 6fca512a9550967e86e0c0735dcb01619f5c248a (diff) | |
| download | zcatch-c9ff80a17d1bdb2632c13696af71a1352fdf9f20.tar.gz zcatch-c9ff80a17d1bdb2632c13696af71a1352fdf9f20.zip | |
made balance teams based apun points/minute (#495)
Diffstat (limited to 'src/game/server')
| -rw-r--r-- | src/game/server/gamecontroller.cpp | 18 | ||||
| -rw-r--r-- | src/game/server/player.cpp | 2 | ||||
| -rw-r--r-- | src/game/server/player.h | 1 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index a822f7ca..519a28ae 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -285,6 +285,7 @@ void IGameController::PostReset() { GameServer()->m_apPlayers[i]->Respawn(); GameServer()->m_apPlayers[i]->m_Score = 0; + GameServer()->m_apPlayers[i]->m_ScoreStartTick = Server()->Tick(); } } } @@ -399,13 +400,16 @@ void IGameController::Tick() dbg_msg("game", "Balancing teams"); int aT[2] = {0,0}; - int aTScore[2] = {0,0}; + float aTScore[2] = {0,0}; + float aPScore[MAX_CLIENTS] = {0.0f}; for(int i = 0; i < MAX_CLIENTS; i++) { if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != -1) { aT[GameServer()->m_apPlayers[i]->GetTeam()]++; - aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += GameServer()->m_apPlayers[i]->m_Score; + aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/ + (Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick); + aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i]; } } @@ -421,23 +425,23 @@ void IGameController::Tick() int PD = aTScore[M]; for(int i = 0; i < MAX_CLIENTS; i++) { - if(!GameServer()->m_apPlayers[i]) - continue; - if(!CanBeMovedOnBalance(i)) + if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i)) continue; // remember the player who would cause lowest score-difference - if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+GameServer()->m_apPlayers[i]->m_Score) - (aTScore[M]-GameServer()->m_apPlayers[i]->m_Score)) < PD)) + if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])) < PD)) { pP = GameServer()->m_apPlayers[i]; - PD = absolute((aTScore[M^1]+pP->m_Score) - (aTScore[M]-pP->m_Score)); + PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])); } } // move the player to other team without losing his score // TODO: change in player::set_team needed: player won't lose score on team-change int ScoreBefore = pP->m_Score; + int ScoreStartTickBefore = pP->m_ScoreStartTick; pP->SetTeam(M^1); pP->m_Score = ScoreBefore; + pP->m_ScoreStartTick = ScoreStartTickBefore; pP->Respawn(); pP->m_ForceBalanced = true; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 0eb61cac..8e58b7c1 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -11,6 +11,7 @@ CPlayer::CPlayer(CGameContext *pGameServer, int CID, int Team) m_pGameServer = pGameServer; m_RespawnTick = Server()->Tick(); m_DieTick = Server()->Tick(); + m_ScoreStartTick = Server()->Tick(); Character = 0; this->m_ClientID = CID; m_Team = GameServer()->m_pController->ClampTeam(Team); @@ -157,6 +158,7 @@ void CPlayer::SetTeam(int Team) KillCharacter(); m_Team = Team; m_Score = 0; + m_ScoreStartTick = Server()->Tick(); // we got to wait 0.5 secs before respawning m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2; dbg_msg("game", "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team); diff --git a/src/game/server/player.h b/src/game/server/player.h index 1b631d45..ca7ab072 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -60,6 +60,7 @@ public: int m_RespawnTick; int m_DieTick; int m_Score; + int m_ScoreStartTick; bool m_ForceBalanced; private: |