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.

78 lines
1.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Handling for the suit batteries.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "player.h"
  9. #include "basecombatweapon.h"
  10. #include "gamerules.h"
  11. #include "items.h"
  12. #include "engine/IEngineSound.h"
  13. #include "hl1_items.h"
  14. #define BATTERY_MODEL "models/w_battery.mdl"
  15. ConVar sk_battery( "sk_battery","0" );
  16. class CItemBattery : public CHL1Item
  17. {
  18. public:
  19. DECLARE_CLASS( CItemBattery, CHL1Item );
  20. void Spawn( void )
  21. {
  22. Precache( );
  23. SetModel( BATTERY_MODEL );
  24. BaseClass::Spawn( );
  25. }
  26. void Precache( void )
  27. {
  28. PrecacheModel( BATTERY_MODEL );
  29. PrecacheScriptSound( "Item.Pickup" );
  30. }
  31. bool MyTouch( CBasePlayer *pPlayer )
  32. {
  33. if ((pPlayer->ArmorValue() < MAX_NORMAL_BATTERY) && pPlayer->IsSuitEquipped())
  34. {
  35. int pct;
  36. char szcharge[64];
  37. pPlayer->IncrementArmorValue( sk_battery.GetFloat(), MAX_NORMAL_BATTERY );
  38. CPASAttenuationFilter filter( pPlayer, "Item.Pickup" );
  39. EmitSound( filter, pPlayer->entindex(), "Item.Pickup" );
  40. CSingleUserRecipientFilter user( pPlayer );
  41. user.MakeReliable();
  42. UserMessageBegin( user, "ItemPickup" );
  43. WRITE_STRING( GetClassname() );
  44. MessageEnd();
  45. // Suit reports new power level
  46. // For some reason this wasn't working in release build -- round it.
  47. pct = (int)( (float)(pPlayer->ArmorValue() * 100.0) * (1.0/MAX_NORMAL_BATTERY) + 0.5);
  48. pct = (pct / 5);
  49. if (pct > 0)
  50. pct--;
  51. Q_snprintf( szcharge,sizeof(szcharge),"!HEV_%1dP", pct );
  52. //UTIL_EmitSoundSuit(edict(), szcharge);
  53. pPlayer->SetSuitUpdate(szcharge, FALSE, SUIT_NEXT_IN_30SEC);
  54. return true;
  55. }
  56. return false;
  57. }
  58. };
  59. LINK_ENTITY_TO_CLASS(item_battery, CItemBattery);
  60. PRECACHE_REGISTER(item_battery);