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.

116 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. // Author: Michael S. Booth ([email protected]), Leon Hartwig, 2003
  8. #include "cbase.h"
  9. #include "cs_shareddefs.h"
  10. #include "basegrenade_shared.h"
  11. #include "bot.h"
  12. #include "bot_util.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. /// @todo Remove this nasty hack - CreateFakeClient() calls CBot::Spawn, which needs the profile and team
  16. const BotProfile *g_botInitProfile = NULL;
  17. int g_botInitTeam = 0;
  18. //
  19. // NOTE: Because CBot had to be templatized, the code was moved into bot.h
  20. //
  21. //--------------------------------------------------------------------------------------------------------------
  22. //--------------------------------------------------------------------------------------------------------------
  23. ActiveGrenade::ActiveGrenade( CBaseGrenade *grenadeEntity )
  24. {
  25. m_entity = grenadeEntity;
  26. m_detonationPosition = grenadeEntity->GetAbsOrigin();
  27. m_dieTimestamp = 0.0f;
  28. m_isSmoke = false;
  29. m_isFlashbang = false;
  30. m_isMolotov = false;
  31. m_isDecoy = false;
  32. switch ( grenadeEntity->GetGrenadeType() )
  33. {
  34. case GRENADE_TYPE_EXPLOSIVE: m_radius = HEGrenadeRadius; break;
  35. case GRENADE_TYPE_FLASH: m_radius = FlashbangGrenadeRadius; m_isFlashbang = true; break;
  36. case GRENADE_TYPE_FIRE: m_radius = MolotovGrenadeRadius; m_isMolotov = true; break;
  37. case GRENADE_TYPE_DECOY: m_radius = DecoyGrenadeRadius; m_isDecoy = true; break;
  38. case GRENADE_TYPE_SMOKE: m_radius = SmokeGrenadeRadius; m_isSmoke = true; break;
  39. case GRENADE_TYPE_SENSOR: m_radius = MolotovGrenadeRadius; m_isSensor = true; break;
  40. default:
  41. AssertMsg( 0, "Invalid grenade type!\n" );
  42. m_radius = HEGrenadeRadius;
  43. }
  44. }
  45. //--------------------------------------------------------------------------------------------------------------
  46. /**
  47. * Called when the grenade in the world goes away
  48. */
  49. void ActiveGrenade::OnEntityGone( void )
  50. {
  51. if (m_isSmoke)
  52. {
  53. // smoke lingers after grenade is gone
  54. const float smokeLingerTime = 4.0f;
  55. m_dieTimestamp = gpGlobals->curtime + smokeLingerTime;
  56. }
  57. m_entity = NULL;
  58. }
  59. //--------------------------------------------------------------------------------------------------------------
  60. void ActiveGrenade::Update( void )
  61. {
  62. if (m_entity != NULL)
  63. {
  64. m_detonationPosition = m_entity->GetAbsOrigin();
  65. }
  66. }
  67. //--------------------------------------------------------------------------------------------------------------
  68. /**
  69. * Return true if this grenade is valid
  70. */
  71. bool ActiveGrenade::IsValid( void ) const
  72. {
  73. if ( m_isSmoke )
  74. {
  75. if ( m_entity == NULL && gpGlobals->curtime > m_dieTimestamp )
  76. {
  77. return false;
  78. }
  79. }
  80. else
  81. {
  82. if ( m_entity == NULL )
  83. {
  84. return false;
  85. }
  86. }
  87. return true;
  88. }
  89. //--------------------------------------------------------------------------------------------------------------
  90. const Vector &ActiveGrenade::GetPosition( void ) const
  91. {
  92. // smoke grenades can vanish before the smoke itself does - refer to the detonation position
  93. if (m_entity == NULL)
  94. return GetDetonationPosition();
  95. return m_entity->GetAbsOrigin();
  96. }