Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
8.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef ECON_ENTITY_H
  7. #define ECON_ENTITY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "ihasattributes.h"
  12. #include "ihasowner.h"
  13. #include "attribute_manager.h"
  14. #include "econ_item_view.h"
  15. #if defined( CLIENT_DLL )
  16. #define CEconEntity C_EconEntity
  17. #define CBaseAttributableItem C_BaseAttributableItem
  18. // Additional attachments.
  19. struct AttachedModelData_t
  20. {
  21. const model_t *m_pModel;
  22. int m_iModelDisplayFlags;
  23. };
  24. #endif
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. class CEconEntity : public CBaseAnimating, public IHasAttributes
  29. {
  30. DECLARE_CLASS( CEconEntity, CBaseAnimating );
  31. public:
  32. DECLARE_NETWORKCLASS();
  33. DECLARE_DATADESC();
  34. CEconEntity();
  35. ~CEconEntity();
  36. void InitializeAttributes( void );
  37. void DebugDescribe( void );
  38. Activity TranslateViewmodelHandActivity( Activity actBase );
  39. virtual void UpdateOnRemove( void );
  40. virtual CStudioHdr * OnNewModel();
  41. #if !defined( CLIENT_DLL )
  42. virtual void GiveTo( CBaseEntity *pOther ) {}
  43. void OnOwnerClassChange( void );
  44. void UpdateModelToClass( void );
  45. void PlayAnimForPlaybackEvent( wearableanimplayback_t iPlayback );
  46. virtual int CalculateVisibleClassFor( CBaseCombatCharacter *pPlayer );
  47. #if defined(TF_DLL) || defined(TF_CLIENT_DLL)
  48. void MarkAttachedEntityAsValidated() { m_bValidatedAttachedEntity = true; }
  49. #endif // TF_DLL || TF_CLIENT_DLL
  50. #else
  51. enum ParticleSystemState_t
  52. {
  53. PARTICLE_SYSTEM_STATE_NOT_VISIBLE,
  54. PARTICLE_SYSTEM_STATE_VISIBLE,
  55. PARTICLE_SYSTEM_STATE_VISIBLE_VM
  56. };
  57. virtual void Release();
  58. virtual void SetDormant( bool bDormant );
  59. virtual void OnPreDataChanged( DataUpdateType_t type );
  60. virtual void OnDataChanged( DataUpdateType_t updateType );
  61. virtual bool ShouldShowToolTip( void ) { return true; }
  62. virtual bool InitializeAsClientEntity( const char *pszModelName, RenderGroup_t renderGroup );
  63. virtual bool OnInternalDrawModel( ClientModelRenderInfo_t *pInfo );
  64. virtual IMaterial *GetEconWeaponMaterialOverride( int iTeam ) OVERRIDE;
  65. virtual void FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  66. virtual bool OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options );
  67. bool InternalFireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  68. // Custom flex controllers
  69. virtual bool UsesFlexDelayedWeights( void );
  70. virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights );
  71. float m_flFlexDelayTime;
  72. float * m_flFlexDelayedWeight;
  73. int m_cFlexDelayedWeight;
  74. // Custom particle attachments
  75. bool HasCustomParticleSystems( void ) const;
  76. void UpdateParticleSystems( void );
  77. virtual bool ShouldDrawParticleSystems( void );
  78. void SetParticleSystemsVisible( ParticleSystemState_t bVisible );
  79. void UpdateSingleParticleSystem( bool bVisible, const attachedparticlesystem_t *pSystem );
  80. virtual void UpdateAttachmentModels( void );
  81. virtual bool AttachmentModelsShouldBeVisible( void ) { return true; }
  82. void GetEconParticleSystems( CUtlVector<const attachedparticlesystem_t *> *out_pvecParticleSystems ) const;
  83. // Model swaping
  84. bool ShouldDraw( void );
  85. bool ShouldHideForVisionFilterFlags( void );
  86. virtual bool IsTransparent( void ) OVERRIDE;
  87. // Viewmodel overriding
  88. virtual bool ViewModel_IsTransparent( void );
  89. virtual bool ViewModel_IsUsingFBTexture( void );
  90. virtual bool IsOverridingViewmodel( void );
  91. virtual int DrawOverriddenViewmodel( C_BaseViewModel *pViewmodel, int flags );
  92. // Attachments
  93. bool WantsToOverrideViewmodelAttachments( void ) { return (m_hViewmodelAttachment != NULL); }
  94. virtual int LookupAttachment( const char *pAttachmentName );
  95. virtual bool GetAttachment( const char *szName, Vector &absOrigin ) { return BaseClass::GetAttachment(szName,absOrigin); }
  96. virtual bool GetAttachment( const char *szName, Vector &absOrigin, QAngle &absAngles ) { return BaseClass::GetAttachment(szName,absOrigin,absAngles); }
  97. virtual bool GetAttachment( int number, matrix3x4_t &matrix );
  98. virtual bool GetAttachment( int number, Vector &origin );
  99. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles );
  100. virtual bool GetAttachmentVelocity( int number, Vector &originVel, Quaternion &angleVel );
  101. C_BaseAnimating *GetViewmodelAttachment( void ) { return m_hViewmodelAttachment.Get(); }
  102. virtual void ViewModelAttachmentBlending( CStudioHdr *hdr, Vector pos[], Quaternion q[], float currentTime, int boneMask ) {}
  103. void SetWaitingToLoad( bool bWaiting );
  104. virtual bool ValidateEntityAttachedToPlayer( bool &bShouldRetry );
  105. virtual void SetMaterialOverride( int team, const char *pszMaterial );
  106. virtual void SetMaterialOverride( int team, CMaterialReference &ref );
  107. // Deal with recording
  108. virtual void GetToolRecordingState( KeyValues *msg );
  109. #endif
  110. public:
  111. // IHasAttributes
  112. CAttributeManager *GetAttributeManager( void ) { return &m_AttributeManager; }
  113. CAttributeContainer *GetAttributeContainer( void ) { return &m_AttributeManager; }
  114. const CAttributeContainer *GetAttributeContainer( void ) const { return &m_AttributeManager; }
  115. CBaseEntity *GetAttributeOwner( void ) { return GetOwnerEntity(); }
  116. CAttributeList *GetAttributeList( void ) { return m_AttributeManager.GetItem()->GetAttributeList(); }
  117. virtual void ReapplyProvision( void );
  118. virtual bool UpdateBodygroups( CBaseCombatCharacter* pOwner, int iState );
  119. protected:
  120. virtual Activity TranslateViewmodelHandActivityInternal( Activity actBase ) { return actBase; }
  121. protected:
  122. CNetworkVarEmbedded( CAttributeContainer, m_AttributeManager );
  123. #if defined(TF_DLL) || defined(TF_CLIENT_DLL)
  124. CNetworkVar( bool, m_bValidatedAttachedEntity );
  125. #endif // TF_DLL || TF_CLIENT_DLL
  126. #ifdef CLIENT_DLL
  127. bool m_bClientside;
  128. ParticleSystemState_t m_nParticleSystemsCreated;
  129. CMaterialReference m_MaterialOverrides[TEAM_VISUAL_SECTIONS];
  130. CHandle<C_BaseAnimating> m_hViewmodelAttachment;
  131. int m_iOldTeam;
  132. bool m_bAttachmentDirty;
  133. int m_nUnloadedModelIndex;
  134. int m_iNumOwnerValidationRetries;
  135. #endif
  136. bool m_bHasParticleSystems;
  137. EHANDLE m_hOldProvidee;
  138. #ifdef GAME_DLL
  139. int m_iOldOwnerClass; // Used to detect class changes on items that have per-class models
  140. #endif
  141. protected:
  142. #ifdef CLIENT_DLL
  143. public:
  144. CUtlVector<AttachedModelData_t> m_vecAttachedModels;
  145. #endif // CLIENT_DLL
  146. };
  147. #define ITEM_PICKUP_BOX_BLOAT 24
  148. //-----------------------------------------------------------------------------
  149. // Purpose:
  150. //-----------------------------------------------------------------------------
  151. class CBaseAttributableItem : public CEconEntity
  152. {
  153. DECLARE_CLASS( CBaseAttributableItem, CEconEntity );
  154. public:
  155. DECLARE_NETWORKCLASS();
  156. DECLARE_DATADESC();
  157. CBaseAttributableItem();
  158. };
  159. #if defined( CLIENT_DLL )
  160. #ifndef DOTA_DLL
  161. //-----------------------------------------------------------------------------
  162. // Purpose:
  163. //-----------------------------------------------------------------------------
  164. class C_ViewmodelAttachmentModel : public C_BaseAnimating, public IHasOwner
  165. {
  166. DECLARE_CLASS( C_ViewmodelAttachmentModel, C_BaseAnimating );
  167. public:
  168. void SetOuter( CEconEntity *pOuter );
  169. CHandle<CEconEntity> GetOuter( void ) { return m_hOuter; }
  170. bool InitializeAsClientEntity( const char *pszModelName, RenderGroup_t renderGroup );
  171. int InternalDrawModel( int flags );
  172. bool OnPostInternalDrawModel( ClientModelRenderInfo_t *pInfo );
  173. virtual void StandardBlendingRules( CStudioHdr *hdr, Vector pos[], Quaternion q[], float currentTime, int boneMask );
  174. virtual CBaseEntity *GetOwnerViaInterface( void ) { return GetOuter()->GetAttributeOwner(); }
  175. virtual void FormatViewModelAttachment( int nAttachment, matrix3x4_t &attachmentToWorld );
  176. virtual int GetSkin( void );
  177. private:
  178. CHandle<CEconEntity> m_hOuter;
  179. bool m_bAlwaysFlip;
  180. };
  181. #endif // !defined( DOTA_DLL )
  182. #endif // defined( CLIENT_DLL )
  183. #endif // ECON_ENTITY_H