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.

237 lines
8.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 "clientmode_tf.h"
  9. #include "c_tf_objective_resource.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. IMPLEMENT_CLIENTCLASS_DT( C_TFObjectiveResource, DT_TFObjectiveResource, CTFObjectiveResource)
  13. RecvPropInt( RECVINFO(m_nMannVsMachineMaxWaveCount) ),
  14. RecvPropInt( RECVINFO(m_nMannVsMachineWaveCount) ),
  15. RecvPropInt( RECVINFO(m_nMannVsMachineWaveEnemyCount) ),
  16. RecvPropInt( RECVINFO(m_nMvMWorldMoney) ),
  17. RecvPropFloat( RECVINFO( m_flMannVsMachineNextWaveTime ) ),
  18. RecvPropBool( RECVINFO( m_bMannVsMachineBetweenWaves ) ),
  19. RecvPropInt( RECVINFO(m_nFlagCarrierUpgradeLevel) ),
  20. RecvPropFloat( RECVINFO( m_flMvMBaseBombUpgradeTime ) ),
  21. RecvPropFloat( RECVINFO( m_flMvMNextBombUpgradeTime ) ),
  22. RecvPropString( RECVINFO( m_iszMvMPopfileName ) ),
  23. RecvPropInt( RECVINFO(m_iChallengeIndex) ),
  24. RecvPropInt( RECVINFO(m_nMvMEventPopfileType) ),
  25. RecvPropArray3( RECVINFO_ARRAY( m_nMannVsMachineWaveClassCounts ), RecvPropInt( RECVINFO( m_nMannVsMachineWaveClassCounts[0] ) ) ),
  26. RecvPropArray( RecvPropString( RECVINFO( m_iszMannVsMachineWaveClassNames[0]) ), m_iszMannVsMachineWaveClassNames ),
  27. RecvPropArray3( RECVINFO_ARRAY( m_nMannVsMachineWaveClassFlags ), RecvPropInt( RECVINFO( m_nMannVsMachineWaveClassFlags[0] ) ) ),
  28. RecvPropArray3( RECVINFO_ARRAY( m_nMannVsMachineWaveClassCounts2 ), RecvPropInt( RECVINFO( m_nMannVsMachineWaveClassCounts2[0] ) ) ),
  29. RecvPropArray( RecvPropString( RECVINFO( m_iszMannVsMachineWaveClassNames2[0]) ), m_iszMannVsMachineWaveClassNames2 ),
  30. RecvPropArray3( RECVINFO_ARRAY( m_nMannVsMachineWaveClassFlags2 ), RecvPropInt( RECVINFO( m_nMannVsMachineWaveClassFlags2[0] ) ) ),
  31. RecvPropArray3( RECVINFO_ARRAY( m_bMannVsMachineWaveClassActive ), RecvPropBool( RECVINFO( m_bMannVsMachineWaveClassActive[0] ) ) ),
  32. RecvPropArray3( RECVINFO_ARRAY( m_bMannVsMachineWaveClassActive2 ), RecvPropBool( RECVINFO( m_bMannVsMachineWaveClassActive2[0] ) ) ),
  33. END_RECV_TABLE()
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. //-----------------------------------------------------------------------------
  37. C_TFObjectiveResource::C_TFObjectiveResource()
  38. {
  39. PrecacheMaterial( "sprites/obj_icons/icon_obj_cap_blu" );
  40. PrecacheMaterial( "sprites/obj_icons/icon_obj_cap_blu_up" );
  41. PrecacheMaterial( "sprites/obj_icons/icon_obj_cap_red" );
  42. PrecacheMaterial( "sprites/obj_icons/icon_obj_cap_red_up" );
  43. PrecacheMaterial( "VGUI/flagtime_empty" );
  44. PrecacheMaterial( "VGUI/flagtime_full" );
  45. m_nMannVsMachineMaxWaveCount = 0;
  46. m_nMannVsMachineWaveCount = 0;
  47. m_nMannVsMachineWaveEnemyCount = 0;
  48. m_nMvMWorldMoney = 0;
  49. m_flMannVsMachineNextWaveTime = 0;
  50. m_bMannVsMachineBetweenWaves = false;
  51. m_nFlagCarrierUpgradeLevel = 0;
  52. m_iChallengeIndex = -1;
  53. m_nMvMEventPopfileType = MVM_EVENT_POPFILE_NONE;
  54. memset( m_nMannVsMachineWaveClassCounts, 0, sizeof( m_nMannVsMachineWaveClassCounts ) );
  55. memset( m_nMannVsMachineWaveClassCounts2, 0, sizeof( m_nMannVsMachineWaveClassCounts2 ) );
  56. memset( m_nMannVsMachineWaveClassFlags, MVM_CLASS_FLAG_NONE, sizeof( m_nMannVsMachineWaveClassFlags ) );
  57. memset( m_nMannVsMachineWaveClassFlags2, MVM_CLASS_FLAG_NONE, sizeof( m_nMannVsMachineWaveClassFlags2 ) );
  58. memset( m_bMannVsMachineWaveClassActive, 0, sizeof( m_bMannVsMachineWaveClassActive ) );
  59. memset( m_bMannVsMachineWaveClassActive2, 0, sizeof( m_bMannVsMachineWaveClassActive2 ) );
  60. int i = 0;
  61. for ( i = 0 ; i < ARRAYSIZE( m_iszMannVsMachineWaveClassNames ) ; ++i )
  62. {
  63. m_iszMannVsMachineWaveClassNames[ i ][ 0 ] = '\0';
  64. }
  65. for ( i = 0 ; i < ARRAYSIZE( m_iszMannVsMachineWaveClassNames2 ) ; ++i )
  66. {
  67. m_iszMannVsMachineWaveClassNames2[ i ][ 0 ] = '\0';
  68. }
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. //-----------------------------------------------------------------------------
  73. C_TFObjectiveResource::~C_TFObjectiveResource()
  74. {
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. //-----------------------------------------------------------------------------
  79. const char *C_TFObjectiveResource::GetGameSpecificCPCappingSwipe( int index_, int iCappingTeam )
  80. {
  81. Assert( index_ < m_iNumControlPoints );
  82. Assert( iCappingTeam != TEAM_UNASSIGNED );
  83. if ( iCappingTeam == TF_TEAM_RED )
  84. return "sprites/obj_icons/icon_obj_cap_red";
  85. return "sprites/obj_icons/icon_obj_cap_blu";
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose:
  89. //-----------------------------------------------------------------------------
  90. const char *C_TFObjectiveResource::GetGameSpecificCPBarFG( int index_, int iOwningTeam )
  91. {
  92. Assert( index_ < m_iNumControlPoints );
  93. if ( iOwningTeam == TF_TEAM_RED )
  94. return "progress_bar_red";
  95. if ( iOwningTeam == TF_TEAM_BLUE )
  96. return "progress_bar_blu";
  97. return "progress_bar";
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose:
  101. //-----------------------------------------------------------------------------
  102. const char *C_TFObjectiveResource::GetGameSpecificCPBarBG( int index_, int iCappingTeam )
  103. {
  104. Assert( index_ < m_iNumControlPoints );
  105. Assert( iCappingTeam != TEAM_UNASSIGNED );
  106. if ( iCappingTeam == TF_TEAM_RED )
  107. return "progress_bar_red";
  108. return "progress_bar_blu";
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose:
  112. //-----------------------------------------------------------------------------
  113. void C_TFObjectiveResource::SetCappingTeam( int index_, int team )
  114. {
  115. //Display warning that someone is capping our point.
  116. //Only do this at the start of a cap and if WE own the point.
  117. //Also don't warn on a point that will do a "Last Point cap" warning.
  118. if ( GetNumControlPoints() > 0 && GetCapWarningLevel( index_ ) == CP_WARN_NORMAL && GetCPCapPercentage( index_ ) == 0.0f && team != TEAM_UNASSIGNED )
  119. {
  120. C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
  121. if ( pLocalPlayer )
  122. {
  123. if ( pLocalPlayer->GetTeamNumber() != team )
  124. {
  125. CLocalPlayerFilter filter;
  126. if ( GetOwningTeam( index_ ) != TEAM_UNASSIGNED )
  127. {
  128. C_BaseEntity::EmitSound( filter, -1, "Announcer.ControlPointContested" );
  129. }
  130. else
  131. {
  132. C_BaseEntity::EmitSound( filter, -1, "Announcer.ControlPointContested_Neutral" );
  133. }
  134. }
  135. }
  136. }
  137. BaseClass::SetCappingTeam( index_, team );
  138. }
  139. //-----------------------------------------------------------------------------
  140. // Purpose:
  141. //-----------------------------------------------------------------------------
  142. int C_TFObjectiveResource::GetMannVsMachineWaveClassCount( int nIndex )
  143. {
  144. if ( nIndex < ARRAYSIZE( m_nMannVsMachineWaveClassCounts ) )
  145. {
  146. return m_nMannVsMachineWaveClassCounts[ nIndex ];
  147. }
  148. nIndex -= ARRAYSIZE( m_nMannVsMachineWaveClassCounts );
  149. if ( nIndex < ARRAYSIZE( m_nMannVsMachineWaveClassCounts2 ) )
  150. {
  151. return m_nMannVsMachineWaveClassCounts2[ nIndex ];
  152. }
  153. return 0;
  154. }
  155. //-----------------------------------------------------------------------------
  156. // Purpose:
  157. //-----------------------------------------------------------------------------
  158. const char *C_TFObjectiveResource::GetMannVsMachineWaveClassName( int nIndex )
  159. {
  160. if ( nIndex < ARRAYSIZE( m_iszMannVsMachineWaveClassNames ) )
  161. {
  162. return m_iszMannVsMachineWaveClassNames[ nIndex ];
  163. }
  164. nIndex -= ARRAYSIZE( m_iszMannVsMachineWaveClassNames );
  165. if ( nIndex < ARRAYSIZE( m_iszMannVsMachineWaveClassNames2 ) )
  166. {
  167. return m_iszMannVsMachineWaveClassNames2[ nIndex ];
  168. }
  169. return "";
  170. }
  171. //-----------------------------------------------------------------------------
  172. // Purpose:
  173. //-----------------------------------------------------------------------------
  174. unsigned int C_TFObjectiveResource::GetMannVsMachineWaveClassFlags( int nIndex )
  175. {
  176. if ( nIndex < ARRAYSIZE( m_nMannVsMachineWaveClassFlags ) )
  177. {
  178. return m_nMannVsMachineWaveClassFlags[ nIndex ];
  179. }
  180. nIndex -= ARRAYSIZE( m_nMannVsMachineWaveClassFlags );
  181. if ( nIndex < ARRAYSIZE( m_nMannVsMachineWaveClassFlags2 ) )
  182. {
  183. return m_nMannVsMachineWaveClassFlags2[ nIndex ];
  184. }
  185. return 0;
  186. }
  187. //-----------------------------------------------------------------------------
  188. // Purpose:
  189. //-----------------------------------------------------------------------------
  190. bool C_TFObjectiveResource::GetMannVsMachineWaveClassActive( int nIndex )
  191. {
  192. if ( nIndex < ARRAYSIZE( m_bMannVsMachineWaveClassActive ) )
  193. {
  194. return m_bMannVsMachineWaveClassActive[ nIndex ];
  195. }
  196. nIndex -= ARRAYSIZE( m_bMannVsMachineWaveClassActive );
  197. if ( nIndex < ARRAYSIZE( m_bMannVsMachineWaveClassActive2 ) )
  198. {
  199. return m_bMannVsMachineWaveClassActive2[ nIndex ];
  200. }
  201. return 0;
  202. }