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.

171 lines
4.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Bomb target area
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "cs_player.h"
  8. #include "weapon_csbase.h"
  9. #include "func_bomb_target.h"
  10. #include "cs_player_resource.h"
  11. #include "cs_gamerules.h"
  12. LINK_ENTITY_TO_CLASS( func_bomb_target, CBombTarget );
  13. BEGIN_DATADESC( CBombTarget )
  14. DEFINE_FUNCTION( BombTargetTouch ),
  15. DEFINE_FUNCTION( BombTargetUse ), //needed?
  16. // Inputs
  17. DEFINE_INPUTFUNC( FIELD_VOID, "BombExplode", OnBombExplode ),
  18. DEFINE_INPUTFUNC( FIELD_VOID, "BombPlanted", OnBombPlanted ),
  19. DEFINE_INPUTFUNC( FIELD_VOID, "BombDefused", OnBombDefused ),
  20. // Outputs
  21. DEFINE_OUTPUT( m_OnBombExplode, "BombExplode" ),
  22. DEFINE_OUTPUT( m_OnBombPlanted, "BombPlanted" ),
  23. DEFINE_OUTPUT( m_OnBombDefused, "BombDefused" ),
  24. DEFINE_KEYFIELD( m_bIsHeistBombTarget, FIELD_BOOLEAN, "heistbomb" ),
  25. DEFINE_KEYFIELD( m_szMountTarget, FIELD_STRING, "bomb_mount_target" ),
  26. END_DATADESC()
  27. CBombTarget::CBombTarget( void )
  28. {
  29. m_bIsHeistBombTarget = false;
  30. m_bBombPlantedHere = false;
  31. m_szMountTarget = NULL_STRING;
  32. m_hInstructorHint = NULL;
  33. }
  34. void CBombTarget::Spawn()
  35. {
  36. InitTrigger();
  37. SetTouch( &CBombTarget::BombTargetTouch );
  38. SetUse( &CBombTarget::BombTargetUse );
  39. //VisibilityMonitor_AddEntity( this, 1200.0f, NULL, NULL );
  40. }
  41. void CBombTarget::ReInitOnRoundStart( void )
  42. {
  43. if ( m_hInstructorHint.Get() )
  44. {
  45. CPointEntity *pEnt = static_cast< CPointEntity* >( m_hInstructorHint.Get() );
  46. UTIL_Remove( pEnt );
  47. m_hInstructorHint = NULL;
  48. }
  49. m_bBombPlantedHere = false;
  50. //CCSPlayerResource *pCSPR = CSPlayerResource();
  51. Vector bombA = Vector( 0, 0, 0 );
  52. Vector bombB = Vector( 0, 0, 0 );
  53. Vector vecTrigger = CollisionProp()->WorldSpaceCenter();
  54. if ( CSPlayerResource() )
  55. {
  56. bombA = CSPlayerResource()->GetBombsiteAPosition();
  57. bombB = CSPlayerResource()->GetBombsiteBPosition();
  58. CPointEntity *pEnt;
  59. if ( vecTrigger.DistTo( bombA ) > vecTrigger.DistTo( bombB ) )
  60. {
  61. pEnt = static_cast< CPointEntity* >( CreateEntityByName( "info_bomb_target_hint_B" ) );
  62. }
  63. else
  64. {
  65. pEnt = static_cast< CPointEntity* >( CreateEntityByName( "info_bomb_target_hint_A" ) );
  66. }
  67. if ( pEnt )
  68. {
  69. pEnt->Spawn();
  70. trace_t tr;
  71. UTIL_TraceLine( vecTrigger, vecTrigger + Vector ( 0, 0, -128 ), MASK_SOLID, this, COLLISION_GROUP_NONE, &tr );
  72. Vector vecHint = tr.endpos + Vector ( 0, 0, 16 );
  73. pEnt->SetAbsOrigin( vecHint );
  74. pEnt->SetOwnerEntity( this );
  75. pEnt->SetParent( this );
  76. m_hInstructorHint = pEnt;
  77. }
  78. }
  79. }
  80. void CBombTarget::BombTargetTouch( CBaseEntity* pOther )
  81. {
  82. CCSPlayer *p = dynamic_cast< CCSPlayer* >( pOther );
  83. if ( p )
  84. {
  85. p->m_bInBombZoneTrigger = true;
  86. if ( p->HasC4() && m_bBombPlantedHere == false && (CSGameRules()->m_bBombPlanted == false || CSGameRules()->IsPlayingCoopMission()) )
  87. {
  88. p->m_bInBombZone = true;
  89. p->m_iBombSiteIndex = entindex();
  90. //bool bC4Active = p->GetActiveCSWeapon() && p->GetActiveCSWeapon()->GetCSWeaponID() == WEAPON_C4;
  91. if ( !(p->m_iDisplayHistoryBits & DHF_IN_TARGET_ZONE) )
  92. {
  93. p->m_iDisplayHistoryBits |= DHF_IN_TARGET_ZONE;
  94. }
  95. }
  96. }
  97. }
  98. void CBombTarget::BombTargetUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
  99. {
  100. //SUB_UseTargets( NULL, USE_TOGGLE, 0 );
  101. DevMsg( 2, "BombTargetUse does nothing\n" );
  102. }
  103. // Relay to our outputs
  104. void CBombTarget::OnBombExplode( inputdata_t &inputdata )
  105. {
  106. m_OnBombExplode.FireOutput(this, this);
  107. }
  108. // Relay to our outputs
  109. void CBombTarget::OnBombPlanted( inputdata_t &inputdata )
  110. {
  111. m_OnBombPlanted.FireOutput(this, this);
  112. m_bBombPlantedHere = true;
  113. }
  114. // Relay to our outputs
  115. void CBombTarget::OnBombDefused( inputdata_t &inputdata )
  116. {
  117. m_OnBombDefused.FireOutput(this, this);
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose: A generic target entity that gets replicated to the client for displaying a hint for the CS bomb targets
  121. //-----------------------------------------------------------------------------
  122. void CInfoInstructorHintBombTargetA::Spawn( void )
  123. {
  124. VisibilityMonitor_AddEntity( this, 5000.0f, NULL, NULL );
  125. }
  126. LINK_ENTITY_TO_CLASS( info_bomb_target_hint_A, CInfoInstructorHintBombTargetA );
  127. BEGIN_DATADESC( CInfoInstructorHintBombTargetA )
  128. END_DATADESC()
  129. //-----------------------------------------------------------------------------
  130. // Purpose: A generic target entity that gets replicated to the client for displaying a hint for the CS bomb targets
  131. //-----------------------------------------------------------------------------
  132. void CInfoInstructorHintBombTargetB::Spawn( void )
  133. {
  134. VisibilityMonitor_AddEntity( this, 5000.0f, NULL, NULL );
  135. }
  136. LINK_ENTITY_TO_CLASS( info_bomb_target_hint_B, CInfoInstructorHintBombTargetB );
  137. BEGIN_DATADESC( CInfoInstructorHintBombTargetB )
  138. END_DATADESC()