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.

172 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // TF Rocket
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_weaponbase.h"
  8. #include "tf_projectile_rocket.h"
  9. #include "tf_player.h"
  10. //=============================================================================
  11. //
  12. // TF Rocket functions (Server specific).
  13. //
  14. #define ROCKET_MODEL "models/weapons/w_models/w_rocket.mdl"
  15. LINK_ENTITY_TO_CLASS( tf_projectile_rocket, CTFProjectile_Rocket );
  16. PRECACHE_REGISTER( tf_projectile_rocket );
  17. IMPLEMENT_NETWORKCLASS_ALIASED( TFProjectile_Rocket, DT_TFProjectile_Rocket )
  18. BEGIN_NETWORK_TABLE( CTFProjectile_Rocket, DT_TFProjectile_Rocket )
  19. SendPropBool( SENDINFO( m_bCritical ) ),
  20. END_NETWORK_TABLE()
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. CTFProjectile_Rocket *CTFProjectile_Rocket::Create( CBaseEntity *pLauncher, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner, CBaseEntity *pScorer )
  25. {
  26. CTFProjectile_Rocket *pRocket = static_cast<CTFProjectile_Rocket*>( CTFBaseRocket::Create( pLauncher, "tf_projectile_rocket", vecOrigin, vecAngles, pOwner ) );
  27. if ( pRocket )
  28. {
  29. pRocket->SetScorer( pScorer );
  30. pRocket->SetEyeBallRocket( false );
  31. pRocket->SetSpell( false );
  32. CTFWeaponBase *pWeapon = dynamic_cast< CTFWeaponBase * >( pLauncher );
  33. bool bDirectHit = pWeapon ? ( pWeapon->GetWeaponID() == TF_WEAPON_ROCKETLAUNCHER_DIRECTHIT ) : false;
  34. pRocket->SetDirectHit( bDirectHit );
  35. }
  36. return pRocket;
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose:
  40. //-----------------------------------------------------------------------------
  41. void CTFProjectile_Rocket::Spawn()
  42. {
  43. SetModel( ROCKET_MODEL );
  44. BaseClass::Spawn();
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. void CTFProjectile_Rocket::Precache()
  50. {
  51. int iModel = PrecacheModel( ROCKET_MODEL );
  52. PrecacheGibsForModel( iModel );
  53. PrecacheParticleSystem( "critical_rocket_blue" );
  54. PrecacheParticleSystem( "critical_rocket_red" );
  55. PrecacheParticleSystem( "eyeboss_projectile" );
  56. PrecacheParticleSystem( "rockettrail" );
  57. BaseClass::Precache();
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose:
  61. //-----------------------------------------------------------------------------
  62. void CTFProjectile_Rocket::SetScorer( CBaseEntity *pScorer )
  63. {
  64. m_Scorer = pScorer;
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. CBasePlayer *CTFProjectile_Rocket::GetScorer( void )
  70. {
  71. return dynamic_cast<CBasePlayer *>( m_Scorer.Get() );
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose:
  75. //-----------------------------------------------------------------------------
  76. int CTFProjectile_Rocket::GetDamageType()
  77. {
  78. int iDmgType = BaseClass::GetDamageType();
  79. if ( m_bCritical )
  80. {
  81. iDmgType |= DMG_CRITICAL;
  82. }
  83. return iDmgType;
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. int CTFProjectile_Rocket::GetDamageCustom()
  89. {
  90. if ( m_bDirectHit )
  91. {
  92. return TF_DMG_CUSTOM_ROCKET_DIRECTHIT;
  93. }
  94. else if ( m_bEyeBallRocket )
  95. {
  96. return TF_DMG_CUSTOM_EYEBALL_ROCKET;
  97. }
  98. else if ( m_bSpell )
  99. {
  100. return TF_DMG_CUSTOM_SPELL_MONOCULUS;
  101. }
  102. else
  103. return BaseClass::GetDamageCustom();
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose:
  107. //-----------------------------------------------------------------------------
  108. void CTFProjectile_Rocket::RocketTouch( CBaseEntity *pOther )
  109. {
  110. BaseClass::RocketTouch( pOther );
  111. if (m_bCritical && pOther && pOther->IsPlayer())
  112. {
  113. CTFPlayer *pHitPlayer = ToTFPlayer( pOther );
  114. int iHitPlayerTeamNumber = pHitPlayer->GetTeamNumber();
  115. int iRocketTeamNumber = BaseClass::GetTeamNumber();
  116. if (pHitPlayer->IsPlayerClass(TF_CLASS_HEAVYWEAPONS) && !pHitPlayer->m_Shared.InCond( TF_COND_INVULNERABLE)
  117. && pHitPlayer->IsAlive() && iHitPlayerTeamNumber != iRocketTeamNumber)
  118. {
  119. pHitPlayer->AwardAchievement( ACHIEVEMENT_TF_HEAVY_SURVIVE_CROCKET );
  120. }
  121. }
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose: Rocket was deflected.
  125. //-----------------------------------------------------------------------------
  126. void CTFProjectile_Rocket::Deflected( CBaseEntity *pDeflectedBy, Vector &vecDir )
  127. {
  128. CTFPlayer *pTFDeflector = ToTFPlayer( pDeflectedBy );
  129. if ( !pTFDeflector )
  130. return;
  131. ChangeTeam( pTFDeflector->GetTeamNumber() );
  132. SetLauncher( pTFDeflector->GetActiveWeapon() );
  133. CTFPlayer* pOldOwner = ToTFPlayer( GetOwnerEntity() );
  134. SetOwnerEntity( pTFDeflector );
  135. if ( pOldOwner )
  136. {
  137. pOldOwner->SpeakConceptIfAllowed( MP_CONCEPT_DEFLECTED, "projectile:1,victim:1" );
  138. }
  139. if ( pTFDeflector->m_Shared.IsCritBoosted() )
  140. {
  141. SetCritical( true );
  142. }
  143. CTFWeaponBase::SendObjectDeflectedEvent( pTFDeflector, pOldOwner, GetWeaponID(), this );
  144. IncrementDeflected();
  145. m_nSkin = ( GetTeamNumber() == TF_TEAM_BLUE ) ? 1 : 0;
  146. }