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.

161 lines
3.7 KiB

  1. // NextBotAttentionInterface.cpp
  2. // Manage what this bot pays attention to
  3. // Author: Michael Booth, April 2007
  4. // Copyright (c) 2007 Turtle Rock Studios, Inc. - All Rights Reserved
  5. #include "cbase.h"
  6. #include "NextBot.h"
  7. #include "NextBotAttentionInterface.h"
  8. #include "NextBotBodyInterface.h"
  9. #include "tier0/vprof.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //------------------------------------------------------------------------------------------
  13. /**
  14. * Reset to initial state
  15. */
  16. void IAttention::Reset( void )
  17. {
  18. m_body = GetBot()->GetBodyInterface();
  19. m_attentionSet.RemoveAll();
  20. }
  21. //------------------------------------------------------------------------------------------
  22. /**
  23. * Update internal state
  24. */
  25. void IAttention::Update( void )
  26. {
  27. }
  28. //------------------------------------------------------------------------------------------
  29. void IAttention::AttendTo( const CBaseCombatCharacter *who, const char *reason )
  30. {
  31. if ( !IsAwareOf( who ) )
  32. {
  33. PointOfInterest p;
  34. p.m_type = PointOfInterest::WHO;
  35. p.m_who = who;
  36. p.m_duration.Start();
  37. m_attentionSet.AddToTail( p );
  38. }
  39. }
  40. //------------------------------------------------------------------------------------------
  41. void IAttention::AttendTo( const CBaseEntity *what, const char *reason )
  42. {
  43. if ( !IsAwareOf( what ) )
  44. {
  45. PointOfInterest p;
  46. p.m_type = PointOfInterest::WHAT;
  47. p.m_what = what;
  48. p.m_duration.Start();
  49. m_attentionSet.AddToTail( p );
  50. }
  51. }
  52. //------------------------------------------------------------------------------------------
  53. void IAttention::AttendTo( const Vector &where, IAttention::SignificanceLevel significance, const char *reason )
  54. {
  55. PointOfInterest p;
  56. p.m_type = PointOfInterest::WHERE;
  57. p.m_where = where;
  58. p.m_duration.Start();
  59. m_attentionSet.AddToTail( p );
  60. }
  61. //------------------------------------------------------------------------------------------
  62. void IAttention::Disregard( const CBaseCombatCharacter *who, const char *reason )
  63. {
  64. FOR_EACH_VEC( m_attentionSet, it )
  65. {
  66. if ( m_attentionSet[ it ].m_type == PointOfInterest::WHO )
  67. {
  68. CBaseCombatCharacter *myWho = m_attentionSet[ it ].m_who;
  69. if ( !myWho || myWho->entindex() == who->entindex() )
  70. {
  71. m_attentionSet.Remove( it );
  72. return;
  73. }
  74. }
  75. }
  76. }
  77. //------------------------------------------------------------------------------------------
  78. void IAttention::Disregard( const CBaseEntity *what, const char *reason )
  79. {
  80. FOR_EACH_VEC( m_attentionSet, it )
  81. {
  82. if ( m_attentionSet[ it ].m_type == PointOfInterest::WHAT )
  83. {
  84. CBaseCombatCharacter *myWhat = m_attentionSet[ it ].m_what;
  85. if ( !myWhat || myWhat->entindex() == what->entindex() )
  86. {
  87. m_attentionSet.Remove( it );
  88. return;
  89. }
  90. }
  91. }
  92. }
  93. //------------------------------------------------------------------------------------------
  94. /**
  95. * Return true if given actor is in our attending set
  96. */
  97. bool IAttention::IsAwareOf( const CBaseCombatCharacter *who ) const
  98. {
  99. FOR_EACH_VEC( m_attentionSet, it )
  100. {
  101. if ( m_attentionSet[ it ].m_type == PointOfInterest::WHO )
  102. {
  103. CBaseCombatCharacter *myWho = m_attentionSet[ it ].m_who;
  104. if ( myWho && myWho->entindex() == who->entindex() )
  105. {
  106. return true;
  107. }
  108. }
  109. }
  110. return false;
  111. }
  112. //------------------------------------------------------------------------------------------
  113. /**
  114. * Return true if given object is in our attending set
  115. */
  116. bool IAttention::IsAwareOf( const CBaseEntity *what ) const
  117. {
  118. FOR_EACH_VEC( m_attentionSet, it )
  119. {
  120. if ( m_attentionSet[ it ].m_type == PointOfInterest::WHAT )
  121. {
  122. CBaseEntity *myWhat = m_attentionSet[ it ].m_what;
  123. if ( myWhat && myWhat->entindex() == what->entindex() )
  124. {
  125. return true;
  126. }
  127. }
  128. }
  129. return false;
  130. }