text: // Copyright © 1996-2018, Valve Corporation, All rights reserved.
  //
  // Purpose: 
  //
  // $NoKeywords: $
  //
  
  #include "cbase.h"
  #include "func_no_build.h"
  #include "tf_team.h"
  #include "ndebugoverlay.h"
  #include "tf_obj.h"
  #include "triggers.h"
  
   
  #include "tier0/include/memdbgon.h"
  
  //-----------------------------------------------------------------------------
  // Purpose: Defines an area where objects cannot be built
  //-----------------------------------------------------------------------------
  class CFuncNoBuild : public CBaseTrigger
  {
  	DECLARE_CLASS( CFuncNoBuild, CBaseTrigger );
  public:
  	CFuncNoBuild();
  
  	DECLARE_DATADESC();
  
  	virtual void Spawn( void );
  	virtual void Precache( void );
  	virtual void Activate( void );
  
  	// Inputs
  	void	InputSetActive( inputdata_t &inputdata );
  	void	InputSetInactive( inputdata_t &inputdata );
  	void	InputToggleActive( inputdata_t &inputdata );
  
  	void	SetActive( bool bActive );
  	bool	GetActive() const;
  
  	//bool	IsEmpty( void );
  	bool	PointIsWithin( const Vector &vecPoint );
  	bool	PreventsBuildOf( int iObjectType );
  
  private:
  	bool	m_bActive;
  };
  
  LINK_ENTITY_TO_CLASS( func_nobuild, CFuncNoBuild);
  
  BEGIN_DATADESC( CFuncNoBuild )
  
  	// inputs
  	DEFINE_INPUTFUNC( FIELD_VOID, "SetActive", InputSetActive ),
  	DEFINE_INPUTFUNC( FIELD_VOID, "SetInactive", InputSetInactive ),
  	DEFINE_INPUTFUNC( FIELD_VOID, "ToggleActive", InputToggleActive ),
  
  END_DATADESC()
  
  
  PRECACHE_REGISTER( func_nobuild );
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  CFuncNoBuild::CFuncNoBuild()
  {
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: Initializes the resource zone
  //-----------------------------------------------------------------------------
  void CFuncNoBuild::Spawn( void )
  {
  	BaseClass::Spawn();
  	InitTrigger();
  
  	m_bActive = true;
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  void CFuncNoBuild::Precache( void )
  {
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  void CFuncNoBuild::Activate( void )
  {
  	BaseClass::Activate();
  	SetActive( true );
  }
  
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  void CFuncNoBuild::InputSetActive( inputdata_t &inputdata )
  {
  	SetActive( true );
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  void CFuncNoBuild::InputSetInactive( inputdata_t &inputdata )
  {
  	SetActive( false );
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  void CFuncNoBuild::InputToggleActive( inputdata_t &inputdata )
  {
  	if ( m_bActive )
  	{
  		SetActive( false );
  	}
  	else
  	{
  		SetActive( true );
  	}
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  void CFuncNoBuild::SetActive( bool bActive )
  {
  	m_bActive = bActive;
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: 
  //-----------------------------------------------------------------------------
  bool CFuncNoBuild::GetActive() const
  {
  	return m_bActive;
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: Return true if the specified point is within this zone
  //-----------------------------------------------------------------------------
  bool CFuncNoBuild::PointIsWithin( const Vector &vecPoint )
  {
  	Ray_t ray;
  	trace_t tr;
  	ICollideable *pCollide = CollisionProp();
  	ray.Init( vecPoint, vecPoint );
  	enginetrace->ClipRayToCollideable( ray, MASK_ALL, pCollide, &tr );
  	return ( tr.startsolid );
  }
  
  //-----------------------------------------------------------------------------
  // Purpose: Does a nobuild zone prevent us from building?
  //-----------------------------------------------------------------------------
  bool PointInNoBuild( const Vector &vecBuildOrigin )
  {
  	// Find out whether we're in a resource zone or not
  	CBaseEntity *pEntity = NULL;
  	while ((pEntity = gEntList.FindEntityByClassname( pEntity, "func_nobuild" )) != NULL)
  	{
  		CFuncNoBuild *pNoBuild = (CFuncNoBuild *)pEntity;
  
  		// Are we within this no build?
  		if ( pNoBuild->GetActive() && pNoBuild->PointIsWithin( vecBuildOrigin ) )
  		{
  			return true;	// prevent building.
  		}
  	}
  
  	return false; // Building should be ok.
  }
  