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.

109 lines
2.7 KiB

  1. //========= Copyright 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 "basegrenade_shared.h"
  10. #include "bot.h"
  11. #include "bot_util.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. /// @todo Remove this nasty hack - CreateFakeClient() calls CBot::Spawn, which needs the profile and team
  15. const BotProfile *g_botInitProfile = NULL;
  16. int g_botInitTeam = 0;
  17. //
  18. // NOTE: Because CBot had to be templatized, the code was moved into bot.h
  19. //
  20. //--------------------------------------------------------------------------------------------------------------
  21. //--------------------------------------------------------------------------------------------------------------
  22. ActiveGrenade::ActiveGrenade( CBaseGrenade *grenadeEntity )
  23. {
  24. m_entity = grenadeEntity;
  25. m_detonationPosition = grenadeEntity->GetAbsOrigin();
  26. m_dieTimestamp = 0.0f;
  27. m_radius = HEGrenadeRadius;
  28. m_isSmoke = FStrEq( grenadeEntity->GetClassname(), "smokegrenade_projectile" );
  29. if ( m_isSmoke )
  30. {
  31. m_radius = SmokeGrenadeRadius;
  32. }
  33. m_isFlashbang = FStrEq( grenadeEntity->GetClassname(), "flashbang_projectile" );
  34. if ( m_isFlashbang )
  35. {
  36. m_radius = FlashbangGrenadeRadius;
  37. }
  38. }
  39. //--------------------------------------------------------------------------------------------------------------
  40. /**
  41. * Called when the grenade in the world goes away
  42. */
  43. void ActiveGrenade::OnEntityGone( void )
  44. {
  45. if (m_isSmoke)
  46. {
  47. // smoke lingers after grenade is gone
  48. const float smokeLingerTime = 4.0f;
  49. m_dieTimestamp = gpGlobals->curtime + smokeLingerTime;
  50. }
  51. m_entity = NULL;
  52. }
  53. //--------------------------------------------------------------------------------------------------------------
  54. void ActiveGrenade::Update( void )
  55. {
  56. if (m_entity != NULL)
  57. {
  58. m_detonationPosition = m_entity->GetAbsOrigin();
  59. }
  60. }
  61. //--------------------------------------------------------------------------------------------------------------
  62. /**
  63. * Return true if this grenade is valid
  64. */
  65. bool ActiveGrenade::IsValid( void ) const
  66. {
  67. if ( m_isSmoke )
  68. {
  69. if ( m_entity == NULL && gpGlobals->curtime > m_dieTimestamp )
  70. {
  71. return false;
  72. }
  73. }
  74. else
  75. {
  76. if ( m_entity == NULL )
  77. {
  78. return false;
  79. }
  80. }
  81. return true;
  82. }
  83. //--------------------------------------------------------------------------------------------------------------
  84. const Vector &ActiveGrenade::GetPosition( void ) const
  85. {
  86. // smoke grenades can vanish before the smoke itself does - refer to the detonation position
  87. if (m_entity == NULL)
  88. return GetDetonationPosition();
  89. return m_entity->GetAbsOrigin();
  90. }