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.

631 lines
23 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Misc utility code.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef UTIL_H
  8. #define UTIL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "ai_activity.h"
  13. #include "steam/steam_gameserver.h"
  14. #include "enginecallback.h"
  15. #include "basetypes.h"
  16. #include "tempentity.h"
  17. #include "string_t.h"
  18. #include "gamestringpool.h"
  19. #include "engine/IEngineTrace.h"
  20. #include "worldsize.h"
  21. #include "dt_send.h"
  22. #include "server_class.h"
  23. #include "shake.h"
  24. #include "vstdlib/random.h"
  25. #include <string.h>
  26. #include "utlvector.h"
  27. #include "util_shared.h"
  28. #include "shareddefs.h"
  29. #include "networkvar.h"
  30. struct levellist_t;
  31. class IServerNetworkable;
  32. class IEntityFactory;
  33. #ifdef _WIN32
  34. #define SETUP_EXTERNC(mapClassName)\
  35. extern "C" _declspec( dllexport ) IServerNetworkable* mapClassName( void );
  36. #else
  37. #define SETUP_EXTERNC(mapClassName)
  38. #endif
  39. //
  40. // How did I ever live without ASSERT?
  41. //
  42. #ifdef DEBUG
  43. void DBG_AssertFunction(bool fExpr, const char* szExpr, const char* szFile, int szLine, const char* szMessage);
  44. #define ASSERT(f) DBG_AssertFunction((bool)((f)!=0), #f, __FILE__, __LINE__, NULL)
  45. #define ASSERTSZ(f, sz) DBG_AssertFunction((bool)((f)!=0), #f, __FILE__, __LINE__, sz)
  46. #else // !DEBUG
  47. #define ASSERT(f)
  48. #define ASSERTSZ(f, sz)
  49. #endif // !DEBUG
  50. #include "tier0/memdbgon.h"
  51. // entity creation
  52. // creates an entity that has not been linked to a classname
  53. template< class T >
  54. T *_CreateEntityTemplate( T *newEnt, const char *className )
  55. {
  56. newEnt = new T; // this is the only place 'new' should be used!
  57. newEnt->PostConstructor( className );
  58. return newEnt;
  59. }
  60. #include "tier0/memdbgoff.h"
  61. CBaseEntity *CreateEntityByName( const char *className, int iForceEdictIndex );
  62. // creates an entity by name, and ensure it's correctness
  63. // does not spawn the entity
  64. // use the CREATE_ENTITY() macro which wraps this, instead of using it directly
  65. template< class T >
  66. T *_CreateEntity( T *newClass, const char *className )
  67. {
  68. T *newEnt = dynamic_cast<T*>( CreateEntityByName(className, -1) );
  69. if ( !newEnt )
  70. {
  71. Warning( "classname %s used to create wrong class type\n", className );
  72. Assert(0);
  73. }
  74. return newEnt;
  75. }
  76. #define CREATE_ENTITY( newClass, className ) _CreateEntity( (newClass*)NULL, className )
  77. #define CREATE_UNSAVED_ENTITY( newClass, className ) _CreateEntityTemplate( (newClass*)NULL, className )
  78. // This is the glue that hooks .MAP entity class names to our CPP classes
  79. abstract_class IEntityFactoryDictionary
  80. {
  81. public:
  82. virtual void InstallFactory( IEntityFactory *pFactory, const char *pClassName ) = 0;
  83. virtual IServerNetworkable *Create( const char *pClassName ) = 0;
  84. virtual void Destroy( const char *pClassName, IServerNetworkable *pNetworkable ) = 0;
  85. virtual IEntityFactory *FindFactory( const char *pClassName ) = 0;
  86. virtual const char *GetCannonicalName( const char *pClassName ) = 0;
  87. };
  88. IEntityFactoryDictionary *EntityFactoryDictionary();
  89. inline bool CanCreateEntityClass( const char *pszClassname )
  90. {
  91. return ( EntityFactoryDictionary() != NULL && EntityFactoryDictionary()->FindFactory( pszClassname ) != NULL );
  92. }
  93. abstract_class IEntityFactory
  94. {
  95. public:
  96. virtual IServerNetworkable *Create( const char *pClassName ) = 0;
  97. virtual void Destroy( IServerNetworkable *pNetworkable ) = 0;
  98. virtual size_t GetEntitySize() = 0;
  99. };
  100. template <class T>
  101. class CEntityFactory : public IEntityFactory
  102. {
  103. public:
  104. CEntityFactory( const char *pClassName )
  105. {
  106. EntityFactoryDictionary()->InstallFactory( this, pClassName );
  107. }
  108. IServerNetworkable *Create( const char *pClassName )
  109. {
  110. T* pEnt = _CreateEntityTemplate((T*)NULL, pClassName);
  111. return pEnt->NetworkProp();
  112. }
  113. void Destroy( IServerNetworkable *pNetworkable )
  114. {
  115. if ( pNetworkable )
  116. {
  117. pNetworkable->Release();
  118. }
  119. }
  120. virtual size_t GetEntitySize()
  121. {
  122. return sizeof(T);
  123. }
  124. };
  125. #define LINK_ENTITY_TO_CLASS(mapClassName,DLLClassName) \
  126. static CEntityFactory<DLLClassName> mapClassName( #mapClassName );
  127. //
  128. // Conversion among the three types of "entity", including identity-conversions.
  129. //
  130. inline int ENTINDEX( edict_t *pEdict)
  131. {
  132. int nResult = pEdict ? pEdict->m_EdictIndex : 0;
  133. Assert( nResult == engine->IndexOfEdict(pEdict) );
  134. return nResult;
  135. }
  136. int ENTINDEX( CBaseEntity *pEnt );
  137. inline edict_t* INDEXENT( int iEdictNum )
  138. {
  139. return engine->PEntityOfEntIndex(iEdictNum);
  140. }
  141. // Testing the three types of "entity" for nullity
  142. inline bool FNullEnt(const edict_t* pent)
  143. {
  144. return pent == NULL || ENTINDEX((edict_t*)pent) == 0;
  145. }
  146. // Dot products for view cone checking
  147. #define VIEW_FIELD_FULL (float)-1.0 // +-180 degrees
  148. #define VIEW_FIELD_WIDE (float)-0.7 // +-135 degrees 0.1 // +-85 degrees, used for full FOV checks
  149. #define VIEW_FIELD_NARROW (float)0.7 // +-45 degrees, more narrow check used to set up ranged attacks
  150. #define VIEW_FIELD_ULTRA_NARROW (float)0.9 // +-25 degrees, more narrow check used to set up ranged attacks
  151. class CBaseEntity;
  152. class CBasePlayer;
  153. extern CGlobalVars *gpGlobals;
  154. // Misc useful
  155. inline bool FStrEq(const char *sz1, const char *sz2)
  156. {
  157. return ( sz1 == sz2 || V_stricmp(sz1, sz2) == 0 );
  158. }
  159. #if 0
  160. // UNDONE: Remove/alter MAKE_STRING so we can do this?
  161. inline bool FStrEq( string_t str1, string_t str2 )
  162. {
  163. // now that these are pooled, we can compare them with
  164. // integer equality
  165. return str1 == str2;
  166. }
  167. #endif
  168. // Misc. Prototypes
  169. void UTIL_SetSize (CBaseEntity *pEnt, const Vector &vecMin, const Vector &vecMax);
  170. void UTIL_ClearTrace ( trace_t &trace );
  171. void UTIL_SetTrace (trace_t& tr, const Ray_t &ray, edict_t* edict, float fraction, int hitgroup, unsigned int contents, const Vector& normal, float intercept );
  172. int UTIL_PrecacheDecal ( const char *name, bool preload = false );
  173. //-----------------------------------------------------------------------------
  174. float UTIL_GetSimulationInterval();
  175. //-----------------------------------------------------------------------------
  176. // Purpose: Gets a player pointer by 1-based index
  177. // If player is not yet spawned or connected, returns NULL
  178. // Input : playerIndex - index of the player - first player is index 1
  179. //-----------------------------------------------------------------------------
  180. // NOTENOTE: Use UTIL_GetLocalPlayer instead of UTIL_PlayerByIndex IF you're in single player
  181. // and you want the player.
  182. CBasePlayer *UTIL_PlayerByIndex( int playerIndex );
  183. CBasePlayer *UTIL_PlayerBySteamID( const CSteamID &steamID );
  184. // NOTENOTE: Use this instead of UTIL_PlayerByIndex IF you're in single player
  185. // and you want the player.
  186. // not useable in multiplayer - see UTIL_GetListenServerHost()
  187. CBasePlayer* UTIL_GetLocalPlayer( void );
  188. // get the local player on a listen server
  189. CBasePlayer *UTIL_GetListenServerHost( void );
  190. // Returns true if the command was issued by the listenserver host, or by the dedicated server, via rcon or the server console.
  191. // This is valid during ConCommand execution.
  192. bool UTIL_IsCommandIssuedByServerAdmin( void );
  193. CBaseEntity* UTIL_EntityByIndex( int entityIndex );
  194. void UTIL_GetPlayerConnectionInfo( int playerIndex, int& ping, int &packetloss );
  195. void UTIL_SetClientVisibilityPVS( edict_t *pClient, const unsigned char *pvs, int pvssize );
  196. bool UTIL_ClientPVSIsExpanded();
  197. edict_t *UTIL_FindClientInPVS( edict_t *pEdict );
  198. edict_t *UTIL_FindClientInVisibilityPVS( edict_t *pEdict );
  199. // This is a version which finds any clients whose PVS intersects the box
  200. CBaseEntity *UTIL_FindClientInPVS( const Vector &vecBoxMins, const Vector &vecBoxMaxs );
  201. CBaseEntity *UTIL_EntitiesInPVS( CBaseEntity *pPVSEntity, CBaseEntity *pStartingEntity );
  202. //-----------------------------------------------------------------------------
  203. // class CFlaggedEntitiesEnum
  204. //-----------------------------------------------------------------------------
  205. // enumerate entities that match a set of edict flags into a static array
  206. class CFlaggedEntitiesEnum : public IPartitionEnumerator
  207. {
  208. public:
  209. CFlaggedEntitiesEnum( CBaseEntity **pList, int listMax, int flagMask );
  210. // This gets called by the enumeration methods with each element
  211. // that passes the test.
  212. virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity );
  213. int GetCount() { return m_count; }
  214. bool AddToList( CBaseEntity *pEntity );
  215. private:
  216. CBaseEntity **m_pList;
  217. int m_listMax;
  218. int m_flagMask;
  219. int m_count;
  220. };
  221. // Pass in an array of pointers and an array size, it fills the array and returns the number inserted
  222. int UTIL_EntitiesInBox( const Vector &mins, const Vector &maxs, CFlaggedEntitiesEnum *pEnum );
  223. int UTIL_EntitiesAlongRay( const Ray_t &ray, CFlaggedEntitiesEnum *pEnum );
  224. int UTIL_EntitiesInSphere( const Vector &center, float radius, CFlaggedEntitiesEnum *pEnum );
  225. inline int UTIL_EntitiesInBox( CBaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask )
  226. {
  227. CFlaggedEntitiesEnum boxEnum( pList, listMax, flagMask );
  228. return UTIL_EntitiesInBox( mins, maxs, &boxEnum );
  229. }
  230. inline int UTIL_EntitiesAlongRay( CBaseEntity **pList, int listMax, const Ray_t &ray, int flagMask )
  231. {
  232. CFlaggedEntitiesEnum rayEnum( pList, listMax, flagMask );
  233. return UTIL_EntitiesAlongRay( ray, &rayEnum );
  234. }
  235. inline int UTIL_EntitiesInSphere( CBaseEntity **pList, int listMax, const Vector &center, float radius, int flagMask )
  236. {
  237. CFlaggedEntitiesEnum sphereEnum( pList, listMax, flagMask );
  238. return UTIL_EntitiesInSphere( center, radius, &sphereEnum );
  239. }
  240. // marks the entity for deletion so it will get removed next frame
  241. void UTIL_Remove( IServerNetworkable *oldObj );
  242. void UTIL_Remove( CBaseEntity *oldObj );
  243. // deletes an entity, without any delay. Only use this when sure no pointers rely on this entity.
  244. void UTIL_DisableRemoveImmediate();
  245. void UTIL_EnableRemoveImmediate();
  246. void UTIL_RemoveImmediate( CBaseEntity *oldObj );
  247. // make this a fixed size so it just sits on the stack
  248. #define MAX_SPHERE_QUERY 512
  249. class CEntitySphereQuery
  250. {
  251. public:
  252. // currently this builds the list in the constructor
  253. // UNDONE: make an iterative query of ISpatialPartition so we could
  254. // make queries like this optimal
  255. CEntitySphereQuery( const Vector &center, float radius, int flagMask=0 );
  256. CBaseEntity *GetCurrentEntity();
  257. inline void NextEntity() { m_listIndex++; }
  258. private:
  259. int m_listIndex;
  260. int m_listCount;
  261. CBaseEntity *m_pList[MAX_SPHERE_QUERY];
  262. };
  263. enum soundlevel_t;
  264. // Drops an entity onto the floor
  265. int UTIL_DropToFloor( CBaseEntity *pEntity, unsigned int mask, CBaseEntity *pIgnore = NULL );
  266. // Returns false if any part of the bottom of the entity is off an edge that is not a staircase.
  267. bool UTIL_CheckBottom( CBaseEntity *pEntity, ITraceFilter *pTraceFilter, float flStepSize );
  268. void UTIL_SetOrigin ( CBaseEntity *entity, const Vector &vecOrigin, bool bFireTriggers = false );
  269. void UTIL_EmitAmbientSound ( int entindex, const Vector &vecOrigin, const char *samp, float vol, soundlevel_t soundlevel, int fFlags, int pitch, float soundtime = 0.0f, float *duration = NULL );
  270. void UTIL_ParticleEffect ( const Vector &vecOrigin, const Vector &vecDirection, ULONG ulColor, ULONG ulCount );
  271. void UTIL_ScreenShake ( const Vector &center, float amplitude, float frequency, float duration, float radius, ShakeCommand_t eCommand, bool bAirShake=false );
  272. void UTIL_ScreenShakeObject ( CBaseEntity *pEnt, const Vector &center, float amplitude, float frequency, float duration, float radius, ShakeCommand_t eCommand, bool bAirShake=false );
  273. void UTIL_ViewPunch ( const Vector &center, QAngle angPunch, float radius, bool bInAir );
  274. void UTIL_ShowMessage ( const char *pString, CBasePlayer *pPlayer );
  275. void UTIL_ShowMessageAll ( const char *pString );
  276. void UTIL_ScreenFadeAll ( const color32 &color, float fadeTime, float holdTime, int flags );
  277. void UTIL_ScreenFade ( CBaseEntity *pEntity, const color32 &color, float fadeTime, float fadeHold, int flags );
  278. void UTIL_MuzzleFlash ( const Vector &origin, const QAngle &angles, int scale, int type );
  279. Vector UTIL_PointOnLineNearestPoint(const Vector& vStartPos, const Vector& vEndPos, const Vector& vPoint, bool clampEnds = false );
  280. int UTIL_EntityInSolid( CBaseEntity *ent );
  281. bool UTIL_IsMasterTriggered (string_t sMaster, CBaseEntity *pActivator);
  282. void UTIL_BloodStream( const Vector &origin, const Vector &direction, int color, int amount );
  283. void UTIL_BloodSpray( const Vector &pos, const Vector &dir, int color, int amount, int flags );
  284. Vector UTIL_RandomBloodVector( void );
  285. void UTIL_ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName = NULL );
  286. void UTIL_PlayerDecalTrace( trace_t *pTrace, int playernum );
  287. void UTIL_Smoke( const Vector &origin, const float scale, const float framerate );
  288. void UTIL_AxisStringToPointDir( Vector &start, Vector &dir, const char *pString );
  289. void UTIL_AxisStringToPointPoint( Vector &start, Vector &end, const char *pString );
  290. void UTIL_AxisStringToUnitDir( Vector &dir, const char *pString );
  291. void UTIL_ClipPunchAngleOffset( QAngle &in, const QAngle &punch, const QAngle &clip );
  292. void UTIL_PredictedPosition( CBaseEntity *pTarget, float flTimeDelta, Vector *vecPredictedPosition );
  293. void UTIL_Beam( Vector &Start, Vector &End, int nModelIndex, int nHaloIndex, unsigned char FrameStart, unsigned char FrameRate,
  294. float Life, unsigned char Width, unsigned char EndWidth, unsigned char FadeLength, unsigned char Noise, unsigned char Red, unsigned char Green,
  295. unsigned char Blue, unsigned char Brightness, unsigned char Speed);
  296. const char *UTIL_VarArgs( PRINTF_FORMAT_STRING const char *format, ... ) FMTFUNCTION( 1, 2 );
  297. bool UTIL_IsValidEntity( CBaseEntity *pEnt );
  298. bool UTIL_TeamsMatch( const char *pTeamName1, const char *pTeamName2 );
  299. // snaps a vector to the nearest axis vector (if within epsilon)
  300. void UTIL_SnapDirectionToAxis( Vector &direction, float epsilon = 0.002f );
  301. //Set the entity to point at the target specified
  302. bool UTIL_PointAtEntity( CBaseEntity *pEnt, CBaseEntity *pTarget );
  303. void UTIL_PointAtNamedEntity( CBaseEntity *pEnt, string_t strTarget );
  304. // Copy the pose parameter values from one entity to the other
  305. bool UTIL_TransferPoseParameters( CBaseEntity *pSourceEntity, CBaseEntity *pDestEntity );
  306. // Search for water transition along a vertical line
  307. float UTIL_WaterLevel( const Vector &position, float minz, float maxz );
  308. // Like UTIL_WaterLevel, but *way* less expensive.
  309. // I didn't replace UTIL_WaterLevel everywhere to avoid breaking anything.
  310. float UTIL_FindWaterSurface( const Vector &position, float minz, float maxz );
  311. void UTIL_Bubbles( const Vector& mins, const Vector& maxs, int count );
  312. void UTIL_BubbleTrail( const Vector& from, const Vector& to, int count );
  313. // allows precacheing of other entities
  314. void UTIL_PrecacheOther( const char *szClassname, const char *modelName = NULL );
  315. // prints a message to each client
  316. void UTIL_ClientPrintAll( int msg_dest, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL );
  317. inline void UTIL_CenterPrintAll( const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL )
  318. {
  319. UTIL_ClientPrintAll( HUD_PRINTCENTER, msg_name, param1, param2, param3, param4 );
  320. }
  321. void UTIL_ValidateSoundName( string_t &name, const char *defaultStr );
  322. void UTIL_ClientPrintFilter( IRecipientFilter& filter, int msg_dest, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL );
  323. // prints messages through the HUD
  324. void ClientPrint( CBasePlayer *player, int msg_dest, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL );
  325. // prints a message to the HUD say (chat)
  326. void UTIL_SayText( const char *pText, CBasePlayer *pEntity );
  327. void UTIL_SayTextAll( const char *pText, CBasePlayer *pEntity = NULL, bool bChat = false );
  328. void UTIL_SayTextFilter( IRecipientFilter& filter, const char *pText, CBasePlayer *pEntity, bool bChat );
  329. void UTIL_SayText2Filter( IRecipientFilter& filter, CBasePlayer *pEntity, bool bChat, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL );
  330. byte *UTIL_LoadFileForMe( const char *filename, int *pLength );
  331. void UTIL_FreeFile( byte *buffer );
  332. class CGameTrace;
  333. typedef CGameTrace trace_t;
  334. //-----------------------------------------------------------------------------
  335. // These are inlined for backwards compatibility
  336. //-----------------------------------------------------------------------------
  337. inline float UTIL_Approach( float target, float value, float speed )
  338. {
  339. return Approach( target, value, speed );
  340. }
  341. inline float UTIL_ApproachAngle( float target, float value, float speed )
  342. {
  343. return ApproachAngle( target, value, speed );
  344. }
  345. inline float UTIL_AngleDistance( float next, float cur )
  346. {
  347. return AngleDistance( next, cur );
  348. }
  349. inline float UTIL_AngleMod(float a)
  350. {
  351. return anglemod(a);
  352. }
  353. inline float UTIL_AngleDiff( float destAngle, float srcAngle )
  354. {
  355. return AngleDiff( destAngle, srcAngle );
  356. }
  357. typedef struct hudtextparms_s
  358. {
  359. float x;
  360. float y;
  361. int effect;
  362. byte r1, g1, b1, a1;
  363. byte r2, g2, b2, a2;
  364. float fadeinTime;
  365. float fadeoutTime;
  366. float holdTime;
  367. float fxTime;
  368. int channel;
  369. } hudtextparms_t;
  370. //-----------------------------------------------------------------------------
  371. // Sets the model to be associated with an entity
  372. //-----------------------------------------------------------------------------
  373. void UTIL_SetModel( CBaseEntity *pEntity, const char *pModelName );
  374. // prints as transparent 'title' to the HUD
  375. void UTIL_HudMessageAll( const hudtextparms_t &textparms, const char *pMessage );
  376. void UTIL_HudMessage( CBasePlayer *pToPlayer, const hudtextparms_t &textparms, const char *pMessage );
  377. // brings up hud keyboard hints display
  378. void UTIL_HudHintText( CBaseEntity *pEntity, const char *pMessage );
  379. // Writes message to console with timestamp and FragLog header.
  380. void UTIL_LogPrintf( PRINTF_FORMAT_STRING const char *fmt, ... ) FMTFUNCTION( 1, 2 );
  381. // Sorta like FInViewCone, but for nonNPCs.
  382. float UTIL_DotPoints ( const Vector &vecSrc, const Vector &vecCheck, const Vector &vecDir );
  383. void UTIL_StripToken( const char *pKey, char *pDest, int nDestLength );// for redundant keynames
  384. // Misc functions
  385. int BuildChangeList( levellist_t *pLevelList, int maxList );
  386. // computes gravity scale for an absolute gravity. Pass the result into CBaseEntity::SetGravity()
  387. float UTIL_ScaleForGravity( float desiredGravity );
  388. //
  389. // Constants that were used only by QC (maybe not used at all now)
  390. //
  391. // Un-comment only as needed
  392. //
  393. #include "globals.h"
  394. #define LFO_SQUARE 1
  395. #define LFO_TRIANGLE 2
  396. #define LFO_RANDOM 3
  397. // func_rotating
  398. #define SF_BRUSH_ROTATE_Y_AXIS 0
  399. #define SF_BRUSH_ROTATE_START_ON 1
  400. #define SF_BRUSH_ROTATE_BACKWARDS 2
  401. #define SF_BRUSH_ROTATE_Z_AXIS 4
  402. #define SF_BRUSH_ROTATE_X_AXIS 8
  403. #define SF_BRUSH_ROTATE_CLIENTSIDE 16
  404. #define SF_BRUSH_ROTATE_SMALLRADIUS 128
  405. #define SF_BRUSH_ROTATE_MEDIUMRADIUS 256
  406. #define SF_BRUSH_ROTATE_LARGERADIUS 512
  407. #define PUSH_BLOCK_ONLY_X 1
  408. #define PUSH_BLOCK_ONLY_Y 2
  409. #define SF_LIGHT_START_OFF 1
  410. #define SPAWNFLAG_NOMESSAGE 1
  411. #define SPAWNFLAG_NOTOUCH 1
  412. #define SPAWNFLAG_DROIDONLY 4
  413. #define SPAWNFLAG_USEONLY 1 // can't be touched, must be used (buttons)
  414. #define TELE_PLAYER_ONLY 1
  415. #define TELE_SILENT 2
  416. // Sound Utilities
  417. enum soundlevel_t;
  418. void SENTENCEG_Init();
  419. void SENTENCEG_Stop(edict_t *entity, int isentenceg, int ipick);
  420. int SENTENCEG_PlayRndI(edict_t *entity, int isentenceg, float volume, soundlevel_t soundlevel, int flags, int pitch);
  421. int SENTENCEG_PlayRndSz(edict_t *entity, const char *szrootname, float volume, soundlevel_t soundlevel, int flags, int pitch);
  422. int SENTENCEG_PlaySequentialSz(edict_t *entity, const char *szrootname, float volume, soundlevel_t soundlevel, int flags, int pitch, int ipick, int freset);
  423. void SENTENCEG_PlaySentenceIndex( edict_t *entity, int iSentenceIndex, float volume, soundlevel_t soundlevel, int flags, int pitch );
  424. int SENTENCEG_PickRndSz(const char *szrootname);
  425. int SENTENCEG_GetIndex(const char *szrootname);
  426. int SENTENCEG_Lookup(const char *sample);
  427. char TEXTURETYPE_Find( trace_t *ptr );
  428. void UTIL_EmitSoundSuit(edict_t *entity, const char *sample);
  429. int UTIL_EmitGroupIDSuit(edict_t *entity, int isentenceg);
  430. int UTIL_EmitGroupnameSuit(edict_t *entity, const char *groupname);
  431. void UTIL_RestartAmbientSounds( void );
  432. class EntityMatrix : public VMatrix
  433. {
  434. public:
  435. void InitFromEntity( CBaseEntity *pEntity, int iAttachment=0 );
  436. void InitFromEntityLocal( CBaseEntity *entity );
  437. inline Vector LocalToWorld( const Vector &vVec ) const
  438. {
  439. return VMul4x3( vVec );
  440. }
  441. inline Vector WorldToLocal( const Vector &vVec ) const
  442. {
  443. return VMul4x3Transpose( vVec );
  444. }
  445. inline Vector LocalToWorldRotation( const Vector &vVec ) const
  446. {
  447. return VMul3x3( vVec );
  448. }
  449. inline Vector WorldToLocalRotation( const Vector &vVec ) const
  450. {
  451. return VMul3x3Transpose( vVec );
  452. }
  453. };
  454. inline float UTIL_DistApprox( const Vector &vec1, const Vector &vec2 );
  455. inline float UTIL_DistApprox2D( const Vector &vec1, const Vector &vec2 );
  456. //---------------------------------------------------------
  457. //---------------------------------------------------------
  458. inline float UTIL_DistApprox( const Vector &vec1, const Vector &vec2 )
  459. {
  460. float dx;
  461. float dy;
  462. float dz;
  463. dx = vec1.x - vec2.x;
  464. dy = vec1.y - vec2.y;
  465. dz = vec1.z - vec2.z;
  466. return fabs(dx) + fabs(dy) + fabs(dz);
  467. }
  468. //---------------------------------------------------------
  469. //---------------------------------------------------------
  470. inline float UTIL_DistApprox2D( const Vector &vec1, const Vector &vec2 )
  471. {
  472. float dx;
  473. float dy;
  474. dx = vec1.x - vec2.x;
  475. dy = vec1.y - vec2.y;
  476. return fabs(dx) + fabs(dy);
  477. }
  478. // Find out if an entity is facing another entity or position within a given tolerance range
  479. bool UTIL_IsFacingWithinTolerance( CBaseEntity *pViewer, const Vector &vecPosition, float flDotTolerance, float *pflDot = NULL );
  480. bool UTIL_IsFacingWithinTolerance( CBaseEntity *pViewer, CBaseEntity *pTarget, float flDotTolerance, float *pflDot = NULL );
  481. void UTIL_GetDebugColorForRelationship( int nRelationship, int &r, int &g, int &b );
  482. struct datamap_t;
  483. extern const char *UTIL_FunctionToName( datamap_t *pMap, inputfunc_t *function );
  484. int UTIL_GetCommandClientIndex( void );
  485. CBasePlayer *UTIL_GetCommandClient( void );
  486. bool UTIL_GetModDir( char *lpszTextOut, unsigned int nSize );
  487. AngularImpulse WorldToLocalRotation( const VMatrix &localToWorld, const Vector &worldAxis, float rotation );
  488. void UTIL_WorldToParentSpace( CBaseEntity *pEntity, Vector &vecPosition, QAngle &vecAngles );
  489. void UTIL_WorldToParentSpace( CBaseEntity *pEntity, Vector &vecPosition, Quaternion &quat );
  490. void UTIL_ParentToWorldSpace( CBaseEntity *pEntity, Vector &vecPosition, QAngle &vecAngles );
  491. void UTIL_ParentToWorldSpace( CBaseEntity *pEntity, Vector &vecPosition, Quaternion &quat );
  492. bool UTIL_LoadAndSpawnEntitiesFromScript( CUtlVector <CBaseEntity*> &entities, const char *pScriptFile, const char *pBlock, bool bActivate = true );
  493. // Given a vector, clamps the scalar axes to MAX_COORD_FLOAT ranges from worldsize.h
  494. void UTIL_BoundToWorldSize( Vector *pVecPos );
  495. #endif // UTIL_H