2010-08-28 13:47:52 +00:00
|
|
|
#include "teams.h"
|
|
|
|
|
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
CGameTeams::CGameTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext) {
|
2010-09-24 13:37:13 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameTeams::Reset() {
|
|
|
|
m_Core.Reset();
|
2010-08-28 13:47:52 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
m_TeamState[i] = EMPTY;
|
|
|
|
m_TeeFinished[i] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
void CGameTeams::OnCharacterStart(int id) {
|
2010-08-28 20:53:42 +00:00
|
|
|
int Tick = Server()->Tick();
|
2010-09-14 18:28:50 +00:00
|
|
|
if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER) {
|
2010-08-28 20:53:42 +00:00
|
|
|
CCharacter* Char = Character(id);
|
|
|
|
Char->m_RaceState = RACE_STARTED;
|
|
|
|
Char->m_StartTime = Tick;
|
|
|
|
Char->m_RefreshTime = Tick;
|
|
|
|
} else {
|
2010-08-30 12:13:43 +00:00
|
|
|
if(m_TeamState[m_Core.Team(id)] <= CLOSED) {
|
|
|
|
ChangeTeamState(m_Core.Team(id), STARTED);
|
2010-08-28 20:53:42 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
2010-09-14 20:36:48 +00:00
|
|
|
if(m_Core.Team(id) == m_Core.Team(i)) {
|
2010-08-28 20:53:42 +00:00
|
|
|
CCharacter* Char = Character(i);
|
2010-08-28 13:47:52 +00:00
|
|
|
|
2010-08-28 20:53:42 +00:00
|
|
|
Char->m_RaceState = RACE_STARTED;
|
|
|
|
Char->m_StartTime = Tick;
|
|
|
|
Char->m_RefreshTime = Tick;
|
|
|
|
}
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
void CGameTeams::OnCharacterFinish(int id) {
|
2010-09-14 18:28:50 +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-08-28 13:47:52 +00:00
|
|
|
} else {
|
|
|
|
m_TeeFinished[id] = true;
|
2010-08-30 12:13:43 +00:00
|
|
|
if(TeamFinished(m_Core.Team(id))) {
|
|
|
|
ChangeTeamState(m_Core.Team(id), FINISHED);//TODO: Make it better
|
2010-08-28 20:53:42 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
2010-09-14 20:36:48 +00:00
|
|
|
if(m_Core.Team(id) == m_Core.Team(i)) {
|
2010-08-28 20:53:42 +00:00
|
|
|
CCharacter * Char = Character(i);
|
|
|
|
if(Char != 0) {
|
|
|
|
Char->OnFinish();
|
|
|
|
m_TeeFinished[i] = false;
|
|
|
|
} //else {
|
2010-08-30 12:13:43 +00:00
|
|
|
// m_Core.Team(id) = 0; //i saw zomby =)
|
2010-08-28 20:53:42 +00:00
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 12:13:43 +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
|
2010-09-14 18:28:50 +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
|
2010-09-14 18:28:50 +00:00
|
|
|
if(Team != TEAM_SUPER && m_TeamState[Team] >= CLOSED) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-14 20:36:48 +00:00
|
|
|
//No need to switch team if you there
|
|
|
|
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
|
2010-09-14 17:05:18 +00:00
|
|
|
if(Character(id)->m_RaceState != RACE_NONE) {
|
2010-09-14 20:36:48 +00:00
|
|
|
//you will be killed if you try to join FLOCK
|
2010-09-14 18:28:50 +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);
|
|
|
|
} else {
|
2010-09-21 19:09:11 +00:00
|
|
|
if(Team != TEAM_SUPER) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-14 17:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-22 10:43:59 +00:00
|
|
|
SetForceCharacterTeam(id, Team);
|
|
|
|
char aBuf[512];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "Id = %d Team = %d", id, Team);
|
|
|
|
dbg_msg("Teams", aBuf);
|
|
|
|
//GameServer()->CreatePlayerSpawn(Character(id)->m_Core.m_Pos, TeamMask());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
&& m_TeamState[m_Core.Team(id)] != EMPTY) {
|
2010-08-28 20:53:42 +00:00
|
|
|
bool NoOneInOldTeam = true;
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
2010-09-14 20:36:48 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(NoOneInOldTeam) {
|
2010-08-30 12:13:43 +00:00
|
|
|
m_TeamState[m_Core.Team(id)] = EMPTY;
|
2010-08-28 20:53:42 +00:00
|
|
|
}
|
2010-08-28 13:47:52 +00:00
|
|
|
}
|
2010-08-30 12:13:43 +00:00
|
|
|
m_Core.Team(id, Team);
|
2010-09-14 18:28:50 +00:00
|
|
|
if(Team != TEAM_SUPER && m_TeamState[Team] == EMPTY) {
|
2010-08-28 13:47:52 +00:00
|
|
|
ChangeTeamState(Team, OPEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
void CGameTeams::ChangeTeamState(int Team, int State) {
|
2010-08-28 13:47:52 +00:00
|
|
|
m_TeamState[Team] = State;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
bool CGameTeams::TeamFinished(int Team) {
|
2010-08-28 13:47:52 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
2010-08-30 12:13:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
2010-10-23 12:15:29 +00:00
|
|
|
if(Character(i) && (m_Core.Team(i) == Team || m_Core.Team(i) == TEAM_SUPER)) {
|
2010-09-08 16:22:11 +00:00
|
|
|
Mask |= 1 << i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Mask;
|
|
|
|
}
|