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.

86 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hl1_basecombatweapon_shared.h"
  8. #include "effect_dispatch_data.h"
  9. #include "te_effect_dispatch.h"
  10. BEGIN_DATADESC( CBaseHL1CombatWeapon )
  11. DEFINE_THINKFUNC( FallThink ),
  12. END_DATADESC();
  13. void CBaseHL1CombatWeapon::Precache()
  14. {
  15. BaseClass::Precache();
  16. PrecacheScriptSound( "BaseCombatWeapon.WeaponDrop" );
  17. }
  18. //-----------------------------------------------------------------------------
  19. // Purpose:
  20. //-----------------------------------------------------------------------------
  21. void CBaseHL1CombatWeapon::FallInit( void )
  22. {
  23. SetModel( GetWorldModel() );
  24. SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
  25. SetSolid( SOLID_BBOX );
  26. AddSolidFlags( FSOLID_TRIGGER );
  27. AddSolidFlags( FSOLID_NOT_SOLID );
  28. SetPickupTouch();
  29. SetThink( &CBaseHL1CombatWeapon::FallThink );
  30. SetNextThink( gpGlobals->curtime + 0.1f );
  31. // HACKHACK - On ground isn't always set, so look for ground underneath
  32. trace_t tr;
  33. UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector(0,0,2), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr );
  34. if ( tr.fraction < 1.0 )
  35. {
  36. SetGroundEntity( tr.m_pEnt );
  37. }
  38. SetViewOffset( Vector(0,0,8) );
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: Items that have just spawned run this think to catch them when
  42. // they hit the ground. Once we're sure that the object is grounded,
  43. // we change its solid type to trigger and set it in a large box that
  44. // helps the player get it.
  45. //-----------------------------------------------------------------------------
  46. void CBaseHL1CombatWeapon::FallThink ( void )
  47. {
  48. SetNextThink( gpGlobals->curtime + 0.1f );
  49. if ( GetFlags() & FL_ONGROUND )
  50. {
  51. // clatter if we have an owner (i.e., dropped by someone)
  52. // don't clatter if the gun is waiting to respawn (if it's waiting, it is invisible!)
  53. if ( GetOwnerEntity() )
  54. {
  55. EmitSound( "BaseCombatWeapon.WeaponDrop" );
  56. }
  57. // lie flat
  58. QAngle ang = GetAbsAngles();
  59. ang.x = 0;
  60. ang.z = 0;
  61. SetAbsAngles( ang );
  62. Materialize();
  63. SetSize( Vector( -24, -24, 0 ), Vector( 24, 24, 16 ) );
  64. }
  65. }