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.

107 lines
2.3 KiB

  1. //========= Copyright 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. class CItemDefuser : public CItem
  10. {
  11. public:
  12. DECLARE_CLASS( CItemDefuser, CItem );
  13. void Spawn( void );
  14. void Precache( void );
  15. void DefuserTouch( CBaseEntity *pOther );
  16. void ActivateThink( void );
  17. DECLARE_DATADESC();
  18. };
  19. LINK_ENTITY_TO_CLASS( item_defuser, CItemDefuser );
  20. PRECACHE_REGISTER(item_defuser);
  21. BEGIN_DATADESC( CItemDefuser )
  22. //Functions
  23. DEFINE_THINKFUNC( ActivateThink ),
  24. DEFINE_ENTITYFUNC( DefuserTouch ),
  25. END_DATADESC()
  26. void CItemDefuser::Spawn( void )
  27. {
  28. Precache( );
  29. SetModel( "models/weapons/w_defuser.mdl" );
  30. BaseClass::Spawn();
  31. SetNextThink( gpGlobals->curtime + 0.5f );
  32. SetThink( &CItemDefuser::ActivateThink );
  33. SetTouch( NULL );
  34. }
  35. void CItemDefuser::Precache( void )
  36. {
  37. PrecacheModel( "models/weapons/w_defuser.mdl" );
  38. PrecacheScriptSound( "BaseCombatCharacter.ItemPickup2" );
  39. }
  40. void CItemDefuser::ActivateThink( void )
  41. {
  42. //since we can't stop the item from being touched while its in the air,
  43. //activate 1 second after being dropped
  44. SetTouch( &CItemDefuser::DefuserTouch );
  45. SetThink( NULL );
  46. }
  47. void CItemDefuser::DefuserTouch( CBaseEntity *pOther )
  48. {
  49. if ( !pOther->IsPlayer() )
  50. {
  51. return;
  52. }
  53. //if( GetFlags() & FL_ONGROUND )
  54. {
  55. CCSPlayer *pPlayer = (CCSPlayer *)pOther;
  56. if ( !pPlayer )
  57. {
  58. Assert( false );
  59. return;
  60. }
  61. if( pPlayer->GetTeamNumber() == TEAM_CT && !pPlayer->HasDefuser() )
  62. {
  63. //=============================================================================
  64. // HPE_BEGIN:
  65. // [dwenger] Added for fun-fact support
  66. //=============================================================================
  67. pPlayer->GiveDefuser( true );
  68. //=============================================================================
  69. // HPE_END
  70. //=============================================================================
  71. if ( pPlayer->IsDead() == false )
  72. {
  73. CPASAttenuationFilter filter( pPlayer );
  74. EmitSound( filter, entindex(), "BaseCombatCharacter.ItemPickup2" );
  75. }
  76. UTIL_Remove( this );
  77. return;
  78. }
  79. }
  80. }