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.

573 lines
23 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: An entity that networks the state of the game's objectives.
  4. // May contain data for objectives that aren't used by your mod, but
  5. // the extra data will never be networked as long as it's zeroed out.
  6. //
  7. //=============================================================================
  8. #include "cbase.h"
  9. #include "team_objectiveresource.h"
  10. #include "shareddefs.h"
  11. #include <coordsize.h>
  12. #include "team.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. #define CAPHUD_PARITY_BITS 6
  16. #define CAPHUD_PARITY_MASK ((1<<CAPHUD_PARITY_BITS)-1)
  17. #define LAZY_UPDATE_TIME 3
  18. // Datatable
  19. IMPLEMENT_SERVERCLASS_ST_NOBASE(CBaseTeamObjectiveResource, DT_BaseTeamObjectiveResource)
  20. SendPropInt( SENDINFO(m_iTimerToShowInHUD), MAX_EDICT_BITS, SPROP_UNSIGNED ),
  21. SendPropInt( SENDINFO(m_iStopWatchTimer), MAX_EDICT_BITS, SPROP_UNSIGNED ),
  22. SendPropInt( SENDINFO(m_iNumControlPoints), 4, SPROP_UNSIGNED ),
  23. SendPropBool( SENDINFO(m_bPlayingMiniRounds) ),
  24. SendPropBool( SENDINFO(m_bControlPointsReset) ),
  25. SendPropInt( SENDINFO(m_iUpdateCapHudParity), CAPHUD_PARITY_BITS, SPROP_UNSIGNED ),
  26. // data variables
  27. SendPropArray( SendPropVector( SENDINFO_ARRAY(m_vCPPositions), -1, SPROP_COORD), m_vCPPositions ),
  28. SendPropArray3( SENDINFO_ARRAY3(m_bCPIsVisible), SendPropInt( SENDINFO_ARRAY(m_bCPIsVisible), 1, SPROP_UNSIGNED ) ),
  29. SendPropArray3( SENDINFO_ARRAY3(m_flLazyCapPerc), SendPropFloat( SENDINFO_ARRAY(m_flLazyCapPerc) ) ),
  30. SendPropArray3( SENDINFO_ARRAY3(m_iTeamIcons), SendPropInt( SENDINFO_ARRAY(m_iTeamIcons), 8, SPROP_UNSIGNED ) ),
  31. SendPropArray3( SENDINFO_ARRAY3(m_iTeamOverlays), SendPropInt( SENDINFO_ARRAY(m_iTeamOverlays), 8, SPROP_UNSIGNED ) ),
  32. SendPropArray3( SENDINFO_ARRAY3(m_iTeamReqCappers), SendPropInt( SENDINFO_ARRAY(m_iTeamReqCappers), 4, SPROP_UNSIGNED ) ),
  33. SendPropArray3( SENDINFO_ARRAY3(m_flTeamCapTime), SendPropTime( SENDINFO_ARRAY(m_flTeamCapTime) ) ),
  34. SendPropArray3( SENDINFO_ARRAY3(m_iPreviousPoints), SendPropInt( SENDINFO_ARRAY(m_iPreviousPoints), 8 ) ),
  35. SendPropArray3( SENDINFO_ARRAY3(m_bTeamCanCap), SendPropBool( SENDINFO_ARRAY(m_bTeamCanCap) ) ),
  36. SendPropArray3( SENDINFO_ARRAY3(m_iTeamBaseIcons), SendPropInt( SENDINFO_ARRAY(m_iTeamBaseIcons), 8 ) ),
  37. SendPropArray3( SENDINFO_ARRAY3(m_iBaseControlPoints), SendPropInt( SENDINFO_ARRAY(m_iBaseControlPoints), 8 ) ),
  38. SendPropArray3( SENDINFO_ARRAY3(m_bInMiniRound), SendPropBool( SENDINFO_ARRAY(m_bInMiniRound) ) ),
  39. SendPropArray3( SENDINFO_ARRAY3(m_iWarnOnCap), SendPropInt( SENDINFO_ARRAY(m_iWarnOnCap), 4, SPROP_UNSIGNED ) ),
  40. SendPropArray( SendPropStringT( SENDINFO_ARRAY( m_iszWarnSound ) ), m_iszWarnSound ),
  41. SendPropArray3( SENDINFO_ARRAY3(m_flPathDistance), SendPropFloat( SENDINFO_ARRAY(m_flPathDistance), 8, 0, 0.0f, 1.0f ) ),
  42. SendPropArray3( SENDINFO_ARRAY3(m_iCPGroup), SendPropInt( SENDINFO_ARRAY(m_iCPGroup), 5 ) ),
  43. SendPropArray3( SENDINFO_ARRAY3(m_bCPLocked), SendPropBool( SENDINFO_ARRAY(m_bCPLocked) ) ),
  44. SendPropArray3( SENDINFO_ARRAY3(m_nNumNodeHillData), SendPropInt( SENDINFO_ARRAY(m_nNumNodeHillData), 4, SPROP_UNSIGNED ) ),
  45. SendPropArray3( SENDINFO_ARRAY3(m_flNodeHillData), SendPropFloat( SENDINFO_ARRAY(m_flNodeHillData), 8, 0, 0.0f, 1.0f ) ),
  46. SendPropArray3( SENDINFO_ARRAY3(m_bTrackAlarm), SendPropBool( SENDINFO_ARRAY(m_bTrackAlarm) ) ),
  47. SendPropArray3( SENDINFO_ARRAY3(m_flUnlockTimes), SendPropFloat( SENDINFO_ARRAY(m_flUnlockTimes) ) ),
  48. SendPropArray3( SENDINFO_ARRAY3(m_bHillIsDownhill), SendPropBool( SENDINFO_ARRAY(m_bHillIsDownhill) ) ),
  49. SendPropArray3( SENDINFO_ARRAY3(m_flCPTimerTimes), SendPropFloat( SENDINFO_ARRAY(m_flCPTimerTimes) ) ),
  50. // state variables
  51. SendPropArray3( SENDINFO_ARRAY3(m_iNumTeamMembers), SendPropInt( SENDINFO_ARRAY(m_iNumTeamMembers), 4, SPROP_UNSIGNED ) ),
  52. SendPropArray3( SENDINFO_ARRAY3(m_iCappingTeam), SendPropInt( SENDINFO_ARRAY(m_iCappingTeam), 4, SPROP_UNSIGNED ) ),
  53. SendPropArray3( SENDINFO_ARRAY3(m_iTeamInZone), SendPropInt( SENDINFO_ARRAY(m_iTeamInZone), 4, SPROP_UNSIGNED ) ),
  54. SendPropArray3( SENDINFO_ARRAY3(m_bBlocked), SendPropInt( SENDINFO_ARRAY(m_bBlocked), 1, SPROP_UNSIGNED ) ),
  55. SendPropArray3( SENDINFO_ARRAY3(m_iOwner), SendPropInt( SENDINFO_ARRAY(m_iOwner), 4, SPROP_UNSIGNED ) ),
  56. SendPropArray3( SENDINFO_ARRAY3(m_bCPCapRateScalesWithPlayers), SendPropBool( SENDINFO_ARRAY(m_bCPCapRateScalesWithPlayers) ) ),
  57. SendPropString( SENDINFO(m_pszCapLayoutInHUD) ),
  58. SendPropFloat( SENDINFO( m_flCustomPositionX ) ),
  59. SendPropFloat( SENDINFO( m_flCustomPositionY ) ),
  60. END_SEND_TABLE()
  61. BEGIN_DATADESC( CBaseTeamObjectiveResource )
  62. DEFINE_FIELD( m_iTimerToShowInHUD, FIELD_INTEGER ),
  63. DEFINE_FIELD( m_iStopWatchTimer, FIELD_INTEGER ),
  64. DEFINE_FIELD( m_iNumControlPoints, FIELD_INTEGER ),
  65. DEFINE_FIELD( m_bPlayingMiniRounds, FIELD_BOOLEAN ),
  66. DEFINE_FIELD( m_bControlPointsReset, FIELD_BOOLEAN ),
  67. DEFINE_FIELD( m_iUpdateCapHudParity, FIELD_INTEGER ),
  68. DEFINE_FIELD( m_flCustomPositionX, FIELD_FLOAT ),
  69. DEFINE_FIELD( m_flCustomPositionY, FIELD_FLOAT ),
  70. DEFINE_ARRAY( m_vCPPositions, FIELD_VECTOR, MAX_CONTROL_POINTS ),
  71. DEFINE_ARRAY( m_bCPIsVisible, FIELD_INTEGER, MAX_CONTROL_POINTS ),
  72. DEFINE_ARRAY( m_flLazyCapPerc, FIELD_FLOAT, MAX_CONTROL_POINTS ),
  73. DEFINE_ARRAY( m_iTeamIcons, FIELD_INTEGER, MAX_CONTROL_POINTS*MAX_CONTROL_POINT_TEAMS ),
  74. DEFINE_ARRAY( m_iTeamOverlays, FIELD_INTEGER, MAX_CONTROL_POINTS*MAX_CONTROL_POINT_TEAMS ),
  75. DEFINE_ARRAY( m_iTeamReqCappers, FIELD_INTEGER, MAX_CONTROL_POINTS*MAX_CONTROL_POINT_TEAMS ),
  76. DEFINE_ARRAY( m_flTeamCapTime, FIELD_FLOAT, MAX_CONTROL_POINTS*MAX_CONTROL_POINT_TEAMS ),
  77. DEFINE_ARRAY( m_iPreviousPoints, FIELD_INTEGER, MAX_CONTROL_POINTS*MAX_CONTROL_POINT_TEAMS*MAX_PREVIOUS_POINTS ),
  78. DEFINE_ARRAY( m_bTeamCanCap, FIELD_BOOLEAN, MAX_CONTROL_POINTS*MAX_CONTROL_POINT_TEAMS ),
  79. DEFINE_ARRAY( m_iTeamBaseIcons, FIELD_INTEGER, MAX_TEAMS ),
  80. DEFINE_ARRAY( m_iBaseControlPoints, FIELD_INTEGER, MAX_TEAMS ),
  81. DEFINE_ARRAY( m_bInMiniRound, FIELD_BOOLEAN, MAX_CONTROL_POINTS ),
  82. DEFINE_ARRAY( m_iWarnOnCap, FIELD_INTEGER, MAX_CONTROL_POINTS ),
  83. DEFINE_ARRAY( m_iszWarnSound, FIELD_STRING, MAX_CONTROL_POINTS ),
  84. DEFINE_ARRAY( m_iNumTeamMembers, FIELD_INTEGER, MAX_CONTROL_POINTS*MAX_CONTROL_POINT_TEAMS ),
  85. DEFINE_ARRAY( m_iCappingTeam, FIELD_INTEGER, MAX_CONTROL_POINTS ),
  86. DEFINE_ARRAY( m_iTeamInZone, FIELD_INTEGER, MAX_CONTROL_POINTS ),
  87. DEFINE_ARRAY( m_bBlocked, FIELD_BOOLEAN, MAX_CONTROL_POINTS ),
  88. DEFINE_ARRAY( m_iOwner, FIELD_INTEGER, MAX_CONTROL_POINTS ),
  89. DEFINE_ARRAY( m_bCPCapRateScalesWithPlayers, FIELD_BOOLEAN, MAX_CONTROL_POINTS ),
  90. DEFINE_ARRAY( m_pszCapLayoutInHUD, FIELD_CHARACTER, MAX_CAPLAYOUT_LENGTH ),
  91. DEFINE_ARRAY( m_flCapPercentages, FIELD_FLOAT, MAX_CONTROL_POINTS ),
  92. DEFINE_ARRAY( m_iCPGroup, FIELD_INTEGER, MAX_CONTROL_POINTS ),
  93. DEFINE_ARRAY( m_bCPLocked, FIELD_BOOLEAN, MAX_CONTROL_POINTS ),
  94. DEFINE_ARRAY( m_nNumNodeHillData, FIELD_INTEGER, TEAM_TRAIN_MAX_TEAMS ),
  95. DEFINE_ARRAY( m_flNodeHillData, FIELD_FLOAT, TEAM_TRAIN_HILLS_ARRAY_SIZE ),
  96. DEFINE_ARRAY( m_bTrackAlarm, FIELD_BOOLEAN, TEAM_TRAIN_MAX_TEAMS ),
  97. DEFINE_ARRAY( m_flUnlockTimes, FIELD_FLOAT, MAX_CONTROL_POINTS ),
  98. DEFINE_ARRAY( m_flCPTimerTimes, FIELD_FLOAT, MAX_CONTROL_POINTS ),
  99. DEFINE_THINKFUNC( ObjectiveThink ),
  100. END_DATADESC()
  101. CBaseTeamObjectiveResource *g_pObjectiveResource = NULL;
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. //-----------------------------------------------------------------------------
  105. CBaseTeamObjectiveResource::CBaseTeamObjectiveResource()
  106. {
  107. g_pObjectiveResource = this;
  108. m_bPlayingMiniRounds = false;
  109. m_iUpdateCapHudParity = 0;
  110. m_bControlPointsReset = false;
  111. m_flCustomPositionX = -1.f;
  112. m_flCustomPositionY = -1.f;
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. //-----------------------------------------------------------------------------
  117. CBaseTeamObjectiveResource::~CBaseTeamObjectiveResource()
  118. {
  119. Assert( g_pObjectiveResource == this );
  120. g_pObjectiveResource = NULL;
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. //-----------------------------------------------------------------------------
  125. void CBaseTeamObjectiveResource::Spawn( void )
  126. {
  127. m_iNumControlPoints = 0;
  128. // If you hit this, you've got too many teams for the control point system to handle.
  129. Assert( GetNumberOfTeams() < MAX_CONTROL_POINT_TEAMS );
  130. for ( int i=0; i < MAX_CONTROL_POINTS; i++ )
  131. {
  132. // data variables
  133. m_vCPPositions.Set( i, vec3_origin );
  134. m_bCPIsVisible.Set( i, true );
  135. m_bBlocked.Set( i, false );
  136. // state variables
  137. m_iOwner.Set( i, TEAM_UNASSIGNED );
  138. m_iCappingTeam.Set( i, TEAM_UNASSIGNED );
  139. m_iTeamInZone.Set( i, TEAM_UNASSIGNED );
  140. m_bInMiniRound.Set( i, true );
  141. m_iWarnOnCap.Set( i, CP_WARN_NORMAL );
  142. m_iCPGroup.Set( i, TEAM_INVALID );
  143. m_flLazyCapPerc.Set( i, 0.0 );
  144. m_bCPLocked.Set( i, false );
  145. m_flUnlockTimes.Set( i, 0.0 );
  146. m_flCPTimerTimes.Set( i, -1.0 );
  147. m_bCPCapRateScalesWithPlayers.Set( i, true );
  148. for ( int team = 0; team < MAX_CONTROL_POINT_TEAMS; team++ )
  149. {
  150. int iTeamIndex = TEAM_ARRAY( i, team );
  151. m_iTeamIcons.Set( iTeamIndex, 0 );
  152. m_iTeamOverlays.Set( iTeamIndex, 0 );
  153. m_iTeamReqCappers.Set( iTeamIndex, 0 );
  154. m_flTeamCapTime.Set( iTeamIndex, 0.0f );
  155. m_iNumTeamMembers.Set( TEAM_ARRAY( i, team ), 0 );
  156. for ( int ipoint = 0; ipoint < MAX_PREVIOUS_POINTS; ipoint++ )
  157. {
  158. int iIntIndex = ipoint + (i * MAX_PREVIOUS_POINTS) + (team * MAX_CONTROL_POINTS * MAX_PREVIOUS_POINTS);
  159. m_iPreviousPoints.Set( iIntIndex, -1 );
  160. }
  161. m_bTeamCanCap.Set( iTeamIndex, false );
  162. }
  163. }
  164. for ( int i = 0; i < MAX_TEAMS; i++ )
  165. {
  166. m_iBaseControlPoints.Set( i, -1 );
  167. }
  168. int nNumEntriesPerTeam = TEAM_TRAIN_MAX_HILLS * TEAM_TRAIN_FLOATS_PER_HILL;
  169. for ( int i = 0; i < TEAM_TRAIN_MAX_TEAMS; i++ )
  170. {
  171. m_nNumNodeHillData.Set( i, 0 );
  172. m_bTrackAlarm.Set( i, false );
  173. int iStartingIndex = i * nNumEntriesPerTeam;
  174. for ( int j = 0 ; j < nNumEntriesPerTeam ; j++ )
  175. {
  176. m_flNodeHillData.Set( iStartingIndex + j, 0 );
  177. }
  178. iStartingIndex = i * TEAM_TRAIN_MAX_HILLS;
  179. for ( int j = 0; j < TEAM_TRAIN_MAX_HILLS; j++ )
  180. {
  181. m_bHillIsDownhill.Set( iStartingIndex + j, 0 );
  182. }
  183. }
  184. SetThink( &CBaseTeamObjectiveResource::ObjectiveThink );
  185. SetNextThink( gpGlobals->curtime + LAZY_UPDATE_TIME );
  186. }
  187. //-----------------------------------------------------------------------------
  188. // Purpose:
  189. //-----------------------------------------------------------------------------
  190. void CBaseTeamObjectiveResource::ObjectiveThink( void )
  191. {
  192. SetNextThink( gpGlobals->curtime + LAZY_UPDATE_TIME );
  193. for ( int i = 0; i < m_iNumControlPoints; i++ )
  194. {
  195. if ( m_iCappingTeam[i] )
  196. {
  197. m_flLazyCapPerc.Set( i, m_flCapPercentages[i] );
  198. }
  199. }
  200. }
  201. //-----------------------------------------------------------------------------
  202. // Purpose: The objective resource is always transmitted to clients
  203. //-----------------------------------------------------------------------------
  204. int CBaseTeamObjectiveResource::UpdateTransmitState()
  205. {
  206. // ALWAYS transmit to all clients.
  207. return SetTransmitState( FL_EDICT_ALWAYS );
  208. }
  209. //-----------------------------------------------------------------------------
  210. // Purpose: Round is starting, reset state
  211. //-----------------------------------------------------------------------------
  212. void CBaseTeamObjectiveResource::ResetControlPoints( void )
  213. {
  214. for ( int i=0; i < MAX_CONTROL_POINTS; i++ )
  215. {
  216. m_iCappingTeam.Set( i, TEAM_UNASSIGNED );
  217. m_iTeamInZone.Set( i, TEAM_UNASSIGNED );
  218. m_bInMiniRound.Set( i, true );
  219. for ( int team = 0; team < MAX_CONTROL_POINT_TEAMS; team++ )
  220. {
  221. m_iNumTeamMembers.Set( TEAM_ARRAY( i, team ), 0.0f );
  222. }
  223. }
  224. UpdateCapHudElement();
  225. m_bControlPointsReset = !m_bControlPointsReset;
  226. }
  227. //-----------------------------------------------------------------------------
  228. // Purpose: Data setting functions
  229. //-----------------------------------------------------------------------------
  230. void CBaseTeamObjectiveResource::SetNumControlPoints( int num )
  231. {
  232. Assert( num <= MAX_CONTROL_POINTS );
  233. m_iNumControlPoints = num;
  234. }
  235. //-----------------------------------------------------------------------------
  236. // Purpose:
  237. //-----------------------------------------------------------------------------
  238. void CBaseTeamObjectiveResource::SetCPIcons( int index, int iTeam, int iIcon )
  239. {
  240. AssertValidIndex(index);
  241. m_iTeamIcons.Set( TEAM_ARRAY( index, iTeam ), iIcon );
  242. }
  243. //-----------------------------------------------------------------------------
  244. // Purpose:
  245. //-----------------------------------------------------------------------------
  246. void CBaseTeamObjectiveResource::SetCPOverlays( int index, int iTeam, int iIcon )
  247. {
  248. AssertValidIndex(index);
  249. m_iTeamOverlays.Set( TEAM_ARRAY( index, iTeam ), iIcon );
  250. }
  251. //-----------------------------------------------------------------------------
  252. // Purpose:
  253. //-----------------------------------------------------------------------------
  254. void CBaseTeamObjectiveResource::SetTeamBaseIcons( int iTeam, int iBaseIcon )
  255. {
  256. Assert( iTeam >= 0 && iTeam < MAX_TEAMS );
  257. m_iTeamBaseIcons.Set( iTeam, iBaseIcon );
  258. }
  259. //-----------------------------------------------------------------------------
  260. // Purpose:
  261. //-----------------------------------------------------------------------------
  262. void CBaseTeamObjectiveResource::SetCPPosition( int index, const Vector& vPosition )
  263. {
  264. AssertValidIndex(index);
  265. m_vCPPositions.Set( index, vPosition );
  266. }
  267. //-----------------------------------------------------------------------------
  268. // Purpose:
  269. //-----------------------------------------------------------------------------
  270. void CBaseTeamObjectiveResource::SetCPVisible( int index, bool bVisible )
  271. {
  272. AssertValidIndex(index);
  273. m_bCPIsVisible.Set( index, bVisible );
  274. }
  275. //-----------------------------------------------------------------------------
  276. // Purpose:
  277. //-----------------------------------------------------------------------------
  278. void CBaseTeamObjectiveResource::SetWarnOnCap( int index, int iWarnLevel )
  279. {
  280. AssertValidIndex(index);
  281. m_iWarnOnCap.Set( index, iWarnLevel );
  282. }
  283. //-----------------------------------------------------------------------------
  284. // Purpose:
  285. //-----------------------------------------------------------------------------
  286. void CBaseTeamObjectiveResource::SetWarnSound( int index, string_t iszSound )
  287. {
  288. AssertValidIndex(index);
  289. m_iszWarnSound.Set( index, iszSound );
  290. }
  291. //-----------------------------------------------------------------------------
  292. // Purpose:
  293. //-----------------------------------------------------------------------------
  294. void CBaseTeamObjectiveResource::SetCPGroup( int index, int iCPGroup )
  295. {
  296. AssertValidIndex(index);
  297. m_iCPGroup.Set( index, iCPGroup );
  298. }
  299. //-----------------------------------------------------------------------------
  300. // Purpose:
  301. //-----------------------------------------------------------------------------
  302. void CBaseTeamObjectiveResource::SetCPRequiredCappers( int index, int iTeam, int iReqPlayers )
  303. {
  304. AssertValidIndex(index);
  305. m_iTeamReqCappers.Set( TEAM_ARRAY( index, iTeam ), iReqPlayers );
  306. }
  307. //-----------------------------------------------------------------------------
  308. // Purpose:
  309. //-----------------------------------------------------------------------------
  310. void CBaseTeamObjectiveResource::SetCPCapTime( int index, int iTeam, float flTime )
  311. {
  312. AssertValidIndex(index);
  313. m_flTeamCapTime.Set( TEAM_ARRAY( index, iTeam ), flTime );
  314. }
  315. //-----------------------------------------------------------------------------
  316. // Purpose:
  317. //-----------------------------------------------------------------------------
  318. void CBaseTeamObjectiveResource::SetCPCapPercentage( int index, float flTime )
  319. {
  320. AssertValidIndex(index);
  321. m_flCapPercentages[index] = flTime;
  322. }
  323. //-----------------------------------------------------------------------------
  324. // Purpose:
  325. //-----------------------------------------------------------------------------
  326. float CBaseTeamObjectiveResource::GetCPCapPercentage( int index )
  327. {
  328. AssertValidIndex(index);
  329. return m_flCapPercentages[index];
  330. }
  331. //-----------------------------------------------------------------------------
  332. // Purpose:
  333. //-----------------------------------------------------------------------------
  334. void CBaseTeamObjectiveResource::SetCPUnlockTime( int index, float flTime )
  335. {
  336. AssertValidIndex(index);
  337. m_flUnlockTimes.Set( index, flTime );
  338. }
  339. //-----------------------------------------------------------------------------
  340. // Purpose:
  341. //-----------------------------------------------------------------------------
  342. void CBaseTeamObjectiveResource::SetCPTimerTime( int index, float flTime )
  343. {
  344. AssertValidIndex(index);
  345. m_flCPTimerTimes.Set( index, flTime );
  346. }
  347. //-----------------------------------------------------------------------------
  348. // Purpose:
  349. //-----------------------------------------------------------------------------
  350. void CBaseTeamObjectiveResource::SetCPCapTimeScalesWithPlayers( int index, bool bScales )
  351. {
  352. AssertValidIndex(index);
  353. m_bCPCapRateScalesWithPlayers.Set( index, bScales );
  354. }
  355. //-----------------------------------------------------------------------------
  356. // Purpose:
  357. //-----------------------------------------------------------------------------
  358. void CBaseTeamObjectiveResource::SetTeamCanCap( int index, int iTeam, bool bCanCap )
  359. {
  360. AssertValidIndex(index);
  361. m_bTeamCanCap.Set( TEAM_ARRAY( index, iTeam ), bCanCap );
  362. UpdateCapHudElement();
  363. }
  364. //-----------------------------------------------------------------------------
  365. // Purpose:
  366. //-----------------------------------------------------------------------------
  367. void CBaseTeamObjectiveResource::SetBaseCP( int index, int iTeam )
  368. {
  369. Assert( iTeam < MAX_TEAMS );
  370. m_iBaseControlPoints.Set( iTeam, index );
  371. }
  372. //-----------------------------------------------------------------------------
  373. // Purpose:
  374. //-----------------------------------------------------------------------------
  375. void CBaseTeamObjectiveResource::SetPreviousPoint( int index, int iTeam, int iPrevIndex, int iPrevPoint )
  376. {
  377. AssertValidIndex(index);
  378. Assert( iPrevIndex >= 0 && iPrevIndex < MAX_PREVIOUS_POINTS );
  379. int iIntIndex = iPrevIndex + (index * MAX_PREVIOUS_POINTS) + (iTeam * MAX_CONTROL_POINTS * MAX_PREVIOUS_POINTS);
  380. m_iPreviousPoints.Set( iIntIndex, iPrevPoint );
  381. }
  382. //-----------------------------------------------------------------------------
  383. // Purpose:
  384. //-----------------------------------------------------------------------------
  385. int CBaseTeamObjectiveResource::GetPreviousPointForPoint( int index, int team, int iPrevIndex )
  386. {
  387. AssertValidIndex(index);
  388. Assert( iPrevIndex >= 0 && iPrevIndex < MAX_PREVIOUS_POINTS );
  389. int iIntIndex = iPrevIndex + (index * MAX_PREVIOUS_POINTS) + (team * MAX_CONTROL_POINTS * MAX_PREVIOUS_POINTS);
  390. return m_iPreviousPoints[ iIntIndex ];
  391. }
  392. //-----------------------------------------------------------------------------
  393. // Purpose:
  394. //-----------------------------------------------------------------------------
  395. bool CBaseTeamObjectiveResource::TeamCanCapPoint( int index, int team )
  396. {
  397. AssertValidIndex(index);
  398. return m_bTeamCanCap[ TEAM_ARRAY( index, team ) ];
  399. }
  400. //-----------------------------------------------------------------------------
  401. // Purpose: Data setting functions
  402. //-----------------------------------------------------------------------------
  403. void CBaseTeamObjectiveResource::SetNumPlayers( int index, int team, int iNumPlayers )
  404. {
  405. AssertValidIndex(index);
  406. m_iNumTeamMembers.Set( TEAM_ARRAY( index, team ), iNumPlayers );
  407. UpdateCapHudElement();
  408. }
  409. //-----------------------------------------------------------------------------
  410. // Purpose:
  411. //-----------------------------------------------------------------------------
  412. void CBaseTeamObjectiveResource::StartCap( int index, int team )
  413. {
  414. AssertValidIndex(index);
  415. if ( m_iCappingTeam.Get( index ) != team )
  416. {
  417. m_iCappingTeam.Set( index, team );
  418. UpdateCapHudElement();
  419. }
  420. }
  421. //-----------------------------------------------------------------------------
  422. // Purpose:
  423. //-----------------------------------------------------------------------------
  424. void CBaseTeamObjectiveResource::SetOwningTeam( int index, int team )
  425. {
  426. AssertValidIndex(index);
  427. m_iOwner.Set( index, team );
  428. // clear the capper
  429. m_iCappingTeam.Set( index, TEAM_UNASSIGNED );
  430. UpdateCapHudElement();
  431. }
  432. //-----------------------------------------------------------------------------
  433. // Purpose:
  434. //-----------------------------------------------------------------------------
  435. void CBaseTeamObjectiveResource::SetCappingTeam( int index, int team )
  436. {
  437. AssertValidIndex(index);
  438. if ( m_iCappingTeam.Get( index ) != team )
  439. {
  440. m_iCappingTeam.Set( index, team );
  441. UpdateCapHudElement();
  442. }
  443. }
  444. //-----------------------------------------------------------------------------
  445. // Purpose:
  446. //-----------------------------------------------------------------------------
  447. void CBaseTeamObjectiveResource::SetTeamInZone( int index, int team )
  448. {
  449. AssertValidIndex(index);
  450. if ( m_iTeamInZone.Get( index ) != team )
  451. {
  452. m_iTeamInZone.Set( index, team );
  453. UpdateCapHudElement();
  454. }
  455. }
  456. //-----------------------------------------------------------------------------
  457. // Purpose:
  458. //-----------------------------------------------------------------------------
  459. void CBaseTeamObjectiveResource::SetCapBlocked( int index, bool bBlocked )
  460. {
  461. AssertValidIndex(index);
  462. if ( m_bBlocked.Get( index ) != bBlocked )
  463. {
  464. m_bBlocked.Set( index, bBlocked );
  465. UpdateCapHudElement();
  466. }
  467. }
  468. //-----------------------------------------------------------------------------
  469. // Purpose:
  470. //-----------------------------------------------------------------------------
  471. int CBaseTeamObjectiveResource::GetOwningTeam( int index )
  472. {
  473. if ( index >= m_iNumControlPoints )
  474. return TEAM_UNASSIGNED;
  475. return m_iOwner[index];
  476. }
  477. //-----------------------------------------------------------------------------
  478. // Purpose:
  479. //-----------------------------------------------------------------------------
  480. void CBaseTeamObjectiveResource::UpdateCapHudElement( void )
  481. {
  482. m_iUpdateCapHudParity = (m_iUpdateCapHudParity + 1) & CAPHUD_PARITY_MASK;
  483. }
  484. //-----------------------------------------------------------------------------
  485. // Purpose:
  486. //-----------------------------------------------------------------------------
  487. void CBaseTeamObjectiveResource::SetTrainPathDistance( int index, float flDistance )
  488. {
  489. AssertValidIndex(index);
  490. m_flPathDistance.Set( index, flDistance );
  491. }
  492. //-----------------------------------------------------------------------------
  493. // Purpose:
  494. //-----------------------------------------------------------------------------
  495. void CBaseTeamObjectiveResource::SetCPLocked( int index, bool bLocked )
  496. {
  497. // This assert always fires on map load and interferes with daily development
  498. //AssertValidIndex(index);
  499. m_bCPLocked.Set( index, bLocked );
  500. }
  501. //-----------------------------------------------------------------------------
  502. // Purpose:
  503. //-----------------------------------------------------------------------------
  504. void CBaseTeamObjectiveResource::SetTrackAlarm( int index, bool bAlarm )
  505. {
  506. Assert( index < TEAM_TRAIN_MAX_TEAMS );
  507. m_bTrackAlarm.Set( index, bAlarm );
  508. }