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.

172 lines
5.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BOT_UTIL_H
  8. #define BOT_UTIL_H
  9. #include "convar.h"
  10. #include "util.h"
  11. //--------------------------------------------------------------------------------------------------------------
  12. enum PriorityType
  13. {
  14. PRIORITY_LOW, PRIORITY_MEDIUM, PRIORITY_HIGH, PRIORITY_UNINTERRUPTABLE
  15. };
  16. extern ConVar cv_bot_traceview;
  17. extern ConVar cv_bot_stop;
  18. extern ConVar cv_bot_show_nav;
  19. extern ConVar cv_bot_walk;
  20. extern ConVar cv_bot_difficulty;
  21. extern ConVar cv_bot_debug;
  22. extern ConVar cv_bot_debug_target;
  23. extern ConVar cv_bot_quota;
  24. extern ConVar cv_bot_quota_mode;
  25. extern ConVar cv_bot_prefix;
  26. extern ConVar cv_bot_allow_rogues;
  27. extern ConVar cv_bot_allow_pistols;
  28. extern ConVar cv_bot_allow_shotguns;
  29. extern ConVar cv_bot_allow_sub_machine_guns;
  30. extern ConVar cv_bot_allow_rifles;
  31. extern ConVar cv_bot_allow_machine_guns;
  32. extern ConVar cv_bot_allow_grenades;
  33. extern ConVar cv_bot_allow_snipers;
  34. extern ConVar cv_bot_allow_shield;
  35. extern ConVar cv_bot_join_team;
  36. extern ConVar cv_bot_join_after_player;
  37. extern ConVar cv_bot_auto_vacate;
  38. extern ConVar cv_bot_zombie;
  39. extern ConVar cv_bot_defer_to_human_goals;
  40. extern ConVar cv_bot_defer_to_human_items;
  41. extern ConVar cv_bot_chatter;
  42. extern ConVar cv_bot_profile_db;
  43. extern ConVar cv_bot_dont_shoot;
  44. extern ConVar cv_bot_eco_limit;
  45. extern ConVar cv_bot_auto_follow;
  46. extern ConVar cv_bot_flipout;
  47. #if CS_CONTROLLABLE_BOTS_ENABLED
  48. extern ConVar cv_bot_controllable;
  49. #endif
  50. #define RAD_TO_DEG( deg ) ((deg) * 180.0 / M_PI)
  51. #define DEG_TO_RAD( rad ) ((rad) * M_PI / 180.0)
  52. #define SIGN( num ) (((num) < 0) ? -1 : 1)
  53. #define ABS( num ) (SIGN(num) * (num))
  54. #define CREATE_FAKE_CLIENT ( *g_engfuncs.pfnCreateFakeClient )
  55. #define GET_USERINFO ( *g_engfuncs.pfnGetInfoKeyBuffer )
  56. #define SET_KEY_VALUE ( *g_engfuncs.pfnSetKeyValue )
  57. #define SET_CLIENT_KEY_VALUE ( *g_engfuncs.pfnSetClientKeyValue )
  58. class BotProfile;
  59. extern void BotPrecache( void );
  60. extern int UTIL_ClientsInGame( void );
  61. extern bool UTIL_IsNameTaken( const char *name, bool ignoreHumans = false ); ///< return true if given name is already in use by another player
  62. #define IS_ALIVE true
  63. extern int UTIL_HumansOnTeam( int teamID, bool isAlive = false );
  64. extern int UTIL_BotsInGame( void );
  65. extern bool UTIL_IsTeamAllBots( int team );
  66. extern void UTIL_DrawBeamFromEnt( int iIndex, Vector vecEnd, int iLifetime, byte bRed, byte bGreen, byte bBlue );
  67. extern void UTIL_DrawBeamPoints( Vector vecStart, Vector vecEnd, int iLifetime, byte bRed, byte bGreen, byte bBlue );
  68. extern CBasePlayer *UTIL_GetClosestPlayer( const Vector &pos, float *distance = NULL );
  69. extern CBasePlayer *UTIL_GetClosestPlayer( const Vector &pos, int team, float *distance = NULL );
  70. extern bool UTIL_KickBotFromTeam( int kickTeam, bool bQueue = false ); ///< kick a bot from the given team. If no bot exists on the team, return false, if bQueue is true kick will occur at round restart
  71. extern bool UTIL_IsVisibleToTeam( const Vector &spot, int team ); ///< return true if anyone on the given team can see the given spot
  72. extern bool UTIL_IsRandomSpawnFarEnoughAwayFromTeam( const Vector &spot, int team ); ///< return true if this spot is far enough away from everyone on specified team defined via
  73. /// return true if moving from "start" to "finish" will cross a player's line of fire.
  74. extern bool IsCrossingLineOfFire( const Vector &start, const Vector &finish, CBaseEntity *ignore = NULL, int ignoreTeam = 0 );
  75. extern void UTIL_ConstructBotNetName(char *name, int nameLength, const BotProfile *bot); ///< constructs a complete name including prefix
  76. /**
  77. * Echos text to the console, and prints it on the client's screen. This is NOT tied to the developer cvar.
  78. * If you are adding debugging output in cstrike, use UTIL_DPrintf() (debug.h) instead.
  79. */
  80. extern void CONSOLE_ECHO( char * pszMsg, ... );
  81. extern void InitBotTrig( void );
  82. extern float BotCOS( float angle );
  83. extern float BotSIN( float angle );
  84. extern void HintMessageToAllPlayers( const char *message );
  85. bool WildcardMatch( const char *query, const char *test ); ///< Performs a simple case-insensitive string comparison, honoring trailing * wildcards
  86. //--------------------------------------------------------------------------------------------------------------
  87. /**
  88. * Return true if the given entity is valid
  89. */
  90. inline bool IsEntityValid( CBaseEntity *entity )
  91. {
  92. if (entity == NULL)
  93. return false;
  94. if (FNullEnt( entity->edict() ))
  95. return false;
  96. return true;
  97. }
  98. //--------------------------------------------------------------------------------------------------------------
  99. /**
  100. * Given two line segments: startA to endA, and startB to endB, return true if they intesect
  101. * and put the intersection point in "result".
  102. * Note that this computes the intersection of the 2D (x,y) projection of the line segments.
  103. */
  104. inline bool IsIntersecting2D( const Vector &startA, const Vector &endA,
  105. const Vector &startB, const Vector &endB,
  106. Vector *result = NULL )
  107. {
  108. float denom = (endA.x - startA.x) * (endB.y - startB.y) - (endA.y - startA.y) * (endB.x - startB.x);
  109. if (denom == 0.0f)
  110. {
  111. // parallel
  112. return false;
  113. }
  114. float numS = (startA.y - startB.y) * (endB.x - startB.x) - (startA.x - startB.x) * (endB.y - startB.y);
  115. if (numS == 0.0f)
  116. {
  117. // coincident
  118. return true;
  119. }
  120. float numT = (startA.y - startB.y) * (endA.x - startA.x) - (startA.x - startB.x) * (endA.y - startA.y);
  121. float s = numS / denom;
  122. if (s < 0.0f || s > 1.0f)
  123. {
  124. // intersection is not within line segment of startA to endA
  125. return false;
  126. }
  127. float t = numT / denom;
  128. if (t < 0.0f || t > 1.0f)
  129. {
  130. // intersection is not within line segment of startB to endB
  131. return false;
  132. }
  133. // compute intesection point
  134. if (result)
  135. *result = startA + s * (endA - startA);
  136. return true;
  137. }
  138. #endif