Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef TF_AUTOBALANCE_H
  8. #define TF_AUTOBALANCE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "GameEventListener.h"
  13. enum autobalance_state_t
  14. {
  15. AB_STATE_INACTIVE = 0,
  16. AB_STATE_MONITOR,
  17. AB_STATE_FIND_VOLUNTEERS
  18. };
  19. enum volunteer_state_t
  20. {
  21. AB_VOLUNTEER_STATE_ASKED = 0,
  22. AB_VOLUNTEER_STATE_NO,
  23. AB_VOLUNTEER_STATE_YES,
  24. };
  25. typedef struct
  26. {
  27. CHandle<CTFPlayer> hPlayer;
  28. volunteer_state_t eState;
  29. float flQueryExpireTime;
  30. } volunteer_info_s;
  31. //-----------------------------------------------------------------------------
  32. class CTFAutobalance : public CAutoGameSystemPerFrame
  33. {
  34. public:
  35. CTFAutobalance();
  36. ~CTFAutobalance();
  37. virtual char const *Name() { return "CTFAutobalance"; }
  38. virtual void Shutdown();
  39. virtual void LevelShutdownPostEntity();
  40. // called after entities think
  41. virtual void FrameUpdatePostEntityThink();
  42. void ReplyReceived( CTFPlayer *pTFPlayer, bool bResponse );
  43. private:
  44. void Reset();
  45. bool ShouldBeActive() const;
  46. bool AreTeamsUnbalanced();
  47. void MonitorTeams();
  48. bool HaveAlreadyAskedPlayer( CTFPlayer *pTFPlayer ) const;
  49. int GetTeamAutoBalanceScore( int nTeam ) const;
  50. int GetPlayerAutoBalanceScore( CTFPlayer *pTFPlayer ) const;
  51. CTFPlayer *FindPlayerToAsk();
  52. void FindVolunteers();
  53. void SwitchVolunteers();
  54. bool IsOkayToBalancePlayers();
  55. private:
  56. int m_iCurrentState;
  57. int m_iLightestTeam;
  58. int m_iHeaviestTeam;
  59. int m_nNeeded;
  60. float m_flBalanceTeamsTime;
  61. CUtlVector< volunteer_info_s > m_vecPlayersAsked;
  62. };
  63. CTFAutobalance *TFAutoBalance();
  64. #endif // TF_AUTOBALANCE_H