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.

191 lines
4.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: area portal entity: toggles visibility areas on/off
  4. //
  5. // NOTE: These are not really brush entities. They are brush entities from a
  6. // designer/worldcraft perspective, but by the time they reach the game, the
  7. // brush model is gone and this is, in effect, a point entity.
  8. //
  9. // $NoKeywords: $
  10. //=============================================================================//
  11. #include "cbase.h"
  12. #include "func_areaportalbase.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. enum areaportal_state
  16. {
  17. AREAPORTAL_CLOSED = 0,
  18. AREAPORTAL_OPEN = 1,
  19. };
  20. class CAreaPortal : public CFuncAreaPortalBase
  21. {
  22. public:
  23. DECLARE_CLASS( CAreaPortal, CFuncAreaPortalBase );
  24. CAreaPortal();
  25. virtual void Spawn( void );
  26. virtual void Precache( void );
  27. virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  28. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  29. virtual int UpdateTransmitState();
  30. // Input handlers
  31. void InputOpen( inputdata_t &inputdata );
  32. void InputClose( inputdata_t &inputdata );
  33. void InputToggle( inputdata_t &inputdata );
  34. virtual bool UpdateVisibility( const CUtlVector< Vector > &vecOrigins, float fovDistanceAdjustFactor, bool &bIsOpenOnClient );
  35. DECLARE_DATADESC();
  36. private:
  37. bool UpdateState( void );
  38. int m_state;
  39. };
  40. LINK_ENTITY_TO_CLASS( func_areaportal, CAreaPortal );
  41. BEGIN_DATADESC( CAreaPortal )
  42. DEFINE_KEYFIELD( m_portalNumber, FIELD_INTEGER, "portalnumber" ),
  43. DEFINE_FIELD( m_state, FIELD_INTEGER ),
  44. // Inputs
  45. DEFINE_INPUTFUNC( FIELD_VOID, "Open", InputOpen ),
  46. DEFINE_INPUTFUNC( FIELD_VOID, "Close", InputClose ),
  47. DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),
  48. // TODO: obsolete! remove
  49. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn", InputClose ),
  50. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOff", InputOpen ),
  51. END_DATADESC()
  52. CAreaPortal::CAreaPortal()
  53. {
  54. m_state = AREAPORTAL_OPEN;
  55. }
  56. void CAreaPortal::Spawn( void )
  57. {
  58. AddEffects( EF_NORECEIVESHADOW | EF_NOSHADOW );
  59. Precache();
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose: notify the engine of the state at startup/restore
  63. //-----------------------------------------------------------------------------
  64. void CAreaPortal::Precache( void )
  65. {
  66. UpdateState();
  67. }
  68. //------------------------------------------------------------------------------
  69. // Purpose :
  70. //------------------------------------------------------------------------------
  71. void CAreaPortal::InputClose( inputdata_t &inputdata )
  72. {
  73. m_state = AREAPORTAL_CLOSED;
  74. UpdateState();
  75. }
  76. //------------------------------------------------------------------------------
  77. // Purpose :
  78. //------------------------------------------------------------------------------
  79. void CAreaPortal::InputOpen( inputdata_t &inputdata )
  80. {
  81. m_state = AREAPORTAL_OPEN;
  82. UpdateState();
  83. }
  84. //------------------------------------------------------------------------------
  85. // Purpose :
  86. //------------------------------------------------------------------------------
  87. void CAreaPortal::InputToggle( inputdata_t &inputdata )
  88. {
  89. m_state = ((m_state == AREAPORTAL_OPEN) ? AREAPORTAL_CLOSED : AREAPORTAL_OPEN);
  90. UpdateState();
  91. }
  92. bool CAreaPortal::UpdateVisibility( const CUtlVector< Vector > &vecOrigins, float fovDistanceAdjustFactor, bool &bIsOpenOnClient )
  93. {
  94. if ( m_state )
  95. {
  96. // We're not closed, so give the base class a chance to close it.
  97. return BaseClass::UpdateVisibility( vecOrigins, fovDistanceAdjustFactor, bIsOpenOnClient );
  98. }
  99. else
  100. {
  101. bIsOpenOnClient = false;
  102. return false;
  103. }
  104. }
  105. //------------------------------------------------------------------------------
  106. // Purpose :
  107. // Input :
  108. // Output :
  109. //------------------------------------------------------------------------------
  110. void CAreaPortal::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
  111. {
  112. if ( useType == USE_ON )
  113. {
  114. m_state = AREAPORTAL_OPEN;
  115. }
  116. else if ( useType == USE_OFF )
  117. {
  118. m_state = AREAPORTAL_CLOSED;
  119. }
  120. else
  121. {
  122. return;
  123. }
  124. UpdateState();
  125. }
  126. bool CAreaPortal::KeyValue( const char *szKeyName, const char *szValue )
  127. {
  128. if( FStrEq( szKeyName, "StartOpen" ) )
  129. {
  130. m_state = (atoi(szValue) != 0) ? AREAPORTAL_OPEN : AREAPORTAL_CLOSED;
  131. return true;
  132. }
  133. else
  134. {
  135. return BaseClass::KeyValue( szKeyName, szValue );
  136. }
  137. }
  138. bool CAreaPortal::UpdateState()
  139. {
  140. engine->SetAreaPortalState( m_portalNumber, m_state );
  141. return !!m_state;
  142. }
  143. int CAreaPortal::UpdateTransmitState()
  144. {
  145. // Our brushes are kept around so don't transmit anything since we don't want to draw them.
  146. return SetTransmitState( FL_EDICT_DONTSEND );
  147. }