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.

222 lines
5.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //
  9. // Geiger.cpp
  10. //
  11. // implementation of CHudAmmo class
  12. //
  13. #include "cbase.h"
  14. #include "hudelement.h"
  15. #include "hud_macros.h"
  16. #include "engine/IEngineSound.h"
  17. #include "SoundEmitterSystem/isoundemittersystembase.h"
  18. #include "iclientmode.h"
  19. #include <vgui_controls/Controls.h>
  20. #include <vgui_controls/Panel.h>
  21. #include <vgui/ISurface.h>
  22. using namespace vgui;
  23. // memdbgon must be the last include file in a .cpp file!!!
  24. #include "tier0/memdbgon.h"
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. class CHudGeiger: public CHudElement, public vgui::Panel
  29. {
  30. DECLARE_CLASS_SIMPLE( CHudGeiger, vgui::Panel );
  31. public:
  32. explicit CHudGeiger( const char *pElementName );
  33. void Init( void );
  34. void VidInit( void );
  35. bool ShouldDraw( void );
  36. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  37. virtual void Paint( void );
  38. bool MsgFunc_Geiger(const CCSUsrMsg_Geiger &msg);
  39. CUserMessageBinder m_UMCMsgGeiger;
  40. private:
  41. int m_iGeigerRange;
  42. float m_flLastSoundTestTime;
  43. };
  44. DECLARE_HUDELEMENT( CHudGeiger );
  45. DECLARE_HUD_MESSAGE( CHudGeiger, Geiger );
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. CHudGeiger::CHudGeiger( const char *pElementName ) :
  50. CHudElement( pElementName ), BaseClass( NULL, "HudGeiger" )
  51. {
  52. vgui::Panel *pParent = GetClientMode()->GetViewport();
  53. SetParent( pParent );
  54. m_flLastSoundTestTime = -9999;
  55. SetHiddenBits( HIDEHUD_HEALTH );
  56. }
  57. void CHudGeiger::ApplySchemeSettings( IScheme *scheme )
  58. {
  59. BaseClass::ApplySchemeSettings( scheme );
  60. SetPaintBackgroundEnabled( false );
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose:
  64. //-----------------------------------------------------------------------------
  65. void CHudGeiger::Init(void)
  66. {
  67. HOOK_HUD_MESSAGE( CHudGeiger, Geiger );
  68. m_iGeigerRange = 0;
  69. };
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. //-----------------------------------------------------------------------------
  73. void CHudGeiger::VidInit(void)
  74. {
  75. m_iGeigerRange = 0;
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. bool CHudGeiger::MsgFunc_Geiger( const CCSUsrMsg_Geiger &msg )
  81. {
  82. // update geiger data
  83. m_iGeigerRange = msg.range();
  84. m_iGeigerRange = m_iGeigerRange << 2;
  85. return true;
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose:
  89. //-----------------------------------------------------------------------------
  90. bool CHudGeiger::ShouldDraw( void )
  91. {
  92. return ( ( m_iGeigerRange > 0 && m_iGeigerRange < 1000 ) && CHudElement::ShouldDraw() );
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose:
  96. //-----------------------------------------------------------------------------
  97. void CHudGeiger::Paint()
  98. {
  99. if ( !ShouldDraw() )
  100. return;
  101. int pct;
  102. float flvol=0;
  103. bool highsound = false;
  104. if ( gpGlobals->curtime - m_flLastSoundTestTime < 0.06 )
  105. {
  106. return;
  107. }
  108. m_flLastSoundTestTime = gpGlobals->curtime;
  109. // piecewise linear is better than continuous formula for this
  110. if (m_iGeigerRange > 800)
  111. {
  112. pct = 0; //Msg ( "range > 800\n");
  113. }
  114. else if (m_iGeigerRange > 600)
  115. {
  116. pct = 2;
  117. flvol = 0.2; //Msg ( "range > 600\n");
  118. }
  119. else if (m_iGeigerRange > 500)
  120. {
  121. pct = 4;
  122. flvol = 0.25; //Msg ( "range > 500\n");
  123. }
  124. else if (m_iGeigerRange > 400)
  125. {
  126. pct = 8;
  127. flvol = 0.3; //Msg ( "range > 400\n");
  128. highsound = true;
  129. }
  130. else if (m_iGeigerRange > 300)
  131. {
  132. pct = 8;
  133. flvol = 0.35; //Msg ( "range > 300\n");
  134. highsound = true;
  135. }
  136. else if (m_iGeigerRange > 200)
  137. {
  138. pct = 28;
  139. flvol = 0.39; //Msg ( "range > 200\n");
  140. highsound = true;
  141. }
  142. else if (m_iGeigerRange > 150)
  143. {
  144. pct = 40;
  145. flvol = 0.40; //Msg ( "range > 150\n");
  146. highsound = true;
  147. }
  148. else if (m_iGeigerRange > 100)
  149. {
  150. pct = 60;
  151. flvol = 0.425; //Msg ( "range > 100\n");
  152. highsound = true;
  153. }
  154. else if (m_iGeigerRange > 75)
  155. {
  156. pct = 80;
  157. flvol = 0.45; //Msg ( "range > 75\n");
  158. //gflGeigerDelay = cl.time + GEIGERDELAY * 0.75;
  159. highsound = true;
  160. }
  161. else if (m_iGeigerRange > 50)
  162. {
  163. pct = 90;
  164. flvol = 0.475; //Msg ( "range > 50\n");
  165. }
  166. else
  167. {
  168. pct = 95;
  169. flvol = 0.5; //Msg ( "range < 50\n");
  170. }
  171. flvol = (flvol * (random->RandomInt(0,127)) / 255) + 0.25;
  172. if ( random->RandomInt(0,127) < pct )
  173. {
  174. char sz[256];
  175. if ( highsound )
  176. {
  177. Q_strncpy( sz, "Geiger.BeepHigh", sizeof( sz ) );
  178. }
  179. else
  180. {
  181. Q_strncpy( sz, "Geiger.BeepLow", sizeof( sz ) );
  182. }
  183. CSoundParameters params;
  184. if ( C_BaseEntity::GetParametersForSound( sz, params, NULL ) )
  185. {
  186. CLocalPlayerFilter filter;
  187. EmitSound_t ep;
  188. ep.m_nChannel = params.channel;
  189. ep.m_pSoundName = params.soundname;
  190. ep.m_flVolume = flvol;
  191. ep.m_SoundLevel = params.soundlevel;
  192. ep.m_nPitch = params.pitch;
  193. C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, ep );
  194. }
  195. }
  196. }