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.

126 lines
3.7 KiB

  1. //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "baseanimating.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. class CProp_Hallucination : public CBaseAnimating
  11. {
  12. public:
  13. DECLARE_CLASS( CProp_Hallucination, CBaseAnimating );
  14. DECLARE_SERVERCLASS();
  15. DECLARE_DATADESC();
  16. CProp_Hallucination( void );
  17. virtual void Precache( void );
  18. virtual void Spawn( void );
  19. virtual int DrawDebugTextOverlays( void );
  20. void InputEnable( inputdata_t &inputdata );
  21. void InputDisable( inputdata_t &inputdata );
  22. void InputSetVisibleTime( inputdata_t &inputdata );
  23. void InputSetRechargeTime( inputdata_t &inputdata );
  24. CNetworkVar( bool, m_bEnabled );
  25. float m_fStartEnabledChance; //0.0 - 100.0% chance that this hallucination will start enabled
  26. CNetworkVar( float, m_fVisibleTime ); //how long in seconds this hallucination can remain on screen from first sighting
  27. CNetworkVar( float, m_fRechargeTime ); //how long in seconds it takes the hallucination to recharge before becoming visible again. 0 to disable
  28. };
  29. BEGIN_DATADESC( CProp_Hallucination )
  30. DEFINE_FIELD( m_bEnabled, FIELD_BOOLEAN ),
  31. DEFINE_KEYFIELD( m_fStartEnabledChance, FIELD_FLOAT, "EnabledChance" ),
  32. DEFINE_KEYFIELD( m_fVisibleTime, FIELD_FLOAT, "VisibleTime" ),
  33. DEFINE_KEYFIELD( m_fRechargeTime, FIELD_FLOAT, "RechargeTime" ),
  34. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  35. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  36. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetVisibleTime", InputSetVisibleTime ),
  37. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetRechargeTime", InputSetRechargeTime ),
  38. END_DATADESC()
  39. IMPLEMENT_SERVERCLASS_ST( CProp_Hallucination, DT_Prop_Hallucination )
  40. SendPropBool( SENDINFO(m_bEnabled) ),
  41. SendPropFloat( SENDINFO(m_fVisibleTime) ),
  42. SendPropFloat( SENDINFO(m_fRechargeTime) ),
  43. END_SEND_TABLE()
  44. LINK_ENTITY_TO_CLASS( prop_hallucination, CProp_Hallucination );
  45. CProp_Hallucination::CProp_Hallucination( void )
  46. {
  47. }
  48. void CProp_Hallucination::Precache( void )
  49. {
  50. BaseClass::Precache();
  51. PrecacheModel( m_ModelName.ToCStr() );
  52. }
  53. void CProp_Hallucination::Spawn( void )
  54. {
  55. Precache();
  56. BaseClass::Spawn();
  57. SetModel( m_ModelName.ToCStr() );
  58. if( m_fStartEnabledChance > 0.0f )
  59. {
  60. m_bEnabled = RandomFloat() <= (m_fStartEnabledChance * 0.01f);
  61. }
  62. }
  63. void CProp_Hallucination::InputEnable( inputdata_t &inputdata )
  64. {
  65. m_bEnabled = true;
  66. }
  67. void CProp_Hallucination::InputDisable( inputdata_t &inputdata )
  68. {
  69. m_bEnabled = false;
  70. }
  71. void CProp_Hallucination::InputSetVisibleTime( inputdata_t &inputdata )
  72. {
  73. m_fVisibleTime = inputdata.value.Float();
  74. }
  75. void CProp_Hallucination::InputSetRechargeTime( inputdata_t &inputdata )
  76. {
  77. m_fRechargeTime = inputdata.value.Float();
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Draw debug overlays
  81. //-----------------------------------------------------------------------------
  82. int CProp_Hallucination::DrawDebugTextOverlays()
  83. {
  84. int text_offset = BaseClass::DrawDebugTextOverlays();
  85. if (m_debugOverlays & OVERLAY_TEXT_BIT)
  86. {
  87. char tempstr[255];
  88. Q_snprintf( tempstr, sizeof(tempstr), "%s", m_bEnabled ? "Enabled" : "Disabled" );
  89. EntityText( text_offset++, tempstr, 0 );
  90. Q_snprintf( tempstr, sizeof(tempstr), "Start Enabled Chance: %f%%", m_fStartEnabledChance );
  91. EntityText( text_offset++, tempstr, 0 );
  92. Q_snprintf( tempstr, sizeof(tempstr), "Visible Time: %fs", m_fVisibleTime.Get() );
  93. EntityText( text_offset++, tempstr, 0 );
  94. Q_snprintf( tempstr, sizeof(tempstr), "Recharge Time: %fs", m_fRechargeTime.Get() );
  95. EntityText( text_offset++, tempstr, 0 );
  96. }
  97. return text_offset;
  98. }