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.

122 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //
  4. //=============================================================================
  5. #include "cbase.h"
  6. #include "tf_weapon_syringegun.h"
  7. #include "tf_fx_shared.h"
  8. #include "tf_weapon_medigun.h"
  9. // Client specific.
  10. #ifdef CLIENT_DLL
  11. #include "c_tf_player.h"
  12. // Server specific.
  13. #else
  14. #include "tf_player.h"
  15. #endif
  16. //=============================================================================
  17. //
  18. // Weapon Syringe Gun tables.
  19. //
  20. IMPLEMENT_NETWORKCLASS_ALIASED( TFSyringeGun, DT_WeaponSyringeGun )
  21. BEGIN_NETWORK_TABLE( CTFSyringeGun, DT_WeaponSyringeGun )
  22. END_NETWORK_TABLE()
  23. BEGIN_PREDICTION_DATA( CTFSyringeGun )
  24. END_PREDICTION_DATA()
  25. LINK_ENTITY_TO_CLASS( tf_weapon_syringegun_medic, CTFSyringeGun );
  26. PRECACHE_WEAPON_REGISTER( tf_weapon_syringegun_medic );
  27. // Server specific.
  28. #ifndef CLIENT_DLL
  29. BEGIN_DATADESC( CTFSyringeGun )
  30. END_DATADESC()
  31. #endif
  32. //=============================================================================
  33. //
  34. // Weapon SyringeGun functions.
  35. //
  36. void CTFSyringeGun::Precache()
  37. {
  38. BaseClass::Precache();
  39. #ifndef CLIENT_DLL
  40. PrecacheParticleSystem( "nailtrails_medic_blue_crit" );
  41. PrecacheParticleSystem( "nailtrails_medic_blue" );
  42. PrecacheParticleSystem( "nailtrails_medic_red_crit" );
  43. PrecacheParticleSystem( "nailtrails_medic_red" );
  44. #endif
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. bool CTFSyringeGun::Deploy()
  50. {
  51. CBaseEntity *pOwner = GetOwnerEntity();
  52. if ( pOwner )
  53. {
  54. ToTFPlayer( pOwner )->TeamFortress_SetSpeed();
  55. }
  56. return BaseClass::Deploy();
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. //-----------------------------------------------------------------------------
  61. bool CTFSyringeGun::Holster( CBaseCombatWeapon *pSwitchingTo )
  62. {
  63. CBaseEntity *pOwner = GetOwnerEntity();
  64. if ( pOwner )
  65. {
  66. ToTFPlayer( pOwner )->TeamFortress_SetSpeed();
  67. }
  68. return BaseClass::Holster( pSwitchingTo );
  69. }
  70. void CTFSyringeGun::RemoveProjectileAmmo( CTFPlayer *pPlayer )
  71. {
  72. float flUberChargeAmmoPerShot = UberChargeAmmoPerShot();
  73. if ( flUberChargeAmmoPerShot > 0.0f )
  74. {
  75. #ifndef CLIENT_DLL
  76. if ( !pPlayer )
  77. return;
  78. CWeaponMedigun *pMedigun = static_cast< CWeaponMedigun * >( pPlayer->Weapon_OwnsThisID( TF_WEAPON_MEDIGUN ) );
  79. if ( !pMedigun )
  80. return;
  81. pMedigun->SubtractCharge( flUberChargeAmmoPerShot );
  82. #endif
  83. return;
  84. }
  85. return BaseClass::RemoveProjectileAmmo( pPlayer );
  86. }
  87. bool CTFSyringeGun::HasPrimaryAmmo( void )
  88. {
  89. float flUberChargeAmmoPerShot = UberChargeAmmoPerShot();
  90. if ( flUberChargeAmmoPerShot > 0.0f )
  91. {
  92. CTFPlayer *pPlayer = ToTFPlayer( GetOwnerEntity() );
  93. if ( !pPlayer )
  94. return false;
  95. CWeaponMedigun *pMedigun = static_cast< CWeaponMedigun * >( pPlayer->Weapon_OwnsThisID( TF_WEAPON_MEDIGUN ) );
  96. if ( !pMedigun )
  97. return false;
  98. float flCharge = pMedigun->GetChargeLevel();
  99. return flUberChargeAmmoPerShot <= flCharge;
  100. }
  101. return BaseClass::HasPrimaryAmmo();
  102. }