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.

294 lines
6.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: 'weapon' what lets the player controll the rollerbuddy.
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "basehlcombatweapon.h"
  10. #include "NPCevent.h"
  11. #include "basecombatcharacter.h"
  12. #include "ai_basenpc.h"
  13. #include "player.h"
  14. #include "entitylist.h"
  15. #include "ndebugoverlay.h"
  16. #include "soundent.h"
  17. #include "engine/IEngineSound.h"
  18. #include "rotorwash.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include "tier0/memdbgon.h"
  21. ConVar thumpFrequency( "thumpfrequency", "2" );
  22. ConVar thumpRadius( "thumpradius", "512" );
  23. //=========================================================
  24. //=========================================================
  25. class CPortableThumper : public CBaseAnimating
  26. {
  27. DECLARE_CLASS( CPortableThumper, CBaseAnimating );
  28. private:
  29. void ThumpThink( void );
  30. void ThumperUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  31. void Precache( void );
  32. void Spawn( void );
  33. int ObjectCaps( void ) { return FCAP_IMPULSE_USE; }
  34. DECLARE_DATADESC();
  35. };
  36. LINK_ENTITY_TO_CLASS( portable_thumper, CPortableThumper );
  37. void CPortableThumper::Precache( void )
  38. {
  39. PrecacheModel( "models/fire_equipment/w_firehydrant.mdl" );
  40. }
  41. void CPortableThumper::Spawn( void )
  42. {
  43. m_takedamage = DAMAGE_NO;
  44. SetModel( "models/fire_equipment/w_firehydrant.mdl" );
  45. Vector vecBBMin, vecBBMax;
  46. vecBBMin.z = 0;
  47. vecBBMin.x = -16;
  48. vecBBMin.y = -16;
  49. vecBBMax.z = 32;
  50. vecBBMax.x = 16;
  51. vecBBMax.y = 16;
  52. SetSolid( SOLID_BBOX );
  53. UTIL_SetSize( this, vecBBMin, vecBBMax );
  54. SetThink( ThumpThink );
  55. SetUse( ThumperUse );
  56. SetNextThink( gpGlobals->curtime + thumpFrequency.GetFloat() );
  57. }
  58. void CPortableThumper::ThumperUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
  59. {
  60. if( !pActivator->IsPlayer() )
  61. {
  62. return;
  63. }
  64. CBasePlayer *pPlayer;
  65. pPlayer = (CBasePlayer *)pActivator;
  66. pPlayer->GiveNamedItem( "weapon_thumper" );
  67. UTIL_Remove( this );
  68. }
  69. void CPortableThumper::ThumpThink( void )
  70. {
  71. EmitSound( "PortableThumper.ThumpSound" );
  72. UTIL_RotorWash( GetAbsOrigin() + Vector( 0, 0, 32 ), Vector( 0, 0, -1 ), 512 );
  73. SetNextThink( gpGlobals->curtime + thumpFrequency.GetFloat() );
  74. CSoundEnt::InsertSound( SOUND_THUMPER, GetAbsOrigin(), thumpRadius.GetInt(), 0.2, this );
  75. }
  76. BEGIN_DATADESC( CPortableThumper )
  77. DEFINE_FUNCTION( ThumpThink ),
  78. DEFINE_FUNCTION( ThumperUse ),
  79. END_DATADESC()
  80. class CWeaponThumper: public CBaseHLCombatWeapon
  81. {
  82. DECLARE_CLASS( CWeaponThumper, CBaseHLCombatWeapon );
  83. public:
  84. DECLARE_SERVERCLASS();
  85. void Spawn( void );
  86. void Precache( void );
  87. int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
  88. void PrimaryAttack( void );
  89. bool Reload( void );
  90. void DecrementAmmo( CBaseCombatCharacter *pOwner );
  91. };
  92. IMPLEMENT_SERVERCLASS_ST(CWeaponThumper, DT_WeaponThumper)
  93. END_SEND_TABLE()
  94. LINK_ENTITY_TO_CLASS( weapon_thumper, CWeaponThumper );
  95. PRECACHE_WEAPON_REGISTER(weapon_thumper);
  96. void CWeaponThumper::Spawn( )
  97. {
  98. BaseClass::Spawn();
  99. Precache( );
  100. UTIL_SetSize(this, Vector(-4,-4,-2),Vector(4,4,2));
  101. FallInit();// get ready to fall down
  102. }
  103. void CWeaponThumper::Precache( void )
  104. {
  105. BaseClass::Precache();
  106. UTIL_PrecacheOther( "portable_thumper" );
  107. PrecacheScriptSound( "PortableThumper.ThumpSound" );
  108. }
  109. bool CWeaponThumper::Reload( void )
  110. {
  111. WeaponIdle();
  112. return true;
  113. }
  114. void CWeaponThumper::PrimaryAttack( void )
  115. {
  116. CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
  117. if ( !pPlayer )
  118. return;
  119. DecrementAmmo( pPlayer );
  120. trace_t tr;
  121. Vector vecStart, vecDir;
  122. Vector vecForward;
  123. Vector vecSpot;
  124. pPlayer->GetVectors( &vecForward, NULL, NULL );
  125. vecForward.z = 0.0;
  126. vecStart = pPlayer->WorldSpaceCenter() + vecForward * 64;
  127. UTIL_TraceLine( vecStart, vecStart - Vector( 0, 0, 128 ), MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr );
  128. if( tr.fraction != 1.0 )
  129. {
  130. Create( "portable_thumper", tr.endpos, vec3_angle, NULL );
  131. m_flNextPrimaryAttack = gpGlobals->curtime + 0.5;
  132. }
  133. m_flNextPrimaryAttack = gpGlobals->curtime + 0.5;
  134. }
  135. void CWeaponThumper::DecrementAmmo( CBaseCombatCharacter *pOwner )
  136. {
  137. pOwner->RemoveAmmo( 1, m_iPrimaryAmmoType );
  138. if (pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0)
  139. {
  140. pOwner->Weapon_Drop( this );
  141. UTIL_Remove(this);
  142. }
  143. }
  144. /*
  145. //=========================================================
  146. //=========================================================
  147. class CWeaponThumper : public CBaseHLCombatWeapon
  148. {
  149. public:
  150. DECLARE_CLASS( CWeaponThumper, CBaseHLCombatWeapon );
  151. CWeaponThumper();
  152. DECLARE_SERVERCLASS();
  153. void Precache( void );
  154. bool Deploy( void );
  155. int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
  156. void PrimaryAttack( void );
  157. void SecondaryAttack( void );
  158. DECLARE_ACTTABLE();
  159. };
  160. IMPLEMENT_SERVERCLASS_ST(CWeaponThumper, DT_WeaponThumper)
  161. END_SEND_TABLE()
  162. LINK_ENTITY_TO_CLASS( weapon_thumper, CWeaponThumper );
  163. PRECACHE_WEAPON_REGISTER(weapon_thumper);
  164. acttable_t CWeaponThumper::m_acttable[] =
  165. {
  166. { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_AR1, true },
  167. };
  168. IMPLEMENT_ACTTABLE(CWeaponThumper);
  169. CWeaponThumper::CWeaponThumper( )
  170. {
  171. }
  172. void CWeaponThumper::Precache( void )
  173. {
  174. UTIL_PrecacheOther( "portable_thumper" );
  175. BaseClass::Precache();
  176. }
  177. bool CWeaponThumper::Deploy( void )
  178. {
  179. bool fReturn;
  180. fReturn = BaseClass::Deploy();
  181. m_flNextPrimaryAttack = gpGlobals->curtime;
  182. m_flNextSecondaryAttack = gpGlobals->curtime;
  183. m_hOwner->m_flNextAttack = gpGlobals->curtime + 0.0;
  184. return fReturn;
  185. }
  186. void CWeaponThumper::PrimaryAttack( void )
  187. {
  188. trace_t tr;
  189. Vector vecStart, vecDir;
  190. Vector vecForward;
  191. Vector vecSpot;
  192. m_hOwner->GetVectors( &vecForward, NULL, NULL );
  193. vecForward.z = 0.0;
  194. vecStart = m_hOwner->Center() + vecForward * 64;
  195. UTIL_TraceLine( vecStart, vecStart - Vector( 0, 0, 128 ), MASK_SHOT, m_hOwner, COLLISION_GROUP_NONE, &tr );
  196. if( tr.fraction != 1.0 )
  197. {
  198. Create( "portable_thumper", tr.endpos, vec3_origin, NULL );
  199. m_flNextPrimaryAttack = gpGlobals->curtime + 0.5;
  200. }
  201. m_hOwner->m_iAmmo[m_iPrimaryAmmoType]++;
  202. }
  203. void CWeaponThumper::SecondaryAttack( void )
  204. {
  205. m_flNextSecondaryAttack = gpGlobals->curtime + 0.5;
  206. }
  207. */