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.

90 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CTF Armor.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "items.h"
  8. #include "tf_gamerules.h"
  9. #include "tf_shareddefs.h"
  10. #include "tf_player.h"
  11. #include "tf_team.h"
  12. #include "engine/IEngineSound.h"
  13. #include "entity_armor.h"
  14. //=============================================================================
  15. //
  16. // CTF Armor defines.
  17. //
  18. #define TF_ARMOR_PICKUP_SOUND "Armor.Touch"
  19. #define TF_ARMOR_CAPACITY 200
  20. LINK_ENTITY_TO_CLASS( item_armor, CArmor );
  21. //=============================================================================
  22. //
  23. // CTF Armor functions.
  24. //
  25. //-----------------------------------------------------------------------------
  26. // Purpose: Spawn function for the armor
  27. //-----------------------------------------------------------------------------
  28. void CArmor::Spawn( void )
  29. {
  30. BaseClass::Spawn();
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose: Precache function for the armor
  34. //-----------------------------------------------------------------------------
  35. void CArmor::Precache( void )
  36. {
  37. PrecacheScriptSound( TF_ARMOR_PICKUP_SOUND );
  38. BaseClass::Precache();
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: MyTouch function for the armor
  42. //-----------------------------------------------------------------------------
  43. bool CArmor::MyTouch( CBasePlayer *pPlayer )
  44. {
  45. bool bSuccess = false;
  46. if ( ValidTouch( pPlayer ) )
  47. {
  48. CTFPlayer *pCTFPlayer = ToTFPlayer(pPlayer);
  49. if ( pCTFPlayer )
  50. {
  51. int iMaxArmor = pCTFPlayer->GetPlayerClass()->GetMaxArmor();
  52. int iCurrentArmor = pCTFPlayer->ArmorValue();
  53. if ( iCurrentArmor < iMaxArmor )
  54. {
  55. if ( iCurrentArmor + TF_ARMOR_CAPACITY >= iMaxArmor )
  56. {
  57. pCTFPlayer->SetArmorValue( iMaxArmor );
  58. }
  59. else
  60. {
  61. pCTFPlayer->SetArmorValue( iCurrentArmor + TF_ARMOR_CAPACITY );
  62. }
  63. CSingleUserRecipientFilter user( pPlayer );
  64. user.MakeReliable();
  65. UserMessageBegin( user, "ItemPickup" );
  66. WRITE_STRING( GetClassname() );
  67. MessageEnd();
  68. CPASAttenuationFilter filter( this, TF_ARMOR_PICKUP_SOUND );
  69. EmitSound( filter, entindex(), TF_ARMOR_PICKUP_SOUND );
  70. bSuccess = true;
  71. }
  72. }
  73. }
  74. return bSuccess;
  75. }