Beispiel #1
0
void CGameControllerCSBB::Tick()
{
	IGameController::Tick();

	
	if(GameServer()->m_World.m_ResetRequested || GameServer()->m_World.m_Paused)
		return;	

	m_RoundTick++;
		
	// no actual players (bots kicked if human_players == 0)
	if (CountPlayers() < 1 || m_NewGame)
	{
		GameServer()->m_CanRespawn = true;
	
		if (m_Round != 0 || m_GameState != CSBB_NEWBASE)
			Restart();
		
		m_RoundTick = 0;
	}
	else
	{
		if (CountPlayers() == 1)
		{
			Restart();
			AutoBalance();
			return;
		}
		
		AutoBalance();
		
		if (m_GameState == CSBB_NEWBASE)
		{
			CaptureBase();
			
			if (GameServer()->m_pArrow)
			{
				GameServer()->m_pArrow->m_Hide = false;
				GameServer()->m_pArrow->m_Target = m_apBombArea[m_Base]->m_Pos;
			}
		}
		if (m_GameState == CSBB_DEFENDING)
		{

			if (GameServer()->m_pArrow)
			{
				GameServer()->m_pArrow->m_Hide = false;
				GameServer()->m_pArrow->m_Target = m_apBombArea[m_Base]->m_Pos;
			}
			
			RoundWinLose();
		}
		if (m_GameState == CSBB_ENDING)
		{
			if (m_RoundTick >= g_Config.m_SvPreroundTime*Server()->TickSpeed())
			{
				if (m_aTeamscore[TEAM_RED] >= g_Config.m_SvNumRounds || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvNumRounds)
				{
					EndRound();
					m_NewGame = true;
					return;
				}
				
				NewBase();
				//AutoBalance();
				
				if (GameServer()->m_pArrow)
					GameServer()->m_pArrow->m_Hide = true;
				

			}
		}
	}
	
	
	
	


	GameServer()->UpdateAI();

	

	// warm welcome
	for (int c = 0; c < MAX_CLIENTS; c++)
	{
		CPlayer *pPlayer = GameServer()->m_apPlayers[c];
		if(!pPlayer)
			continue;
		
		if (!pPlayer->m_Welcomed && !pPlayer->m_IsBot)
		{
			GameServer()->SendBroadcast("Welcome to Counter-Strike: Base Bombing", pPlayer->GetCID(), true);
			pPlayer->m_Welcomed = true;
		}
	}
	
	
	
	
	// the bomb (red flag)
	CBomb *B = m_pBomb;
	
	if (!B)
		return;
	
	
	
	/*
	// always update bomb position
	if(B->m_pCarryingCharacter)
	{
		B->m_Pos = B->m_pCarryingCharacter->m_Pos;
	}
	else
	{
		if (B->m_Status == BOMB_CARRYING || B->m_Status == BOMB_IDLE)
		{
			B->m_Vel.y += GameServer()->m_World.m_Core.m_Tuning.m_Gravity;
			GameServer()->Collision()->MoveBox(&B->m_Pos, &B->m_Vel, vec2(B->ms_PhysSize, B->ms_PhysSize), 0.5f);
			B->m_Status = BOMB_IDLE;
		}
	}
	*/
	
	
	if (m_Timeout || m_BombDefused || m_GameState != CSBB_DEFENDING)
		return;

	
	if (B->m_Status == BOMB_PLANTED)
	{
		B->m_Timer++;
		
		// bomb ticking sound
		int Time = Server()->TickSpeed();
		
		if (Server()->TickSpeed() / 30 + GetTimeLeft()*8 < Time)
			Time = Server()->TickSpeed() / 20 + GetTimeLeft()*4;
		
		if (++m_BombSoundTimer >= Time)
		{
			m_BombSoundTimer = 0;
			GameServer()->CreateSound(B->m_Pos, SOUND_CHAT_SERVER);
			GameServer()->CreateSound(B->m_Pos, SOUND_CHAT_SERVER);
		}
		
		// bomb defusing
		//CCharacter *apCloseCCharacters[MAX_CLIENTS];
		//int Num = GameServer()->m_World.FindEntities(B->m_Pos, CFlag::ms_PhysSize * 2, (CEntity**)apCloseCCharacters, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
		
		bool DefusingBomb = false;
		
		for (int i = 0; i < MAX_CLIENTS; i++)
		{
			CPlayer *pPlayer = GameServer()->m_apPlayers[i];
			if(!pPlayer)
				continue;

			CCharacter *pCharacter = pPlayer->GetCharacter();
			if (!pCharacter)
				continue;
		
			if(!pCharacter->IsAlive() || pPlayer->GetTeam() != m_DefendingTeam)
				continue;
			
			// check distance
			if (abs(pCharacter->m_Pos.x - B->m_Pos.x) < 150 && abs(pCharacter->m_Pos.y - B->m_Pos.y) < 150 &&
				pCharacter->IsGrounded())
			{
				DefusingBomb = true;
				m_aDefusing[i] = true;
				
				pPlayer->m_InterestPoints += 7;
							
				if (m_BombDefuseTimer == 0)
				{
					GameServer()->SendBroadcast("Defusing bomb", pPlayer->GetCID());
					//GameServer()->CreateSoundGlobal(SOUND_CTF_DROP, pPlayer->GetCID());
				}
			}
			else
			{
				if (m_aDefusing[i])
				{
					m_aDefusing[i] = false;
					GameServer()->SendBroadcast("", pPlayer->GetCID());
				}
			}
		}
		
		if (DefusingBomb)
		{
			// bomb defusing sound
			if (++m_BombActionTimer >= Server()->TickSpeed()/4)
			{
				m_BombActionTimer = 0;
				GameServer()->CreateSound(B->m_Pos, SOUND_BODY_LAND);
			}
			
			if (++m_BombDefuseTimer >= g_Config.m_SvBombDefuseTime*Server()->TickSpeed())
			{
				B->m_Hide = true;
				m_BombDefused = true;
				if (m_DefendingTeam == TEAM_RED)
					GameServer()->SendBroadcast("Bomb defused - Terrorists score!", -1, true);
				if (m_DefendingTeam == TEAM_BLUE)
					GameServer()->SendBroadcast("Bomb defused - Counter-terrorists score!", -1, true);
				GameServer()->CreateSoundGlobal(SOUND_CTF_GRAB_PL, -1);
							
				m_RoundTimeLimit = 0; // gamecontroller
				m_ResetTime = true; // gamecontroller
			}
		}
		else
		{
			m_BombDefuseTimer = 0;
		}
		
		return;
	}
	else
	{
		for (int c = 0; c < MAX_CLIENTS; c++)
		{
			bool BombPlantable = false;
			CPlayer *pPlayer = GameServer()->m_apPlayers[c];
			if(!pPlayer)
				continue;
			
			if(pPlayer->GetTeam() == m_DefendingTeam)
				continue;

			CCharacter *pCharacter = pPlayer->GetCharacter();
			if (!pCharacter)
				continue;
		
			if(!pCharacter->IsAlive() || pPlayer->GetTeam() == m_DefendingTeam)
				continue;
				
			if (m_Base >= 0)
			{
				if (m_apBombArea[m_Base] && !m_apBombArea[m_Base]->m_Hide)
				{
					
					// check distance
					if (abs(m_apBombArea[m_Base]->m_Pos.x - pCharacter->m_Pos.x) < 200 && abs(m_apBombArea[m_Base]->m_Pos.y - pCharacter->m_Pos.y) < 200 &&
						pCharacter->IsGrounded())
					{
						BombPlantable = true;
						//GameServer()->SendBroadcast("Inside range", pPlayer->GetCID());
						
						if (pCharacter->m_BombStatus != BOMB_PLANTING)
						{
							pCharacter->m_BombStatus = BOMB_PLANTING;
							m_aPlanting[c] = 0;
							
							GameServer()->SendBroadcast("Planting bomb", pPlayer->GetCID());
						}
						else if (pCharacter->m_BombStatus == BOMB_PLANTING)
						{
							// bomb planting sound
							if (++m_aBombActionTimer[c] >= Server()->TickSpeed()/4)
							{
								m_aBombActionTimer[c] = 0;
								GameServer()->CreateSound(B->m_Pos, SOUND_BODY_LAND);
							}
							
							pPlayer->m_InterestPoints += 6;
							
							if (++m_aPlanting[c] >= g_Config.m_SvBombPlantTime*Server()->TickSpeed())
							{
								pPlayer->m_InterestPoints += 120;
								
								B->m_pCarryingCharacter = NULL;
								B->m_Status = BOMB_PLANTED;
								pCharacter->m_BombStatus = BOMB_PLANTED;
								m_aPlanting[c] = 0;
								B->m_Timer = 0;
								GameServer()->SendBroadcast("Bomb planted!", -1, true);
								GameServer()->CreateSoundGlobal(SOUND_CTF_GRAB_PL, -1);
								
								B->m_Hide = false;
								B->m_Pos = pCharacter->m_Pos;
								B->m_Owner = c;
								
								m_RoundTimeLimit = g_Config.m_SvBombTime; // gamecontroller
								m_ResetTime = true; // gamecontroller
								
								return;
							}
						}
					}
				}
			}
			
			if (!BombPlantable)
			{
				pCharacter->m_BombStatus = BOMB_CARRYING;
				if (m_aPlanting[c] > 0)
					GameServer()->SendBroadcast("", c);
				
				m_aPlanting[c] = 0;
			}
		}
	}


	// don't add anything relevant here! possible return; above!
}