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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Frequently used global functions.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "doors.h"
#include "entitylist.h"
#include "globals.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// Landmark class
void CPointEntity::Spawn( void )
{
SetSolid( SOLID_NONE );
// UTIL_SetSize(this, vec3_origin, vec3_origin);
}
class CNullEntity : public CBaseEntity
{
public:
DECLARE_CLASS( CNullEntity, CBaseEntity );
void Spawn( void );
};
// Null Entity, remove on startup
void CNullEntity::Spawn( void )
{
UTIL_Remove( this );
}
LINK_ENTITY_TO_CLASS(info_null,CNullEntity);
class CBaseDMStart : public CPointEntity
{
public:
DECLARE_CLASS( CBaseDMStart, CPointEntity );
bool IsTriggered( CBaseEntity *pEntity );
DECLARE_DATADESC();
string_t m_Master;
private:
};
BEGIN_DATADESC( CBaseDMStart )
DEFINE_KEYFIELD( m_Master, FIELD_STRING, "master" ),
END_DATADESC()
// These are the new entry points to entities.
LINK_ENTITY_TO_CLASS(info_player_deathmatch,CBaseDMStart);
LINK_ENTITY_TO_CLASS(info_player_start,CPointEntity);
LINK_ENTITY_TO_CLASS(info_landmark,CPointEntity);
bool CBaseDMStart::IsTriggered( CBaseEntity *pEntity )
{
bool master = UTIL_IsMasterTriggered( m_Master, pEntity );
return master;
}
// Convenient way to delay removing oneself
void CBaseEntity::SUB_Remove( void )
{
if (m_iHealth > 0)
{
// this situation can screw up NPCs who can't tell their entity pointers are invalid.
m_iHealth = 0;
DevWarning( 2, "SUB_Remove called on entity with health > 0\n");
}
UTIL_Remove( this );
}
// Convenient way to explicitly do nothing (passed to functions that require a method)
void CBaseEntity::SUB_DoNothing( void )
{
}
//-----------------------------------------------------------------------------
// Purpose: Finds all active entities with the given targetname and calls their
// 'Use' function.
// Input : targetName - Target name to search for.
// pActivator -
// pCaller -
// useType -
// value -
//-----------------------------------------------------------------------------
void FireTargets( const char *targetName, CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
CBaseEntity *pTarget = NULL;
if ( !targetName || !targetName[0] )
return;
DevMsg( 2, "Firing: (%s)\n", targetName );
for (;;)
{
CBaseEntity *pSearchingEntity = pActivator;
pTarget = gEntList.FindEntityByName( pTarget, targetName, pSearchingEntity, pActivator, pCaller );
if ( !pTarget )
break;
if (!pTarget->IsMarkedForDeletion() ) // Don't use dying ents
{
DevMsg( 2, "[%03d] Found: %s, firing (%s)\n", gpGlobals->tickcount%1000, pTarget->GetDebugName(), targetName );
pTarget->Use( pActivator, pCaller, useType, value );
}
}
}
enum togglemovetypes_t
{
MOVE_TOGGLE_NONE = 0,
MOVE_TOGGLE_LINEAR = 1,
MOVE_TOGGLE_ANGULAR = 2,
};
// Global Savedata for Toggle
BEGIN_DATADESC( CBaseToggle )
DEFINE_FIELD( m_toggle_state, FIELD_INTEGER ),
DEFINE_FIELD( m_flMoveDistance, FIELD_FLOAT ),
DEFINE_FIELD( m_flWait, FIELD_FLOAT ),
DEFINE_FIELD( m_flLip, FIELD_FLOAT ),
DEFINE_FIELD( m_vecPosition1, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecPosition2, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecMoveAng, FIELD_VECTOR ), // UNDONE: Position could go through transition, but also angle?
DEFINE_FIELD( m_vecAngle1, FIELD_VECTOR ), // UNDONE: Position could go through transition, but also angle?
DEFINE_FIELD( m_vecAngle2, FIELD_VECTOR ), // UNDONE: Position could go through transition, but also angle?
DEFINE_FIELD( m_flHeight, FIELD_FLOAT ),
DEFINE_FIELD( m_hActivator, FIELD_EHANDLE ),
DEFINE_FIELD( m_vecFinalDest, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecFinalAngle, FIELD_VECTOR ),
DEFINE_FIELD( m_sMaster, FIELD_STRING),
DEFINE_FIELD( m_movementType, FIELD_INTEGER ), // Linear or angular movement? (togglemovetypes_t)
END_DATADESC()
CBaseToggle::CBaseToggle()
{
#ifdef _DEBUG
// necessary since in debug, we initialize vectors to NAN for debugging
m_vecPosition1.Init();
m_vecPosition2.Init();
m_vecAngle1.Init();
m_vecAngle2.Init();
m_vecFinalDest.Init();
m_vecFinalAngle.Init();
#endif
}
bool CBaseToggle::KeyValue( const char *szKeyName, const char *szValue )
{
if (FStrEq(szKeyName, "lip"))
{
m_flLip = atof(szValue);
}
else if (FStrEq(szKeyName, "wait"))
{
m_flWait = atof(szValue);
}
else if (FStrEq(szKeyName, "master"))
{
m_sMaster = AllocPooledString(szValue);
}
else if (FStrEq(szKeyName, "distance"))
{
m_flMoveDistance = atof(szValue);
}
else
return BaseClass::KeyValue( szKeyName, szValue );
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Calculate m_vecVelocity and m_flNextThink to reach vecDest from
// GetOrigin() traveling at flSpeed.
// Input : Vector vecDest -
// flSpeed -
//-----------------------------------------------------------------------------
void CBaseToggle::LinearMove( const Vector &vecDest, float flSpeed )
{
ASSERTSZ(flSpeed != 0, "LinearMove: no speed is defined!");
m_vecFinalDest = vecDest;
m_movementType = MOVE_TOGGLE_LINEAR;
// Already there?
if (vecDest == GetLocalOrigin())
{
MoveDone();
return;
}
// set destdelta to the vector needed to move
Vector vecDestDelta = vecDest - GetLocalOrigin();
// divide vector length by speed to get time to reach dest
float flTravelTime = vecDestDelta.Length() / flSpeed;
// set m_flNextThink to trigger a call to LinearMoveDone when dest is reached
SetMoveDoneTime( flTravelTime );
// scale the destdelta vector by the time spent traveling to get velocity
SetLocalVelocity( vecDestDelta / flTravelTime );
}
void CBaseToggle::MoveDone( void )
{
switch ( m_movementType )
{
case MOVE_TOGGLE_LINEAR:
LinearMoveDone();
break;
case MOVE_TOGGLE_ANGULAR:
AngularMoveDone();
break;
}
m_movementType = MOVE_TOGGLE_NONE;
BaseClass::MoveDone();
}
//-----------------------------------------------------------------------------
// Purpose: After moving, set origin to exact final destination, call "move done" function.
//-----------------------------------------------------------------------------
void CBaseToggle::LinearMoveDone( void )
{
UTIL_SetOrigin( this, m_vecFinalDest);
SetAbsVelocity( vec3_origin );
SetMoveDoneTime( -1 );
}
// DVS TODO: obselete, remove?
bool CBaseToggle::IsLockedByMaster( void )
{
if (m_sMaster != NULL_STRING && !UTIL_IsMasterTriggered(m_sMaster, m_hActivator))
return true;
else
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Calculate m_vecVelocity and m_flNextThink to reach vecDest from
// GetLocalOrigin() traveling at flSpeed. Just like LinearMove, but rotational.
// Input : vecDestAngle -
// flSpeed -
//-----------------------------------------------------------------------------
void CBaseToggle::AngularMove( const QAngle &vecDestAngle, float flSpeed )
{
ASSERTSZ(flSpeed != 0, "AngularMove: no speed is defined!");
m_vecFinalAngle = vecDestAngle;
m_movementType = MOVE_TOGGLE_ANGULAR;
// Already there?
if (vecDestAngle == GetLocalAngles())
{
MoveDone();
return;
}
// set destdelta to the vector needed to move
QAngle vecDestDelta = vecDestAngle - GetLocalAngles();
// divide by speed to get time to reach dest
float flTravelTime = vecDestDelta.Length() / flSpeed;
const float MinTravelTime = 0.01f;
if ( flTravelTime < MinTravelTime )
{
// If we only travel for a short time, we can fail WillSimulateGamePhysics()
flTravelTime = MinTravelTime;
flSpeed = vecDestDelta.Length() / flTravelTime;
}
// set m_flNextThink to trigger a call to AngularMoveDone when dest is reached
SetMoveDoneTime( flTravelTime );
// scale the destdelta vector by the time spent traveling to get velocity
SetLocalAngularVelocity( vecDestDelta * (1.0 / flTravelTime) );
}
//-----------------------------------------------------------------------------
// Purpose: After rotating, set angle to exact final angle, call "move done" function.
//-----------------------------------------------------------------------------
void CBaseToggle::AngularMoveDone( void )
{
SetLocalAngles( m_vecFinalAngle );
SetLocalAngularVelocity( vec3_angle );
SetMoveDoneTime( -1 );
}
float CBaseToggle::AxisValue( int flags, const QAngle &angles )
{
if ( FBitSet(flags, SF_DOOR_ROTATE_ROLL) )
return angles.z;
if ( FBitSet(flags, SF_DOOR_ROTATE_PITCH) )
return angles.x;
return angles.y;
}
void CBaseToggle::AxisDir( void )
{
if ( m_spawnflags & SF_DOOR_ROTATE_ROLL )
m_vecMoveAng = QAngle( 0, 0, 1 ); // angles are roll
else if ( m_spawnflags & SF_DOOR_ROTATE_PITCH )
m_vecMoveAng = QAngle( 1, 0, 0 ); // angles are pitch
else
m_vecMoveAng = QAngle( 0, 1, 0 ); // angles are yaw
}
float CBaseToggle::AxisDelta( int flags, const QAngle &angle1, const QAngle &angle2 )
{
// UNDONE: Use AngleDistance() here?
if ( FBitSet (flags, SF_DOOR_ROTATE_ROLL) )
return angle1.z - angle2.z;
if ( FBitSet (flags, SF_DOOR_ROTATE_PITCH) )
return angle1.x - angle2.x;
return angle1.y - angle2.y;
}
|