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.

242 lines
8.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TEAM_OBJECTIVERESOURCE_H
  7. #define TEAM_OBJECTIVERESOURCE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "shareddefs.h"
  12. #define TEAM_ARRAY( index, team ) (index + (team * MAX_CONTROL_POINTS))
  13. //-----------------------------------------------------------------------------
  14. // Purpose: An entity that networks the state of the game's objectives.
  15. // May contain data for objectives that aren't used by your mod, but
  16. // the extra data will never be networked as long as it's zeroed out.
  17. //-----------------------------------------------------------------------------
  18. class CBaseTeamObjectiveResource : public CBaseEntity
  19. {
  20. DECLARE_CLASS( CBaseTeamObjectiveResource, CBaseEntity );
  21. public:
  22. DECLARE_SERVERCLASS();
  23. DECLARE_DATADESC();
  24. CBaseTeamObjectiveResource();
  25. ~CBaseTeamObjectiveResource();
  26. virtual void Spawn( void );
  27. virtual int UpdateTransmitState(void);
  28. virtual void ObjectiveThink( void );
  29. //--------------------------------------------------------------------
  30. // CONTROL POINT DATA
  31. //--------------------------------------------------------------------
  32. public:
  33. void ResetControlPoints( void );
  34. // Data functions, called to set up the state at the beginning of a round
  35. void SetNumControlPoints( int num );
  36. int GetNumControlPoints( void ) { return m_iNumControlPoints; }
  37. void SetCPIcons( int index, int iTeam, int iIcon );
  38. void SetCPOverlays( int index, int iTeam, int iIcon );
  39. void SetTeamBaseIcons( int iTeam, int iBaseIcon );
  40. void SetCPPosition( int index, const Vector& vPosition );
  41. void SetCPVisible( int index, bool bVisible );
  42. void SetCPRequiredCappers( int index, int iTeam, int iReqPlayers );
  43. void SetCPCapTime( int index, int iTeam, float flTime );
  44. void SetCPCapPercentage( int index, float flTime );
  45. float GetCPCapPercentage( int index );
  46. void SetTeamCanCap( int index, int iTeam, bool bCanCap );
  47. void SetBaseCP( int index, int iTeam );
  48. void SetPreviousPoint( int index, int iTeam, int iPrevIndex, int iPrevPoint );
  49. int GetPreviousPointForPoint( int index, int team, int iPrevIndex );
  50. bool TeamCanCapPoint( int index, int team );
  51. void SetCapLayoutInHUD( const char *pszLayout ) { Q_strncpy(m_pszCapLayoutInHUD.GetForModify(), pszLayout, MAX_CAPLAYOUT_LENGTH ); }
  52. void SetCapLayoutCustomPosition( float flPositionX, float flPositionY ) { m_flCustomPositionX = flPositionX; m_flCustomPositionY = flPositionY; }
  53. void SetWarnOnCap( int index, int iWarnLevel );
  54. void SetWarnSound( int index, string_t iszSound );
  55. void SetCPGroup( int index, int iCPGroup );
  56. void SetCPLocked( int index, bool bLocked );
  57. void SetTrackAlarm( int index, bool bAlarm );
  58. void SetCPUnlockTime( int index, float flTime );
  59. void SetCPTimerTime( int index, float flTime );
  60. void SetCPCapTimeScalesWithPlayers( int index, bool bScales );
  61. // State functions, called many times
  62. void SetNumPlayers( int index, int team, int iNumPlayers );
  63. void StartCap( int index, int team );
  64. void SetOwningTeam( int index, int team );
  65. void SetCappingTeam( int index, int team );
  66. void SetTeamInZone( int index, int team );
  67. void SetCapBlocked( int index, bool bBlocked );
  68. int GetOwningTeam( int index );
  69. void AssertValidIndex( int index )
  70. {
  71. Assert( 0 <= index && index <= MAX_CONTROL_POINTS && index < m_iNumControlPoints );
  72. }
  73. int GetBaseControlPointForTeam( int iTeam )
  74. {
  75. Assert( iTeam < MAX_TEAMS );
  76. return m_iBaseControlPoints[iTeam];
  77. }
  78. int GetCappingTeam( int index )
  79. {
  80. if ( index >= m_iNumControlPoints )
  81. return TEAM_UNASSIGNED;
  82. return m_iCappingTeam[index];
  83. }
  84. void SetTimerInHUD( CBaseEntity *pTimer )
  85. {
  86. m_iTimerToShowInHUD = pTimer ? pTimer->entindex() : 0;
  87. }
  88. void SetStopWatchTimer( CBaseEntity *pTimer )
  89. {
  90. m_iStopWatchTimer = pTimer ? pTimer->entindex() : 0;
  91. }
  92. int GetStopWatchTimer( void ) { return m_iStopWatchTimer; }
  93. int GetTimerInHUD( void ) { return m_iTimerToShowInHUD; }
  94. // Mini-rounds data
  95. void SetPlayingMiniRounds( bool bPlayingMiniRounds ){ m_bPlayingMiniRounds = bPlayingMiniRounds; }
  96. bool PlayingMiniRounds( void ){ return m_bPlayingMiniRounds; }
  97. void SetInMiniRound( int index, bool bInRound ) { m_bInMiniRound.Set( index, bInRound ); }
  98. bool IsInMiniRound( int index ) { return m_bInMiniRound[index]; }
  99. void UpdateCapHudElement( void );
  100. // Train Path data
  101. void SetTrainPathDistance( int index, float flDistance );
  102. bool GetCPLocked( int index )
  103. {
  104. Assert( index < m_iNumControlPoints );
  105. return m_bCPLocked[index];
  106. }
  107. void ResetHillData( int team )
  108. {
  109. if ( team < TEAM_TRAIN_MAX_TEAMS )
  110. {
  111. m_nNumNodeHillData.Set( team, 0 );
  112. int nNumEntriesPerTeam = TEAM_TRAIN_MAX_HILLS * TEAM_TRAIN_FLOATS_PER_HILL;
  113. int iStartingIndex = team * nNumEntriesPerTeam;
  114. for ( int i = 0 ; i < nNumEntriesPerTeam ; i++ )
  115. {
  116. m_flNodeHillData.Set( iStartingIndex + i, 0 );
  117. }
  118. iStartingIndex = team * TEAM_TRAIN_MAX_HILLS;
  119. for ( int i = 0; i < TEAM_TRAIN_MAX_HILLS; i++ )
  120. {
  121. m_bHillIsDownhill.Set( iStartingIndex + i, 0 );
  122. }
  123. }
  124. }
  125. void SetHillData( int team, float flStart, float flEnd, bool bDownhill )
  126. {
  127. if ( team < TEAM_TRAIN_MAX_TEAMS )
  128. {
  129. int index = ( m_nNumNodeHillData[team] * TEAM_TRAIN_FLOATS_PER_HILL ) + ( team * TEAM_TRAIN_MAX_HILLS * TEAM_TRAIN_FLOATS_PER_HILL );
  130. if ( index < TEAM_TRAIN_HILLS_ARRAY_SIZE - 1 ) // - 1 because we want to add 2 entries
  131. {
  132. m_flNodeHillData.Set( index, flStart );
  133. m_flNodeHillData.Set( index + 1, flEnd );
  134. if ( m_nNumNodeHillData[team] < TEAM_TRAIN_MAX_HILLS )
  135. {
  136. m_bHillIsDownhill.Set( m_nNumNodeHillData[team] + ( team * TEAM_TRAIN_MAX_HILLS ), bDownhill );
  137. }
  138. m_nNumNodeHillData.Set( team, m_nNumNodeHillData[team] + 1);
  139. }
  140. }
  141. }
  142. private:
  143. CNetworkVar( int, m_iTimerToShowInHUD );
  144. CNetworkVar( int, m_iStopWatchTimer );
  145. CNetworkVar( int, m_iNumControlPoints );
  146. CNetworkVar( bool, m_bPlayingMiniRounds );
  147. CNetworkVar( bool, m_bControlPointsReset );
  148. CNetworkVar( int, m_iUpdateCapHudParity );
  149. // data variables
  150. CNetworkArray( Vector, m_vCPPositions, MAX_CONTROL_POINTS );
  151. CNetworkArray( int, m_bCPIsVisible, MAX_CONTROL_POINTS );
  152. CNetworkArray( float, m_flLazyCapPerc, MAX_CONTROL_POINTS );
  153. CNetworkArray( int, m_iTeamIcons, MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS );
  154. CNetworkArray( int, m_iTeamOverlays, MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS );
  155. CNetworkArray( int, m_iTeamReqCappers, MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS );
  156. CNetworkArray( float, m_flTeamCapTime, MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS );
  157. CNetworkArray( int, m_iPreviousPoints, MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS * MAX_PREVIOUS_POINTS );
  158. CNetworkArray( bool, m_bTeamCanCap, MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS );
  159. CNetworkArray( int, m_iTeamBaseIcons, MAX_TEAMS );
  160. CNetworkArray( int, m_iBaseControlPoints, MAX_TEAMS );
  161. CNetworkArray( bool, m_bInMiniRound, MAX_CONTROL_POINTS );
  162. CNetworkArray( int, m_iWarnOnCap, MAX_CONTROL_POINTS );
  163. CNetworkArray( string_t, m_iszWarnSound, MAX_CONTROL_POINTS );
  164. CNetworkArray( float, m_flPathDistance, MAX_CONTROL_POINTS );
  165. CNetworkArray( bool, m_bCPLocked, MAX_CONTROL_POINTS );
  166. CNetworkArray( float, m_flUnlockTimes, MAX_CONTROL_POINTS );
  167. CNetworkArray( float, m_flCPTimerTimes, MAX_CONTROL_POINTS );
  168. // change when players enter/exit an area
  169. CNetworkArray( int, m_iNumTeamMembers, MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS );
  170. // changes when a cap starts. start and end times are calculated on client
  171. CNetworkArray( int, m_iCappingTeam, MAX_CONTROL_POINTS );
  172. CNetworkArray( int, m_iTeamInZone, MAX_CONTROL_POINTS );
  173. CNetworkArray( bool, m_bBlocked, MAX_CONTROL_POINTS );
  174. // changes when a point is successfully captured
  175. CNetworkArray( int, m_iOwner, MAX_CONTROL_POINTS );
  176. CNetworkArray( bool, m_bCPCapRateScalesWithPlayers, MAX_CONTROL_POINTS );
  177. // describes how to lay out the cap points in the hud
  178. CNetworkString( m_pszCapLayoutInHUD, MAX_CAPLAYOUT_LENGTH );
  179. // custom screen position for the cap points in the hud
  180. CNetworkVar( float, m_flCustomPositionX );
  181. CNetworkVar( float, m_flCustomPositionY );
  182. // the groups the points belong to
  183. CNetworkArray( int, m_iCPGroup, MAX_CONTROL_POINTS );
  184. // Not networked, because the client recalculates it
  185. float m_flCapPercentages[ MAX_CONTROL_POINTS ];
  186. // hill data for multi-escort payload maps
  187. CNetworkArray( int, m_nNumNodeHillData, TEAM_TRAIN_MAX_TEAMS );
  188. CNetworkArray( float, m_flNodeHillData, TEAM_TRAIN_HILLS_ARRAY_SIZE );
  189. CNetworkArray( bool, m_bTrackAlarm, TEAM_TRAIN_MAX_TEAMS );
  190. CNetworkArray( bool, m_bHillIsDownhill, TEAM_TRAIN_MAX_HILLS*TEAM_TRAIN_MAX_TEAMS );
  191. };
  192. extern CBaseTeamObjectiveResource *g_pObjectiveResource;
  193. inline CBaseTeamObjectiveResource *ObjectiveResource()
  194. {
  195. return g_pObjectiveResource;
  196. }
  197. #endif // TEAM_OBJECTIVERESOURCE_H