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.

210 lines
5.8 KiB

  1. //========= Copyright 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 "econ/ihasowner.h"
  17. class CBaseCombatWeapon;
  18. class CBaseCombatCharacter;
  19. class CVGuiScreen;
  20. #if defined( CLIENT_DLL )
  21. #define CBaseViewModel C_BaseViewModel
  22. #define CBaseCombatWeapon C_BaseCombatWeapon
  23. #endif
  24. #define VIEWMODEL_INDEX_BITS 1
  25. class CBaseViewModel : public CBaseAnimating, public IHasOwner
  26. {
  27. DECLARE_CLASS( CBaseViewModel, CBaseAnimating );
  28. public:
  29. DECLARE_NETWORKCLASS();
  30. DECLARE_PREDICTABLE();
  31. #if !defined( CLIENT_DLL )
  32. DECLARE_DATADESC();
  33. #endif
  34. CBaseViewModel( void );
  35. ~CBaseViewModel( void );
  36. bool IsViewable(void) { return false; }
  37. virtual void UpdateOnRemove( void );
  38. // Weapon client handling
  39. virtual void SendViewModelMatchingSequence( int sequence );
  40. virtual void SetWeaponModel( const char *pszModelname, CBaseCombatWeapon *weapon );
  41. virtual void CalcViewModelLag( Vector& origin, QAngle& angles, QAngle& original_angles );
  42. virtual void CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition,
  43. const QAngle& eyeAngles );
  44. virtual void AddViewModelBob( CBasePlayer *owner, Vector& eyePosition, QAngle& eyeAngles ) {};
  45. // Initializes the viewmodel for use
  46. void SetOwner( CBaseEntity *pEntity );
  47. void SetIndex( int nIndex );
  48. // Returns which viewmodel it is
  49. int ViewModelIndex( ) const;
  50. virtual void Precache( void );
  51. virtual void Spawn( void );
  52. virtual CBaseEntity *GetOwner( void ) { return m_hOwner; };
  53. virtual void AddEffects( int nEffects );
  54. virtual void RemoveEffects( int nEffects );
  55. void SpawnControlPanels();
  56. void DestroyControlPanels();
  57. void SetControlPanelsActive( bool bState );
  58. void ShowControlPanells( bool show );
  59. virtual CBaseCombatWeapon *GetOwningWeapon( void );
  60. virtual CBaseEntity *GetOwnerViaInterface( void ) { return GetOwner(); }
  61. virtual bool IsSelfAnimating()
  62. {
  63. return true;
  64. }
  65. Vector m_vecLastFacing;
  66. // Only support prediction in TF2 for now
  67. #if defined( INVASION_DLL ) || defined( INVASION_CLIENT_DLL )
  68. // All predicted weapons need to implement and return true
  69. virtual bool IsPredicted( void ) const
  70. {
  71. return true;
  72. }
  73. #endif
  74. #if !defined( CLIENT_DLL )
  75. virtual int UpdateTransmitState( void );
  76. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  77. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  78. #else
  79. virtual RenderGroup_t GetRenderGroup();
  80. // Only supported in TF2 right now
  81. #if defined( INVASION_CLIENT_DLL )
  82. virtual bool ShouldPredict( void )
  83. {
  84. if ( GetOwner() && GetOwner() == C_BasePlayer::GetLocalPlayer() )
  85. return true;
  86. return BaseClass::ShouldPredict();
  87. }
  88. #endif
  89. virtual void FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  90. virtual void OnDataChanged( DataUpdateType_t updateType );
  91. virtual void PostDataUpdate( DataUpdateType_t updateType );
  92. virtual bool Interpolate( float currentTime );
  93. bool ShouldFlipViewModel();
  94. void UpdateAnimationParity( void );
  95. virtual void ApplyBoneMatrixTransform( matrix3x4_t& transform );
  96. virtual bool ShouldDraw();
  97. virtual int DrawModel( int flags );
  98. virtual int InternalDrawModel( int flags );
  99. int DrawOverriddenViewmodel( int flags );
  100. virtual int GetFxBlend( void );
  101. virtual bool IsTransparent( void );
  102. virtual bool UsesPowerOfTwoFrameBufferTexture( void );
  103. // Should this object cast shadows?
  104. virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; }
  105. // Should this object receive shadows?
  106. virtual bool ShouldReceiveProjectedTextures( int flags )
  107. {
  108. return false;
  109. }
  110. // Add entity to visible view models list?
  111. virtual void AddEntity( void );
  112. virtual void GetBoneControllers(float controllers[MAXSTUDIOBONECTRLS]);
  113. // See C_StudioModel's definition of this.
  114. virtual void UncorrectViewModelAttachment( Vector &vOrigin );
  115. // (inherited from C_BaseAnimating)
  116. virtual void FormatViewModelAttachment( int nAttachment, matrix3x4_t &attachmentToWorld );
  117. virtual bool IsViewModel() const;
  118. CBaseCombatWeapon *GetWeapon() const { return m_hWeapon.Get(); }
  119. #ifdef CLIENT_DLL
  120. virtual bool ShouldResetSequenceOnNewModel( void ) { return false; }
  121. // Attachments
  122. virtual int LookupAttachment( const char *pAttachmentName );
  123. virtual bool GetAttachment( int number, matrix3x4_t &matrix );
  124. virtual bool GetAttachment( int number, Vector &origin );
  125. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles );
  126. virtual bool GetAttachmentVelocity( int number, Vector &originVel, Quaternion &angleVel );
  127. #endif
  128. private:
  129. CBaseViewModel( const CBaseViewModel & ); // not defined, not accessible
  130. #endif
  131. private:
  132. CNetworkVar( int, m_nViewModelIndex ); // Which viewmodel is it?
  133. CNetworkHandle( CBaseEntity, m_hOwner ); // Player or AI carrying this weapon
  134. // soonest time Update will call WeaponIdle
  135. float m_flTimeWeaponIdle;
  136. Activity m_Activity;
  137. // Used to force restart on client, only needs a few bits
  138. CNetworkVar( int, m_nAnimationParity );
  139. // Weapon art
  140. string_t m_sVMName; // View model of this weapon
  141. string_t m_sAnimationPrefix; // Prefix of the animations that should be used by the player carrying this weapon
  142. #if defined( CLIENT_DLL )
  143. int m_nOldAnimationParity;
  144. #endif
  145. typedef CHandle< CBaseCombatWeapon > CBaseCombatWeaponHandle;
  146. CNetworkVar( CBaseCombatWeaponHandle, m_hWeapon );
  147. // Control panel
  148. typedef CHandle<CVGuiScreen> ScreenHandle_t;
  149. CUtlVector<ScreenHandle_t> m_hScreens;
  150. };
  151. #endif // BASEVIEWMODEL_SHARED_H