summaryrefslogtreecommitdiff
path: root/game/shared/tf/achievements_tf.h
blob: 0fd095dc8568835952c24ccc46e7c4b3b9e4d375 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================


#include "cbase.h"

#ifdef CLIENT_DLL

bool CheckWinNoEnemyCaps( IGameEvent *event, int iRole );
bool IsLocalTFPlayerClass( int iClass );
bool GameRulesAllowsAchievements( void );


//----------------------------------------------------------------------------------------------------------------
// All achievements should derive from this. It takes care of ensuring that MVM mode isn't active for
// non MVM achievements and that MVM is active for MVM achievements
class CBaseTFAchievementSimple : public CBaseAchievement
{
	DECLARE_CLASS( CBaseTFAchievementSimple, CBaseAchievement );
public:
	virtual bool LocalPlayerCanEarn( void );

	virtual void FireGameEvent( IGameEvent *event );
};

//----------------------------------------------------------------------------------------------------------------
// All class specific achievements should derive from this. It takes care of ensuring that the class
// check is performed, and saves needless event handling for other class's achievements.
class CBaseTFAchievement : public CBaseTFAchievementSimple
{
	DECLARE_CLASS( CBaseTFAchievement, CBaseTFAchievementSimple );
public:
	virtual bool LocalPlayerCanEarn( void );
};

//----------------------------------------------------------------------------------------------------------------
// Helper class for achievements that check that the player was playing on a game team for the full round
class CTFAchievementFullRound : public CBaseTFAchievement
{
	DECLARE_CLASS( CTFAchievementFullRound, CBaseTFAchievement );
public:
	void Init() ;
	virtual void ListenForEvents();
	void FireGameEvent_Internal( IGameEvent *event );
	bool PlayerWasInEntireRound( float flRoundTime );

	virtual void Event_OnRoundComplete( float flRoundTime, IGameEvent *event ) = 0 ;
};

class CAchievementTopScoreboard : public CTFAchievementFullRound
{
	DECLARE_CLASS( CAchievementTopScoreboard, CTFAchievementFullRound );

public:
	void Init();
	virtual void ListenForEvents();
	virtual void Event_OnRoundComplete( float flRoundTime, IGameEvent *event );
};

//----------------------------------------------------------------------------------------------------------------
// Helper class for achievements that involve killing players after walking through a teleporter
template < class tBaseClass >
class CTFAchievementTeleporterTimingKills : public tBaseClass
{
	DECLARE_CLASS( CTFAchievementTeleporterTimingKills, CBaseTFAchievement );

	void Init() 
	{
		this->SetFlags( ACH_SAVE_GLOBAL | ACH_LISTEN_KILL_ENEMY_EVENTS );
		this->SetGoal( 1 );
	}

	virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event ) 
	{
		if ( !pVictim || !pVictim->IsPlayer() )
			return;

		C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
		if ( pAttacker == pLocalPlayer && pVictim != pLocalPlayer )
		{
			C_TFPlayer *pTFAttacker = ToTFPlayer( pAttacker );
			if ( pTFAttacker && pTFAttacker->m_Shared.InCond( TF_COND_TELEPORTED ) && ( gpGlobals->curtime - pTFAttacker->m_Shared.GetTimeTeleEffectAdded() <= 5.0f ) )
			{
				this->IncrementCount();
			}
		}
	}
};



extern CAchievementMgr g_AchievementMgrTF;	// global achievement mgr for TF

#endif // CLIENT_DLL