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.

221 lines
6.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TEAM_CONTROL_POINT_MASTER_H
  7. #define TEAM_CONTROL_POINT_MASTER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "utlmap.h"
  12. #include "team.h"
  13. #include "teamplay_gamerules.h"
  14. #include "team_control_point.h"
  15. #include "trigger_area_capture.h"
  16. #include "team_objectiveresource.h"
  17. #include "team_control_point_round.h"
  18. #define CPM_THINK "CTeamControlPointMasterCPMThink"
  19. #define CPM_POSTINITTHINK "CTeamControlPointMasterCPMPostInitThink"
  20. //-----------------------------------------------------------------------------
  21. // Purpose: One ControlPointMaster is spawned per level. Shortly after spawning it detects all the Control
  22. // points in the map and puts them into the m_ControlPoints. From there it detects the state
  23. // where all points are captured and resets them if necessary It gives points every time interval to
  24. // the owners of the points
  25. //-----------------------------------------------------------------------------
  26. class CTeamControlPointMaster : public CBaseEntity
  27. {
  28. DECLARE_CLASS( CTeamControlPointMaster, CBaseEntity );
  29. // Derived, game-specific control point masters must override these functions
  30. public:
  31. CTeamControlPointMaster();
  32. // Used to find game specific entities
  33. virtual const char *GetControlPointName( void ) { return "team_control_point"; }
  34. virtual const char *GetControlPointRoundName( void ) { return "team_control_point_round"; }
  35. public:
  36. virtual void Spawn( void );
  37. virtual void UpdateOnRemove( void );
  38. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  39. virtual void Precache( void );
  40. virtual void Activate( void );
  41. void RoundRespawn( void );
  42. void Reset( void );
  43. int GetNumPoints( void ){ return m_ControlPoints.Count(); }
  44. int GetNumPointsOwnedByTeam( int iTeam );
  45. int CalcNumRoundsRemaining( int iTeam );
  46. bool IsActive( void ) { return ( m_bDisabled == false ); }
  47. void FireTeamWinOutput( int iWinningTeam );
  48. bool IsInRound( CTeamControlPoint *pPoint );
  49. void CheckWinConditions( void );
  50. bool WouldNewCPOwnerWinGame( CTeamControlPoint *pPoint, int iNewOwner );
  51. int GetBaseControlPoint( int iTeam );
  52. bool IsBaseControlPoint( int iPointIndex );
  53. bool PlayingMiniRounds( void ){ return ( m_ControlPointRounds.Count() > 0 ); }
  54. int GetNumRounds( void ) { return m_ControlPointRounds.Count(); }
  55. const CTeamControlPointRound* GetRoundByIndex( int nIndex ) const;
  56. float PointLastContestedAt( int point );
  57. CTeamControlPoint *GetControlPoint( int point )
  58. {
  59. Assert( point >= 0 );
  60. Assert( point < MAX_CONTROL_POINTS );
  61. for ( unsigned int i = 0; i < m_ControlPoints.Count(); i++ )
  62. {
  63. CTeamControlPoint *pPoint = m_ControlPoints[i];
  64. if ( pPoint && pPoint->GetPointIndex() == point )
  65. return pPoint;
  66. }
  67. return NULL;
  68. }
  69. CTeamControlPointRound *GetCurrentRound( void )
  70. {
  71. if ( !PlayingMiniRounds() || m_iCurrentRoundIndex == -1 )
  72. {
  73. return NULL;
  74. }
  75. return m_ControlPointRounds[m_iCurrentRoundIndex];
  76. }
  77. string_t GetRoundToUseAfterRestart( void )
  78. {
  79. int nCurrentPriority = -1;
  80. int nHighestPriority = -1;
  81. string_t nRetVal = NULL_STRING;
  82. if ( PlayingMiniRounds() && GetCurrentRound() )
  83. {
  84. nCurrentPriority = GetCurrentRound()->GetPriorityValue();
  85. nHighestPriority = GetHighestRoundPriorityValue();
  86. // if the current round has the highest priority, then use it again
  87. if ( nCurrentPriority == nHighestPriority )
  88. {
  89. nRetVal = GetCurrentRound()->GetEntityName();
  90. }
  91. }
  92. return nRetVal;
  93. }
  94. void FireRoundStartOutput( void );
  95. void FireRoundEndOutput( void );
  96. bool ShouldScorePerCapture( void ){ return m_bScorePerCapture; }
  97. bool ShouldPlayAllControlPointRounds( void ){ return m_bPlayAllRounds; }
  98. int NumPlayableControlPointRounds( void ); // checks to see if there are any more rounds to play (but doesn't actually "get" one to play)
  99. #ifdef STAGING_ONLY
  100. void ListRounds( void );
  101. #endif
  102. float GetPartialCapturePointRate( void );
  103. void SetLastOwnershipChangeTime( float m_flTime ) { m_flLastOwnershipChangeTime = m_flTime; }
  104. float GetLastOwnershipChangeTime( void ) { return m_flLastOwnershipChangeTime; }
  105. int GetCurrentRoundIndex() { return m_iCurrentRoundIndex; }
  106. bool ShouldSwitchTeamsOnRoundWin( void ) { return m_bSwitchTeamsOnWin; }
  107. private:
  108. void EXPORT CPMThink( void );
  109. void SetBaseControlPoints( void );
  110. int TeamOwnsAllPoints( CTeamControlPoint *pOverridePoint = NULL, int iOverrideNewTeam = TEAM_UNASSIGNED );
  111. bool FindControlPoints( void ); // look in the map to find active control points
  112. bool FindControlPointRounds( void ); // look in the map to find active control point rounds
  113. bool GetControlPointRoundToPlay( void ); // gets the next round we should play
  114. bool SelectSpecificRound( void ); // selects a specific round to play
  115. int GetHighestRoundPriorityValue( void )
  116. {
  117. int nRetVal = -1;
  118. // rounds are sorted with the higher priority rounds first
  119. for ( int i = 0 ; i < m_ControlPointRounds.Count() ; ++i )
  120. {
  121. CTeamControlPointRound *pRound = m_ControlPointRounds[i];
  122. if ( pRound )
  123. {
  124. if ( pRound->GetPriorityValue() > nRetVal )
  125. {
  126. nRetVal = pRound->GetPriorityValue();
  127. }
  128. }
  129. }
  130. return nRetVal;
  131. }
  132. void RegisterRoundBeingPlayed( void );
  133. CUtlMap<int, CTeamControlPoint *> m_ControlPoints;
  134. bool m_bFoundPoints; // true when the control points have been found and the array is initialized
  135. CUtlVector<CTeamControlPointRound *> m_ControlPointRounds;
  136. int m_iCurrentRoundIndex;
  137. DECLARE_DATADESC();
  138. bool m_bDisabled;
  139. void InputEnable( inputdata_t &inputdata );
  140. void InputDisable( inputdata_t &inputdata );
  141. void InputRoundSpawn( inputdata_t &inputdata );
  142. void InputRoundActivate( inputdata_t &inputdata );
  143. void InputSetWinner( inputdata_t &inputdata );
  144. void InputSetWinnerAndForceCaps( inputdata_t &inputdata );
  145. void InputSetCapLayout( inputdata_t &inputdata );
  146. void InputSetCapLayoutCustomPositionX( inputdata_t &inputdata );
  147. void InputSetCapLayoutCustomPositionY( inputdata_t &inputdata );
  148. void InternalSetWinner( int iTeam );
  149. void HandleRandomOwnerControlPoints( void );
  150. string_t m_iszTeamBaseIcons[MAX_TEAMS];
  151. int m_iTeamBaseIcons[MAX_TEAMS];
  152. string_t m_iszCapLayoutInHUD;
  153. float m_flCustomPositionX;
  154. float m_flCustomPositionY;
  155. int m_iInvalidCapWinner;
  156. bool m_bSwitchTeamsOnWin;
  157. bool m_bScorePerCapture;
  158. bool m_bPlayAllRounds;
  159. bool m_bFirstRoundAfterRestart;
  160. COutputEvent m_OnWonByTeam1;
  161. COutputEvent m_OnWonByTeam2;
  162. float m_flPartialCapturePointsRate;
  163. float m_flLastOwnershipChangeTime;
  164. };
  165. extern CUtlVector< CHandle<CTeamControlPointMaster> > g_hControlPointMasters;
  166. #endif // TEAM_CONTROL_POINT_MASTER_H