diff --git a/sp/src/game/server/hl2/item_battery.cpp b/sp/src/game/server/hl2/item_battery.cpp index d5c8b416..fe174c04 100644 --- a/sp/src/game/server/hl2/item_battery.cpp +++ b/sp/src/game/server/hl2/item_battery.cpp @@ -63,3 +63,88 @@ BEGIN_DATADESC( CItemBattery ) END_DATADESC() #endif +#ifdef MAPBASE +extern ConVar sk_battery; + +//----------------------------------------------------------------------------- +// Custom player battery. Heals the player when picked up. +//----------------------------------------------------------------------------- +class CItemBatteryCustom : public CItem +{ +public: + DECLARE_CLASS( CItemBatteryCustom, CItem ); + CItemBatteryCustom(); + + void Spawn( void ); + void Precache( void ); + bool MyTouch( CBasePlayer *pPlayer ); + + float GetItemAmount() { return m_flPowerAmount; } + + void InputSetPowerAmount( inputdata_t &inputdata ) { m_flPowerAmount = inputdata.value.Float(); } + + float m_flPowerAmount; + string_t m_iszTouchSound; + + DECLARE_DATADESC(); +}; + +LINK_ENTITY_TO_CLASS( item_battery_custom, CItemBatteryCustom ); + +#ifdef MAPBASE +BEGIN_DATADESC( CItemBatteryCustom ) + + DEFINE_KEYFIELD( m_flPowerAmount, FIELD_FLOAT, "PowerAmount" ), + DEFINE_KEYFIELD( m_iszTouchSound, FIELD_STRING, "TouchSound" ), + + DEFINE_INPUTFUNC( FIELD_FLOAT, "SetPowerAmount", InputSetPowerAmount ), + +END_DATADESC() +#endif + + +CItemBatteryCustom::CItemBatteryCustom() +{ + SetModelName( AllocPooledString( "models/items/battery.mdl" ) ); + m_flPowerAmount = sk_battery.GetFloat(); + m_iszTouchSound = AllocPooledString( "ItemBattery.Touch" ); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CItemBatteryCustom::Spawn( void ) +{ + Precache(); + SetModel( STRING( GetModelName() ) ); + + BaseClass::Spawn(); +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CItemBatteryCustom::Precache( void ) +{ + PrecacheModel( STRING( GetModelName() ) ); + + PrecacheScriptSound( STRING( m_iszTouchSound ) ); +} + + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *pPlayer - +// Output : +//----------------------------------------------------------------------------- +bool CItemBatteryCustom::MyTouch( CBasePlayer *pPlayer ) +{ + CHL2_Player *pHL2Player = assert_cast(pPlayer); + if (!pHL2Player || sk_battery.GetFloat() == 0.0f) + return false; + + float flPowerMult = m_flPowerAmount / sk_battery.GetFloat(); + return pHL2Player->ApplyBattery( flPowerMult ); +} +#endif