forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathachievements_hlx.cpp
253 lines (225 loc) · 7.74 KB
/
achievements_hlx.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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "cbase.h"
#ifdef GAME_DLL
// this gets compiled in for HL2 + Ep(X) only
#if ( defined( HL2_DLL ) || defined( HL2_EPISODIC ) ) && ( !defined ( PORTAL ) )
#include "baseachievement.h"
#include "prop_combine_ball.h"
#include "combine_mine.h"
#include "basegrenade_shared.h"
#include "basehlcombatweapon_shared.h"
#include "ammodef.h"
class CAchievementHLXKillWithPhysicsObjects : public CBaseAchievement
{
void Init()
{
SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
SetInflictorFilter( "prop_physics" );
SetGoal( 30 );
if ( IsPC() )
{
// only in Ep2 for PC. (Shared across HLX for X360.)
SetGameDirFilter( "ep2" );
}
}
virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
{
int iDamageBits = event->GetInt( "damagebits" );
// was victim killed with crushing damage?
if ( iDamageBits & DMG_CRUSH )
{
IncrementCount();
}
}
};
DECLARE_ACHIEVEMENT( CAchievementHLXKillWithPhysicsObjects, ACHIEVEMENT_HLX_KILL_ENEMIES_WITHPHYSICS, "HLX_KILL_ENEMIES_WITHPHYSICS", 5 );
class CAchievementHLXKillWithHopper : public CBaseAchievement
{
void Init()
{
SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
SetAttackerFilter( "combine_mine" );
SetGoal( 1 );
if ( IsPC() )
{
// only in Ep2 for PC. (Shared across HLX for X360.)
SetGameDirFilter( "ep2" );
}
}
virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
{
// If we get here, a combine mine has killed a player enemy. Now check and see if the player planted it
CBounceBomb *pBounceBomb = dynamic_cast<CBounceBomb *>( pAttacker );
if ( pBounceBomb && pBounceBomb->IsPlayerPlaced() )
{
IncrementCount();
}
}
};
DECLARE_ACHIEVEMENT( CAchievementHLXKillWithHopper, ACHIEVEMENT_HLX_KILL_ENEMY_WITHHOPPERMINE, "HLX_KILL_ENEMY_WITHHOPPERMINE", 5 );
class CAchievementHLXKillWithManhack : public CBaseAchievement
{
void Init()
{
SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
SetInflictorFilter( "npc_manhack" );
SetGoal( 5 );
if ( IsPC() )
{
// only in HL2 for PC. (Shared across HLX for X360.)
SetGameDirFilter( "hl2" );
}
}
virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
{
// We've already filtered to only get called when a player enemy gets killed with a manhack. Now just check for the
// case of player smashing manhack into something, in which case the manhack is both the victim and inflictor.
// If that's not the case, this is a player kill w/manhack.
if ( pVictim != pInflictor )
{
IncrementCount();
}
}
};
DECLARE_ACHIEVEMENT( CAchievementHLXKillWithManhack, ACHIEVEMENT_HLX_KILL_ENEMIES_WITHMANHACK, "HLX_KILL_ENEMIES_WITHMANHACK", 5 );
class CAchievementHLXKillSoldierWithOwnGrenade : public CBaseAchievement
{
protected:
void Init()
{
SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
SetInflictorFilter( "npc_grenade_frag" );
SetVictimFilter( "npc_combine_s" );
SetGoal( 1 );
if ( IsPC() )
{
// only in Ep2 for PC. (Shared across HLX for X360.)
SetGameDirFilter( "ep2" );
}
}
virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
{
CBaseGrenade *pGrenade = dynamic_cast<CBaseGrenade *>( pInflictor );
if ( pGrenade )
{
CBaseEntity *pThrower = pGrenade->GetThrower();
CBaseEntity *pOriginalThrower = pGrenade->GetOriginalThrower();
CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
// check if player was most recent thrower, but the victim was the original thrower
if ( ( pPlayer == pThrower ) && ( pOriginalThrower == pVictim ) )
{
IncrementCount();
}
}
}
};
DECLARE_ACHIEVEMENT( CAchievementHLXKillSoldierWithOwnGrenade, ACHIEVEMENT_HLX_KILL_SOLDIER_WITHHISGRENADE, "HLX_KILL_SOLDIER_WITHHISGRENADE", 10 );
class CAchievementHLXKillWithOneEnergyBall : public CBaseAchievement
{
protected:
virtual void Init()
{
SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
SetInflictorFilter( "prop_combine_ball" );
SetGoal( 1 );
m_pLastInflictor = NULL;
m_iLocalCount = 0;
if ( IsPC() )
{
// only in Ep1 for PC. (Shared across HLX for X360.)
SetGameDirFilter( "episodic" );
}
}
virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
{
// to count # of kills with same energy ball, keep track of previous inflictor
if ( m_pLastInflictor != NULL && pInflictor != m_pLastInflictor )
{
// new inflictor, start the count over at 1
m_iLocalCount = 1;
}
else
{
// same inflictor, keep counting
m_iLocalCount++;
if ( 5 == m_iLocalCount )
{
IncrementCount();
}
}
// keep track of last inflictor
m_pLastInflictor = pInflictor;
}
CBaseEntity *m_pLastInflictor;
int m_iLocalCount;
};
DECLARE_ACHIEVEMENT( CAchievementHLXKillWithOneEnergyBall, ACHIEVEMENT_HLX_KILL_ENEMIES_WITHONEENERGYBALL, "HLX_KILL_ENEMIES_WITHONEENERGYBALL", 5 );
class CAchievementHLXKillEliteSoldierWithOwnEnergyBall : public CBaseAchievement
{
protected:
virtual void Init()
{
SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
SetInflictorFilter( "prop_combine_ball" );
SetVictimFilter( "npc_combine_s" );
SetGoal( 1 );
if ( IsPC() )
{
// only in Ep2 for PC. (Shared across HLX for X360.)
SetGameDirFilter( "episodic" );
}
}
virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
{
CPropCombineBall *pBall = dynamic_cast<CPropCombineBall *>( pInflictor );
if ( pBall )
{
// determine original owner of this ball
CBaseEntity *pOriginalOwner = pBall->GetOriginalOwner();
// see if original owner is the victim
if ( pOriginalOwner && ( pOriginalOwner == pVictim ) )
{
IncrementCount();
}
}
}
};
DECLARE_ACHIEVEMENT( CAchievementHLXKillEliteSoldierWithOwnEnergyBall, ACHIEVEMENT_HLX_KILL_ELITESOLDIER_WITHHISENERGYBALL, "HLX_KILL_ELITESOLDIER_WITHHISENERGYBALL", 10 );
//-----------------------------------------------------------------------------
// Purpose: Counts the accumulated # of primary and secondary attacks from all
// weapons (except grav gun). If bBulletOnly is true, only counts
// attacks with ammo that does bullet damage.
//-----------------------------------------------------------------------------
int CalcPlayerAttacks( bool bBulletOnly )
{
CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
CAmmoDef *pAmmoDef = GetAmmoDef();
if ( !pPlayer || !pAmmoDef )
return 0;
int iTotalAttacks = 0;
int iWeapons = pPlayer->WeaponCount();
for ( int i = 0; i < iWeapons; i++ )
{
CBaseHLCombatWeapon *pWeapon = dynamic_cast<CBaseHLCombatWeapon *>( pPlayer->GetWeapon( i ) );
if ( pWeapon )
{
// add primary attacks if we were asked for all attacks, or only if it uses bullet ammo if we were asked to count bullet attacks
if ( !bBulletOnly || ( pAmmoDef->m_AmmoType[pWeapon->GetPrimaryAmmoType()].nDamageType == DMG_BULLET ) )
{
iTotalAttacks += pWeapon->m_iPrimaryAttacks;
}
// add secondary attacks if we were asked for all attacks, or only if it uses bullet ammo if we were asked to count bullet attacks
if ( !bBulletOnly || ( pAmmoDef->m_AmmoType[pWeapon->GetSecondaryAmmoType()].nDamageType == DMG_BULLET ) )
{
iTotalAttacks += pWeapon->m_iSecondaryAttacks;
}
}
}
return iTotalAttacks;
}
#endif // ( defined( HL2_DLL ) || defined( HL2_EPISODIC ) ) && ( !defined ( PORTAL ) )
#endif // GAME_DLL