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.

145 lines
4.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PHYSICS_CANNISTER_H
  7. #define PHYSICS_CANNISTER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "player_pickup.h"
  12. class CSteamJet;
  13. class CThrustController : public IMotionEvent
  14. {
  15. DECLARE_SIMPLE_DATADESC();
  16. public:
  17. IMotionEvent::simresult_e Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular )
  18. {
  19. angular = m_torqueVector;
  20. linear = m_thrustVector;
  21. return SIM_LOCAL_ACCELERATION;
  22. }
  23. void CalcThrust( const Vector &position, const Vector &direction, IPhysicsObject *pPhys )
  24. {
  25. Vector force = direction * m_thrust * pPhys->GetMass();
  26. // Adjust for the position of the thruster -- apply proper torque)
  27. pPhys->CalculateVelocityOffset( force, position, &m_thrustVector, &m_torqueVector );
  28. pPhys->WorldToLocalVector( &m_thrustVector, m_thrustVector );
  29. }
  30. Vector m_thrustVector;
  31. AngularImpulse m_torqueVector;
  32. float m_thrust;
  33. };
  34. class CPhysicsCannister : public CBaseCombatCharacter, public CDefaultPlayerPickupVPhysics
  35. {
  36. DECLARE_CLASS( CPhysicsCannister, CBaseCombatCharacter );
  37. public:
  38. ~CPhysicsCannister( void );
  39. void Spawn( void );
  40. void Precache( void );
  41. virtual void OnRestore();
  42. bool CreateVPhysics();
  43. DECLARE_DATADESC();
  44. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  45. virtual QAngle PreferredCarryAngles( void ) { return QAngle( -90, 0, 0 ); }
  46. virtual bool HasPreferredCarryAnglesForPlayer( CBasePlayer *pPlayer ) { return true; }
  47. //
  48. // Input handlers.
  49. //
  50. void InputActivate(inputdata_t &data);
  51. void InputDeactivate(inputdata_t &data);
  52. void InputExplode(inputdata_t &data);
  53. void InputWake( inputdata_t &data );
  54. bool TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace );
  55. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  56. int ObjectCaps()
  57. {
  58. return (BaseClass::ObjectCaps() | FCAP_IMPULSE_USE);
  59. }
  60. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
  61. {
  62. CBasePlayer *pPlayer = ToBasePlayer( pActivator );
  63. if ( pPlayer )
  64. {
  65. pPlayer->PickupObject( this );
  66. }
  67. }
  68. void CannisterActivate( CBaseEntity *pActivator, const Vector &thrustOffset );
  69. void CannisterFire( CBaseEntity *pActivator );
  70. void Deactivate( void );
  71. void Explode( CBaseEntity *pAttacker );
  72. void ExplodeTouch( CBaseEntity *pOther );
  73. void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  74. // Don't treat as a live target
  75. virtual bool IsAlive( void ) { return false; }
  76. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &dir, trace_t *ptr );
  77. void ShutdownJet( void );
  78. void BeginShutdownThink( void );
  79. public:
  80. virtual bool OnAttemptPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason ) { return true; }
  81. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  82. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t reason );
  83. virtual CBasePlayer *HasPhysicsAttacker( float dt );
  84. virtual bool ShouldPuntUseLaunchForces( PhysGunForce_t reason )
  85. {
  86. if ( reason == PHYSGUN_FORCE_LAUNCHED )
  87. return (m_thrustTime!=0);
  88. return false;
  89. }
  90. virtual AngularImpulse PhysGunLaunchAngularImpulse( void ) { return vec3_origin; }
  91. virtual Vector PhysGunLaunchVelocity( const Vector &forward, float flMass ) { return vec3_origin; }
  92. protected:
  93. void SetPhysicsAttacker( CBasePlayer *pEntity, float flTime );
  94. public:
  95. Vector m_thrustOrigin;
  96. CThrustController m_thruster;
  97. IPhysicsMotionController *m_pController;
  98. CSteamJet *m_pJet;
  99. bool m_active;
  100. float m_thrustTime;
  101. float m_damage;
  102. float m_damageRadius;
  103. float m_activateTime;
  104. string_t m_gasSound;
  105. bool m_bFired; // True if this cannister was fire by a weapon
  106. COutputEvent m_onActivate;
  107. COutputEvent m_OnAwakened;
  108. CHandle<CBasePlayer> m_hPhysicsAttacker;
  109. float m_flLastPhysicsInfluenceTime;
  110. EHANDLE m_hLauncher; // Entity that caused this cannister to launch
  111. private:
  112. Vector CalcLocalThrust( const Vector &offset );
  113. };
  114. #endif // PHYSICS_CANNISTER_H