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.

147 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. // func_passtime_goal - based on func_capture_zone
  8. #include "cbase.h"
  9. #include "func_passtime_goal.h"
  10. #include "tf_passtime_ball.h"
  11. #include "tf_passtime_logic.h"
  12. #include "passtime_convars.h"
  13. #include "tf_team.h"
  14. #include "tf_player.h"
  15. #include "tf_gamerules.h"
  16. #include "tf_gamestats.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. //-----------------------------------------------------------------------------
  20. BEGIN_DATADESC( CFuncPasstimeGoal )
  21. DEFINE_KEYFIELD( m_iPoints, FIELD_INTEGER, "points" ),
  22. DEFINE_FUNCTION( CFuncPasstimeGoalShim::StartTouch ),
  23. DEFINE_FUNCTION( CFuncPasstimeGoalShim::EndTouch ),
  24. DEFINE_OUTPUT( m_onScoreBlu, "OnScoreBlu" ),
  25. DEFINE_OUTPUT( m_onScoreRed, "OnScoreRed" ),
  26. END_DATADESC()
  27. //-----------------------------------------------------------------------------
  28. LINK_ENTITY_TO_CLASS( func_passtime_goal, CFuncPasstimeGoal );
  29. //-----------------------------------------------------------------------------
  30. IMPLEMENT_SERVERCLASS_ST( CFuncPasstimeGoal, DT_FuncPasstimeGoal )
  31. SendPropBool( SENDINFO( m_bTriggerDisabled ) ),
  32. SendPropInt( SENDINFO( m_iGoalType ) ),
  33. END_SEND_TABLE()
  34. //-----------------------------------------------------------------------------
  35. CFuncPasstimeGoal::CFuncPasstimeGoal()
  36. {
  37. m_iPoints = -1;
  38. m_bTriggerDisabled = false;
  39. }
  40. //-----------------------------------------------------------------------------
  41. void CFuncPasstimeGoal::Spawn()
  42. {
  43. // HACK spawnflags to work around initially wrong understanding of how triggers work; needs rewrite and map changes
  44. AddSpawnFlags( GetSpawnFlags() << 24 );
  45. RemoveSpawnFlags( 0xffffff );
  46. AddSpawnFlags( SF_TRIGGER_ALLOW_CLIENTS | SF_TRIGGER_ALLOW_PHYSICS );
  47. InitTrigger();
  48. m_bTriggerDisabled = m_bDisabled;
  49. SetThink( &CFuncPasstimeGoal::GoalThink );
  50. SetNextThink( gpGlobals->curtime );
  51. // set goal type
  52. if ( BTowerGoal() )
  53. {
  54. m_iGoalType = TYPE_TOWER;
  55. }
  56. else if ( BEnablePlayerScore() )
  57. {
  58. m_iGoalType = TYPE_ENDZONE;
  59. }
  60. else
  61. {
  62. m_iGoalType = TYPE_HOOP;
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. void CFuncPasstimeGoal::GoalThink()
  67. {
  68. SetNextThink( gpGlobals->curtime );
  69. m_bTriggerDisabled = m_bDisabled;
  70. for( int i = 0; i < m_hTouchingEntities.Count(); ++i )
  71. {
  72. CTFPlayer *pPlayer = ToTFPlayer( m_hTouchingEntities[i] );
  73. if ( pPlayer )
  74. {
  75. g_pPasstimeLogic->OnStayInGoal( pPlayer, this );
  76. }
  77. }
  78. }
  79. //-----------------------------------------------------------------------------
  80. bool CFuncPasstimeGoal::CanTouchMe( CBaseEntity *pOther )
  81. {
  82. return !m_bDisabled
  83. && (pOther != 0)
  84. && (g_pPasstimeLogic != 0);
  85. }
  86. //-----------------------------------------------------------------------------
  87. void CFuncPasstimeGoal::ShimStartTouch( CBaseEntity *pOther )
  88. {
  89. if ( !CanTouchMe( pOther ) )
  90. {
  91. return;
  92. }
  93. if ( CPasstimeBall *pBall = dynamic_cast<CPasstimeBall*>( pOther ) )
  94. {
  95. g_pPasstimeLogic->OnEnterGoal( pBall, this );
  96. }
  97. else if ( pOther->IsPlayer() )
  98. {
  99. g_pPasstimeLogic->OnEnterGoal( ToTFPlayer( pOther ), this );
  100. }
  101. }
  102. //-----------------------------------------------------------------------------
  103. void CFuncPasstimeGoal::ShimEndTouch( CBaseEntity *pOther )
  104. {
  105. if ( !CanTouchMe( pOther ) )
  106. {
  107. return;
  108. }
  109. if ( CPasstimeBall *pBall = dynamic_cast<CPasstimeBall*>( pOther ) )
  110. {
  111. g_pPasstimeLogic->OnExitGoal( pBall, this );
  112. }
  113. }
  114. //-----------------------------------------------------------------------------
  115. void CFuncPasstimeGoal::OnScore( int iTeam )
  116. {
  117. if( iTeam == TF_TEAM_RED )
  118. {
  119. m_onScoreRed.FireOutput( this, this );
  120. }
  121. else if( iTeam == TF_TEAM_BLUE )
  122. {
  123. m_onScoreBlu.FireOutput( this, this );
  124. }
  125. }
  126. //-----------------------------------------------------------------------------
  127. int CFuncPasstimeGoal::UpdateTransmitState()
  128. {
  129. // so the hud can point to it
  130. return SetTransmitState( FL_EDICT_ALWAYS );
  131. }