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.

157 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defuser kit that drops from counter-strike CTS
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "items.h"
  8. #include "cs_player.h"
  9. #include "cs_gamerules.h"
  10. #include "cs_entity_spotting.h"
  11. class CItemDefuser : public CItem
  12. {
  13. public:
  14. DECLARE_CLASS( CItemDefuser, CItem );
  15. CItemDefuser();
  16. ~CItemDefuser();
  17. void Spawn( void );
  18. void Precache( void );
  19. void DefuserTouch( CBaseEntity *pOther );
  20. void ActivateThink( void );
  21. DECLARE_DATADESC();
  22. };
  23. LINK_ENTITY_TO_CLASS( item_defuser, CItemDefuser );
  24. LINK_ENTITY_TO_CLASS( item_cutters, CItemDefuser );
  25. PRECACHE_REGISTER(item_defuser);
  26. BEGIN_DATADESC( CItemDefuser )
  27. //Functions
  28. DEFINE_THINKFUNC( ActivateThink ),
  29. DEFINE_ENTITYFUNC( DefuserTouch ),
  30. END_DATADESC()
  31. Vector g_vecDefuserPosition = vec3_origin;
  32. CBaseEntity* g_pDefuserEntity = NULL;
  33. CItemDefuser::CItemDefuser()
  34. {
  35. g_pDefuserEntity = this;
  36. SetSpotRules( CCSEntitySpotting::SPOT_RULE_T | CCSEntitySpotting::SPOT_RULE_ALWAYS_SEEN_BY_CT );
  37. }
  38. CItemDefuser::~CItemDefuser()
  39. {
  40. if ( g_pDefuserEntity == this )
  41. {
  42. g_pDefuserEntity = NULL;
  43. g_vecDefuserPosition = vec3_origin;
  44. }
  45. }
  46. void CItemDefuser::Spawn( void )
  47. {
  48. Precache( );
  49. SetModel( "models/weapons/w_defuser.mdl" );
  50. BaseClass::Spawn();
  51. #if !defined( CLIENT_DLL )
  52. if ( mp_defuser_allocation.GetInt() == DefuserAllocation::Random )
  53. {
  54. IGameEvent * event = gameeventmanager->CreateEvent( "defuser_dropped" );
  55. if ( event )
  56. {
  57. event->SetInt( "entityid", entindex() );
  58. event->SetInt( "priority", 0 ); //defuser_dropped
  59. gameeventmanager->FireEvent( event );
  60. }
  61. }
  62. g_vecDefuserPosition = GetAbsOrigin();
  63. #endif
  64. SetNextThink( gpGlobals->curtime + 0.5f );
  65. SetThink( &CItemDefuser::ActivateThink );
  66. SetTouch( NULL );
  67. }
  68. void CItemDefuser::Precache( void )
  69. {
  70. PrecacheModel( "models/weapons/w_defuser.mdl" );
  71. PrecacheScriptSound( "BaseCombatCharacter.ItemPickup2" );
  72. }
  73. void CItemDefuser::ActivateThink( void )
  74. {
  75. //since we can't stop the item from being touched while its in the air,
  76. //activate 1 second after being dropped
  77. SetTouch( &CItemDefuser::DefuserTouch );
  78. SetThink( NULL );
  79. }
  80. void CItemDefuser::DefuserTouch( CBaseEntity *pOther )
  81. {
  82. if ( !pOther->IsPlayer() )
  83. {
  84. return;
  85. }
  86. //if( GetFlags() & FL_ONGROUND )
  87. {
  88. CCSPlayer *pPlayer = (CCSPlayer *)pOther;
  89. if ( !pPlayer )
  90. {
  91. Assert( false );
  92. return;
  93. }
  94. if( pPlayer->GetTeamNumber() == TEAM_CT && !pPlayer->HasDefuser() )
  95. {
  96. // [dwenger] Added for fun-fact support
  97. pPlayer->GiveDefuser( true );
  98. #if !defined( CLIENT_DLL )
  99. if ( mp_defuser_allocation.GetInt() == DefuserAllocation::Random )
  100. {
  101. IGameEvent * event = gameeventmanager->CreateEvent( "defuser_pickup" );
  102. if ( event )
  103. {
  104. event->SetInt( "entityid", entindex() );
  105. event->SetInt( "userid", pPlayer->GetUserID() );
  106. event->SetInt( "priority", 0 ); //defuser_pickup
  107. gameeventmanager->FireEvent( event );
  108. }
  109. }
  110. #endif
  111. // if ( pPlayer->IsDead() == false )
  112. // {
  113. // CBroadcastRecipientFilter filter;
  114. // EmitSound( filter, entindex(), "BaseCombatCharacter.ItemPickup2" );
  115. // }
  116. UTIL_Remove( this );
  117. return;
  118. }
  119. }
  120. }