Advertisement
Guest User

Untitled

a guest
May 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. void IGameController::DoPlayerNumWincheck()
  2. {
  3.     if(m_GameOverTick != -1 || m_Warmup)
  4.         return;
  5.     // get winning team
  6.     int FirstFoundTeam = -1;
  7.     int NumPlayers = 0;
  8.     bool MoreThanOneTeam = false;
  9.     // gather some stats
  10.     int Topscore = 0;
  11.     int TopscoreCount = 0;
  12.     int TopID = -1;
  13.     for(int i = 0; i < MAX_CLIENTS; i++)
  14.     {
  15.         if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() > -1)
  16.         {
  17.             NumPlayers++;
  18.             if(GameServer()->m_apPlayers[i]->m_Score > Topscore)
  19.             {
  20.                 Topscore = GameServer()->m_apPlayers[i]->m_Score;
  21.                 TopscoreCount = 1;
  22.                 TopID = i;
  23.             }
  24.             else if(GameServer()->m_apPlayers[i]->m_Score == Topscore)
  25.                 TopscoreCount++;
  26.         }
  27.         else
  28.             continue;
  29.            
  30.         if(FirstFoundTeam < 0)
  31.         {
  32.             FirstFoundTeam = GameServer()->m_apPlayers[i]->m_CatchingTeam;
  33.             continue;
  34.         }
  35.  
  36.         // if more than 1 team ingame dont end round
  37.         if(GameServer()->m_apPlayers[i]->m_CatchingTeam != FirstFoundTeam)
  38.             MoreThanOneTeam = true;
  39.     }
  40.    
  41.     // check score win condition
  42.     if((g_Config.m_SvScorelimit > 0 && Topscore >= g_Config.m_SvScorelimit) ||
  43.         (g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
  44.     {
  45.         if(TopscoreCount == 1)
  46.         {
  47.             char buf[1024];
  48.             str_format(buf, sizeof(buf), "%s won the game. A new round start", Server()->ClientName(TopID));
  49.             GameServer()->SendBroadcast(buf, -1);
  50.             GameServer()->SendChatTarget(-1, buf);
  51.             m_RoundRestart = true;
  52.             EndRound();
  53.         }
  54.         else
  55.             m_SuddenDeath = 1;
  56.     }
  57.  
  58.     // get the winner
  59.     if(NumPlayers > 1 && !MoreThanOneTeam)
  60.     {
  61.         int Winner = -1;
  62.         for(int i = 0; i < MAX_CLIENTS; i++)
  63.             if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->m_BaseCatchingTeam == FirstFoundTeam)
  64.                 Winner = i;
  65.        
  66.         if(Winner > -1)
  67.         {
  68.             char buf[1024];
  69.             str_format(buf, sizeof(buf), "%s's Team wins", Server()->ClientName(Winner));
  70.             GameServer()->SendBroadcast(buf, -1);
  71.             GameServer()->SendChatTarget(-1, buf);
  72.             GameServer()->m_apPlayers[Winner]->m_Score += g_Config.m_SvScoreIncrease;
  73.             EndRound();
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement