blob: dc3508c05ef8f74c5869455281d7ac0035e10ee7 (
plain) (
blame)
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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef TF_AUTOBALANCE_H
#define TF_AUTOBALANCE_H
#ifdef _WIN32
#pragma once
#endif
#include "GameEventListener.h"
enum autobalance_state_t
{
AB_STATE_INACTIVE = 0,
AB_STATE_MONITOR,
AB_STATE_FIND_VOLUNTEERS
};
enum volunteer_state_t
{
AB_VOLUNTEER_STATE_ASKED = 0,
AB_VOLUNTEER_STATE_NO,
AB_VOLUNTEER_STATE_YES,
};
typedef struct
{
CHandle<CTFPlayer> hPlayer;
volunteer_state_t eState;
float flQueryExpireTime;
} volunteer_info_s;
//-----------------------------------------------------------------------------
class CTFAutobalance : public CAutoGameSystemPerFrame
{
public:
CTFAutobalance();
~CTFAutobalance();
virtual char const *Name() { return "CTFAutobalance"; }
virtual void Shutdown();
virtual void LevelShutdownPostEntity();
// called after entities think
virtual void FrameUpdatePostEntityThink();
void ReplyReceived( CTFPlayer *pTFPlayer, bool bResponse );
private:
void Reset();
bool ShouldBeActive() const;
bool AreTeamsUnbalanced();
void MonitorTeams();
bool HaveAlreadyAskedPlayer( CTFPlayer *pTFPlayer ) const;
int GetTeamAutoBalanceScore( int nTeam ) const;
int GetPlayerAutoBalanceScore( CTFPlayer *pTFPlayer ) const;
CTFPlayer *FindPlayerToAsk();
void FindVolunteers();
void SwitchVolunteers();
bool IsOkayToBalancePlayers();
private:
int m_iCurrentState;
int m_iLightestTeam;
int m_iHeaviestTeam;
int m_nNeeded;
float m_flBalanceTeamsTime;
CUtlVector< volunteer_info_s > m_vecPlayersAsked;
};
CTFAutobalance *TFAutoBalance();
#endif // TF_AUTOBALANCE_H
|