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.

239 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Entity that propagates general data needed by clients for every player.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef C_DOD_OBJECTIVE_RESOURCE_H
  8. #define C_DOD_OBJECTIVE_RESOURCE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "dod_shareddefs.h"
  13. #include "const.h"
  14. #include "c_baseentity.h"
  15. #include <igameresources.h>
  16. class C_DODObjectiveResource : public C_BaseEntity
  17. {
  18. DECLARE_CLASS( C_DODObjectiveResource, C_BaseEntity );
  19. public:
  20. DECLARE_CLIENTCLASS();
  21. C_DODObjectiveResource();
  22. virtual ~C_DODObjectiveResource();
  23. public:
  24. float GetCPCapPercentage( int index );
  25. int GetNumControlPoints( void ) { return m_iNumControlPoints; }
  26. void SetOwningTeam( int index, int team );
  27. void SetCappingTeam( int index, int team );
  28. // Is the point visible in the objective display
  29. bool IsCPVisible( int index )
  30. {
  31. Assert( index < m_iNumControlPoints );
  32. return m_bCPIsVisible[index];
  33. }
  34. // Get the world location of this control point
  35. Vector& GetCPPosition( int index )
  36. {
  37. Assert( index < m_iNumControlPoints );
  38. return m_vCPPositions[index];
  39. }
  40. int GetOwningTeam( int index )
  41. {
  42. if ( index >= m_iNumControlPoints )
  43. return TEAM_UNASSIGNED;
  44. return m_iOwner[index];
  45. }
  46. int GetCappingTeam( int index )
  47. {
  48. if ( index >= m_iNumControlPoints )
  49. return TEAM_UNASSIGNED;
  50. return m_iCappingTeam[index];
  51. }
  52. // Icons
  53. int GetCPCurrentOwnerIcon( int index )
  54. {
  55. Assert( index < m_iNumControlPoints );
  56. int iOwner = GetOwningTeam(index);
  57. return GetIconForTeam( index, iOwner );
  58. }
  59. int GetCPCappingIcon( int index )
  60. {
  61. Assert( index < m_iNumControlPoints );
  62. int iCapper = GetCappingTeam(index);
  63. Assert( iCapper != TEAM_UNASSIGNED );
  64. return GetIconForTeam( index, iCapper );;
  65. }
  66. int GetCPTimerCapIcon( int index )
  67. {
  68. Assert( index < m_iNumControlPoints );
  69. return m_iTimerCapIcons[index];
  70. }
  71. int GetCPBombedIcon( int index )
  72. {
  73. Assert( index < m_iNumControlPoints );
  74. return m_iBombedIcons[index];
  75. }
  76. int GetIconForTeam( int index, int team )
  77. {
  78. int icon = 0;
  79. switch ( team )
  80. {
  81. case TEAM_ALLIES:
  82. icon = m_iAlliesIcons[index];
  83. break;
  84. case TEAM_AXIS:
  85. icon = m_iAxisIcons[index];
  86. break;
  87. case TEAM_UNASSIGNED:
  88. icon = m_iNeutralIcons[index];
  89. break;
  90. default:
  91. Assert(0);
  92. break;
  93. }
  94. return icon;
  95. }
  96. // Number of players in the area
  97. int GetNumPlayersInArea( int index, int team )
  98. {
  99. Assert( index < m_iNumControlPoints );
  100. int num = 0;
  101. switch ( team )
  102. {
  103. case TEAM_ALLIES:
  104. num = m_iNumAllies[index];
  105. break;
  106. case TEAM_AXIS:
  107. num = m_iNumAxis[index];
  108. break;
  109. default:
  110. Assert(0);
  111. break;
  112. }
  113. return num;
  114. }
  115. // get the required cappers for the passed team
  116. int GetRequiredCappers( int index, int team )
  117. {
  118. Assert( index < m_iNumControlPoints );
  119. int num = 0;
  120. switch ( team )
  121. {
  122. case TEAM_ALLIES:
  123. num = m_iAlliesReqCappers[index];
  124. break;
  125. case TEAM_AXIS:
  126. num = m_iAxisReqCappers[index];
  127. break;
  128. default:
  129. Assert(0);
  130. break;
  131. }
  132. return num;
  133. }
  134. void SetBombPlanted( int index, int iBombPlanted );
  135. void SetBombBeingDefused( int index, bool bBombBeingDefused )
  136. {
  137. m_bBombBeingDefused[index] = bBombBeingDefused;
  138. }
  139. bool IsBombSetAtPoint( int index )
  140. {
  141. return m_bBombPlanted[index];
  142. }
  143. bool IsBombBeingDefused( int index )
  144. {
  145. return m_bBombBeingDefused[index];
  146. }
  147. float GetBombTimeForPoint( int index )
  148. {
  149. return MAX( 0, m_flBombEndTimes[index] - gpGlobals->curtime );
  150. }
  151. int GetBombsRequired( int index )
  152. {
  153. return m_iBombsRequired[index];
  154. }
  155. int GetBombsRemaining( int index )
  156. {
  157. return m_iBombsRemaining[index];
  158. }
  159. protected:
  160. int m_iNumControlPoints;
  161. // data variables
  162. Vector m_vCPPositions[MAX_CONTROL_POINTS];
  163. bool m_bCPIsVisible[MAX_CONTROL_POINTS];
  164. int m_iAlliesIcons[MAX_CONTROL_POINTS];
  165. int m_iAxisIcons[MAX_CONTROL_POINTS];
  166. int m_iNeutralIcons[MAX_CONTROL_POINTS];
  167. int m_iTimerCapIcons[MAX_CONTROL_POINTS];
  168. int m_iBombedIcons[MAX_CONTROL_POINTS];
  169. int m_iAlliesReqCappers[MAX_CONTROL_POINTS];
  170. int m_iAxisReqCappers[MAX_CONTROL_POINTS];
  171. float m_flAlliesCapTime[MAX_CONTROL_POINTS];
  172. float m_flAxisCapTime[MAX_CONTROL_POINTS];
  173. bool m_bBombPlanted[MAX_CONTROL_POINTS];
  174. int m_iBombsRequired[MAX_CONTROL_POINTS];
  175. int m_iBombsRemaining[MAX_CONTROL_POINTS];
  176. bool m_bBombBeingDefused[MAX_CONTROL_POINTS];
  177. // state variables
  178. int m_iNumAllies[MAX_CONTROL_POINTS];
  179. int m_iNumAxis[MAX_CONTROL_POINTS];
  180. int m_iCappingTeam[MAX_CONTROL_POINTS];
  181. int m_iOwner[MAX_CONTROL_POINTS];
  182. // client calculated state
  183. float m_flCapStartTimes[MAX_CONTROL_POINTS];
  184. float m_flCapEndTimes[MAX_CONTROL_POINTS];
  185. float m_flBombEndTimes[MAX_CONTROL_POINTS];
  186. };
  187. extern C_DODObjectiveResource *g_pObjectiveResource;
  188. #endif // C_DOD_OBJECTIVE_RESOURCE_H