summaryrefslogtreecommitdiff
path: root/game/server/dod/dod_bombtarget.h
blob: 316ca80cfb7dc1b021d9e9f099b69db4fcbd1586 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef DOD_BOMBTARGET_H
#define DOD_BOMBTARGET_H

#ifdef _WIN32
#pragma once
#endif

#include "baseanimating.h"
#include "dod_control_point.h"

#define DOD_BOMB_TARGET_MODEL_ARMED			"models/weapons/w_tnt.mdl"
#define DOD_BOMB_TARGET_MODEL_TARGET		"models/weapons/w_tnt_red.mdl"
#define DOD_BOMB_TARGET_MODEL_UNAVAILABLE	"models/weapons/w_tnt_grey.mdl"

class CDODBombTarget;

class CDODBombTargetStateInfo
{
public:
	BombTargetState m_iState;
	const char *m_pStateName;

	void (CDODBombTarget::*pfnEnterState)();	// Init and deinit the state.
	void (CDODBombTarget::*pfnLeaveState)();
	void (CDODBombTarget::*pfnThink)();	// Do a PreThink() in this state.
	void (CDODBombTarget::*pfnUse)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
};


struct DefusingPlayer 
{
	CHandle<CDODPlayer> m_pPlayer;

	float m_flDefuseTimeoutTime;
	float m_flDefuseCompleteTime;
};

class CDODBombTarget : public CBaseAnimating
{
public:
	DECLARE_CLASS( CDODBombTarget, CBaseAnimating );
	DECLARE_DATADESC();

	DECLARE_NETWORKCLASS();

	CDODBombTarget() {}

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

	// Set these flags so players can use the bomb target ( for planting or defusing )
	virtual int	ObjectCaps( void );

	// Inputs
	void InputEnable( inputdata_t &inputdata );
	void InputDisable( inputdata_t &inputdata );

	// State Functions
	void State_Transition( BombTargetState newState );
	void State_Enter( BombTargetState newState );
	void State_Leave();
	void State_Think();
	void State_Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );

	int State_Get( void ) { return m_iState; }

	CDODBombTargetStateInfo* State_LookupInfo( BombTargetState state );

	// Enter
	void State_Enter_INACTIVE( void );
	void State_Enter_ACTIVE( void );
	void State_Enter_ARMED( void );

	// Leave
	void State_Leave_Armed( void );

	// Think
	void State_Think_ARMED( void );

	// Use
	void State_Use_ACTIVE( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
	void State_Use_ARMED( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );

	float GetBombTimerLength( void );

	// Get the dod_control_point that we're linked to
	CControlPoint *GetControlPoint( void );

	bool CanPlantHere( CDODPlayer *pPlayer );
	void CompletePlanting( CDODPlayer *pPlantingPlayer );

	void DefuseBlocked( CDODPlayer *pAttacker );
	void PlantBlocked( CDODPlayer *pAttacker );

	int GetTimerAddSeconds( void ) { return m_iTimerAddSeconds; }

	int GetBombingTeam( void ) { return m_iBombingTeam; }

	DefusingPlayer *FindDefusingPlayer( CDODPlayer *pPlayer );
	void Explode( void );
	void BombDefused( CDODPlayer *pDefuser );
	void ResetDefuse( int index );

	bool CanPlayerStartDefuse( CDODPlayer *pPlayer );
	bool CanPlayerContinueDefusing( CDODPlayer *pPlayer, DefusingPlayer *pDefuseRecord );
private:

	// Control Point we're linked to
	string_t m_iszCapPointName;
	CControlPoint	*m_pControlPoint;

	// Outputs
	COutputEvent	m_OnBecomeActive;
	COutputEvent	m_OnBecomeInactive;
	COutputEvent	m_OnBombPlanted;
	COutputEvent	m_OnBombExploded;
	COutputEvent	m_OnBombDisarmed;

	// state
	CNetworkVar( int, m_iState );
	CDODBombTargetStateInfo *m_pCurStateInfo;
	bool m_bStartDisabled;

	// timers for armed state
	float m_flExplodeTime;
	float m_flNextAnnounce;

	// player that planted this bomb
	CHandle<CDODPlayer> m_pPlantingPlayer;

	// The team that is allowed to plant bombs here
	CNetworkVar( int, m_iBombingTeam );

	// network the model indices of active bomb so we can change per-team
	CNetworkVar( int, m_iTargetModel );
	CNetworkVar( int, m_iUnavailableModel );

	int m_iTimerAddSeconds;

	// List of defusing players and time until completion
	CUtlVector< DefusingPlayer > m_DefusingPlayers;

private:
	CDODBombTarget( const CDODBombTarget & );
};

#endif //DOD_BOMBTARGET_H