2010-08-28 13:47:52 +00:00
|
|
|
#include "teams.h"
|
2010-11-06 22:54:35 +00:00
|
|
|
#include <engine/shared/config.h>
|
2010-08-28 13:47:52 +00:00
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
CGameTeams::CGameTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext)
|
|
|
|
{
|
2010-09-24 13:37:13 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
void CGameTeams::Reset()
|
|
|
|
{
|
2010-09-24 13:37:13 +00:00
|
|
|
m_Core.Reset();
|
2011-01-06 05:30:19 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
{
|
2010-08-28 13:47:52 +00:00
|
|
|
m_TeamState[i] = EMPTY;
|
|
|
|
m_TeeFinished[i] = false;
|
2010-11-06 22:54:35 +00:00
|
|
|
m_MembersCount[i] = 0;
|
2010-12-19 03:48:16 +00:00
|
|
|
m_LastChat[i] = 0;
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
void CGameTeams::OnCharacterStart(int id){
|
2010-08-28 20:53:42 +00:00
|
|
|
int Tick = Server()->Tick();
|
2010-12-19 03:48:16 +00:00
|
|
|
CCharacter* StartingChar = Character(id);
|
|
|
|
if(!StartingChar)
|
|
|
|
return;
|
|
|
|
if(StartingChar->m_DDRaceState == DDRACE_FINISHED)
|
|
|
|
StartingChar->m_DDRaceState = DDRACE_NONE;
|
|
|
|
if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER)
|
|
|
|
{
|
|
|
|
StartingChar->m_DDRaceState = DDRACE_STARTED;
|
|
|
|
StartingChar->m_StartTime = Tick;
|
|
|
|
StartingChar->m_RefreshTime = Tick;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool Waiting = false;
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
{
|
|
|
|
if(m_Core.Team(id) == m_Core.Team(i))
|
|
|
|
{
|
|
|
|
CCharacter* Char = Character(i);
|
|
|
|
if(Char->m_DDRaceState == DDRACE_FINISHED)
|
|
|
|
{
|
|
|
|
Waiting = true;
|
|
|
|
if(m_LastChat[id] + Server()->TickSpeed() + g_Config.m_SvChatDelay < Tick)
|
|
|
|
{
|
|
|
|
char aBuf[128];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "%s has finished and didn't go through start yet, wait for him or join another team.", Server()->ClientName(i));
|
|
|
|
GameServer()->SendChatTarget(id, aBuf);
|
|
|
|
m_LastChat[id] = Tick;
|
|
|
|
}
|
|
|
|
if(m_LastChat[i] + Server()->TickSpeed() + g_Config.m_SvChatDelay < Tick)
|
|
|
|
{
|
|
|
|
char aBuf[128];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "%s wants to start a new round, kill or walk to start.", Server()->ClientName(id));
|
|
|
|
GameServer()->SendChatTarget(i, aBuf);
|
|
|
|
m_LastChat[i] = Tick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_TeamState[m_Core.Team(id)] <= CLOSED && !Waiting)
|
|
|
|
{
|
2010-08-30 12:13:43 +00:00
|
|
|
ChangeTeamState(m_Core.Team(id), STARTED);
|
2010-12-19 03:48:16 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
{
|
|
|
|
if(m_Core.Team(id) == m_Core.Team(i))
|
|
|
|
{
|
2010-08-28 20:53:42 +00:00
|
|
|
CCharacter* Char = Character(i);
|
2010-12-19 03:48:16 +00:00
|
|
|
if(Char)
|
|
|
|
{
|
|
|
|
Char->m_DDRaceState = DDRACE_STARTED;
|
|
|
|
Char->m_StartTime = Tick;
|
|
|
|
Char->m_RefreshTime = Tick;
|
|
|
|
}
|
2010-08-28 20:53:42 +00:00
|
|
|
}
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
void CGameTeams::OnCharacterFinish(int id)
|
|
|
|
{
|
2010-12-19 03:48:16 +00:00
|
|
|
if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER)
|
|
|
|
{
|
2010-08-28 20:53:42 +00:00
|
|
|
Character(id)->OnFinish();
|
2010-12-19 03:48:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-28 13:47:52 +00:00
|
|
|
m_TeeFinished[id] = true;
|
2010-12-19 03:48:16 +00:00
|
|
|
if(TeamFinished(m_Core.Team(id)))
|
|
|
|
{
|
|
|
|
//ChangeTeamState(m_Core.Team(id), FINISHED);//TODO: Make it better
|
|
|
|
ChangeTeamState(m_Core.Team(id), OPEN);
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
{
|
|
|
|
if(m_Core.Team(id) == m_Core.Team(i))
|
|
|
|
{
|
2010-08-28 20:53:42 +00:00
|
|
|
CCharacter * Char = Character(i);
|
2010-12-19 03:48:16 +00:00
|
|
|
if(Char != 0)
|
|
|
|
{
|
2010-08-28 20:53:42 +00:00
|
|
|
Char->OnFinish();
|
|
|
|
m_TeeFinished[i] = false;
|
2010-12-19 03:48:16 +00:00
|
|
|
}
|
|
|
|
/*else
|
|
|
|
*{
|
|
|
|
* m_Core.Team(id) = 0; //i saw zomby =)
|
|
|
|
*}
|
|
|
|
*/
|
2010-08-28 20:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
bool CGameTeams::SetCharacterTeam(int id, int Team)
|
|
|
|
{
|
2010-09-14 20:36:48 +00:00
|
|
|
//Check on wrong parameters. +1 for TEAM_SUPER
|
2011-01-06 05:30:19 +00:00
|
|
|
if(id < 0 || id >= MAX_CLIENTS || Team < 0 || Team >= MAX_CLIENTS + 1)
|
2010-08-28 13:47:52 +00:00
|
|
|
return false;
|
2010-09-14 20:36:48 +00:00
|
|
|
//You can join to TEAM_SUPER at any time, but any other group you cannot if it started
|
2011-01-06 05:30:19 +00:00
|
|
|
if(Team != TEAM_SUPER && m_TeamState[Team] >= CLOSED)
|
2010-09-14 18:28:50 +00:00
|
|
|
return false;
|
2010-09-14 20:36:48 +00:00
|
|
|
//No need to switch team if you there
|
2011-01-06 05:30:19 +00:00
|
|
|
if(m_Core.Team(id) == Team)
|
2010-08-28 13:47:52 +00:00
|
|
|
return false;
|
2010-09-14 20:36:48 +00:00
|
|
|
//You cannot be in TEAM_SUPER if you not super
|
|
|
|
if(Team == TEAM_SUPER && !Character(id)->m_Super) return false;
|
|
|
|
//if you begin race
|
2011-01-06 05:30:19 +00:00
|
|
|
if(Character(id)->m_DDRaceState != DDRACE_NONE)
|
2010-09-14 20:36:48 +00:00
|
|
|
//you will be killed if you try to join FLOCK
|
2011-01-06 05:30:19 +00:00
|
|
|
if(Team == TEAM_FLOCK && m_Core.Team(id) != TEAM_FLOCK)
|
2010-09-14 17:05:18 +00:00
|
|
|
Character(id)->GetPlayer()->KillCharacter(WEAPON_GAME);
|
2011-01-06 05:30:19 +00:00
|
|
|
else if(Team != TEAM_SUPER)
|
|
|
|
return false;
|
2010-09-22 10:43:59 +00:00
|
|
|
SetForceCharacterTeam(id, Team);
|
2010-11-06 22:54:35 +00:00
|
|
|
|
|
|
|
|
2010-09-22 10:43:59 +00:00
|
|
|
//GameServer()->CreatePlayerSpawn(Character(id)->m_Core.m_Pos, TeamMask());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
void CGameTeams::SetForceCharacterTeam(int id, int Team)
|
|
|
|
{
|
2010-10-02 11:54:43 +00:00
|
|
|
m_TeeFinished[id] = false;
|
|
|
|
if(m_Core.Team(id) != TEAM_FLOCK
|
|
|
|
&& m_Core.Team(id) != TEAM_SUPER
|
2011-01-06 05:30:19 +00:00
|
|
|
&& m_TeamState[m_Core.Team(id)] != EMPTY)
|
|
|
|
{
|
2010-08-28 20:53:42 +00:00
|
|
|
bool NoOneInOldTeam = true;
|
2011-01-06 05:30:19 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
if(i != id && m_Core.Team(id) == m_Core.Team(i))
|
|
|
|
{
|
2010-08-28 20:53:42 +00:00
|
|
|
NoOneInOldTeam = false;//all good exists someone in old team
|
|
|
|
break;
|
|
|
|
}
|
2011-01-06 05:30:19 +00:00
|
|
|
if(NoOneInOldTeam)
|
2010-08-30 12:13:43 +00:00
|
|
|
m_TeamState[m_Core.Team(id)] = EMPTY;
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
2010-11-06 22:54:35 +00:00
|
|
|
if(Count(m_Core.Team(id)) > 0) m_MembersCount[m_Core.Team(id)]--;
|
2010-08-30 12:13:43 +00:00
|
|
|
m_Core.Team(id, Team);
|
2010-11-06 22:54:35 +00:00
|
|
|
if(m_Core.Team(id) != TEAM_SUPER) m_MembersCount[m_Core.Team(id)]++;
|
2011-01-06 05:30:19 +00:00
|
|
|
if(Team != TEAM_SUPER && m_TeamState[Team] == EMPTY)
|
2010-08-28 13:47:52 +00:00
|
|
|
ChangeTeamState(Team, OPEN);
|
2010-11-12 21:50:51 +00:00
|
|
|
dbg_msg1("Teams", "Id = %d Team = %d", id, Team);
|
|
|
|
|
2011-01-06 05:22:08 +00:00
|
|
|
for (int ClientID = 0; ClientID < MAX_CLIENTS; ++ClientID)
|
|
|
|
{
|
|
|
|
if(Character(ClientID) && Character(ClientID)->GetPlayer()->m_IsUsingDDRaceClient)
|
|
|
|
SendTeamsState(ClientID);
|
2010-11-12 21:50:51 +00:00
|
|
|
}
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
int CGameTeams::Count(int Team) const
|
|
|
|
{
|
2010-11-06 22:54:35 +00:00
|
|
|
if(Team == TEAM_SUPER) return -1;
|
|
|
|
return m_MembersCount[Team];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
void CGameTeams::ChangeTeamState(int Team, int State)
|
|
|
|
{
|
2010-08-28 13:47:52 +00:00
|
|
|
m_TeamState[Team] = State;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
bool CGameTeams::TeamFinished(int Team)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
if(m_Core.Team(i) == Team && !m_TeeFinished[i])
|
2010-08-28 13:47:52 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2010-09-08 16:22:11 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
int CGameTeams::TeamMask(int Team)
|
|
|
|
{
|
2010-09-14 20:36:48 +00:00
|
|
|
if(Team == TEAM_SUPER) return -1;
|
2010-09-08 16:22:11 +00:00
|
|
|
int Mask = 0;
|
2011-01-06 05:30:19 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
2010-11-06 16:54:59 +00:00
|
|
|
if((Character(i) && (m_Core.Team(i) == Team || m_Core.Team(i) == TEAM_SUPER))
|
2011-01-06 05:30:19 +00:00
|
|
|
|| (GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() == -1))
|
2010-09-08 16:22:11 +00:00
|
|
|
Mask |= 1 << i;
|
|
|
|
return Mask;
|
|
|
|
}
|
2010-10-24 10:47:25 +00:00
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
void CGameTeams::SendTeamsState(int Cid)
|
|
|
|
{
|
2010-10-24 10:47:25 +00:00
|
|
|
CNetMsg_Cl_TeamsState Msg;
|
|
|
|
Msg.m_Tee0 = m_Core.Team(0);
|
|
|
|
Msg.m_Tee1 = m_Core.Team(1);
|
|
|
|
Msg.m_Tee2 = m_Core.Team(2);
|
|
|
|
Msg.m_Tee3 = m_Core.Team(3);
|
|
|
|
Msg.m_Tee4 = m_Core.Team(4);
|
|
|
|
Msg.m_Tee5 = m_Core.Team(5);
|
|
|
|
Msg.m_Tee6 = m_Core.Team(6);
|
|
|
|
Msg.m_Tee7 = m_Core.Team(7);
|
|
|
|
Msg.m_Tee8 = m_Core.Team(8);
|
|
|
|
Msg.m_Tee9 = m_Core.Team(9);
|
|
|
|
Msg.m_Tee10 = m_Core.Team(10);
|
|
|
|
Msg.m_Tee11 = m_Core.Team(11);
|
|
|
|
Msg.m_Tee12 = m_Core.Team(12);
|
|
|
|
Msg.m_Tee13 = m_Core.Team(13);
|
|
|
|
Msg.m_Tee14 = m_Core.Team(14);
|
|
|
|
Msg.m_Tee15 = m_Core.Team(15);
|
|
|
|
|
|
|
|
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, Cid);
|
|
|
|
|
|
|
|
}
|