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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef NPC_CROW_H
#define NPC_CROW_H
#ifdef _WIN32
#pragma once
#endif
#define BIRDTYPE_CROW 1
#define BIRDTYPE_PIGEON 2
#define BIRDTYPE_SEAGULL 3
//
// Spawnflags.
//
#define SF_CROW_FLYING 16
#define CROW_TAKEOFF_SPEED 170
#define CROW_AIRSPEED 220 // FIXME: should be about 440, but I need to add acceleration
//
// Custom schedules.
//
enum
{
SCHED_CROW_IDLE_WALK = LAST_SHARED_SCHEDULE,
SCHED_CROW_IDLE_FLY,
//
// Various levels of wanting to get away from something, selected
// by current value of m_nMorale.
//
SCHED_CROW_WALK_AWAY,
SCHED_CROW_RUN_AWAY,
SCHED_CROW_HOP_AWAY,
SCHED_CROW_FLY_AWAY,
SCHED_CROW_FLY,
SCHED_CROW_FLY_FAIL,
SCHED_CROW_BARNACLED,
};
//
// Custom tasks.
//
enum
{
TASK_CROW_FIND_FLYTO_NODE = LAST_SHARED_TASK,
//TASK_CROW_PREPARE_TO_FLY,
TASK_CROW_TAKEOFF,
//TASK_CROW_LAND,
TASK_CROW_FLY,
TASK_CROW_FLY_TO_HINT,
TASK_CROW_PICK_RANDOM_GOAL,
TASK_CROW_PICK_EVADE_GOAL,
TASK_CROW_HOP,
TASK_CROW_FALL_TO_GROUND,
TASK_CROW_PREPARE_TO_FLY_RANDOM,
TASK_CROW_WAIT_FOR_BARNACLE_KILL,
};
//
// Custom conditions.
//
enum
{
COND_CROW_ENEMY_TOO_CLOSE = LAST_SHARED_CONDITION,
COND_CROW_ENEMY_WAY_TOO_CLOSE,
COND_CROW_FORCED_FLY,
COND_CROW_BARNACLED,
};
enum FlyState_t
{
FlyState_Walking = 0,
FlyState_Flying,
FlyState_Falling,
FlyState_Landing,
};
//-----------------------------------------------------------------------------
// The crow class.
//-----------------------------------------------------------------------------
class CNPC_Crow : public CAI_BaseNPC
{
DECLARE_CLASS( CNPC_Crow, CAI_BaseNPC );
public:
//
// CBaseEntity:
//
virtual void Spawn( void );
virtual void Precache( void );
virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true );
virtual int DrawDebugTextOverlays( void );
//
// CBaseCombatCharacter:
//
virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
virtual bool CorpseGib( const CTakeDamageInfo &info );
bool BecomeRagdollOnClient( const Vector &force );
//
// CAI_BaseNPC:
//
virtual float MaxYawSpeed( void ) { return 120.0f; }
virtual Class_T Classify( void );
virtual void GatherEnemyConditions( CBaseEntity *pEnemy );
virtual void HandleAnimEvent( animevent_t *pEvent );
virtual int GetSoundInterests( void );
virtual int SelectSchedule( void );
virtual void StartTask( const Task_t *pTask );
virtual void RunTask( const Task_t *pTask );
virtual bool HandleInteraction( int interactionType, void *data, CBaseCombatCharacter *sourceEnt );
virtual void OnChangeActivity( Activity eNewActivity );
virtual bool OverrideMove( float flInterval );
virtual bool FValidateHintType( CAI_Hint *pHint );
virtual Activity GetHintActivity( short sHintType, Activity HintsActivity );
virtual void PainSound( const CTakeDamageInfo &info );
virtual void DeathSound( const CTakeDamageInfo &info );
virtual void IdleSound( void );
virtual void AlertSound( void );
virtual void StopLoopingSounds( void );
virtual void UpdateEfficiency( bool bInPVS );
virtual bool QueryHearSound( CSound *pSound );
void InputFlyAway( inputdata_t &inputdata );
void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
void StartTargetHandling( CBaseEntity *pTargetEnt );
DEFINE_CUSTOM_AI;
DECLARE_DATADESC();
int m_iBirdType;
bool m_bOnJeep;
protected:
void SetFlyingState( FlyState_t eState );
inline bool IsFlying( void ) const { return GetNavType() == NAV_FLY; }
void Takeoff( const Vector &vGoal );
void FlapSound( void );
void MoveCrowFly( float flInterval );
bool Probe( const Vector &vecMoveDir, float flSpeed, Vector &vecDeflect );
bool IsDeaf() { return m_bIsDeaf; }
protected:
float m_flGroundIdleMoveTime;
float m_flEnemyDist; // Distance to GetEnemy(), cached in GatherEnemyConditions.
int m_nMorale; // Used to determine which avoidance schedule to pick. Degrades as I pick avoidance schedules.
bool m_bReachedMoveGoal;
float m_flHopStartZ; // Our Z coordinate when we started a hop. Used to check for accidentally hopping off things.
bool m_bPlayedLoopingSound;
private:
Activity NPC_TranslateActivity( Activity eNewActivity );
float m_flSoarTime;
bool m_bSoar;
Vector m_vLastStoredOrigin;
float m_flLastStuckCheck;
float m_flDangerSoundTime;
Vector m_vDesiredTarget;
Vector m_vCurrentTarget;
bool m_bIsDeaf;
};
//-----------------------------------------------------------------------------
// Purpose: Seagull. Crow with a different model.
//-----------------------------------------------------------------------------
class CNPC_Seagull : public CNPC_Crow
{
DECLARE_CLASS( CNPC_Seagull, CNPC_Crow );
public:
void Spawn( void )
{
SetModelName( AllocPooledString("models/seagull.mdl") );
BaseClass::Spawn();
m_iBirdType = BIRDTYPE_SEAGULL;
}
void PainSound( const CTakeDamageInfo &info )
{
EmitSound( "NPC_Seagull.Pain" );
}
void DeathSound( const CTakeDamageInfo &info )
{
EmitSound( "NPC_Seagull.Pain" );
}
void IdleSound( void )
{
EmitSound( "NPC_Seagull.Idle" );
}
};
//-----------------------------------------------------------------------------
// Purpose: Pigeon. Crow with a different model.
//-----------------------------------------------------------------------------
class CNPC_Pigeon : public CNPC_Crow
{
DECLARE_CLASS( CNPC_Pigeon, CNPC_Crow );
public:
void Spawn( void )
{
SetModelName( AllocPooledString("models/pigeon.mdl") );
BaseClass::Spawn();
m_iBirdType = BIRDTYPE_PIGEON;
}
void IdleSound( void )
{
EmitSound( "NPC_Pigeon.Idle" );
}
};
#endif // NPC_CROW_H
|