hlsdk-xash3d/dlls/h_battery.cpp

195 lines
4.9 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* 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"
2016-06-04 15:24:23 +02:00
class CRecharge : public CBaseToggle
{
public:
2016-07-31 15:48:50 +02:00
void Spawn();
2016-06-04 15:24:23 +02:00
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 );
2016-07-31 15:48:50 +02:00
virtual int ObjectCaps( void ) { return ( CBaseToggle::ObjectCaps() | FCAP_CONTINUOUS_USE ) & ~FCAP_ACROSS_TRANSITION; }
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
static TYPEDESCRIPTION m_SaveData[];
2016-06-04 15:24:23 +02:00
float m_flNextCharge;
2016-07-31 15:48:50 +02:00
int m_iReactivate; // DeathMatch Delay until reactvated
int m_iJuice;
int m_iOn; // 0 = off, 1 = startup, 2 = going
float m_flSoundTime;
2016-06-04 15:24:23 +02:00
};
TYPEDESCRIPTION CRecharge::m_SaveData[] =
{
DEFINE_FIELD( CRecharge, m_flNextCharge, FIELD_TIME ),
2016-07-31 15:48:50 +02:00
DEFINE_FIELD( CRecharge, m_iReactivate, FIELD_INTEGER ),
DEFINE_FIELD( CRecharge, m_iJuice, FIELD_INTEGER ),
DEFINE_FIELD( CRecharge, m_iOn, FIELD_INTEGER ),
2016-06-04 15:24:23 +02:00
DEFINE_FIELD( CRecharge, m_flSoundTime, FIELD_TIME ),
};
IMPLEMENT_SAVERESTORE( CRecharge, CBaseToggle )
2016-06-04 15:24:23 +02:00
LINK_ENTITY_TO_CLASS( func_recharge, CRecharge )
2016-06-04 15:24:23 +02:00
void CRecharge::KeyValue( KeyValueData *pkvd )
{
2016-07-31 15:48:50 +02:00
if( FStrEq( pkvd->szKeyName, "style" ) ||
FStrEq( pkvd->szKeyName, "height" ) ||
FStrEq( pkvd->szKeyName, "value1" ) ||
FStrEq( pkvd->szKeyName, "value2" ) ||
FStrEq( pkvd->szKeyName, "value3" ) )
2016-06-04 15:24:23 +02:00
{
pkvd->fHandled = TRUE;
}
2016-07-31 15:48:50 +02:00
else if( FStrEq( pkvd->szKeyName, "dmdelay" ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_iReactivate = atoi( pkvd->szValue );
2016-06-04 15:24:23 +02:00
pkvd->fHandled = TRUE;
}
else
CBaseToggle::KeyValue( pkvd );
}
void CRecharge::Spawn()
{
2016-07-31 15:48:50 +02:00
Precache();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_BSP;
pev->movetype = MOVETYPE_PUSH;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
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 ) );
2017-06-29 15:56:03 +02:00
m_iJuice = (int)gSkillData.suitchargerCapacity;
2016-06-04 15:24:23 +02:00
pev->frame = 0;
}
void CRecharge::Precache()
{
2016-07-31 15:48:50 +02:00
PRECACHE_SOUND( "items/suitcharge1.wav" );
PRECACHE_SOUND( "items/suitchargeno1.wav" );
PRECACHE_SOUND( "items/suitchargeok1.wav" );
2016-06-04 15:24:23 +02:00
}
void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
2019-09-24 00:00:37 +02:00
// Make sure that we have a caller
if( !pActivator )
return;
2016-06-04 15:24:23 +02:00
// if it's not a player, ignore
2019-09-24 00:00:37 +02:00
if( !pActivator->IsPlayer() )
2016-06-04 15:24:23 +02:00
return;
// if there is no juice left, turn it off
2016-07-31 15:48:50 +02:00
if( m_iJuice <= 0 )
2016-06-04 15:24:23 +02:00
{
pev->frame = 1;
Off();
}
// if the player doesn't have the suit, or there is no juice left, make the deny noise
2019-07-07 17:08:01 +02:00
if( ( m_iJuice <= 0 ) || ( !( pActivator->pev->weapons & ( 1 << WEAPON_SUIT ) ) ) || ( ( chargerfix.value ) && ( pActivator->pev->armorvalue == MAX_NORMAL_BATTERY ) ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_flSoundTime <= gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
m_flSoundTime = gpGlobals->time + 0.62f;
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/suitchargeno1.wav", 0.85, ATTN_NORM );
2016-06-04 15:24:23 +02:00
}
return;
}
2019-10-13 13:49:25 +02:00
pev->nextthink = pev->ltime + 0.25f;
2016-07-31 15:48:50 +02:00
SetThink( &CRecharge::Off );
2016-06-04 15:24:23 +02:00
// Time to recharge yet?
2016-07-31 15:48:50 +02:00
if( m_flNextCharge >= gpGlobals->time )
2016-06-04 15:24:23 +02:00
return;
m_hActivator = pActivator;
// Play the on sound or the looping charging sound
2016-07-31 15:48:50 +02:00
if( !m_iOn )
2016-06-04 15:24:23 +02:00
{
m_iOn++;
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM );
2019-10-13 13:49:25 +02:00
m_flSoundTime = 0.56f + gpGlobals->time;
2016-06-04 15:24:23 +02:00
}
2019-09-24 00:00:37 +02:00
2016-07-31 15:48:50 +02:00
if( ( m_iOn == 1 ) && ( m_flSoundTime <= gpGlobals->time ) )
2016-06-04 15:24:23 +02:00
{
m_iOn++;
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_STATIC, "items/suitcharge1.wav", 0.85, ATTN_NORM );
2016-06-04 15:24:23 +02:00
}
// charge the player
2016-07-31 15:48:50 +02:00
if( m_hActivator->pev->armorvalue < 100 )
2016-06-04 15:24:23 +02:00
{
m_iJuice--;
m_hActivator->pev->armorvalue += 1;
2016-07-31 15:48:50 +02:00
if( m_hActivator->pev->armorvalue > 100 )
2016-06-04 15:24:23 +02:00
m_hActivator->pev->armorvalue = 100;
}
// govern the rate of charge
2019-10-13 13:49:25 +02:00
m_flNextCharge = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CRecharge::Recharge( void )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
m_iJuice = (int)gSkillData.suitchargerCapacity;
2016-07-31 15:48:50 +02:00
pev->frame = 0;
2016-06-04 15:24:23 +02:00
SetThink( &CBaseEntity::SUB_DoNothing );
}
2016-07-31 15:48:50 +02:00
void CRecharge::Off( void )
2016-06-04 15:24:23 +02:00
{
// Stop looping sound.
2016-07-31 15:48:50 +02:00
if( m_iOn > 1 )
STOP_SOUND( ENT( pev ), CHAN_STATIC, "items/suitcharge1.wav" );
2016-06-04 15:24:23 +02:00
m_iOn = 0;
2017-06-29 15:56:03 +02:00
if( ( !m_iJuice ) && ( ( m_iReactivate = (int)g_pGameRules->FlHEVChargerRechargeTime() ) > 0 ) )
2016-06-04 15:24:23 +02:00
{
pev->nextthink = pev->ltime + m_iReactivate;
2016-07-31 15:48:50 +02:00
SetThink( &CRecharge::Recharge );
2016-06-04 15:24:23 +02:00
}
else
SetThink( &CBaseEntity::SUB_DoNothing );
2016-04-17 22:30:05 +02:00
}