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.

177 lines
5.2 KiB

  1. //========= Copyright 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. );
  35. static CRopeKeyframe* CreateWithSecondPointDetached(
  36. CBaseEntity *pStartEnt,
  37. int iStartAttachment = 0, // must be 0 if you don't want to use a specific model attachment.
  38. int ropeLength = 20,
  39. int ropeWidth = 2,
  40. const char *pMaterialName = "cable/cable.vmt", // Note: whoever creates the rope
  41. // use PrecacheModel for whatever material
  42. // it specifies here.
  43. int numSegments = 5,
  44. bool bInitialHang = false
  45. );
  46. bool SetupHangDistance( float flHangDist );
  47. void ActivateStartDirectionConstraints( bool bEnable );
  48. void ActivateEndDirectionConstraints( bool bEnable );
  49. // Shakes all ropes near vCenter. The higher flMagnitude is, the larger the shake will be.
  50. static void ShakeRopes( const Vector &vCenter, float flRadius, float flMagnitude );
  51. // CBaseEntity overrides.
  52. public:
  53. // don't cross transitions
  54. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  55. virtual void Activate();
  56. virtual void Precache();
  57. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  58. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  59. void PropagateForce(CBaseEntity *pActivator, CBaseEntity *pCaller, CBaseEntity *pFirstLink, float x, float y, float z);
  60. // Once-off length recalculation
  61. void RecalculateLength( void );
  62. // Kill myself when I next come to rest
  63. void DieAtNextRest( void );
  64. virtual int UpdateTransmitState(void);
  65. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  66. virtual void SetParent( CBaseEntity *pParentEntity, int iAttachment );
  67. // Input functions.
  68. public:
  69. void InputSetScrollSpeed( inputdata_t &inputdata );
  70. void InputSetForce( inputdata_t &inputdata );
  71. void InputBreak( inputdata_t &inputdata );
  72. public:
  73. bool Break( void );
  74. void DetachPoint( int iPoint );
  75. void EndpointsChanged();
  76. // By default, ropes don't collide with the world. Call this to enable it.
  77. void EnableCollision();
  78. // Toggle wind.
  79. void EnableWind( bool bEnable );
  80. // Unless this is called during initialization, the caller should have done
  81. // PrecacheModel on whatever material they specify in here.
  82. void SetMaterial( const char *pName );
  83. CBaseEntity* GetEndPoint() { return m_hEndPoint.Get(); }
  84. int GetEndAttachment() { return m_iStartAttachment; };
  85. void SetStartPoint( CBaseEntity *pStartPoint, int attachment = 0 );
  86. void SetEndPoint( CBaseEntity *pEndPoint, int attachment = 0 );
  87. // See ROPE_PLAYER_WPN_ATTACH for info.
  88. void EnablePlayerWeaponAttach( bool bAttach );
  89. // IPositionWatcher
  90. virtual void NotifyPositionChanged( CBaseEntity *pEntity );
  91. private:
  92. void SetAttachmentPoint( CBaseHandle &hOutEnt, short &iOutAttachment, CBaseEntity *pEnt, int iAttachment );
  93. // This is normally called by Activate but if you create the rope at runtime,
  94. // you must call it after you have setup its variables.
  95. void Init();
  96. // These work just like the client-side versions.
  97. bool GetEndPointPos2( CBaseEntity *pEnt, int iAttachment, Vector &v );
  98. bool GetEndPointPos( int iPt, Vector &v );
  99. void UpdateBBox( bool bForceRelink );
  100. public:
  101. CNetworkVar( int, m_RopeFlags ); // Combination of ROPE_ defines in rope_shared.h
  102. string_t m_iNextLinkName;
  103. CNetworkVar( int, m_Slack );
  104. CNetworkVar( float, m_Width );
  105. CNetworkVar( float, m_TextureScale );
  106. CNetworkVar( int, m_nSegments ); // Number of segments.
  107. CNetworkVar( bool, m_bConstrainBetweenEndpoints );
  108. string_t m_strRopeMaterialModel;
  109. CNetworkVar( int, m_iRopeMaterialModelIndex ); // Index of sprite model with the rope's material.
  110. // Number of subdivisions in between segments.
  111. CNetworkVar( int, m_Subdiv );
  112. //EHANDLE m_hNextLink;
  113. CNetworkVar( int, m_RopeLength ); // Rope length at startup, used to calculate tension.
  114. CNetworkVar( int, m_fLockedPoints );
  115. bool m_bCreatedFromMapFile; // set to false when creating at runtime
  116. CNetworkVar( float, m_flScrollSpeed );
  117. private:
  118. // Used to detect changes.
  119. bool m_bStartPointValid;
  120. bool m_bEndPointValid;
  121. CNetworkHandle( CBaseEntity, m_hStartPoint ); // StartPoint/EndPoint are entities
  122. CNetworkHandle( CBaseEntity, m_hEndPoint );
  123. CNetworkVar( short, m_iStartAttachment ); // StartAttachment/EndAttachment are attachment points.
  124. CNetworkVar( short, m_iEndAttachment );
  125. };
  126. #endif // ROPE_H