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:
  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 Vector &vOrigin, float fovDistanceAdjustFactor )
  64. {
  65. float flDist = CollisionProp()->CalcDistanceFromPoint( vOrigin );
  66. flDist *= fovDistanceAdjustFactor;
  67. return ( flDist <= (m_flFadeDist + FADE_DIST_BUFFER) );
  68. }
  69. bool CFuncAreaPortalWindow::UpdateVisibility( const Vector &vOrigin, float fovDistanceAdjustFactor, bool &bIsOpenOnClient )
  70. {
  71. if ( IsWindowOpen( vOrigin, fovDistanceAdjustFactor ) )
  72. {
  73. return BaseClass::UpdateVisibility( vOrigin, fovDistanceAdjustFactor, bIsOpenOnClient );
  74. }
  75. else
  76. {
  77. bIsOpenOnClient = false;
  78. return false;
  79. }
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Changes the fade start distance
  83. // Input: float distance in inches
  84. //-----------------------------------------------------------------------------
  85. void CFuncAreaPortalWindow::InputSetFadeStartDistance( inputdata_t &inputdata )
  86. {
  87. m_flFadeStartDist = inputdata.value.Float();
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose: Changes the fade end distance
  91. // Input: float distance in inches
  92. //-----------------------------------------------------------------------------
  93. void CFuncAreaPortalWindow::InputSetFadeEndDistance( inputdata_t &inputdata )
  94. {
  95. m_flFadeDist = inputdata.value.Float();
  96. }