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.

170 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "ai_goal_police.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. // ai_goal_police
  11. // Used by police to define a region they should keep a target outside of
  12. LINK_ENTITY_TO_CLASS( ai_goal_police, CAI_PoliceGoal );
  13. BEGIN_DATADESC( CAI_PoliceGoal )
  14. DEFINE_KEYFIELD( m_flRadius, FIELD_FLOAT, "PoliceRadius" ),
  15. DEFINE_KEYFIELD( m_iszTarget, FIELD_STRING, "PoliceTarget" ),
  16. DEFINE_FIELD( m_bOverrideKnockOut, FIELD_BOOLEAN ),
  17. // m_hTarget
  18. DEFINE_INPUTFUNC( FIELD_VOID, "EnableKnockOut", InputEnableKnockOut ),
  19. DEFINE_INPUTFUNC( FIELD_VOID, "DisableKnockOut", InputDisableKnockOut ),
  20. DEFINE_OUTPUT( m_OnKnockOut, "OnKnockOut" ),
  21. DEFINE_OUTPUT( m_OnFirstWarning, "OnFirstWarning" ),
  22. DEFINE_OUTPUT( m_OnSecondWarning, "OnSecondWarning" ),
  23. DEFINE_OUTPUT( m_OnLastWarning, "OnLastWarning" ),
  24. DEFINE_OUTPUT( m_OnSupressingTarget,"OnSupressingTarget" ),
  25. END_DATADESC()
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. CAI_PoliceGoal::CAI_PoliceGoal( void )
  30. {
  31. m_hTarget = NULL;
  32. m_bOverrideKnockOut = false;
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. // Output : float
  37. //-----------------------------------------------------------------------------
  38. float CAI_PoliceGoal::GetRadius( void )
  39. {
  40. return m_flRadius;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. // Output : CBaseEntity
  45. //-----------------------------------------------------------------------------
  46. CBaseEntity *CAI_PoliceGoal::GetTarget( void )
  47. {
  48. if ( m_hTarget == NULL )
  49. {
  50. CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, m_iszTarget );
  51. if ( pTarget == NULL )
  52. {
  53. DevMsg( "Unable to find ai_goal_police target: %s\n", STRING(m_iszTarget) );
  54. return NULL;
  55. }
  56. m_hTarget = pTarget;
  57. }
  58. return m_hTarget;
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. // Input : &targetPos -
  63. // Output : Returns true on success, false on failure.
  64. //-----------------------------------------------------------------------------
  65. bool CAI_PoliceGoal::ShouldKnockOutTarget( const Vector &targetPos, bool bTargetVisible )
  66. {
  67. if ( m_bOverrideKnockOut )
  68. return true;
  69. // Must be flagged to do it
  70. if ( HasSpawnFlags( SF_POLICE_GOAL_KNOCKOUT_BEHIND ) == false )
  71. return false;
  72. // If the target's not visible, we don't care about him
  73. if ( !bTargetVisible )
  74. return false;
  75. Vector targetDir = targetPos - GetAbsOrigin();
  76. VectorNormalize( targetDir );
  77. Vector facingDir;
  78. AngleVectors( GetAbsAngles(), &facingDir );
  79. // See if it's behind us
  80. if ( DotProduct( facingDir, targetDir ) < 0 )
  81. return true;
  82. return false;
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. // Input : *pTarget -
  87. //-----------------------------------------------------------------------------
  88. void CAI_PoliceGoal::KnockOutTarget( CBaseEntity *pTarget )
  89. {
  90. m_OnKnockOut.FireOutput( pTarget, this );
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose:
  94. // Output : Returns true on success, false on failure.
  95. //-----------------------------------------------------------------------------
  96. bool CAI_PoliceGoal::ShouldRemainAtPost( void )
  97. {
  98. return HasSpawnFlags( SF_POLICE_GOAL_DO_NOT_LEAVE_POST );
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. // Input : level -
  103. //-----------------------------------------------------------------------------
  104. void CAI_PoliceGoal::FireWarningLevelOutput( int level )
  105. {
  106. switch( level )
  107. {
  108. case 1:
  109. m_OnFirstWarning.FireOutput( this, this );
  110. break;
  111. case 2:
  112. m_OnSecondWarning.FireOutput( this, this );
  113. break;
  114. case 3:
  115. m_OnLastWarning.FireOutput( this, this );
  116. break;
  117. default:
  118. m_OnSupressingTarget.FireOutput( this, this );
  119. break;
  120. }
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. // Input : &data -
  125. //-----------------------------------------------------------------------------
  126. void CAI_PoliceGoal::InputEnableKnockOut( inputdata_t &data )
  127. {
  128. m_bOverrideKnockOut = true;
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose:
  132. // Input : &data -
  133. //-----------------------------------------------------------------------------
  134. void CAI_PoliceGoal::InputDisableKnockOut( inputdata_t &data )
  135. {
  136. m_bOverrideKnockOut = false;
  137. }