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.

189 lines
5.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ROPE_H
  8. #define ROPE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "baseentity.h"
  13. #include "positionwatcher.h"
  14. class CRopeKeyframe : public CBaseEntity, public IPositionWatcher
  15. {
  16. DECLARE_CLASS( CRopeKeyframe, CBaseEntity );
  17. public:
  18. DECLARE_SERVERCLASS();
  19. DECLARE_DATADESC();
  20. CRopeKeyframe();
  21. virtual ~CRopeKeyframe();
  22. // Create a rope and attach it to two entities.
  23. // Attachment points on the entities are optional.
  24. static CRopeKeyframe* Create(
  25. CBaseEntity *pStartEnt,
  26. CBaseEntity *pEndEnt,
  27. int iStartAttachment=0,
  28. int iEndAttachment=0,
  29. int ropeWidth = 2,
  30. const char *pMaterialName = "cable/cable.vmt", // Note: whoever creates the rope must
  31. // use PrecacheModel for whatever material
  32. // it specifies here.
  33. int numSegments = 5,
  34. const char *pClassName = "keyframe_rope"
  35. );
  36. static CRopeKeyframe* CreateWithSecondPointDetached(
  37. CBaseEntity *pStartEnt,
  38. int iStartAttachment = 0, // must be 0 if you don't want to use a specific model attachment.
  39. int ropeLength = 20,
  40. int ropeWidth = 2,
  41. const char *pMaterialName = "cable/cable.vmt", // Note: whoever creates the rope
  42. // use PrecacheModel for whatever material
  43. // it specifies here.
  44. int numSegments = 5,
  45. bool bInitialHang = false,
  46. const char *pClassName = "keyframe_rope"
  47. );
  48. bool SetupHangDistance( float flHangDist );
  49. void ActivateStartDirectionConstraints( bool bEnable );
  50. void ActivateEndDirectionConstraints( bool bEnable );
  51. // Shakes all ropes near vCenter. The higher flMagnitude is, the larger the shake will be.
  52. static void ShakeRopes( const Vector &vCenter, float flRadius, float flMagnitude );
  53. static void PrecacheShakeRopes();
  54. // CBaseEntity overrides.
  55. public:
  56. // don't cross transitions
  57. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  58. virtual void Activate();
  59. virtual void Precache();
  60. virtual void Spawn( void );
  61. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  62. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  63. void PropagateForce(CBaseEntity *pActivator, CBaseEntity *pCaller, CBaseEntity *pFirstLink, float x, float y, float z);
  64. // Once-off length recalculation
  65. void RecalculateLength( void );
  66. // Kill myself when I next come to rest
  67. void DieAtNextRest( void );
  68. virtual int UpdateTransmitState(void);
  69. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  70. virtual void SetParent( CBaseEntity *pParentEntity, int iAttachment );
  71. // Input functions.
  72. public:
  73. void InputSetScrollSpeed( inputdata_t &inputdata );
  74. void InputSetForce( inputdata_t &inputdata );
  75. void InputBreak( inputdata_t &inputdata );
  76. public:
  77. bool Break( void );
  78. void DetachPoint( int iPoint );
  79. void EndpointsChanged();
  80. // By default, ropes don't collide with the world. Call this to enable it.
  81. void EnableCollision();
  82. // Toggle wind.
  83. void EnableWind( bool bEnable );
  84. CBaseEntity* GetStartPoint() { return m_hStartPoint.Get(); }
  85. int GetStartAttachment() { return m_iStartAttachment; };
  86. CBaseEntity* GetEndPoint() { return m_hEndPoint.Get(); }
  87. int GetEndAttachment() { return m_iEndAttachment; };
  88. void SetStartPoint( CBaseEntity *pStartPoint, int attachment = 0 );
  89. void SetEndPoint( CBaseEntity *pEndPoint, int attachment = 0 );
  90. // See ROPE_PLAYER_WPN_ATTACH for info.
  91. void EnablePlayerWeaponAttach( bool bAttach );
  92. // IPositionWatcher
  93. virtual void NotifyPositionChanged( CBaseEntity *pEntity );
  94. private:
  95. // Unless this is called during initialization, the caller should have done
  96. // PrecacheModel on whatever material they specify in here.
  97. void SetMaterial( const char *pName );
  98. protected:
  99. void SetAttachmentPoint( CBaseHandle &hOutEnt, short &iOutAttachment, CBaseEntity *pEnt, int iAttachment );
  100. // This is normally called by Activate but if you create the rope at runtime,
  101. // you must call it after you have setup its variables.
  102. virtual void Init();
  103. private:
  104. // These work just like the client-side versions.
  105. bool GetEndPointPos2( CBaseEntity *pEnt, int iAttachment, Vector &v );
  106. bool GetEndPointPos( int iPt, Vector &v );
  107. void UpdateBBox( bool bForceRelink );
  108. public:
  109. CNetworkVar( int, m_RopeFlags ); // Combination of ROPE_ defines in rope_shared.h
  110. string_t m_iNextLinkName;
  111. CNetworkVar( int, m_Slack );
  112. CNetworkVar( float, m_Width );
  113. CNetworkVar( float, m_TextureScale );
  114. CNetworkVar( int, m_nSegments ); // Number of segments.
  115. CNetworkVar( bool, m_bConstrainBetweenEndpoints );
  116. string_t m_strRopeMaterialModel;
  117. CNetworkVar( int, m_iRopeMaterialModelIndex ); // Index of sprite model with the rope's material.
  118. // Number of subdivisions in between segments.
  119. CNetworkVar( int, m_Subdiv );
  120. // Used simply to wake up rope on the client side if it has gone to sleep
  121. CNetworkVar( unsigned char, m_nChangeCount );
  122. //EHANDLE m_hNextLink;
  123. CNetworkVar( int, m_RopeLength ); // Rope length at startup, used to calculate tension.
  124. CNetworkVar( int, m_fLockedPoints );
  125. bool m_bCreatedFromMapFile; // set to false when creating at runtime
  126. CNetworkVar( float, m_flScrollSpeed );
  127. CNetworkVar( int, m_iDefaultRopeMaterialModelIndex );
  128. private:
  129. // Used to detect changes.
  130. bool m_bStartPointValid;
  131. bool m_bEndPointValid;
  132. CNetworkHandle( CBaseEntity, m_hStartPoint ); // StartPoint/EndPoint are entities
  133. CNetworkHandle( CBaseEntity, m_hEndPoint );
  134. CNetworkVar( short, m_iStartAttachment ); // StartAttachment/EndAttachment are attachment points.
  135. CNetworkVar( short, m_iEndAttachment );
  136. };
  137. #endif // ROPE_H