Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
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.

195 lines
4.9 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
/*
===== h_battery.cpp ========================================================
battery-related code
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "saverestore.h"
#include "skill.h"
#include "gamerules.h"
#include "weapons.h"
#include "game.h"
9 years ago
class CRecharge : public CBaseToggle
{
public:
9 years ago
void Spawn();
9 years ago
void Precache( void );
void EXPORT Off(void);
void EXPORT Recharge(void);
void KeyValue( KeyValueData *pkvd );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
9 years ago
virtual int ObjectCaps( void ) { return ( CBaseToggle::ObjectCaps() | FCAP_CONTINUOUS_USE ) & ~FCAP_ACROSS_TRANSITION; }
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
9 years ago
9 years ago
static TYPEDESCRIPTION m_SaveData[];
9 years ago
float m_flNextCharge;
9 years ago
int m_iReactivate; // DeathMatch Delay until reactvated
int m_iJuice;
int m_iOn; // 0 = off, 1 = startup, 2 = going
float m_flSoundTime;
9 years ago
};
TYPEDESCRIPTION CRecharge::m_SaveData[] =
{
DEFINE_FIELD( CRecharge, m_flNextCharge, FIELD_TIME ),
9 years ago
DEFINE_FIELD( CRecharge, m_iReactivate, FIELD_INTEGER ),
DEFINE_FIELD( CRecharge, m_iJuice, FIELD_INTEGER ),
DEFINE_FIELD( CRecharge, m_iOn, FIELD_INTEGER ),
9 years ago
DEFINE_FIELD( CRecharge, m_flSoundTime, FIELD_TIME ),
};
IMPLEMENT_SAVERESTORE( CRecharge, CBaseToggle )
9 years ago
LINK_ENTITY_TO_CLASS( func_recharge, CRecharge )
9 years ago
void CRecharge::KeyValue( KeyValueData *pkvd )
{
9 years ago
if( FStrEq( pkvd->szKeyName, "style" ) ||
FStrEq( pkvd->szKeyName, "height" ) ||
FStrEq( pkvd->szKeyName, "value1" ) ||
FStrEq( pkvd->szKeyName, "value2" ) ||
FStrEq( pkvd->szKeyName, "value3" ) )
9 years ago
{
pkvd->fHandled = TRUE;
}
9 years ago
else if( FStrEq( pkvd->szKeyName, "dmdelay" ) )
9 years ago
{
9 years ago
m_iReactivate = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
else
CBaseToggle::KeyValue( pkvd );
}
void CRecharge::Spawn()
{
9 years ago
Precache();
9 years ago
9 years ago
pev->solid = SOLID_BSP;
pev->movetype = MOVETYPE_PUSH;
9 years ago
9 years ago
UTIL_SetOrigin( pev, pev->origin ); // set size and link into world
UTIL_SetSize( pev, pev->mins, pev->maxs );
SET_MODEL( ENT( pev ), STRING( pev->model ) );
m_iJuice = (int)gSkillData.suitchargerCapacity;
9 years ago
pev->frame = 0;
}
void CRecharge::Precache()
{
9 years ago
PRECACHE_SOUND( "items/suitcharge1.wav" );
PRECACHE_SOUND( "items/suitchargeno1.wav" );
PRECACHE_SOUND( "items/suitchargeok1.wav" );
9 years ago
}
void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
// Make sure that we have a caller
if( !pActivator )
return;
9 years ago
// if it's not a player, ignore
if( !pActivator->IsPlayer() )
9 years ago
return;
// if there is no juice left, turn it off
9 years ago
if( m_iJuice <= 0 )
9 years ago
{
pev->frame = 1;
Off();
}
// if the player doesn't have the suit, or there is no juice left, make the deny noise
6 years ago
if( ( m_iJuice <= 0 ) || ( !( pActivator->pev->weapons & ( 1 << WEAPON_SUIT ) ) ) || ( ( chargerfix.value ) && ( pActivator->pev->armorvalue == MAX_NORMAL_BATTERY ) ) )
9 years ago
{
9 years ago
if( m_flSoundTime <= gpGlobals->time )
9 years ago
{
m_flSoundTime = gpGlobals->time + 0.62f;
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/suitchargeno1.wav", 0.85, ATTN_NORM );
9 years ago
}
return;
}
pev->nextthink = pev->ltime + 0.25f;
9 years ago
SetThink( &CRecharge::Off );
9 years ago
// Time to recharge yet?
9 years ago
if( m_flNextCharge >= gpGlobals->time )
9 years ago
return;
m_hActivator = pActivator;
// Play the on sound or the looping charging sound
9 years ago
if( !m_iOn )
9 years ago
{
m_iOn++;
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM );
m_flSoundTime = 0.56f + gpGlobals->time;
9 years ago
}
9 years ago
if( ( m_iOn == 1 ) && ( m_flSoundTime <= gpGlobals->time ) )
9 years ago
{
m_iOn++;
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_STATIC, "items/suitcharge1.wav", 0.85, ATTN_NORM );
9 years ago
}
// charge the player
9 years ago
if( m_hActivator->pev->armorvalue < 100 )
9 years ago
{
m_iJuice--;
m_hActivator->pev->armorvalue += 1;
9 years ago
if( m_hActivator->pev->armorvalue > 100 )
9 years ago
m_hActivator->pev->armorvalue = 100;
}
// govern the rate of charge
m_flNextCharge = gpGlobals->time + 0.1f;
9 years ago
}
9 years ago
void CRecharge::Recharge( void )
9 years ago
{
m_iJuice = (int)gSkillData.suitchargerCapacity;
9 years ago
pev->frame = 0;
9 years ago
SetThink( &CBaseEntity::SUB_DoNothing );
}
9 years ago
void CRecharge::Off( void )
9 years ago
{
// Stop looping sound.
9 years ago
if( m_iOn > 1 )
STOP_SOUND( ENT( pev ), CHAN_STATIC, "items/suitcharge1.wav" );
9 years ago
m_iOn = 0;
if( ( !m_iJuice ) && ( ( m_iReactivate = (int)g_pGameRules->FlHEVChargerRechargeTime() ) > 0 ) )
9 years ago
{
pev->nextthink = pev->ltime + m_iReactivate;
9 years ago
SetThink( &CRecharge::Recharge );
9 years ago
}
else
SetThink( &CBaseEntity::SUB_DoNothing );
}