summaryrefslogtreecommitdiff
path: root/game/shared/econ/econ_entity.h
blob: e0c2453deaf1ebc6d2c6e5286aeb11c3c8e48b84 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

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

#include "ihasattributes.h"
#include "ihasowner.h"
#include "attribute_manager.h"
#include "econ_item_view.h"

#if defined( CLIENT_DLL )
#define CEconEntity				C_EconEntity
#define CBaseAttributableItem	C_BaseAttributableItem

// Additional attachments.
struct AttachedModelData_t
{
	const model_t *m_pModel;
	int m_iModelDisplayFlags;
};

#endif


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CEconEntity : public CBaseAnimating, public IHasAttributes
{
	DECLARE_CLASS( CEconEntity, CBaseAnimating );
public:
	DECLARE_NETWORKCLASS();
	DECLARE_DATADESC();
	CEconEntity();
	~CEconEntity();

	void					InitializeAttributes( void );
	void					DebugDescribe( void );
	Activity				TranslateViewmodelHandActivity( Activity actBase );
	virtual void			UpdateOnRemove( void );

	virtual CStudioHdr *	OnNewModel();

#if !defined( CLIENT_DLL )
	virtual void 			GiveTo( CBaseEntity *pOther ) {}
	void					OnOwnerClassChange( void );
	void					UpdateModelToClass( void );
	void					PlayAnimForPlaybackEvent( wearableanimplayback_t iPlayback );
	virtual int				CalculateVisibleClassFor( CBaseCombatCharacter *pPlayer );

#if defined(TF_DLL) || defined(TF_CLIENT_DLL)
	void					MarkAttachedEntityAsValidated() { m_bValidatedAttachedEntity = true; }
#endif // TF_DLL || TF_CLIENT_DLL

#else
	enum ParticleSystemState_t
	{
		PARTICLE_SYSTEM_STATE_NOT_VISIBLE, 
		PARTICLE_SYSTEM_STATE_VISIBLE,
		PARTICLE_SYSTEM_STATE_VISIBLE_VM
	};

	virtual void			Release();
	virtual void			SetDormant( bool bDormant );
	virtual void			OnPreDataChanged( DataUpdateType_t type );
	virtual void			OnDataChanged( DataUpdateType_t updateType );
	virtual bool			ShouldShowToolTip( void	) { return true; }
	virtual bool			InitializeAsClientEntity( const char *pszModelName, RenderGroup_t renderGroup );
	virtual bool			OnInternalDrawModel( ClientModelRenderInfo_t *pInfo );
	virtual IMaterial		*GetEconWeaponMaterialOverride( int iTeam ) OVERRIDE;
	virtual void			FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
	virtual bool			OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options );
	bool					InternalFireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );

	// Custom flex controllers
	virtual bool			UsesFlexDelayedWeights( void );
	virtual	void			SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights );
	float					m_flFlexDelayTime;
	float *					m_flFlexDelayedWeight;
	int						m_cFlexDelayedWeight;

	// Custom particle attachments
	bool					HasCustomParticleSystems( void ) const;
	void					UpdateParticleSystems( void );
	virtual bool			ShouldDrawParticleSystems( void );
	void					SetParticleSystemsVisible( ParticleSystemState_t bVisible );
	void					UpdateSingleParticleSystem( bool bVisible, const attachedparticlesystem_t *pSystem );
	virtual void			UpdateAttachmentModels( void );
	virtual bool			AttachmentModelsShouldBeVisible( void ) { return true; }
	void					GetEconParticleSystems( CUtlVector<const attachedparticlesystem_t *> *out_pvecParticleSystems ) const;

	// Model swaping
	bool					ShouldDraw( void );
	bool					ShouldHideForVisionFilterFlags( void );

	virtual bool			IsTransparent( void ) OVERRIDE;

	// Viewmodel overriding
	virtual bool			ViewModel_IsTransparent( void );
	virtual bool			ViewModel_IsUsingFBTexture( void );
	virtual bool			IsOverridingViewmodel( void );
	virtual int				DrawOverriddenViewmodel( C_BaseViewModel *pViewmodel, int flags );

	// Attachments
	bool					WantsToOverrideViewmodelAttachments( void ) { return (m_hViewmodelAttachment != NULL); }
	virtual int				LookupAttachment( const char *pAttachmentName );
	virtual bool			GetAttachment( const char *szName, Vector &absOrigin ) { return BaseClass::GetAttachment(szName,absOrigin); }
	virtual bool			GetAttachment( const char *szName, Vector &absOrigin, QAngle &absAngles ) { return BaseClass::GetAttachment(szName,absOrigin,absAngles); }
	virtual bool			GetAttachment( int number, matrix3x4_t &matrix );
	virtual bool			GetAttachment( int number, Vector &origin );
	virtual	bool			GetAttachment( int number, Vector &origin, QAngle &angles );
	virtual bool			GetAttachmentVelocity( int number, Vector &originVel, Quaternion &angleVel );

	C_BaseAnimating			*GetViewmodelAttachment( void ) { return m_hViewmodelAttachment.Get(); }
	virtual void			ViewModelAttachmentBlending( CStudioHdr *hdr, Vector pos[], Quaternion q[], float currentTime, int boneMask ) {}

	void					SetWaitingToLoad( bool bWaiting );

	virtual bool			ValidateEntityAttachedToPlayer( bool &bShouldRetry );

	virtual void			SetMaterialOverride( int team, const char *pszMaterial );
	virtual void			SetMaterialOverride( int team, CMaterialReference &ref );

	// Deal with recording
	virtual void GetToolRecordingState( KeyValues *msg );

#endif

public:
	// IHasAttributes
	CAttributeManager			*GetAttributeManager( void ) { return &m_AttributeManager; }
	CAttributeContainer			*GetAttributeContainer( void ) { return &m_AttributeManager; }
	const CAttributeContainer	*GetAttributeContainer( void ) const { return &m_AttributeManager; }
	CBaseEntity					*GetAttributeOwner( void ) { return GetOwnerEntity(); }
	CAttributeList				*GetAttributeList( void ) { return m_AttributeManager.GetItem()->GetAttributeList(); }
	virtual void				ReapplyProvision( void );

	virtual bool			UpdateBodygroups( CBaseCombatCharacter* pOwner, int iState );

protected:
	virtual Activity		TranslateViewmodelHandActivityInternal( Activity actBase ) { return actBase; }
	
protected:
	CNetworkVarEmbedded(	CAttributeContainer, m_AttributeManager );

#if defined(TF_DLL) || defined(TF_CLIENT_DLL)
	CNetworkVar( bool, m_bValidatedAttachedEntity );
#endif // TF_DLL || TF_CLIENT_DLL

#ifdef CLIENT_DLL
	bool					m_bClientside;
	ParticleSystemState_t		m_nParticleSystemsCreated;
	CMaterialReference		m_MaterialOverrides[TEAM_VISUAL_SECTIONS];
	CHandle<C_BaseAnimating>	m_hViewmodelAttachment;
	int						m_iOldTeam;
	bool					m_bAttachmentDirty;
	int						m_nUnloadedModelIndex;
	int						m_iNumOwnerValidationRetries;
#endif

	bool					m_bHasParticleSystems;
	EHANDLE					m_hOldProvidee;

#ifdef GAME_DLL
	int						m_iOldOwnerClass; // Used to detect class changes on items that have per-class models
#endif

protected:
#ifdef CLIENT_DLL

public:

	CUtlVector<AttachedModelData_t> m_vecAttachedModels;

#endif // CLIENT_DLL
};

#define ITEM_PICKUP_BOX_BLOAT		24

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CBaseAttributableItem : public CEconEntity
{
	DECLARE_CLASS( CBaseAttributableItem, CEconEntity );
public:
	DECLARE_NETWORKCLASS();
	DECLARE_DATADESC();

	CBaseAttributableItem();
};

#if defined( CLIENT_DLL )
#ifndef DOTA_DLL
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class C_ViewmodelAttachmentModel : public C_BaseAnimating, public IHasOwner
{
	DECLARE_CLASS( C_ViewmodelAttachmentModel, C_BaseAnimating );
public:
	void SetOuter( CEconEntity *pOuter );
	CHandle<CEconEntity> GetOuter( void ) { return m_hOuter; }
	bool InitializeAsClientEntity( const char *pszModelName, RenderGroup_t renderGroup );
	int  InternalDrawModel( int flags );
	bool OnPostInternalDrawModel( ClientModelRenderInfo_t *pInfo );
	virtual void StandardBlendingRules( CStudioHdr *hdr, Vector pos[], Quaternion q[], float currentTime, int boneMask );
	
	virtual CBaseEntity	*GetOwnerViaInterface( void ) { return GetOuter()->GetAttributeOwner(); }

	virtual void FormatViewModelAttachment( int nAttachment, matrix3x4_t &attachmentToWorld );

	virtual int GetSkin( void );

private:
	CHandle<CEconEntity>  m_hOuter;
	bool							m_bAlwaysFlip;
};
#endif // !defined( DOTA_DLL )
#endif // defined( CLIENT_DLL )

#endif // ECON_ENTITY_H