diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/tf/tf_autobalance.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/server/tf/tf_autobalance.h')
| -rw-r--r-- | game/server/tf/tf_autobalance.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/game/server/tf/tf_autobalance.h b/game/server/tf/tf_autobalance.h new file mode 100644 index 0000000..dc3508c --- /dev/null +++ b/game/server/tf/tf_autobalance.h @@ -0,0 +1,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 |