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.

115 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "c_dod_bombtarget.h"
  8. #include "dod_shareddefs.h"
  9. #include "c_dod_player.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. IMPLEMENT_NETWORKCLASS_ALIASED( DODBombTarget, DT_DODBombTarget )
  13. BEGIN_NETWORK_TABLE(C_DODBombTarget, DT_DODBombTarget )
  14. RecvPropInt( RECVINFO(m_iState) ),
  15. RecvPropInt( RECVINFO(m_iBombingTeam) ),
  16. RecvPropInt( RECVINFO(m_iTargetModel) ),
  17. RecvPropInt( RECVINFO(m_iUnavailableModel) ),
  18. END_NETWORK_TABLE()
  19. void C_DODBombTarget::NotifyShouldTransmit( ShouldTransmitState_t state )
  20. {
  21. BaseClass::NotifyShouldTransmit( state );
  22. // Turn off
  23. if ( state == SHOULDTRANSMIT_END )
  24. {
  25. SetNextClientThink( CLIENT_THINK_NEVER );
  26. }
  27. // Turn on
  28. if ( state == SHOULDTRANSMIT_START )
  29. {
  30. SetNextClientThink( CLIENT_THINK_ALWAYS );
  31. }
  32. }
  33. void C_DODBombTarget::ClientThink( void )
  34. {
  35. // if we are near the player, maybe give them a hint!
  36. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  37. if ( pPlayer && pPlayer->IsAlive() )
  38. {
  39. Vector vecDist = GetAbsOrigin() - pPlayer->GetAbsOrigin();
  40. if ( vecDist.Length() < 200 )
  41. {
  42. int iOppositeTeam = ( m_iBombingTeam == TEAM_ALLIES ) ? TEAM_AXIS : TEAM_ALLIES;
  43. if ( pPlayer->GetTeamNumber() == m_iBombingTeam && m_iState == BOMB_TARGET_ACTIVE )
  44. {
  45. pPlayer->CheckBombTargetPlantHint();
  46. }
  47. else if ( pPlayer->GetTeamNumber() == iOppositeTeam && m_iState == BOMB_TARGET_ARMED )
  48. {
  49. pPlayer->CheckBombTargetDefuseHint();
  50. }
  51. }
  52. }
  53. SetNextClientThink( gpGlobals->curtime + 0.5 );
  54. }
  55. int C_DODBombTarget::DrawModel( int flags )
  56. {
  57. if ( m_iState == BOMB_TARGET_ACTIVE )
  58. {
  59. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  60. int iOppositeTeam = ( m_iBombingTeam == TEAM_ALLIES ) ? TEAM_AXIS : TEAM_ALLIES;
  61. #ifdef _DEBUG
  62. if ( m_iBombingTeam == TEAM_UNASSIGNED )
  63. iOppositeTeam = TEAM_UNASSIGNED;
  64. #endif
  65. if ( pPlayer && pPlayer->GetTeamNumber() == iOppositeTeam )
  66. {
  67. // draw a different model for the non-planting team
  68. if ( GetModelIndex() != m_iUnavailableModel )
  69. {
  70. SetModelIndex( m_iUnavailableModel );
  71. }
  72. }
  73. else
  74. {
  75. if ( GetModelIndex() != m_iTargetModel )
  76. {
  77. SetModelIndex( m_iTargetModel );
  78. }
  79. }
  80. }
  81. return BaseClass::DrawModel( flags );
  82. }
  83. // a player of the passed team is looking at us, see if we should
  84. // play the hint telling them how to defuse
  85. bool C_DODBombTarget::ShouldPlayDefuseHint( int team )
  86. {
  87. return ( m_iState == BOMB_TARGET_ARMED && team != m_iBombingTeam );
  88. }
  89. // a player of the passed team is looking at us, see if we should
  90. // play the hint telling them how to plant a bomb here
  91. bool C_DODBombTarget::ShouldPlayPlantHint( int team )
  92. {
  93. return ( m_iState == BOMB_TARGET_ACTIVE && team == m_iBombingTeam );
  94. }