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.

132 lines
3.8 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_achievement.h"
  10. LINK_ENTITY_TO_CLASS( func_achievement, CAchievementZone );
  11. //=============================================================================
  12. //
  13. // CTF Achievement Zone functions.
  14. //
  15. BEGIN_DATADESC( CAchievementZone )
  16. DEFINE_KEYFIELD( m_iZoneID, FIELD_INTEGER, "zone_id" ),
  17. END_DATADESC()
  18. //-----------------------------------------------------------------------------
  19. // Purpose:
  20. //-----------------------------------------------------------------------------
  21. CAchievementZone::CAchievementZone()
  22. {
  23. m_bDisabled = false;
  24. m_iZoneID = 0;
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Spawn function for the entity
  28. //-----------------------------------------------------------------------------
  29. void CAchievementZone::Spawn( void )
  30. {
  31. Precache();
  32. BaseClass::Spawn();
  33. InitTrigger();
  34. AddSpawnFlags( SF_TRIGGER_ALLOW_ALL ); // so we can keep track of who is touching us
  35. AddEffects( EF_NODRAW );
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. //-----------------------------------------------------------------------------
  40. void CAchievementZone::Precache( void )
  41. {
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Return true if the specified entity is touching this zone
  45. //-----------------------------------------------------------------------------
  46. bool CAchievementZone::IsTouching( const CBaseEntity *pEntity ) const
  47. {
  48. return BaseClass::IsTouching( pEntity );
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. void CAchievementZone::InputEnable( inputdata_t &inputdata )
  54. {
  55. SetDisabled( false );
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. void CAchievementZone::InputDisable( inputdata_t &inputdata )
  61. {
  62. SetDisabled( true );
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose:
  66. //-----------------------------------------------------------------------------
  67. bool CAchievementZone::IsDisabled( void )
  68. {
  69. return m_bDisabled;
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose:
  73. //-----------------------------------------------------------------------------
  74. void CAchievementZone::InputToggle( inputdata_t &inputdata )
  75. {
  76. if ( m_bDisabled )
  77. {
  78. SetDisabled( false );
  79. }
  80. else
  81. {
  82. SetDisabled( true );
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. void CAchievementZone::SetDisabled( bool bDisabled )
  89. {
  90. m_bDisabled = bDisabled;
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Return true if the specified entity is in an Achievement zone
  94. //-----------------------------------------------------------------------------
  95. CAchievementZone *InAchievementZone( CBaseEntity *pEntity )
  96. {
  97. if ( pEntity )
  98. {
  99. CBaseEntity *pTempEnt = NULL;
  100. while ( ( pTempEnt = gEntList.FindEntityByClassname( pTempEnt, "func_achievement" ) ) != NULL )
  101. {
  102. CAchievementZone *pZone = dynamic_cast<CAchievementZone *>( pTempEnt );
  103. if ( !pZone->IsDisabled() && pZone->PointIsWithin( pEntity->GetAbsOrigin() ) )
  104. {
  105. int iTeam = pZone->GetTeamNumber();
  106. if ( !iTeam || ( iTeam && ( pEntity->GetTeamNumber() == iTeam ) ) )
  107. {
  108. return pZone;
  109. }
  110. }
  111. }
  112. }
  113. return NULL;
  114. }