forked from SwagSoftware/Kisak-Strike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.cpp
169 lines (134 loc) · 3.25 KB
/
game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//===== Copyright © 1996-2009, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#include "game.h"
#include "gamemanager.h"
#include "matchsystem.h"
#include "playermanager.h"
#include "matchmaking.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
CMatchGame::CMatchGame()
{
}
CMatchGame::~CMatchGame()
{
}
void CMatchGame::Reset()
{
RemoveAllPlayers();
}
XNKID CMatchGame::GetXNKID()
{
return (XNKID) g_pMatchmaking->GetSessionXNKID();
}
int CMatchGame::GetNumPlayers()
{
return m_PlayerList.Count();
}
IPlayer * CMatchGame::GetPlayer( int index )
{
if ( m_PlayerList.IsValidIndex( index ) )
return m_PlayerList[index];
else
return NULL;
}
void CMatchGame::AddPlayer( XUID xuid, int pExperience[ MATCH_MAX_DIFFICULTIES ] /*= NULL*/, int pSkills[ MATCH_MAX_DIFFICULTIES ][ MATCH_MAX_SKILL_FIELDS ] /*= NULL*/ )
{
if ( MM_IsDebug() )
{
Msg( "[L4DMM] CMatchGame::AddPlayer( %llx )\n", xuid );
}
IPlayer * player = g_pPlayerManager->FindPlayer( xuid );
if ( !player )
{
Warning( "[L4DMM] CMatchGame::AddPlayer - Cannot find player by %llx!\n", xuid );
return;
}
// Find a player first
for ( int k = 0; k < m_PlayerList.Count(); ++ k )
{
if( m_PlayerList[k]->GetXUID() == xuid )
{
Warning( "[L4DMM] CMatchGame::AddPlayer - player %llx already added!\n", xuid );
return;
}
}
m_PlayerList.AddToTail( player );
}
void CMatchGame::RemovePlayer( XUID xuid )
{
if ( MM_IsDebug() )
{
Msg( "[L4DMM] CMatchGame::RemovePlayer( %llx )\n", xuid );
}
int numRemoved = 0;
for ( int k = 0; k < m_PlayerList.Count(); ++ k )
{
if( m_PlayerList[k]->GetXUID() == xuid )
{
m_PlayerList.Remove( k );
++ numRemoved;
}
}
if ( !numRemoved )
{
Warning( "[L4DMM] CMatchGame::RemovePlayer - Cannot find player by %llx!\n", xuid );
}
}
void CMatchGame::RemoveAllPlayers( )
{
if ( MM_IsDebug() )
{
Msg( "[L4DMM] CMatchGame::RemoveAllPlayers\n" );
}
m_PlayerList.RemoveAll();
}
int CMatchGame::GetAggregateExperience( )
{
int difficulty = 1; // CMatchSystem::GetMatchSystem()->GetManager()->GameGetDifficulty();
double exp = 0;
int numExp = 0;
int numPlayers = m_PlayerList.Count();
for( int index = 0; index < numPlayers; ++index )
{
IPlayer * player = GetPlayer( index );
if( player )
{
// TODO: exp += player->GetExperience( difficulty );
++ numExp;
}
}
if( numExp )
exp /= numExp;
if ( MM_IsDebug() >= 2 )
{
Msg( "[L4DMM] Game aggregate experience on difficulty%d = %f out of %d exp players.\n", difficulty, exp, numExp );
}
return exp;
}
int CMatchGame::GetAggregateSkill( int iSkillType )
{
int difficulty = 1; // CMatchSystem::GetMatchSystem()->GetManager()->GameGetDifficulty();
double skill = 0;
int numSkills = 0;
int numPlayers = m_PlayerList.Count();
for( int index = 0; index < numPlayers; ++index )
{
IPlayer * player = GetPlayer( index );
if( player )
{
// TODO: skill += player->GetSkill( iSkillType, difficulty );
++ numSkills;
}
}
if( numSkills )
skill /= numSkills;
if ( MM_IsDebug() >= 2 )
{
Msg( "[L4DMM] Game aggregate skill%d on difficulty%d = %f out of %d skill players.\n", iSkillType, difficulty, skill, numSkills );
}
return skill;
}