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.

167 lines
5.5 KiB

  1. //========= Copyright 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;
  40. extern ConVar cv_bot_chatter;
  41. extern ConVar cv_bot_profile_db;
  42. extern ConVar cv_bot_dont_shoot;
  43. extern ConVar cv_bot_eco_limit;
  44. extern ConVar cv_bot_auto_follow;
  45. extern ConVar cv_bot_flipout;
  46. #define RAD_TO_DEG( deg ) ((deg) * 180.0 / M_PI)
  47. #define DEG_TO_RAD( rad ) ((rad) * M_PI / 180.0)
  48. #define SIGN( num ) (((num) < 0) ? -1 : 1)
  49. #define ABS( num ) (SIGN(num) * (num))
  50. #define CREATE_FAKE_CLIENT ( *g_engfuncs.pfnCreateFakeClient )
  51. #define GET_USERINFO ( *g_engfuncs.pfnGetInfoKeyBuffer )
  52. #define SET_KEY_VALUE ( *g_engfuncs.pfnSetKeyValue )
  53. #define SET_CLIENT_KEY_VALUE ( *g_engfuncs.pfnSetClientKeyValue )
  54. class BotProfile;
  55. extern void BotPrecache( void );
  56. extern int UTIL_ClientsInGame( void );
  57. extern bool UTIL_IsNameTaken( const char *name, bool ignoreHumans = false ); ///< return true if given name is already in use by another player
  58. #define IS_ALIVE true
  59. extern int UTIL_HumansOnTeam( int teamID, bool isAlive = false );
  60. extern int UTIL_BotsInGame( void );
  61. extern bool UTIL_IsTeamAllBots( int team );
  62. extern void UTIL_DrawBeamFromEnt( int iIndex, Vector vecEnd, int iLifetime, byte bRed, byte bGreen, byte bBlue );
  63. extern void UTIL_DrawBeamPoints( Vector vecStart, Vector vecEnd, int iLifetime, byte bRed, byte bGreen, byte bBlue );
  64. extern CBasePlayer *UTIL_GetClosestPlayer( const Vector &pos, float *distance = NULL );
  65. extern CBasePlayer *UTIL_GetClosestPlayer( const Vector &pos, int team, float *distance = NULL );
  66. extern bool UTIL_KickBotFromTeam( int kickTeam ); ///< kick a bot from the given team. If no bot exists on the team, return false.
  67. extern bool UTIL_IsVisibleToTeam( const Vector &spot, int team ); ///< return true if anyone on the given team can see the given spot
  68. /// return true if moving from "start" to "finish" will cross a player's line of fire.
  69. extern bool IsCrossingLineOfFire( const Vector &start, const Vector &finish, CBaseEntity *ignore = NULL, int ignoreTeam = 0 );
  70. extern void UTIL_ConstructBotNetName(char *name, int nameLength, const BotProfile *bot); ///< constructs a complete name including prefix
  71. /**
  72. * Echos text to the console, and prints it on the client's screen. This is NOT tied to the developer cvar.
  73. * If you are adding debugging output in cstrike, use UTIL_DPrintf() (debug.h) instead.
  74. */
  75. extern void CONSOLE_ECHO( PRINTF_FORMAT_STRING const char * pszMsg, ... );
  76. extern void InitBotTrig( void );
  77. extern float BotCOS( float angle );
  78. extern float BotSIN( float angle );
  79. extern void HintMessageToAllPlayers( const char *message );
  80. bool WildcardMatch( const char *query, const char *test ); ///< Performs a simple case-insensitive string comparison, honoring trailing * wildcards
  81. //--------------------------------------------------------------------------------------------------------------
  82. /**
  83. * Return true if the given entity is valid
  84. */
  85. inline bool IsEntityValid( CBaseEntity *entity )
  86. {
  87. if (entity == NULL)
  88. return false;
  89. if (FNullEnt( entity->edict() ))
  90. return false;
  91. return true;
  92. }
  93. //--------------------------------------------------------------------------------------------------------------
  94. /**
  95. * Given two line segments: startA to endA, and startB to endB, return true if they intesect
  96. * and put the intersection point in "result".
  97. * Note that this computes the intersection of the 2D (x,y) projection of the line segments.
  98. */
  99. inline bool IsIntersecting2D( const Vector &startA, const Vector &endA,
  100. const Vector &startB, const Vector &endB,
  101. Vector *result = NULL )
  102. {
  103. float denom = (endA.x - startA.x) * (endB.y - startB.y) - (endA.y - startA.y) * (endB.x - startB.x);
  104. if (denom == 0.0f)
  105. {
  106. // parallel
  107. return false;
  108. }
  109. float numS = (startA.y - startB.y) * (endB.x - startB.x) - (startA.x - startB.x) * (endB.y - startB.y);
  110. if (numS == 0.0f)
  111. {
  112. // coincident
  113. return true;
  114. }
  115. float numT = (startA.y - startB.y) * (endA.x - startA.x) - (startA.x - startB.x) * (endA.y - startA.y);
  116. float s = numS / denom;
  117. if (s < 0.0f || s > 1.0f)
  118. {
  119. // intersection is not within line segment of startA to endA
  120. return false;
  121. }
  122. float t = numT / denom;
  123. if (t < 0.0f || t > 1.0f)
  124. {
  125. // intersection is not within line segment of startB to endB
  126. return false;
  127. }
  128. // compute intesection point
  129. if (result)
  130. *result = startA + s * (endA - startA);
  131. return true;
  132. }
  133. #endif