Counter Strike : Global Offensive Source Code
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.

304 lines
9.8 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef BASEVIEWMODEL_SHARED_H
  8. #define BASEVIEWMODEL_SHARED_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "predictable_entity.h"
  13. #include "utlvector.h"
  14. #include "baseplayer_shared.h"
  15. #include "shared_classnames.h"
  16. #include "ihasowner.h"
  17. #ifdef CSTRIKE15
  18. #include "cs_shareddefs.h"
  19. #endif
  20. class CBaseCombatWeapon;
  21. class CBaseCombatCharacter;
  22. class CVGuiScreen;
  23. #if defined( CLIENT_DLL )
  24. class C_ViewmodelAttachmentModel;
  25. class C_CSPlayer;
  26. #define CBaseViewModel C_BaseViewModel
  27. #undef CBaseCombatWeapon
  28. #define CBaseCombatWeapon C_BaseCombatWeapon
  29. #define NUM_UID_CHARS 20
  30. class C_BaseViewModel;
  31. //--------------------------------------------------------------------------------------------------------
  32. class C_ViewmodelAttachmentModel : public C_BaseAnimating
  33. {
  34. DECLARE_CLASS( C_ViewmodelAttachmentModel, C_BaseAnimating );
  35. public:
  36. bool InitializeAsClientEntity( const char *pszModelName, bool bRenderWithViewModels );
  37. void SetViewmodel( C_BaseViewModel *pVM );
  38. virtual int InternalDrawModel( int flags, const RenderableInstance_t &instance );
  39. private:
  40. CHandle< C_BaseViewModel > m_hViewmodel;
  41. };
  42. #endif
  43. #define VIEWMODEL_INDEX_BITS 1
  44. class CBaseViewModel : public CBaseAnimating, public IHasOwner
  45. {
  46. DECLARE_CLASS( CBaseViewModel, CBaseAnimating );
  47. public:
  48. DECLARE_NETWORKCLASS();
  49. DECLARE_PREDICTABLE();
  50. #if !defined( CLIENT_DLL )
  51. DECLARE_DATADESC();
  52. #endif
  53. CBaseViewModel( void );
  54. ~CBaseViewModel( void );
  55. bool IsViewable(void) { return false; }
  56. virtual void UpdateOnRemove( void );
  57. // Weapon client handling
  58. virtual void SendViewModelMatchingSequence( int sequence );
  59. virtual void SetWeaponModel( const char *pszModelname, CBaseCombatWeapon *weapon );
  60. virtual void CalcViewModelLag( Vector& origin, QAngle& angles, QAngle& original_angles );
  61. virtual void CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition,
  62. const QAngle& eyeAngles );
  63. virtual void AddViewModelBob( CBasePlayer *owner, Vector& eyePosition, QAngle& eyeAngles ) {};
  64. void CalcViewModelUnzoom( CBasePlayer *owner, Vector& origin, QAngle& angles );
  65. // Initializes the viewmodel for use
  66. void SetOwner( CBaseEntity *pEntity );
  67. void SetIndex( int nIndex );
  68. // Returns which viewmodel it is
  69. int ViewModelIndex( ) const;
  70. virtual void Precache( void );
  71. virtual void Spawn( void );
  72. virtual CBaseEntity *GetOwner( void ) { return m_hOwner; };
  73. virtual void AddEffects( int nEffects );
  74. virtual void RemoveEffects( int nEffects );
  75. void SpawnControlPanels();
  76. void DestroyControlPanels();
  77. void SetControlPanelsActive( bool bState );
  78. void ShowControlPanells( bool show );
  79. virtual CBaseCombatWeapon *GetOwningWeapon( void );
  80. virtual CBaseEntity *GetOwnerViaInterface( void ) { return GetOwner(); }
  81. virtual bool IsSelfAnimating()
  82. {
  83. return true;
  84. }
  85. Vector m_vecLastFacing;
  86. virtual bool IsViewModel() const { return true; }
  87. virtual bool IsViewModelOrAttachment() const { return true; }
  88. void UpdateAllViewmodelAddons( void );
  89. #if defined ( CLIENT_DLL )
  90. C_ViewmodelAttachmentModel *AddViewmodelArmModel( const char *pszModel, int nSkintoneIndex = -1 );
  91. C_ViewmodelAttachmentModel* FindArmModelForLoadoutPosition( loadout_positions_t nPosition ) const;
  92. #endif
  93. void AddViewmodelLabel( CEconItemView *pItem );
  94. void AddViewmodelStatTrak( CEconItemView *pItem, int nStatTrakType, int nWeaponID, AccountID_t holderAcctId );
  95. void AddViewmodelStickers( CEconItemView *pItem, int nWeaponID );
  96. bool ViewmodelStickersAreValid( int nWeaponID );
  97. void RemoveViewmodelArmModels( void );
  98. void RemoveViewmodelLabel( void );
  99. void RemoveViewmodelStatTrak( void );
  100. void RemoveViewmodelStickers( void );
  101. CNetworkVar(bool, m_bShouldIgnoreOffsetAndAccuracy );
  102. virtual void SetShouldIgnoreOffsetAndAccuracy( bool bIgnore ) { m_bShouldIgnoreOffsetAndAccuracy = bIgnore; }
  103. #if !defined( CLIENT_DLL )
  104. virtual int UpdateTransmitState( void );
  105. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  106. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  107. #else
  108. virtual void FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  109. virtual void OnDataChanged( DataUpdateType_t updateType );
  110. virtual void PostDataUpdate( DataUpdateType_t updateType );
  111. virtual C_BasePlayer *GetPredictionOwner( void );
  112. virtual bool Interpolate( float currentTime );
  113. virtual bool ShouldFlipModel( void );
  114. void UpdateAnimationParity( void );
  115. virtual void PostBuildTransformations( CStudioHdr *pStudioHdr, BoneVector *pos, BoneQuaternion q[] );
  116. Vector m_vecCamDriverLastPos;
  117. QAngle m_angCamDriverLastAng;
  118. float m_flCamDriverAppliedTime;
  119. float m_flCamDriverWeight;
  120. virtual void ApplyBoneMatrixTransform( matrix3x4_t& transform );
  121. virtual bool ShouldDraw();
  122. virtual bool ShouldSuppressForSplitScreenPlayer( int nSlot );
  123. virtual int DrawModel( int flags, const RenderableInstance_t &instance );
  124. virtual int DrawOverriddenViewmodel( C_BaseViewModel *pViewmodel, int flags, const RenderableInstance_t &instance );
  125. virtual uint8 OverrideAlphaModulation( uint8 nAlpha );
  126. RenderableTranslucencyType_t ComputeTranslucencyType( void );
  127. // Should this object cast shadows?
  128. virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; }
  129. // Should this object receive shadows?
  130. virtual bool ShouldReceiveProjectedTextures( int flags )
  131. {
  132. return false;
  133. }
  134. virtual void GetBoneControllers(float controllers[MAXSTUDIOBONECTRLS]);
  135. // See C_StudioModel's definition of this.
  136. virtual void UncorrectViewModelAttachment( Vector &vOrigin );
  137. // (inherited from C_BaseAnimating)
  138. virtual void FormatViewModelAttachment( int nAttachment, matrix3x4_t &attachmentToWorld );
  139. CBaseCombatWeapon *GetWeapon() const { return m_hWeapon.Get(); }
  140. virtual bool ShouldResetSequenceOnNewModel( void ) { return false; }
  141. // Attachments
  142. virtual int LookupAttachment( const char *pAttachmentName );
  143. virtual bool GetAttachment( int number, matrix3x4_t &matrix );
  144. virtual bool GetAttachment( int number, Vector &origin );
  145. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles );
  146. virtual bool GetAttachmentVelocity( int number, Vector &originVel, Quaternion &angleVel );
  147. virtual bool Simulate( void );
  148. private:
  149. CBaseViewModel( const CBaseViewModel & ); // not defined, not accessible
  150. void UpdateParticles( int nSlot );
  151. virtual void OnNewParticleEffect( const char *pszParticleName, CNewParticleEffect *pNewParticleEffect );
  152. virtual void OnParticleEffectDeleted( CNewParticleEffect *pParticleEffect );
  153. CUtlReference<CNewParticleEffect> m_viewmodelParticleEffect;
  154. #endif
  155. #ifdef PORTAL2
  156. // We need to always transition because we handle our transition volumes in a different manner
  157. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_FORCE_TRANSITION; }
  158. #endif // PORTAL2
  159. private:
  160. typedef CHandle< CBaseCombatWeapon > CBaseCombatWeaponHandle;
  161. // FTYPEDESC_INSENDTABLE STUFF
  162. CNetworkVar( int, m_nViewModelIndex ); // Which viewmodel is it?
  163. // Used to force restart on client, only needs a few bits
  164. CNetworkVar( int, m_nAnimationParity );
  165. CNetworkVar( CBaseCombatWeaponHandle, m_hWeapon );
  166. // FTYPEDESC_INSENDTABLE STUFF (end)
  167. CNetworkHandle( CBaseEntity, m_hOwner ); // Player or AI carrying this weapon
  168. // soonest time Update will call WeaponIdle
  169. float m_flTimeWeaponIdle;
  170. Activity m_Activity;
  171. // Weapon art
  172. string_t m_sVMName; // View model of this weapon
  173. string_t m_sAnimationPrefix; // Prefix of the animations that should be used by the player carrying this weapon
  174. #if defined( CLIENT_DLL )
  175. int m_nOldAnimationParity;
  176. public:
  177. float m_fCycleOffset;
  178. void UpdateStatTrakGlow( void );
  179. void SetStatTrakGlowMultiplier( float flNewIdealGlow ) { m_flStatTrakGlowMultiplierIdeal = flNewIdealGlow; }
  180. const float GetStatTrakGlowMultiplier( void ){ return m_flStatTrakGlowMultiplier; }
  181. #ifdef IRONSIGHT
  182. void SetScopeStencilMaskMode( bool bEnabled ) { m_bScopeStencilMaskModeEnabled = bEnabled; }
  183. bool GetScopeStencilMaskMode( void ) { return m_bScopeStencilMaskModeEnabled; }
  184. #endif
  185. private:
  186. #ifdef IRONSIGHT
  187. bool m_bScopeStencilMaskModeEnabled;
  188. CHandle< C_ViewmodelAttachmentModel > m_viewmodelScopeStencilMask;
  189. #endif
  190. CUtlVector< CHandle< C_ViewmodelAttachmentModel > > m_vecViewmodelArmModels; // gloves, sleeves, etc
  191. CHandle< C_ViewmodelAttachmentModel > m_viewmodelStatTrakAddon;
  192. CHandle< C_ViewmodelAttachmentModel > m_viewmodelUidAddon;
  193. int m_iAddOnPlayerClass;
  194. int m_iAddOnWeaponID;
  195. float m_flStatTrakGlowMultiplierIdeal;
  196. float m_flStatTrakGlowMultiplier;
  197. //stickers
  198. typedef CHandle<C_ViewmodelAttachmentModel> StickerHandle_t;
  199. CUtlVector<StickerHandle_t> m_hStickerModelAddons;
  200. CBaseAnimating* m_pMaterialPreviewShape;
  201. char m_szLastSound[64];
  202. float m_flLastSoundTime;
  203. bool IsSoundSameAsPreviousSound( const char* soundName, float flPastTimeThreshold ) { return ( gpGlobals->curtime - m_flLastSoundTime < flPastTimeThreshold ) && !V_strcmp( soundName, m_szLastSound ); }
  204. void ResetTimeSincePreviousSound( void ) { m_flLastSoundTime = gpGlobals->curtime; }
  205. void SetPreviousSoundStr( const char* soundName ) { V_strcpy( m_szLastSound, soundName ); }
  206. #endif
  207. // Control panel
  208. typedef CHandle<CVGuiScreen> ScreenHandle_t;
  209. CUtlVector<ScreenHandle_t> m_hScreens;
  210. };
  211. inline CBaseViewModel *ToBaseViewModel( CBaseAnimating *pAnim )
  212. {
  213. if ( pAnim && pAnim->IsViewModel() )
  214. return assert_cast<CBaseViewModel *>(pAnim);
  215. return NULL;
  216. }
  217. inline CBaseViewModel *ToBaseViewModel( CBaseEntity *pEntity )
  218. {
  219. if ( !pEntity )
  220. return NULL;
  221. return ToBaseViewModel(pEntity->GetBaseAnimating());
  222. }
  223. #endif // BASEVIEWMODEL_SHARED_H