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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Dove entity for the Meet the Medic tease.
//
//=============================================================================//
#include "cbase.h"
#include "tf_gamerules.h"
#include "c_baseanimating.h"
#define ENTITY_FLYING_BIRD_MODEL "models/props_forest/dove.mdl"
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class C_EntityFlyingBird : public CBaseAnimating
{
DECLARE_CLASS( C_EntityFlyingBird, CBaseAnimating );
public:
void InitFromServerData( float flyAngle, float flyAngleRate, float flAccelZ, float flSpeed, float flGlideTime );
virtual void Touch( CBaseEntity *pOther );
private:
virtual void ClientThink( void );
void UpdateFlyDirection( void );
private:
Vector m_flyForward;
float m_flyAngle;
float m_flyAngleRate;
float m_flyZ;
float m_accelZ;
float m_speed;
float m_timestamp;
CountdownTimer m_lifetimeTimer;
CountdownTimer m_glideTimer;
};
//-----------------------------------------------------------------------------
// Purpose: Server message that tells us to create a dove
//-----------------------------------------------------------------------------
void __MsgFunc_SpawnFlyingBird( bf_read &msg )
{
Vector vecPos;
msg.ReadBitVec3Coord( vecPos );
float flyAngle = msg.ReadFloat();
float flyAngleRate = msg.ReadFloat();
float flAccelZ = msg.ReadFloat();
float flSpeed = msg.ReadFloat();
float flGlideTime = msg.ReadFloat();
C_EntityFlyingBird *pBird = new C_EntityFlyingBird();
if ( !pBird )
return;
pBird->SetAbsOrigin( vecPos );
pBird->InitFromServerData( flyAngle, flyAngleRate, flAccelZ, flSpeed, flGlideTime );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlyingBird::UpdateFlyDirection( void )
{
Vector forward;
forward.x = cos( m_flyAngle );
forward.y = sin( m_flyAngle );
forward.z = m_flyZ;
forward.NormalizeInPlace();
SetAbsVelocity( forward * m_speed );
QAngle angles;
VectorAngles( forward, angles );
SetAbsAngles( angles );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlyingBird::InitFromServerData( float flyAngle, float flyAngleRate, float flAccelZ, float flSpeed, float flGlideTime )
{
if ( InitializeAsClientEntity( ENTITY_FLYING_BIRD_MODEL, RENDER_GROUP_OPAQUE_ENTITY ) == false )
{
Release();
return;
}
SetMoveType( MOVETYPE_FLY );
SetSolid( SOLID_BBOX );
SetCollisionGroup( COLLISION_GROUP_DEBRIS );
SetSize( -Vector(8,8,0), Vector(8,8,16) );
m_flyAngle = flyAngle;
m_flyAngleRate = flyAngleRate;
m_accelZ = flAccelZ;
m_flyZ = 0.0;
m_speed = flSpeed;
UpdateFlyDirection();
SetSequence( 0 );
SetPlaybackRate( 1.0f );
SetCycle( 0 );
ResetSequenceInfo();
// make sure the bird is removed
m_lifetimeTimer.Start( 10.0f );
m_glideTimer.Start( flGlideTime );
SetNextClientThink( CLIENT_THINK_ALWAYS );
m_timestamp = gpGlobals->curtime;
SetModelScale( 0.1f );
SetModelScale( 1.0f, 0.5f );
}
//-----------------------------------------------------------------------------
// Purpose: Fly away!
//-----------------------------------------------------------------------------
void C_EntityFlyingBird::ClientThink( void )
{
if ( m_lifetimeTimer.IsElapsed() )
{
Release();
return;
}
if ( m_glideTimer.HasStarted() && m_glideTimer.IsElapsed() )
{
SetSequence( 1 );
SetPlaybackRate( 1.0f );
SetCycle( 0 );
ResetSequenceInfo();
m_glideTimer.Invalidate();
}
StudioFrameAdvance();
PhysicsSimulate();
const float deltaT = gpGlobals->curtime - m_timestamp;
m_flyAngle += m_flyAngleRate * deltaT;
m_flyZ += m_accelZ * deltaT;
UpdateFlyDirection();
m_timestamp = gpGlobals->curtime;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlyingBird::Touch( CBaseEntity *pOther )
{
if ( !pOther || !pOther->IsWorld() )
return;
BaseClass::Touch( pOther );
// Die at next think. Not safe to remove ourselves during physics touch.
m_lifetimeTimer.Invalidate();
}
|