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.

174 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "baseentity.h"
  9. #include "sendproxy.h"
  10. #include "ragdoll_shared.h"
  11. #include "ai_basenpc.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. class CRagdollManager : public CBaseEntity
  15. {
  16. public:
  17. DECLARE_CLASS( CRagdollManager, CBaseEntity );
  18. DECLARE_SERVERCLASS();
  19. DECLARE_DATADESC();
  20. CRagdollManager();
  21. virtual void Activate();
  22. virtual int UpdateTransmitState();
  23. void InputSetMaxRagdollCount(inputdata_t &data);
  24. void InputSetMaxRagdollCountDX8(inputdata_t &data);
  25. int DrawDebugTextOverlays(void);
  26. public:
  27. void UpdateCurrentMaxRagDollCount();
  28. CNetworkVar( int, m_iCurrentMaxRagdollCount );
  29. int m_iDXLevel;
  30. int m_iMaxRagdollCount;
  31. int m_iMaxRagdollCountDX8;
  32. bool m_bSaveImportant;
  33. };
  34. IMPLEMENT_SERVERCLASS_ST_NOBASE( CRagdollManager, DT_RagdollManager )
  35. SendPropInt( SENDINFO( m_iCurrentMaxRagdollCount ), 6 ),
  36. END_SEND_TABLE()
  37. LINK_ENTITY_TO_CLASS( game_ragdoll_manager, CRagdollManager );
  38. BEGIN_DATADESC( CRagdollManager )
  39. //DEFINE_FIELD( m_iDXLevel, FIELD_INTEGER ),
  40. DEFINE_FIELD( m_iCurrentMaxRagdollCount, FIELD_INTEGER ),
  41. DEFINE_KEYFIELD( m_iMaxRagdollCount, FIELD_INTEGER, "MaxRagdollCount" ),
  42. DEFINE_KEYFIELD( m_iMaxRagdollCountDX8, FIELD_INTEGER, "MaxRagdollCountDX8" ),
  43. DEFINE_KEYFIELD( m_bSaveImportant, FIELD_BOOLEAN, "SaveImportant" ),
  44. DEFINE_INPUTFUNC( FIELD_INTEGER, "SetMaxRagdollCount", InputSetMaxRagdollCount ),
  45. DEFINE_INPUTFUNC( FIELD_INTEGER, "SetMaxRagdollCountDX8", InputSetMaxRagdollCountDX8 ),
  46. END_DATADESC()
  47. //-----------------------------------------------------------------------------
  48. // Constructor
  49. //-----------------------------------------------------------------------------
  50. CRagdollManager::CRagdollManager( void )
  51. {
  52. m_iMaxRagdollCount = -1;
  53. m_iMaxRagdollCountDX8 = -1;
  54. m_iCurrentMaxRagdollCount = -1;
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose:
  58. // Input : *pInfo -
  59. // Output : int
  60. //-----------------------------------------------------------------------------
  61. int CRagdollManager::UpdateTransmitState()
  62. {
  63. return SetTransmitState( FL_EDICT_ALWAYS );
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose:
  67. //-----------------------------------------------------------------------------
  68. void CRagdollManager::Activate()
  69. {
  70. BaseClass::Activate();
  71. // Cache off the DX level for use later.
  72. ConVarRef mat_dxlevel( "mat_dxlevel" );
  73. m_iDXLevel = mat_dxlevel.GetInt();
  74. UpdateCurrentMaxRagDollCount();
  75. }
  76. //-----------------------------------------------------------------------------
  77. //-----------------------------------------------------------------------------
  78. void CRagdollManager::UpdateCurrentMaxRagDollCount()
  79. {
  80. if ( ( m_iDXLevel < 90 ) && ( m_iMaxRagdollCountDX8 >= 0 ) )
  81. {
  82. m_iCurrentMaxRagdollCount = m_iMaxRagdollCountDX8;
  83. }
  84. else
  85. {
  86. m_iCurrentMaxRagdollCount = m_iMaxRagdollCount;
  87. }
  88. s_RagdollLRU.SetMaxRagdollCount( m_iCurrentMaxRagdollCount );
  89. }
  90. //-----------------------------------------------------------------------------
  91. //-----------------------------------------------------------------------------
  92. void CRagdollManager::InputSetMaxRagdollCount(inputdata_t &inputdata)
  93. {
  94. m_iMaxRagdollCount = inputdata.value.Int();
  95. UpdateCurrentMaxRagDollCount();
  96. }
  97. //-----------------------------------------------------------------------------
  98. //-----------------------------------------------------------------------------
  99. void CRagdollManager::InputSetMaxRagdollCountDX8(inputdata_t &inputdata)
  100. {
  101. m_iMaxRagdollCountDX8 = inputdata.value.Int();
  102. UpdateCurrentMaxRagDollCount();
  103. }
  104. bool RagdollManager_SaveImportant( CAI_BaseNPC *pNPC )
  105. {
  106. #ifdef HL2_DLL
  107. CRagdollManager *pEnt = (CRagdollManager *)gEntList.FindEntityByClassname( NULL, "game_ragdoll_manager" );
  108. if ( pEnt == NULL )
  109. return false;
  110. if ( pEnt->m_bSaveImportant )
  111. {
  112. if ( pNPC->Classify() == CLASS_PLAYER_ALLY || pNPC->Classify() == CLASS_PLAYER_ALLY_VITAL )
  113. {
  114. return true;
  115. }
  116. }
  117. #endif
  118. return false;
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose: Draw any debug text overlays
  122. // Output : Current text offset from the top
  123. //-----------------------------------------------------------------------------
  124. int CRagdollManager::DrawDebugTextOverlays( void )
  125. {
  126. int text_offset = BaseClass::DrawDebugTextOverlays();
  127. if (m_debugOverlays & OVERLAY_TEXT_BIT)
  128. {
  129. char tempstr[512];
  130. // print max ragdoll count
  131. Q_snprintf(tempstr,sizeof(tempstr),"max ragdoll count: %d", m_iCurrentMaxRagdollCount.Get());
  132. EntityText(text_offset,tempstr,0);
  133. text_offset++;
  134. }
  135. return text_offset;
  136. }