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.

153 lines
3.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "game.h"
  10. #include "ai_looktarget.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. // Mothballing this entity to get rid of it. info_hint does its job better (sjb)
  14. //LINK_ENTITY_TO_CLASS( ai_looktarget, CAI_LookTarget );
  15. BEGIN_DATADESC( CAI_LookTarget )
  16. // Keyfields
  17. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "StartDisabled" ),
  18. DEFINE_KEYFIELD( m_iContext, FIELD_INTEGER, "context" ),
  19. DEFINE_KEYFIELD( m_iPriority, FIELD_INTEGER, "priority" ),
  20. DEFINE_KEYFIELD( m_flMaxDist, FIELD_FLOAT, "maxdist" ),
  21. // Fields
  22. DEFINE_FIELD( m_flTimeNextAvailable, FIELD_TIME ),
  23. END_DATADESC()
  24. //---------------------------------------------------------
  25. //---------------------------------------------------------
  26. int CAI_LookTarget::DrawDebugTextOverlays(void)
  27. {
  28. int text_offset = BaseClass::DrawDebugTextOverlays();
  29. if (m_debugOverlays & OVERLAY_BBOX_BIT)
  30. {
  31. int color = random->RandomInt( 50, 255 );
  32. NDebugOverlay::Cross3D( GetAbsOrigin(), 12, color, color, color, false, 0.1 );
  33. }
  34. if (m_debugOverlays & OVERLAY_TEXT_BIT)
  35. {
  36. char tempstr[512];
  37. if( !IsEnabled() )
  38. {
  39. Q_snprintf(tempstr,sizeof(tempstr),"DISABLED" );
  40. EntityText(text_offset,tempstr,0);
  41. text_offset++;
  42. }
  43. if( IsEligible( NULL ) )
  44. {
  45. Q_snprintf(tempstr,sizeof(tempstr),"Eligible" );
  46. EntityText(text_offset,tempstr,0);
  47. text_offset++;
  48. }
  49. else
  50. {
  51. Q_snprintf(tempstr,sizeof(tempstr),"NOT Eligible for selection");
  52. EntityText(text_offset,tempstr,0);
  53. text_offset++;
  54. }
  55. }
  56. return text_offset;
  57. }
  58. //---------------------------------------------------------
  59. //---------------------------------------------------------
  60. bool CAI_LookTarget::IsEligible( CBaseEntity *pLooker )
  61. {
  62. if( !IsEnabled() )
  63. return false;
  64. if( !IsAvailable() )
  65. return false;
  66. if( pLooker )
  67. {
  68. float maxdistsqr = m_flMaxDist * m_flMaxDist;
  69. Vector vecPos = GetAbsOrigin();
  70. if( vecPos.DistToSqr( pLooker->WorldSpaceCenter() ) > maxdistsqr )
  71. {
  72. return false;
  73. }
  74. }
  75. return true;
  76. }
  77. //---------------------------------------------------------
  78. // Someone's reserving this entity because they're going
  79. // to attempt to look at it for flDuration seconds. We'll
  80. // make it unavailable to anyone else for that time.
  81. //---------------------------------------------------------
  82. void CAI_LookTarget::Reserve( float flDuration )
  83. {
  84. m_flTimeNextAvailable = gpGlobals->curtime + flDuration;
  85. if( HasSpawnFlags( SF_LOOKTARGET_ONLYONCE ) )
  86. {
  87. // No one will look at this again.
  88. Disable();
  89. }
  90. }
  91. //---------------------------------------------------------
  92. //---------------------------------------------------------
  93. CAI_LookTarget *CAI_LookTarget::GetFirstLookTarget()
  94. {
  95. CBaseEntity *pEnt;
  96. string_t iszLookTarget = FindPooledString( "ai_looktarget" );
  97. if( iszLookTarget == NULL_STRING )
  98. {
  99. return NULL;
  100. }
  101. pEnt = gEntList.FirstEnt();
  102. while( pEnt && pEnt->m_iClassname != iszLookTarget )
  103. {
  104. pEnt = gEntList.NextEnt( pEnt );
  105. }
  106. return (CAI_LookTarget*)pEnt;
  107. }
  108. //---------------------------------------------------------
  109. //---------------------------------------------------------
  110. CAI_LookTarget *CAI_LookTarget::GetNextLookTarget( CAI_LookTarget *pCurrentTarget )
  111. {
  112. CBaseEntity *pEnt;
  113. string_t iszLookTarget = FindPooledString( "ai_looktarget" );
  114. if( iszLookTarget == NULL_STRING )
  115. {
  116. return NULL;
  117. }
  118. pEnt = gEntList.NextEnt( pCurrentTarget );
  119. while( pEnt && pEnt->m_iClassname != iszLookTarget )
  120. {
  121. pEnt = gEntList.NextEnt( pEnt );
  122. }
  123. return (CAI_LookTarget*)pEnt;
  124. }