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.

248 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "util.h"
  8. #include "weapon_tfc_medikit.h"
  9. #include "tfc_gamerules.h"
  10. #if defined( CLIENT_DLL )
  11. #include "c_tfc_player.h"
  12. #else
  13. #include "tfc_player.h"
  14. #include "tfc_timer.h"
  15. #endif
  16. // ----------------------------------------------------------------------------- //
  17. // CTFCMedikit tables.
  18. // ----------------------------------------------------------------------------- //
  19. IMPLEMENT_NETWORKCLASS_ALIASED( TFCMedikit, DT_WeaponMedikit )
  20. BEGIN_NETWORK_TABLE( CTFCMedikit, DT_WeaponMedikit )
  21. END_NETWORK_TABLE()
  22. BEGIN_PREDICTION_DATA( CTFCMedikit )
  23. END_PREDICTION_DATA()
  24. LINK_ENTITY_TO_CLASS( weapon_medikit, CTFCMedikit );
  25. PRECACHE_WEAPON_REGISTER( weapon_medikit );
  26. #ifndef CLIENT_DLL
  27. BEGIN_DATADESC( CTFCMedikit )
  28. END_DATADESC()
  29. #endif
  30. // ----------------------------------------------------------------------------- //
  31. // CTFCMedikit implementation.
  32. // ----------------------------------------------------------------------------- //
  33. CTFCMedikit::CTFCMedikit()
  34. {
  35. }
  36. void CTFCMedikit::Precache()
  37. {
  38. BaseClass::Precache();
  39. }
  40. TFCWeaponID CTFCMedikit::GetWeaponID( void ) const
  41. {
  42. return WEAPON_MEDIKIT;
  43. }
  44. #ifdef CLIENT_DLL
  45. // ------------------------------------------------------------------------------------------------ //
  46. // ------------------------------------------------------------------------------------------------ //
  47. // CLIENT DLL SPECIFIC CODE
  48. // ------------------------------------------------------------------------------------------------ //
  49. // ------------------------------------------------------------------------------------------------ //
  50. #else
  51. // ------------------------------------------------------------------------------------------------ //
  52. // ------------------------------------------------------------------------------------------------ //
  53. // GAME DLL SPECIFIC CODE
  54. // ------------------------------------------------------------------------------------------------ //
  55. // ------------------------------------------------------------------------------------------------ //
  56. void CTFCMedikit::AxeHit( CBaseEntity *pHit, bool bFirstSwing, trace_t &tr, float *flDamage, bool *bDoEffects )
  57. {
  58. *flDamage = 0;
  59. *bDoEffects = false;
  60. CTFCPlayer *pPlayer = GetPlayerOwner();
  61. if ( !pPlayer )
  62. return;
  63. // We only care about players.
  64. CTFCPlayer *pTarget = ToTFCPlayer( pHit );
  65. if ( !pTarget )
  66. return;
  67. // If other player is dead ( just changed teams? ) don't hit
  68. if ( !pTarget->IsAlive() )
  69. return;
  70. Vector vAttackDir = tr.endpos - tr.startpos;
  71. VectorNormalize( vAttackDir );
  72. // Heal if we're on the same team, Infect if not
  73. if ( pPlayer->IsAlly( pTarget ) )
  74. {
  75. // Heal Concussion
  76. CTimer *pTimer = Timer_FindTimer( pTarget, TF_TIMER_CONCUSSION );
  77. if ( pTimer )
  78. {
  79. // Tell everyone
  80. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Medic_cureconc", pPlayer->GetPlayerName(), pTarget->GetPlayerName() );
  81. // Give the medic a frag if it was an enemy concussion
  82. if ( pTimer->GetTeamNumber() != pPlayer->GetTeamNumber() )
  83. pPlayer->TF_AddFrags(1);
  84. Timer_Remove( pTimer );
  85. }
  86. // Heal Hallucination
  87. if ( pTarget->m_Shared.GetStateFlags() & TFSTATE_HALLUCINATING )
  88. {
  89. pTimer = Timer_FindTimer( pTarget, TF_TIMER_HALLUCINATION );
  90. ASSERT(pTimer != NULL);
  91. // Tell everyone
  92. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Medic_curehalluc", pPlayer->GetPlayerName(), pTarget->GetPlayerName() );
  93. // Give the medic a frag if it was an enemy hallucination
  94. if (pTimer->GetTeamNumber() != pPlayer->GetTeamNumber())
  95. pPlayer->TF_AddFrags(1);
  96. pTarget->m_Shared.RemoveStateFlags( TFSTATE_HALLUCINATING );
  97. Timer_Remove( pTimer );
  98. }
  99. // Heal Tranquilisation
  100. if (pTarget->m_Shared.GetStateFlags() & TFSTATE_TRANQUILISED)
  101. {
  102. pTimer = Timer_FindTimer( pTarget, TF_TIMER_TRANQUILISATION );
  103. ASSERT(pTimer != NULL);
  104. // Tell everyone
  105. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Medic_curetranq", pPlayer->GetPlayerName(), pTarget->GetPlayerName() );
  106. // Give the medic a frag if it was an enemy tranquilisation
  107. if (pTimer->GetTeamNumber() != pPlayer->GetTeamNumber())
  108. pPlayer->TF_AddFrags(1);
  109. pTarget->m_Shared.RemoveStateFlags( TFSTATE_TRANQUILISED );
  110. // TFCTODO: ((CBasePlayer*)pTarget)->TeamFortress_SetSpeed();
  111. Timer_Remove( pTimer );
  112. }
  113. // Heal Infection
  114. if (pTarget->m_Shared.GetStateFlags() & TFSTATE_INFECTED)
  115. {
  116. int fDmg = pTarget->GetHealth() / 2;
  117. SpawnBlood(pTarget->GetAbsOrigin(), vAttackDir, pTarget->BloodColor(), fDmg);
  118. #if !defined( CLIENT_DLL )
  119. pTimer = Timer_FindTimer( pTarget, TF_TIMER_INFECTION );
  120. ASSERT(pTimer != NULL);
  121. // Tell everyone
  122. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Medic_cureinfection", pPlayer->GetPlayerName(), pTarget->GetPlayerName() );
  123. // Give the medic a frag if it was an enemy tranquilisation
  124. if ( pTimer->GetTeamNumber() != pPlayer->GetTeamNumber() )
  125. pPlayer->TF_AddFrags(1);
  126. // The operation removes half of the player's health
  127. CBaseEntity *pOwner = pTimer->m_hOwner;
  128. pTarget->TakeDamage( CTakeDamageInfo( this, pOwner, fDmg, DMG_IGNOREARMOR | DMG_NERVEGAS ) );
  129. pTarget->m_Shared.RemoveStateFlags( TFSTATE_INFECTED );
  130. Timer_Remove( pTimer );
  131. #endif
  132. }
  133. // Extinguish Flames
  134. if ( pTarget->GetNumFlames() > 0 )
  135. {
  136. // Tell everyone
  137. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Medic_curefire", pPlayer->GetPlayerName(), pTarget->GetPlayerName() );
  138. pTarget->SetNumFlames( 0 );
  139. //PLAYBACK_EVENT( 0, pPlayer->edict(), m_usSteamShot );
  140. }
  141. // Heal
  142. if ( pTarget->GetHealth() < pTarget->GetMaxHealth() )
  143. {
  144. //PLAYBACK_EVENT( 0, pPlayer->edict(), m_usNormalShot );
  145. pTarget->TakeHealth( WEAP_MEDIKIT_HEAL, DMG_GENERIC ); // Heal fully in one hit
  146. }
  147. else if (pTarget->GetHealth() < pTarget->GetMaxHealth() + WEAP_MEDIKIT_OVERHEAL)
  148. {
  149. // "Heal" over and above the player's max health
  150. //PLAYBACK_EVENT( 0, pPlayer->edict(), m_usSuperShot );
  151. pTarget->TakeHealth( 5, DMG_GENERIC | DMG_IGNORE_MAXHEALTH);
  152. if ( !(pTarget->m_Shared.GetItemFlags() & IT_SUPERHEALTH) )
  153. {
  154. pTarget->m_Shared.AddItemFlags( IT_SUPERHEALTH );
  155. #if !defined( CLIENT_DLL )
  156. // Start Superhealth rot timer
  157. Timer_CreateTimer( pTarget, TF_TIMER_ROTHEALTH );
  158. #endif
  159. }
  160. }
  161. }
  162. else
  163. {
  164. Vector vecDir;
  165. AngleVectors( pPlayer->EyeAngles(), &vecDir );
  166. // Damage Target
  167. ClearMultiDamage();
  168. pTarget->TraceAttack( CTakeDamageInfo( pPlayer, pPlayer, 10, DMG_CLUB ), vecDir, &tr );
  169. ApplyMultiDamage();
  170. // Don't infect if the player's already infected, a medic, or we're still in prematch
  171. if ( (pTarget->m_Shared.GetStateFlags() & TFSTATE_INFECTED) ||
  172. (pTarget->m_Shared.GetPlayerClass() == PC_MEDIC) ||
  173. TFCGameRules()->IsInPreMatch() )
  174. {
  175. return;
  176. }
  177. // Infect
  178. pTarget->m_Shared.AddStateFlags( TFSTATE_INFECTED );
  179. #if !defined( CLIENT_DLL )
  180. // we don't want to create another timer if the player we're attacking
  181. // with the medikit is currently dying ( already "killed" but still playing
  182. // their death animation )
  183. if ( pTarget->m_lifeState != LIFE_ALIVE )
  184. return;
  185. CTimer *pTimer = Timer_CreateTimer( pTarget, TF_TIMER_INFECTION );
  186. pTimer->m_hEnemy = pPlayer;
  187. #endif
  188. }
  189. }
  190. #endif