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.
832 lines
20 KiB
832 lines
20 KiB
9 years ago
|
/***
|
||
|
Created by Solexid
|
||
|
*
|
||
|
****/
|
||
|
|
||
|
|
||
|
|
||
|
#include "extdll.h"
|
||
|
#include "util.h"
|
||
|
#include "cbase.h"
|
||
|
#include "player.h"
|
||
|
#include "monsters.h"
|
||
|
#include "soundent.h"
|
||
|
#include "weapons.h"
|
||
|
#include "nodes.h"
|
||
|
#include "effects.h"
|
||
|
#include "customentity.h"
|
||
|
#include "gamerules.h"
|
||
8 years ago
|
#include "customweapons.h"
|
||
6 years ago
|
#include "unpredictedweapon.h"
|
||
9 years ago
|
|
||
|
#define GRAV_BEAM_SPRITE_PRIMARY_VOLUME 30
|
||
|
#define GRAV_BEAM_SPRITE "sprites/xbeam3.spr"
|
||
|
#define GRAV_FLARE_SPRITE "sprites/hotglow.spr"
|
||
|
#define GRAV_SOUND_OFF "buttons/latchunlocked1.wav"
|
||
|
#define GRAV_SOUND_RUN "weapons/mine_activate.wav"
|
||
|
#define GRAV_SOUND_FAILRUN "houndeye/he_die3.wav"
|
||
|
#define GRAV_SOUND_STARTUP "weapons/gauss2.wav"
|
||
|
#define EGON_SWITCH_NARROW_TIME 0.75 // Time it takes to switch fire modes
|
||
|
|
||
|
enum gauss_e {
|
||
|
GAUSS_IDLE = 0,
|
||
|
GAUSS_IDLE2,
|
||
|
GAUSS_FIDGET,
|
||
|
GAUSS_SPINUP,
|
||
|
GAUSS_SPIN,
|
||
|
GAUSS_FIRE,
|
||
|
GAUSS_FIRE2,
|
||
|
GAUSS_HOLSTER,
|
||
|
GAUSS_DRAW
|
||
|
};
|
||
|
|
||
7 years ago
|
|
||
6 years ago
|
class CGravGun : public CBasePlayerWeaponU
|
||
9 years ago
|
{
|
||
|
public:
|
||
|
|
||
|
|
||
7 years ago
|
float m_flLastCmd;
|
||
9 years ago
|
void Spawn(void);
|
||
|
void Precache(void);
|
||
|
int iItemSlot(void) { return 4; }
|
||
|
int GetItemInfo(ItemInfo *p);
|
||
|
int AddToPlayer(CBasePlayer *pPlayer);
|
||
9 years ago
|
int m_iStage;
|
||
9 years ago
|
BOOL Deploy(void);
|
||
|
void Holster(int skiplocal = 0);
|
||
9 years ago
|
int m_iGrabFailures;
|
||
9 years ago
|
EHANDLE m_hAimentEntity;
|
||
9 years ago
|
void UpdateEffect(const Vector &startPoint, const Vector &endPoint, float timeBlend);
|
||
9 years ago
|
CBaseEntity * TraceForward(CBaseEntity *pMe, float radius);
|
||
9 years ago
|
void CreateEffect(void);
|
||
|
void DestroyEffect(void);
|
||
|
void EndAttack(void);
|
||
|
void Attack(void);
|
||
|
void Attack2(void);
|
||
|
void PrimaryAttack(void);
|
||
|
void SecondaryAttack(void);
|
||
|
void WeaponIdle(void);
|
||
7 years ago
|
void Pull(CBaseEntity* ent);
|
||
9 years ago
|
void GravAnim(int iAnim, int skiplocal, int body);
|
||
7 years ago
|
Vector PredictTarget( float length );
|
||
9 years ago
|
CBaseEntity *GetCrossEnt( Vector gunpos, Vector aim, float radius );
|
||
|
float m_flNextGravgunAttack;
|
||
9 years ago
|
float m_flAmmoUseTime;// since we use < 1 point of ammo per update, we subtract ammo on a timer.
|
||
|
|
||
|
|
||
7 years ago
|
void EXPORT GrabThink( void );
|
||
|
void EXPORT PullThink( void );
|
||
9 years ago
|
float Fire(const Vector &vecOrigSrc, const Vector &vecDir);
|
||
9 years ago
|
|
||
|
BOOL HasAmmo(void);
|
||
|
|
||
|
|
||
|
enum GRAV_FIREMODE { FIRE_NARROW, FIRE_WIDE };
|
||
|
|
||
|
CBeam *m_pBeam;
|
||
|
CBeam *m_pNoise;
|
||
|
CSprite *m_pSprite;
|
||
|
|
||
|
private:
|
||
|
float m_shootTime;
|
||
|
GRAV_FIREMODE m_fireMode;
|
||
|
float m_shakeTime;
|
||
|
BOOL m_deployed;
|
||
9 years ago
|
float m_fPushSpeed;
|
||
9 years ago
|
};
|
||
|
|
||
7 years ago
|
LINK_ENTITY_TO_CLASS(weapon_gravgun, CGravGun);
|
||
9 years ago
|
|
||
7 years ago
|
void CGravGun::Spawn()
|
||
9 years ago
|
{
|
||
6 years ago
|
if( !cvar_allow_gravgun.value )
|
||
|
{
|
||
|
pev->flags = FL_KILLME;
|
||
|
return;
|
||
|
}
|
||
|
pev->classname = MAKE_STRING("weapon_gravgun");
|
||
9 years ago
|
Precache();
|
||
|
m_iId = WEAPON_GRAVGUN;
|
||
|
SET_MODEL(ENT(pev), "models/w_gravcannon.mdl");
|
||
|
m_iClip = -1;
|
||
|
m_iDefaultAmmo = -1;
|
||
|
|
||
|
FallInit();// get ready to fall down.
|
||
|
}
|
||
7 years ago
|
#define CONST_MULT 10
|
||
|
#define CMD_MULT 100
|
||
|
Vector CGravGun::PredictTarget(float length)
|
||
|
{
|
||
|
Vector predicted = m_pPlayer->pev->origin;
|
||
|
float cmdtime = gpGlobals->time - m_flLastCmd;
|
||
7 years ago
|
//ALERT( at_notice, "PredictTarget %f\n", cmdtime );
|
||
7 years ago
|
|
||
|
// button-based prediction
|
||
|
if( m_pPlayer->pev->button & IN_FORWARD )
|
||
|
predicted = predicted + gpGlobals->v_forward * CONST_MULT + gpGlobals->v_forward * cmdtime * CMD_MULT;
|
||
|
// do not predict back? it may hurt player
|
||
|
//if( m_pPlayer->pev->button & IN_BACK )
|
||
|
//predicted = predicted + gpGlobals->v_forward * -CONST_MULT / 2 + gpGlobals->v_forward * cmdtime * -CMD_MULT / 2;
|
||
|
if( m_pPlayer->pev->button & IN_MOVELEFT )
|
||
|
predicted = predicted + gpGlobals->v_right * -CONST_MULT + gpGlobals->v_right * cmdtime * -CMD_MULT;
|
||
|
if( m_pPlayer->pev->button & IN_MOVERIGHT )
|
||
|
predicted = predicted + gpGlobals->v_right * CONST_MULT + gpGlobals->v_right * cmdtime * CMD_MULT;
|
||
|
|
||
|
// distance
|
||
|
predicted = predicted + gpGlobals->v_forward * length;
|
||
|
|
||
|
// velocity animation
|
||
|
predicted = predicted + m_pPlayer->pev->velocity * cmdtime;
|
||
|
return predicted;
|
||
|
}
|
||
9 years ago
|
|
||
7 years ago
|
void CGravGun::Precache(void)
|
||
9 years ago
|
{
|
||
6 years ago
|
if( !cvar_allow_gravgun.value )
|
||
|
return;
|
||
9 years ago
|
PRECACHE_MODEL("models/w_gravcannon.mdl");
|
||
|
PRECACHE_MODEL("models/v_gravcannon.mdl");
|
||
|
PRECACHE_MODEL("models/p_gravcannon.mdl");
|
||
|
|
||
|
PRECACHE_MODEL("models/w_9mmclip.mdl");
|
||
|
PRECACHE_SOUND("items/9mmclip1.wav");
|
||
|
|
||
|
PRECACHE_SOUND(GRAV_SOUND_OFF);
|
||
|
PRECACHE_SOUND(GRAV_SOUND_RUN);
|
||
|
PRECACHE_SOUND(GRAV_SOUND_FAILRUN);
|
||
|
PRECACHE_SOUND(GRAV_SOUND_STARTUP);
|
||
|
|
||
|
PRECACHE_MODEL(GRAV_BEAM_SPRITE);
|
||
|
PRECACHE_MODEL("sprites/hotglow.spr");
|
||
|
|
||
|
PRECACHE_SOUND("weapons/357_cock1.wav");
|
||
6 years ago
|
PRECACHE_GENERIC("sprites/weapon_gravgun.txt");
|
||
9 years ago
|
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
BOOL CGravGun::Deploy(void)
|
||
9 years ago
|
{
|
||
|
m_deployed = FALSE;
|
||
|
m_fireState = FIRE_OFF;
|
||
7 years ago
|
SetThink( NULL );
|
||
9 years ago
|
return DefaultDeploy("models/v_gravcannon.mdl", "models/p_gravcannon.mdl", GAUSS_DRAW, "gauss");
|
||
|
}
|
||
|
|
||
7 years ago
|
int CGravGun::AddToPlayer(CBasePlayer *pPlayer)
|
||
9 years ago
|
{
|
||
6 years ago
|
if( !cvar_allow_gravgun.value )
|
||
|
return FALSE;
|
||
|
|
||
9 years ago
|
if (CBasePlayerWeapon::AddToPlayer(pPlayer))
|
||
|
{
|
||
|
MESSAGE_BEGIN(MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev);
|
||
|
WRITE_BYTE(m_iId);
|
||
|
MESSAGE_END();
|
||
|
return TRUE;
|
||
|
}
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::Holster(int skiplocal /* = 0 */)
|
||
9 years ago
|
{
|
||
|
|
||
|
SetThink(NULL);
|
||
9 years ago
|
if (m_hAimentEntity) { m_hAimentEntity->pev->velocity = Vector(0, 0, 0); }
|
||
|
m_hAimentEntity = NULL;
|
||
9 years ago
|
EndAttack();
|
||
9 years ago
|
m_iStage = 0;
|
||
|
m_flNextGravgunAttack = gpGlobals->time + 0.5;
|
||
9 years ago
|
m_pPlayer->m_flNextAttack = gpGlobals->time + 0.5;
|
||
|
GravAnim(GAUSS_HOLSTER,0,0);
|
||
|
SetThink(NULL);
|
||
|
}
|
||
|
|
||
7 years ago
|
int CGravGun::GetItemInfo(ItemInfo *p)
|
||
9 years ago
|
{
|
||
|
p->pszName = STRING(pev->classname);
|
||
|
p->pszAmmo1 = NULL;
|
||
|
p->iMaxAmmo1 = -1;
|
||
|
p->pszAmmo2 = NULL;
|
||
|
p->iMaxAmmo2 = -1;
|
||
|
p->iMaxClip = WEAPON_NOCLIP;
|
||
|
p->iSlot = 0;
|
||
|
p->iPosition = 1;
|
||
|
p->iId = m_iId = WEAPON_GRAVGUN;
|
||
|
p->iFlags = 0;
|
||
|
p->iWeight = 20;
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
7 years ago
|
BOOL CGravGun::HasAmmo(void)
|
||
9 years ago
|
{
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::Attack(void)
|
||
9 years ago
|
{
|
||
|
pev->nextthink = gpGlobals->time + 1.1;
|
||
9 years ago
|
m_flNextGravgunAttack - gpGlobals->time + 0.5;
|
||
9 years ago
|
|
||
|
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
|
||
|
Vector vecAiming = gpGlobals->v_forward;
|
||
|
Vector vecSrc = m_pPlayer->GetGunPosition();
|
||
|
|
||
|
switch (m_fireState)
|
||
|
{
|
||
|
case FIRE_OFF:
|
||
|
{
|
||
|
m_fireMode = FIRE_WIDE;
|
||
|
|
||
|
|
||
|
GravAnim(GAUSS_FIRE2, 1, 0);
|
||
|
m_pPlayer->m_iWeaponVolume = 20;
|
||
|
m_flTimeWeaponIdle = gpGlobals->time + 0.04;
|
||
|
pev->fuser1 = gpGlobals->time + 0.1;
|
||
|
|
||
9 years ago
|
m_iStage = 0;
|
||
9 years ago
|
m_fireState = FIRE_CHARGE;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case FIRE_CHARGE:
|
||
|
{
|
||
9 years ago
|
float dist = Fire(vecSrc, vecAiming);
|
||
9 years ago
|
m_pPlayer->m_iWeaponVolume = 20;
|
||
|
|
||
|
if (pev->fuser1 <= gpGlobals->time)
|
||
|
{
|
||
|
GravAnim(GAUSS_SPIN, 1, 0);
|
||
|
pev->fuser1 = 1000;
|
||
|
SetThink(NULL);
|
||
|
}
|
||
|
|
||
|
|
||
9 years ago
|
//CBaseEntity* crosent = TraceForward(m_pPlayer, 1000);
|
||
|
CBaseEntity* crossent = m_hAimentEntity;
|
||
7 years ago
|
if( m_hAimentEntity )
|
||
|
m_hAimentEntity->m_fireState = 0;
|
||
9 years ago
|
m_hAimentEntity = NULL;
|
||
9 years ago
|
if( !crossent )
|
||
9 years ago
|
crossent = GetCrossEnt(vecSrc, gpGlobals->v_forward, dist + 30);
|
||
9 years ago
|
if( !crossent || !( m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,3) ) )
|
||
|
crossent = TraceForward(m_pPlayer, 1000);
|
||
|
if(crossent && (m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,3) ) )
|
||
|
{
|
||
9 years ago
|
m_flNextGravgunAttack = gpGlobals->time + 0.8;
|
||
9 years ago
|
DestroyEffect();
|
||
|
m_fireMode = FIRE_WIDE;
|
||
|
Vector origin = crossent->pev->origin;
|
||
|
if(crossent->IsBSPModel())
|
||
|
origin = VecBModelOrigin( crossent->pev );
|
||
|
UpdateEffect( vecSrc, origin, 1 );
|
||
9 years ago
|
|
||
9 years ago
|
|
||
8 years ago
|
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_STARTUP, 0.1, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
|
||
9 years ago
|
|
||
9 years ago
|
//if (crosent->pev->flags& FL_ONGROUND) { pev->velocity = pev->velocity * 0.95; };
|
||
9 years ago
|
|
||
9 years ago
|
//crossent->TouchGravGun(m_pPlayer,3);
|
||
|
Vector pusher = vecAiming;
|
||
|
pusher.x = pusher.x * m_fPushSpeed;
|
||
|
pusher.y = pusher.y * m_fPushSpeed;
|
||
|
pusher.z = pusher.z * m_fPushSpeed * 0.7;
|
||
|
crossent->pev->velocity = pusher+m_pPlayer->pev->velocity;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
8 years ago
|
EMIT_SOUND(ENT(pev), CHAN_WEAPON, "gravgun/dry.wav", 0.6, ATTN_NORM);
|
||
9 years ago
|
crossent = NULL;
|
||
9 years ago
|
}
|
||
9 years ago
|
if (gpGlobals->time >= m_flNextGravgunAttack)
|
||
9 years ago
|
{
|
||
9 years ago
|
m_flNextGravgunAttack = gpGlobals->time + 0.7;
|
||
9 years ago
|
EndAttack();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
9 years ago
|
m_flNextGravgunAttack = gpGlobals->time + 0.5;
|
||
9 years ago
|
pev->nextthink = gpGlobals->time + 0.2;
|
||
7 years ago
|
SetThink( &CGravGun::DestroyEffect );
|
||
9 years ago
|
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
}
|
||
7 years ago
|
void CGravGun::GravAnim(int iAnim, int skiplocal, int body)
|
||
9 years ago
|
{
|
||
|
|
||
|
m_pPlayer->pev->weaponanim = iAnim;
|
||
|
|
||
|
|
||
|
|
||
|
MESSAGE_BEGIN(MSG_ONE, SVC_WEAPONANIM, NULL, m_pPlayer->pev);
|
||
|
WRITE_BYTE(iAnim); // sequence number
|
||
|
WRITE_BYTE(pev->body); // weaponmodel bodygroup.
|
||
|
MESSAGE_END();
|
||
|
}
|
||
|
|
||
7 years ago
|
void CGravGun::Attack2(void)
|
||
9 years ago
|
{
|
||
|
//if (temp) { temp = NULL; }
|
||
|
//if(temp) return;
|
||
|
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
|
||
|
Vector vecAiming = gpGlobals->v_forward;
|
||
|
//Vector vecAiming = UTIL_GetAimVector(m_pPlayer->edict(), 1000);
|
||
|
Vector vecSrc = m_pPlayer->GetGunPosition();
|
||
|
|
||
|
switch (m_fireState)
|
||
|
{
|
||
9 years ago
|
case FIRE_OFF:
|
||
|
{
|
||
|
GravAnim(GAUSS_FIRE, 1, 0);
|
||
|
m_pPlayer->m_iWeaponVolume = 20;
|
||
|
|
||
|
m_fireState = FIRE_CHARGE;
|
||
|
m_fireMode = FIRE_WIDE;
|
||
|
|
||
|
}
|
||
9 years ago
|
break;
|
||
|
|
||
9 years ago
|
case FIRE_CHARGE:
|
||
|
{
|
||
|
float dist = Fire(vecSrc, vecAiming) + 30;
|
||
|
m_flNextGravgunAttack = gpGlobals->time + 0.1;
|
||
|
//ALERT( at_console, "dist: %f\n", dist );
|
||
|
m_pPlayer->m_iWeaponVolume = 100;
|
||
|
|
||
|
if (pev->fuser1 <= gpGlobals->time)
|
||
|
{
|
||
|
|
||
|
pev->fuser1 = 1000;
|
||
|
}
|
||
|
//CBaseEntity* crossent = TraceForward(m_pPlayer,500);
|
||
|
CBaseEntity* crossent = GetCrossEnt(vecSrc, gpGlobals->v_forward, dist );
|
||
|
if( !crossent || !(m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,0)) )
|
||
|
{
|
||
|
crossent = TraceForward(m_pPlayer, 1000);
|
||
8 years ago
|
if( !crossent )
|
||
|
EMIT_SOUND(ENT(pev), CHAN_WEAPON, "gravgun/dry.wav", 0.3, ATTN_NORM);
|
||
|
else if( !(m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,0)) )
|
||
9 years ago
|
{
|
||
8 years ago
|
EMIT_SOUND(ENT(pev), CHAN_WEAPON, GRAV_SOUND_FAILRUN, 0.3, ATTN_NORM);
|
||
9 years ago
|
crossent = NULL;
|
||
|
}
|
||
|
}
|
||
|
if ( crossent ){
|
||
8 years ago
|
if(m_fireMode != FIRE_NARROW)
|
||
|
DestroyEffect();
|
||
9 years ago
|
m_fireMode = FIRE_NARROW;
|
||
9 years ago
|
Vector origin = crossent->pev->origin;
|
||
|
if(crossent->IsBSPModel())
|
||
|
origin = VecBModelOrigin( crossent->pev );
|
||
|
UpdateEffect( vecSrc, origin, 1 );
|
||
8 years ago
|
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, "gravgun/pickup.wav", 0.6, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
|
||
9 years ago
|
if(crossent->TouchGravGun(m_pPlayer, 0))
|
||
|
{
|
||
|
m_hAimentEntity = crossent;
|
||
|
GravAnim(GAUSS_SPIN, 0, 0);
|
||
7 years ago
|
SetThink( &CGravGun::PullThink );
|
||
|
pev->nextthink = gpGlobals->time + 0.001;
|
||
9 years ago
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if( m_fireMode == FIRE_NARROW )
|
||
|
DestroyEffect();
|
||
|
|
||
|
m_fireMode = FIRE_WIDE;
|
||
|
}
|
||
|
}
|
||
9 years ago
|
break;
|
||
|
}
|
||
|
|
||
|
}
|
||
7 years ago
|
CBaseEntity *CGravGun::GetCrossEnt( Vector gunpos, Vector aim, float radius )
|
||
9 years ago
|
{
|
||
|
edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex( 1 );
|
||
|
edict_t *pClosest = NULL;
|
||
|
Vector vecLOS;
|
||
9 years ago
|
float flMaxDot = 0.9;
|
||
9 years ago
|
float flDot;
|
||
|
|
||
|
if ( !pEdict )
|
||
|
return NULL;
|
||
|
|
||
9 years ago
|
edict_t *player = m_pPlayer->edict();
|
||
|
|
||
|
// uncomment this for profiling
|
||
8 years ago
|
// int tracecount = 0;
|
||
9 years ago
|
|
||
9 years ago
|
for ( int i = 1; i < gpGlobals->maxEntities; i++, pEdict++ )
|
||
|
{
|
||
|
if ( pEdict->free ) // Not in use
|
||
|
continue;
|
||
9 years ago
|
|
||
|
if( pEdict->v.solid == SOLID_BSP || pEdict->v.movetype == MOVETYPE_PUSHSTEP )
|
||
|
continue; //bsp models will be found by trace later
|
||
|
|
||
|
Vector origin = VecBModelOrigin(&pEdict->v);
|
||
|
|
||
9 years ago
|
vecLOS = origin - gunpos;
|
||
9 years ago
|
|
||
|
// too far, ignore it now
|
||
9 years ago
|
if( vecLOS.Length() > radius )
|
||
|
continue;
|
||
9 years ago
|
|
||
|
// ignore player
|
||
|
if( pEdict == player )
|
||
9 years ago
|
continue;
|
||
9 years ago
|
|
||
|
//ALERT( at_console, "len: %f\n", vecLOS.Length() );
|
||
9 years ago
|
vecLOS = UTIL_ClampVectorToBox(vecLOS, pEdict->v.size * 0.5);
|
||
|
|
||
|
flDot = DotProduct(vecLOS, aim);
|
||
9 years ago
|
if (flDot <= flMaxDot)
|
||
|
continue;
|
||
8 years ago
|
//tracecount++;
|
||
9 years ago
|
TraceResult tr;
|
||
|
UTIL_TraceLine(gunpos, origin, missile, player, &tr);
|
||
9 years ago
|
if( ( tr.vecEndPos - gunpos ).Length() + 30 < (origin - gunpos).Length())
|
||
9 years ago
|
continue;
|
||
|
pClosest = pEdict;
|
||
|
flMaxDot = flDot;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
//ALERT( at_console, "tracecount: %d\n", tracecount );
|
||
9 years ago
|
|
||
9 years ago
|
return CBaseEntity::Instance(pClosest);
|
||
9 years ago
|
|
||
|
}
|
||
|
|
||
7 years ago
|
CBaseEntity* CGravGun::TraceForward(CBaseEntity *pMe,float radius)
|
||
9 years ago
|
{
|
||
|
TraceResult tr;
|
||
|
UTIL_MakeVectors(pMe->pev->v_angle);
|
||
|
UTIL_TraceLine(pMe->pev->origin + pMe->pev->view_ofs, pMe->pev->origin + pMe->pev->view_ofs + gpGlobals->v_forward * radius, missile, pMe->edict(), &tr);
|
||
9 years ago
|
if( tr.flFraction != 1.0 && !FNullEnt(tr.pHit) )
|
||
|
return CBaseEntity::Instance(tr.pHit);
|
||
9 years ago
|
return NULL;
|
||
|
}
|
||
|
|
||
|
//Used for prop grab and
|
||
7 years ago
|
void CGravGun::GrabThink()
|
||
9 years ago
|
{
|
||
9 years ago
|
if (( m_iGrabFailures < 50 )&& m_hAimentEntity )
|
||
9 years ago
|
{
|
||
9 years ago
|
Vector origin = m_hAimentEntity->pev->origin;
|
||
|
if( m_hAimentEntity->IsBSPModel() )
|
||
|
origin = VecBModelOrigin(m_hAimentEntity->pev );
|
||
|
if( ( origin - m_pPlayer->pev->origin).Length() > 150 )
|
||
9 years ago
|
m_iGrabFailures++;
|
||
9 years ago
|
else
|
||
9 years ago
|
m_iGrabFailures = 0;
|
||
9 years ago
|
|
||
9 years ago
|
UpdateEffect(pev->origin, origin, 1);
|
||
9 years ago
|
|
||
7 years ago
|
Pull(m_hAimentEntity);
|
||
9 years ago
|
pev->nextthink = gpGlobals->time + 0.001;
|
||
|
}
|
||
|
else{
|
||
8 years ago
|
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, GRAV_SOUND_OFF, 1, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
|
||
9 years ago
|
m_iGrabFailures = 0;
|
||
7 years ago
|
SetThink( NULL );
|
||
|
|
||
9 years ago
|
if(m_hAimentEntity)
|
||
9 years ago
|
{
|
||
7 years ago
|
m_hAimentEntity->m_fireState = 0;
|
||
9 years ago
|
m_hAimentEntity->pev->velocity = Vector(0,0,0);
|
||
|
m_hAimentEntity = NULL;
|
||
9 years ago
|
}
|
||
|
EndAttack();
|
||
9 years ago
|
m_iStage = 0;
|
||
9 years ago
|
}
|
||
7 years ago
|
}
|
||
9 years ago
|
|
||
7 years ago
|
void CGravGun::PullThink()
|
||
|
{
|
||
|
if( m_hAimentEntity )
|
||
|
{
|
||
|
Pull( m_hAimentEntity );
|
||
|
pev->nextthink = gpGlobals->time + 0.05;
|
||
|
}
|
||
|
else SetThink( NULL );
|
||
9 years ago
|
}
|
||
7 years ago
|
|
||
|
void CGravGun::Pull(CBaseEntity* ent)
|
||
9 years ago
|
{
|
||
9 years ago
|
Vector origin = ent->pev->origin;
|
||
|
if( ent->IsBSPModel())
|
||
|
origin = VecBModelOrigin(ent->pev);
|
||
9 years ago
|
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
|
||
7 years ago
|
Vector target = PredictTarget( 75 );
|
||
9 years ago
|
target.z += 32;
|
||
9 years ago
|
if ((target - origin).Length() > 60){
|
||
7 years ago
|
target = PredictTarget(110);
|
||
7 years ago
|
Vector diff = target - origin;
|
||
9 years ago
|
|
||
9 years ago
|
target.z += 60;
|
||
|
|
||
|
|
||
9 years ago
|
//ALERT(at_console, "%s 1 %d : %f\n", STRING(ent->pev->classname), m_iStage, ((target - VecBModelOrigin(ent->pev)).Length()));
|
||
9 years ago
|
|
||
9 years ago
|
|
||
9 years ago
|
if( !m_iStage )
|
||
|
{
|
||
7 years ago
|
ent->pev->velocity = diff.Normalize()*(55000.0* 1.0/diff.Length());
|
||
|
if(ent->pev->velocity.Length() > 500 )
|
||
|
ent->pev->velocity = diff.Normalize() * 500;
|
||
|
|
||
7 years ago
|
ent->pev->velocity.z += 20;
|
||
7 years ago
|
if( diff.Length() < 150 )
|
||
9 years ago
|
{
|
||
|
m_iStage = 1;
|
||
7 years ago
|
|
||
|
SetThink( &CGravGun::GrabThink );
|
||
9 years ago
|
pev->nextthink = gpGlobals->time + 0.001;
|
||
9 years ago
|
ent->TouchGravGun(m_pPlayer, 1);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
7 years ago
|
ent->pev->velocity = diff.Normalize()*(55000.0* 1.0/diff.Length());
|
||
|
if(ent->pev->velocity.Length() > 900 )
|
||
|
ent->pev->velocity = diff.Normalize() * 900;
|
||
7 years ago
|
ent->pev->velocity.z += 15;
|
||
7 years ago
|
//ALERT( at_notice, "vel %f\n", ent->pev->velocity.Length() );
|
||
9 years ago
|
}
|
||
9 years ago
|
//ent->pev->velocity = ent->pev->velocity + m_pPlayer->pev->velocity;
|
||
9 years ago
|
/////
|
||
|
#ifdef BEAMS
|
||
|
CBeam* m_pBeam1 = CBeam::BeamCreate(GRAV_BEAM_SPRITE, 40);
|
||
|
m_pBeam1->SetFlags(BEAM_FSHADEOUT);
|
||
|
m_pBeam1->pev->spawnflags |= SF_BEAM_TEMPORARY; // Flag these to be destroyed on save/restore or level transition
|
||
|
m_pBeam1->pev->flags |= FL_SKIPLOCALHOST;
|
||
|
m_pBeam1->pev->owner = m_pPlayer->edict();
|
||
|
m_pBeam1->SetStartPos(target);
|
||
|
m_pBeam1->SetEndPos(VecBModelOrigin(ent->pev));
|
||
|
m_pBeam1->SetWidth(40 - (1 * 20));
|
||
|
m_pBeam1->SetBrightness(130);
|
||
|
#endif // BEAMS
|
||
|
|
||
|
|
||
|
/////
|
||
9 years ago
|
//ALERT(at_console, "%s 2: %f\n", STRING(ent->pev->classname), m_iStage, ent->pev->velocity.Length());
|
||
9 years ago
|
}
|
||
9 years ago
|
else if( ent->TouchGravGun(m_pPlayer, 2) )
|
||
9 years ago
|
{
|
||
7 years ago
|
ent->pev->velocity = (target - origin)* 80;
|
||
7 years ago
|
ent->m_fireState = ENTINDEX( m_pPlayer->edict() );
|
||
9 years ago
|
if(ent->pev->velocity.Length()>900)
|
||
9 years ago
|
ent->pev->velocity = (target - origin).Normalize() * 900;
|
||
9 years ago
|
ent->pev->velocity = ent->pev->velocity + m_pPlayer->pev->velocity;
|
||
9 years ago
|
m_iStage = 2;
|
||
7 years ago
|
SetThink( &CGravGun::GrabThink );
|
||
9 years ago
|
pev->nextthink = gpGlobals->time + 0.001;
|
||
9 years ago
|
}
|
||
9 years ago
|
else
|
||
|
{
|
||
|
SetThink(NULL);
|
||
7 years ago
|
if( m_hAimentEntity )
|
||
|
{
|
||
|
m_hAimentEntity->m_fireState = 0;
|
||
|
m_hAimentEntity = NULL;
|
||
|
}
|
||
9 years ago
|
EndAttack();
|
||
|
m_iStage = 0;
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::PrimaryAttack(void)
|
||
9 years ago
|
{
|
||
7 years ago
|
m_flLastCmd = gpGlobals->time;
|
||
9 years ago
|
if (m_flNextGravgunAttack < gpGlobals->time)
|
||
9 years ago
|
{
|
||
|
|
||
|
|
||
|
SetThink(NULL);
|
||
|
Attack();
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::SecondaryAttack(void)
|
||
9 years ago
|
{
|
||
7 years ago
|
m_flLastCmd = gpGlobals->time;
|
||
9 years ago
|
if (m_flNextGravgunAttack < gpGlobals->time)
|
||
9 years ago
|
{
|
||
9 years ago
|
if (m_iStage)
|
||
9 years ago
|
{
|
||
9 years ago
|
if( m_fireState != FIRE_OFF )
|
||
|
{
|
||
9 years ago
|
return;
|
||
9 years ago
|
}
|
||
9 years ago
|
//m_fireMode = FIRE_WIDE;
|
||
9 years ago
|
EndAttack();
|
||
|
SetThink(NULL);
|
||
9 years ago
|
m_flNextGravgunAttack = gpGlobals->time + 0.6;
|
||
9 years ago
|
//m_flTimeWeaponIdle = gpGlobals->time + 0.1;
|
||
9 years ago
|
|
||
|
m_iStage = 0;
|
||
9 years ago
|
if( m_hAimentEntity )
|
||
9 years ago
|
{
|
||
9 years ago
|
m_hAimentEntity->pev->velocity = Vector(0,0,0);
|
||
7 years ago
|
m_hAimentEntity->m_fireState = 0;
|
||
8 years ago
|
EMIT_SOUND( ENT( m_hAimentEntity->pev ), CHAN_VOICE, "weapons/357_cock1.wav", 0.8, ATTN_NORM );
|
||
9 years ago
|
m_hAimentEntity = NULL;
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
|
else {
|
||
|
Attack2();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
7 years ago
|
float CGravGun::Fire(const Vector &vecOrigSrc, const Vector &vecDir)
|
||
9 years ago
|
{
|
||
|
Vector vecDest = vecOrigSrc + vecDir * 2048;
|
||
|
edict_t *pentIgnore;
|
||
|
TraceResult tr;
|
||
|
|
||
|
pentIgnore = m_pPlayer->edict();
|
||
|
Vector tmpSrc = vecOrigSrc + gpGlobals->v_up * -8 + gpGlobals->v_right * 3;
|
||
|
UTIL_TraceLine(vecOrigSrc, vecDest, dont_ignore_monsters, pentIgnore, &tr);
|
||
|
|
||
|
if (tr.fAllSolid)
|
||
9 years ago
|
return (tr.vecEndPos - tmpSrc).Length();
|
||
9 years ago
|
|
||
|
UpdateEffect(tmpSrc, tr.vecEndPos, 1);
|
||
9 years ago
|
return (tr.vecEndPos - tmpSrc).Length();
|
||
9 years ago
|
}
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::UpdateEffect(const Vector &startPoint, const Vector &endPoint, float timeBlend)
|
||
9 years ago
|
{
|
||
|
#ifndef CLIENT_DLL
|
||
|
if (!m_pBeam)
|
||
|
{
|
||
|
CreateEffect();
|
||
|
}
|
||
|
|
||
|
m_pBeam->SetStartPos(endPoint);
|
||
|
m_pBeam->SetBrightness(255 - (timeBlend * 180));
|
||
|
m_pBeam->SetWidth(40 - (timeBlend * 20));
|
||
|
|
||
|
if (m_fireMode == FIRE_WIDE)
|
||
|
m_pBeam->SetColor(100 + (25 * timeBlend), 104 + 80 * fabs(sin(gpGlobals->time * 10)),10 );
|
||
|
else
|
||
|
m_pBeam->SetColor(90 + (25 * timeBlend), 100 + 80 * fabs(sin(gpGlobals->time * 10)), 10+(30 * timeBlend));
|
||
|
Vector& lel=pev->origin;
|
||
|
lel[0] = 30;
|
||
|
lel[1] = 30;
|
||
|
lel[2] = 30;
|
||
|
|
||
|
//Vector& ar= m_pPlayer->pev-> origin+ m_pPlayer->pev->view_ofs;
|
||
|
//Vector& al = pev->angles;
|
||
|
|
||
|
|
||
|
// UTIL_SetOrigin(m_pSprite->pev, ar);
|
||
|
// m_pSprite->pev->frame += 8 * gpGlobals->frametime;
|
||
|
//if (m_pSprite->pev->frame > m_pSprite->Frames())
|
||
|
// m_pSprite->pev->frame = 0;
|
||
|
|
||
|
m_pNoise->SetStartPos(endPoint);
|
||
|
|
||
|
#endif
|
||
|
|
||
|
}
|
||
|
|
||
7 years ago
|
void CGravGun::CreateEffect(void)
|
||
9 years ago
|
{
|
||
|
|
||
|
#ifndef CLIENT_DLL
|
||
|
DestroyEffect();
|
||
|
|
||
|
m_pBeam = CBeam::BeamCreate(GRAV_BEAM_SPRITE, 40);
|
||
|
m_pBeam->PointEntInit(pev->origin, m_pPlayer->entindex());
|
||
|
m_pBeam->SetFlags(BEAM_FSINE);
|
||
|
m_pBeam->SetEndAttachment(1);
|
||
|
m_pBeam->pev->spawnflags |= SF_BEAM_TEMPORARY; // Flag these to be destroyed on save/restore or level transition
|
||
|
//m_pBeam->pev->flags |= FL_SKIPLOCALHOST;
|
||
|
m_pBeam->pev->owner = m_pPlayer->edict();
|
||
|
|
||
|
m_pNoise = CBeam::BeamCreate(GRAV_BEAM_SPRITE, 55);
|
||
|
m_pNoise->PointEntInit(pev->origin, m_pPlayer->entindex());
|
||
|
m_pNoise->SetScrollRate(3);
|
||
|
m_pNoise->SetBrightness(100);
|
||
|
m_pNoise->SetEndAttachment(1);
|
||
|
m_pNoise->pev->spawnflags |= SF_BEAM_TEMPORARY;
|
||
|
//m_pNoise->pev->flags |= FL_SKIPLOCALHOST;
|
||
|
m_pNoise->pev->owner = m_pPlayer->edict();
|
||
|
|
||
|
/*m_pSprite = CSprite::SpriteCreate(GRAV_FLARE_SPRITE, m_pPlayer->GetGunPosition(), TRUE);
|
||
|
m_pSprite->pev->scale = 1.0;
|
||
|
|
||
|
m_pSprite->SetTransparency(kRenderGlow, 255, 140, 0, 255, kRenderFxPulseFast);
|
||
|
m_pSprite->pev->spawnflags |= SF_SPRITE_TEMPORARY;
|
||
|
m_pSprite->pev->flags |= FL_SKIPLOCALHOST;
|
||
|
m_pSprite->pev->owner = m_pPlayer->edict();*/
|
||
|
|
||
|
if (m_fireMode == FIRE_WIDE)
|
||
|
{
|
||
|
m_pBeam->SetScrollRate(300);
|
||
|
m_pBeam->SetNoise(20);
|
||
|
m_pNoise->SetColor(200, 120, 30);
|
||
|
m_pNoise->SetNoise(8);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
m_pBeam->SetScrollRate(200);
|
||
|
m_pBeam->SetNoise(5);
|
||
|
m_pNoise->SetColor(0, 255, 0);
|
||
|
m_pNoise->SetNoise(2);
|
||
8 years ago
|
EMIT_SOUND_DYN(ENT(m_pBeam->pev), CHAN_VOICE, "gravgun/hold.wav", 0.2, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
|
||
9 years ago
|
}
|
||
|
#endif
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::DestroyEffect(void)
|
||
9 years ago
|
{
|
||
|
|
||
|
#ifndef CLIENT_DLL
|
||
|
if (m_pBeam)
|
||
|
{
|
||
8 years ago
|
if( m_fireMode == FIRE_NARROW )
|
||
|
EMIT_SOUND( ENT(m_pBeam->pev), CHAN_VOICE, "gravgun/drop.wav", 0.2, ATTN_NORM );
|
||
9 years ago
|
UTIL_Remove(m_pBeam);
|
||
|
m_pBeam = NULL;
|
||
|
}
|
||
|
if (m_pNoise)
|
||
|
{
|
||
|
UTIL_Remove(m_pNoise);
|
||
|
m_pNoise = NULL;
|
||
|
}
|
||
|
if (m_pSprite)
|
||
|
{
|
||
|
if (m_fireMode == FIRE_WIDE)
|
||
|
m_pSprite->Expand(10, 500);
|
||
|
else
|
||
|
UTIL_Remove(m_pSprite);
|
||
|
m_pSprite = NULL;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::WeaponIdle(void)
|
||
9 years ago
|
{
|
||
7 years ago
|
m_flLastCmd = gpGlobals->time;
|
||
9 years ago
|
ResetEmptySound();
|
||
|
|
||
|
if (m_flTimeWeaponIdle > gpGlobals->time)
|
||
|
return;
|
||
|
|
||
|
if (m_fireState != FIRE_OFF)
|
||
|
EndAttack();
|
||
|
|
||
|
GravAnim(GAUSS_IDLE, 0, 0);
|
||
|
m_deployed = TRUE;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
7 years ago
|
void CGravGun::EndAttack(void)
|
||
9 years ago
|
{
|
||
|
bool bMakeNoise = false;
|
||
9 years ago
|
// if (m_AimentEntity&&m_AimentEntity->pev->velocity.Length() > 100&& (m_AimentEntity->pev->origin-m_pPlayer->pev->origin).Length()<100) { m_AimentEntity->pev->velocity = m_AimentEntity->pev->velocity / 10; }
|
||
8 years ago
|
//ALERT( at_console, "EndAttack()\n");
|
||
9 years ago
|
if (m_fireState != FIRE_OFF) //Checking the button just in case!.
|
||
|
bMakeNoise = true;
|
||
9 years ago
|
m_flNextGravgunAttack = gpGlobals->time + 0.1;
|
||
9 years ago
|
m_flTimeWeaponIdle = gpGlobals->time + 0.2;
|
||
|
|
||
|
m_fireState = FIRE_OFF;
|
||
|
|
||
|
DestroyEffect();
|
||
7 years ago
|
if( m_pfnThink == &CGravGun::PullThink )
|
||
|
SetThink( NULL );
|
||
9 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|