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.

140 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "func_areaportalwindow.h"
  9. #include "entitylist.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. // The server will still send entities through a window even after it opaque
  13. // to allow for net lag.
  14. #define FADE_DIST_BUFFER 10
  15. LINK_ENTITY_TO_CLASS( func_areaportalwindow, CFuncAreaPortalWindow );
  16. IMPLEMENT_SERVERCLASS_ST( CFuncAreaPortalWindow, DT_FuncAreaPortalWindow )
  17. SendPropFloat( SENDINFO(m_flFadeDist), 0, SPROP_NOSCALE ),
  18. SendPropFloat( SENDINFO(m_flFadeStartDist), 0, SPROP_NOSCALE ),
  19. SendPropFloat( SENDINFO(m_flTranslucencyLimit), 0, SPROP_NOSCALE ),
  20. SendPropModelIndex(SENDINFO(m_iBackgroundModelIndex) ),
  21. END_SEND_TABLE()
  22. BEGIN_DATADESC( CFuncAreaPortalWindow )
  23. DEFINE_KEYFIELD( m_portalNumber, FIELD_INTEGER, "portalnumber" ),
  24. DEFINE_KEYFIELD( m_flFadeStartDist, FIELD_FLOAT, "FadeStartDist" ),
  25. DEFINE_KEYFIELD( m_flFadeDist, FIELD_FLOAT, "FadeDist" ),
  26. DEFINE_KEYFIELD( m_flTranslucencyLimit, FIELD_FLOAT, "TranslucencyLimit" ),
  27. DEFINE_KEYFIELD( m_iBackgroundBModelName,FIELD_STRING, "BackgroundBModel" ),
  28. // DEFINE_KEYFIELD( m_iBackgroundModelIndex,FIELD_INTEGER ),
  29. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFadeStartDistance", InputSetFadeStartDistance ),
  30. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFadeEndDistance", InputSetFadeEndDistance ),
  31. END_DATADESC()
  32. CFuncAreaPortalWindow::CFuncAreaPortalWindow()
  33. {
  34. m_iBackgroundModelIndex = -1;
  35. }
  36. CFuncAreaPortalWindow::~CFuncAreaPortalWindow()
  37. {
  38. }
  39. void CFuncAreaPortalWindow::Spawn()
  40. {
  41. Precache();
  42. engine->SetAreaPortalState( m_portalNumber, 1 );
  43. }
  44. void CFuncAreaPortalWindow::Activate()
  45. {
  46. BaseClass::Activate();
  47. // Find our background model.
  48. CBaseEntity *pBackground = gEntList.FindEntityByName( NULL, m_iBackgroundBModelName );
  49. if( pBackground )
  50. {
  51. m_iBackgroundModelIndex = modelinfo->GetModelIndex( STRING( pBackground->GetModelName() ) );
  52. pBackground->AddEffects( EF_NODRAW ); // we will draw for it.
  53. }
  54. // Find our target and steal its bmodel.
  55. CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, m_target );
  56. if( pTarget )
  57. {
  58. SetModel( STRING(pTarget->GetModelName()) );
  59. SetAbsOrigin( pTarget->GetAbsOrigin() );
  60. pTarget->AddEffects( EF_NODRAW ); // we will draw for it.
  61. }
  62. }
  63. bool CFuncAreaPortalWindow::IsWindowOpen( const CUtlVector< Vector > &vecOrigins, float fovDistanceAdjustFactor )
  64. {
  65. float flClosestDistance = FLT_MAX;
  66. for ( int i = 0; i < vecOrigins.Count(); ++i )
  67. {
  68. float flDist = CollisionProp()->CalcDistanceFromPoint( vecOrigins[ i ] );
  69. if ( flDist < flClosestDistance )
  70. {
  71. flClosestDistance = flDist;
  72. }
  73. }
  74. if ( flClosestDistance == FLT_MAX )
  75. return false;
  76. flClosestDistance *= fovDistanceAdjustFactor;
  77. return ( flClosestDistance <= (m_flFadeDist + FADE_DIST_BUFFER) );
  78. }
  79. bool CFuncAreaPortalWindow::UpdateVisibility( const CUtlVector< Vector > &vecOrigins, float fovDistanceAdjustFactor, bool &bIsOpenOnClient )
  80. {
  81. if ( IsWindowOpen( vecOrigins, fovDistanceAdjustFactor ) )
  82. {
  83. return BaseClass::UpdateVisibility( vecOrigins, fovDistanceAdjustFactor, bIsOpenOnClient );
  84. }
  85. else
  86. {
  87. bIsOpenOnClient = false;
  88. return false;
  89. }
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose: Changes the fade start distance
  93. // Input: float distance in inches
  94. //-----------------------------------------------------------------------------
  95. void CFuncAreaPortalWindow::InputSetFadeStartDistance( inputdata_t &inputdata )
  96. {
  97. m_flFadeStartDist = inputdata.value.Float();
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Changes the fade end distance
  101. // Input: float distance in inches
  102. //-----------------------------------------------------------------------------
  103. void CFuncAreaPortalWindow::InputSetFadeEndDistance( inputdata_t &inputdata )
  104. {
  105. m_flFadeDist = inputdata.value.Float();
  106. }