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.

250 lines
7.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //
  9. // Purpose:
  10. //
  11. //=============================================================================
  12. #ifndef VEHICLE_CRANE_H
  13. #define VEHICLE_CRANE_H
  14. #ifdef _WIN32
  15. #pragma once
  16. #endif
  17. #include "physobj.h"
  18. #include "rope.h"
  19. #include "rope_shared.h"
  20. #include "physics_bone_follower.h"
  21. #define CRANE_EXTENSION_RATE_MAX 0.01
  22. #define CRANE_TURN_RATE_MAX 1.2
  23. #define MAXIMUM_CRANE_PICKUP_MASS 10000
  24. #define MINIMUM_CRANE_PICKUP_MASS 500
  25. #define MAX_CRANE_FLAT_REACH 1400.0
  26. #define MIN_CRANE_FLAT_REACH 700.0
  27. #define CRANE_EXTENSION_ACCEL 0.006
  28. #define CRANE_EXTENSION_DECEL 0.02
  29. #define CRANE_TURN_ACCEL 0.2
  30. #define CRANE_DECEL 0.5
  31. #define CRANE_SLOWRAISE_TIME 5.0
  32. // Turning stats
  33. enum
  34. {
  35. TURNING_NOT,
  36. TURNING_LEFT,
  37. TURNING_RIGHT,
  38. };
  39. class CPropCrane;
  40. //-----------------------------------------------------------------------------
  41. // Purpose: This is the entity we attach to the tip of the crane and dangle the cable from
  42. //-----------------------------------------------------------------------------
  43. class CCraneTip : public CBaseAnimating
  44. {
  45. DECLARE_CLASS( CCraneTip, CBaseAnimating );
  46. public:
  47. DECLARE_DATADESC();
  48. ~CCraneTip( void )
  49. {
  50. if ( m_pSpring )
  51. {
  52. physenv->DestroySpring( m_pSpring );
  53. }
  54. }
  55. void Spawn( void );
  56. void Precache( void );
  57. bool CreateConstraint( CBaseAnimating *pMagnet, IPhysicsConstraintGroup *pGroup );
  58. static CCraneTip *Create( CBaseAnimating *pCraneMagnet, IPhysicsConstraintGroup *pGroup, const Vector &vecOrigin, const QAngle &vecAngles );
  59. public:
  60. IPhysicsSpring *m_pSpring;
  61. };
  62. //-----------------------------------------------------------------------------
  63. // Purpose: Crane vehicle server
  64. //-----------------------------------------------------------------------------
  65. class CCraneServerVehicle : public CBaseServerVehicle
  66. {
  67. typedef CBaseServerVehicle BaseClass;
  68. // IServerVehicle
  69. public:
  70. void GetVehicleViewPosition( int nRole, Vector *pAbsOrigin, QAngle *pAbsAngles, float *pFOV = NULL );
  71. // NPC Driving
  72. void NPC_SetDriver( CNPC_VehicleDriver *pDriver );
  73. void NPC_DriveVehicle( void );
  74. virtual bool IsPassengerEntering( void ) { return false; } // NOTE: This mimics the scenario HL2 would have seen
  75. virtual bool IsPassengerExiting( void ) { return false; }
  76. protected:
  77. CPropCrane *GetCrane( void );
  78. };
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. class CPropCrane : public CBaseProp, public IDrivableVehicle
  83. {
  84. DECLARE_CLASS( CPropCrane, CBaseProp );
  85. public:
  86. DECLARE_DATADESC();
  87. DECLARE_SERVERCLASS();
  88. CPropCrane( void )
  89. {
  90. m_ServerVehicle.SetVehicle( this );
  91. }
  92. ~CPropCrane( void )
  93. {
  94. physenv->DestroyConstraintGroup( m_pConstraintGroup );
  95. }
  96. // CBaseEntity
  97. virtual void Precache( void );
  98. void Spawn( void );
  99. void Activate( void );
  100. void UpdateOnRemove( void );
  101. bool CreateVPhysics( void );
  102. void InitCraneSpeeds( void );
  103. void Think(void);
  104. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_IMPULSE_USE; };
  105. virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  106. virtual void DrawDebugGeometryOverlays( void );
  107. virtual bool PassengerShouldReceiveDamage( CTakeDamageInfo &info )
  108. {
  109. if ( info.GetDamageType() & DMG_VEHICLE )
  110. return true;
  111. return (info.GetDamageType() & (DMG_RADIATION|DMG_BLAST) ) == 0;
  112. }
  113. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true );
  114. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  115. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  116. void PlayerControlInit( CBasePlayer *pPlayer );
  117. void PlayerControlShutdown( void );
  118. void ResetUseKey( CBasePlayer *pPlayer );
  119. void DriveCrane( int iDriverButtons, int iButtonsPressed, float flNPCSteering = 0.0 );
  120. void RunCraneMovement( float flTime );
  121. void TurnMagnetOn( void );
  122. void TurnMagnetOff( void );
  123. const Vector &GetCraneTipPosition( void );
  124. float GetExtensionRate( void ) { return m_flExtensionRate; }
  125. float GetTurnRate( void ) { return m_flTurn; }
  126. float GetMaxTurnRate( void ) { return m_flMaxTurnSpeed; }
  127. CPhysMagnet *GetMagnet( void ) { return m_hCraneMagnet; }
  128. float GetTotalMassOnCrane( void ) { return m_hCraneMagnet->GetTotalMassAttachedObjects(); }
  129. bool IsDropping( void ) { return m_bDropping; }
  130. // Inputs
  131. void InputLock( inputdata_t &inputdata );
  132. void InputUnlock( inputdata_t &inputdata );
  133. void InputForcePlayerIn( inputdata_t &inputdata );
  134. // Crane handling
  135. void GetCraneTipPosition( Vector *vecOrigin, QAngle *vecAngles );
  136. void RecalculateCraneTip( void );
  137. void GetVectors(Vector* pForward, Vector* pRight, Vector* pUp) const;
  138. void SetNPCDriver( CNPC_VehicleDriver *pDriver );
  139. // IDrivableVehicle
  140. public:
  141. virtual CBaseEntity *GetDriver( void );
  142. virtual void ItemPostFrame( CBasePlayer *pPlayer );
  143. virtual void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
  144. virtual void ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMoveData ) { return; }
  145. virtual void FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move ) { return; }
  146. virtual bool CanEnterVehicle( CBaseEntity *pEntity );
  147. virtual bool CanExitVehicle( CBaseEntity *pEntity );
  148. virtual void SetVehicleEntryAnim( bool bOn ) { m_bEnterAnimOn = bOn; }
  149. virtual void SetVehicleExitAnim( bool bOn, Vector vecEyeExitEndpoint ) { m_bExitAnimOn = bOn; if ( bOn ) m_vecEyeExitEndpoint = vecEyeExitEndpoint; }
  150. virtual void EnterVehicle( CBaseCombatCharacter *pPassenger );
  151. virtual bool AllowBlockedExit( CBaseCombatCharacter *pPassenger, int nRole ) { return true; }
  152. virtual bool AllowMidairExit( CBaseCombatCharacter *pPassenger, int nRole ) { return false; }
  153. virtual void PreExitVehicle( CBaseCombatCharacter *pPassenger, int nRole );
  154. virtual void ExitVehicle( int nRole );
  155. virtual string_t GetVehicleScriptName() { return m_vehicleScript; }
  156. // If this is a vehicle, returns the vehicle interface
  157. virtual IServerVehicle *GetServerVehicle() { return &m_ServerVehicle; }
  158. protected:
  159. // Contained IServerVehicle
  160. CCraneServerVehicle m_ServerVehicle;
  161. // Contained Bone Follower manager
  162. CBoneFollowerManager m_BoneFollowerManager;
  163. private:
  164. CNetworkHandle( CBasePlayer, m_hPlayer );
  165. CNetworkVar( bool, m_bMagnetOn );
  166. // NPC Driving
  167. CHandle<CNPC_VehicleDriver> m_hNPCDriver;
  168. int m_nNPCButtons;
  169. // Entering / Exiting
  170. bool m_bLocked;
  171. CNetworkVar( bool, m_bEnterAnimOn );
  172. CNetworkVar( bool, m_bExitAnimOn );
  173. CNetworkVector( m_vecEyeExitEndpoint );
  174. COutputEvent m_playerOn;
  175. COutputEvent m_playerOff;
  176. // Turning
  177. int m_iTurning;
  178. bool m_bStartSoundAtCrossover;
  179. float m_flTurn;
  180. // Crane arm extension / retraction
  181. bool m_bExtending;
  182. float m_flExtension;
  183. float m_flExtensionRate;
  184. // Magnet movement
  185. bool m_bDropping;
  186. float m_flNextDangerSoundTime;
  187. float m_flNextCreakSound;
  188. float m_flNextDropAllowedTime;
  189. float m_flSlowRaiseTime;
  190. // Speeds
  191. float m_flMaxExtensionSpeed;
  192. float m_flMaxTurnSpeed;
  193. float m_flExtensionAccel;
  194. float m_flExtensionDecel;
  195. float m_flTurnAccel;
  196. float m_flTurnDecel;
  197. // Cable Tip & Magnet
  198. string_t m_iszMagnetName;
  199. CHandle<CPhysMagnet> m_hCraneMagnet;
  200. CHandle<CCraneTip> m_hCraneTip;
  201. CHandle<CRopeKeyframe> m_hRope;
  202. IPhysicsConstraintGroup *m_pConstraintGroup;
  203. // Vehicle script filename
  204. string_t m_vehicleScript;
  205. };
  206. #endif // VEHICLE_CRANE_H