-
Notifications
You must be signed in to change notification settings - Fork 638
/
Copy pathsqueakgrenade.cpp
601 lines (476 loc) · 14.5 KB
/
squeakgrenade.cpp
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/***
*
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "soundent.h"
#include "gamerules.h"
enum w_squeak_e {
WSQUEAK_IDLE1 = 0,
WSQUEAK_FIDGET,
WSQUEAK_JUMP,
WSQUEAK_RUN,
};
enum squeak_e {
SQUEAK_IDLE1 = 0,
SQUEAK_FIDGETFIT,
SQUEAK_FIDGETNIP,
SQUEAK_DOWN,
SQUEAK_UP,
SQUEAK_THROW
};
#ifndef CLIENT_DLL
class CSqueakGrenade : public CGrenade
{
void Spawn( void );
void Precache( void );
int Classify( void );
void EXPORT SuperBounceTouch( CBaseEntity *pOther );
void EXPORT HuntThink( void );
int BloodColor( void ) { return BLOOD_COLOR_YELLOW; }
void Killed( entvars_t *pevAttacker, int iGib );
void GibMonster( void );
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
static float m_flNextBounceSoundTime;
// CBaseEntity *m_pTarget;
float m_flDie;
Vector m_vecTarget;
float m_flNextHunt;
float m_flNextHit;
Vector m_posPrev;
EHANDLE m_hOwner;
int m_iMyClass;
};
float CSqueakGrenade::m_flNextBounceSoundTime = 0;
LINK_ENTITY_TO_CLASS( monster_snark, CSqueakGrenade );
TYPEDESCRIPTION CSqueakGrenade::m_SaveData[] =
{
DEFINE_FIELD( CSqueakGrenade, m_flDie, FIELD_TIME ),
DEFINE_FIELD( CSqueakGrenade, m_vecTarget, FIELD_VECTOR ),
DEFINE_FIELD( CSqueakGrenade, m_flNextHunt, FIELD_TIME ),
DEFINE_FIELD( CSqueakGrenade, m_flNextHit, FIELD_TIME ),
DEFINE_FIELD( CSqueakGrenade, m_posPrev, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CSqueakGrenade, m_hOwner, FIELD_EHANDLE ),
};
IMPLEMENT_SAVERESTORE( CSqueakGrenade, CGrenade );
#define SQUEEK_DETONATE_DELAY 15.0
int CSqueakGrenade :: Classify ( void )
{
if (m_iMyClass != 0)
return m_iMyClass; // protect against recursion
if (m_hEnemy != NULL)
{
m_iMyClass = CLASS_INSECT; // no one cares about it
switch( m_hEnemy->Classify( ) )
{
case CLASS_PLAYER:
case CLASS_HUMAN_PASSIVE:
case CLASS_HUMAN_MILITARY:
m_iMyClass = 0;
return CLASS_ALIEN_MILITARY; // barney's get mad, grunts get mad at it
}
m_iMyClass = 0;
}
return CLASS_ALIEN_BIOWEAPON;
}
void CSqueakGrenade :: Spawn( void )
{
Precache( );
// motor
pev->movetype = MOVETYPE_BOUNCE;
pev->solid = SOLID_BBOX;
SET_MODEL(ENT(pev), "models/w_squeak.mdl");
UTIL_SetSize(pev, Vector( -4, -4, 0), Vector(4, 4, 8));
UTIL_SetOrigin( pev, pev->origin );
SetTouch( &CSqueakGrenade::SuperBounceTouch );
SetThink( &CSqueakGrenade::HuntThink );
pev->nextthink = gpGlobals->time + 0.1;
m_flNextHunt = gpGlobals->time + 1E6;
pev->flags |= FL_MONSTER;
pev->takedamage = DAMAGE_AIM;
pev->health = gSkillData.snarkHealth;
pev->gravity = 0.5;
pev->friction = 0.5;
pev->dmg = gSkillData.snarkDmgPop;
m_flDie = gpGlobals->time + SQUEEK_DETONATE_DELAY;
m_flFieldOfView = 0; // 180 degrees
if ( pev->owner )
m_hOwner = Instance( pev->owner );
m_flNextBounceSoundTime = gpGlobals->time;// reset each time a snark is spawned.
pev->sequence = WSQUEAK_RUN;
ResetSequenceInfo( );
}
void CSqueakGrenade::Precache( void )
{
PRECACHE_MODEL("models/w_squeak.mdl");
PRECACHE_SOUND("squeek/sqk_blast1.wav");
PRECACHE_SOUND("common/bodysplat.wav");
PRECACHE_SOUND("squeek/sqk_die1.wav");
PRECACHE_SOUND("squeek/sqk_hunt1.wav");
PRECACHE_SOUND("squeek/sqk_hunt2.wav");
PRECACHE_SOUND("squeek/sqk_hunt3.wav");
PRECACHE_SOUND("squeek/sqk_deploy1.wav");
}
void CSqueakGrenade :: Killed( entvars_t *pevAttacker, int iGib )
{
pev->model = iStringNull;// make invisible
SetThink( &CSqueakGrenade::SUB_Remove );
SetTouch( NULL );
pev->nextthink = gpGlobals->time + 0.1;
// since squeak grenades never leave a body behind, clear out their takedamage now.
// Squeaks do a bit of radius damage when they pop, and that radius damage will
// continue to call this function unless we acknowledge the Squeak's death now. (sjb)
pev->takedamage = DAMAGE_NO;
// play squeek blast
EMIT_SOUND_DYN(ENT(pev), CHAN_ITEM, "squeek/sqk_blast1.wav", 1, 0.5, 0, PITCH_NORM);
CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, SMALL_EXPLOSION_VOLUME, 3.0 );
UTIL_BloodDrips( pev->origin, g_vecZero, BloodColor(), 80 );
if (m_hOwner != NULL)
RadiusDamage ( pev, m_hOwner->pev, pev->dmg, CLASS_NONE, DMG_BLAST );
else
RadiusDamage ( pev, pev, pev->dmg, CLASS_NONE, DMG_BLAST );
// reset owner so death message happens
if (m_hOwner != NULL)
pev->owner = m_hOwner->edict();
CBaseMonster :: Killed( pevAttacker, GIB_ALWAYS );
}
void CSqueakGrenade :: GibMonster( void )
{
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "common/bodysplat.wav", 0.75, ATTN_NORM, 0, 200);
}
void CSqueakGrenade::HuntThink( void )
{
// ALERT( at_console, "think\n" );
if (!IsInWorld())
{
SetTouch( NULL );
UTIL_Remove( this );
return;
}
StudioFrameAdvance( );
pev->nextthink = gpGlobals->time + 0.1;
// explode when ready
if (gpGlobals->time >= m_flDie)
{
g_vecAttackDir = pev->velocity.Normalize( );
pev->health = -1;
Killed( pev, 0 );
return;
}
// float
if (pev->waterlevel != 0)
{
if (pev->movetype == MOVETYPE_BOUNCE)
{
pev->movetype = MOVETYPE_FLY;
}
pev->velocity = pev->velocity * 0.9;
pev->velocity.z += 8.0;
}
else if (pev->movetype = MOVETYPE_FLY)
{
pev->movetype = MOVETYPE_BOUNCE;
}
// return if not time to hunt
if (m_flNextHunt > gpGlobals->time)
return;
m_flNextHunt = gpGlobals->time + 2.0;
CBaseEntity *pOther = NULL;
Vector vecDir;
TraceResult tr;
Vector vecFlat = pev->velocity;
vecFlat.z = 0;
vecFlat = vecFlat.Normalize( );
UTIL_MakeVectors( pev->angles );
if (m_hEnemy == NULL || !m_hEnemy->IsAlive())
{
// find target, bounce a bit towards it.
Look( 512 );
m_hEnemy = BestVisibleEnemy( );
}
// squeek if it's about time blow up
if ((m_flDie - gpGlobals->time <= 0.5) && (m_flDie - gpGlobals->time >= 0.3))
{
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_die1.wav", 1, ATTN_NORM, 0, 100 + RANDOM_LONG(0,0x3F));
CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 256, 0.25 );
}
// higher pitch as squeeker gets closer to detonation time
float flpitch = 155.0 - 60.0 * ((m_flDie - gpGlobals->time) / SQUEEK_DETONATE_DELAY);
if (flpitch < 80)
flpitch = 80;
if (m_hEnemy != NULL)
{
if (FVisible( m_hEnemy ))
{
vecDir = m_hEnemy->EyePosition() - pev->origin;
m_vecTarget = vecDir.Normalize( );
}
float flVel = pev->velocity.Length();
float flAdj = 50.0 / (flVel + 10.0);
if (flAdj > 1.2)
flAdj = 1.2;
// ALERT( at_console, "think : enemy\n");
// ALERT( at_console, "%.0f %.2f %.2f %.2f\n", flVel, m_vecTarget.x, m_vecTarget.y, m_vecTarget.z );
pev->velocity = pev->velocity * flAdj + m_vecTarget * 300;
}
if (pev->flags & FL_ONGROUND)
{
pev->avelocity = Vector( 0, 0, 0 );
}
else
{
if (pev->avelocity == Vector( 0, 0, 0))
{
pev->avelocity.x = RANDOM_FLOAT( -100, 100 );
pev->avelocity.z = RANDOM_FLOAT( -100, 100 );
}
}
if ((pev->origin - m_posPrev).Length() < 1.0)
{
pev->velocity.x = RANDOM_FLOAT( -100, 100 );
pev->velocity.y = RANDOM_FLOAT( -100, 100 );
}
m_posPrev = pev->origin;
pev->angles = UTIL_VecToAngles( pev->velocity );
pev->angles.z = 0;
pev->angles.x = 0;
}
void CSqueakGrenade::SuperBounceTouch( CBaseEntity *pOther )
{
float flpitch;
TraceResult tr = UTIL_GetGlobalTrace( );
// don't hit the guy that launched this grenade
if ( pev->owner && pOther->edict() == pev->owner )
return;
// at least until we've bounced once
pev->owner = NULL;
pev->angles.x = 0;
pev->angles.z = 0;
// avoid bouncing too much
if (m_flNextHit > gpGlobals->time)
return;
// higher pitch as squeeker gets closer to detonation time
flpitch = 155.0 - 60.0 * ((m_flDie - gpGlobals->time) / SQUEEK_DETONATE_DELAY);
if ( pOther->pev->takedamage && m_flNextAttack < gpGlobals->time )
{
// attack!
// make sure it's me who has touched them
if (tr.pHit == pOther->edict())
{
// and it's not another squeakgrenade
if (tr.pHit->v.modelindex != pev->modelindex)
{
// ALERT( at_console, "hit enemy\n");
ClearMultiDamage( );
pOther->TraceAttack(pev, gSkillData.snarkDmgBite, gpGlobals->v_forward, &tr, DMG_SLASH );
if (m_hOwner != NULL)
ApplyMultiDamage( pev, m_hOwner->pev );
else
ApplyMultiDamage( pev, pev );
pev->dmg += gSkillData.snarkDmgPop; // add more explosion damage
// m_flDie += 2.0; // add more life
// make bite sound
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, "squeek/sqk_deploy1.wav", 1.0, ATTN_NORM, 0, (int)flpitch);
m_flNextAttack = gpGlobals->time + 0.5;
}
}
else
{
// ALERT( at_console, "been hit\n");
}
}
m_flNextHit = gpGlobals->time + 0.1;
m_flNextHunt = gpGlobals->time;
if ( g_pGameRules->IsMultiplayer() )
{
// in multiplayer, we limit how often snarks can make their bounce sounds to prevent overflows.
if ( gpGlobals->time < m_flNextBounceSoundTime )
{
// too soon!
return;
}
}
if (!(pev->flags & FL_ONGROUND))
{
// play bounce sound
float flRndSound = RANDOM_FLOAT ( 0 , 1 );
if ( flRndSound <= 0.33 )
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_hunt1.wav", 1, ATTN_NORM, 0, (int)flpitch);
else if (flRndSound <= 0.66)
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_hunt2.wav", 1, ATTN_NORM, 0, (int)flpitch);
else
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_hunt3.wav", 1, ATTN_NORM, 0, (int)flpitch);
CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 256, 0.25 );
}
else
{
// skittering sound
CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 100, 0.1 );
}
m_flNextBounceSoundTime = gpGlobals->time + 0.5;// half second.
}
#endif
LINK_ENTITY_TO_CLASS( weapon_snark, CSqueak );
void CSqueak::Spawn( )
{
Precache( );
m_iId = WEAPON_SNARK;
SET_MODEL(ENT(pev), "models/w_sqknest.mdl");
FallInit();//get ready to fall down.
m_iDefaultAmmo = SNARK_DEFAULT_GIVE;
pev->sequence = 1;
pev->animtime = gpGlobals->time;
pev->framerate = 1.0;
}
void CSqueak::Precache( void )
{
PRECACHE_MODEL("models/w_sqknest.mdl");
PRECACHE_MODEL("models/v_squeak.mdl");
PRECACHE_MODEL("models/p_squeak.mdl");
PRECACHE_SOUND("squeek/sqk_hunt2.wav");
PRECACHE_SOUND("squeek/sqk_hunt3.wav");
UTIL_PrecacheOther("monster_snark");
m_usSnarkFire = PRECACHE_EVENT ( 1, "events/snarkfire.sc" );
}
int CSqueak::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "Snarks";
p->iMaxAmmo1 = SNARK_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 4;
p->iPosition = 3;
p->iId = m_iId = WEAPON_SNARK;
p->iWeight = SNARK_WEIGHT;
p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
return 1;
}
BOOL CSqueak::Deploy( )
{
// play hunt sound
float flRndSound = RANDOM_FLOAT ( 0 , 1 );
if ( flRndSound <= 0.5 )
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_hunt2.wav", 1, ATTN_NORM, 0, 100);
else
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_hunt3.wav", 1, ATTN_NORM, 0, 100);
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
return DefaultDeploy( "models/v_squeak.mdl", "models/p_squeak.mdl", SQUEAK_UP, "squeak" );
}
void CSqueak::Holster( int skiplocal /* = 0 */ )
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
if ( !m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ] )
{
m_pPlayer->pev->weapons &= ~(1<<WEAPON_SNARK);
SetThink( &CSqueak::DestroyItem );
pev->nextthink = gpGlobals->time + 0.1;
return;
}
SendWeaponAnim( SQUEAK_DOWN );
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM);
}
void CSqueak::PrimaryAttack()
{
if ( m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ] )
{
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
TraceResult tr;
Vector trace_origin;
// HACK HACK: Ugly hacks to handle change in origin based on new physics code for players
// Move origin up if crouched and start trace a bit outside of body ( 20 units instead of 16 )
trace_origin = m_pPlayer->pev->origin;
if ( m_pPlayer->pev->flags & FL_DUCKING )
{
trace_origin = trace_origin - ( VEC_HULL_MIN - VEC_DUCK_HULL_MIN );
}
// find place to toss monster
UTIL_TraceLine( trace_origin + gpGlobals->v_forward * 20, trace_origin + gpGlobals->v_forward * 64, dont_ignore_monsters, NULL, &tr );
int flags;
#ifdef CLIENT_WEAPONS
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usSnarkFire, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, 0, 0, 0, 0 );
if ( tr.fAllSolid == 0 && tr.fStartSolid == 0 && tr.flFraction > 0.25 )
{
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
#ifndef CLIENT_DLL
CBaseEntity *pSqueak = CBaseEntity::Create( "monster_snark", tr.vecEndPos, m_pPlayer->pev->v_angle, m_pPlayer->edict() );
pSqueak->pev->velocity = gpGlobals->v_forward * 200 + m_pPlayer->pev->velocity;
#endif
// play hunt sound
float flRndSound = RANDOM_FLOAT ( 0 , 1 );
if ( flRndSound <= 0.5 )
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_hunt2.wav", 1, ATTN_NORM, 0, 105);
else
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_hunt3.wav", 1, ATTN_NORM, 0, 105);
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_fJustThrown = 1;
m_flNextPrimaryAttack = GetNextAttackDelay(0.3);
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0;
}
}
}
void CSqueak::SecondaryAttack( void )
{
}
void CSqueak::WeaponIdle( void )
{
if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
return;
if (m_fJustThrown)
{
m_fJustThrown = 0;
if ( !m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] )
{
RetireWeapon();
return;
}
SendWeaponAnim( SQUEAK_UP );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
return;
}
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
if (flRand <= 0.75)
{
iAnim = SQUEAK_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 30.0 / 16 * (2);
}
else if (flRand <= 0.875)
{
iAnim = SQUEAK_FIDGETFIT;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 70.0 / 16.0;
}
else
{
iAnim = SQUEAK_FIDGETNIP;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 80.0 / 16.0;
}
SendWeaponAnim( iAnim );
}
#endif