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.

273 lines
14 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef ITOOLENTITY_H
  7. #define ITOOLENTITY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/interface.h"
  12. #include "tier1/utlvector.h"
  13. #include "Color.h"
  14. #include "basehandle.h"
  15. #include "iclientrenderable.h"
  16. #include "engine/ishadowmgr.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. class IServerEntity;
  21. class IClientEntity;
  22. class IToolSystem;
  23. class IClientRenderable;
  24. class Vector;
  25. class QAngle;
  26. class CBaseEntity;
  27. class CBaseAnimating;
  28. class CTakeDamageInfo;
  29. class ITempEntsSystem;
  30. class IEntityFactoryDictionary;
  31. class CBaseTempEntity;
  32. class CGlobalEntityList;
  33. class IEntityFindFilter;
  34. //-----------------------------------------------------------------------------
  35. // Safe accessor to an entity
  36. //-----------------------------------------------------------------------------
  37. typedef unsigned int HTOOLHANDLE;
  38. enum
  39. {
  40. HTOOLHANDLE_INVALID = 0
  41. };
  42. //-----------------------------------------------------------------------------
  43. // If you change this, change the flags in IClientShadowMgr.h also
  44. //-----------------------------------------------------------------------------
  45. enum ClientShadowFlags_t
  46. {
  47. SHADOW_FLAGS_USE_RENDER_TO_TEXTURE = (SHADOW_FLAGS_LAST_FLAG<<1),
  48. SHADOW_FLAGS_ANIMATING_SOURCE = (SHADOW_FLAGS_LAST_FLAG<<2),
  49. SHADOW_FLAGS_USE_DEPTH_TEXTURE = (SHADOW_FLAGS_LAST_FLAG<<3),
  50. // Update this if you add flags
  51. CLIENT_SHADOW_FLAGS_LAST_FLAG = SHADOW_FLAGS_USE_DEPTH_TEXTURE
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Opaque pointer returned from Find* methods, don't store this, you need to
  55. // Attach it to a tool entity or discard after searching
  56. //-----------------------------------------------------------------------------
  57. typedef void *EntitySearchResult;
  58. //-----------------------------------------------------------------------------
  59. // Purpose: Client side tool interace (right now just handles IClientRenderables).
  60. // In theory could support hooking into client side entities directly
  61. //-----------------------------------------------------------------------------
  62. class IClientTools : public IBaseInterface
  63. {
  64. public:
  65. // Allocates or returns the handle to an entity previously found using the Find* APIs below
  66. virtual HTOOLHANDLE AttachToEntity( EntitySearchResult entityToAttach ) = 0;
  67. virtual void DetachFromEntity( EntitySearchResult entityToDetach ) = 0;
  68. // Checks whether a handle is still valid.
  69. virtual bool IsValidHandle( HTOOLHANDLE handle ) = 0;
  70. // Iterates the list of entities which have been associated with tools
  71. virtual int GetNumRecordables() = 0;
  72. virtual HTOOLHANDLE GetRecordable( int index ) = 0;
  73. // Iterates through ALL entities (separate list for client vs. server)
  74. virtual EntitySearchResult NextEntity( EntitySearchResult currentEnt ) = 0;
  75. EntitySearchResult FirstEntity() { return NextEntity( NULL ); }
  76. // Use this to turn on/off the presence of an underlying game entity
  77. virtual void SetEnabled( HTOOLHANDLE handle, bool enabled ) = 0;
  78. // Use this to tell an entity to post "state" to all listening tools
  79. virtual void SetRecording( HTOOLHANDLE handle, bool recording ) = 0;
  80. // Some entities are marked with ShouldRecordInTools false, such as ui entities, etc.
  81. virtual bool ShouldRecord( HTOOLHANDLE handle ) = 0;
  82. virtual HTOOLHANDLE GetToolHandleForEntityByIndex( int entindex ) = 0;
  83. virtual int GetModelIndex( HTOOLHANDLE handle ) = 0;
  84. virtual const char* GetModelName ( HTOOLHANDLE handle ) = 0;
  85. virtual const char* GetClassname ( HTOOLHANDLE handle ) = 0;
  86. virtual void AddClientRenderable( IClientRenderable *pRenderable, int renderGroup ) = 0;
  87. virtual void RemoveClientRenderable( IClientRenderable *pRenderable ) = 0;
  88. virtual void SetRenderGroup( IClientRenderable *pRenderable, int renderGroup ) = 0;
  89. virtual void MarkClientRenderableDirty( IClientRenderable *pRenderable ) = 0;
  90. virtual void UpdateProjectedTexture( ClientShadowHandle_t h, bool bForce ) = 0;
  91. virtual bool DrawSprite( IClientRenderable *pRenderable, float scale, float frame, int rendermode, int renderfx, const Color &color, float flProxyRadius, int *pVisHandle ) = 0;
  92. virtual EntitySearchResult GetLocalPlayer() = 0;
  93. virtual bool GetLocalPlayerEyePosition( Vector& org, QAngle& ang, float &fov ) = 0;
  94. // See ClientShadowFlags_t above
  95. virtual ClientShadowHandle_t CreateShadow( CBaseHandle handle, int nFlags ) = 0;
  96. virtual void DestroyShadow( ClientShadowHandle_t h ) = 0;
  97. virtual ClientShadowHandle_t CreateFlashlight( const FlashlightState_t &lightState ) = 0;
  98. virtual void DestroyFlashlight( ClientShadowHandle_t h ) = 0;
  99. virtual void UpdateFlashlightState( ClientShadowHandle_t h, const FlashlightState_t &lightState ) = 0;
  100. virtual void AddToDirtyShadowList( ClientShadowHandle_t h, bool force = false ) = 0;
  101. virtual void MarkRenderToTextureShadowDirty( ClientShadowHandle_t h ) = 0;
  102. // Global toggle for recording
  103. virtual void EnableRecordingMode( bool bEnable ) = 0;
  104. virtual bool IsInRecordingMode() const = 0;
  105. // Trigger a temp entity
  106. virtual void TriggerTempEntity( KeyValues *pKeyValues ) = 0;
  107. // get owning weapon (for viewmodels)
  108. virtual int GetOwningWeaponEntIndex( int entindex ) = 0;
  109. virtual int GetEntIndex( EntitySearchResult entityToAttach ) = 0;
  110. virtual int FindGlobalFlexcontroller( char const *name ) = 0;
  111. virtual char const *GetGlobalFlexControllerName( int idx ) = 0;
  112. // helper for traversing ownership hierarchy
  113. virtual EntitySearchResult GetOwnerEntity( EntitySearchResult currentEnt ) = 0;
  114. // common and useful types to query for hierarchically
  115. virtual bool IsPlayer ( EntitySearchResult currentEnt ) = 0;
  116. virtual bool IsBaseCombatCharacter( EntitySearchResult currentEnt ) = 0;
  117. virtual bool IsNPC ( EntitySearchResult currentEnt ) = 0;
  118. virtual Vector GetAbsOrigin( HTOOLHANDLE handle ) = 0;
  119. virtual QAngle GetAbsAngles( HTOOLHANDLE handle ) = 0;
  120. // This reloads a portion or all of a particle definition file.
  121. // It's up to the client to decide if it cares about this file
  122. // Use a UtlBuffer to crack the data
  123. virtual void ReloadParticleDefintions( const char *pFileName, const void *pBufData, int nLen ) = 0;
  124. // Sends a mesage from the tool to the client
  125. virtual void PostToolMessage( KeyValues *pKeyValues ) = 0;
  126. // Indicates whether the client should render particle systems
  127. virtual void EnableParticleSystems( bool bEnable ) = 0;
  128. // Is the game rendering in 3rd person mode?
  129. virtual bool IsRenderingThirdPerson() const = 0;
  130. };
  131. #define VCLIENTTOOLS_INTERFACE_VERSION "VCLIENTTOOLS001"
  132. //-----------------------------------------------------------------------------
  133. // Purpose: Interface from engine to tools for manipulating entities
  134. //-----------------------------------------------------------------------------
  135. class IServerTools : public IBaseInterface
  136. {
  137. public:
  138. virtual IServerEntity *GetIServerEntity( IClientEntity *pClientEntity ) = 0;
  139. virtual bool SnapPlayerToPosition( const Vector &org, const QAngle &ang, IClientEntity *pClientPlayer = NULL ) = 0;
  140. virtual bool GetPlayerPosition( Vector &org, QAngle &ang, IClientEntity *pClientPlayer = NULL ) = 0;
  141. virtual bool SetPlayerFOV( int fov, IClientEntity *pClientPlayer = NULL ) = 0;
  142. virtual int GetPlayerFOV( IClientEntity *pClientPlayer = NULL ) = 0;
  143. virtual bool IsInNoClipMode( IClientEntity *pClientPlayer = NULL ) = 0;
  144. // entity searching
  145. virtual CBaseEntity *FirstEntity( void ) = 0;
  146. virtual CBaseEntity *NextEntity( CBaseEntity *pEntity ) = 0;
  147. virtual CBaseEntity *FindEntityByHammerID( int iHammerID ) = 0;
  148. // entity query
  149. virtual bool GetKeyValue( CBaseEntity *pEntity, const char *szField, char *szValue, int iMaxLen ) = 0;
  150. virtual bool SetKeyValue( CBaseEntity *pEntity, const char *szField, const char *szValue ) = 0;
  151. virtual bool SetKeyValue( CBaseEntity *pEntity, const char *szField, float flValue ) = 0;
  152. virtual bool SetKeyValue( CBaseEntity *pEntity, const char *szField, const Vector &vecValue ) = 0;
  153. // entity spawning
  154. virtual CBaseEntity *CreateEntityByName( const char *szClassName ) = 0;
  155. virtual void DispatchSpawn( CBaseEntity *pEntity ) = 0;
  156. // This reloads a portion or all of a particle definition file.
  157. // It's up to the server to decide if it cares about this file
  158. // Use a UtlBuffer to crack the data
  159. virtual void ReloadParticleDefintions( const char *pFileName, const void *pBufData, int nLen ) = 0;
  160. virtual void AddOriginToPVS( const Vector &org ) = 0;
  161. virtual void MoveEngineViewTo( const Vector &vPos, const QAngle &vAngles ) = 0;
  162. virtual bool DestroyEntityByHammerId( int iHammerID ) = 0;
  163. virtual CBaseEntity *GetBaseEntityByEntIndex( int iEntIndex ) = 0;
  164. virtual void RemoveEntity( CBaseEntity *pEntity ) = 0;
  165. virtual void RemoveEntityImmediate( CBaseEntity *pEntity ) = 0;
  166. virtual IEntityFactoryDictionary *GetEntityFactoryDictionary( void ) = 0;
  167. virtual void SetMoveType( CBaseEntity *pEntity, int val ) = 0;
  168. virtual void SetMoveType( CBaseEntity *pEntity, int val, int moveCollide ) = 0;
  169. virtual void ResetSequence( CBaseAnimating *pEntity, int nSequence ) = 0;
  170. virtual void ResetSequenceInfo( CBaseAnimating *pEntity ) = 0;
  171. virtual void ClearMultiDamage( void ) = 0;
  172. virtual void ApplyMultiDamage( void ) = 0;
  173. virtual void AddMultiDamage( const CTakeDamageInfo &pTakeDamageInfo, CBaseEntity *pEntity ) = 0;
  174. virtual void RadiusDamage( const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore ) = 0;
  175. virtual ITempEntsSystem *GetTempEntsSystem( void ) = 0;
  176. virtual CBaseTempEntity *GetTempEntList( void ) = 0;
  177. virtual CGlobalEntityList *GetEntityList( void ) = 0;
  178. virtual bool IsEntityPtr( void *pTest ) = 0;
  179. virtual CBaseEntity *FindEntityByClassname( CBaseEntity *pStartEntity, const char *szName ) = 0;
  180. virtual CBaseEntity *FindEntityByName( CBaseEntity *pStartEntity, const char *szName, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL, IEntityFindFilter *pFilter = NULL ) = 0;
  181. virtual CBaseEntity *FindEntityInSphere( CBaseEntity *pStartEntity, const Vector &vecCenter, float flRadius ) = 0;
  182. virtual CBaseEntity *FindEntityByTarget( CBaseEntity *pStartEntity, const char *szName ) = 0;
  183. virtual CBaseEntity *FindEntityByModel( CBaseEntity *pStartEntity, const char *szModelName ) = 0;
  184. virtual CBaseEntity *FindEntityByNameNearest( const char *szName, const Vector &vecSrc, float flRadius, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL ) = 0;
  185. virtual CBaseEntity *FindEntityByNameWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecSrc, float flRadius, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL ) = 0;
  186. virtual CBaseEntity *FindEntityByClassnameNearest( const char *szName, const Vector &vecSrc, float flRadius ) = 0;
  187. virtual CBaseEntity *FindEntityByClassnameWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecSrc, float flRadius ) = 0;
  188. virtual CBaseEntity *FindEntityByClassnameWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecMins, const Vector &vecMaxs ) = 0;
  189. virtual CBaseEntity *FindEntityGeneric( CBaseEntity *pStartEntity, const char *szName, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL ) = 0;
  190. virtual CBaseEntity *FindEntityGenericWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecSrc, float flRadius, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL ) = 0;
  191. virtual CBaseEntity *FindEntityGenericNearest( const char *szName, const Vector &vecSrc, float flRadius, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL ) = 0;
  192. virtual CBaseEntity *FindEntityNearestFacing( const Vector &origin, const Vector &facing, float threshold ) = 0;
  193. virtual CBaseEntity *FindEntityClassNearestFacing( const Vector &origin, const Vector &facing, float threshold, char *classname ) = 0;
  194. virtual CBaseEntity *FindEntityProcedural( const char *szName, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL ) = 0;
  195. };
  196. typedef IServerTools IServerTools001;
  197. typedef IServerTools IServerTools002;
  198. #define VSERVERTOOLS_INTERFACE_VERSION_1 "VSERVERTOOLS001"
  199. #define VSERVERTOOLS_INTERFACE_VERSION_2 "VSERVERTOOLS002"
  200. #define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS003"
  201. #define VSERVERTOOLS_INTERFACE_VERSION_INT 3
  202. //-----------------------------------------------------------------------------
  203. // Purpose: Client side tool interace (right now just handles IClientRenderables).
  204. // In theory could support hooking into client side entities directly
  205. //-----------------------------------------------------------------------------
  206. class IServerChoreoTools : public IBaseInterface
  207. {
  208. public:
  209. // Iterates through ALL entities (separate list for client vs. server)
  210. virtual EntitySearchResult NextChoreoEntity( EntitySearchResult currentEnt ) = 0;
  211. EntitySearchResult FirstChoreoEntity() { return NextChoreoEntity( NULL ); }
  212. virtual const char *GetSceneFile( EntitySearchResult sr ) = 0;
  213. // For interactive editing
  214. virtual int GetEntIndex( EntitySearchResult sr ) = 0;
  215. virtual void ReloadSceneFromDisk( int entindex ) = 0;
  216. };
  217. #define VSERVERCHOREOTOOLS_INTERFACE_VERSION "VSERVERCHOREOTOOLS001"
  218. #endif // ITOOLENTITY_H