1/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
2#include "teamscore.h"
3
4#include <base/system.h>
5
6#include <engine/shared/config.h>
7
8CTeamsCore::CTeamsCore()
9{
10 Reset();
11}
12
13bool CTeamsCore::SameTeam(int ClientId1, int ClientId2) const
14{
15 return m_aTeam[ClientId1] == TEAM_SUPER || m_aTeam[ClientId2] == TEAM_SUPER || m_aTeam[ClientId1] == m_aTeam[ClientId2];
16}
17
18int CTeamsCore::Team(int ClientId) const
19{
20 return m_aTeam[ClientId];
21}
22
23void CTeamsCore::Team(int ClientId, int Team)
24{
25 dbg_assert(Team >= TEAM_FLOCK && Team < NUM_DDRACE_TEAMS, "Invalid Team: %d", Team);
26 m_aTeam[ClientId] = Team;
27}
28
29bool CTeamsCore::CanKeepHook(int ClientId1, int ClientId2) const
30{
31 if(m_aTeam[ClientId1] == (m_IsDDRace16 ? VANILLA_TEAM_SUPER : TEAM_SUPER) || m_aTeam[ClientId2] == (m_IsDDRace16 ? VANILLA_TEAM_SUPER : TEAM_SUPER) || ClientId1 == ClientId2)
32 return true;
33 return m_aTeam[ClientId1] == m_aTeam[ClientId2];
34}
35
36bool CTeamsCore::CanCollide(int ClientId1, int ClientId2) const
37{
38 if(m_aTeam[ClientId1] == (m_IsDDRace16 ? VANILLA_TEAM_SUPER : TEAM_SUPER) || m_aTeam[ClientId2] == (m_IsDDRace16 ? VANILLA_TEAM_SUPER : TEAM_SUPER) || ClientId1 == ClientId2)
39 return true;
40 if(m_aIsSolo[ClientId1] || m_aIsSolo[ClientId2])
41 return false;
42 return m_aTeam[ClientId1] == m_aTeam[ClientId2];
43}
44
45void CTeamsCore::Reset()
46{
47 m_IsDDRace16 = false;
48
49 for(int i = 0; i < MAX_CLIENTS; ++i)
50 {
51 if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO)
52 m_aTeam[i] = i;
53 else
54 m_aTeam[i] = TEAM_FLOCK;
55 m_aIsSolo[i] = false;
56 }
57}
58
59void CTeamsCore::SetSolo(int ClientId, bool Value)
60{
61 dbg_assert(ClientId >= 0 && ClientId < MAX_CLIENTS, "Invalid client id");
62 m_aIsSolo[ClientId] = Value;
63}
64
65bool CTeamsCore::GetSolo(int ClientId) const
66{
67 if(ClientId < 0 || ClientId >= MAX_CLIENTS)
68 return false;
69 return m_aIsSolo[ClientId];
70}
71