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.

226 lines
7.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Entity that propagates general data needed by clients for every player.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "dod_objective_resource.h"
  9. #include "shareddefs.h"
  10. #include <coordsize.h>
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. // Datatable
  14. IMPLEMENT_SERVERCLASS_ST_NOBASE(CDODObjectiveResource, DT_DODObjectiveResource)
  15. SendPropInt( SENDINFO(m_iNumControlPoints), 4, SPROP_UNSIGNED ),
  16. // data variables
  17. SendPropArray( SendPropVector( SENDINFO_ARRAY(m_vCPPositions), -1, SPROP_COORD), m_vCPPositions ),
  18. SendPropArray3( SENDINFO_ARRAY3(m_bCPIsVisible), SendPropInt( SENDINFO_ARRAY(m_bCPIsVisible), 1, SPROP_UNSIGNED ) ),
  19. SendPropArray3( SENDINFO_ARRAY3(m_iAlliesIcons), SendPropInt( SENDINFO_ARRAY(m_iAlliesIcons), 8, SPROP_UNSIGNED ) ),
  20. SendPropArray3( SENDINFO_ARRAY3(m_iAxisIcons), SendPropInt( SENDINFO_ARRAY(m_iAxisIcons), 8, SPROP_UNSIGNED ) ),
  21. SendPropArray3( SENDINFO_ARRAY3(m_iNeutralIcons), SendPropInt( SENDINFO_ARRAY(m_iNeutralIcons), 8, SPROP_UNSIGNED ) ),
  22. SendPropArray3( SENDINFO_ARRAY3(m_iTimerCapIcons), SendPropInt( SENDINFO_ARRAY(m_iTimerCapIcons), 8, SPROP_UNSIGNED ) ),
  23. SendPropArray3( SENDINFO_ARRAY3(m_iBombedIcons), SendPropInt( SENDINFO_ARRAY(m_iBombedIcons), 8, SPROP_UNSIGNED ) ),
  24. SendPropArray3( SENDINFO_ARRAY3(m_iAlliesReqCappers), SendPropInt( SENDINFO_ARRAY(m_iAlliesReqCappers), 4, SPROP_UNSIGNED ) ),
  25. SendPropArray3( SENDINFO_ARRAY3(m_iAxisReqCappers), SendPropInt( SENDINFO_ARRAY(m_iAxisReqCappers), 4, SPROP_UNSIGNED ) ),
  26. SendPropArray3( SENDINFO_ARRAY3(m_flAlliesCapTime), SendPropTime( SENDINFO_ARRAY(m_flAlliesCapTime) ) ),
  27. SendPropArray3( SENDINFO_ARRAY3(m_flAxisCapTime), SendPropTime( SENDINFO_ARRAY(m_flAxisCapTime) ) ),
  28. SendPropArray3( SENDINFO_ARRAY3(m_bBombPlanted), SendPropInt( SENDINFO_ARRAY(m_bBombPlanted), 1, SPROP_UNSIGNED ) ),
  29. SendPropArray3( SENDINFO_ARRAY3(m_iBombsRequired), SendPropInt( SENDINFO_ARRAY(m_iBombsRequired), 2, SPROP_UNSIGNED ) ),
  30. SendPropArray3( SENDINFO_ARRAY3(m_iBombsRemaining), SendPropInt( SENDINFO_ARRAY(m_iBombsRemaining), 2, SPROP_UNSIGNED ) ),
  31. SendPropArray3( SENDINFO_ARRAY3(m_bBombBeingDefused), SendPropInt( SENDINFO_ARRAY(m_bBombBeingDefused), 1, SPROP_UNSIGNED ) ),
  32. // state variables
  33. SendPropArray3( SENDINFO_ARRAY3(m_iNumAllies), SendPropInt( SENDINFO_ARRAY(m_iNumAllies), 4, SPROP_UNSIGNED ) ),
  34. SendPropArray3( SENDINFO_ARRAY3(m_iNumAxis), SendPropInt( SENDINFO_ARRAY(m_iNumAxis), 4, SPROP_UNSIGNED ) ),
  35. SendPropArray3( SENDINFO_ARRAY3(m_iCappingTeam), SendPropInt( SENDINFO_ARRAY(m_iCappingTeam), 4, SPROP_UNSIGNED ) ),
  36. SendPropArray3( SENDINFO_ARRAY3(m_iOwner), SendPropInt( SENDINFO_ARRAY(m_iOwner), 4, SPROP_UNSIGNED ) ),
  37. END_SEND_TABLE()
  38. BEGIN_DATADESC( CDODObjectiveResource )
  39. END_DATADESC()
  40. LINK_ENTITY_TO_CLASS( dod_objective_resource, CDODObjectiveResource );
  41. CDODObjectiveResource *g_pObjectiveResource;
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. void CDODObjectiveResource::Spawn( void )
  46. {
  47. m_iNumControlPoints = 0;
  48. for ( int i=0; i < MAX_CONTROL_POINTS; i++ )
  49. {
  50. // data variables
  51. m_vCPPositions.Set( i, vec3_origin );
  52. m_bCPIsVisible.Set( i, true );
  53. m_iAlliesIcons.Set( i, 0 );
  54. m_iAxisIcons.Set( i, 0 );
  55. m_iNeutralIcons.Set( i, 0 );
  56. m_iTimerCapIcons.Set( i, 0 );
  57. m_iBombedIcons.Set( i, 0 );
  58. m_iAlliesReqCappers.Set( i, 0 );
  59. m_iAxisReqCappers.Set( i, 0 );
  60. m_flAlliesCapTime.Set( i, 0.0f );
  61. m_flAxisCapTime.Set( i, 0.0f );
  62. m_bBombPlanted.Set( i, 0 );
  63. m_iBombsRequired.Set( i, 0 );
  64. m_iBombsRemaining.Set( i, 0 );
  65. m_bBombBeingDefused.Set( i, 0 );
  66. // state variables
  67. m_iNumAllies.Set( i, 0 );
  68. m_iNumAxis.Set( i, 0 );
  69. m_iCappingTeam.Set( i, TEAM_UNASSIGNED );
  70. m_iOwner.Set( i, TEAM_UNASSIGNED );
  71. }
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose: The objective resource is always transmitted to clients
  75. //-----------------------------------------------------------------------------
  76. int CDODObjectiveResource::UpdateTransmitState()
  77. {
  78. // ALWAYS transmit to all clients.
  79. return SetTransmitState( FL_EDICT_ALWAYS );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Round is starting, reset state
  83. //-----------------------------------------------------------------------------
  84. void CDODObjectiveResource::ResetControlPoints( void )
  85. {
  86. for ( int i=0; i < MAX_CONTROL_POINTS; i++ )
  87. {
  88. m_iNumAllies.Set( i, 0 );
  89. m_iNumAxis.Set( i, 0 );
  90. m_iCappingTeam.Set( i, TEAM_UNASSIGNED );
  91. m_bBombPlanted.Set( i, 0 );
  92. m_bBombBeingDefused.Set( i, 0 );
  93. }
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Data setting functions
  97. //-----------------------------------------------------------------------------
  98. void CDODObjectiveResource::SetNumControlPoints( int num )
  99. {
  100. Assert( num <= MAX_CONTROL_POINTS );
  101. m_iNumControlPoints = num;
  102. }
  103. void CDODObjectiveResource::SetCPIcons( int index, int iAlliesIcon, int iAxisIcon, int iNeutralIcon, int iTimerCapIcon, int iBombedIcon )
  104. {
  105. AssertValidIndex(index);
  106. m_iAlliesIcons.Set( index, iAlliesIcon);
  107. m_iAxisIcons.Set( index, iAxisIcon );
  108. m_iNeutralIcons.Set( index, iNeutralIcon );
  109. m_iTimerCapIcons.Set( index, iTimerCapIcon );
  110. m_iBombedIcons.Set( index, iBombedIcon );
  111. }
  112. void CDODObjectiveResource::SetCPPosition( int index, const Vector& vPosition )
  113. {
  114. AssertValidIndex(index);
  115. m_vCPPositions.Set( index, vPosition );
  116. }
  117. void CDODObjectiveResource::SetCPVisible( int index, bool bVisible )
  118. {
  119. AssertValidIndex(index);
  120. m_bCPIsVisible.Set( index, bVisible );
  121. }
  122. void CDODObjectiveResource::SetCPRequiredCappers( int index, int iReqAllies, int iReqAxis )
  123. {
  124. AssertValidIndex(index);
  125. m_iAlliesReqCappers.Set( index, iReqAllies );
  126. m_iAxisReqCappers.Set( index, iReqAxis );
  127. }
  128. void CDODObjectiveResource::SetCPCapTime( int index, float flAlliesCapTime, float flAxisCapTime )
  129. {
  130. AssertValidIndex(index);
  131. m_flAlliesCapTime.Set( index, flAlliesCapTime );
  132. m_flAxisCapTime.Set( index, flAxisCapTime );
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Purpose: Data setting functions
  136. //-----------------------------------------------------------------------------
  137. void CDODObjectiveResource::SetNumPlayers( int index, int team, int iNumPlayers )
  138. {
  139. AssertValidIndex(index);
  140. switch( team )
  141. {
  142. case TEAM_ALLIES:
  143. m_iNumAllies.Set( index, iNumPlayers );
  144. break;
  145. case TEAM_AXIS:
  146. m_iNumAxis.Set( index, iNumPlayers );
  147. break;
  148. default:
  149. Assert( 0 );
  150. break;
  151. }
  152. }
  153. void CDODObjectiveResource::StartCap( int index, int team )
  154. {
  155. AssertValidIndex(index);
  156. m_iCappingTeam.Set( index, team );
  157. }
  158. void CDODObjectiveResource::SetOwningTeam( int index, int team )
  159. {
  160. AssertValidIndex(index);
  161. m_iOwner.Set( index, team );
  162. // clear the capper
  163. m_iCappingTeam.Set( index, TEAM_UNASSIGNED );
  164. }
  165. void CDODObjectiveResource::SetCappingTeam( int index, int team )
  166. {
  167. AssertValidIndex(index);
  168. m_iCappingTeam.Set( index, team );
  169. }
  170. void CDODObjectiveResource::SetBombPlanted( int index, bool bPlanted )
  171. {
  172. AssertValidIndex(index);
  173. m_bBombPlanted.Set( index, bPlanted );
  174. }
  175. void CDODObjectiveResource::SetBombBeingDefused( int index, bool bBeingDefused )
  176. {
  177. AssertValidIndex(index);
  178. m_bBombBeingDefused.Set( index, bBeingDefused );
  179. }
  180. void CDODObjectiveResource::SetBombsRequired( int index, int iBombsRequired )
  181. {
  182. AssertValidIndex(index);
  183. m_iBombsRequired.Set( index, iBombsRequired );
  184. }
  185. void CDODObjectiveResource::SetBombsRemaining( int index, int iBombsRemaining )
  186. {
  187. AssertValidIndex(index);
  188. m_iBombsRemaining.Set( index, iBombsRemaining );
  189. }