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.

176 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Entity that propagates objective data
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "c_dod_objective_resource.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. // owner recv proxy
  12. void RecvProxy_Owner( const CRecvProxyData *pData, void *pStruct, void *pOut )
  13. {
  14. // hacks? Not sure how else to get the index of the integer that is
  15. // being transmitted.
  16. int index = pData->m_pRecvProp->GetOffset() / sizeof(int);
  17. g_pObjectiveResource->SetOwningTeam( index, pData->m_Value.m_Int );
  18. }
  19. // capper recv proxy
  20. void RecvProxy_CappingTeam( const CRecvProxyData *pData, void *pStruct, void *pOut )
  21. {
  22. int index = pData->m_pRecvProp->GetOffset() / sizeof(int);
  23. g_pObjectiveResource->SetCappingTeam( index, pData->m_Value.m_Int );
  24. }
  25. void RecvProxy_BombPlanted( const CRecvProxyData *pData, void *pStruct, void *pOut )
  26. {
  27. int index = pData->m_pRecvProp->GetOffset() / sizeof(bool);
  28. g_pObjectiveResource->SetBombPlanted( index, pData->m_Value.m_Int );
  29. }
  30. IMPLEMENT_CLIENTCLASS_DT_NOBASE(C_DODObjectiveResource, DT_DODObjectiveResource, CDODObjectiveResource)
  31. RecvPropInt( RECVINFO(m_iNumControlPoints) ),
  32. // data variables
  33. RecvPropArray( RecvPropVector(RECVINFO(m_vCPPositions[0])), m_vCPPositions),
  34. RecvPropArray3( RECVINFO_ARRAY(m_bCPIsVisible), RecvPropInt( RECVINFO(m_bCPIsVisible[0]) ) ),
  35. RecvPropArray3( RECVINFO_ARRAY(m_iAlliesIcons), RecvPropInt( RECVINFO(m_iAlliesIcons[0]) ) ),
  36. RecvPropArray3( RECVINFO_ARRAY(m_iAxisIcons), RecvPropInt( RECVINFO(m_iAxisIcons[0]) ) ),
  37. RecvPropArray3( RECVINFO_ARRAY(m_iNeutralIcons), RecvPropInt( RECVINFO(m_iNeutralIcons[0]) ) ),
  38. RecvPropArray3( RECVINFO_ARRAY(m_iTimerCapIcons), RecvPropInt( RECVINFO(m_iTimerCapIcons[0]) ) ),
  39. RecvPropArray3( RECVINFO_ARRAY(m_iBombedIcons), RecvPropInt( RECVINFO(m_iBombedIcons[0]) ) ),
  40. RecvPropArray3( RECVINFO_ARRAY(m_iAlliesReqCappers),RecvPropInt( RECVINFO(m_iAlliesReqCappers[0]) ) ),
  41. RecvPropArray3( RECVINFO_ARRAY(m_iAxisReqCappers), RecvPropInt( RECVINFO(m_iAxisReqCappers[0]) ) ),
  42. RecvPropArray3( RECVINFO_ARRAY(m_flAlliesCapTime), RecvPropTime( RECVINFO(m_flAlliesCapTime[0]) ) ),
  43. RecvPropArray3( RECVINFO_ARRAY(m_flAxisCapTime), RecvPropTime( RECVINFO(m_flAxisCapTime[0]) ) ),
  44. RecvPropArray3( RECVINFO_ARRAY(m_bBombPlanted), RecvPropInt( RECVINFO(m_bBombPlanted[0]), 0, RecvProxy_BombPlanted ) ),
  45. RecvPropArray3( RECVINFO_ARRAY(m_iBombsRequired), RecvPropInt( RECVINFO(m_iBombsRequired[0]) ) ),
  46. RecvPropArray3( RECVINFO_ARRAY(m_iBombsRemaining), RecvPropInt( RECVINFO(m_iBombsRemaining[0]) ) ),
  47. RecvPropArray3( RECVINFO_ARRAY(m_bBombBeingDefused),RecvPropInt( RECVINFO(m_bBombBeingDefused[0]) ) ),
  48. // state variables
  49. RecvPropArray3( RECVINFO_ARRAY(m_iNumAllies), RecvPropInt( RECVINFO(m_iNumAllies[0]) ) ),
  50. RecvPropArray3( RECVINFO_ARRAY(m_iNumAxis), RecvPropInt( RECVINFO(m_iNumAxis[0]) ) ),
  51. RecvPropArray3( RECVINFO_ARRAY(m_iCappingTeam), RecvPropInt( RECVINFO(m_iCappingTeam[0]), 0, RecvProxy_CappingTeam ) ),
  52. RecvPropArray3( RECVINFO_ARRAY(m_iOwner), RecvPropInt( RECVINFO(m_iOwner[0]), 0, RecvProxy_Owner ) ),
  53. END_RECV_TABLE()
  54. C_DODObjectiveResource *g_pObjectiveResource;
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. C_DODObjectiveResource::C_DODObjectiveResource()
  59. {
  60. m_iNumControlPoints = 0;
  61. for ( int i=0; i < MAX_CONTROL_POINTS; i++ )
  62. {
  63. m_flCapStartTimes[i] = 0;
  64. m_flCapEndTimes[i] = 0;
  65. m_iAlliesIcons[i] = 0;
  66. m_iAxisIcons[i] = 0;
  67. m_iNeutralIcons[i] = 0;
  68. m_iTimerCapIcons[i] = 0;
  69. m_iBombedIcons[i] = 0;
  70. m_iNumAllies[i] = 0;
  71. m_iNumAxis[i] = 0;
  72. }
  73. g_pObjectiveResource = this;
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. //-----------------------------------------------------------------------------
  78. C_DODObjectiveResource::~C_DODObjectiveResource()
  79. {
  80. g_pObjectiveResource = NULL;
  81. }
  82. float C_DODObjectiveResource::GetCPCapPercentage( int index )
  83. {
  84. Assert( 0 <= index && index <= m_iNumControlPoints );
  85. float flCapLength = m_flCapEndTimes[index] - m_flCapStartTimes[index];
  86. if( flCapLength <= 0 )
  87. return 0.0f;
  88. float flElapsedTime = gpGlobals->curtime - m_flCapStartTimes[index];
  89. if( flElapsedTime > flCapLength )
  90. return 1.0f;
  91. return ( flElapsedTime / flCapLength );
  92. }
  93. void C_DODObjectiveResource::SetOwningTeam( int index, int team )
  94. {
  95. int cappingTeam = GetCappingTeam(index);
  96. if ( team == cappingTeam )
  97. {
  98. // successful cap, reset things
  99. m_iCappingTeam[index] = TEAM_UNASSIGNED;
  100. m_flCapStartTimes[index] = 0.0f;
  101. m_flCapEndTimes[index] = 0.0f;
  102. }
  103. m_iOwner[index] = team;
  104. }
  105. void C_DODObjectiveResource::SetCappingTeam( int index, int team )
  106. {
  107. if ( team != GetOwningTeam( index ) && ( team == TEAM_ALLIES || team == TEAM_AXIS ) )
  108. {
  109. int caplength = 0;
  110. switch ( team )
  111. {
  112. case TEAM_ALLIES:
  113. caplength = m_flAlliesCapTime[index];
  114. break;
  115. case TEAM_AXIS:
  116. caplength = m_flAxisCapTime[index];
  117. break;
  118. }
  119. // start the cap
  120. m_flCapStartTimes[index] = gpGlobals->curtime;
  121. m_flCapEndTimes[index] = gpGlobals->curtime + caplength;
  122. }
  123. else
  124. {
  125. m_flCapStartTimes[index] = 0.0;
  126. m_flCapEndTimes[index] = 0.0;
  127. }
  128. m_iCappingTeam[index] = team;
  129. }
  130. void C_DODObjectiveResource::SetBombPlanted( int index, int iBombPlanted )
  131. {
  132. // Assert( index < m_iNumControlPoints );
  133. m_bBombPlanted[index] = ( iBombPlanted > 0 );
  134. if ( m_bBombPlanted[index] )
  135. {
  136. // start the countdown, make timer visible
  137. m_flBombEndTimes[index] = gpGlobals->curtime + DOD_BOMB_TIMER_LENGTH;
  138. }
  139. else
  140. {
  141. // hide timer, reset countdown
  142. m_flBombEndTimes[index] = 0;
  143. }
  144. }