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.

347 lines
9.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef C_TEAM_OBJECTIVERESOURCE_H
  7. #define C_TEAM_OBJECTIVERESOURCE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "shareddefs.h"
  12. #include "const.h"
  13. #include "c_baseentity.h"
  14. #include <igameresources.h>
  15. #define TEAM_ARRAY( index, team ) (index + (team * MAX_CONTROL_POINTS))
  16. //-----------------------------------------------------------------------------
  17. // Purpose: An entity that networks the state of the game's objectives.
  18. // May contain data for objectives that aren't used by your mod, but
  19. // the extra data will never be networked as long as it's zeroed out.
  20. //-----------------------------------------------------------------------------
  21. class C_BaseTeamObjectiveResource : public C_BaseEntity
  22. {
  23. DECLARE_CLASS( C_BaseTeamObjectiveResource, C_BaseEntity );
  24. public:
  25. DECLARE_CLIENTCLASS();
  26. C_BaseTeamObjectiveResource();
  27. virtual ~C_BaseTeamObjectiveResource();
  28. public:
  29. virtual void ClientThink();
  30. virtual void OnPreDataChanged( DataUpdateType_t updateType );
  31. virtual void OnDataChanged( DataUpdateType_t updateType );
  32. void UpdateControlPoint( const char *pszEvent, int index = -1 );
  33. float GetCPCapPercentage( int index );
  34. int GetNumControlPoints( void ) { return m_iNumControlPoints; }
  35. int GetNumControlPointsOwned( void );
  36. void SetOwningTeam( int index, int team );
  37. virtual void SetCappingTeam( int index, int team );
  38. void SetCapLayout( const char *pszLayout );
  39. // Is the point visible in the objective display
  40. bool IsCPVisible( int index_ )
  41. {
  42. Assert( index_ < m_iNumControlPoints );
  43. return m_bCPIsVisible[index_];
  44. }
  45. bool IsCPBlocked( int index_ )
  46. {
  47. Assert( index_ < m_iNumControlPoints );
  48. return m_bBlocked[index_];
  49. }
  50. // Get the world location of this control point
  51. Vector& GetCPPosition( int index_ )
  52. {
  53. Assert( index_ < m_iNumControlPoints );
  54. return m_vCPPositions[index_];
  55. }
  56. int GetOwningTeam( int index_ )
  57. {
  58. if ( index_ >= m_iNumControlPoints )
  59. return TEAM_UNASSIGNED;
  60. return m_iOwner[index_];
  61. }
  62. int GetCappingTeam( int index_ )
  63. {
  64. if ( index_ >= m_iNumControlPoints )
  65. return TEAM_UNASSIGNED;
  66. return m_iCappingTeam[index_];
  67. }
  68. int GetTeamInZone( int index_ )
  69. {
  70. if ( index_ >= m_iNumControlPoints )
  71. return TEAM_UNASSIGNED;
  72. return m_iTeamInZone[index_];
  73. }
  74. // Icons
  75. int GetCPCurrentOwnerIcon( int index_, int iOwner )
  76. {
  77. Assert( index_ < m_iNumControlPoints );
  78. return GetIconForTeam( index_, iOwner );
  79. }
  80. int GetCPCappingIcon( int index_ )
  81. {
  82. Assert( index_ < m_iNumControlPoints );
  83. int iCapper = GetCappingTeam( index_ );
  84. Assert( iCapper != TEAM_UNASSIGNED );
  85. return GetIconForTeam( index_, iCapper );
  86. }
  87. // Icon for the specified team
  88. int GetIconForTeam( int index_, int team )
  89. {
  90. Assert( index_ < m_iNumControlPoints );
  91. return m_iTeamIcons[ TEAM_ARRAY( index_,team) ];
  92. }
  93. // Overlay for the specified team
  94. int GetOverlayForTeam( int index_, int team )
  95. {
  96. Assert( index_ < m_iNumControlPoints );
  97. return m_iTeamOverlays[ TEAM_ARRAY( index_,team) ];
  98. }
  99. // Number of players in the area
  100. int GetNumPlayersInArea( int index_, int team )
  101. {
  102. Assert( index_ < m_iNumControlPoints );
  103. return m_iNumTeamMembers[ TEAM_ARRAY( index_,team) ];
  104. }
  105. // get the required cappers for the passed team
  106. int GetRequiredCappers( int index_, int team )
  107. {
  108. Assert( index_ < m_iNumControlPoints );
  109. return m_iTeamReqCappers[ TEAM_ARRAY( index_,team) ];
  110. }
  111. // Base Icon for the specified team
  112. int GetBaseIconForTeam( int team )
  113. {
  114. Assert( team < MAX_TEAMS );
  115. return m_iTeamBaseIcons[ team ];
  116. }
  117. int GetBaseControlPointForTeam( int iTeam )
  118. {
  119. Assert( iTeam < MAX_TEAMS );
  120. return m_iBaseControlPoints[iTeam];
  121. }
  122. int GetPreviousPointForPoint( int index_, int team, int iPrevIndex )
  123. {
  124. Assert( index_ < m_iNumControlPoints );
  125. Assert( iPrevIndex >= 0 && iPrevIndex < MAX_PREVIOUS_POINTS );
  126. int iIntIndex = iPrevIndex + (index_ * MAX_PREVIOUS_POINTS) + (team * MAX_CONTROL_POINTS * MAX_PREVIOUS_POINTS);
  127. return m_iPreviousPoints[ iIntIndex ];
  128. }
  129. bool TeamCanCapPoint( int index_, int team )
  130. {
  131. Assert( index_ < m_iNumControlPoints );
  132. return m_bTeamCanCap[ TEAM_ARRAY( index_, team ) ];
  133. }
  134. const char *GetCapLayoutInHUD( void ) { return m_pszCapLayoutInHUD; }
  135. void GetCapLayoutCustomPosition( float& flCustomPositionX, float& flCustomPositionY ) { flCustomPositionX = m_flCustomPositionX; flCustomPositionY = m_flCustomPositionY; }
  136. bool PlayingMiniRounds( void ){ return m_bPlayingMiniRounds; }
  137. bool IsInMiniRound( int index_ ) { return m_bInMiniRound[index_]; }
  138. int GetCapWarningLevel( int index_ )
  139. {
  140. Assert( index_ < m_iNumControlPoints );
  141. return m_iWarnOnCap[index_];
  142. }
  143. int GetCPGroup( int index_ )
  144. {
  145. Assert( index_ < m_iNumControlPoints );
  146. return m_iCPGroup[index_];
  147. }
  148. const char *GetWarnSound( int index_ )
  149. {
  150. Assert( index_ < m_iNumControlPoints );
  151. return m_iszWarnSound[index_];
  152. }
  153. virtual const char *GetGameSpecificCPCappingSwipe( int index_, int iCappingTeam )
  154. {
  155. // You need to implement this in your game's objective resource.
  156. Assert(0);
  157. return NULL;
  158. }
  159. virtual const char *GetGameSpecificCPBarFG( int index_, int iOwningTeam )
  160. {
  161. // You need to implement this in your game's objective resource.
  162. Assert(0);
  163. return NULL;
  164. }
  165. virtual const char *GetGameSpecificCPBarBG( int index_, int iCappingTeam )
  166. {
  167. // You need to implement this in your game's objective resource.
  168. Assert(0);
  169. return NULL;
  170. }
  171. bool CapIsBlocked( int index_ );
  172. int GetTimerToShowInHUD( void ) { return m_iTimerToShowInHUD; }
  173. int GetStopWatchTimer( void ) { return m_iStopWatchTimer; }
  174. float GetPathDistance( int index_ )
  175. {
  176. Assert( index_ < m_iNumControlPoints );
  177. return m_flPathDistance[index_];
  178. }
  179. bool GetCPLocked( int index_ )
  180. {
  181. Assert( index_ < m_iNumControlPoints );
  182. return m_bCPLocked[index_];
  183. }
  184. bool GetTrackAlarm( int index_ )
  185. {
  186. Assert( index_ < TEAM_TRAIN_MAX_TEAMS );
  187. return m_bTrackAlarm[index_];
  188. }
  189. int GetNumNodeHillData( int team ){ return ( team < TEAM_TRAIN_MAX_TEAMS ) ? m_nNumNodeHillData[team] : 0; }
  190. void GetHillData( int team, int hill, float &flStart, float &flEnd )
  191. {
  192. if ( hill < TEAM_TRAIN_MAX_HILLS && team < TEAM_TRAIN_MAX_TEAMS )
  193. {
  194. int index_ = ( hill * TEAM_TRAIN_FLOATS_PER_HILL ) + ( team * TEAM_TRAIN_MAX_HILLS * TEAM_TRAIN_FLOATS_PER_HILL );
  195. if ( index_ < TEAM_TRAIN_HILLS_ARRAY_SIZE - 1 ) // - 1 because we want to look at 2 entries
  196. {
  197. flStart = m_flNodeHillData[index_];
  198. flEnd = m_flNodeHillData[index_ +1];
  199. }
  200. }
  201. }
  202. void SetTrainOnHill( int team, int hill, bool state )
  203. {
  204. if ( team < TEAM_TRAIN_MAX_TEAMS && hill < TEAM_TRAIN_MAX_HILLS )
  205. {
  206. int index_ = hill + ( team * TEAM_TRAIN_MAX_HILLS );
  207. m_bTrainOnHill[index_] = state;
  208. }
  209. }
  210. bool IsTrainOnHill( int team, int hill )
  211. {
  212. if ( team < TEAM_TRAIN_MAX_TEAMS && hill < TEAM_TRAIN_MAX_HILLS )
  213. {
  214. return m_bTrainOnHill[hill + ( team * TEAM_TRAIN_MAX_HILLS )];
  215. }
  216. return false;
  217. }
  218. bool IsHillDownhill( int team, int hill )
  219. {
  220. if ( team < TEAM_TRAIN_MAX_TEAMS && hill < TEAM_TRAIN_MAX_HILLS )
  221. {
  222. return m_bHillIsDownhill[hill + ( team * TEAM_TRAIN_MAX_HILLS )];
  223. }
  224. return true;
  225. }
  226. protected:
  227. int m_iTimerToShowInHUD;
  228. int m_iStopWatchTimer;
  229. int m_iNumControlPoints;
  230. int m_iPrevNumControlPoints;
  231. bool m_bPlayingMiniRounds;
  232. bool m_bControlPointsReset;
  233. bool m_bOldControlPointsReset;
  234. int m_iUpdateCapHudParity;
  235. int m_iOldUpdateCapHudParity;
  236. // data variables
  237. Vector m_vCPPositions[MAX_CONTROL_POINTS];
  238. bool m_bCPIsVisible[MAX_CONTROL_POINTS];
  239. float m_flLazyCapPerc[MAX_CONTROL_POINTS];
  240. float m_flOldLazyCapPerc[MAX_CONTROL_POINTS];
  241. int m_iTeamIcons[MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS];
  242. int m_iTeamOverlays[MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS];
  243. int m_iTeamReqCappers[MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS];
  244. float m_flTeamCapTime[MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS];
  245. int m_iPreviousPoints[ MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS * MAX_PREVIOUS_POINTS ];
  246. bool m_bTeamCanCap[ MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS ];
  247. int m_iTeamBaseIcons[MAX_TEAMS];
  248. int m_iBaseControlPoints[MAX_TEAMS];
  249. bool m_bInMiniRound[MAX_CONTROL_POINTS];
  250. int m_iWarnOnCap[MAX_CONTROL_POINTS];
  251. char m_iszWarnSound[MAX_CONTROL_POINTS][255];
  252. float m_flPathDistance[MAX_CONTROL_POINTS];
  253. int m_iCPGroup[MAX_CONTROL_POINTS];
  254. bool m_bCPLocked[MAX_CONTROL_POINTS];
  255. float m_flUnlockTimes[MAX_CONTROL_POINTS];
  256. float m_flOldUnlockTimes[MAX_CONTROL_POINTS];
  257. float m_flCPTimerTimes[MAX_CONTROL_POINTS];
  258. float m_flOldCPTimerTimes[MAX_CONTROL_POINTS];
  259. // state variables
  260. int m_iNumTeamMembers[MAX_CONTROL_POINTS * MAX_CONTROL_POINT_TEAMS];
  261. int m_iCappingTeam[MAX_CONTROL_POINTS];
  262. int m_iTeamInZone[MAX_CONTROL_POINTS];
  263. bool m_bBlocked[MAX_CONTROL_POINTS];
  264. int m_iOwner[MAX_CONTROL_POINTS];
  265. bool m_bCPCapRateScalesWithPlayers[MAX_CONTROL_POINTS];
  266. // client calculated state
  267. float m_flCapTimeLeft[MAX_CONTROL_POINTS];
  268. float m_flCapLastThinkTime[MAX_CONTROL_POINTS];
  269. bool m_bWarnedOnFinalCap[MAX_CONTROL_POINTS];
  270. float m_flLastCapWarningTime[MAX_CONTROL_POINTS];
  271. char m_pszCapLayoutInHUD[MAX_CAPLAYOUT_LENGTH];
  272. float m_flOldCustomPositionX;
  273. float m_flOldCustomPositionY;
  274. float m_flCustomPositionX;
  275. float m_flCustomPositionY;
  276. // hill data for multi-escort payload maps
  277. int m_nNumNodeHillData[TEAM_TRAIN_MAX_TEAMS];
  278. float m_flNodeHillData[TEAM_TRAIN_HILLS_ARRAY_SIZE];
  279. bool m_bTrainOnHill[TEAM_TRAIN_MAX_HILLS*TEAM_TRAIN_MAX_TEAMS];
  280. bool m_bTrackAlarm[TEAM_TRAIN_MAX_TEAMS];
  281. bool m_bHillIsDownhill[TEAM_TRAIN_MAX_HILLS*TEAM_TRAIN_MAX_TEAMS];
  282. };
  283. extern C_BaseTeamObjectiveResource *g_pObjectiveResource;
  284. inline C_BaseTeamObjectiveResource *ObjectiveResource()
  285. {
  286. return g_pObjectiveResource;
  287. }
  288. #endif // C_TEAM_OBJECTIVERESOURCE_H