summaryrefslogtreecommitdiff
path: root/game/server/hl1/hl1_item_battery.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/hl1/hl1_item_battery.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/server/hl1/hl1_item_battery.cpp')
-rw-r--r--game/server/hl1/hl1_item_battery.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/game/server/hl1/hl1_item_battery.cpp b/game/server/hl1/hl1_item_battery.cpp
new file mode 100644
index 0000000..6cddacb
--- /dev/null
+++ b/game/server/hl1/hl1_item_battery.cpp
@@ -0,0 +1,78 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: Handling for the suit batteries.
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "cbase.h"
+#include "player.h"
+#include "basecombatweapon.h"
+#include "gamerules.h"
+#include "items.h"
+#include "engine/IEngineSound.h"
+#include "hl1_items.h"
+
+
+#define BATTERY_MODEL "models/w_battery.mdl"
+
+ConVar sk_battery( "sk_battery","0" );
+
+class CItemBattery : public CHL1Item
+{
+public:
+ DECLARE_CLASS( CItemBattery, CHL1Item );
+
+ void Spawn( void )
+ {
+ Precache( );
+ SetModel( BATTERY_MODEL );
+ BaseClass::Spawn( );
+ }
+ void Precache( void )
+ {
+ PrecacheModel( BATTERY_MODEL );
+
+ PrecacheScriptSound( "Item.Pickup" );
+ }
+
+ bool MyTouch( CBasePlayer *pPlayer )
+ {
+ if ((pPlayer->ArmorValue() < MAX_NORMAL_BATTERY) && pPlayer->IsSuitEquipped())
+ {
+ int pct;
+ char szcharge[64];
+
+ pPlayer->IncrementArmorValue( sk_battery.GetFloat(), MAX_NORMAL_BATTERY );
+
+ CPASAttenuationFilter filter( pPlayer, "Item.Pickup" );
+ EmitSound( filter, pPlayer->entindex(), "Item.Pickup" );
+
+ CSingleUserRecipientFilter user( pPlayer );
+ user.MakeReliable();
+
+ UserMessageBegin( user, "ItemPickup" );
+ WRITE_STRING( GetClassname() );
+ MessageEnd();
+
+
+ // Suit reports new power level
+ // For some reason this wasn't working in release build -- round it.
+ pct = (int)( (float)(pPlayer->ArmorValue() * 100.0) * (1.0/MAX_NORMAL_BATTERY) + 0.5);
+ pct = (pct / 5);
+ if (pct > 0)
+ pct--;
+
+ Q_snprintf( szcharge,sizeof(szcharge),"!HEV_%1dP", pct );
+
+ //UTIL_EmitSoundSuit(edict(), szcharge);
+ pPlayer->SetSuitUpdate(szcharge, FALSE, SUIT_NEXT_IN_30SEC);
+ return true;
+ }
+ return false;
+ }
+};
+
+LINK_ENTITY_TO_CLASS(item_battery, CItemBattery);
+PRECACHE_REGISTER(item_battery);
+