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.

206 lines
5.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CS's custom C_PlayerResource
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "c_cs_playerresource.h"
  9. #include <shareddefs.h>
  10. #include <cs_shareddefs.h>
  11. #include "hud.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. IMPLEMENT_CLIENTCLASS_DT(C_CS_PlayerResource, DT_CSPlayerResource, CCSPlayerResource)
  15. RecvPropInt( RECVINFO( m_iPlayerC4 ) ),
  16. RecvPropInt( RECVINFO( m_iPlayerVIP ) ),
  17. RecvPropVector( RECVINFO(m_vecC4) ),
  18. RecvPropArray3( RECVINFO_ARRAY(m_bHostageAlive), RecvPropInt( RECVINFO(m_bHostageAlive[0]))),
  19. RecvPropArray3( RECVINFO_ARRAY(m_isHostageFollowingSomeone), RecvPropInt( RECVINFO(m_isHostageFollowingSomeone[0]))),
  20. RecvPropArray3( RECVINFO_ARRAY(m_iHostageEntityIDs), RecvPropInt( RECVINFO(m_iHostageEntityIDs[0]))),
  21. RecvPropArray3( RECVINFO_ARRAY(m_iHostageX), RecvPropInt( RECVINFO(m_iHostageX[0]))),
  22. RecvPropArray3( RECVINFO_ARRAY(m_iHostageY), RecvPropInt( RECVINFO(m_iHostageY[0]))),
  23. RecvPropArray3( RECVINFO_ARRAY(m_iHostageZ), RecvPropInt( RECVINFO(m_iHostageZ[0]))),
  24. RecvPropVector( RECVINFO(m_bombsiteCenterA) ),
  25. RecvPropVector( RECVINFO(m_bombsiteCenterB) ),
  26. RecvPropArray3( RECVINFO_ARRAY(m_hostageRescueX), RecvPropInt( RECVINFO(m_hostageRescueX[0]))),
  27. RecvPropArray3( RECVINFO_ARRAY(m_hostageRescueY), RecvPropInt( RECVINFO(m_hostageRescueY[0]))),
  28. RecvPropArray3( RECVINFO_ARRAY(m_hostageRescueZ), RecvPropInt( RECVINFO(m_hostageRescueZ[0]))),
  29. RecvPropInt( RECVINFO( m_bBombSpotted ) ),
  30. RecvPropArray3( RECVINFO_ARRAY(m_bPlayerSpotted), RecvPropInt( RECVINFO(m_bPlayerSpotted[0]))),
  31. RecvPropArray3( RECVINFO_ARRAY(m_iMVPs), RecvPropInt( RECVINFO(m_iMVPs[0]))),
  32. RecvPropArray3( RECVINFO_ARRAY(m_bHasDefuser), RecvPropInt( RECVINFO(m_bHasDefuser[0]))),
  33. RecvPropArray3( RECVINFO_ARRAY(m_szClan), RecvPropString( RECVINFO(m_szClan[0]))),
  34. END_RECV_TABLE()
  35. //=============================================================================
  36. // HPE_END
  37. //=============================================================================
  38. //-----------------------------------------------------------------------------
  39. // Purpose:
  40. //-----------------------------------------------------------------------------
  41. C_CS_PlayerResource::C_CS_PlayerResource()
  42. {
  43. m_Colors[TEAM_TERRORIST] = COLOR_RED;
  44. m_Colors[TEAM_CT] = COLOR_BLUE;
  45. memset( m_iMVPs, 0, sizeof( m_iMVPs ) );
  46. memset( m_bHasDefuser, 0, sizeof( m_bHasDefuser ) );
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose:
  50. //-----------------------------------------------------------------------------
  51. C_CS_PlayerResource::~C_CS_PlayerResource()
  52. {
  53. }
  54. bool C_CS_PlayerResource::IsVIP(int iIndex )
  55. {
  56. return m_iPlayerVIP == iIndex;
  57. }
  58. bool C_CS_PlayerResource::HasC4(int iIndex )
  59. {
  60. return m_iPlayerC4 == iIndex;
  61. }
  62. bool C_CS_PlayerResource::IsHostageAlive(int iIndex)
  63. {
  64. if ( iIndex < 0 || iIndex >= MAX_HOSTAGES )
  65. return false;
  66. return m_bHostageAlive[iIndex];
  67. }
  68. bool C_CS_PlayerResource::IsHostageFollowingSomeone(int iIndex)
  69. {
  70. if ( iIndex < 0 || iIndex >= MAX_HOSTAGES )
  71. return false;
  72. return m_isHostageFollowingSomeone[iIndex];
  73. }
  74. int C_CS_PlayerResource::GetHostageEntityID(int iIndex)
  75. {
  76. if ( iIndex < 0 || iIndex >= MAX_HOSTAGES )
  77. return -1;
  78. return m_iHostageEntityIDs[iIndex];
  79. }
  80. const Vector C_CS_PlayerResource::GetHostagePosition( int iIndex )
  81. {
  82. if ( iIndex < 0 || iIndex >= MAX_HOSTAGES )
  83. return vec3_origin;
  84. Vector ret;
  85. ret.x = m_iHostageX[iIndex];
  86. ret.y = m_iHostageY[iIndex];
  87. ret.z = m_iHostageZ[iIndex];
  88. return ret;
  89. }
  90. const Vector C_CS_PlayerResource::GetC4Postion()
  91. {
  92. if ( m_iPlayerC4 > 0 )
  93. {
  94. // C4 is carried by player
  95. C_BasePlayer *pPlayer = UTIL_PlayerByIndex( m_iPlayerC4 );
  96. if ( pPlayer )
  97. {
  98. return pPlayer->GetAbsOrigin();
  99. }
  100. }
  101. // C4 is lying on ground
  102. return m_vecC4;
  103. }
  104. const Vector C_CS_PlayerResource::GetBombsiteAPosition()
  105. {
  106. return m_bombsiteCenterA;
  107. }
  108. const Vector C_CS_PlayerResource::GetBombsiteBPosition()
  109. {
  110. return m_bombsiteCenterB;
  111. }
  112. const Vector C_CS_PlayerResource::GetHostageRescuePosition( int iIndex )
  113. {
  114. if ( iIndex < 0 || iIndex >= MAX_HOSTAGE_RESCUES )
  115. return vec3_origin;
  116. Vector ret;
  117. ret.x = m_hostageRescueX[iIndex];
  118. ret.y = m_hostageRescueY[iIndex];
  119. ret.z = m_hostageRescueZ[iIndex];
  120. return ret;
  121. }
  122. int C_CS_PlayerResource::GetPlayerClass( int iIndex )
  123. {
  124. if ( !IsConnected( iIndex ) )
  125. {
  126. return CS_CLASS_NONE;
  127. }
  128. return m_iPlayerClasses[ iIndex ];
  129. }
  130. //--------------------------------------------------------------------------------------------------------
  131. bool C_CS_PlayerResource::IsBombSpotted( void ) const
  132. {
  133. return m_bBombSpotted;
  134. }
  135. //--------------------------------------------------------------------------------------------------------
  136. bool C_CS_PlayerResource::IsPlayerSpotted( int iIndex )
  137. {
  138. if ( !IsConnected( iIndex ) )
  139. return false;
  140. return m_bPlayerSpotted[iIndex];
  141. }
  142. //-----------------------------------------------------------------------------
  143. const char *C_CS_PlayerResource::GetClanTag( int iIndex )
  144. {
  145. if ( iIndex < 1 || iIndex > MAX_PLAYERS )
  146. {
  147. Assert( false );
  148. return "";
  149. }
  150. if ( !IsConnected( iIndex ) )
  151. return "";
  152. return m_szClan[iIndex];
  153. }
  154. //-----------------------------------------------------------------------------
  155. int C_CS_PlayerResource::GetNumMVPs( int iIndex )
  156. {
  157. if ( !IsConnected( iIndex ) )
  158. return false;
  159. return m_iMVPs[iIndex];
  160. }
  161. //-----------------------------------------------------------------------------
  162. bool C_CS_PlayerResource::HasDefuser( int iIndex )
  163. {
  164. if ( !IsConnected( iIndex ) )
  165. return false;
  166. return m_bHasDefuser[iIndex];
  167. }