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.

311 lines
9.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Clients CBaseObject
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef C_BASEOBJECT_H
  8. #define C_BASEOBJECT_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "baseobject_shared.h"
  13. #include <vgui_controls/Panel.h>
  14. #include "particlemgr.h"
  15. #include "particle_prototype.h"
  16. #include "particle_util.h"
  17. #include "c_basecombatcharacter.h"
  18. #include "ihasbuildpoints.h"
  19. #include <vgui/ILocalize.h>
  20. class C_TFPlayer;
  21. // Max Length of ID Strings
  22. #define MAX_ID_STRING 256
  23. extern mstudioevent_t *GetEventIndexForSequence( mstudioseqdesc_t &seqdesc );
  24. DECLARE_AUTO_LIST( IBaseObjectAutoList );
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. class C_BaseObject : public C_BaseCombatCharacter, public IHasBuildPoints, public ITargetIDProvidesHint, public IBaseObjectAutoList
  29. {
  30. DECLARE_CLASS( C_BaseObject, C_BaseCombatCharacter );
  31. public:
  32. DECLARE_CLIENTCLASS();
  33. C_BaseObject();
  34. ~C_BaseObject( void );
  35. virtual void Spawn( void );
  36. virtual bool IsBaseObject( void ) const { return true; }
  37. virtual bool IsAnUpgrade(void ) const { return false; }
  38. virtual void SetType( int iObjectType );
  39. virtual void AddEntity();
  40. virtual void Select( void );
  41. void SetActivity( Activity act );
  42. Activity GetActivity( ) const;
  43. void SetObjectSequence( int sequence );
  44. virtual void ResetClientsideFrame( void );
  45. virtual void PreDataUpdate( DataUpdateType_t updateType );
  46. virtual void OnDataChanged( DataUpdateType_t updateType );
  47. virtual int GetHealth() const { return m_iHealth; }
  48. void SetHealth( int health ) { m_iHealth = health; }
  49. virtual int GetMaxHealth() const { return m_iMaxHealth; }
  50. int GetObjectFlags( void ) { return m_fObjectFlags; }
  51. void SetObjectFlags( int flags ) { m_fObjectFlags = flags; }
  52. // Derive to customize an object's attached version
  53. virtual void SetupAttachedVersion( void ) { return; }
  54. virtual const char *GetTargetDescription( void ) const;
  55. virtual const char *GetIDString( void );
  56. virtual bool IsValidIDTarget( void );
  57. virtual void GetTargetIDString( OUT_Z_BYTECAP(iMaxLenInBytes) wchar_t *sIDString, int iMaxLenInBytes, bool bSpectator );
  58. virtual void GetTargetIDDataString( OUT_Z_BYTECAP(iMaxLenInBytes) wchar_t *sDataString, int iMaxLenInBytes );
  59. virtual bool ShouldBeActive( void );
  60. virtual void OnGoActive( void );
  61. virtual void OnGoInactive( void );
  62. virtual void UpdateOnRemove( void );
  63. C_TFPlayer *GetBuilder( void ) { return m_hBuilder; }
  64. virtual void SetDormant( bool bDormant );
  65. void SendClientCommand( const char *pCmd );
  66. virtual void FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  67. // Builder preview...
  68. void ActivateYawPreview( bool enable );
  69. void PreviewYaw( float yaw );
  70. bool IsPreviewingYaw() const;
  71. virtual void RecalculateIDString( void );
  72. int GetType() const { return m_iObjectType; }
  73. bool IsOwnedByLocalPlayer() const;
  74. C_TFPlayer *GetOwner();
  75. virtual void Simulate();
  76. virtual int DrawModel( int flags );
  77. float GetPercentageConstructed( void ) { return m_flPercentageConstructed; }
  78. bool IsPlacing( void ) const { return m_bPlacing; }
  79. bool IsBuilding( void ) const { return m_bBuilding; }
  80. virtual bool IsUpgrading( void ) const { return false; }
  81. bool IsCarried( void ) const { return m_bCarried; }
  82. float GetReversesBuildingConstructionSpeed( void );
  83. virtual void FinishedBuilding( void ) { return; }
  84. virtual const char* GetStatusName() const;
  85. // Object Previews
  86. void HighlightBuildPoints( int flags );
  87. bool HasSapper( void );
  88. bool IsPlasmaDisabled( void );
  89. virtual void OnStartDisabled( void );
  90. virtual void OnEndDisabled( void );
  91. virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const;
  92. virtual bool ShouldPlayersAvoid( void );
  93. bool MustBeBuiltOnAttachmentPoint( void ) const;
  94. virtual bool IsHostileUpgrade( void ) { return false; }
  95. // For ordering in hud building status
  96. virtual int GetDisplayPriority( void );
  97. virtual const char *GetHudStatusIcon( void );
  98. virtual BuildingHudAlert_t GetBuildingAlertLevel( void );
  99. // Upgrading
  100. virtual int GetUpgradeLevel( void ) { return m_iUpgradeLevel; }
  101. int GetUpgradeMetal( void ) { return m_iUpgradeMetal; }
  102. virtual int GetUpgradeMetalRequired( void ) { return m_iUpgradeMetalRequired; }
  103. virtual void UpgradeLevelChanged() { return; }
  104. int GetHighestUpgradeLevel( void ) { return m_iHighestUpgradeLevel; }
  105. int GetObjectMode( void ) const { return m_iObjectMode; }
  106. // Shadows
  107. virtual ShadowType_t ShadowCastType( void ) OVERRIDE;
  108. // Stealth
  109. virtual float GetInvisibilityLevel( void );
  110. virtual void SetInvisibilityLevel( float flValue );
  111. bool IsEnteringOrExitingFullyInvisible( float flValue ) { return ( ( m_flInvisibilityPercent != 1.f && flValue == 1.f ) || ( m_flInvisibilityPercent == 1.f && flValue != 1.f ) ); }
  112. private:
  113. void StopAnimGeneratedSounds( void );
  114. public:
  115. // Client/Server shared build point code
  116. void CreateBuildPoints( void );
  117. void AddAndParseBuildPoint( int iAttachmentNumber, KeyValues *pkvBuildPoint );
  118. virtual int AddBuildPoint( int iAttachmentNum );
  119. virtual void AddValidObjectToBuildPoint( int iPoint, int iObjectType );
  120. virtual CBaseObject *GetBuildPointObject( int iPoint );
  121. bool IsBuiltOnAttachment( void ) { return m_hBuiltOnEntity.IsValid(); }
  122. void AttachObjectToObject( CBaseEntity *pEntity, int iPoint, Vector &vecOrigin );
  123. CBaseObject *GetParentObject( void );
  124. CBaseEntity *GetParentEntity( void );
  125. void SetBuildPointPassenger( int iPoint, int iPassenger );
  126. // Build points
  127. CUtlVector<BuildPoint_t> m_BuildPoints;
  128. bool IsDisabled( void ) { return m_bDisabled || m_bCarried; }
  129. // Shared placement
  130. bool VerifyCorner( const Vector &vBottomCenter, float xOffset, float yOffset );
  131. virtual bool IsPlacementPosValid( void );
  132. virtual float GetNearbyObjectCheckRadius( void ) { return 30.0; }
  133. virtual void OnPlacementStateChanged( bool bValidPlacement );
  134. bool ServerValidPlacement( void ); // allow server to trump our placement state
  135. bool WasLastPlacementPosValid( void ); // query if we're in a valid place, when we last tried to calculate it
  136. // IHasBuildPoints
  137. public:
  138. virtual int GetNumBuildPoints( void ) const;
  139. virtual bool GetBuildPoint( int iPoint, Vector &vecOrigin, QAngle &vecAngles );
  140. virtual int GetBuildPointAttachmentIndex( int iPoint ) const;
  141. virtual bool CanBuildObjectOnBuildPoint( int iPoint, int iObjectType );
  142. virtual void SetObjectOnBuildPoint( int iPoint, CBaseObject *pObject );
  143. virtual float GetMaxSnapDistance( int iBuildPoint );
  144. virtual bool ShouldCheckForMovement( void ) { return true; }
  145. virtual int GetNumObjectsOnMe( void );
  146. virtual CBaseObject *GetObjectOfTypeOnMe( int iObjectType );
  147. virtual void RemoveAllObjects( void );
  148. virtual int FindObjectOnBuildPoint( CBaseObject *pObject );
  149. virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  150. bool IsMiniBuilding() { return m_bMiniBuilding; }
  151. bool IsDisposableBuilding( void ) const { return m_bDisposableBuilding; }
  152. // ITargetIDProvidesHint
  153. public:
  154. virtual void DisplayHintTo( C_BasePlayer *pPlayer );
  155. virtual void GetGlowEffectColor( float *r, float *g, float *b );
  156. bool IsMapPlaced( void ){ return m_bWasMapPlaced; }
  157. protected:
  158. virtual void UpdateDamageEffects( BuildingDamageLevel_t damageLevel ) {} // default is no effects
  159. void UpdateDesiredBuildRotation( float flFrameTime );
  160. bool CalculatePlacementPos( void );
  161. protected:
  162. BuildingDamageLevel_t CalculateDamageLevel( void );
  163. char m_szIDString[ MAX_ID_STRING ];
  164. BuildingDamageLevel_t m_damageLevel;
  165. Vector m_vecBuildOrigin;
  166. Vector m_vecBuildCenterOfMass;
  167. // Upgrading
  168. int m_iUpgradeLevel;
  169. int m_iOldUpgradeLevel;
  170. int m_iUpgradeMetal;
  171. int m_iHighestUpgradeLevel;
  172. int m_iUpgradeMetalRequired;
  173. HPARTICLEFFECT m_hDamageEffects;
  174. private:
  175. enum
  176. {
  177. YAW_PREVIEW_OFF = 0,
  178. YAW_PREVIEW_ON,
  179. YAW_PREVIEW_WAITING_FOR_UPDATE
  180. };
  181. Activity m_Activity;
  182. int m_fObjectFlags;
  183. float m_fYawPreview;
  184. char m_YawPreviewState;
  185. CHandle< C_TFPlayer > m_hOldOwner;
  186. CHandle< C_TFPlayer > m_hBuilder;
  187. bool m_bWasActive;
  188. int m_iOldHealth;
  189. bool m_bHasSapper;
  190. bool m_bOldSapper;
  191. int m_iObjectType;
  192. int m_iHealth;
  193. int m_iMaxHealth;
  194. bool m_bWasBuilding;
  195. bool m_bBuilding;
  196. bool m_bWasPlacing;
  197. bool m_bPlacing;
  198. bool m_bDisabled;
  199. bool m_bOldDisabled;
  200. bool m_bCarried;
  201. bool m_bCarryDeploy;
  202. bool m_bOldCarryDeploy;
  203. bool m_bMiniBuilding;
  204. bool m_bDisposableBuilding;
  205. float m_flPercentageConstructed;
  206. EHANDLE m_hBuiltOnEntity;
  207. int m_iObjectMode;
  208. bool m_bPlasmaDisable;
  209. CNetworkVector( m_vecBuildMaxs );
  210. CNetworkVector( m_vecBuildMins );
  211. CNetworkVar( int, m_iDesiredBuildRotations );
  212. float m_flCurrentBuildRotation;
  213. int m_iLastPlacementPosValid; // -1 - init, 0 - invalid, 1 - valid
  214. CNetworkVar( bool, m_bServerOverridePlacement );
  215. int m_nObjectOldSequence;
  216. // used when calculating the placement position
  217. Vector m_vecBuildForward;
  218. float m_flBuildDistance;
  219. // Stealth
  220. float m_flInvisibilityPercent;
  221. float m_flPrevInvisibilityPercent;
  222. CNetworkVar( bool, m_bWasMapPlaced );
  223. private:
  224. C_BaseObject( const C_BaseObject & ); // not defined, not accessible
  225. };
  226. #endif // C_BASEOBJECT_H