summaryrefslogtreecommitdiff
path: root/game/shared/tf/tf_logic_robot_destruction.h
blob: c5e3a2c82f0e0569aa998fa6432d101e78f3cac4 (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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Entities for use in the Robot Destruction TF2 game mode.
//
//=========================================================================//
#ifndef LOGIC_ROBOT_DESTRUCTION_H
#define LOGIC_ROBOT_DESTRUCTION_H
#pragma once

#include "cbase.h"

#ifdef GAME_DLL
	#include "triggers.h"
	#include "tf_shareddefs.h"
	#include "GameEventListener.h"
	#include "entity_capture_flag.h"
#else
	#include "c_tf_player.h"
#endif


#include "tf_robot_destruction_robot.h"

#ifdef CLIENT_DLL
	#define CTFRobotDestructionLogic C_TFRobotDestructionLogic
	#define CTFRobotDestruction_RobotSpawn C_TFRobotDestruction_RobotSpawn
	#define CTFRobotDestruction_RobotGroup C_TFRobotDestruction_RobotGroup
#endif

#include "props_shared.h"

#define RD_POINTS_STOLEN_PER_TICK 2

//-----------------------------------------------------------------------------
class CTFRobotDestruction_RobotSpawn : public CBaseEntity
{
public:
	DECLARE_DATADESC();
	DECLARE_CLASS( CTFRobotDestruction_RobotSpawn, CBaseEntity )
	DECLARE_NETWORKCLASS();

	CTFRobotDestruction_RobotSpawn();

	virtual void Spawn() OVERRIDE;
	virtual void Activate() OVERRIDE;

#ifdef GAME_DLL
	virtual void Precache() OVERRIDE;
	virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const OVERRIDE;

	CTFRobotDestruction_Robot* GetRobot() const { return m_hRobot.Get(); }
	void OnRobotKilled();
	void ClearRobot();
	void SpawnRobot();
	void SetGroup( class CTFRobotDestruction_RobotGroup* pGroup ) { m_hGroup.Set( pGroup ); }
	// Inputs
	void InputSpawnRobot( inputdata_t &inputdata );
	
#endif
private:
	CHandle< CTFRobotDestruction_Robot > m_hRobot;
#ifdef GAME_DLL
	CHandle< class CTFRobotDestruction_RobotGroup > m_hGroup;
	RobotSpawnData_t m_spawnData;
	COutputEvent m_OnRobotKilled;
#endif
};

//-----------------------------------------------------------------------------
DECLARE_AUTO_LIST( IRobotDestructionGroupAutoList );
class CTFRobotDestruction_RobotGroup : public CBaseEntity, public IRobotDestructionGroupAutoList
{
	DECLARE_DATADESC();
	DECLARE_CLASS( CTFRobotDestruction_RobotGroup, CBaseEntity )
	DECLARE_NETWORKCLASS();
public:
	virtual ~CTFRobotDestruction_RobotGroup();
#ifdef GAME_DLL

	CTFRobotDestruction_RobotGroup();

	virtual int		UpdateTransmitState() OVERRIDE { return SetTransmitState( FL_EDICT_ALWAYS ); }
	virtual void	Spawn() OVERRIDE;
	virtual void	Activate() OVERRIDE;
	void	AddToGroup( CTFRobotDestruction_RobotSpawn * pSpawn );
	void	RemoveFromGroup( CTFRobotDestruction_RobotSpawn * pSpawn );
	void	UpdateState();
	void	RespawnRobots();
	int		GetNumAliveBots() const;
	float	GetTeamRespawnScale() const	{ return m_flTeamRespawnReductionScale; }

	// Respawn functions
	void StopRespawnTimer();
	void StartRespawnTimerIfNeeded( CTFRobotDestruction_RobotGroup *pMasterGroup );
	void RespawnCountdownFinish();

	void EnableUberForGroup();
	void DisableUberForGroup();

	void OnRobotAttacked();
	void OnRobotKilled();
	void OnRobotSpawned();
#else
	virtual void PostDataUpdate( DataUpdateType_t updateType ) OVERRIDE;
	virtual int GetTeamNumber( void ) const OVERRIDE { return m_iTeamNum; }
	virtual void SetDormant( bool bDormant ) OVERRIDE;
#endif
	const char *GetHUDIcon() const		{ return m_pszHudIcon; }
	int		GetGroupNumber() const		{ return m_nGroupNumber; }
	int		GetState() const			{ return m_nState; }
	float	GetRespawnStartTime() const	{ return m_flRespawnStartTime; }
	float	GetRespawnEndTime() const	{ return m_flRespawnEndTime; }
	float	GetLastAttackedTime() const	{ return m_flLastAttackedTime; }

private:

#ifdef GAME_DLL
	CUtlVector< CTFRobotDestruction_RobotSpawn* > m_vecSpawns;
	int m_nTeamNumber;
	IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_iTeamNum );
	float m_flRespawnTime;
	static float m_sflNextAllowedAttackAlertTime[ TF_TEAM_COUNT ];
	string_t m_iszHudIcon;
	float m_flTeamRespawnReductionScale;

	COutputEvent m_OnRobotsRespawn;
	COutputEvent m_OnAllRobotsDead;
#else
	int m_iTeamNum;
#endif
	CNetworkString( m_pszHudIcon, MAX_PATH );
	CNetworkVar( int, m_nGroupNumber );
	CNetworkVar( int, m_nState );
	CNetworkVar( float, m_flRespawnStartTime );
	CNetworkVar( float, m_flRespawnEndTime );
	CNetworkVar( float, m_flLastAttackedTime );
};

struct RateLimitedSound_t
{
	RateLimitedSound_t( float flPause )
	{
		m_mapNextAllowedTime.SetLessFunc( DefLessFunc( const CBaseEntity* ) );
		m_flPause = flPause;
	}

	float m_flPause;
	CUtlMap< const CBaseEntity*, float > m_mapNextAllowedTime;
};

struct TeamSound_t
{
	const char *m_pszYourTeam;
	const char *m_pszTheirTeam;
};

//-----------------------------------------------------------------------------
class CTFRobotDestructionLogic : public CBaseEntity
#ifdef GAME_DLL
	, public CGameEventListener
#endif
{
	DECLARE_CLASS( CTFRobotDestructionLogic, CBaseEntity )
	DECLARE_NETWORKCLASS();
public:

	enum EType
	{
		TYPE_ROBOT_DESTRUCTION,
		TYPE_PLAYER_DESTRUCTION,
	};

	virtual EType GetType() const { return TYPE_ROBOT_DESTRUCTION; }

	CTFRobotDestructionLogic();
	virtual ~CTFRobotDestructionLogic();
	static CTFRobotDestructionLogic* GetRobotDestructionLogic();

	virtual void Spawn() OVERRIDE;
	virtual void Precache() OVERRIDE;

	float	GetRespawnScaleForTeam( int nTeam ) const;
	int		GetScore( int nTeam ) const;
	int		GetTargetScore( int nTeam ) const;
	int		GetMaxPoints() const { return m_nMaxPoints.Get(); }
	float	GetFinaleWinTime( int nTeam ) const;
	float	GetFinaleLength() const { return m_flFinaleLength; }
	void	PlaySoundInfoForScoreEvent( CTFPlayer* pPlayer, bool bPositive, int nNewScore, int nTeam, RDScoreMethod_t eMethod = SCORE_UNDEFINED );
	RDScoreMethod_t GetLastScoreMethod( int nTeam ) const { return (RDScoreMethod_t)m_eWinningMethod[ nTeam ]; }

#ifdef CLIENT_DLL

	virtual void OnDataChanged( DataUpdateType_t type ) OVERRIDE;
	virtual void ClientThink() OVERRIDE;
	const char* GetResFile() const { return STRING( m_szResFile ); }

#else
	DECLARE_DATADESC();

	virtual void Activate() OVERRIDE;
	virtual void FireGameEvent( IGameEvent * event ) OVERRIDE;

	virtual int UpdateTransmitState() OVERRIDE { return SetTransmitState( FL_EDICT_ALWAYS ); }

	CTFRobotDestruction_Robot * IterateRobots( CTFRobotDestruction_Robot * ) const;
	void	RobotCreated( CTFRobotDestruction_Robot *pRobot );
	void	RobotRemoved( CTFRobotDestruction_Robot *pRobot );
	void	RobotAttacked( CTFRobotDestruction_Robot *pRobot );
	float	GetScoringInterval() const { return m_flRobotScoreInterval; }
	void	ScorePoints( int nTeam, int nPoints, RDScoreMethod_t eMethod, CTFPlayer *pPlayer );
	void	AddRobotGroup( CTFRobotDestruction_RobotGroup* pGroup );
	void	ManageGameState();
	void	FlagCreated( int nTeam );
	void	FlagDestroyed( int nTeam );
	
	void	DBG_SetMaxPoints( int nNewMax ) { m_nMaxPoints.Set( nNewMax ); }
	void	InputRoundActivate( inputdata_t &inputdata );
	virtual int GetHealDistance( void ) { return 64; }
#endif

	virtual void SetCountdownEndTime( float flTime ){ m_flCountdownEndTime = flTime; }
	virtual float GetCountdownEndTime(){ return m_flCountdownEndTime; }
	virtual CTFPlayer *GetTeamLeader( int iTeam ) const { return NULL; }
	virtual string_t GetCountdownImage( void ) { return NULL_STRING; }
	virtual bool IsUsingCustomCountdownImage( void ) { return false; }

protected:


#ifdef GAME_DLL
	virtual void OnRedScoreChanged() {}
	virtual void OnBlueScoreChanged() {}
	void	ApproachTargetScoresThink();
	int		ApproachTeamTargetScore( int nTeam, int nApproachScore, int nCurrentScore );
	void	PlaySoundInPlayersEars( CTFPlayer* pPlayer, const EmitSound_t& params ) const;
	void	RedTeamWin();
	void	BlueTeamWin();
	virtual void	TeamWin( int nTeam );

	typedef CUtlMap< int, CTFRobotDestruction_RobotGroup* > RobotSpawnMap_t;
	CUtlVector< CTFRobotDestruction_Robot* > m_vecRobots;
	CUtlVector< CTFRobotDestruction_RobotGroup * > m_vecSpawnGroups;
	float m_flLoserRespawnBonusPerBot;
	float m_flRobotScoreInterval;
	float m_flNextRedRobotAttackedAlertTime;
	float m_flNextBlueRobotAttackedAlertTime;
	int m_nNumFlagsOut[ TF_TEAM_COUNT ];
	bool m_bEducateNewConnectors;
	string_t m_iszResFile;

	TeamSound_t m_AnnouncerProgressSound;
	CUtlMap< const char *, RateLimitedSound_t * > m_mapRateLimitedSounds;

	CUtlVector< CTFPlayer* > m_vecEducatedPlayers;

	// Outputs
	COutputEvent m_OnRedFinalePeriodEnd;
	COutputEvent m_OnBlueFinalePeriodEnd;
	COutputEvent m_OnBlueHitZeroPoints;
	COutputEvent m_OnRedHitZeroPoints;
	COutputEvent m_OnBlueHasPoints;
	COutputEvent m_OnRedHasPoints;
	COutputEvent m_OnBlueHitMaxPoints;
	COutputEvent m_OnRedHitMaxPoints;
	COutputEvent m_OnBlueLeaveMaxPoints;
	COutputEvent m_OnRedLeaveMaxPoints;

	COutputEvent m_OnRedFirstFlagStolen;
	COutputEvent m_OnRedFlagStolen;
	COutputEvent m_OnRedLastFlagReturned;
	COutputEvent m_OnBlueFirstFlagStolen;
	COutputEvent m_OnBlueFlagStolen;
	COutputEvent m_OnBlueLastFlagReturned;
#else
	float		m_flLastTickSoundTime;
#endif
	static CTFRobotDestructionLogic* m_sCTFRobotDestructionLogic;
	CNetworkVar( int, m_nMaxPoints );
	CNetworkVar( float, m_flFinaleLength );
	CNetworkVar( float, m_flBlueFinaleEndTime );
	CNetworkVar( float, m_flRedFinaleEndTime );
	CNetworkVar( int, m_nBlueScore );
	CNetworkVar( int, m_nRedScore );
	CNetworkVar( int, m_nBlueTargetPoints );
	CNetworkVar( int, m_nRedTargetPoints );
	CNetworkVar( float, m_flBlueTeamRespawnScale );
	CNetworkVar( float, m_flRedTeamRespawnScale );
	CNetworkString( m_szResFile, MAX_PATH );
	CNetworkArray( int, m_eWinningMethod, TF_TEAM_COUNT );
	CNetworkVar( float, m_flCountdownEndTime ); // used for player destruction countdown timers
};

#ifdef GAME_DLL
class CRobotDestructionVaultTrigger : public CBaseTrigger
{
	DECLARE_CLASS( CRobotDestructionVaultTrigger, CBaseTrigger );
	DECLARE_DATADESC();

public:
	CRobotDestructionVaultTrigger();
	virtual void Spawn() OVERRIDE;
	virtual void Precache() OVERRIDE;

	virtual bool PassesTriggerFilters( CBaseEntity *pOther ) OVERRIDE;
	virtual void StartTouch(CBaseEntity *pOther) OVERRIDE;
	virtual void EndTouch(CBaseEntity *pOther) OVERRIDE;

private:
	void StealPointsThink();
	int StealPoints( CTFPlayer *pPlayer );

	bool m_bIsStealing;
	COutputEvent m_OnPointsStolen;
	COutputEvent m_OnPointsStartStealing;
	COutputEvent m_OnPointsEndStealing;
};

#endif// GAME_DLL
#endif// LOGIC_ROBOT_DESTRUCTION_H