Counter Strike : Global Offensive Source Code
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.

147 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, 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. int DrawDebugTextOverlays(void);
  25. public:
  26. void UpdateCurrentMaxRagDollCount();
  27. CNetworkVar( int, m_iCurrentMaxRagdollCount );
  28. int m_iMaxRagdollCount;
  29. bool m_bSaveImportant;
  30. };
  31. IMPLEMENT_SERVERCLASS_ST_NOBASE( CRagdollManager, DT_RagdollManager )
  32. SendPropInt( SENDINFO( m_iCurrentMaxRagdollCount ), 6 ),
  33. END_SEND_TABLE()
  34. LINK_ENTITY_TO_CLASS( game_ragdoll_manager, CRagdollManager );
  35. BEGIN_DATADESC( CRagdollManager )
  36. DEFINE_FIELD( m_iCurrentMaxRagdollCount, FIELD_INTEGER ),
  37. DEFINE_KEYFIELD( m_iMaxRagdollCount, FIELD_INTEGER, "MaxRagdollCount" ),
  38. DEFINE_KEYFIELD( m_bSaveImportant, FIELD_BOOLEAN, "SaveImportant" ),
  39. DEFINE_INPUTFUNC( FIELD_INTEGER, "SetMaxRagdollCount", InputSetMaxRagdollCount ),
  40. END_DATADESC()
  41. //-----------------------------------------------------------------------------
  42. // Constructor
  43. //-----------------------------------------------------------------------------
  44. CRagdollManager::CRagdollManager( void )
  45. {
  46. m_iMaxRagdollCount = -1;
  47. m_iCurrentMaxRagdollCount = -1;
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. // Input : *pInfo -
  52. // Output : int
  53. //-----------------------------------------------------------------------------
  54. int CRagdollManager::UpdateTransmitState()
  55. {
  56. return SetTransmitState( FL_EDICT_ALWAYS );
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. //-----------------------------------------------------------------------------
  61. void CRagdollManager::Activate()
  62. {
  63. BaseClass::Activate();
  64. UpdateCurrentMaxRagDollCount();
  65. }
  66. //-----------------------------------------------------------------------------
  67. //-----------------------------------------------------------------------------
  68. void CRagdollManager::UpdateCurrentMaxRagDollCount()
  69. {
  70. m_iCurrentMaxRagdollCount = m_iMaxRagdollCount;
  71. s_RagdollLRU.SetMaxRagdollCount( m_iCurrentMaxRagdollCount );
  72. }
  73. //-----------------------------------------------------------------------------
  74. //-----------------------------------------------------------------------------
  75. void CRagdollManager::InputSetMaxRagdollCount(inputdata_t &inputdata)
  76. {
  77. m_iMaxRagdollCount = inputdata.value.Int();
  78. UpdateCurrentMaxRagDollCount();
  79. }
  80. //-----------------------------------------------------------------------------
  81. //-----------------------------------------------------------------------------
  82. bool RagdollManager_SaveImportant( CAI_BaseNPC *pNPC )
  83. {
  84. #ifdef HL2_DLL
  85. CRagdollManager *pEnt = (CRagdollManager *)gEntList.FindEntityByClassname( NULL, "game_ragdoll_manager" );
  86. if ( pEnt == NULL )
  87. return false;
  88. if ( pEnt->m_bSaveImportant )
  89. {
  90. if ( pNPC->Classify() == CLASS_PLAYER_ALLY || pNPC->Classify() == CLASS_PLAYER_ALLY_VITAL )
  91. {
  92. return true;
  93. }
  94. }
  95. #endif
  96. return false;
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose: Draw any debug text overlays
  100. // Output : Current text offset from the top
  101. //-----------------------------------------------------------------------------
  102. int CRagdollManager::DrawDebugTextOverlays( void )
  103. {
  104. int text_offset = BaseClass::DrawDebugTextOverlays();
  105. if (m_debugOverlays & OVERLAY_TEXT_BIT)
  106. {
  107. char tempstr[512];
  108. // print max ragdoll count
  109. Q_snprintf(tempstr,sizeof(tempstr),"max ragdoll count: %d", m_iCurrentMaxRagdollCount.Get());
  110. EntityText(text_offset,tempstr,0);
  111. text_offset++;
  112. }
  113. return text_offset;
  114. }