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