summaryrefslogtreecommitdiff
path: root/game/client/tf/c_baseobject.h
blob: ab12f8f4e8eaadba025627de01603df9f844f25a (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Clients CBaseObject
//
// $NoKeywords: $
//=============================================================================//

#ifndef C_BASEOBJECT_H
#define C_BASEOBJECT_H
#ifdef _WIN32
#pragma once
#endif

#include "baseobject_shared.h"
#include <vgui_controls/Panel.h>
#include "particlemgr.h"
#include "particle_prototype.h"
#include "particle_util.h"
#include "c_basecombatcharacter.h"
#include "ihasbuildpoints.h"
#include <vgui/ILocalize.h>

class C_TFPlayer;

// Max Length of ID Strings
#define MAX_ID_STRING		256

extern mstudioevent_t *GetEventIndexForSequence( mstudioseqdesc_t &seqdesc );

DECLARE_AUTO_LIST( IBaseObjectAutoList );

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class C_BaseObject : public C_BaseCombatCharacter, public IHasBuildPoints, public ITargetIDProvidesHint, public IBaseObjectAutoList
{
	DECLARE_CLASS( C_BaseObject, C_BaseCombatCharacter );
public:
	DECLARE_CLIENTCLASS();

	C_BaseObject();
	~C_BaseObject( void );

	virtual void	Spawn( void );

	virtual bool	IsBaseObject( void ) const { return true; }
	virtual bool	IsAnUpgrade(void ) const { return false; }

	virtual void	SetType( int iObjectType );

	virtual void	AddEntity();
	virtual void	Select( void );

	void			SetActivity( Activity act );
	Activity		GetActivity( ) const;
	void			SetObjectSequence( int sequence );
	virtual void	ResetClientsideFrame( void );

	virtual void	PreDataUpdate( DataUpdateType_t updateType );
	virtual void	OnDataChanged( DataUpdateType_t updateType );

	virtual int		GetHealth() const { return m_iHealth; }
	void			SetHealth( int health ) { m_iHealth = health; }
	virtual int		GetMaxHealth() const { return m_iMaxHealth; }
	int				GetObjectFlags( void ) { return m_fObjectFlags; }
	void			SetObjectFlags( int flags ) { m_fObjectFlags = flags; }

	// Derive to customize an object's attached version
	virtual	void	SetupAttachedVersion( void ) { return; }

	virtual const char	*GetTargetDescription( void ) const;
	virtual const char	*GetIDString( void );
	virtual bool	IsValidIDTarget( void );

	virtual void	GetTargetIDString( OUT_Z_BYTECAP(iMaxLenInBytes) wchar_t *sIDString, int iMaxLenInBytes, bool bSpectator );
	virtual void	GetTargetIDDataString( OUT_Z_BYTECAP(iMaxLenInBytes) wchar_t *sDataString, int iMaxLenInBytes );

	virtual bool	ShouldBeActive( void );
	virtual void	OnGoActive( void );
	virtual void	OnGoInactive( void );

	virtual void	UpdateOnRemove( void );

	C_TFPlayer		*GetBuilder( void ) { return m_hBuilder; }

	virtual void	SetDormant( bool bDormant );

	void			SendClientCommand( const char *pCmd );

	virtual void FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );

	// Builder preview...
	void			ActivateYawPreview( bool enable );
	void			PreviewYaw( float yaw );
	bool			IsPreviewingYaw() const;
	
	virtual void	RecalculateIDString( void );

	int GetType() const { return m_iObjectType; }
	bool IsOwnedByLocalPlayer() const;
	C_TFPlayer *GetOwner();

	virtual void	Simulate();

	virtual int		DrawModel( int flags );

	float			GetPercentageConstructed( void ) { return m_flPercentageConstructed; }

	bool			IsPlacing( void ) const { return m_bPlacing; }
	bool			IsBuilding( void ) const { return m_bBuilding; }
	virtual bool	IsUpgrading( void ) const { return false; }
	bool			IsCarried( void ) const { return m_bCarried; }

	float			GetReversesBuildingConstructionSpeed( void );

	virtual void	FinishedBuilding( void ) { return; }

	virtual const char* GetStatusName() const;

	// Object Previews
	void			HighlightBuildPoints( int flags );

	bool			HasSapper( void );

	bool			IsPlasmaDisabled( void );

	virtual void	OnStartDisabled( void );
	virtual void	OnEndDisabled( void );

	virtual bool	ShouldCollide( int collisionGroup, int contentsMask ) const;
	virtual bool	ShouldPlayersAvoid( void );

	bool			MustBeBuiltOnAttachmentPoint( void ) const;

	virtual bool	IsHostileUpgrade( void ) { return false; }

	// For ordering in hud building status
	virtual int		GetDisplayPriority( void );

	virtual const char *GetHudStatusIcon( void );

	virtual BuildingHudAlert_t GetBuildingAlertLevel( void );

	// Upgrading
	virtual int		GetUpgradeLevel( void ) { return m_iUpgradeLevel; }
	int				GetUpgradeMetal( void ) { return m_iUpgradeMetal; }
	virtual int		GetUpgradeMetalRequired( void ) { return m_iUpgradeMetalRequired; }
	virtual void	UpgradeLevelChanged() { return; }
	int				GetHighestUpgradeLevel( void ) { return m_iHighestUpgradeLevel; }

	int				GetObjectMode( void ) const { return m_iObjectMode; }

	// Shadows
	virtual ShadowType_t ShadowCastType( void ) OVERRIDE;

	// Stealth
	virtual float	GetInvisibilityLevel( void );
	virtual void	SetInvisibilityLevel( float flValue );
	bool			IsEnteringOrExitingFullyInvisible( float flValue ) { return ( ( m_flInvisibilityPercent != 1.f && flValue == 1.f ) || ( m_flInvisibilityPercent == 1.f && flValue != 1.f ) ); }

private:
	void StopAnimGeneratedSounds( void );

public:
	// Client/Server shared build point code
	void				CreateBuildPoints( void );
	void				AddAndParseBuildPoint( int iAttachmentNumber, KeyValues *pkvBuildPoint );
	virtual int			AddBuildPoint( int iAttachmentNum );
	virtual void		AddValidObjectToBuildPoint( int iPoint, int iObjectType );
	virtual CBaseObject *GetBuildPointObject( int iPoint );
	bool				IsBuiltOnAttachment( void ) { return m_hBuiltOnEntity.IsValid(); }
	void				AttachObjectToObject( CBaseEntity *pEntity, int iPoint, Vector &vecOrigin );
	CBaseObject			*GetParentObject( void );
	CBaseEntity			*GetParentEntity( void );
	void				SetBuildPointPassenger( int iPoint, int iPassenger );

	// Build points
	CUtlVector<BuildPoint_t>	m_BuildPoints;

	bool				IsDisabled( void ) { return m_bDisabled || m_bCarried; }

	// Shared placement
	bool 				VerifyCorner( const Vector &vBottomCenter, float xOffset, float yOffset );
	virtual bool		IsPlacementPosValid( void );
	virtual float		GetNearbyObjectCheckRadius( void ) { return 30.0; }

	virtual void		OnPlacementStateChanged( bool bValidPlacement );

	bool				ServerValidPlacement( void );		// allow server to trump our placement state

	bool				WasLastPlacementPosValid( void );	// query if we're in a valid place, when we last tried to calculate it

// IHasBuildPoints
public:
	virtual int			GetNumBuildPoints( void ) const;
	virtual bool		GetBuildPoint( int iPoint, Vector &vecOrigin, QAngle &vecAngles );
	virtual int			GetBuildPointAttachmentIndex( int iPoint ) const;
	virtual bool		CanBuildObjectOnBuildPoint( int iPoint, int iObjectType );
	virtual void		SetObjectOnBuildPoint( int iPoint, CBaseObject *pObject );
	virtual float		GetMaxSnapDistance( int iBuildPoint );
	virtual bool		ShouldCheckForMovement( void ) { return true; }
	virtual int			GetNumObjectsOnMe( void );
	virtual CBaseObject *GetObjectOfTypeOnMe( int iObjectType );
	virtual void		RemoveAllObjects( void );
	virtual int			FindObjectOnBuildPoint( CBaseObject *pObject );

	virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );

	bool				IsMiniBuilding() { return m_bMiniBuilding; }
	bool				IsDisposableBuilding( void ) const { return m_bDisposableBuilding; }

// ITargetIDProvidesHint
public:
	virtual void		DisplayHintTo( C_BasePlayer *pPlayer );

	virtual void		GetGlowEffectColor( float *r, float *g, float *b );

	bool				IsMapPlaced( void ){ return m_bWasMapPlaced; }

protected:
	virtual void		UpdateDamageEffects( BuildingDamageLevel_t damageLevel ) {}	// default is no effects

	void				UpdateDesiredBuildRotation( float flFrameTime );

	bool				CalculatePlacementPos( void );

protected:

	BuildingDamageLevel_t CalculateDamageLevel( void );

	char			m_szIDString[ MAX_ID_STRING ];

	BuildingDamageLevel_t m_damageLevel;

	Vector m_vecBuildOrigin;
	Vector m_vecBuildCenterOfMass;

	// Upgrading
	int				m_iUpgradeLevel;
	int				m_iOldUpgradeLevel;
	int				m_iUpgradeMetal;
	int				m_iHighestUpgradeLevel;
	int				m_iUpgradeMetalRequired;

	HPARTICLEFFECT	m_hDamageEffects;

private:
	enum
	{
		YAW_PREVIEW_OFF	= 0,
		YAW_PREVIEW_ON,
		YAW_PREVIEW_WAITING_FOR_UPDATE
	};

	Activity		m_Activity;

	int				m_fObjectFlags;
	float			m_fYawPreview;
	char			m_YawPreviewState;
	CHandle< C_TFPlayer > m_hOldOwner;
	CHandle< C_TFPlayer > m_hBuilder;
	bool			m_bWasActive;
	int				m_iOldHealth;
	bool			m_bHasSapper;
	bool			m_bOldSapper;
	int				m_iObjectType;
	int				m_iHealth;
	int				m_iMaxHealth;
	bool			m_bWasBuilding;
	bool			m_bBuilding;
	bool			m_bWasPlacing;
	bool			m_bPlacing;
	bool			m_bDisabled;
	bool			m_bOldDisabled;
	bool			m_bCarried;
	bool			m_bCarryDeploy;
	bool			m_bOldCarryDeploy;
	bool			m_bMiniBuilding;
	bool			m_bDisposableBuilding;
	float			m_flPercentageConstructed;
	EHANDLE			m_hBuiltOnEntity;
	int				m_iObjectMode;
	bool			m_bPlasmaDisable;

	CNetworkVector( m_vecBuildMaxs );
	CNetworkVector( m_vecBuildMins );

	CNetworkVar( int, m_iDesiredBuildRotations );
	float m_flCurrentBuildRotation;

	int m_iLastPlacementPosValid;	// -1 - init, 0 - invalid, 1 - valid

	CNetworkVar( bool, m_bServerOverridePlacement );

	int m_nObjectOldSequence;

	// used when calculating the placement position
	Vector	m_vecBuildForward;
	float	m_flBuildDistance;

	// Stealth
	float			m_flInvisibilityPercent;
	float			m_flPrevInvisibilityPercent;

	CNetworkVar( bool, m_bWasMapPlaced );

private:
	C_BaseObject( const C_BaseObject & ); // not defined, not accessible
};

#endif // C_BASEOBJECT_H