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.

127 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CTF NoGrenades Zone.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf_player.h"
  8. #include "tf_item.h"
  9. #include "func_nogrenades.h"
  10. LINK_ENTITY_TO_CLASS( func_nogrenades, CNoGrenadesZone );
  11. //=============================================================================
  12. //
  13. // CTF NoGrenades Zone functions.
  14. //
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. //-----------------------------------------------------------------------------
  18. CNoGrenadesZone::CNoGrenadesZone()
  19. {
  20. m_bDisabled = false;
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Spawn function for the entity
  24. //-----------------------------------------------------------------------------
  25. void CNoGrenadesZone::Spawn( void )
  26. {
  27. Precache();
  28. BaseClass::Spawn();
  29. InitTrigger();
  30. AddSpawnFlags( SF_TRIGGER_ALLOW_ALL ); // so we can keep track of who is touching us
  31. AddEffects( EF_NODRAW );
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void CNoGrenadesZone::Precache( void )
  37. {
  38. PrecacheModel( NOGRENADE_SPRITE );
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: Return true if the specified entity is touching this zone
  42. //-----------------------------------------------------------------------------
  43. bool CNoGrenadesZone::IsTouching( const CBaseEntity *pEntity ) const
  44. {
  45. return BaseClass::IsTouching( pEntity );
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. //-----------------------------------------------------------------------------
  50. void CNoGrenadesZone::InputEnable( inputdata_t &inputdata )
  51. {
  52. SetDisabled( false );
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose:
  56. //-----------------------------------------------------------------------------
  57. void CNoGrenadesZone::InputDisable( inputdata_t &inputdata )
  58. {
  59. SetDisabled( true );
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. //-----------------------------------------------------------------------------
  64. bool CNoGrenadesZone::IsDisabled( void )
  65. {
  66. return m_bDisabled;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. void CNoGrenadesZone::InputToggle( inputdata_t &inputdata )
  72. {
  73. if ( m_bDisabled )
  74. {
  75. SetDisabled( false );
  76. }
  77. else
  78. {
  79. SetDisabled( true );
  80. }
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose:
  84. //-----------------------------------------------------------------------------
  85. void CNoGrenadesZone::SetDisabled( bool bDisabled )
  86. {
  87. m_bDisabled = bDisabled;
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose: Return true if the specified entity is in a NoGrenades zone
  91. //-----------------------------------------------------------------------------
  92. bool InNoGrenadeZone( CBaseEntity *pEntity )
  93. {
  94. if ( pEntity )
  95. {
  96. CBaseEntity *pTempEnt = NULL;
  97. while ( ( pTempEnt = gEntList.FindEntityByClassname( pTempEnt, "func_nogrenades" ) ) != NULL )
  98. {
  99. CNoGrenadesZone *pZone = dynamic_cast<CNoGrenadesZone *>( pTempEnt );
  100. if ( !pZone->IsDisabled() && pZone->PointIsWithin( pEntity->GetAbsOrigin() ) )
  101. {
  102. int iTeam = pZone->GetTeamNumber();
  103. if ( !iTeam || ( iTeam && ( pEntity->GetTeamNumber() == iTeam ) ) )
  104. {
  105. return true;
  106. }
  107. }
  108. }
  109. }
  110. return false;
  111. }